diff --git a/floatimg.h b/floatimg.h index 59c0e31..4412db9 100644 --- a/floatimg.h +++ b/floatimg.h @@ -20,7 +20,7 @@ * https://git.tetalab.org/tTh/FloatImg */ -#define FIMG_VERSION (212) +#define FIMG_VERSION (218) #define RELEASE_NAME ("noname") /* XXX add a test for stdint.h / uint32_t XXX */ @@ -174,6 +174,7 @@ int fimg_binarize(FloatImg *pimg, int notused); int fimg_trinarize(FloatImg *pimg, int notused); /* module sfx3.c */ +int fimg_make_rndfluffy_lines(FloatImg *src, FloatImg *dst, int rndt); int fimg_crump_hard(FloatImg *src, FloatImg *dst, float kval, int notused); /* module sfx4.c */ diff --git a/funcs/sfx3.c b/funcs/sfx3.c index c21e542..148401f 100644 --- a/funcs/sfx3.c +++ b/funcs/sfx3.c @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -16,6 +17,45 @@ extern int verbosity; +/* -------------------------------------------------------------- */ +/* new Sun 29 Jan 2023 10:01:39 PM CET + +*/ +int fimg_make_rndfluffy_lines(FloatImg *src, FloatImg *dst, int rndt) +{ +int x, y, ol; +float accu; + +// #if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( '%p' '%p' %d )\n", __func__, + src, dst, rndt); +// #endif + +if (fimg_images_not_compatible(src, dst)) { + /* be hard for the lamers */ + fprintf(stderr, "compatibility OUPS in %s\n", __func__); + abort(); + } + +for (y=0; yheight; y++) { + ol = y * src->width; + if (rndt < (rand() % 100)) { + accu = 0.0; + for (x=0; xwidth; x++) accu += src->R[ol + x]; + accu /= (float)src->width; + for (x=0; xwidth; x++) dst->R[ol + x] = accu; + } + else { + for (x=0; xwidth; x++) { + dst->R[ol+x] = src->R[ol+x]; + dst->G[ol+x] = src->G[ol+x]; + dst->B[ol+x] = src->B[ol+x]; + } + } + } + +return 0; +} /* -------------------------------------------------------------- */ int fimg_crump_hard(FloatImg *src, FloatImg *dst, float kval, int notused) { diff --git a/funcs/t.c b/funcs/t.c index 93f1140..fdc3879 100644 --- a/funcs/t.c +++ b/funcs/t.c @@ -26,7 +26,7 @@ enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff, Geometrie, FileType, Mirror, KillRGB, Pixelize,SplitLevel, DecompRgbz, DecompRgbg, Rectangle, Dicom, Fakolor0, Fakolor3, - Fmorpho0 }; + Fmorpho0, Fluffy }; typedef struct { char *name; int Cmd; @@ -64,6 +64,7 @@ Command commands[] = { { "fakolor0", Fakolor0 }, { "fakolor3", Fakolor3 }, { "fmorpho0", Fmorpho0 }, + { "fluffy", Fluffy }, { NULL, 0 } } ; @@ -262,6 +263,9 @@ switch(opt) { case Fmorpho0: foo = essai_fmorpho_0(filename, "/tmp/fmorpho", 0); break; + case Fluffy: + foo = essai_rndfluffy(filename, outfile, 0); + break; default: fprintf(stderr, "'%s' is a bad command\n", command); exit(1); diff --git a/funcs/tests.c b/funcs/tests.c index 25e68be..4819f18 100644 --- a/funcs/tests.c +++ b/funcs/tests.c @@ -27,7 +27,6 @@ extern int verbosity; /* * nouveau 30 octobre 2022 --> fmorpho.c */ - int essai_fmorpho_0(char *infile, char *basefname, int k) { FloatImg src, dst; @@ -318,6 +317,42 @@ if (foo) { return 0; } /* --------------------------------------------------------------------- */ +/* new Sun Feb 12 10:34:06 CET 2023 + */ +int essai_rndfluffy(char *infile, char *outfile, int k) +{ +int foo; +FloatImg src, dst; + +fprintf(stderr, ">>> %s ( '%s' '%s' %d )\n", __func__, + infile, outfile, k); + +foo = fimg_create_from_dump(infile, &src); +if (0 != foo) { + fprintf(stderr, "%s: err %d loading image '%s'\n", __func__, + foo, infile); + return foo; + } +fprintf(stderr, " %s loaded.\n", infile); + +fimg_clone(&src, &dst, 0); +fprintf(stderr, " %p cloned.\n", &src); + +foo = fimg_make_rndfluffy_lines(&src, &dst, 80); +if (foo) { + fprintf(stderr, "err %d while making fluffy\n", foo); + return foo; + } + +foo = fimg_export_picture(&dst, outfile, 0); +if (foo) { + fprintf(stderr, "%s: err %d exporting %s\n", __func__, foo, outfile); + return foo; + } +fimg_destroy(&src); fimg_destroy(&dst); + +return 0; +} /* --------------------------------------------------------------------- */ int essai_split_level(char *inf, char *outf, int flags) { diff --git a/funcs/tests.h b/funcs/tests.h index cfbc349..0fd7c5c 100644 --- a/funcs/tests.h +++ b/funcs/tests.h @@ -8,6 +8,7 @@ int essai_miroir(char *inf, char *outf, int flags); int essai_killrgb(char *inf, char *outf); int essai_decomprgb_color(char *inf, char *outf); int essai_decomprgb_gray(char *inf, char *outf); +int essai_rndfluffy(char *infile, char *outfile, int k); /* sfx3.c */ int essai_split_level(char *inf, char *outf, int flags); int essai_displacement(char *infile, char *outfile);