From 9ddbef4e91330458f001a419070c282a25c0905f Mon Sep 17 00:00:00 2001 From: tth Date: Mon, 26 Apr 2021 11:43:42 +0200 Subject: [PATCH] added a mirror function --- floatimg.h | 5 +++-- funcs/geometry.c | 40 ++++++++++++++++++++++++++++++++++++++++ funcs/t.c | 6 +++++- funcs/tests.c | 33 +++++++++++++++++++++++++++++++++ funcs/tests.h | 1 + tools/fimgfx.c | 7 +++++-- 6 files changed, 87 insertions(+), 5 deletions(-) diff --git a/floatimg.h b/floatimg.h index 7b0fe79c..c97db603 100644 --- a/floatimg.h +++ b/floatimg.h @@ -4,7 +4,7 @@ * http://la.buvette.org/photos/cumul */ -#define FIMG_VERSION 135 +#define FIMG_VERSION 137 /* * in memory descriptor @@ -157,7 +157,7 @@ int fimg_classif_trial(FloatImg *src, FloatImg*dst, float fval, int notused); int fimg_qsort_rgb_a(FloatImg *psrc, FloatImg *pdst, int notused); int fimg_qsort_rgb_b(FloatImg *psrc, FloatImg *pdst, int notused); -/* module funcs/geometry.c */ +/* module funcs/??????.c */ int fimg_equalize_compute(FloatImg *src, void *vptr, float vmax); int fimg_mk_gray_from(FloatImg *src, FloatImg*dst, int k); @@ -167,6 +167,7 @@ int fimg_desaturate(FloatImg *src, FloatImg *dst, int notused); int fimg_halfsize_0(FloatImg *src, FloatImg *dst, int notused); int fimg_halfsize_1(FloatImg *src, FloatImg *dst, int notused); int fimg_extractor(FloatImg *in, FloatImg *out, Rectangle *rect); +int fimg_mirror(FloatImg *src, FloatImg *dst, int notused); int fimg_displacement_0(FloatImg *psrc, FloatImg *pdst, int flags); diff --git a/funcs/geometry.c b/funcs/geometry.c index d10ff28a..3343c2ec 100644 --- a/funcs/geometry.c +++ b/funcs/geometry.c @@ -5,6 +5,7 @@ #include #include +#include #include "../floatimg.h" @@ -135,4 +136,43 @@ for (yd=0; ydh; yd++) { return 0; } /* --------------------------------------------------------------------- */ +int fimg_mirror(FloatImg *src, FloatImg *dst, int notused) +{ +float *fptr; +int line, col, offl; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %p %p 0x%04x )\n", __func__, + src, dst, notused); +#endif + +if (fimg_images_not_compatible(src, dst)) { + fprintf(stderr, "bad karma in %s\n", __func__); + return -9; + } + +if (NULL == (fptr=alloca(src->width*sizeof(float)))) { + fprintf(stderr, "%s: no mem available\n", __func__); +#if MUST_ABORT + abort(); +#endif + return -11; + } + +for (line=0; lineheight; line++) { + offl = line * src->width; + for (col=0; colwidth; col++) + fptr[(src->width-1) - col] = src->R[offl+col]; + memcpy(dst->R+offl, fptr, src->width*sizeof(float)); + for (col=0; colwidth; col++) + fptr[(src->width-1) - col] = src->G[offl+col]; + memcpy(dst->G+offl, fptr, src->width*sizeof(float)); + for (col=0; colwidth; col++) + fptr[(src->width-1) - col] = src->B[offl+col]; + memcpy(dst->B+offl, fptr, src->width*sizeof(float)); + } + +return 0; +} +/* --------------------------------------------------------------------- */ diff --git a/funcs/t.c b/funcs/t.c index c751fa1c..77ef3c60 100644 --- a/funcs/t.c +++ b/funcs/t.c @@ -22,7 +22,7 @@ float global_fvalue; enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff, Histo, Hsv, Classif, Ctr2x2, Qsortrgb, Displace, ReadPNG, Plasmas, Hilight, OpenEXR, - Geometrie, FileType }; + Geometrie, FileType, Mirror }; typedef struct { char *name; int Cmd; @@ -49,6 +49,7 @@ Command commands[] = { { "openexr", OpenEXR }, { "geometrie", Geometrie, }, { "filetype", FileType }, + { "mirror", Mirror }, { NULL, 0 } } ; @@ -211,6 +212,9 @@ switch(opt) { case FileType: foo = essai_detect_type(); break; + case Mirror: + foo = essai_miroir(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 d9bfd256..6b9f5be7 100644 --- a/funcs/tests.c +++ b/funcs/tests.c @@ -16,6 +16,39 @@ extern int verbosity; +/* --------------------------------------------------------------------- */ +int essai_miroir(char *inf, char *outf, int flags) +{ +int foo; +FloatImg src, dst; + +fprintf(stderr, ">>> %s ( '%s' '%s' 0x%X )\n", __func__, + inf, outf, flags); + +foo = fimg_create_from_dump(inf, &src); +if (0 != foo) { + fprintf(stderr, "%s: err %d loading image '%s'\n", __func__, + foo, inf); + return foo; + } + +fimg_clone(&src, &dst, 0); + +/* run the crappy code */ +foo = fimg_mirror(&src, &dst, 0); +if (foo) { + fprintf(stderr, "err %d in fimg_mirrot\n", foo); + return -6; + } + +foo = fimg_export_picture(&dst, outf, 0); +if (foo) { + fprintf(stderr, "%s : err %d saving result\n", __func__, foo); + return foo; + } + +return -1; +} /* --------------------------------------------------------------------- */ /* nouveau 21 mars 2021 - rue d'Aragon */ int essai_openexr(char *inf, char *outf, int flags) diff --git a/funcs/tests.h b/funcs/tests.h index c955a891..e8ce240a 100644 --- a/funcs/tests.h +++ b/funcs/tests.h @@ -4,6 +4,7 @@ */ int essai_plasma(char *infile, char *outfile, int ikoef, float fkoef); +int essai_miroir(char *inf, char *outf, int flags); int essai_displacement(char *infile, char *outfile); int essai_qsort_rgb(char *infile, char *outfile); diff --git a/tools/fimgfx.c b/tools/fimgfx.c index ef1af3e7..2ae43f6b 100644 --- a/tools/fimgfx.c +++ b/tools/fimgfx.c @@ -22,7 +22,7 @@ typedef struct { enum fxid { Fx_cos01=5, Fx_cos010, Fx_pow2, Fx_sqrt, Fx_gray0, Fx_halfsz0, Fx_rot90, Fx_cmixa, Fx_desat, Fx_ctr2x2, Fx_norm, - Fx_classtrial, + Fx_classtrial, Fx_mirror, Fx_xper, Fx_binarize, Fx_trinarize,Fx_hilight_R }; Fx fx_list[] = { @@ -37,6 +37,7 @@ Fx fx_list[] = { { "xper", Fx_xper, 0, 1 }, { "desat", Fx_desat, 0, 1 }, { "ctr2x2", Fx_ctr2x2, 0, 1 }, + { "mirror", Fx_mirror, 0, 1 }, // { "norm", Fx_norm, 0, 1 }, { "classtrial", Fx_classtrial, 0, 1 }, { "binarize", Fx_binarize, 0, 1 }, @@ -204,7 +205,9 @@ switch (action) { fimg_copy_data(&src, &dest); foo = fimg_mix_rgb_gray(&dest, global_fvalue); break; - + case Fx_mirror: + foo = fimg_mirror(&src, &dest, 0); + break; case Fx_ctr2x2: foo = fimg_contour_2x2(&src, &dest, 0); break;