Zzzzz....

This commit is contained in:
2020-02-29 21:59:12 +01:00
parent f9467dacee
commit 248061f46b
5 changed files with 249 additions and 20 deletions

View File

@@ -7,7 +7,75 @@
#include "../floatimg.h"
/* -------------------------------------------------------------------- */
int fimg_lissage_2x2(FloatImg *img)
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
int fimg_filter_3x3(FloatImg *src, FloatImg *dst, FimgFilter3x3 *filtr)
{
int x, y, w, h, of;
float *pr, *pg, *pb; /* alias for src pix filds */
float *M; /* alias of filter matrix */
double dval;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %p)\n", __func__, s, d, filtr);
#endif
/* aliasing some vars for cleaner code */
pr = src->R; pg = src->G; pb = src->B;
w = src->width; h = src->height;
M = filtr->matrix;
for (y=1; y < h-1; y++) {
for (x=1; x < w-1; x++) {
of = x + (y * w);
dval = M[0] * pr[of-(w+1)] +
M[1] * pr[of-w] +
M[2] * pr[of-(w-1)] +
M[3] * pr[of-1] +
M[4] * pr[of] +
M[5] * pr[of+1] +
M[6] * pr[of+(w+1)] +
M[7] * pr[of+w] +
M[8] * pr[of+(w-1)] ;
dst->R[of] = dval;
dval = M[0] * pg[of-(w+1)] +
M[1] * pg[of-w] +
M[2] * pg[of-(w-1)] +
M[3] * pg[of-1] +
M[4] * pg[of] +
M[5] * pg[of+1] +
M[6] * pg[of+(w+1)] +
M[7] * pg[of+w] +
M[8] * pg[of+(w-1)] ;
dst->G[of] = dval;
dval = M[0] * pb[of-(w+1)] +
M[1] * pb[of-w] +
M[2] * pb[of-(w-1)] +
M[3] * pb[of-1] +
M[4] * pb[of] +
M[5] * pb[of+1] +
M[6] * pb[of+(w+1)] +
M[7] * pb[of+w] +
M[8] * pb[of+(w-1)] ;
dst->B[of] = dval;
}
}
return -1;
}
/* -------------------------------------------------------------------- */
/*
* this is the more shifting hack on the block.
*/
static int fimg_lissage_2x2_a(FloatImg *img)
{
int x, y, offset;
float cr, cg, cb;
@@ -66,7 +134,6 @@ if (img->type != FIMG_TYPE_RGB) {
return -99;
}
h = img->height; w = img->width;
for (idx=0; idx<h; idx++) {
@@ -104,4 +171,20 @@ for (idx=0; idx<w; idx++) {
return -1;
}
/* -------------------------------------------------------------------- */
int fimg_lissage_2x2(FloatImg *img)
{
int foo;
foo = fimg_lissage_2x2_a(img);
if (foo) {
fprintf(stderr, "%s: fail %d\n", __func__, foo);
return foo;
}
/* XXX */
fimg_killborders(img);
return foo;
}
/* -------------------------------------------------------------------- */