diff --git a/doc/the_floatimg_hack.tex b/doc/the_floatimg_hack.tex index 1b47989..c64208a 100644 --- a/doc/the_floatimg_hack.tex +++ b/doc/the_floatimg_hack.tex @@ -956,7 +956,7 @@ encore un peu rudimentaire vers le programme de capture d'image décrit page \pageref{grabvidseq}. Il utilise deux fichiers dans le répertoire de travail~: \textit{reglages} et \textit{compteur}. Le premier est, en fait, -un bout de shell affectant quelques variables, ou plutôt, les surchargent. +un bout de shell affectant quelques variables, ou plutôt, les surchargant. \begin{lstlisting} OPTIONS="${OPTIONS} -v -c pow2 " diff --git a/floatimg.h b/floatimg.h index 5732591..334ce97 100644 --- a/floatimg.h +++ b/floatimg.h @@ -1,8 +1,9 @@ /* - * floatimg.h + * floatimg.h + * ugly code from tTh */ -#define FIMG_VERSION 98 +#define FIMG_VERSION 100 /* * in memory descriptor @@ -115,6 +116,10 @@ int fimg_power_2(FloatImg *s, FloatImg *d, double maxval); int fimg_cos_01(FloatImg *s, FloatImg *d, double maxval); int fimg_cos_010(FloatImg *s, FloatImg *d, double maxval); +/* module funcs/geometry.c */ +int fimg_equalize_compute(FloatImg *src, void *vptr); + + int fimg_mk_gray_from(FloatImg *src, FloatImg*dst, int k); int fimg_desaturate(FloatImg *src, FloatImg *dst, int k); diff --git a/funcs/Makefile b/funcs/Makefile index a849b0c..9bd7423 100644 --- a/funcs/Makefile +++ b/funcs/Makefile @@ -1,9 +1,10 @@ #--------------------------------------------------------------- -COPT = -Wall -fpic -g -pg -no-pie -DDEBUG_LEVEL=0 +COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=0 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 + fimg-libpnm.o rampes.o sfx0.o geometry.o rotate.o \ + equalize.o #--------------------------------------------------------------- @@ -36,6 +37,9 @@ geometry.o: geometry.c $(DEPS) rotate.o: rotate.c $(DEPS) gcc $(COPT) -c $< +equalize.o: equalize.c $(DEPS) + gcc $(COPT) -c $< + sfx0.o: sfx0.c $(DEPS) gcc $(COPT) -c $< diff --git a/funcs/equalize.c b/funcs/equalize.c new file mode 100644 index 0000000..ca6cccc --- /dev/null +++ b/funcs/equalize.c @@ -0,0 +1,39 @@ +/* + * FLOATIMG + * egalisation dinamique approximative + * #coronamaison Thu 09 Apr 2020 03:37:10 PM CEST + */ + +#include +#include + +#include "../floatimg.h" + +extern int verbosity; + +/* --------------------------------------------------------------------- */ +int fimg_equalize_compute(FloatImg *src, void *vptr) +{ +float minmax[6]; +int foo; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %p )\n", __func__, src); +#endif + +foo = fimg_get_minmax_rgb(src, minmax); +printf("Rmin %12.4g Rmax %12.4g\n", minmax[0], minmax[1]); +printf("Gmin %12.4g Gmax %12.4g\n", minmax[2], minmax[3]); +printf("Bmin %12.4g Bmax %12.4g\n", minmax[4], minmax[5]); + +if ( (minmax[0]<0.0) || (minmax[2]<0.0) || (minmax[4]<0.0) ) { + fprintf(stderr, "%s: negative value ?\n", __func__); + return -4; + } + +return 0; +} +/* --------------------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ + diff --git a/funcs/t.c b/funcs/t.c index 76ab01a..23abe96 100644 --- a/funcs/t.c +++ b/funcs/t.c @@ -12,6 +12,37 @@ int verbosity; float global_fvalue; +/* --------------------------------------------------------------------- */ +/* + * egalisation dynamique approximative + * #coronamaison Thu 09 Apr 2020 03:37:10 PM CEST + */ +int essai_equalize(char *infile) +{ +FloatImg src; +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: err load '%s'\n", __func__, infile); + return foo; + } + } +else { + fprintf(stderr, "%s : NOT INPUT FILE, FUBAR\n", __func__); + abort(); + } + +foo = fimg_equalize_compute(&src, NULL); +fprintf(stderr, "equalize compute --> %d\n", foo); + + +fimg_destroy(&src); + +return -1; +} /* --------------------------------------------------------------------- */ int essai_rotate(char *infile) { @@ -82,19 +113,24 @@ else { fimg_test_pattern(&src, 0, 255.0); } -fimg_save_as_png(&src, "test.png", 0); +// fimg_save_as_png(&src, "test.png", 0); foo = fimg_clone(&src, &dst, 0); if (foo) { fprintf(stderr, "%s: err clone %p\n", __func__, &src); return -44; } + + fimg_filter_3x3(&src, &dst, &filter_a); + + foo = fimg_clamp_negativ(&dst); + if (foo) { fprintf(stderr, "clamped %d negative pixels\n", foo); } -foo = fimg_save_as_png(&dst, "f3x3a.png", 0); +// foo = fimg_save_as_png(&dst, "f3x3a.png", 0); // foo = fimg_save_as_pnm(&dst, "f3x3a.pnm", 0); fimg_filter_3x3(&src, &dst, &filter_b); @@ -102,7 +138,7 @@ foo = fimg_clamp_negativ(&dst); if (foo) { fprintf(stderr, "clamped %d negative pixels\n", foo); } -foo = fimg_save_as_png(&dst, "f3x3b.png", 0); +// foo = fimg_save_as_png(&dst, "f3x3b.png", 0); // foo = fimg_save_as_pnm(&dst, "f3x3a.pnm", 0); fimg_destroy(&src); fimg_destroy(&dst); @@ -315,36 +351,102 @@ fprintf(stderr, "save as png -> %d\n", foo); return 0; } /* --------------------------------------------------------------------- */ +enum nCmd { Equalize=1, Rotate, Sfx0, F3x3 }; +typedef struct { + char *name; + int Cmd; + } Command; + +Command commands[] = { + { "equalize", Equalize }, + { "rotate", Rotate }, + { "sfx0", Sfx0 }, + { "f3x3", F3x3 }, + { NULL, 0 } + } ; + +/* --------------------------------------------------------------------- */ +int lookup_cmd(char *cmdtxt) +{ +Command *pcmd; + +pcmd = commands; +while (pcmd->name) { + if (!strcmp(pcmd->name, cmdtxt)) return pcmd->Cmd; + pcmd++; + } + +return -1; +} +/* --------------------------------------------------------------------- */ +void help(int k) +{ +Command *pcmd; + +fprintf(stderr, "usage:\n\t./t command in-filename\n"); + +fprintf(stderr, "commands:\n"); +pcmd = commands; +while (pcmd->name) { + fprintf(stderr, "\t%-15s %d\n", pcmd->name, pcmd->Cmd); + pcmd++; + } +fprintf(stderr, "\ncompiled on "__DATE__" at "__TIME__"\n"); + +exit(0); +} +/* --------------------------------------------------------------------- */ int main(int argc, char *argv[]) { int foo, opt; -char *filename; +char *filename, *command; -puts("++++++++++++++++++++++++++++++++"); +puts("++++++++ test des fonctions +++++++"); global_fvalue = 1.0; while ((opt = getopt(argc, argv, "hk:v")) != -1) { switch(opt) { - // case 'h': help(0); break; + case 'h': help(0); break; case 'k': global_fvalue = atof(optarg); break; case 'v': verbosity++; break; } } -fprintf(stderr, "argc %d optind %d\n", argc, optind); +// fprintf(stderr, "argc %d optind %d\n", argc, optind); filename = NULL; -if (1 == argc-optind) filename = argv[optind]; - -/* -foo = essai_filtrage_2x2(filename); -if (foo) { - fprintf(stderr, "Filtre 2x2 ====> %d\n", foo); +if (2 != argc-optind) { + fprintf(stderr, "%s: bad command line\n", argv[0]); + help(1); + } + +command = argv[optind]; +filename = argv[optind+1]; + +if (verbosity) { + fprintf(stderr, "running command '%s' on '%s'\n", command, filename); + } + +opt = lookup_cmd(command); +fprintf(stderr, "lookup '%s' --> %d\n", command, opt); + +switch(opt) { + case Equalize: + foo = essai_equalize(filename); break; + + case Sfx0: + foo = essai_sfx0(filename); break; + case F3x3: + foo = essai_filtrage_3x3(filename); break; + + + default: + fprintf(stderr, "%s : bad command\n", command); + exit(1); + } -*/ -foo = essai_rotate(filename); if (foo) { fprintf(stderr, "Essai ====> %d\n", foo); } diff --git a/lib/fimg-core.c b/lib/fimg-core.c index 430837c..412ef8c 100644 --- a/lib/fimg-core.c +++ b/lib/fimg-core.c @@ -111,7 +111,7 @@ if (NULL==fptr) { } #if DEBUG_LEVEL > 1 -fprintf(stderr, " got %d bytes at %p\n", size, fptr); +fprintf(stderr, " %s: got %d bytes at %p\n", __func__, size, fptr); #endif fimg->width = w; fimg->height = h; diff --git a/lib/fimg-math.c b/lib/fimg-math.c index 0c4e398..32da0d3 100644 --- a/lib/fimg-math.c +++ b/lib/fimg-math.c @@ -19,7 +19,7 @@ extern int verbosity; /* must be declared around main() */ float fimg_get_maxvalue(FloatImg *head) { float maxval; -int foo; +int foo, surface; if (head->type != FIMG_TYPE_RGB && head->type != FIMG_TYPE_GRAY) { fprintf(stderr, "%s : type %d invalide\n", @@ -29,15 +29,17 @@ if (head->type != FIMG_TYPE_RGB && head->type != FIMG_TYPE_GRAY) { maxval = 0.0; /* no negative values allowed */ +surface = head->width*head->height; + switch (head->type) { case FIMG_TYPE_RGB: - for (foo=0; foo<(head->width*head->height); foo++) { + for (foo=0; fooR[foo] > maxval) maxval = head->R[foo]; if (head->G[foo] > maxval) maxval = head->G[foo]; if (head->B[foo] > maxval) maxval = head->B[foo]; } case FIMG_TYPE_GRAY: - for (foo=0; foo<(head->width*head->height); foo++) { + for (foo=0; fooR[foo] > maxval) maxval = head->R[foo]; } } @@ -209,6 +211,19 @@ for (idx=0; idx