FloatImg/funcs/contour2x2.c

72 lines
1.6 KiB
C
Raw Normal View History

2020-10-07 20:32:23 +11:00
/*
* classif.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "../floatimg.h"
int verbosity;
/* --------------------------------------------------------------------- */
/* nouveau 4 octobre 2020, juste avant sonoptic de la pluie craignos */
int fimg_contour_2x2(FloatImg *psrc, FloatImg *pdst, int notused)
{
float avg[4];
int foo, x, y, q;
2020-10-09 10:26:07 +11:00
int tbl[] = /* deep magic inside */
2020-10-07 20:32:23 +11:00
{
0, 1, 1, 1,
1, 1, 0, 1,
1, 0, 1, 1,
1, 1, 1, 0
};
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, psrc, pdst, notused);
#endif
foo = fimg_meanvalues(psrc, avg);
if (verbosity) {
fprintf(stderr, "mean values : %f %f %f\n", avg[0], avg[1], avg[2]);
}
#define RP(ix, iy) ( psrc->R[((iy)*psrc->width)+(ix)] < avg[0] )
#define GP(ix, iy) ( psrc->G[((iy)*psrc->width)+(ix)] < avg[1] )
#define BP(ix, iy) ( psrc->B[((iy)*psrc->width)+(ix)] < avg[2] )
for (y=0; y<psrc->height-1; y++) {
for (x=0; x<psrc->width-1; x++) {
q = ( ( RP(x, y) << 3 ) |
( RP(x+1, y) << 2 ) |
( RP(x, y+1) << 1 ) |
( RP(x+1, y+1) ) );
pdst->R[(y*psrc->width)+x] = tbl[q] ? 1.0 : 0.0 ;
q = ( ( GP(x, y) << 3 ) |
( GP(x+1, y) << 2 ) |
( GP(x, y+1) << 1 ) |
( GP(x+1, y+1) ) );
pdst->G[(y*psrc->width)+x] = tbl[q] ? 1.0 : 0.0 ;
q = ( ( BP(x, y) << 3 ) |
( BP(x+1, y) << 2 ) |
( BP(x, y+1) << 1 ) |
( BP(x+1, y+1) ) );
pdst->B[(y*psrc->width)+x] = tbl[q] ? 1.0 : 0.0 ;
}
}
return 0;
}
/* --------------------------------------------------------------------- */