2019-03-04 02:22:55 +11:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <float.h>
|
|
|
|
|
2019-03-07 04:07:23 +11:00
|
|
|
#include "../floatimg.h"
|
2019-03-04 02:22:55 +11:00
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
int fimg_lissage_2x2(FloatImg *img)
|
|
|
|
{
|
2019-05-20 17:47:13 +11:00
|
|
|
int x, y, offset;
|
2020-02-26 10:14:47 +11:00
|
|
|
float cr, cg, cb;
|
|
|
|
float *pr, *pg, *pb;
|
2019-03-04 02:22:55 +11:00
|
|
|
|
2019-05-20 17:47:13 +11:00
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( %p )\n", __func__, img);
|
2020-01-04 01:30:47 +11:00
|
|
|
fprintf(stderr," type %d size %dx%d\n", img->type,
|
2019-05-20 17:47:13 +11:00
|
|
|
img->width, img->height);
|
|
|
|
#endif
|
|
|
|
|
2020-02-27 21:25:30 +11:00
|
|
|
if (img->type != FIMG_TYPE_RGB) {
|
|
|
|
fprintf(stderr, "%s : type %d invalide\n", __func__, img->type);
|
|
|
|
return -99;
|
|
|
|
}
|
|
|
|
|
2020-02-26 10:14:47 +11:00
|
|
|
pr = img->R; pg = img->G; pb = img->B;
|
2019-05-20 17:47:13 +11:00
|
|
|
|
2020-02-26 10:14:47 +11:00
|
|
|
for (y=1; y < img->height-1; y++) {
|
|
|
|
|
|
|
|
for (x=1; x < img->width-1; x++) {
|
2019-05-20 17:47:13 +11:00
|
|
|
|
|
|
|
offset = x + (y * img->width);
|
|
|
|
|
2020-02-26 10:14:47 +11:00
|
|
|
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;
|
|
|
|
|
2019-05-20 17:47:13 +11:00
|
|
|
}
|
|
|
|
}
|
2019-03-04 02:22:55 +11:00
|
|
|
|
2020-02-26 10:14:47 +11:00
|
|
|
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
|
|
|
|
|
2020-02-27 21:25:30 +11:00
|
|
|
if (img->type != FIMG_TYPE_RGB) {
|
|
|
|
fprintf(stderr, "%s : type %d invalide\n", __func__, img->type);
|
|
|
|
return -99;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-26 10:14:47 +11:00
|
|
|
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
|
|
|
|
}
|
2019-03-04 02:22:55 +11:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|