diff --git a/doc/the_floatimg_hack.tex b/doc/the_floatimg_hack.tex index 2676a92..4566a26 100644 --- a/doc/the_floatimg_hack.tex +++ b/doc/the_floatimg_hack.tex @@ -586,14 +586,21 @@ int fimg_killcolors_b(FloatImg *fimg, float fval); \end{lstlisting} + % ---------------------------------- -\subsection{Filtrages} +\subsection{Filtrages}\index{filtrage} -To be done\index{XXX}, et il faut que je réfléchisse au traitement -des bords d'image. +Pour commencer, il faut que je réfléchisse au traitement +des bordures des images. +Ensuite que je débuggue\index{bug} cette fonction~: +\begin{lstlisting} +int fimg_lissage_2x2(FloatImg *img); +\end{lstlisting} + +To be continued\index{XXX}\dots % ---------------------------------- @@ -694,7 +701,7 @@ devra être donné avec l'option \texttt{-k F.F} avec une valeur par défaut \subsection{png2fimg}\index{png2fimg}\label{png2fimg} -Grosse panne à réparer. +Grosse panne\index{bug} à réparer. \begin{verbatim} tth@debian:~/TMP/floatimg$ png2fimg A.png foo.fimg @@ -753,8 +760,9 @@ sera lisible avec le sélecteur \texttt{-L}. \subsection{fimgops}\index{fimgops}\label{fimgops} Quelques opérations diverses entre deux images, qui doivent être -de la même taille, et du même type \textsl{pour le moment, -uniquement RGB}. +de la même taille, et uniquement du type \textsl{RGB}. Certaines +de ces opérations peuvent avoir un effet étrange sur vos images, +par exemple si un pixel se retrouve avec une valeur négative. \begin{verbatim} usage: @@ -770,6 +778,7 @@ options: -g convert output to gray -k N.N set float value -v increase verbosity + -X explosive action \end{verbatim} Pour des operateurs paramétrable (comme \texttt{mix}), le paramêtre @@ -791,6 +800,9 @@ D'un autre coté, écrire un greffon d'import/export pour Gimp\index{Gimp} ou Imagemagick\index{Imagemagick} ou Krita\index{Krita} ne devrait pas être trop difficile. Des volontaires ? +\textsl{D'ailleurs, pourquoi $n$ logiciels indépendants alors q'un +seul devrait être nécessaire ?} + \subsection{fimg2gray}\index{fimg2gray}\label{fimg2gray} Nous avons vu dans ce document que chaque image flottante pouvait @@ -836,7 +848,6 @@ nous faisons la somme de plusieurs centaines de ces images ? ACCU="quux.fimg" TMPF="tmp.fimg" DIMS="320 240" - mkfimg $ACCU $DIMS for i in {0..1000} do diff --git a/floatimg.h b/floatimg.h index 811b79b..c9e40d0 100644 --- a/floatimg.h +++ b/floatimg.h @@ -2,7 +2,7 @@ * floatimg.h */ -#define FIMG_VERSION 93 +#define FIMG_VERSION 94 /* * in memory descriptor @@ -80,6 +80,9 @@ int fimg_minimum(FloatImg *a, FloatImg *b, FloatImg *d); int fimg_maximum(FloatImg *a, FloatImg *b, FloatImg *d); +int fimg_killborders(FloatImg *img); +int fimg_lissage_2x2(FloatImg *img); + /* 'sfx0' module */ int fimg_killcolors_a(FloatImg *fimg, float fval); int fimg_killcolors_b(FloatImg *fimg, float fval); diff --git a/funcs/filtrage.c b/funcs/filtrage.c index 18ffb44..732c303 100644 --- a/funcs/filtrage.c +++ b/funcs/filtrage.c @@ -10,6 +10,8 @@ int fimg_lissage_2x2(FloatImg *img) { int x, y, offset; +float cr, cg, cb; +float *pr, *pg, *pb; #if DEBUG_LEVEL fprintf(stderr, ">>> %s ( %p )\n", __func__, img); @@ -17,15 +19,77 @@ fprintf(stderr," type %d size %dx%d\n", img->type, img->width, img->height); #endif -for (y=1; yheight; y++) { +pr = img->R; pg = img->G; pb = img->B; - for (x=1; xwidth; x++) { +for (y=1; y < img->height-1; y++) { + + for (x=1; x < img->width-1; x++) { offset = x + (y * img->width); + 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; + } } +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 + +h = img->height; w = img->width; + +for (idx=0; idxR[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; idxR[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 + } return -1; } /* -------------------------------------------------------------------- */ diff --git a/funcs/t.c b/funcs/t.c index 07fcb61..2a8dc12 100644 --- a/funcs/t.c +++ b/funcs/t.c @@ -12,6 +12,40 @@ int verbosity; float global_fvalue; +/* --------------------------------------------------------------------- */ +int essai_filtrage(char *infile) +{ +FloatImg fimg; +int foo, idx; +char buffer[100]; + +if (NULL != infile) { + fprintf(stderr, "loading %s\n", infile); + foo = fimg_create_from_dump(infile, &fimg); + 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(&fimg, 512, 512, FIMG_TYPE_RGB); + fimg_draw_something(&fimg); + } + +foo = fimg_save_as_pnm(&fimg, "source.pnm", 0); + +for (idx=0; idx<20; idx++) { + foo = fimg_lissage_2x2(&fimg); + foo = fimg_killborders(&fimg); + sprintf(buffer, "filter%03d.pnm", idx); + foo = fimg_save_as_pnm(&fimg, buffer, 0); + } + +fimg_destroy(&fimg); + +return 0; +} /* --------------------------------------------------------------------- */ int essai_geometrie(char *infile) { @@ -173,6 +207,7 @@ return 0; int main(int argc, char *argv[]) { int foo, opt; +char *filename; puts("++++++++++++++++++++++++++++++++"); @@ -186,9 +221,14 @@ while ((opt = getopt(argc, argv, "hk:v")) != -1) { } } -foo = essai_geometrie("foo.fimg"); +fprintf(stderr, "argc %d optind %d\n", argc, optind); + +filename = NULL; +if (1 == argc-optind) filename = argv[optind]; + +foo = essai_filtrage(filename); if (foo) { - fprintf(stderr, "************ %d\n", foo); + fprintf(stderr, "====> %d\n", foo); } return 0;