added "qsortrgb" effect

This commit is contained in:
Tonton Th 2020-10-08 11:24:29 +02:00
parent bbee507851
commit ceb806d19c
3 changed files with 93 additions and 2 deletions

View File

@ -5,7 +5,7 @@ DEPS = ../floatimg.h Makefile
OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \
fimg-libpnm.o rampes.o sfx0.o geometry.o rotate.o \
equalize.o fimg-fits.o saturation.o histogram.o \
hsv.o classif.o contour2x2.o
hsv.o classif.o contour2x2.o qsortrgb.o
#---------------------------------------------------------------
@ -64,6 +64,10 @@ rampes.o: rampes.c $(DEPS)
classif.o: classif.c $(DEPS)
gcc $(COPT) -c $<
qsortrgb.o: qsortrgb.c $(DEPS)
gcc $(COPT) -c $<
hsv.o: hsv.c $(DEPS)
gcc $(COPT) -c $<

41
funcs/qsortrgb.c Normal file
View File

@ -0,0 +1,41 @@
/*
* qsort_rgb.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "../floatimg.h"
int verbosity;
/* --------------------------------------------------------------------- */
/* nouveau 7 octobre 2020, juste avant sonoptic de la pluie craignos */
static int compare(const void *p1, const void *p2)
{
return ( *(float *)p1 < *(float *)p2 );
}
int fimg_qsort_rgb(FloatImg *psrc, FloatImg *pdst, int notused)
{
int foo, szimg;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, psrc, pdst, notused);
#endif
foo = fimg_copy_data(psrc, pdst);
szimg = pdst->width * pdst->height;
fprintf(stderr, "%s : %d pixels\n", __func__, szimg);
qsort(pdst->R, szimg, sizeof(float), compare);
qsort(pdst->G, szimg, sizeof(float), compare);
qsort(pdst->B, szimg, sizeof(float), compare);
return 0;
}
/* --------------------------------------------------------------------- */

View File

@ -14,6 +14,48 @@ int verbosity;
float global_fvalue;
/* --------------------------------------------------------------------- */
/*
* nouveau 7 octobre 2020 pendant sonoptic
*/
int fimg_qsort_rgb(FloatImg *psrc, FloatImg *pdst, int notused);
int essai_qsort_rgb(char *infile)
{
FloatImg src, dst;
int foo;
if (NULL != infile) {
fprintf(stderr, "%s : loading %s\n", __func__, infile);
foo = fimg_create_from_dump(infile, &src);
if (foo) {
fprintf(stderr, "%s: error loading '%s'\n", __func__, infile);
return foo;
}
}
else {
fprintf(stderr, "%s : NOT INPUT FILE, FUBAR\n", __func__);
abort();
}
fimg_clone(&src, &dst, 1);
foo = fimg_qsort_rgb(&src, &dst, 0);
if (foo) {
fprintf(stderr, "%s: err %d in qsort_rgb\n", __func__, foo);
return foo;
}
foo = fimg_save_as_pnm(&dst, "out.pnm", 0);
if (foo) {
fprintf(stderr, "%s : err %d saving result\n", __func__, foo);
return foo;
}
return 0;
}
/* --------------------------------------------------------------------- */
/*
* nouveau 5 octobre 2020 pendant sonoptic
@ -511,7 +553,7 @@ return 0;
}
/* --------------------------------------------------------------------- */
enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff,
Histo, Hsv, Classif, Ctr2x2 };
Histo, Hsv, Classif, Ctr2x2, Qsortrgb };
typedef struct {
char *name;
int Cmd;
@ -530,6 +572,7 @@ Command commands[] = {
{ "hsv", Hsv },
{ "classif", Classif },
{ "ctr2x2", Ctr2x2 },
{ "qsortrgb", Qsortrgb },
{ NULL, 0 }
} ;
@ -634,6 +677,9 @@ switch(opt) {
case Ctr2x2:
foo = essai_contour_2x2(filename);
break;
case Qsortrgb:
foo = essai_qsort_rgb(filename);
break;
default:
fprintf(stderr, "%s : bad command\n", command);
exit(1);