From 27af6d5282bdb3cd11c6eec50ae005e69cd35e79 Mon Sep 17 00:00:00 2001 From: tth Date: Fri, 9 Apr 2021 19:04:59 +0200 Subject: [PATCH] new func: fimg_halfsize_1 --- floatimg.h | 3 ++- funcs/geometry.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++- funcs/t.c | 7 ++++++- funcs/tests.c | 20 ++++++++++++++----- funcs/tests.h | 1 + 5 files changed, 73 insertions(+), 8 deletions(-) diff --git a/floatimg.h b/floatimg.h index cdcc8e9..09f05bc 100644 --- a/floatimg.h +++ b/floatimg.h @@ -4,7 +4,7 @@ * http://la.buvette.org/photos/cumul */ -#define FIMG_VERSION 131 +#define FIMG_VERSION 132 /* * in memory descriptor @@ -158,6 +158,7 @@ int fimg_desaturate(FloatImg *src, FloatImg *dst, int notused); /* module funcs/geometry.c */ int fimg_halfsize_0(FloatImg *src, FloatImg *dst, int notused); +int fimg_halfsize_1(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 dab2ee3..b6fcd15 100644 --- a/funcs/geometry.c +++ b/funcs/geometry.c @@ -26,7 +26,7 @@ fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, /* no magic check here ? */ if (dst->width || dst->height) { fprintf(stderr, "*** %s: image at %p not empty\n", __func__, dst); - fimg_describe(dst, "destination halfsize"); + fimg_describe(dst, "destination halfsize 0"); return -2; } @@ -55,3 +55,51 @@ for (y=0; ywidth || dst->height) { + fprintf(stderr, "*** %s: image at %p not empty\n", __func__, dst); + fimg_describe(dst, "destination halfsize 1"); + return -2; + } + +wd = src->width / 2; hd = src->height / 2; +if ( (foo = fimg_create(dst, wd, hd, FIMG_TYPE_RGB)) ) { + fprintf(stderr, "%s: err create %d\n", __func__, foo); + return -3; + } + +#define WS (src->width) +#define WD (dst->width) + +for (y=0; yR[(y2*WS)+x2] + src->R[(y2*WS)+x2+1] + + src->R[((1+y2)*WS)+x2] + src->R[((1+y2)*WS)+x2+1]; + dst->R[y*WD +x] = ac / 4.0; + + ac = src->G[(y2*WS)+x2] + src->G[(y2*WS)+x2+1] + + src->G[((1+y2)*WS)+x2] + src->G[((1+y2)*WS)+x2+1]; + dst->G[y*WD +x] = ac / 4.0; + + ac = src->B[(y2*WS)+x2] + src->B[(y2*WS)+x2+1] + + src->B[((1+y2)*WS)+x2] + src->B[((1+y2)*WS)+x2+1]; + dst->B[y*WD +x] = ac / 4.0; + + } + } + +#undef WS +#undef WD + +return 0; +} +/* --------------------------------------------------------------------- */ + diff --git a/funcs/t.c b/funcs/t.c index 64443a7..2f16c7d 100644 --- a/funcs/t.c +++ b/funcs/t.c @@ -21,7 +21,8 @@ float global_fvalue; /* --------------------------------------------------------------------- */ enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff, Histo, Hsv, Classif, Ctr2x2, Qsortrgb, - Displace, ReadPNG, Plasmas, Hilight, OpenEXR }; + Displace, ReadPNG, Plasmas, Hilight, OpenEXR, + Geometrie }; typedef struct { char *name; int Cmd; @@ -46,6 +47,7 @@ Command commands[] = { { "plasma", Plasmas }, { "hilight", Hilight }, { "openexr", OpenEXR }, + { "geometrie", Geometrie, }, { NULL, 0 } } ; @@ -202,6 +204,9 @@ switch(opt) { case OpenEXR: foo = essai_openexr(filename, outfile, 0x55); break; + case Geometrie: + foo = essai_geometrie(filename, 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 96a6250..ca5a35e 100644 --- a/funcs/tests.c +++ b/funcs/tests.c @@ -498,7 +498,7 @@ fimg_destroy(&fimg); return 0; } /* --------------------------------------------------------------------- */ -int essai_geometrie(char *infile) +int essai_geometrie(char *infile, int notused) { FloatImg fimg, result; int foo; @@ -516,19 +516,29 @@ else { fimg_draw_something(&fimg); } -foo = fimg_save_as_pnm(&fimg, "source.pnm", 0); +// foo = fimg_save_as_pnm(&fimg, "source.pnm", 0); memset(&result, 0, sizeof(FloatImg)); foo = fimg_halfsize_0(&fimg, &result, 0); -fprintf(stderr, "retour halfsize -> %d\n", foo); +fprintf(stderr, "retour halfsize 0 -> %d\n", foo); if (foo) { return -2; } +if (verbosity) fimg_describe(&result, "result after halfsize 0"); +foo = fimg_save_as_pnm(&result, "halfsize0.pnm", 0); -if (verbosity) fimg_describe(&result, "result after halfsize"); +fimg_destroy(&result); +foo = fimg_halfsize_1(&fimg, &result, 0); +fprintf(stderr, "retour halfsize 1 -> %d\n", foo); +if (foo) { + return -2; + } +if (verbosity) fimg_describe(&result, "result after halfsize 1"); +foo = fimg_save_as_pnm(&result, "halfsize1.pnm", 0); -foo = fimg_save_as_pnm(&result, "something.pnm", 0); +/* hop, un peu de nettoyage */ +fimg_destroy(&result); fimg_destroy(&fimg); return 0; } diff --git a/funcs/tests.h b/funcs/tests.h index 2fb1f09..bc46751 100644 --- a/funcs/tests.h +++ b/funcs/tests.h @@ -19,6 +19,7 @@ int essai_ecriture_tiff(char *infile); int fimg_essai_hsv(char *infile); int essai_classif(char *infile, char *outfile, float fvalue); int essai_contour_2x2(char *filename, char *outfile); +int essai_geometrie(char *infile, int notused); int fimg_essai_histo(FloatImg *src, char *outpic, int k); /* histogram.c */ int essai_histogramme(char *fname, int k);