diff --git a/floatimg.h b/floatimg.h index 4c021d0f..c55fc4de 100644 --- a/floatimg.h +++ b/floatimg.h @@ -3,7 +3,7 @@ * ugly code from tTh */ -#define FIMG_VERSION 108 +#define FIMG_VERSION 109 /* * in memory descriptor @@ -59,7 +59,7 @@ int fimg_type_is_valid(int type); int fimg_print_version(int k); -void fimg_print_sizeof(void); +void fimg_print_sizeof(void); void fimg_printhead(FloatImg *h); int fimg_describe(FloatImg *head, char *txt); char *fimg_str_type(int type); @@ -97,6 +97,9 @@ int fimg_killborders(FloatImg *img); int fimg_lissage_2x2(FloatImg *img); int fimg_filter_3x3(FloatImg *s, FloatImg *d, FimgFilter3x3 *filtr); + +int fimg_contour_2x2(FloatImg *psrc, FloatImg *pdst, int notused); + /* 'sfx0' module */ int fimg_killcolors_a(FloatImg *fimg, float fval); int fimg_killcolors_b(FloatImg *fimg, float fval); diff --git a/funcs/Makefile b/funcs/Makefile index bea3a39e..9dbf5df8 100644 --- a/funcs/Makefile +++ b/funcs/Makefile @@ -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 + hsv.o classif.o contour2x2.o #--------------------------------------------------------------- @@ -55,6 +55,9 @@ equalize.o: equalize.c $(DEPS) sfx0.o: sfx0.c $(DEPS) gcc $(COPT) -c $< +contour2x2.o: contour2x2.c $(DEPS) + gcc $(COPT) -c $< + rampes.o: rampes.c $(DEPS) gcc $(COPT) -c $< diff --git a/funcs/contour2x2.c b/funcs/contour2x2.c new file mode 100644 index 00000000..7bc6bde8 --- /dev/null +++ b/funcs/contour2x2.c @@ -0,0 +1,70 @@ +/* + * classif.c + */ + +#include +#include +#include +#include + +#include "../floatimg.h" + +int verbosity; + +/* --------------------------------------------------------------------- */ +/* nouveau 4 octobre 2020, juste avant sonoptic de la pluie craignos */ + +int fimg_contour_2x2(FloatImg *psrc, FloatImg *pdst, int notused) +{ +float avg[4]; +int foo, x, y, q; +int tbl[] = + { + 0, 1, 1, 1, + 1, 1, 0, 1, + 1, 0, 1, 1, + 1, 1, 1, 0 + }; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, psrc, pdst, notused); +#endif + +foo = fimg_meanvalues(psrc, avg); +if (verbosity) { + fprintf(stderr, "mean values : %f %f %f\n", avg[0], avg[1], avg[2]); + } + +#define RP(ix, iy) ( psrc->R[((iy)*psrc->width)+(ix)] < avg[0] ) +#define GP(ix, iy) ( psrc->G[((iy)*psrc->width)+(ix)] < avg[1] ) +#define BP(ix, iy) ( psrc->B[((iy)*psrc->width)+(ix)] < avg[2] ) + +for (y=0; yheight-1; y++) { + + for (x=0; xwidth-1; x++) { + + q = ( ( RP(x, y) << 3 ) | + ( RP(x+1, y) << 2 ) | + ( RP(x, y+1) << 1 ) | + ( RP(x+1, y+1) ) ); + pdst->R[(y*psrc->width)+x] = tbl[q] ? 1.0 : 0.0 ; + + q = ( ( GP(x, y) << 3 ) | + ( GP(x+1, y) << 2 ) | + ( GP(x, y+1) << 1 ) | + ( GP(x+1, y+1) ) ); + pdst->G[(y*psrc->width)+x] = tbl[q] ? 1.0 : 0.0 ; + + q = ( ( BP(x, y) << 3 ) | + ( BP(x+1, y) << 2 ) | + ( BP(x, y+1) << 1 ) | + ( BP(x+1, y+1) ) ); + pdst->B[(y*psrc->width)+x] = tbl[q] ? 1.0 : 0.0 ; + + } + + } + +return 0; +} +/* --------------------------------------------------------------------- */ diff --git a/funcs/t.c b/funcs/t.c index 84fd4a68..08330fb2 100644 --- a/funcs/t.c +++ b/funcs/t.c @@ -14,6 +14,44 @@ int verbosity; float global_fvalue; +/* --------------------------------------------------------------------- */ +/* + * nouveau 5 octobre 2020 pendant sonoptic + */ +int essai_contour_2x2(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_contour_2x2(&src, &dst, 0); +if (foo) { + fprintf(stderr, "%s: err %d in contour_2x2\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 @@ -473,7 +511,7 @@ return 0; } /* --------------------------------------------------------------------- */ enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff, - Histo, Hsv,Classif }; + Histo, Hsv, Classif, Ctr2x2 }; typedef struct { char *name; int Cmd; @@ -491,6 +529,7 @@ Command commands[] = { { "histo", Histo }, { "hsv", Hsv }, { "classif", Classif }, + { "ctr2x2", Ctr2x2 }, { NULL, 0 } } ; @@ -592,6 +631,9 @@ switch(opt) { case Classif: foo = essai_classif(filename); break; + case Ctr2x2: + foo = essai_contour_2x2(filename); + break; default: fprintf(stderr, "%s : bad command\n", command); exit(1); diff --git a/funcs/vroum.sh b/funcs/vroum.sh index b8ffeb2c..74a40c49 100755 --- a/funcs/vroum.sh +++ b/funcs/vroum.sh @@ -2,8 +2,9 @@ src=foo.fimg -maxi=111 -grabopt=" s 640x480 -vv -p 0 -n 400 -c none " +maxi=179 +grabopt=" s 320x240 -vv -p 0 -n 100 -c none " + for foo in $(seq 0 $maxi) do @@ -11,7 +12,7 @@ do grabvidseq -$grabopt -o $src fval=$(echo "$foo / $maxi" | bc -l) - ./t -k $fval -v classif $src + ./t -k $fval -v ctr2x2 $src echo $foo $fval @@ -22,4 +23,4 @@ do done -convert -delay 10 v_*.pnm foo.gif +convert -delay 20 v_*.pnm foo.gif