tracking a math bug in filters3x3

This commit is contained in:
tth 2021-02-23 03:49:24 +01:00
parent c6f10d642a
commit d867b905a8
4 changed files with 41 additions and 19 deletions

View File

@ -14,6 +14,8 @@
#include "glitches.h"
#include "sfx.h"
extern int verbosity;
/* -------------------------------------------------------------- */
static int trier_les_pixels(FloatImg *pimg)
{
@ -76,7 +78,7 @@ return 0;
static int insitu_filtre3x3(FloatImg *pimg, int typef)
{
FloatImg img;
int retval;
int foo, retval;
FimgFilter3x3 *pfiltre;
FimgFilter3x3 lowpass = {
@ -103,7 +105,7 @@ FimgFilter3x3 diagonal = {
1.0, 0.0, -1.0,
0.0, -1.0, -2.0,
},
1.0, 0.0
1.0, 4.0
};
switch (typef) {
@ -124,8 +126,12 @@ if (retval) {
fprintf(stderr, "%s error %d on filter\n", __func__, retval);
exit(1);
}
/*
* may be, here, we can check for negative values ? */
/** may be, we can check for negative values ? */
if (verbosity) {
foo = fimg_count_negativ(&img);
fprintf(stderr, "%s -> %d negs\n", __func__, foo);
}
fimg_killborders(&img);
fimg_copy_data(&img, pimg);
fimg_destroy(&img);
@ -206,7 +212,7 @@ switch (idFx) {
break;
case CR_liss2x2:
retval = fimg_lissage_2x2(image);
(void)fimg_killborders(image);
// (void)fimg_killborders(image);
break;
case CR_liss3x3:
/* smooth filter */

View File

@ -3,7 +3,7 @@
* ugly code from tTh
*/
#define FIMG_VERSION 118
#define FIMG_VERSION 119
/*
* in memory descriptor

View File

@ -48,7 +48,7 @@ for (y=1; y < h-1; y++) {
M[7] * pr[of+w] +
M[8] * pr[of+(w-1)] ;
dst->R[of] = dval;
dst->R[of] = dval + filtr->offset;
dval = M[0] * pg[of-(w+1)] +
M[1] * pg[of-w] +
@ -60,7 +60,7 @@ for (y=1; y < h-1; y++) {
M[7] * pg[of+w] +
M[8] * pg[of+(w-1)] ;
dst->G[of] = dval;
dst->G[of] = dval + filtr->offset;
dval = M[0] * pb[of-(w+1)] +
M[1] * pb[of-w] +
@ -72,7 +72,7 @@ for (y=1; y < h-1; y++) {
M[7] * pb[of+w] +
M[8] * pb[of+(w-1)] ;
dst->B[of] = dval;
dst->B[of] = dval + filtr->offset;
}
}
@ -189,7 +189,6 @@ if (foo) {
return foo;
}
/* XXX */
fimg_killborders(img);
return foo;

View File

@ -323,7 +323,7 @@ FimgFilter3x3 filter_a = {
{ 1.0, 1.0, 1.0,
1.0, -3.0, 1.0,
1.0, 1.0, 1.0 },
8.0, 0.0
9.0, 0.0
};
@ -336,6 +336,15 @@ FimgFilter3x3 filter_b = {
};
FimgFilter3x3 filter_c = {
{
2.0, 1.0, 0.0,
1.0, 0.0, -1.0,
0.0, -1.0, -2.0,
},
1.0, 8.0
};
if (NULL != infile) {
fprintf(stderr, "%s: loading %s\n", __func__, infile);
foo = fimg_create_from_dump(infile, &src);
@ -351,6 +360,8 @@ else {
}
// fimg_save_as_png(&src, "test.png", 0);
foo = fimg_count_negativ(&src);
fprintf(stderr, "%s: source have %d negs\n", __func__, foo);
foo = fimg_clone(&src, &dst, 0);
if (foo) {
@ -359,21 +370,27 @@ if (foo) {
}
fimg_filter_3x3(&src, &dst, &filter_a);
foo = fimg_clamp_negativ(&dst);
if (foo) {
fprintf(stderr, "clamped %d negative pixels\n", foo);
fprintf(stderr, "A clamped %d negative pixels\n", foo);
}
// foo = fimg_save_as_png(&dst, "f3x3a.png", 0);
foo = fimg_save_as_png(&dst, "f3x3a.png", 0);
// foo = fimg_save_as_pnm(&dst, "f3x3a.pnm", 0);
fimg_filter_3x3(&src, &dst, &filter_b);
foo = fimg_clamp_negativ(&dst);
if (foo) {
fprintf(stderr, "clamped %d negative pixels\n", foo);
fprintf(stderr, "B clamped %d negative pixels\n", foo);
}
// foo = fimg_save_as_png(&dst, "f3x3b.png", 0);
foo = fimg_save_as_png(&dst, "f3x3b.png", 0);
// foo = fimg_save_as_pnm(&dst, "f3x3a.pnm", 0);
fimg_filter_3x3(&src, &dst, &filter_c);
foo = fimg_clamp_negativ(&dst);
if (foo) {
fprintf(stderr, "C clamped %d negative pixels\n", foo);
}
foo = fimg_save_as_png(&dst, "f3x3b.png", 0);
// foo = fimg_save_as_pnm(&dst, "f3x3a.pnm", 0);
fimg_destroy(&src); fimg_destroy(&dst);