Browse Source

tracking a math bug in filters3x3

master
tth 1 year ago
parent
commit
d867b905a8
  1. 16
      Fonderie/crapulator.c
  2. 2
      floatimg.h
  3. 9
      funcs/filtrage.c
  4. 33
      funcs/tests.c

16
Fonderie/crapulator.c

@ -14,6 +14,8 @@ @@ -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; @@ -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 = { @@ -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) { @@ -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) { @@ -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 */

2
floatimg.h

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

9
funcs/filtrage.c

@ -15,7 +15,7 @@ float *M; /* alias of filter matrix */ @@ -15,7 +15,7 @@ float *M; /* alias of filter matrix */
double dval;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %p)\n", __func__, src, dst, filtr);
fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, src, dst, filtr);
#endif
if (src->type != FIMG_TYPE_RGB) {
@ -48,7 +48,7 @@ for (y=1; y < h-1; y++) { @@ -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++) { @@ -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++) { @@ -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) { @@ -189,7 +189,6 @@ if (foo) {
return foo;
}
/* XXX */
fimg_killborders(img);
return foo;

33
funcs/tests.c

@ -323,7 +323,7 @@ FimgFilter3x3 filter_a = { @@ -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
};
@ -332,10 +332,19 @@ FimgFilter3x3 filter_b = { @@ -332,10 +332,19 @@ FimgFilter3x3 filter_b = {
{ -2.0, -1.0, 0.0,
-1.0, 3.0, 1.0,
0.0, 1.0, 2.0 },
8.0, 0.0
8.0, 0.0
};
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 { @@ -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) { @@ -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_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_png(&dst, "f3x3b.png", 0);
// foo = fimg_save_as_pnm(&dst, "f3x3a.pnm", 0);
fimg_destroy(&src); fimg_destroy(&dst);

Loading…
Cancel
Save