From 905022e782594289824117cdcce54bb8344455e7 Mon Sep 17 00:00:00 2001 From: Tonton Th Date: Wed, 4 Nov 2020 10:41:21 +0100 Subject: [PATCH] modularizing the crapulator --- Fonderie/crapulator.c | 61 ++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/Fonderie/crapulator.c b/Fonderie/crapulator.c index b57bfece..75485f4e 100644 --- a/Fonderie/crapulator.c +++ b/Fonderie/crapulator.c @@ -10,6 +10,44 @@ #include "fonctions.h" #include "crapulator.h" +/* -------------------------------------------------------------- */ +/* support function for the crapulator */ +static int effect_3(FloatImg *image) +{ +float value; +int foo; + +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; + } +return 0; +} +/* -------------------------------------------------------------- */ +static int insitu_ctr2x2(FloatImg *pimg) +{ +FloatImg img; +int retval; + +fimg_clone(pimg, &img, 0); +// XXX fimg_clear(&img); +retval = fimg_contour_2x2(pimg, &img, 0); +if (retval) { + fprintf(stderr, "%s : err contour %d\n", + __func__, retval); + exit(1); + } +fimg_copy_data(&img, pimg); +fimg_destroy(&img); + +return 0; +} /* -------------------------------------------------------------- */ /* * This is the main filter engine @@ -21,7 +59,6 @@ int retval, foo; FloatImg imgtmp; static int count = 0; int flag_debug = 0; -float value; #if DEBUG_LEVEL fprintf(stderr, ">>> %s ( %p %d %f )\n", __func__, @@ -49,16 +86,7 @@ switch (idFx) { 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; - } + retval = effect_3(image); break; case 4: brotche_rand48_a(image, 0.20, @@ -77,16 +105,7 @@ switch (idFx) { break; case 8: - fimg_clone(image, &imgtmp, 0); - fimg_clear(&imgtmp); - retval = fimg_contour_2x2(image, &imgtmp, 0); - if (retval) { - fprintf(stderr, "%s : err contour %d\n", - __func__, retval); - exit(1); - } - fimg_copy_data(&imgtmp, image); - fimg_destroy(&imgtmp); + retval = insitu_ctr2x2(image); break; case 9: