From 8206a1ac0aafe3a7328b3159238948c0db5bed03 Mon Sep 17 00:00:00 2001 From: tth Date: Sat, 10 Oct 2020 12:34:29 +0200 Subject: [PATCH 01/21] add "reverse flag" to fimg_contour_2x2 --- floatimg.h | 2 +- funcs/contour2x2.c | 18 +++++++++++++----- funcs/t.c | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/floatimg.h b/floatimg.h index f3d402db..6d54a1f6 100644 --- a/floatimg.h +++ b/floatimg.h @@ -98,7 +98,7 @@ 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); +int fimg_contour_2x2(FloatImg *psrc, FloatImg *pdst, int reverse); /* 'sfx0' module */ int fimg_killcolors_a(FloatImg *fimg, float fval); diff --git a/funcs/contour2x2.c b/funcs/contour2x2.c index f33eea5e..804a95c0 100644 --- a/funcs/contour2x2.c +++ b/funcs/contour2x2.c @@ -14,10 +14,11 @@ int verbosity; /* --------------------------------------------------------------------- */ /* nouveau 4 octobre 2020, juste avant sonoptic de la pluie craignos */ -int fimg_contour_2x2(FloatImg *psrc, FloatImg *pdst, int notused) +int fimg_contour_2x2(FloatImg *psrc, FloatImg *pdst, int reverse) { float avg[4]; int foo, x, y, q; +float v1, v2; int tbl[] = /* deep magic inside */ { @@ -28,9 +29,16 @@ int tbl[] = /* deep magic inside */ }; #if DEBUG_LEVEL -fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, psrc, pdst, notused); +fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, psrc, pdst, reverse); #endif +if (reverse) { + v1 = 0.0; v2 = 1.0; + } +else { + v1 = 1.0; v2 = 0.0; + } + foo = fimg_meanvalues(psrc, avg); if (verbosity) { fprintf(stderr, "mean values : %f %f %f\n", avg[0], avg[1], avg[2]); @@ -48,19 +56,19 @@ for (y=0; yheight-1; y++) { ( 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 ; + pdst->R[(y*psrc->width)+x] = tbl[q] ? v1 : v2 ; 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 ; + pdst->G[(y*psrc->width)+x] = tbl[q] ? v1 : v2 ; 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 ; + pdst->B[(y*psrc->width)+x] = tbl[q] ? v1 : v2 ; } diff --git a/funcs/t.c b/funcs/t.c index d7d543b2..6b48bd64 100644 --- a/funcs/t.c +++ b/funcs/t.c @@ -78,7 +78,7 @@ else { fimg_clone(&src, &dst, 1); -foo = fimg_contour_2x2(&src, &dst, 0); +foo = fimg_contour_2x2(&src, &dst, 1); if (foo) { fprintf(stderr, "%s: err %d in contour_2x2\n", __func__, foo); return foo; From 947152532d4103196b9fd56551b1b84772a51e09 Mon Sep 17 00:00:00 2001 From: tth Date: Mon, 12 Oct 2020 15:55:06 +0200 Subject: [PATCH 02/21] more extension tets --- funcs/t.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/funcs/t.c b/funcs/t.c index 6b48bd64..ecdf4b51 100644 --- a/funcs/t.c +++ b/funcs/t.c @@ -456,6 +456,12 @@ printf("%-10s %d\n\n", fname, foo); foo = format_from_extension(fname="foo.png"); printf("%-10s %d\n\n", fname, foo); +foo = format_from_extension(fname="foo.tiff"); +printf("%-10s %d\n\n", fname, foo); + +foo = format_from_extension(fname="foo.fits"); +printf("%-10s %d\n\n", fname, foo); + foo = format_from_extension(fname="foo.xyzzy"); printf("%-10s %d\n\n", fname, foo); @@ -688,7 +694,7 @@ if (foo) { fprintf(stderr, "Essai ====> %d\n", foo); } -fprintf(stderr, "++++++++++++++ end of pid %d\n", getpid()); +fprintf(stderr, "+++++ end of %s pid %d\n", command, getpid()); return 0; } /* --------------------------------------------------------------------- */ From 9fda48ab304a920629d1337d6004ae31972c7307 Mon Sep 17 00:00:00 2001 From: tth Date: Wed, 14 Oct 2020 10:32:29 +0200 Subject: [PATCH 03/21] adding mollyguard --- funcs/classif.c | 12 +++++++++++- funcs/contour2x2.c | 10 ++++++++++ funcs/qsortrgb.c | 20 +++++++++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/funcs/classif.c b/funcs/classif.c index eb6dc373..9e4fd60b 100644 --- a/funcs/classif.c +++ b/funcs/classif.c @@ -21,9 +21,19 @@ float range, dist, rgb[3], dr, dg, db; int x, y, on, off; #if DEBUG_LEVEL -fprintf(stderr, ">>> %s ( %p %p %f %d )\n", __func__, psrc, pdst, fval, notused); +fprintf(stderr, ">>> %s ( %p %p %f %d )\n", __func__, + psrc, pdst, fval, notused); #endif +if (FIMG_TYPE_RGB != psrc->type) { + fprintf(stderr, "%s: bad src type %d\n", __func__, psrc->type); + return -7; + } +if (fimg_images_not_compatible(psrc, pdst)) { + fprintf(stderr, "%s: bad dst type %d\n", __func__, pdst->type); + return -8; + } + /* calculer les amplitudes RGB de l'image source */ fimg_get_minmax_rgb(psrc, minmax); delta[0] = minmax[1] - minmax[0]; diff --git a/funcs/contour2x2.c b/funcs/contour2x2.c index 804a95c0..0c3add96 100644 --- a/funcs/contour2x2.c +++ b/funcs/contour2x2.c @@ -32,6 +32,16 @@ int tbl[] = /* deep magic inside */ fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, psrc, pdst, reverse); #endif +if (FIMG_TYPE_RGB != psrc->type) { + fprintf(stderr, "%s: bad src type %d\n", __func__, psrc->type); + return -7; + } +if (fimg_images_not_compatible(psrc, pdst)) { + fprintf(stderr, "%s: bad dst type %d\n", __func__, pdst->type); + return -8; + } + + if (reverse) { v1 = 0.0; v2 = 1.0; } diff --git a/funcs/qsortrgb.c b/funcs/qsortrgb.c index 6a1a96a9..dd801f86 100644 --- a/funcs/qsortrgb.c +++ b/funcs/qsortrgb.c @@ -27,6 +27,15 @@ int foo, szimg; fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, psrc, pdst, notused); #endif +if (FIMG_TYPE_RGB != psrc->type) { + fprintf(stderr, "%s: bad src type %d\n", __func__, psrc->type); + return -7; + } +if (fimg_images_not_compatible(psrc, pdst)) { + fprintf(stderr, "%s: bad dst type %d\n", __func__, pdst->type); + return -8; + } + foo = fimg_copy_data(psrc, pdst); szimg = pdst->width * pdst->height; @@ -44,7 +53,7 @@ typedef struct { float r, g, b; } pix; -static compare_b(const void *p1, const void *p2) +static int compare_b(const void *p1, const void *p2) { pix *s1, *s2; s1 = (pix *)p1; @@ -62,6 +71,15 @@ float rgb[3]; fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, psrc, pdst, notused); #endif +if (FIMG_TYPE_RGB != psrc->type) { + fprintf(stderr, "%s: bad src type %d\n", __func__, psrc->type); + return -7; + } +if (fimg_images_not_compatible(psrc, pdst)) { + fprintf(stderr, "%s: bad dst type %d\n", __func__, pdst->type); + return -8; + } + szimg = pdst->width * pdst->height; fprintf(stderr, "%s : %d pixels\n", __func__, szimg); From 453d08aa236307e91bcc4977e3a97a7381937077 Mon Sep 17 00:00:00 2001 From: tth Date: Fri, 16 Oct 2020 11:20:10 +0200 Subject: [PATCH 04/21] added universal exporter --- floatimg.h | 4 +++ funcs/Makefile | 5 +++- funcs/exporter.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ funcs/t.c | 32 +++++++++++++-------- 4 files changed, 103 insertions(+), 13 deletions(-) create mode 100644 funcs/exporter.c diff --git a/floatimg.h b/floatimg.h index 6d54a1f6..15fb0cd3 100644 --- a/floatimg.h +++ b/floatimg.h @@ -109,6 +109,10 @@ int fimg_colors_mixer_a(FloatImg *fimg, float fval); /* #coronamaison */ int fimg_rotate_90(FloatImg *src, FloatImg *dst, int notused); + +/* universal exporter XXX */ +int fimg_export_picture(FloatImg *pic, char *fname, int flags); + /* PNM files module */ int fimg_save_as_pnm(FloatImg *head, char *fname, int flags); int fimg_load_from_pnm(char *fname, FloatImg *head, int notused); diff --git a/funcs/Makefile b/funcs/Makefile index 971c09e3..c7aa9576 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 contour2x2.o qsortrgb.o + hsv.o classif.o contour2x2.o qsortrgb.o exporter.o #--------------------------------------------------------------- @@ -67,6 +67,9 @@ classif.o: classif.c $(DEPS) qsortrgb.o: qsortrgb.c $(DEPS) gcc $(COPT) -c $< +exporter.o: exporter.c $(DEPS) + gcc $(COPT) -c $< + hsv.o: hsv.c $(DEPS) gcc $(COPT) -c $< diff --git a/funcs/exporter.c b/funcs/exporter.c new file mode 100644 index 00000000..ed6b698a --- /dev/null +++ b/funcs/exporter.c @@ -0,0 +1,75 @@ +/* + * exporter.c + */ + +#include +#include +#include + +#include "../floatimg.h" + +extern int verbosity; + +/* --------------------------------------------------------------------- */ +/* + * multi-magic 'save file' function. + */ +int fimg_export_picture(FloatImg *pic, char *fname, int flags) +{ +int filetype; +int foo; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %p '%s' 0x%X )\n", __func__, + pic, fname, flags); +#endif + +filetype = format_from_extension(fname); +if (verbosity) { + fprintf(stderr, "file %s : type %d\n", fname, filetype); + } + +switch(filetype) { + + case FILE_TYPE_FIMG: + foo = fimg_dump_to_file(pic, fname, 0); + break; + + case FILE_TYPE_PNM: + foo = fimg_save_as_pnm(pic, fname, 0); + break; + + case FILE_TYPE_PNG: + foo = fimg_save_as_png(pic, fname, 0); + break; + + case FILE_TYPE_TGA: + fprintf(stderr, "%s: FILE_TYPE_TGA not implemented\n", + __func__); + foo = -666; + break; + + case FILE_TYPE_TIFF: + foo = fimg_write_as_tiff(pic, fname, 0); + break; + + case FILE_TYPE_FITS: + foo = fimg_save_R_as_fits(pic, fname, 0); + break; + + default: + foo = -1789; + break; + + } + +if (foo) { + fprintf(stderr, "%s: exporting '%s' -> %d\n", __func__, + fname, foo); + /* que faire maintenant ? */ + } + +return foo; +} +/* --------------------------------------------------------------------- */ + diff --git a/funcs/t.c b/funcs/t.c index ecdf4b51..08d0a4e1 100644 --- a/funcs/t.c +++ b/funcs/t.c @@ -45,7 +45,7 @@ if (foo) { return foo; } -foo = fimg_dump_to_file(&dst, "out.fimg", 0); +foo = fimg_export_picture(&dst, "out.pnm", 0); if (foo) { fprintf(stderr, "%s : err %d saving result\n", __func__, foo); return foo; @@ -58,6 +58,9 @@ return 0; /* * nouveau 5 octobre 2020 pendant sonoptic */ + + + int essai_contour_2x2(char *infile) { FloatImg src, dst; @@ -78,13 +81,13 @@ else { fimg_clone(&src, &dst, 1); -foo = fimg_contour_2x2(&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); +foo = fimg_export_picture(&dst, "out2x2.pnm", 0); if (foo) { fprintf(stderr, "%s : err %d saving result\n", __func__, foo); return foo; @@ -124,7 +127,7 @@ if (foo) { return foo; } -foo = fimg_save_as_pnm(&dst, "out.pnm", 0); +foo = fimg_export_picture(&dst, "out.pnm", 0); if (foo) { fprintf(stderr, "%s : err %d saving result\n", __func__, foo); return foo; @@ -222,8 +225,8 @@ fimg_save_as_png(&src, "test.png", 0); foo = fimg_rotate_90(&src, &dst, 0); fprintf(stderr, "rotate 90 -> %d\n", foo); -foo = fimg_save_as_png(&dst, "rotated90.png", 0); -foo = fimg_save_as_pnm(&dst, "rotated90.pnm", 0); +foo = fimg_export_picture(&dst, "rotated90.png", 0); +foo = fimg_export_picture(&dst, "rotated90.pnm", 0); fimg_destroy(&src); @@ -479,7 +482,7 @@ re = fimg_test_pattern(&fimg, 9, 1.0); if (re) { fprintf(stderr, "fimg_test_pattern -> %d\n", re); } -fimg_save_as_pnm(&fimg, "mire.pnm", 0); +fimg_export_picture(&fimg, "mire.pnm", 0); return -1; } @@ -525,7 +528,6 @@ return 0; } /* --------------------------------------------------------------------- */ - int fimg_essai_histo(FloatImg *src, char *outpic, int k); /* histogram.c */ int fimg_essai_hsv(char *fname); /* hsv.c */ @@ -598,7 +600,10 @@ void help(int k) { Command *pcmd; -fprintf(stderr, "usage:\n\t./t command filename\n"); +fprintf(stderr, "usage:\n\t./t [options] command filename\n"); + +fprintf(stderr, "options:\n"); +fprintf(stderr, "\t-o outfile\n"); fprintf(stderr, "commands:\n"); pcmd = commands; @@ -614,16 +619,19 @@ exit(0); int main(int argc, char *argv[]) { int foo, opt; -char *filename, *command; +char *filename, *command, *outfile; fprintf(stderr, "++++++++ test des fonctions pid=%d\n", getpid()); -global_fvalue = 1.0; +global_fvalue = 1.0; +outfile = "out.pnm"; -while ((opt = getopt(argc, argv, "hk:v")) != -1) { + +while ((opt = getopt(argc, argv, "hk:p:v")) != -1) { switch(opt) { case 'h': help(0); break; case 'k': global_fvalue = atof(optarg); break; + case 'o': outfile = optarg; break; case 'v': verbosity++; break; } } From 0b703e06337bc2e5123b6c5c0d88893c64df4606 Mon Sep 17 00:00:00 2001 From: tth Date: Fri, 16 Oct 2020 11:48:54 +0200 Subject: [PATCH 05/21] hmmm, no warning for that ? --- funcs/classif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/funcs/classif.c b/funcs/classif.c index 9e4fd60b..3190ba63 100644 --- a/funcs/classif.c +++ b/funcs/classif.c @@ -9,7 +9,7 @@ #include "../floatimg.h" -int verbosity; +extern int verbosity; /* --------------------------------------------------------------------- */ /* nouveau 2 octobre 2020, juste avant sonoptic de la pluie craignos */ From 29480bfdfdbf944a7ea09a70c4c3b7d9f8943b1a Mon Sep 17 00:00:00 2001 From: tth Date: Tue, 20 Oct 2020 00:09:20 +0200 Subject: [PATCH 06/21] oups again... --- funcs/contour2x2.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/funcs/contour2x2.c b/funcs/contour2x2.c index 0c3add96..52bc00bc 100644 --- a/funcs/contour2x2.c +++ b/funcs/contour2x2.c @@ -9,7 +9,7 @@ #include "../floatimg.h" -int verbosity; +extern int verbosity; /* --------------------------------------------------------------------- */ /* nouveau 4 octobre 2020, juste avant sonoptic de la pluie craignos */ @@ -41,7 +41,6 @@ if (fimg_images_not_compatible(psrc, pdst)) { return -8; } - if (reverse) { v1 = 0.0; v2 = 1.0; } From 8b8cf74128dd88a7b9de72839040e0f1f60959e8 Mon Sep 17 00:00:00 2001 From: tth Date: Tue, 20 Oct 2020 00:28:33 +0200 Subject: [PATCH 07/21] test program is going to be a real application --- funcs/t.c | 22 ++++++++++------------ funcs/vroum.sh | 14 +++++++------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/funcs/t.c b/funcs/t.c index 08d0a4e1..a91807ba 100644 --- a/funcs/t.c +++ b/funcs/t.c @@ -19,7 +19,7 @@ float global_fvalue; * nouveau 7 octobre 2020 pendant sonoptic */ -int essai_qsort_rgb(char *infile) +int essai_qsort_rgb(char *infile, char *outfile) { FloatImg src, dst; int foo; @@ -45,7 +45,7 @@ if (foo) { return foo; } -foo = fimg_export_picture(&dst, "out.pnm", 0); +foo = fimg_export_picture(&dst, outfile, 0); if (foo) { fprintf(stderr, "%s : err %d saving result\n", __func__, foo); return foo; @@ -59,9 +59,7 @@ return 0; * nouveau 5 octobre 2020 pendant sonoptic */ - - -int essai_contour_2x2(char *infile) +int essai_contour_2x2(char *infile, char *outfile) { FloatImg src, dst; int foo; @@ -87,7 +85,7 @@ if (foo) { return foo; } -foo = fimg_export_picture(&dst, "out2x2.pnm", 0); +foo = fimg_export_picture(&dst, outfile, 0); if (foo) { fprintf(stderr, "%s : err %d saving result\n", __func__, foo); return foo; @@ -99,7 +97,7 @@ return 0; /* * nouveau 5 octobre 2020 pendant sonoptic */ -int essai_classif(char *infile) +int essai_classif(char *infile, char *outfile) { FloatImg src, dst; int foo; @@ -127,7 +125,7 @@ if (foo) { return foo; } -foo = fimg_export_picture(&dst, "out.pnm", 0); +foo = fimg_export_picture(&dst, outfile, 0); if (foo) { fprintf(stderr, "%s : err %d saving result\n", __func__, foo); return foo; @@ -627,7 +625,7 @@ global_fvalue = 1.0; outfile = "out.pnm"; -while ((opt = getopt(argc, argv, "hk:p:v")) != -1) { +while ((opt = getopt(argc, argv, "hk:o:p:v")) != -1) { switch(opt) { case 'h': help(0); break; case 'k': global_fvalue = atof(optarg); break; @@ -684,13 +682,13 @@ switch(opt) { foo = fimg_essai_hsv(filename); break; case Classif: - foo = essai_classif(filename); + foo = essai_classif(filename, outfile); break; case Ctr2x2: - foo = essai_contour_2x2(filename); + foo = essai_contour_2x2(filename, outfile); break; case Qsortrgb: - foo = essai_qsort_rgb(filename); + foo = essai_qsort_rgb(filename, outfile); break; default: fprintf(stderr, "%s : bad command\n", command); diff --git a/funcs/vroum.sh b/funcs/vroum.sh index d0bf7ce9..dbb5b460 100755 --- a/funcs/vroum.sh +++ b/funcs/vroum.sh @@ -3,10 +3,10 @@ src=/dev/shm/foo.fimg out=out.fimg -maxi=99 +maxi=49 W="640" H="480" -grabopt=" -s 640x480 -v -p 0 -n 500 -c cos01 " +grabopt=" -s 640x480 -vv -p 0 -n 400 -c pow2 " mkdir /tmp/V @@ -20,13 +20,13 @@ do grabvidseq -$grabopt -o $src fval=$(echo "$foo / $maxi" | bc -l) - ./t -k $fval qsortrgb $src - echo $foo ' = ' $fval + ./t -vv -k 0.333 -o $out classif $src + echo $foo ' => ' $fval dst=$(printf "/tmp/V/%03d.png" $foo) - - montage $src $out -geometry $G $dst + echo $dst + montage $src $out -tile 1x2 -geometry $G $dst done -convert -delay 20 /tmp/V/*.png foo.gif +convert -delay 10 /tmp/V/*.png foo.gif From f04f37ce4360f7cf4b40a631be7cea68ee68655d Mon Sep 17 00:00:00 2001 From: tth Date: Mon, 26 Oct 2020 16:19:51 +0100 Subject: [PATCH 08/21] printf min & max values --- floatimg.h | 4 +++- funcs/utils.c | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/floatimg.h b/floatimg.h index 15fb0cd3..199ff818 100644 --- a/floatimg.h +++ b/floatimg.h @@ -3,7 +3,7 @@ * ugly code from tTh */ -#define FIMG_VERSION 109 +#define FIMG_VERSION 110 /* * in memory descriptor @@ -182,6 +182,8 @@ int fimg_save_as_png(FloatImg *src, char *outname, int flags); int fimg_test_pattern(FloatImg *fimg, int type, double dval); int fimg_draw_something(FloatImg *fimg); +/* file is 'funcs/utils.c' */ +void fimg_print_minmax(float minmax[6], char *titre); int parse_WxH(char *str, int *pw, int *ph); int parse_double(char *str, double *dptr); int format_from_extension(char *fname); diff --git a/funcs/utils.c b/funcs/utils.c index 32a9a1de..78aa0c1b 100644 --- a/funcs/utils.c +++ b/funcs/utils.c @@ -7,6 +7,16 @@ extern int verbosity; /* must be declared around main() */ +/* --------------------------------------------------------------------- */ +void fimg_print_minmax(float minmax[6], char *titre) +{ + +fprintf(stderr, "\t\tminmax %s\n", titre); +fprintf(stderr, "red\t\t%10f %10f\n", minmax[0], minmax[1]); +fprintf(stderr, "green\t\t%10f %10f\n", minmax[2], minmax[3]); +fprintf(stderr, "blue\t\t%10f %10f\n", minmax[4], minmax[5]); + +} /* --------------------------------------------------------------------- */ int parse_WxH(char *str, int *pw, int *ph) { From 3e820c8298fff7322b3cb3fa10c99ece2715bed6 Mon Sep 17 00:00:00 2001 From: tth Date: Mon, 26 Oct 2020 16:45:36 +0100 Subject: [PATCH 09/21] first version of displacement mapping --- funcs/Makefile | 6 ++- funcs/displacement.c | 91 ++++++++++++++++++++++++++++++++++++++++++++ funcs/t.c | 43 ++++++++++++++++++++- funcs/vroum.sh | 8 ++-- 4 files changed, 142 insertions(+), 6 deletions(-) create mode 100644 funcs/displacement.c diff --git a/funcs/Makefile b/funcs/Makefile index c7aa9576..d56af7ad 100644 --- a/funcs/Makefile +++ b/funcs/Makefile @@ -5,7 +5,8 @@ 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 qsortrgb.o exporter.o + hsv.o classif.o contour2x2.o qsortrgb.o exporter.o \ + displacement.o #--------------------------------------------------------------- @@ -19,6 +20,9 @@ t: t.c $(DEPS) ../libfloatimg.a ../libfloatimg.a: $(OBJS) $(AR) r $@ $? +displacement.o: displacement.c + gcc $(COPT) -c $< + fimg-png.o: fimg-png.c $(DEPS) gcc $(COPT) -c $< diff --git a/funcs/displacement.c b/funcs/displacement.c new file mode 100644 index 00000000..9b2ed35c --- /dev/null +++ b/funcs/displacement.c @@ -0,0 +1,91 @@ +/* + * displacement.c + */ + +#include +#include +#include +#include + +#include "../floatimg.h" + +extern int verbosity; + +/* --------------------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ +/* nouveau 24 octobre 2020, pendant le masque-flamme coronavidique */ + +int fimg_displacement_0(FloatImg *psrc, FloatImg *pdst, int flags) +{ +int x, y, foo; +float minmax[6]; +float rgb[3]; +float dltr, dltg, dltb; /* delta des minmax */ +float dispx, dispy; + +int dstx, dsty; +int in, out; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %p %p 0x%04x )\n", __func__, psrc, pdst, flags); +#endif + +if (FIMG_TYPE_RGB != psrc->type) { + fprintf(stderr, "%s: bad src type %d\n", __func__, psrc->type); + return -7; + } +if (fimg_images_not_compatible(psrc, pdst)) { + fprintf(stderr, "%s: bad dst type %d\n", __func__, pdst->type); + return -8; + } + +foo = fimg_get_minmax_rgb(psrc, minmax); +if (verbosity) { + fimg_print_minmax(minmax, (char *)__func__); + } + +dltr = minmax[1] - minmax[0]; +dltg = minmax[3] - minmax[2]; +dltb = minmax[5] - minmax[4]; + +in = out = 0; + +for (y=0; yheight; y++) { + + for (x=0; xwidth; x++) { + + fimg_get_rgb(psrc, x, y, rgb); + + dispx = (float)x + (rgb[1]/dltg * 10.0); + dispy = (float)y + (rgb[2]/dltb * 10.0); + dstx = (int)roundf(dispx - 5.0); + dsty = (int)roundf(dispy - 5.0); + + if ( (dstx < 0) || (dsty < 0) || + (dstx >= psrc->width) || + (dsty >= psrc->height) ) + { + /* OUT OF DESTINATION PICTURE */ + out++; + } + else { + rgb[1] = rgb[2] = rgb[0]; + fimg_put_rgb(pdst, dstx, dsty, rgb); + // fprintf(stderr, "%5d %5d %f\n", dstx, dsty, rgb[1]); + in++; + } + + } + + if (verbosity > 2) { + fprintf(stderr, "%4d / %4d\n", y, psrc->height); + } + } + +fprintf(stderr, "%s -------> in %d out %d\n", __func__, in, out); + +return 0; +} +/* --------------------------------------------------------------------- */ + + diff --git a/funcs/t.c b/funcs/t.c index a91807ba..edb9079b 100644 --- a/funcs/t.c +++ b/funcs/t.c @@ -14,6 +14,39 @@ int verbosity; float global_fvalue; +/* --------------------------------------------------------------------- */ +/* nouveau 24 octobre 2020, pendant le masque-flamme coronavidique */ + +int fimg_displacement_0(FloatImg *psrc, FloatImg *pdst, int flags); + +int essai_displacement(char *infile, char *outfile) +{ +int foo; +FloatImg src, dst; + +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; + } + +fimg_clone(&src, &dst, 1); + +foo = fimg_displacement_0(&src, &dst, 0); +if (foo) { + fprintf(stderr, "%s: err %d in disp map 0\n", __func__, foo); + return foo; + } + +foo = fimg_export_picture(&dst, outfile, 0); +if (foo) { + fprintf(stderr, "%s : err %d saving result\n", __func__, foo); + return foo; + } + +return 0; +} /* --------------------------------------------------------------------- */ /* * nouveau 7 octobre 2020 pendant sonoptic @@ -557,7 +590,8 @@ return 0; } /* --------------------------------------------------------------------- */ enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff, - Histo, Hsv, Classif, Ctr2x2, Qsortrgb }; + Histo, Hsv, Classif, Ctr2x2, Qsortrgb, + Displace }; typedef struct { char *name; int Cmd; @@ -577,6 +611,7 @@ Command commands[] = { { "classif", Classif }, { "ctr2x2", Ctr2x2 }, { "qsortrgb", Qsortrgb }, + { "displace", Displace }, { NULL, 0 } } ; @@ -620,10 +655,11 @@ int foo, opt; char *filename, *command, *outfile; fprintf(stderr, "++++++++ test des fonctions pid=%d\n", getpid()); +fprintf(stderr, "++++++++ compiled "__DATE__" at " __TIME__ "\n"); global_fvalue = 1.0; outfile = "out.pnm"; - +command = "none"; while ((opt = getopt(argc, argv, "hk:o:p:v")) != -1) { switch(opt) { @@ -690,6 +726,9 @@ switch(opt) { case Qsortrgb: foo = essai_qsort_rgb(filename, outfile); break; + case Displace: + foo = essai_displacement(filename, outfile); + break; default: fprintf(stderr, "%s : bad command\n", command); exit(1); diff --git a/funcs/vroum.sh b/funcs/vroum.sh index dbb5b460..ce0b1a02 100755 --- a/funcs/vroum.sh +++ b/funcs/vroum.sh @@ -6,7 +6,7 @@ out=out.fimg maxi=49 W="640" H="480" -grabopt=" -s 640x480 -vv -p 0 -n 400 -c pow2 " +grabopt=" -s 640x480 -vv -p 0 -n 300 -c cos01 " mkdir /tmp/V @@ -20,9 +20,11 @@ do grabvidseq -$grabopt -o $src fval=$(echo "$foo / $maxi" | bc -l) - ./t -vv -k 0.333 -o $out classif $src - echo $foo ' => ' $fval + ./t -vv -k 0.333 -o $out displace $src + # fimgstats $out + + echo $foo ' => ' $fval dst=$(printf "/tmp/V/%03d.png" $foo) echo $dst montage $src $out -tile 1x2 -geometry $G $dst From ce02cf96bc8b597de2aca29fee2473a113a0bb55 Mon Sep 17 00:00:00 2001 From: tth Date: Mon, 26 Oct 2020 18:49:37 +0100 Subject: [PATCH 10/21] tuning... --- floatimg.h | 4 +++- funcs/displacement.c | 14 ++++++++------ funcs/t.c | 2 -- funcs/vroum.sh | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/floatimg.h b/floatimg.h index 199ff818..06363a7c 100644 --- a/floatimg.h +++ b/floatimg.h @@ -3,7 +3,7 @@ * ugly code from tTh */ -#define FIMG_VERSION 110 +#define FIMG_VERSION 111 /* * in memory descriptor @@ -145,6 +145,8 @@ int fimg_desaturate(FloatImg *src, FloatImg *dst, int k); /* module funcs/geometry.c */ int fimg_halfsize_0(FloatImg *src, FloatImg *dst, int notused); +int fimg_displacement_0(FloatImg *psrc, FloatImg *pdst, int flags); + /* module funcs/rampes.c */ int fimg_hdeg_a(FloatImg *img, double dcoef); int fimg_vdeg_a(FloatImg *img, double dcoef); diff --git a/funcs/displacement.c b/funcs/displacement.c index 9b2ed35c..9821d6c1 100644 --- a/funcs/displacement.c +++ b/funcs/displacement.c @@ -43,7 +43,6 @@ foo = fimg_get_minmax_rgb(psrc, minmax); if (verbosity) { fimg_print_minmax(minmax, (char *)__func__); } - dltr = minmax[1] - minmax[0]; dltg = minmax[3] - minmax[2]; dltb = minmax[5] - minmax[4]; @@ -56,10 +55,10 @@ for (y=0; yheight; y++) { fimg_get_rgb(psrc, x, y, rgb); - dispx = (float)x + (rgb[1]/dltg * 10.0); + dispx = (float)x + (rgb[1]/dltg * 20.0); dispy = (float)y + (rgb[2]/dltb * 10.0); - dstx = (int)roundf(dispx - 5.0); - dsty = (int)roundf(dispy - 5.0); + dstx = (int)roundf(dispx - 10.0); + dsty = (int)roundf(dispy - 10.0); if ( (dstx < 0) || (dsty < 0) || (dstx >= psrc->width) || @@ -69,7 +68,10 @@ for (y=0; yheight; y++) { out++; } else { - rgb[1] = rgb[2] = rgb[0]; + if (flags & 1) { + /* going monochrome */ + rgb[1] = rgb[2] = rgb[0]; + } fimg_put_rgb(pdst, dstx, dsty, rgb); // fprintf(stderr, "%5d %5d %f\n", dstx, dsty, rgb[1]); in++; @@ -82,7 +84,7 @@ for (y=0; yheight; y++) { } } -fprintf(stderr, "%s -------> in %d out %d\n", __func__, in, out); +if (verbosity) fprintf(stderr, "%s -> in %d out %d\n", __func__, in, out); return 0; } diff --git a/funcs/t.c b/funcs/t.c index edb9079b..0782967b 100644 --- a/funcs/t.c +++ b/funcs/t.c @@ -17,8 +17,6 @@ float global_fvalue; /* --------------------------------------------------------------------- */ /* nouveau 24 octobre 2020, pendant le masque-flamme coronavidique */ -int fimg_displacement_0(FloatImg *psrc, FloatImg *pdst, int flags); - int essai_displacement(char *infile, char *outfile) { int foo; diff --git a/funcs/vroum.sh b/funcs/vroum.sh index ce0b1a02..c6a6748e 100755 --- a/funcs/vroum.sh +++ b/funcs/vroum.sh @@ -6,7 +6,7 @@ out=out.fimg maxi=49 W="640" H="480" -grabopt=" -s 640x480 -vv -p 0 -n 300 -c cos01 " +grabopt=" -s 640x480 -vv -p 0 -n 500 -c cos01 " mkdir /tmp/V From a6658532de343e7bf1c613e720cfacbc0a821b93 Mon Sep 17 00:00:00 2001 From: tth Date: Wed, 28 Oct 2020 13:00:12 +0100 Subject: [PATCH 11/21] remove useless message, fix parameter bug in vroum --- funcs/displacement.c | 3 --- funcs/vroum.sh | 10 +++++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/funcs/displacement.c b/funcs/displacement.c index 9821d6c1..00fab780 100644 --- a/funcs/displacement.c +++ b/funcs/displacement.c @@ -79,9 +79,6 @@ for (y=0; yheight; y++) { } - if (verbosity > 2) { - fprintf(stderr, "%4d / %4d\n", y, psrc->height); - } } if (verbosity) fprintf(stderr, "%s -> in %d out %d\n", __func__, in, out); diff --git a/funcs/vroum.sh b/funcs/vroum.sh index c6a6748e..aa661844 100755 --- a/funcs/vroum.sh +++ b/funcs/vroum.sh @@ -3,10 +3,10 @@ src=/dev/shm/foo.fimg out=out.fimg -maxi=49 -W="640" -H="480" -grabopt=" -s 640x480 -vv -p 0 -n 500 -c cos01 " +maxi=149 +W="320" +H="240" +grabopt=" -s ${W}x${H}w -vv -p 0 -n 600 -c none " mkdir /tmp/V @@ -20,7 +20,7 @@ do grabvidseq -$grabopt -o $src fval=$(echo "$foo / $maxi" | bc -l) - ./t -vv -k 0.333 -o $out displace $src + ./t -vv -k 0.333 -o $out ctr2x2 $src # fimgstats $out From 76b7e9ad55b29126fdd47e40e6280fbf0371c77f Mon Sep 17 00:00:00 2001 From: tth Date: Thu, 29 Oct 2020 18:49:02 +0100 Subject: [PATCH 12/21] remove useless message --- funcs/displacement.c | 1 - 1 file changed, 1 deletion(-) diff --git a/funcs/displacement.c b/funcs/displacement.c index 00fab780..bb0cf491 100644 --- a/funcs/displacement.c +++ b/funcs/displacement.c @@ -73,7 +73,6 @@ for (y=0; yheight; y++) { rgb[1] = rgb[2] = rgb[0]; } fimg_put_rgb(pdst, dstx, dsty, rgb); - // fprintf(stderr, "%5d %5d %f\n", dstx, dsty, rgb[1]); in++; } From 2d072bdfc926790ad3494b6374b06d4d8e1c5e2d Mon Sep 17 00:00:00 2001 From: tth Date: Thu, 29 Oct 2020 22:40:00 +0100 Subject: [PATCH 13/21] silencing an useless values display --- funcs/contour2x2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/funcs/contour2x2.c b/funcs/contour2x2.c index 52bc00bc..1569e2e4 100644 --- a/funcs/contour2x2.c +++ b/funcs/contour2x2.c @@ -49,7 +49,7 @@ else { } foo = fimg_meanvalues(psrc, avg); -if (verbosity) { +if (verbosity > 1) { fprintf(stderr, "mean values : %f %f %f\n", avg[0], avg[1], avg[2]); } From 6ff326d7d54d284b2cf7fa3bb6521a63ba2c00b9 Mon Sep 17 00:00:00 2001 From: tth Date: Fri, 30 Oct 2020 10:03:35 +0100 Subject: [PATCH 14/21] some tuning on tests --- funcs/t.c | 6 ++++++ funcs/vroum.sh | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/funcs/t.c b/funcs/t.c index 0782967b..758ddd7b 100644 --- a/funcs/t.c +++ b/funcs/t.c @@ -82,6 +82,8 @@ if (foo) { return foo; } +fimg_destroy(&src); fimg_destroy(&dst); + return 0; } @@ -122,6 +124,8 @@ if (foo) { return foo; } +fimg_destroy(&src); fimg_destroy(&dst); + return 0; } /* --------------------------------------------------------------------- */ @@ -162,6 +166,8 @@ if (foo) { return foo; } +fimg_destroy(&src); fimg_destroy(&dst); + return 0; } /* --------------------------------------------------------------------- */ diff --git a/funcs/vroum.sh b/funcs/vroum.sh index aa661844..3931b42f 100755 --- a/funcs/vroum.sh +++ b/funcs/vroum.sh @@ -3,10 +3,10 @@ src=/dev/shm/foo.fimg out=out.fimg -maxi=149 +maxi=249 W="320" H="240" -grabopt=" -s ${W}x${H}w -vv -p 0 -n 600 -c none " +grabopt=" -s ${W}x${H}w -vv -p 0 -n 60 -c none " mkdir /tmp/V @@ -20,7 +20,7 @@ do grabvidseq -$grabopt -o $src fval=$(echo "$foo / $maxi" | bc -l) - ./t -vv -k 0.333 -o $out ctr2x2 $src + ./t -vv -k 0.333 -o $out classif $src # fimgstats $out From 31ba65f01d68c872b06f4f14f76ce917867a0f3d Mon Sep 17 00:00:00 2001 From: tth Date: Fri, 30 Oct 2020 13:14:23 +0100 Subject: [PATCH 15/21] wip again... --- funcs/Makefile | 6 +++++- funcs/README.md | 20 ++++++++++++++++++++ funcs/dithering.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 funcs/README.md create mode 100644 funcs/dithering.c diff --git a/funcs/Makefile b/funcs/Makefile index d56af7ad..4e398651 100644 --- a/funcs/Makefile +++ b/funcs/Makefile @@ -6,7 +6,7 @@ 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 qsortrgb.o exporter.o \ - displacement.o + displacement.o dithering.o #--------------------------------------------------------------- @@ -56,6 +56,10 @@ histogram.o: histogram.c $(DEPS) equalize.o: equalize.c $(DEPS) gcc $(COPT) -c $< +dithering.o: dithering.c $(DEPS) + gcc $(COPT) -c $< + + sfx0.o: sfx0.c $(DEPS) gcc $(COPT) -c $< diff --git a/funcs/README.md b/funcs/README.md new file mode 100644 index 00000000..65b2f6eb --- /dev/null +++ b/funcs/README.md @@ -0,0 +1,20 @@ +# Fonctions + +Plein de fonctions qu'il serait bon de documenter :) + +## Contours + +Détecter des contours est une activité respectable. + +## Exporter + +Une méta-fonction qui va sauvegarder (dans la mesure de ses conséquences) +une image en fonction de l'extension du nom de fichier. + +## Sfx + +Effets spéciaux divers. + +## Dithering + +Work in progress... diff --git a/funcs/dithering.c b/funcs/dithering.c new file mode 100644 index 00000000..14305487 --- /dev/null +++ b/funcs/dithering.c @@ -0,0 +1,31 @@ +/* + * FloatImg : some dithering experiments + */ + +#include +#include +#include +#include + +#include "../floatimg.h" + +extern int verbosity; + +/* --------------------------------------------------------------------- */ +int fimg_dither_0(FloatImg *psrc, FloatImg *pdst, int flags) +{ +int x, y; + +for (y=0; yheight; y++) { + + for (x=0; xwidth; x++) + { + + + } + } + +return -1; +} +/* --------------------------------------------------------------------- */ + From 1cc2f9caaff8a5eb6ade3cee64a74998de4bc4fc Mon Sep 17 00:00:00 2001 From: tth Date: Sun, 1 Nov 2020 12:59:21 +0100 Subject: [PATCH 16/21] mutting useless message --- funcs/classif.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/funcs/classif.c b/funcs/classif.c index 3190ba63..b0198bb3 100644 --- a/funcs/classif.c +++ b/funcs/classif.c @@ -47,7 +47,7 @@ range = delta[0]; if (delta[1] 1) fprintf(stderr, "deltas : %f %f %f / %f\n", delta[0], delta[1], delta[2], range); @@ -55,7 +55,7 @@ if (verbosity ) fprintf(stderr, "deltas : %f %f %f / %f\n", baryc[0] = (minmax[1] + minmax[0]) / 2; baryc[1] = (minmax[3] + minmax[2]) / 2; baryc[2] = (minmax[5] + minmax[4]) / 2; -if (verbosity) fprintf(stderr, "barycs : %f %f %f\n", +if (verbosity > 1) fprintf(stderr, "barycs : %f %f %f\n", baryc[0], baryc[1], baryc[2]); on = off = 0; From 922292adf8ef3add523d98f56faa1d2afe6033ef Mon Sep 17 00:00:00 2001 From: tth Date: Mon, 2 Nov 2020 00:07:14 +0100 Subject: [PATCH 17/21] oups... --- funcs/classif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/funcs/classif.c b/funcs/classif.c index b0198bb3..29860f33 100644 --- a/funcs/classif.c +++ b/funcs/classif.c @@ -93,7 +93,7 @@ for (y=0; yheight; y++) { } } -fprintf(stderr, "on %d off %d\n", on, off); +if (verbosity > 1) fprintf(stderr, "on %d off %d\n", on, off); return 0; } From 364ce061308a8f34e1683f995cd6bb5b78e4a572 Mon Sep 17 00:00:00 2001 From: tth Date: Mon, 2 Nov 2020 00:08:47 +0100 Subject: [PATCH 18/21] avant inportation fonderie --- floatimg.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/floatimg.h b/floatimg.h index 06363a7c..3f542a9f 100644 --- a/floatimg.h +++ b/floatimg.h @@ -3,7 +3,7 @@ * ugly code from tTh */ -#define FIMG_VERSION 111 +#define FIMG_VERSION 112 /* * in memory descriptor From d50f2145ba5a08ad57a63afcf5245678e5579ee4 Mon Sep 17 00:00:00 2001 From: Tonton Th Date: Mon, 2 Nov 2020 01:25:00 +0100 Subject: [PATCH 19/21] embarquement de la fonderie --- .gitignore | 3 + Fonderie/Makefile | 28 +++++ Fonderie/crapulator.c | 42 +++++++ Fonderie/crapulator.h | 6 + Fonderie/fonctions.c | 252 ++++++++++++++++++++++++++++++++++++++++++ Fonderie/fonctions.h | 49 ++++++++ Fonderie/fonderie.c | 191 ++++++++++++++++++++++++++++++++ Fonderie/sfx.c | 101 +++++++++++++++++ README.md | 8 +- funcs/contour2x2.c | 3 + funcs/filtrage.c | 3 +- 11 files changed, 681 insertions(+), 5 deletions(-) create mode 100644 Fonderie/Makefile create mode 100644 Fonderie/crapulator.c create mode 100644 Fonderie/crapulator.h create mode 100644 Fonderie/fonctions.c create mode 100644 Fonderie/fonctions.h create mode 100644 Fonderie/fonderie.c create mode 100644 Fonderie/sfx.c diff --git a/.gitignore b/.gitignore index 8ba49abc..a95a764e 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ doc/*.idx doc/*.ilg doc/*.ind doc/co*.tex + funcs/t funcs/*.o funcs/*.png @@ -61,4 +62,6 @@ tools/fimgfx tools/*.png tools/*.tiff +Fonderie/*.o +Fonderie/fonderie diff --git a/Fonderie/Makefile b/Fonderie/Makefile new file mode 100644 index 00000000..155459ac --- /dev/null +++ b/Fonderie/Makefile @@ -0,0 +1,28 @@ + + +COPT = -g -no-pie -Wall -O3 -DDEBUG_LEVEL=0 -Werror=parentheses +LIBS = -lfloatimg -lpnglite -lm +OBJS = fonctions.o sfx.o crapulator.o +DEPS = fonctions.h crapulator.h + +fonderie: fonderie.c fonctions.h ${OBJS} Makefile + gcc ${COPT} $< ${OBJS} ${LIBS} -o $@ + +crapulator.o: crapulator.c ${DEPS} + gcc ${COPT} -c $< + +fonctions.o: fonctions.c fonctions.h Makefile + gcc ${COPT} -c $< + +sfx.o: sfx.c fonctions.h Makefile + gcc ${COPT} -c $< + +# --------------------------------------------------------- + +TOTAR = *.c *.h Makefile \ + *.sh + + + +# --------------------------------------------------------- + diff --git a/Fonderie/crapulator.c b/Fonderie/crapulator.c new file mode 100644 index 00000000..d1fee9da --- /dev/null +++ b/Fonderie/crapulator.c @@ -0,0 +1,42 @@ +/* + * crapulator.c + */ + +#include +#include + +#include + +#include "crapulator.h" + +/* -------------------------------------------------------------- */ + +int crapulator(FloatImg *image, int notused) +{ +int retval; +FloatImg imgtmp; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %p %d )\n", __func__, image, notused); +#endif + +/* contour 2x2 don't work inplace */ +fimg_clone(image, &imgtmp, 0); + +/* so we work on a copy */ +retval = fimg_contour_2x2(image, &imgtmp, 0); +if (retval) { + fprintf(stderr, "%s : err contour %d\n", + __func__, retval); + exit(1); + } + +/* and put back porcessed pixels */ +fimg_copy_data(&imgtmp, image); +fimg_destroy(&imgtmp); + +return 0; +} + +/* -------------------------------------------------------------- */ + diff --git a/Fonderie/crapulator.h b/Fonderie/crapulator.h new file mode 100644 index 00000000..85a7f90e --- /dev/null +++ b/Fonderie/crapulator.h @@ -0,0 +1,6 @@ +/* + * crapulator.h + */ + +int crapulator(FloatImg *image, int notused); + diff --git a/Fonderie/fonctions.c b/Fonderie/fonctions.c new file mode 100644 index 00000000..b1e3ff4a --- /dev/null +++ b/Fonderie/fonctions.c @@ -0,0 +1,252 @@ +/* + * Fonctions de la Fonderie du Cumul + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * Du code bien cracra / tTh / Tetalab + */ +#include +#include +#include +#include + +#include + +#include "fonctions.h" + +/* -------------------------------------------------------------- */ +/* global vars from main + */ +extern int verbosity; + +/* private vars of this module - it was very dirty + */ +static A_Fifo g_fifo; + +/* -------------------------------------------------------------- */ + +int faire_la_somme(A_Fifo *pfifo, FloatImg *destination, int step) +{ +int idx, foo; +FloatImg *pdest; + +if (NULL==destination) { + pdest = &(pfifo->total); } +else { + pdest = destination; } + +fimg_clear(pdest); +for (idx=0; idxnbslots; idx += step) { + foo = fimg_add_2(&(pfifo->slots[idx]), pdest); + if (foo) + { + fprintf(stderr, "%s: err %d on add_2\n", __func__, foo); + abort(); + } + } + +return 0; +} +/* -------------------------------------------------------------- */ +int post_process_picture(FloatImg *image, int numFx, float fval) +{ +int retval = 0; +int foo; +float value; +FloatImg imgtmp; +static int count, flag_debug; + +if (666==count) { + flag_debug = 1; + fprintf(stderr, "DEBUG POINT 1 in %s\n", __func__); + fimg_save_as_png(image, "source.png", 0); + } + +switch (numFx) { + case 0: /* DO NOTHING */ break; + + case 1: + fimg_cos_01(image, image, + fimg_get_maxvalue(image)); + break; + case 2: + fimg_cos_010(image, image, + fimg_get_maxvalue(image)); + break; + case 3: + value = fimg_get_maxvalue(image); + fimg_mul_cste(image, -1.0); + fimg_add_cste(image, value); + foo = fimg_count_negativ(image); + if (foo) { + fimg_dump_to_file(image, "err.fimg", 0); + fprintf(stderr, "%s negativ %d\n", __func__, foo); + return -78; + } + break; + case 4: + brotche_rand48(image, 0.20, + fimg_get_maxvalue(image)); + break; + case 5: + brotche_rand48_b(image, 0.10, + fimg_get_maxvalue(image)*0.8); + break; + case 6: + kill_colors_a(image, 0.0); + break; + + case 7: + retval = fimg_colors_mixer_a(image, 2.0); + break; + + case 8: + fimg_clone(image, &imgtmp, 0); + fimg_clear(&imgtmp); + if (flag_debug) { + fprintf(stderr, "DEBUG A contour 2x2\n"); + fimg_save_as_png(image, "before.png", 0); + fimg_dump_to_file(image, "before.fimg", 0); + } + retval = fimg_contour_2x2(image, &imgtmp, 0); + if (retval) { + fprintf(stderr, "%s : err contour %d\n", + __func__, retval); + exit(1); + } + if (flag_debug) { + fprintf(stderr, "DEBUG B contour 2x2\n"); + // fimg_save_as_png(&imgtmp, "contour.png", 0); + fimg_dump_to_file(&imgtmp, "contour.fimg", 0); + } + fimg_copy_data(&imgtmp, image); + fimg_destroy(&imgtmp); + break; + + case 9: + retval = fimg_classif_trial(image, image, 0.42, 0); + if (retval) { + fprintf(stderr, "err %d in classif\n", retval); + exit(1); + } + break; + + default : + fprintf(stderr, "%s : postproc #%d invalid\n", + __func__, numFx); + return -77; + } + +if (flag_debug) { + fprintf(stderr, "DEBUG POINT 2 in %s\n", __func__); + fimg_save_as_png(image, "after.png", 0); + } + +count++; flag_debug = 0; + +return retval; +} +/* -------------------------------------------------------------- */ +/* + * this func save the fifo content as + * - float FIMG + * - 16 bits PNM + * - 8 bits PNG + */ +int export_fifo(char *fname, int postproc, int step) +{ +int foo, type; + +foo = faire_la_somme(&g_fifo, NULL, step); + +/* BEGIN GRUIK CODE */ +extern int convert_to_gray; +/* END OF THE KLUGE */ +if (convert_to_gray) { + fimg_to_gray(&g_fifo.total); + // fprintf(stderr, "%p gray-washed\n", &fifo.total); + } + +foo = post_process_picture(&g_fifo.total, postproc, 0.0); +if (foo) { + fprintf(stderr, "ERR post process picture -> %d\n", foo); + return foo; + } + +type = format_from_extension(fname); +switch (type) { + case FILE_TYPE_PNG: + foo = fimg_save_as_png(&g_fifo.total, fname, 0); + break; + case FILE_TYPE_PNM: + foo = fimg_save_as_pnm(&g_fifo.total, fname, 0); + break; + case FILE_TYPE_FIMG: + foo = fimg_dump_to_file(&g_fifo.total, fname, 0); + break; + default: + fprintf(stderr, "%s : type of '%s' unknow\n", + __func__, fname); + foo = 888; + break; + } + +if (foo) { + fprintf(stderr, "ERR EXPORT '%s' is %d\n", fname, foo); + exit(3); + } + +return 0; +} +/* -------------------------------------------------------------- */ +int insert_picture(FloatImg *src) +{ +FloatImg *dst; +int nbre; + +/* + * this is the where we can insert the 'input filter' + */ + +dst = &g_fifo.slots[g_fifo.next]; + +nbre = dst->width * dst->height * dst->type; +memcpy(dst->R, src->R, nbre*sizeof(float)); + +g_fifo.next++, g_fifo.next %= g_fifo.nbslots; +// maybe we can write : +// (++fifo.next) %= fifo.nbslots; + +if (verbosity > 2) fprintf(stderr, "%s : next slot %d\n", + __func__, g_fifo.next); + +return 0; +} +/* -------------------------------------------------------------- */ +int create_fifo(int nbslot, int w, int h, int t) +{ +int foo, idx; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %d %dx%d %d )\n", __func__, + nbslot, w, h, t); +#endif + +memset(&g_fifo, 0, sizeof(A_Fifo)); + +g_fifo.nbslots = nbslot; + +g_fifo.slots = calloc(nbslot, sizeof(FloatImg)); +if (NULL==g_fifo.slots) abort(); +for (idx=0; idx +#include +#include +#include +#include +#include + +#include "fonctions.h" +#include "crapulator.h" + + +int verbosity; + +int convert_to_gray; + +/* -------------------------------------------------------------- */ +int traite_une_image(FloatImg *image, int proc, int step) +{ +static int numero; +int foo; +char ligne[200]; + +/* here, we put the picz in the fifo machinery */ +foo = insert_picture(image); +if (foo) { + fprintf(stderr, "%s : err %d on insert\n", __func__, foo); + return foo; + } + +sprintf(ligne, "p8/%05d.png", numero); +foo = export_fifo(ligne, proc, step); +if (foo) { + fprintf(stderr, "%s : err %d on export\n", __func__, foo); + return foo; + } + +numero++; /* VERY IMPORTANT :) */ + +return 0; +} +/* -------------------------------------------------------------- */ +int insert_blank(FloatImg *image, int nbre, int pproc) +{ +int idx, foo; + +fimg_clear(image); + +for (idx=0; idx>> %s ( '%s' -> '%s' %d )\n", __func__, + pattern, outdir, szfifo); +#endif + +fprintf(stderr, "\tstep is %d\n", step); + +(void)fimg_timer_set(0); + +if (outfx) fprintf(stderr, "\tout fx #%d\n", outfx); +else fprintf(stderr, "\tno out fx\n"); + +foo = create_fifo(szfifo, 640, 480, FIMG_TYPE_RGB); +fprintf(stderr, "init fifo (%d slots) --> %d\n", szfifo, foo); + +fimg_create(&input, 640, 480, 3); + +/* XXX inject a few stange pics in the fifo */ +insert_blank(&input, BLANK, outfx); + +memset(&globbuf, 0, sizeof(glob_t)); +foo = glob(pattern, 0, NULL, &globbuf); +fprintf(stderr, "glob '%s' -> %d, %ld files found\n", pattern, foo, + globbuf.gl_pathc); + +for (idx=0; idx %d\n", idx, foo); + continue; + } + + /* ========================= */ + /* FSCKING INPUT FILTER HERE */ + + foo = crapulator(&input, idx); + if (foo) { + fprintf(stderr, "%s crapulator -> %d\n", __func__, foo); + exit(1); + } + + foo = traite_une_image(&input, outfx, step); + if (foo) { + fprintf(stderr, "traitement %s -> %d WTF?\n", cptr, foo); + break; + } + fprintf(stderr, "\t%5d\r", idx); + } + +fputs("\n", stderr); + +insert_blank(&input, BLANK, outfx); + +fin = fimg_timer_get(0); +if (idx) { + fprintf(stderr, "\nelapsed %.2f seconds, %.2f s/pic\n", fin, fin/idx); + } +else { + fprintf(stderr, "\nelapsed %.2f seconds\n", fin); + } + +return 8; +} +/* -------------------------------------------------------------- */ +int main (int argc, char *argv[]) +{ +int foo, opt; +int fifosize = 10; +char *in_pattern = "capture/?????.fimg"; +char *out_dir = "p8"; +int out_effect = 0; +int steps = 1; + +// float maxlevel = 2500.0; + +fprintf(stderr, "*** %s : compiled by tTh, %s %s\n", argv[0], + __DATE__, __TIME__); +fimg_print_version(2); + +while ((opt = getopt(argc, argv, "gI:O:s:T:vx:")) != -1) { + switch(opt) { + + case 'g': convert_to_gray = 1; + break; + case 'I': in_pattern = optarg; + break; + case 'O': out_dir = optarg; + break; + case 'T': fifosize = atoi(optarg); + break; + case 'v': verbosity++; + break; + case 'x': out_effect = atoi(optarg); + break; + case 's': steps = atoi(optarg); + break; + } + } + +foo = demarre_la_machine(in_pattern, out_dir, fifosize, out_effect, steps); +fprintf(stderr, "retour du big-run de la machine -> %d\n", foo); + +return 0; +} +/* -------------------------------------------------------------- */ diff --git a/Fonderie/sfx.c b/Fonderie/sfx.c new file mode 100644 index 00000000..04df13fd --- /dev/null +++ b/Fonderie/sfx.c @@ -0,0 +1,101 @@ +/* + * SPECIAL EFFECTS + * + * Du code bien cracra / tTh / Tetalab + */ +#include +#include +#include +#include + +#include + +#include "fonctions.h" + +/* -------------------------------------------------------------- */ +/* global vars from main + */ +extern int verbosity; + +/* -------------------------------------------------------------- */ + +int brotche_rand48(FloatImg *fimg, float ratio, float mval) +{ +int nbpix, todo, foo; +int x, y; +float fval; + +nbpix = fimg->width * fimg->height; +todo = (int)((float)nbpix * ratio); + +if (verbosity > 1) + fprintf(stderr, "ratio %f nbpix %d todo %d\n", ratio, nbpix, todo); + +for (foo=0; foowidth; + y = rand() % fimg->height; + fimg_plot_rgb(fimg, x, y, fval, fval, fval); + } + +return 0; +} +/* -------------------------------------------------------------- */ +int brotche_rand48_b(FloatImg *fimg, float ratio, float mval) +{ +int nbpix, todo, foo; +int x, y; +float fval; + +nbpix = fimg->width * fimg->height; +todo = (int)((float)nbpix * ratio); + +if (verbosity > 1) { + fprintf(stderr, "ratio %f nbpix %d todo %d\n", + ratio, nbpix, todo); + } + +for (foo=0; foowidth-2)); + y = rand() % fimg->height; + fimg_plot_rgb(fimg, x-1, y, fval, 0.0, 0.0); + fimg_plot_rgb(fimg, x , y, 0.0, 0.0, fval); + fimg_plot_rgb(fimg, x+1, y, 0.0, fval, 0.0); + } + +return 0; +} +/* -------------------------------------------------------------- */ +/* + * OMG ! a Color Graphic Adaptor emulator :) + */ +int kill_colors_a(FloatImg *fimg, float fval) +{ +int nbpix, foo; + +if (FIMG_TYPE_RGB != fimg->type) { + fprintf(stderr, "%s: bad src type %d on %p\n", __func__, + fimg->type, fimg); + return -8; + } + +nbpix = fimg->width * fimg->height; + +for (foo=0; fooR[foo] > fimg->G[foo]) + fimg->B[foo] = fimg->R[foo]; + else + fimg->B[foo] = fimg->G[foo]; + } + +return 0; +} +/* -------------------------------------------------------------- */ +/* -------------------------------------------------------------- */ + + + diff --git a/README.md b/README.md index f8232f40..816880c4 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,8 @@ le canal IRC #tetalab sur le réseau de Par ailleurs, d'autres expérimentations sont [en cours](http://la.buvette.org/photos/cumul/fonderie/vidz.html#interpolator) sur le traitement et l'assemblage de ces images floues dans le but de faire -des films flous. Je sais aussi qu'un autre _diehard coder_ travaille sur la -parallélisation de certaines opérations. +des films flous. + +Un logiciel à base de [moyenne mobile](fonderie/) est en bonne voie. + *En avant vers l'infini, et au-delà...* - - diff --git a/funcs/contour2x2.c b/funcs/contour2x2.c index 1569e2e4..87c42359 100644 --- a/funcs/contour2x2.c +++ b/funcs/contour2x2.c @@ -83,6 +83,9 @@ for (y=0; yheight-1; y++) { } +/* kill potential NaN values in last row or last column */ + fimg_killborders(pdst); + return 0; } /* --------------------------------------------------------------------- */ diff --git a/funcs/filtrage.c b/funcs/filtrage.c index caec0c95..a1fbe59a 100644 --- a/funcs/filtrage.c +++ b/funcs/filtrage.c @@ -168,7 +168,8 @@ for (idx=0; idx Date: Mon, 2 Nov 2020 14:51:48 +0100 Subject: [PATCH 20/21] refactoring fonderie, step 1 --- Fonderie/README.md | 9 ++++ Fonderie/crapulator.c | 114 +++++++++++++++++++++++++++++++++++------- Fonderie/crapulator.h | 2 +- Fonderie/fonctions.c | 104 ++------------------------------------ Fonderie/fonctions.h | 3 +- Fonderie/fonderie.c | 34 ++++++++----- Fonderie/sfx.c | 43 ++++------------ 7 files changed, 143 insertions(+), 166 deletions(-) create mode 100644 Fonderie/README.md diff --git a/Fonderie/README.md b/Fonderie/README.md new file mode 100644 index 00000000..aefc9d8e --- /dev/null +++ b/Fonderie/README.md @@ -0,0 +1,9 @@ +# Fonderie + +Avec toutes ces fonctions disponibles et `grabvidseq`, nous +savons faire des images **floues***. L'étape suivante, les plus +pervers d'entre vous le savent déja, est celle de la création +de **films flous**. + +## fonderie + diff --git a/Fonderie/crapulator.c b/Fonderie/crapulator.c index d1fee9da..977ea99b 100644 --- a/Fonderie/crapulator.c +++ b/Fonderie/crapulator.c @@ -7,35 +7,115 @@ #include +#include "fonctions.h" #include "crapulator.h" /* -------------------------------------------------------------- */ -int crapulator(FloatImg *image, int notused) +int crapulator(FloatImg *image, int idFx, float fval) { -int retval; -FloatImg imgtmp; +int retval, foo; +FloatImg imgtmp; +static int count = 0; +int flag_debug = 0; +float value; #if DEBUG_LEVEL -fprintf(stderr, ">>> %s ( %p %d )\n", __func__, image, notused); +fprintf(stderr, ">>> %s ( %p %d %f )\n", __func__, + image, idFx, fval); #endif -/* contour 2x2 don't work inplace */ -fimg_clone(image, &imgtmp, 0); - -/* so we work on a copy */ -retval = fimg_contour_2x2(image, &imgtmp, 0); -if (retval) { - fprintf(stderr, "%s : err contour %d\n", - __func__, retval); - exit(1); +if (666==count) { + flag_debug = 1; + fprintf(stderr, "DEBUG POINT 1 in %s\n", __func__); + fimg_save_as_png(image, "source.png", 0); } -/* and put back porcessed pixels */ -fimg_copy_data(&imgtmp, image); -fimg_destroy(&imgtmp); +switch (idFx) { + case 0: /* DO NOTHING */ + retval = 0; break; -return 0; + case 1: + fimg_cos_01(image, image, + fimg_get_maxvalue(image)); + break; + case 2: + fimg_cos_010(image, image, + fimg_get_maxvalue(image)); + break; + case 3: + value = fimg_get_maxvalue(image); + fimg_mul_cste(image, -1.0); + fimg_add_cste(image, value); + foo = fimg_count_negativ(image); + if (foo) { + fimg_dump_to_file(image, "err.fimg", 0); + fprintf(stderr, "%s negativ %d\n", + __func__, foo); + return -78; + } + break; + case 4: + brotche_rand48_a(image, 0.20, + fimg_get_maxvalue(image)); + break; + case 5: + brotche_rand48_b(image, 0.10, + fimg_get_maxvalue(image)*0.8); + break; + case 6: + fimg_killcolors_a(image, 0.0); + break; + + case 7: + retval = fimg_colors_mixer_a(image, 2.0); + break; + + case 8: + fimg_clone(image, &imgtmp, 0); + fimg_clear(&imgtmp); + if (flag_debug) { + fprintf(stderr, "DEBUG A contour 2x2\n"); + fimg_save_as_png(image, "before.png", 0); + fimg_dump_to_file(image, "before.fimg", 0); + } + retval = fimg_contour_2x2(image, &imgtmp, 0); + if (retval) { + fprintf(stderr, "%s : err contour %d\n", + __func__, retval); + exit(1); + } + if (flag_debug) { + fprintf(stderr, "DEBUG B contour 2x2\n"); + // fimg_save_as_png(&imgtmp, "contour.png", 0); + fimg_dump_to_file(&imgtmp, "contour.fimg", 0); + } + fimg_copy_data(&imgtmp, image); + fimg_destroy(&imgtmp); + break; + + case 9: + retval = fimg_classif_trial(image, image, 0.42, 0); + if (retval) { + fprintf(stderr, "err %d in classif\n", retval); + exit(1); + } + break; + + default : + fprintf(stderr, "%s : effect #%d invalid\n", + __func__, idFx); + return -77; + } + +if (flag_debug) { + fprintf(stderr, "DEBUG POINT 2 in %s\n", __func__); + fimg_save_as_png(image, "after.png", 0); + } + +count++; flag_debug = 0; + +return retval; } /* -------------------------------------------------------------- */ diff --git a/Fonderie/crapulator.h b/Fonderie/crapulator.h index 85a7f90e..58d15e99 100644 --- a/Fonderie/crapulator.h +++ b/Fonderie/crapulator.h @@ -2,5 +2,5 @@ * crapulator.h */ -int crapulator(FloatImg *image, int notused); +int crapulator(FloatImg *image, int id_effect, float fparam); diff --git a/Fonderie/fonctions.c b/Fonderie/fonctions.c index b1e3ff4a..5544e2ec 100644 --- a/Fonderie/fonctions.c +++ b/Fonderie/fonctions.c @@ -11,6 +11,7 @@ #include #include "fonctions.h" +#include "crapulator.h" /* -------------------------------------------------------------- */ /* global vars from main @@ -46,104 +47,6 @@ for (idx=0; idxnbslots; idx += step) { return 0; } /* -------------------------------------------------------------- */ -int post_process_picture(FloatImg *image, int numFx, float fval) -{ -int retval = 0; -int foo; -float value; -FloatImg imgtmp; -static int count, flag_debug; - -if (666==count) { - flag_debug = 1; - fprintf(stderr, "DEBUG POINT 1 in %s\n", __func__); - fimg_save_as_png(image, "source.png", 0); - } - -switch (numFx) { - case 0: /* DO NOTHING */ break; - - case 1: - fimg_cos_01(image, image, - fimg_get_maxvalue(image)); - break; - case 2: - fimg_cos_010(image, image, - fimg_get_maxvalue(image)); - break; - case 3: - value = fimg_get_maxvalue(image); - fimg_mul_cste(image, -1.0); - fimg_add_cste(image, value); - foo = fimg_count_negativ(image); - if (foo) { - fimg_dump_to_file(image, "err.fimg", 0); - fprintf(stderr, "%s negativ %d\n", __func__, foo); - return -78; - } - break; - case 4: - brotche_rand48(image, 0.20, - fimg_get_maxvalue(image)); - break; - case 5: - brotche_rand48_b(image, 0.10, - fimg_get_maxvalue(image)*0.8); - break; - case 6: - kill_colors_a(image, 0.0); - break; - - case 7: - retval = fimg_colors_mixer_a(image, 2.0); - break; - - case 8: - fimg_clone(image, &imgtmp, 0); - fimg_clear(&imgtmp); - if (flag_debug) { - fprintf(stderr, "DEBUG A contour 2x2\n"); - fimg_save_as_png(image, "before.png", 0); - fimg_dump_to_file(image, "before.fimg", 0); - } - retval = fimg_contour_2x2(image, &imgtmp, 0); - if (retval) { - fprintf(stderr, "%s : err contour %d\n", - __func__, retval); - exit(1); - } - if (flag_debug) { - fprintf(stderr, "DEBUG B contour 2x2\n"); - // fimg_save_as_png(&imgtmp, "contour.png", 0); - fimg_dump_to_file(&imgtmp, "contour.fimg", 0); - } - fimg_copy_data(&imgtmp, image); - fimg_destroy(&imgtmp); - break; - - case 9: - retval = fimg_classif_trial(image, image, 0.42, 0); - if (retval) { - fprintf(stderr, "err %d in classif\n", retval); - exit(1); - } - break; - - default : - fprintf(stderr, "%s : postproc #%d invalid\n", - __func__, numFx); - return -77; - } - -if (flag_debug) { - fprintf(stderr, "DEBUG POINT 2 in %s\n", __func__); - fimg_save_as_png(image, "after.png", 0); - } - -count++; flag_debug = 0; - -return retval; -} /* -------------------------------------------------------------- */ /* * this func save the fifo content as @@ -165,9 +68,10 @@ if (convert_to_gray) { // fprintf(stderr, "%p gray-washed\n", &fifo.total); } -foo = post_process_picture(&g_fifo.total, postproc, 0.0); +foo = crapulator(&g_fifo.total, postproc, 0.0); if (foo) { - fprintf(stderr, "ERR post process picture -> %d\n", foo); + fprintf(stderr, "%s: ERR post process picture -> %d\n", + __func__, foo); return foo; } diff --git a/Fonderie/fonctions.h b/Fonderie/fonctions.h index e836b385..eb304f59 100644 --- a/Fonderie/fonctions.h +++ b/Fonderie/fonctions.h @@ -40,9 +40,8 @@ int create_fifo(int nbslot, int w, int h, int t); * funcs in 'sfx.c' */ -int brotche_rand48(FloatImg *fimg, float ratio, float mval); +int brotche_rand48_a(FloatImg *fimg, float ratio, float mval); int brotche_rand48_b(FloatImg *fimg, float ratio, float mval); -int kill_colors_a(FloatImg *fimg, float fval); int colors_brotcher(FloatImg *fimg, float fval); /* -------------------------------------------------------------- */ diff --git a/Fonderie/fonderie.c b/Fonderie/fonderie.c index 3beebdf4..6c5a013d 100644 --- a/Fonderie/fonderie.c +++ b/Fonderie/fonderie.c @@ -12,9 +12,7 @@ #include "fonctions.h" #include "crapulator.h" - int verbosity; - int convert_to_gray; /* -------------------------------------------------------------- */ @@ -27,17 +25,16 @@ char ligne[200]; /* here, we put the picz in the fifo machinery */ foo = insert_picture(image); if (foo) { - fprintf(stderr, "%s : err %d on insert\n", __func__, foo); + fprintf(stderr, "%s: err %d on insert\n", __func__, foo); return foo; } sprintf(ligne, "p8/%05d.png", numero); foo = export_fifo(ligne, proc, step); if (foo) { - fprintf(stderr, "%s : err %d on export\n", __func__, foo); + fprintf(stderr, "%s: err %d on export\n", __func__, foo); return foo; } - numero++; /* VERY IMPORTANT :) */ return 0; @@ -67,7 +64,7 @@ puts(""); return 0; } /* -------------------------------------------------------------- */ -#define BLANK 30 +#define BLANK 40 int demarre_la_machine(char *pattern, char *outdir, int szfifo, int outfx, int step) @@ -110,7 +107,6 @@ for (idx=0; idx %d\n", idx, foo); continue; @@ -118,8 +114,7 @@ for (idx=0; idx %d\n", __func__, foo); exit(1); @@ -148,26 +143,41 @@ else { return 8; } /* -------------------------------------------------------------- */ +void help(void) +{ +puts("\tFONDERIE\noptions:"); + +puts("\t-g\tconvert to gray"); +puts("\t-I\tinput glob pattern"); +puts("\t-O\toutput directory"); +puts("\t-T\tfifo size"); +puts("\t-v\tincrease verbosity"); +puts("\t-x\toutput effect"); + +exit(0); +} +/* -------------------------------------------------------------- */ int main (int argc, char *argv[]) { int foo, opt; int fifosize = 10; char *in_pattern = "capture/?????.fimg"; char *out_dir = "p8"; +int in_effect = 0; int out_effect = 0; int steps = 1; -// float maxlevel = 2500.0; - fprintf(stderr, "*** %s : compiled by tTh, %s %s\n", argv[0], __DATE__, __TIME__); fimg_print_version(2); -while ((opt = getopt(argc, argv, "gI:O:s:T:vx:")) != -1) { +while ((opt = getopt(argc, argv, "ghI:O:s:T:vx:")) != -1) { switch(opt) { case 'g': convert_to_gray = 1; break; + case 'h': help(); + break; case 'I': in_pattern = optarg; break; case 'O': out_dir = optarg; diff --git a/Fonderie/sfx.c b/Fonderie/sfx.c index 04df13fd..e56841f5 100644 --- a/Fonderie/sfx.c +++ b/Fonderie/sfx.c @@ -15,11 +15,12 @@ /* -------------------------------------------------------------- */ /* global vars from main */ -extern int verbosity; +extern int verbosity; /* -------------------------------------------------------------- */ -int brotche_rand48(FloatImg *fimg, float ratio, float mval) +/* -------------------------------------------------------------- */ +int brotche_rand48_a(FloatImg *fimg, float ratio, float mval) { int nbpix, todo, foo; int x, y; @@ -27,9 +28,10 @@ float fval; nbpix = fimg->width * fimg->height; todo = (int)((float)nbpix * ratio); - -if (verbosity > 1) - fprintf(stderr, "ratio %f nbpix %d todo %d\n", ratio, nbpix, todo); +if (verbosity > 1) { + fprintf(stderr, "%s: ratio %f nbpix %d todo %d\n", __func__, + ratio, nbpix, todo); + } for (foo=0; foowidth * fimg->height; todo = (int)((float)nbpix * ratio); - if (verbosity > 1) { - fprintf(stderr, "ratio %f nbpix %d todo %d\n", + fprintf(stderr, "%s: ratio %f nbpix %d todo %d\n", __func__, ratio, nbpix, todo); } @@ -69,33 +70,7 @@ for (foo=0; footype) { - fprintf(stderr, "%s: bad src type %d on %p\n", __func__, - fimg->type, fimg); - return -8; - } - -nbpix = fimg->width * fimg->height; - -for (foo=0; fooR[foo] > fimg->G[foo]) - fimg->B[foo] = fimg->R[foo]; - else - fimg->B[foo] = fimg->G[foo]; - } - -return 0; -} -/* -------------------------------------------------------------- */ -/* -------------------------------------------------------------- */ + From 423ab7f0eca3e74777b24f795fadf075c0066138 Mon Sep 17 00:00:00 2001 From: Tonton Th Date: Mon, 2 Nov 2020 22:20:54 +0100 Subject: [PATCH 21/21] refactoring fonderie, step 2 --- Fonderie/README.md | 13 +++++++++++++ Fonderie/crapulator.c | 6 +++--- Fonderie/fonderie.c | 20 +++++++++++++++----- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/Fonderie/README.md b/Fonderie/README.md index aefc9d8e..ca7e8c12 100644 --- a/Fonderie/README.md +++ b/Fonderie/README.md @@ -7,3 +7,16 @@ de **films flous**. ## fonderie +Le programme principal, utilisé à partir de la ligne de commande +avec une foule d'options aux mnémoniques abscons. + +Rassurez-vous, en général ils sont wrappables dans des scripts +shell. Il est même possible un jour qu'ils puissent lire des +paramètres dans `$(env)`. + + +## crapulator + +C'est dans ce module qu'est codé le moteur de filtrage, utilisé +aussi bien en entrée qu'en sortie. + diff --git a/Fonderie/crapulator.c b/Fonderie/crapulator.c index 977ea99b..dc5acfdb 100644 --- a/Fonderie/crapulator.c +++ b/Fonderie/crapulator.c @@ -27,7 +27,7 @@ fprintf(stderr, ">>> %s ( %p %d %f )\n", __func__, if (666==count) { flag_debug = 1; - fprintf(stderr, "DEBUG POINT 1 in %s\n", __func__); + fprintf(stderr, "DEBUG PT 1 in %s:%d\n", __func__, __LINE__); fimg_save_as_png(image, "source.png", 0); } @@ -95,7 +95,7 @@ switch (idFx) { break; case 9: - retval = fimg_classif_trial(image, image, 0.42, 0); + retval = fimg_classif_trial(image, image, 0.37, 0); if (retval) { fprintf(stderr, "err %d in classif\n", retval); exit(1); @@ -109,7 +109,7 @@ switch (idFx) { } if (flag_debug) { - fprintf(stderr, "DEBUG POINT 2 in %s\n", __func__); + fprintf(stderr, "DEBUG PT 2 in %s:%d\n", __func__, __LINE__); fimg_save_as_png(image, "after.png", 0); } diff --git a/Fonderie/fonderie.c b/Fonderie/fonderie.c index 6c5a013d..fa8e3033 100644 --- a/Fonderie/fonderie.c +++ b/Fonderie/fonderie.c @@ -30,6 +30,10 @@ if (foo) { } sprintf(ligne, "p8/%05d.png", numero); +/* ^^^ + XXX hardcoded value ? wtf ? + */ + foo = export_fifo(ligne, proc, step); if (foo) { fprintf(stderr, "%s: err %d on export\n", __func__, foo); @@ -67,7 +71,7 @@ return 0; #define BLANK 40 int demarre_la_machine(char *pattern, char *outdir, int szfifo, - int outfx, int step) + int infx, int outfx, int step) { int foo, idx; glob_t globbuf; @@ -84,6 +88,8 @@ fprintf(stderr, "\tstep is %d\n", step); (void)fimg_timer_set(0); +if (infx) fprintf(stderr, "\tin fx #%d\n", infx); +else fprintf(stderr, "\tno in fx\n"); if (outfx) fprintf(stderr, "\tout fx #%d\n", outfx); else fprintf(stderr, "\tno out fx\n"); @@ -114,7 +120,7 @@ for (idx=0; idx %d\n", __func__, foo); exit(1); @@ -152,6 +158,7 @@ puts("\t-I\tinput glob pattern"); puts("\t-O\toutput directory"); puts("\t-T\tfifo size"); puts("\t-v\tincrease verbosity"); +puts("\t-w\tinput effect"); puts("\t-x\toutput effect"); exit(0); @@ -167,8 +174,8 @@ int in_effect = 0; int out_effect = 0; int steps = 1; -fprintf(stderr, "*** %s : compiled by tTh, %s %s\n", argv[0], - __DATE__, __TIME__); +fprintf(stderr, "*** %s :\n\tcompiled by tTh, %s %s\n\tpid %d\n", + argv[0], __DATE__, __TIME__, getpid()); fimg_print_version(2); while ((opt = getopt(argc, argv, "ghI:O:s:T:vx:")) != -1) { @@ -186,6 +193,8 @@ while ((opt = getopt(argc, argv, "ghI:O:s:T:vx:")) != -1) { break; case 'v': verbosity++; break; + case 'w': in_effect = atoi(optarg); + break; case 'x': out_effect = atoi(optarg); break; case 's': steps = atoi(optarg); @@ -193,7 +202,8 @@ while ((opt = getopt(argc, argv, "ghI:O:s:T:vx:")) != -1) { } } -foo = demarre_la_machine(in_pattern, out_dir, fifosize, out_effect, steps); +foo = demarre_la_machine(in_pattern, out_dir, fifosize, in_effect, + out_effect, steps); fprintf(stderr, "retour du big-run de la machine -> %d\n", foo); return 0;