FloatImg4PythonBinding/funcs/filtrage.c

97 lines
1.9 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <float.h>
#include "../floatimg.h"
/* -------------------------------------------------------------------- */
int fimg_lissage_2x2(FloatImg *img)
{
int x, y, offset;
float cr, cg, cb;
float *pr, *pg, *pb;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p )\n", __func__, img);
fprintf(stderr," type %d size %dx%d\n", img->type,
img->width, img->height);
#endif
pr = img->R; pg = img->G; pb = img->B;
for (y=1; y < img->height-1; y++) {
for (x=1; x < img->width-1; x++) {
offset = x + (y * img->width);
cr = pr[offset] + pr[offset+1] +
pr[offset+img->width] + pr[offset+img->width+1];
cg = pg[offset] + pg[offset+1] +
pg[offset+img->width] + pg[offset+img->width+1];
cb = pb[offset] + pb[offset+1] +
pb[offset+img->width] + pb[offset+img->width+1];
pr[offset] = cr / 4.0;
pg[offset] = cg / 4.0;
pb[offset] = cb / 4.0;
}
}
return 0;
}
/* -------------------------------------------------------------------- */
int fimg_killborders(FloatImg *img)
{
int idx, h, w, o;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p )\n", __func__, img);
fprintf(stderr," type %d size %dx%d\n", img->type,
img->width, img->height);
#endif
h = img->height; w = img->width;
for (idx=0; idx<h; idx++) {
#define FAST 1
#if FAST
img->R[idx*w] = 0.0;
img->G[idx*w] = 0.0;
img->B[idx*w] = 0.0;
img->R[(idx*w)+w-1] = 0.0;
img->G[(idx*w)+w-1] = 0.0;
img->B[(idx*w)+w-1] = 0.0;
#else
fimg_plot_rgb(img, 0, idx, 0.0, 0.0, 0.0);
fimg_plot_rgb(img, w-1, idx, 0.0, 0.0, 0.0);
#endif
}
o = w * (h - 1);
for (idx=0; idx<w; idx++) {
#if FAST
img->R[idx] = 0.0;
img->G[idx] = 0.0;
img->B[idx] = 0.0;
img->R[idx+o] = 0.0;
img->G[idx+o] = 0.0;
img->B[idx+o] = 0.0;
#else
fimg_plot_rgb(img, idx, 0, 0.0, 0.0, 0.0);
fimg_plot_rgb(img, idx, h-1, 0.0, 0.0, 0.0);
#endif
}
return -1;
}
/* -------------------------------------------------------------------- */