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"
|
|
|
|
|
2020-10-20 09:09:20 +11:00
|
|
|
extern int verbosity;
|
2020-10-07 20:32:23 +11:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
/* nouveau 4 octobre 2020, juste avant sonoptic de la pluie craignos */
|
|
|
|
|
2020-10-10 21:34:29 +11:00
|
|
|
int fimg_contour_2x2(FloatImg *psrc, FloatImg *pdst, int reverse)
|
2020-10-07 20:32:23 +11:00
|
|
|
{
|
|
|
|
float avg[4];
|
|
|
|
int foo, x, y, q;
|
2020-10-10 21:34:29 +11:00
|
|
|
float v1, v2;
|
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
|
2020-10-10 21:34:29 +11:00
|
|
|
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, psrc, pdst, reverse);
|
2020-10-07 20:32:23 +11:00
|
|
|
#endif
|
|
|
|
|
2020-10-14 19:32:29 +11:00
|
|
|
if (FIMG_TYPE_RGB != psrc->type) {
|
|
|
|
fprintf(stderr, "%s: bad src type %d\n", __func__, psrc->type);
|
|
|
|
return -7;
|
|
|
|
}
|
|
|
|
if (fimg_images_not_compatible(psrc, pdst)) {
|
|
|
|
fprintf(stderr, "%s: bad dst type %d\n", __func__, pdst->type);
|
|
|
|
return -8;
|
|
|
|
}
|
|
|
|
|
2020-10-10 21:34:29 +11:00
|
|
|
if (reverse) {
|
|
|
|
v1 = 0.0; v2 = 1.0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
v1 = 1.0; v2 = 0.0;
|
|
|
|
}
|
|
|
|
|
2020-10-07 20:32:23 +11:00
|
|
|
foo = fimg_meanvalues(psrc, avg);
|
2021-03-09 21:55:48 +11:00
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "%s: err %d on fimg_meanvalues\n", __func__, foo);
|
|
|
|
return foo;
|
|
|
|
}
|
2020-10-30 08:40:00 +11:00
|
|
|
if (verbosity > 1) {
|
2021-03-09 21:55:48 +11:00
|
|
|
fprintf(stderr, "%s: %f %f %f\n", __func__, avg[0], avg[1], avg[2]);
|
2020-10-07 20:32:23 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
#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) ) );
|
2020-10-10 21:34:29 +11:00
|
|
|
pdst->R[(y*psrc->width)+x] = tbl[q] ? v1 : v2 ;
|
2020-10-07 20:32:23 +11:00
|
|
|
|
|
|
|
q = ( ( GP(x, y) << 3 ) |
|
|
|
|
( GP(x+1, y) << 2 ) |
|
|
|
|
( GP(x, y+1) << 1 ) |
|
|
|
|
( GP(x+1, y+1) ) );
|
2020-10-10 21:34:29 +11:00
|
|
|
pdst->G[(y*psrc->width)+x] = tbl[q] ? v1 : v2 ;
|
2020-10-07 20:32:23 +11:00
|
|
|
|
|
|
|
q = ( ( BP(x, y) << 3 ) |
|
|
|
|
( BP(x+1, y) << 2 ) |
|
|
|
|
( BP(x, y+1) << 1 ) |
|
|
|
|
( BP(x+1, y+1) ) );
|
2020-10-10 21:34:29 +11:00
|
|
|
pdst->B[(y*psrc->width)+x] = tbl[q] ? v1 : v2 ;
|
2020-10-07 20:32:23 +11:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-11-02 11:25:00 +11:00
|
|
|
/* kill potential NaN values in last row or last column */
|
|
|
|
fimg_killborders(pdst);
|
|
|
|
|
2020-10-07 20:32:23 +11:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|