FloatImg/funcs/pixelize.c

102 lines
2.2 KiB
C
Raw Normal View History

2021-10-11 08:38:10 +11:00
/*
* P I X E L I Z E
*/
#include <stdio.h>
#include <stdint.h>
2021-10-16 08:21:02 +11:00
#include <stdlib.h>
2021-10-11 08:38:10 +11:00
#include "../floatimg.h"
extern int verbosity;
/* -------------------------------------------------------------- */
2021-10-16 08:21:02 +11:00
/* nouveau 10 octobre 2021 dans la roulotte de Terreblanque */
#define LARGEUR 16
int fimg_pixelize_h_0(FloatImg *psrc, FloatImg *pdst, int largeur)
2021-10-11 08:38:10 +11:00
{
int line, col, loop, idx;
float cr, cg, cb; /* cumuls */
2021-10-16 08:21:02 +11:00
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, psrc, pdst, largeur);
#endif
2021-10-11 08:38:10 +11:00
if (fimg_images_not_compatible(psrc, pdst)) {
fprintf(stderr, "%s: err compatibility\n", __func__);
return -8;
}
2021-10-16 08:21:02 +11:00
switch(largeur) {
case 8: case 16: case 32:
break;
default:
2023-02-14 03:56:08 +11:00
fprintf(stderr, "%s: bad width %d\n", __func__, largeur);
2021-10-16 08:21:02 +11:00
return -77;
}
2021-10-11 08:38:10 +11:00
for (line=0; line<psrc->height; line++) {
2021-10-16 08:21:02 +11:00
for (col=0; col<psrc->width; col+=largeur) {
2021-10-11 08:38:10 +11:00
cr = cg = cb = 0.0;
idx = line * psrc->width + col;
2021-10-16 08:21:02 +11:00
for (loop=0; loop<largeur; loop++) {
2021-10-11 08:38:10 +11:00
cr += psrc->R[idx+loop];
cg += psrc->G[idx+loop];
cb += psrc->B[idx+loop];
}
2021-10-16 08:21:02 +11:00
for (loop=0; loop<largeur; loop++) {
pdst->R[idx+loop] = cr / (float)largeur;
pdst->G[idx+loop] = cg / (float)largeur;
pdst->B[idx+loop] = cb / (float)largeur;
2021-10-11 08:38:10 +11:00
}
}
}
return 0;
}
/* -------------------------------------------------------------- */
2021-10-16 08:21:02 +11:00
/*
* un essai dans la roulotte :)
2022-07-06 19:27:55 +11:00
* 11 oct 2021 : premier jet, essai concluant, mais necessite
* du travail sur les rand() pour etre plus 'noisy'
2021-10-16 08:21:02 +11:00
*
*/
int fimg_pixelize_h_rnd(FloatImg *psrc, FloatImg *pdst, int largeur)
{
static int count = 0;
static int flag = 0;
int foo;
2021-10-11 08:38:10 +11:00
2022-07-06 19:27:55 +11:00
/* may be a mollyguard on 'largeur' parameter ? */
2021-10-16 08:21:02 +11:00
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);
}
2022-07-06 19:27:55 +11:00
foo = fimg_pixelize_h_0(psrc, pdst, flag ? largeur : 32);
2021-10-16 08:21:02 +11:00
if (foo) {
2023-02-12 05:23:43 +11:00
fprintf(stderr, "pixelize_h_0 give err %d in %s\n", foo, __func__);
2021-10-16 08:21:02 +11:00
}
count--; /* nice trick bro */
return 0;
}
2021-10-11 08:38:10 +11:00
/* -------------------------------------------------------------- */