From 6c92cca12c90704de83246cdba1dc871899d51da Mon Sep 17 00:00:00 2001 From: tth Date: Fri, 15 Oct 2021 23:21:02 +0200 Subject: [PATCH] this is a big mess --- Fonderie/crapulator.c | 79 ++++++++++++++++++++- Fonderie/crapulors.liste | 6 ++ Fonderie/sfx.c | 5 +- experiment/extracteur.c | 2 + experiment/muxplanes.c | 5 +- floatimg.h | 13 +++- funcs/Makefile | 5 +- funcs/decomprgb.c | 149 +++++++++++++++++++++++++++++++++++++++ funcs/fimg-tiff.c | 1 + funcs/pixelize.c | 71 ++++++++++++++++--- funcs/sfx4.c | 31 ++++++++ funcs/t.c | 11 ++- funcs/tests.c | 66 ++++++++++++++++- funcs/tests.h | 2 + funcs/utils.c | 7 ++ 15 files changed, 434 insertions(+), 19 deletions(-) create mode 100644 funcs/decomprgb.c diff --git a/Fonderie/crapulator.c b/Fonderie/crapulator.c index c59519e0..af46fc3b 100644 --- a/Fonderie/crapulator.c +++ b/Fonderie/crapulator.c @@ -102,9 +102,9 @@ FimgFilter3x3 hipass = { FimgFilter3x3 diagonal = { { - 2.0, 1.0, 0.0, + 4.0, 1.0, 0.0, 1.0, 0.0, -1.0, - 0.0, -1.0, -2.0, + 0.0, -1.0, -4.0, }, 1.0, 0.0 }; @@ -168,6 +168,62 @@ fimg_destroy(&tmp); // fprintf(stderr, "%s ---->\n", __func__); +return ret; +} +/* -------------------------------------------------------------- */ +static int run_pixelize_0(FloatImg *img, int k) +{ +FloatImg tmp; +int ret; + +memset(&tmp, 0, sizeof(FloatImg)); +fimg_clone(img, &tmp, 0); +ret = fimg_pixelize_h_0(img, &tmp, k); +fimg_copy_data(&tmp, img); +fimg_destroy(&tmp); + +return ret; +} +/* -------------------------------------------------------------- */ +static int run_pixelize_random(FloatImg *img, int k) +{ +FloatImg tmp; +int ret; + +memset(&tmp, 0, sizeof(FloatImg)); +fimg_clone(img, &tmp, 0); +ret = fimg_pixelize_h_rnd(img, &tmp, k); +fimg_copy_data(&tmp, img); +fimg_destroy(&tmp); + +return ret; +} +/* -------------------------------------------------------------- */ +static int run_decomprgbz_color(FloatImg *img, int k) +{ +FloatImg tmp; +int ret; + +memset(&tmp, 0, sizeof(FloatImg)); +fimg_clone(img, &tmp, 0); +ret = fimg_decomp_rgbz_color(img, &tmp, k); +fimg_copy_data(&tmp, img); +fimg_destroy(&tmp); + +return ret; +} +/* -------------------------------------------------------------- */ +static int run_decomprgbz_gray(FloatImg *img, int k) +{ +FloatImg tmp; +int ret; + +memset(&tmp, 0, sizeof(FloatImg)); +fimg_clone(img, &tmp, 0); +ret = fimg_decomp_rgbz_gray(img, &tmp, k); +fimg_copy_data(&tmp, img); +fimg_destroy(&tmp); + return ret; } /* -------------------------------------------------------------- */ @@ -342,6 +398,25 @@ switch (idFx) { retval = run_killrgb_0(image, 0); break; + case CR_pixelizh: + retval = run_pixelize_0(image, 8); + break; + + case CR_pixelrand: + retval = run_pixelize_random(image, -1); + break; + + case CR_splitlevel: + retval = fimg_split_level(image, image, 0); + break; + + case CR_decrgbzc: + retval = run_decomprgbz_color(image, -1); + break; + case CR_decrgbzg: + retval = run_decomprgbz_gray(image, -1); + break; + case CR_hilightr: retval = fimg_highlight_color(image, image, 'R', 1.717); break; diff --git a/Fonderie/crapulors.liste b/Fonderie/crapulors.liste index 28ae509d..21b6ab98 100644 --- a/Fonderie/crapulors.liste +++ b/Fonderie/crapulors.liste @@ -35,5 +35,11 @@ 42 nothing 42 3.1415926 43 killrgb0 1 9 45 hilightr 1 1.717 +46 pixelizh 1 1.111 +47 pixelizv 1 1.111 +48 pixelrand 1 1 +49 splitlevel 1 1 +50 decrgbzc 1 99 +51 decrgbzg 1 99 99 message 1 1.0 -1 end 1 1.0 diff --git a/Fonderie/sfx.c b/Fonderie/sfx.c index d9de7c56..dc7efdad 100644 --- a/Fonderie/sfx.c +++ b/Fonderie/sfx.c @@ -47,6 +47,9 @@ return -1; } /* -------------------------------------------------------------- */ /* nouveau du premier dimanche de 2020 'nextgen' */ + +/* CE TRUC NE MARCHE PAS COMME PRÉVU */ + static int pixel_trinitron(FloatImg *pimg, int pos[4], float *fvals) { int x, y, pline, off; @@ -65,7 +68,7 @@ return 0; } /* - * need more explanation, need more worg + * need more explanation, need more work */ int trinitron(FloatImg *pimg, int notused) { diff --git a/experiment/extracteur.c b/experiment/extracteur.c index a1f8e3b2..83fa278a 100644 --- a/experiment/extracteur.c +++ b/experiment/extracteur.c @@ -66,6 +66,8 @@ for (foo=0; foo %s\n", fr, fg, fb, dst); +fprintf(stderr, "muxing: %s %s %s -> %s\n", fr, fg, fb, dst); foo = fimg_create_from_dump(fr, &imr); if (foo) { @@ -82,7 +82,8 @@ int main(int argc, char *argv[]) int foo; if (5 != argc) { - fprintf(stderr, "ERROR: %s need four fimg files arguments\n", argv[0]); + fprintf(stderr, "ERROR: %s need four fimg files arguments\n", + argv[0]); return 1; } diff --git a/floatimg.h b/floatimg.h index d4e5cf44..5aec108b 100644 --- a/floatimg.h +++ b/floatimg.h @@ -4,7 +4,7 @@ * http://la.buvette.org/photos/cumul */ -#define FIMG_VERSION 155 +#define FIMG_VERSION 157 /* * in memory descriptor @@ -28,6 +28,9 @@ typedef struct { char magic[8]; int32_t w, h, t; } FimgFileHead; +/* + * we MUST look at packing and endianess problems NOW */ + #define MAGIC_AREA51 0xA5EA0051 typedef struct { @@ -128,12 +131,15 @@ int fimg_crump_hard(FloatImg *src, FloatImg *dst, float kval, int notused); /* module sfx4.c */ int fimg_sfx_triplemul(FloatImg *s, FloatImg *d, int notused); +int fimg_split_level(FloatImg *src, FloatImg *dst, int notused); /* funcs/rotate.c module */ /* #coronamaison */ int fimg_rotate_90(FloatImg *src, FloatImg *dst, int notused); int fimg_killrgb_v(FloatImg *src, FloatImg *dst, int k); +int fimg_decomp_rgbz_color(FloatImg *psrc, FloatImg *pdst, int k); +int fimg_decomp_rgbz_gray(FloatImg *psrc, FloatImg *pdst, int k); /* universal exporter XXX */ int fimg_export_picture(FloatImg *pic, char *fname, int flags); @@ -160,8 +166,10 @@ int fimg_auto_shift_to_zero(FloatImg *s, FloatImg *d); /* --> funcs/plasmas.c */ int fimg_prototype_plasma(FloatImg *img, double time, int type); - +/* --> funcs/pixelize.c + voir fimg_pixelize_h_rnd() */ int fimg_pixelize_h_0(FloatImg *psrc, FloatImg *pdst, int k); +int fimg_pixelize_h_rnd(FloatImg *psrc, FloatImg *pdst, int largeur); /* * * * experimental ! */ int fimg_classif_trial(FloatImg *src, FloatImg*dst, float fval, int notused); @@ -234,6 +242,7 @@ int fimg_multirandom(FloatImg *fimg, long nbpass); void fimg_print_minmax(float minmax[6], char *titre); int parse_WxH(char *str, int *pw, int *ph); int parse_double(char *str, double *dptr); +int irand2(int offset, int modulo); int print_rectangle(char *str, FimgArea51 *rect); int parse_rectangle(char *str, FimgArea51 *r, int notused); int format_from_extension(char *fname); diff --git a/funcs/Makefile b/funcs/Makefile index e68a7c15..cc665229 100644 --- a/funcs/Makefile +++ b/funcs/Makefile @@ -13,7 +13,7 @@ OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \ equalize.o fimg-fits.o saturation.o histogram.o \ hsv.o classif.o contour2x2.o qsortrgb.o exporter.o \ displacement.o dithering.o plasmas.o incrustator.o \ - killrgb.o recurse.o pixelize.o + killrgb.o recurse.o pixelize.o decomprgb.o #--------------------------------------------------------------- @@ -37,6 +37,9 @@ tests.o: tests.c tests.h $(DEPS) # ### +decomprgb.o: decomprgb.c $(DEPS) + gcc $(COPT) -c $< + pixelize.o: pixelize.c $(DEPS) gcc $(COPT) -c $< diff --git a/funcs/decomprgb.c b/funcs/decomprgb.c new file mode 100644 index 00000000..58ef5343 --- /dev/null +++ b/funcs/decomprgb.c @@ -0,0 +1,149 @@ +/* + * DECOMPOSITION RGB + */ + +#include +#include + +#include "../floatimg.h" + +extern int verbosity; + +/* == ---------------------------------------------------- == */ + +/* some dirty macros */ + +#define pixidx(fi,x,y) (((y)*fi->width)+(x)) + +#define getRpix(fi,x,y) (fi->R[ pixidx(fi,(x),(y)) ]) +#define getGpix(fi,x,y) (fi->G[ pixidx(fi,(x),(y)) ]) +#define getBpix(fi,x,y) (fi->B[ pixidx(fi,(x),(y)) ]) + +/* A lot of strange and usefull parenthesis */ + +/* == ---------------------------------------------------- == */ + +static float compute_z_value(float r, float g, float b) +{ +double dval; + + + +return 42.0; +} +/* == ---------------------------------------------------- == */ + +int fimg_decomp_rgbz_color(FloatImg *psrc, FloatImg *pdst, int k) +{ +int x, y, x2, y2; +int w2, h2, idx; +float cumul, vgray; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, + psrc, pdst, k); +#endif + +fimg_clear(pdst); + +w2 = psrc->width/2; h2 = psrc->height/2; + +for (y=0; yR[pixidx(pdst,x,y)] = cumul; + + cumul = getGpix(psrc, x2, y2) + + getGpix(psrc, x2, y2+1) + + getGpix(psrc, x2+1, y2) + + getGpix(psrc, x2+1, y2+1); + cumul /= 4, vgray += cumul; + pdst->G[pixidx(pdst,x+w2,y)] = cumul; + + cumul = getBpix(psrc, x2, y2) + + getBpix(psrc, x2, y2+1) + + getBpix(psrc, x2+1, y2) + + getBpix(psrc, x2+1, y2+1); + cumul /= 4, vgray += cumul; + pdst->B[pixidx(pdst,x,y+h2)] = cumul; + + idx = pixidx(pdst,x+w2,y+h2); + pdst->R[idx] = pdst->G[idx] = \ + pdst->B[idx] = vgray / 3.0; + } + + } + + +return 0; +} + +/* == ---------------------------------------------------- == */ + + /* PUTAIN LE COPIER/COLLÉ DE BATARD !!! */ + +int fimg_decomp_rgbz_gray(FloatImg *psrc, FloatImg *pdst, int k) +{ +int x, y, x2, y2; +int w2, h2, idx; +float cumul, vgray; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, + psrc, pdst, k); +#endif + +fimg_clear(pdst); + +w2 = psrc->width/2; h2 = psrc->height/2; + +for (y=0; yR[idx] = pdst->G[idx] = pdst->B[idx] = cumul; + + cumul = getGpix(psrc, x2, y2) + + getGpix(psrc, x2, y2+1) + + getGpix(psrc, x2+1, y2) + + getGpix(psrc, x2+1, y2+1); + cumul /= 4, vgray += cumul; + idx = pixidx(pdst,x+w2,y); + pdst->R[idx] = pdst->G[idx] = pdst->B[idx] = cumul; + + cumul = getBpix(psrc, x2, y2) + + getBpix(psrc, x2, y2+1) + + getBpix(psrc, x2+1, y2) + + getBpix(psrc, x2+1, y2+1); + cumul /= 4, vgray += cumul; + idx = pixidx(pdst,x,y+h2); + pdst->R[idx] = pdst->G[idx] = pdst->B[idx] = cumul; + + idx = pixidx(pdst,x+w2,y+h2); + pdst->R[idx] = pdst->G[idx] = \ + pdst->B[idx] = vgray / 3.0; + } + + } + + +return 0; +} + +/* == ---------------------------------------------------- == */ diff --git a/funcs/fimg-tiff.c b/funcs/fimg-tiff.c index 355b2ee2..6cd0721c 100644 --- a/funcs/fimg-tiff.c +++ b/funcs/fimg-tiff.c @@ -44,6 +44,7 @@ if (verbosity) { tiff = TIFFOpen(fname, "w"); if (NULL==tiff) { + fprintf(stderr, "erreur TIFFOpen\n"); return -6; } diff --git a/funcs/pixelize.c b/funcs/pixelize.c index 483a4ceb..fa9fc27b 100644 --- a/funcs/pixelize.c +++ b/funcs/pixelize.c @@ -3,37 +3,52 @@ */ #include #include +#include #include "../floatimg.h" extern int verbosity; /* -------------------------------------------------------------- */ -int fimg_pixelize_h_0(FloatImg *psrc, FloatImg *pdst, int k) +/* nouveau 10 octobre 2021 dans la roulotte de Terreblanque */ + +#define LARGEUR 16 + +int fimg_pixelize_h_0(FloatImg *psrc, FloatImg *pdst, int largeur) { int line, col, loop, idx; float cr, cg, cb; /* cumuls */ -fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, psrc, pdst, k); +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, psrc, pdst, largeur); +#endif if (fimg_images_not_compatible(psrc, pdst)) { fprintf(stderr, "%s: err compatibility\n", __func__); return -8; } +switch(largeur) { + case 8: case 16: case 32: + break; + default: + fprintf(stderr, "pixeliz bad width %d\n", largeur); + return -77; + } + for (line=0; lineheight; line++) { - for (col=0; colwidth; col+=8) { + for (col=0; colwidth; col+=largeur) { cr = cg = cb = 0.0; idx = line * psrc->width + col; - for (loop=0; loop<8; loop++) { + for (loop=0; loopR[idx+loop]; cg += psrc->G[idx+loop]; cb += psrc->B[idx+loop]; } - for (loop=0; loop<8; loop++) { - pdst->R[idx+loop] = cr / 8.0; - pdst->G[idx+loop] = cg / 8.0; - pdst->B[idx+loop] = cb / 8.0; + for (loop=0; loopR[idx+loop] = cr / (float)largeur; + pdst->G[idx+loop] = cg / (float)largeur; + pdst->B[idx+loop] = cb / (float)largeur; } } } @@ -41,7 +56,47 @@ for (line=0; lineheight; line++) { return 0; } /* -------------------------------------------------------------- */ +/* + * un essai dans la roulotte :) + * 11 oct 2021 : premier jet, essai concluant, mais nécessite + * du travail sur les rand() pour être plus 'noisy' + * + */ +int fimg_pixelize_h_rnd(FloatImg *psrc, FloatImg *pdst, int largeur) +{ +static int count = 0; +static int flag = 0; +int foo; +if (0==count) { + if (flag) { + count = irand2(5, 10); + flag = ! flag; + } + else { + count = irand2(20, 40); + flag = ! flag; + } + if (verbosity) { + fprintf(stderr, "%s c=%d f=%c\n", __func__, + count, flag?'T':'F'); + } + } + +if (verbosity) { + fprintf(stderr, "%s: count=%d flag=%d\n", __func__, count, flag); + } + +foo = fimg_pixelize_h_0(psrc, pdst, flag ? 8 : 32); +if (foo) { + fprintf(stderr, "PANIC in %s\n", __func__); + abort(); + } + +count--; /* nice trick bro */ + +return 0; +} /* -------------------------------------------------------------- */ diff --git a/funcs/sfx4.c b/funcs/sfx4.c index 717b15ff..c21883a5 100644 --- a/funcs/sfx4.c +++ b/funcs/sfx4.c @@ -40,5 +40,36 @@ for (y=0; yheight; y++) { return 0; } /* -------------------------------------------------------------- */ +/* + * see also: + sfx3.c:fimg_crump_hard() +*/ +int fimg_split_level(FloatImg *src, FloatImg *dst, int notused) +{ +float means[4]; +float in[3], out[3]; +int foo, idx, surface; +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %p %p 0x%04x )\n", __func__, src, dst, notused); +#endif + +foo = fimg_meanvalues(src, means); +if (foo) { + return -66; + } + +surface = src->width*src->height; +for(idx=0; idxR[idx]R[idx]=src->R[idx]*2.0; + else dst->R[idx]=(src->R[idx]-means[0])*2.0; + if (src->G[idx]G[idx]=src->G[idx]*2.0; + else dst->G[idx]=(src->G[idx]-means[1])*2.0; + if (src->B[idx]B[idx]=src->B[idx]*2.0; + else dst->B[idx]=(src->B[idx]-means[2])*2.0; + } + +return 0; +} +/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */ diff --git a/funcs/t.c b/funcs/t.c index 4026dc93..58826467 100644 --- a/funcs/t.c +++ b/funcs/t.c @@ -24,7 +24,7 @@ enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff, Histo, Hsv, Classif, Ctr2x2, Qsortrgb, Displace, ReadPNG, Plasmas, Hilight, OpenEXR, Geometrie, FileType, Mirror, KillRGB, - Pixelize }; + Pixelize,SplitLevel,DecompRgbz }; typedef struct { char *name; int Cmd; @@ -54,6 +54,8 @@ Command commands[] = { { "mirror", Mirror }, { "killrgb", KillRGB }, { "pixelize", Pixelize }, + { "spltlvl", SplitLevel }, + { "decomprgbz", DecompRgbz }, { NULL, 0 } } ; @@ -225,7 +227,12 @@ switch(opt) { case Pixelize: foo = essai_pixelize(filename, outfile); break; - + case SplitLevel: + foo = essai_split_level(filename, outfile, 0); + break; + case DecompRgbz: + foo = essai_decomprgb(filename, outfile); + break; default: fprintf(stderr, "'%s' is a bad command\n", command); exit(1); diff --git a/funcs/tests.c b/funcs/tests.c index 91d49672..eaee9a05 100644 --- a/funcs/tests.c +++ b/funcs/tests.c @@ -46,6 +46,40 @@ if (foo) { return foo; } +return 0; +} +/* --------------------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ +int essai_decomprgb(char *inf, char *outf) +{ +int foo; +FloatImg src, dst; + +fprintf(stderr, ">>> %s ( %s %s )\n", __func__, inf, outf); + +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, 1); + +foo = fimg_decomp_rgbz_gray(&src, &dst, 0); +if (foo) { + fprintf(stderr, "%s:%s(): fail %d line %d\n", + __FILE__, __func__, foo, __LINE__); + return foo; + } + +foo = fimg_export_picture(&dst, outf, 0); +if (foo) { + fprintf(stderr, "%s : err %d saving result\n", __func__, foo); + return foo; + } + +fimg_destroy(&src); fimg_destroy(&dst); + return 0; } /* --------------------------------------------------------------------- */ @@ -104,7 +138,7 @@ 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); + fprintf(stderr, "err %d in fimg_mirror\n", foo); return -6; } @@ -114,6 +148,36 @@ if (foo) { return foo; } +return 0; +} +/* --------------------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ +int essai_split_level(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); +foo = fimg_split_level(&src, &dst, 0); +if (foo) { + fprintf(stderr, "err %d in split_level\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 0; } /* --------------------------------------------------------------------- */ diff --git a/funcs/tests.h b/funcs/tests.h index 45ffd7b3..ef196d07 100644 --- a/funcs/tests.h +++ b/funcs/tests.h @@ -6,6 +6,8 @@ int essai_plasma(char *infile, char *outfile, int ikoef, float fkoef); int essai_miroir(char *inf, char *outf, int flags); int essai_killrgb(char *inf, char *outf); +int essai_decomprgb(char *inf, char *outf); +int essai_split_level(char *inf, char *outf, int flags); int essai_displacement(char *infile, char *outfile); int essai_qsort_rgb(char *infile, char *outfile); diff --git a/funcs/utils.c b/funcs/utils.c index 2e3c945b..3fe60e49 100644 --- a/funcs/utils.c +++ b/funcs/utils.c @@ -3,6 +3,7 @@ */ #include +#include #include #include @@ -53,6 +54,12 @@ if (1 == foo) { return -1; } /* --------------------------------------------------------------------- */ +/* new Mon 11 Oct 2021 08:28:27 PM CEST */ +int irand2(int offset, int modulo) +{ +return offset + (rand() % modulo); +} +/* --------------------------------------------------------------------- */ int file_type_from_name(char *name) {