first version of pixelize_h

This commit is contained in:
tth 2021-10-10 23:38:10 +02:00
parent f3dc73782a
commit 9bde22f560
6 changed files with 103 additions and 3 deletions

View File

@ -160,6 +160,9 @@ int fimg_auto_shift_to_zero(FloatImg *s, FloatImg *d);
/* --> funcs/plasmas.c */ /* --> funcs/plasmas.c */
int fimg_prototype_plasma(FloatImg *img, double time, int type); int fimg_prototype_plasma(FloatImg *img, double time, int type);
int fimg_pixelize_h_0(FloatImg *psrc, FloatImg *pdst, int k);
/* * * * experimental ! */ /* * * * experimental ! */
int fimg_classif_trial(FloatImg *src, FloatImg*dst, float fval, int notused); 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_a(FloatImg *psrc, FloatImg *pdst, int notused);

View File

@ -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 \ equalize.o fimg-fits.o saturation.o histogram.o \
hsv.o classif.o contour2x2.o qsortrgb.o exporter.o \ hsv.o classif.o contour2x2.o qsortrgb.o exporter.o \
displacement.o dithering.o plasmas.o incrustator.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) killrgb.o: killrgb.c $(DEPS)
gcc $(COPT) -c $< gcc $(COPT) -c $<

47
funcs/pixelize.c Normal file
View File

@ -0,0 +1,47 @@
/*
* P I X E L I Z E
*/
#include <stdio.h>
#include <stdint.h>
#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; line<psrc->height; line++) {
for (col=0; col<psrc->width; 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;
}
/* -------------------------------------------------------------- */
/* -------------------------------------------------------------- */

View File

@ -23,7 +23,8 @@ float global_fvalue;
enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff, enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff,
Histo, Hsv, Classif, Ctr2x2, Qsortrgb, Histo, Hsv, Classif, Ctr2x2, Qsortrgb,
Displace, ReadPNG, Plasmas, Hilight, OpenEXR, Displace, ReadPNG, Plasmas, Hilight, OpenEXR,
Geometrie, FileType, Mirror, KillRGB }; Geometrie, FileType, Mirror, KillRGB,
Pixelize };
typedef struct { typedef struct {
char *name; char *name;
int Cmd; int Cmd;
@ -52,6 +53,7 @@ Command commands[] = {
{ "filetype", FileType }, { "filetype", FileType },
{ "mirror", Mirror }, { "mirror", Mirror },
{ "killrgb", KillRGB }, { "killrgb", KillRGB },
{ "pixelize", Pixelize },
{ NULL, 0 } { NULL, 0 }
} ; } ;
@ -220,6 +222,10 @@ switch(opt) {
case KillRGB: case KillRGB:
foo = essai_killrgb(filename, outfile); foo = essai_killrgb(filename, outfile);
break; break;
case Pixelize:
foo = essai_pixelize(filename, outfile);
break;
default: default:
fprintf(stderr, "'%s' is a bad command\n", command); fprintf(stderr, "'%s' is a bad command\n", command);
exit(1); exit(1);

View File

@ -859,4 +859,43 @@ fprintf(stderr, "\\o/ end of %s\n", __func__);
return 0; 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;
}
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */

View File

@ -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_highlights(char *inf, char *outf, int ikoef, float fkoef);
int essai_openexr(char *inf, char *outf, int flags); int essai_openexr(char *inf, char *outf, int flags);
int essai_pixelize(char *infile, char *outfile);