diff --git a/.gitignore b/.gitignore index cb771632..5fba36f9 100644 --- a/.gitignore +++ b/.gitignore @@ -67,6 +67,7 @@ Fonderie/*.o Fonderie/*.png Fonderie/*.pnm Fonderie/*.gif +Fonderie/*.fimg Fonderie/fonderie Fonderie/interpolator Fonderie/t diff --git a/Fonderie/crapulator.c b/Fonderie/crapulator.c index 4485e69f..22a70106 100644 --- a/Fonderie/crapulator.c +++ b/Fonderie/crapulator.c @@ -14,6 +14,8 @@ #include "glitches.h" #include "sfx.h" +extern int verbosity; + /* -------------------------------------------------------------- */ static int trier_les_pixels(FloatImg *pimg) { @@ -76,7 +78,7 @@ return 0; static int insitu_filtre3x3(FloatImg *pimg, int typef) { FloatImg img; -int retval; +int foo, retval; FimgFilter3x3 *pfiltre; FimgFilter3x3 lowpass = { @@ -97,9 +99,19 @@ FimgFilter3x3 hipass = { 1.0, 0.0 }; +FimgFilter3x3 diagonal = { + { + 2.0, 1.0, 0.0, + 1.0, 0.0, -1.0, + 0.0, -1.0, -2.0, + }, + 1.0, 4.0 + }; + switch (typef) { case 0: pfiltre = &lowpass; break; case 1: pfiltre = &hipass; break; + case 2: pfiltre = &diagonal; break; default: fprintf(stderr, "%s: bad filter number %d\n", __func__, typef); @@ -114,7 +126,14 @@ if (retval) { fprintf(stderr, "%s error %d on filter\n", __func__, retval); exit(1); } -fimg_killborders(&img); /* XXX WTF OMG */ +/** may be, we can check for negative values ? */ +if (verbosity > 1) { + foo = fimg_count_negativ(&img); + fprintf(stderr, "%s -> %d / %d negative pixels\n", __func__, + foo, img.width*img.height); + } + +fimg_killborders(&img); fimg_copy_data(&img, pimg); fimg_destroy(&img); @@ -194,7 +213,7 @@ switch (idFx) { break; case CR_liss2x2: retval = fimg_lissage_2x2(image); - (void)fimg_killborders(image); + // (void)fimg_killborders(image); break; case CR_liss3x3: /* smooth filter */ @@ -220,6 +239,9 @@ switch (idFx) { /* hipass filter */ retval = insitu_filtre3x3(image, 1); break; + case CR_diagonal: + retval = insitu_filtre3x3(image, 2); + break; case CR_octotree: retval = octotree_classif(image, 0.500, 0); break; diff --git a/Fonderie/crapulors.liste b/Fonderie/crapulors.liste index 05fd1f25..f1afc314 100644 --- a/Fonderie/crapulors.liste +++ b/Fonderie/crapulors.liste @@ -26,6 +26,7 @@ 27 shiftln0 1 1.0 28 qsortrgb 2 1.0 30 multidots 100 1.333 +31 diagonal 1 1.0 42 nothing 42 3.1415926 99 message 1 1.0 -1 end 1 1.0 diff --git a/Fonderie/essai.sh b/Fonderie/essai.sh index 9a787aba..9b38da8d 100755 --- a/Fonderie/essai.sh +++ b/Fonderie/essai.sh @@ -9,7 +9,8 @@ FILTRES=$(./t -L | awk 'NR>1 { print $1 }' | sort) rm /tmp/fstack*.png -SRC=$(ls -rt1 $HOME/Essais/FondageDePlomb/capture/* | tail -1) +# SRC=$(ls -rt1 $HOME/Essais/FondageDePlomb/capture/* | tail -1) +SRC=mire.fimg for F in $FILTRES do @@ -53,6 +54,6 @@ ffmpeg -nostdin \ # ------------------------------------------------------------ # MAIN -essai_singlepass +essai_filtres # ------------------------------------------------------------ diff --git a/Fonderie/fonctions.c b/Fonderie/fonctions.c index 80fba59a..878f5286 100644 --- a/Fonderie/fonctions.c +++ b/Fonderie/fonctions.c @@ -120,10 +120,6 @@ 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 * sizeof(float); diff --git a/Fonderie/fonderie.c b/Fonderie/fonderie.c index 5f9e94d0..5d92d256 100644 --- a/Fonderie/fonderie.c +++ b/Fonderie/fonderie.c @@ -43,20 +43,49 @@ int insert_blank(FloatImg *image, int nbre, int pproc, float fval, char *outd) { int idx, foo; +int preloaded = 0; +FloatImg blank; +char *fname; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %p %d %d %f '%s' )\n", __func__, + image, nbre, pproc, fval, outd); +#endif + +if (NULL != (fname=getenv("BLANK_FIMG"))) { + fprintf(stderr,"%s: try to load %s\n", __func__, fname); + fimg_clone(image, &blank, 1); + foo = fimg_load_from_dump(fname, &blank); + if (foo) { + fprintf(stderr, "epic fail %d on %s\n", foo, fname); + exit(1); + } + if (verbosity) fimg_describe(&blank, "Blank pic"); + preloaded = 1; + } fimg_clear(image); for (idx=0; idx>> %s ( %p %p %p)\n", __func__, src, dst, filtr); +fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, src, dst, filtr); #endif if (src->type != FIMG_TYPE_RGB) { @@ -48,7 +48,7 @@ for (y=1; y < h-1; y++) { M[7] * pr[of+w] + M[8] * pr[of+(w-1)] ; - dst->R[of] = dval; + dst->R[of] = dval + filtr->offset; dval = M[0] * pg[of-(w+1)] + M[1] * pg[of-w] + @@ -60,7 +60,7 @@ for (y=1; y < h-1; y++) { M[7] * pg[of+w] + M[8] * pg[of+(w-1)] ; - dst->G[of] = dval; + dst->G[of] = dval + filtr->offset; dval = M[0] * pb[of-(w+1)] + M[1] * pb[of-w] + @@ -72,7 +72,7 @@ for (y=1; y < h-1; y++) { M[7] * pb[of+w] + M[8] * pb[of+(w-1)] ; - dst->B[of] = dval; + dst->B[of] = dval + filtr->offset; } } @@ -189,7 +189,6 @@ if (foo) { return foo; } -/* XXX */ fimg_killborders(img); return foo; diff --git a/funcs/tests.c b/funcs/tests.c index 3d61ee4a..df327ada 100644 --- a/funcs/tests.c +++ b/funcs/tests.c @@ -323,7 +323,7 @@ FimgFilter3x3 filter_a = { { 1.0, 1.0, 1.0, 1.0, -3.0, 1.0, 1.0, 1.0, 1.0 }, - 8.0, 0.0 + 9.0, 0.0 }; @@ -332,10 +332,19 @@ FimgFilter3x3 filter_b = { { -2.0, -1.0, 0.0, -1.0, 3.0, 1.0, 0.0, 1.0, 2.0 }, - 8.0, 0.0 + 8.0, 0.0 }; +FimgFilter3x3 filter_c = { + { + 2.0, 1.0, 0.0, + 1.0, 0.0, -1.0, + 0.0, -1.0, -2.0, + }, + 1.0, 8.0 + }; + if (NULL != infile) { fprintf(stderr, "%s: loading %s\n", __func__, infile); foo = fimg_create_from_dump(infile, &src); @@ -351,6 +360,8 @@ else { } // fimg_save_as_png(&src, "test.png", 0); +foo = fimg_count_negativ(&src); +fprintf(stderr, "%s: source have %d negs\n", __func__, foo); foo = fimg_clone(&src, &dst, 0); if (foo) { @@ -359,21 +370,27 @@ if (foo) { } fimg_filter_3x3(&src, &dst, &filter_a); - foo = fimg_clamp_negativ(&dst); - if (foo) { - fprintf(stderr, "clamped %d negative pixels\n", foo); + fprintf(stderr, "A 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); foo = fimg_clamp_negativ(&dst); if (foo) { - fprintf(stderr, "clamped %d negative pixels\n", foo); + fprintf(stderr, "B 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_filter_3x3(&src, &dst, &filter_c); +foo = fimg_clamp_negativ(&dst); +if (foo) { + fprintf(stderr, "C clamped %d negative pixels\n", foo); + } +foo = fimg_save_as_png(&dst, "f3x3b.png", 0); // foo = fimg_save_as_pnm(&dst, "f3x3a.pnm", 0); fimg_destroy(&src); fimg_destroy(&dst); diff --git a/tools/png2fimg.c b/tools/png2fimg.c index 5273e783..ff8a4a2f 100644 --- a/tools/png2fimg.c +++ b/tools/png2fimg.c @@ -16,33 +16,42 @@ int verbosity = 0; +/* --------------------------------------------------------------------- */ +void help(int k) +{ +if (verbosity) fimg_print_version(k); + +exit(0); +} /* --------------------------------------------------------------------- */ int main(int argc, char *argv[]) { FloatImg fimg; -int foo; +int foo, opt; - /* - * pas de traitement des options ? - */ +while ((opt = getopt(argc, argv, "hv")) != -1) { + switch(opt) { + case 'v': verbosity++; break; + case 'h': help(1); exit(1); + } + } -if (3 != argc) { - fimg_print_version(1); - fprintf(stderr, "usage:\n\t%s foo.png bar.fimg\n", argv[0]); +if (2 != argc-optind) { + fprintf(stderr, "error: %s need two filenames\n", argv[0]); exit(1); } memset(&fimg, 0, sizeof(FloatImg)); -foo = fimg_create_from_png(argv[1], &fimg); +foo = fimg_create_from_png(argv[optind], &fimg); if (foo) { fprintf(stderr, "%s : err %d, abort.\n", argv[0], foo); exit(1); } -if (verbosity) fimg_describe(&fimg, argv[2]); +if (verbosity) fimg_describe(&fimg, argv[optind+1]); -foo = fimg_dump_to_file(&fimg, argv[2], 0); +foo = fimg_dump_to_file(&fimg, argv[optind+1], 0); if (foo) { fprintf(stderr, "save as '%s' -> err %d\n", argv[2], foo); exit(1); diff --git a/v4l2/grabvidseq.c b/v4l2/grabvidseq.c index ef855ae4..16b0acf8 100644 --- a/v4l2/grabvidseq.c +++ b/v4l2/grabvidseq.c @@ -168,6 +168,11 @@ if (verbosity > 1) { if (upscaling) fprintf(stderr, "upscaling is on\n"); } +if (upscaling && (nbre_capt%4)) { + fprintf(stderr, "WARN upscaling: %d bad nbre_capt\n", + nbre_capt); + } + fd = v4l2_open(dev_name, O_RDWR | O_NONBLOCK, 0); if (fd < 0) { perror(dev_name);