From 9bde22f560bb65a7b9503a8a10780d93e024850c Mon Sep 17 00:00:00 2001 From: tth Date: Sun, 10 Oct 2021 23:38:10 +0200 Subject: [PATCH] first version of pixelize_h --- floatimg.h | 3 +++ funcs/Makefile | 5 ++++- funcs/pixelize.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ funcs/t.c | 8 +++++++- funcs/tests.c | 41 ++++++++++++++++++++++++++++++++++++++++- funcs/tests.h | 2 ++ 6 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 funcs/pixelize.c diff --git a/floatimg.h b/floatimg.h index 2521ec2..d4e5cf4 100644 --- a/floatimg.h +++ b/floatimg.h @@ -160,6 +160,9 @@ int fimg_auto_shift_to_zero(FloatImg *s, FloatImg *d); /* --> funcs/plasmas.c */ int fimg_prototype_plasma(FloatImg *img, double time, int type); + +int fimg_pixelize_h_0(FloatImg *psrc, FloatImg *pdst, int k); + /* * * * experimental ! */ int fimg_classif_trial(FloatImg *src, FloatImg*dst, float fval, int notused); int fimg_qsort_rgb_a(FloatImg *psrc, FloatImg *pdst, int notused); diff --git a/funcs/Makefile b/funcs/Makefile index 2252814..e68a7c1 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 + killrgb.o recurse.o pixelize.o #--------------------------------------------------------------- @@ -37,6 +37,9 @@ tests.o: tests.c tests.h $(DEPS) # ### +pixelize.o: pixelize.c $(DEPS) + gcc $(COPT) -c $< + killrgb.o: killrgb.c $(DEPS) gcc $(COPT) -c $< diff --git a/funcs/pixelize.c b/funcs/pixelize.c new file mode 100644 index 0000000..483a4ce --- /dev/null +++ b/funcs/pixelize.c @@ -0,0 +1,47 @@ +/* + * P I X E L I Z E + */ +#include +#include + +#include "../floatimg.h" + +extern int verbosity; + +/* -------------------------------------------------------------- */ +int fimg_pixelize_h_0(FloatImg *psrc, FloatImg *pdst, int k) +{ +int line, col, loop, idx; +float cr, cg, cb; /* cumuls */ + +fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, psrc, pdst, k); + +if (fimg_images_not_compatible(psrc, pdst)) { + fprintf(stderr, "%s: err compatibility\n", __func__); + return -8; + } + +for (line=0; lineheight; line++) { + for (col=0; colwidth; col+=8) { + cr = cg = cb = 0.0; + idx = line * psrc->width + col; + for (loop=0; loop<8; loop++) { + cr += psrc->R[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; + } + } + } + +return 0; +} +/* -------------------------------------------------------------- */ + + + +/* -------------------------------------------------------------- */ diff --git a/funcs/t.c b/funcs/t.c index 56dbf9d..4026dc9 100644 --- a/funcs/t.c +++ b/funcs/t.c @@ -23,7 +23,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, - Geometrie, FileType, Mirror, KillRGB }; + Geometrie, FileType, Mirror, KillRGB, + Pixelize }; typedef struct { char *name; int Cmd; @@ -52,6 +53,7 @@ Command commands[] = { { "filetype", FileType }, { "mirror", Mirror }, { "killrgb", KillRGB }, + { "pixelize", Pixelize }, { NULL, 0 } } ; @@ -220,6 +222,10 @@ switch(opt) { case KillRGB: foo = essai_killrgb(filename, outfile); break; + case Pixelize: + foo = essai_pixelize(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 e5dead9..f134bdb 100644 --- a/funcs/tests.c +++ b/funcs/tests.c @@ -830,7 +830,7 @@ return 0; } /* --------------------------------------------------------------------- */ -int fimg_essai_hsv(char *fname); /* hsv.c */ +int fimg_essai_hsv(char *fname); /* hsv.c */ int essai_histogramme(char *fname, int k) @@ -859,4 +859,43 @@ fprintf(stderr, "\\o/ end of %s\n", __func__); return 0; } /* --------------------------------------------------------------------- */ +/* + * dans la roulotte de terreblanque + */ +int essai_pixelize(char *infile, char *outfile) +{ +FloatImg src, dst; +int foo; + +fprintf(stderr, ">>> %s ( '%s' '%s' )\n", __func__, infile, outfile); + +memset(&src, 0, sizeof(FloatImg)); +foo = fimg_create_from_dump(infile, &src); +if (foo) { + fprintf(stderr, "%s: err load '%s'\n", __func__, infile); + return foo; + } + +memset(&dst, 0, sizeof(FloatImg)); +foo = fimg_clone(&src, &dst, 0); +if (foo) return -888; + +foo = fimg_pixelize_h_0(&src, &dst, 0); +if (foo) { + fprintf(stderr, "in %s, pixelize give us a %d\n", __func__, foo); + return foo; + } + +foo = fimg_export_picture(&dst, outfile, 0); +if (foo) { + fprintf(stderr, "%s : err %d saving result to %s\n", __func__, + foo, outfile); + return foo; + } + +fimg_destroy(&src); +fimg_destroy(&dst); + +return 0; +} /* --------------------------------------------------------------------- */ diff --git a/funcs/tests.h b/funcs/tests.h index 5dbbde4..45ffd7b 100644 --- a/funcs/tests.h +++ b/funcs/tests.h @@ -31,3 +31,5 @@ int essai_lecture_png(char *fname, char *outfile, int notused); int essai_highlights(char *inf, char *outf, int ikoef, float fkoef); int essai_openexr(char *inf, char *outf, int flags); +int essai_pixelize(char *infile, char *outfile); +