From 8206a1ac0aafe3a7328b3159238948c0db5bed03 Mon Sep 17 00:00:00 2001 From: tth Date: Sat, 10 Oct 2020 12:34:29 +0200 Subject: [PATCH] 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 f3d402d..6d54a1f 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 f33eea5..804a95c 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 d7d543b..6b48bd6 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;