Zzzzz....
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#---------------------------------------------------------------
|
||||
|
||||
COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=0
|
||||
COPT = -Wall -fpic -g -pg -no-pie -DDEBUG_LEVEL=0
|
||||
DEPS = ../floatimg.h Makefile
|
||||
OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \
|
||||
fimg-libpnm.o rampes.o sfx0.o geometry.o
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
|
||||
76
funcs/t.c
76
funcs/t.c
@@ -13,14 +13,68 @@ int verbosity;
|
||||
float global_fvalue;
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
int essai_filtrage(char *infile)
|
||||
int essai_filtrage_3x3(char *infile)
|
||||
{
|
||||
FloatImg src, dst;
|
||||
int foo, idx;
|
||||
char buffer[100];
|
||||
|
||||
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
|
||||
|
||||
};
|
||||
|
||||
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
|
||||
|
||||
};
|
||||
|
||||
if (NULL != infile) {
|
||||
fprintf(stderr, "%s: loading %s\n", __func__, infile);
|
||||
foo = fimg_create_from_dump(infile, &src);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err load '%s'\n", __func__, infile);
|
||||
return foo;
|
||||
}
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "%s is creating the picz\n", __func__);
|
||||
fimg_create(&src, 640, 480, FIMG_TYPE_RGB);
|
||||
fimg_test_pattern(&src, 0, 255.0);
|
||||
fimg_save_as_png(&src, "test.png", 0);
|
||||
}
|
||||
|
||||
foo = fimg_clone(&src, &dst, 0);
|
||||
|
||||
fimg_filter_3x3(&src, &dst, &filter_b);
|
||||
foo = fimg_clamp_negativ(&dst);
|
||||
if (foo) {
|
||||
fprintf(stderr, "clamped %d negativ pixels\n", foo);
|
||||
}
|
||||
foo = fimg_save_as_png(&dst, "f3x3.png", 0);
|
||||
foo = fimg_save_as_pnm(&dst, "f3x3.pnm", 0);
|
||||
|
||||
fimg_destroy(&src); fimg_destroy(&dst);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int essai_filtrage_2x2(char *infile)
|
||||
{
|
||||
FloatImg fimg;
|
||||
int foo, idx;
|
||||
char buffer[100];
|
||||
|
||||
if (NULL != infile) {
|
||||
fprintf(stderr, "loading %s\n", infile);
|
||||
fprintf(stderr, "%s: loading %s\n", __func__, infile);
|
||||
foo = fimg_create_from_dump(infile, &fimg);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err load '%s'\n", __func__, infile);
|
||||
@@ -39,11 +93,13 @@ foo = fimg_save_as_pnm(&fimg, "source.pnm", 0);
|
||||
* running multiple filters so you can
|
||||
* watch the up-left shift :)
|
||||
*/
|
||||
for (idx=0; idx<10; idx++) {
|
||||
for (idx=0; idx<5; idx++) {
|
||||
foo = fimg_lissage_2x2(&fimg);
|
||||
foo = fimg_killborders(&fimg);
|
||||
sprintf(buffer, "filter%03d.png", idx);
|
||||
foo = fimg_save_as_png(&fimg, buffer, 0);
|
||||
if (verbosity) {
|
||||
fprintf(stderr, "%s %d\n", buffer, foo);
|
||||
}
|
||||
}
|
||||
|
||||
fimg_destroy(&fimg);
|
||||
@@ -238,11 +294,19 @@ fprintf(stderr, "argc %d optind %d\n", argc, optind);
|
||||
filename = NULL;
|
||||
if (1 == argc-optind) filename = argv[optind];
|
||||
|
||||
foo = essai_filtrage(filename);
|
||||
/*
|
||||
foo = essai_filtrage_2x2(filename);
|
||||
if (foo) {
|
||||
fprintf(stderr, "====> %d\n", foo);
|
||||
fprintf(stderr, "Filtre 2x2 ====> %d\n", foo);
|
||||
}
|
||||
*/
|
||||
|
||||
foo = essai_filtrage_3x3(filename);
|
||||
if (foo) {
|
||||
fprintf(stderr, "Filtre 3x3 ====> %d\n", foo);
|
||||
}
|
||||
|
||||
fprintf(stderr, "++++++++++++++ end of pid %d\n", getpid());
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
Reference in New Issue
Block a user