FloatImg4PythonBinding/funcs/pixelize.c

48 lines
1.0 KiB
C
Raw Normal View History

2021-10-10 23:38:10 +02:00
/*
* 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;
}
/* -------------------------------------------------------------- */
/* -------------------------------------------------------------- */