From e9a61bb96ac95b35b99237f46a59025a9355f79b Mon Sep 17 00:00:00 2001 From: tonton Th Date: Tue, 24 Mar 2020 09:31:52 +0100 Subject: [PATCH] added a new function : fimg_rotate_90, need more tests --- doc/the_floatimg_hack.tex | 16 +++++++--- floatimg.h | 5 ++- funcs/Makefile | 5 ++- funcs/rotate.c | 65 +++++++++++++++++++++++++++++++++++++++ funcs/sfx0.c | 1 + funcs/t.c | 44 +++++++++++++++++++++++--- 6 files changed, 125 insertions(+), 11 deletions(-) create mode 100644 funcs/rotate.c diff --git a/doc/the_floatimg_hack.tex b/doc/the_floatimg_hack.tex index 07fd34d..a51077d 100644 --- a/doc/the_floatimg_hack.tex +++ b/doc/the_floatimg_hack.tex @@ -29,6 +29,7 @@ \setlength \parskip {0.40em} \makeatletter +% exlpication de ce truc ? \def\verbatim@font{\normalfont\ttfamily\small} \makeatother @@ -208,8 +209,9 @@ lesquels sont décrits en page \pageref{outils}. Vous devez, en dehors des outils classiques (bash, gcc, make\dots), avoir quelques bibliothèques installées\footnote{Les \texttt{-dev} -pour Debian et dérivées}~: libv4l2, libpnglite, libtiff, libnetpbm, -libz, +pour Debian et dérivées}~: +\textsf{libv4l2, libpnglite, libtiff, libnetpbm, libz}, +éventuellement avec le \textsf{-dev} correspondant, et probablement d'autres choses. Il est même quasiment certain que Bash soit indispensable, tout @@ -496,7 +498,6 @@ Et pour attendre, un truc improbable, voire même inutile, en fait l'inverse de l'upscaling. \begin{lstlisting} -/* module funcs/geometry.c */ int fimg_halfsize_0(FloatImg *src, FloatImg *dst, int notused); \end{lstlisting} @@ -506,7 +507,6 @@ contenir d'image, et doit être effacé avec un bon Et le résultat est très moyen : il n'y a pas d'interpolation. \begin{lstlisting} -/* module funcs/geometry.c */ int fimg_extract_0(FloatImg *src, FloatImg *dst, int x, int y); \end{lstlisting} @@ -514,6 +514,14 @@ Contrairement à la fonction précédente, celle-ci demande absolument une image de destination initialisée aux dimensions (largeur et hauteur) désirées. +\begin{lstlisting} +int fimg_rotate_90(FloatImg *src, FloatImg *dst, int notused); +\end{lstlisting} + +Rotation de 90 degrés dans le sens horlogique d'une image RGB. +L'image de destination peut être soir vierge, soit pré-allouée +aux bonnes dimensions (échange W et H). + % ---------------------------------- \subsection{Exportation \& Importation}\index{export}\label{export} diff --git a/floatimg.h b/floatimg.h index e6d6b5c..f2e0c3a 100644 --- a/floatimg.h +++ b/floatimg.h @@ -2,7 +2,7 @@ * floatimg.h */ -#define FIMG_VERSION 95 +#define FIMG_VERSION 96 /* * in memory descriptor @@ -96,6 +96,9 @@ int fimg_filter_3x3(FloatImg *s, FloatImg *d, FimgFilter3x3 *filtr); int fimg_killcolors_a(FloatImg *fimg, float fval); int fimg_killcolors_b(FloatImg *fimg, float fval); +/* funcs/rotate.c module */ +/* #coronamaison */ +int fimg_rotate_90(FloatImg *src, FloatImg *dst, int notused); /* PNM files module */ int fimg_save_as_pnm(FloatImg *head, char *fname, int flags); diff --git a/funcs/Makefile b/funcs/Makefile index 98875dc..b7ccb0e 100644 --- a/funcs/Makefile +++ b/funcs/Makefile @@ -3,7 +3,7 @@ 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 + fimg-libpnm.o rampes.o sfx0.o geometry.o rotate.o #--------------------------------------------------------------- @@ -33,6 +33,9 @@ filtrage.o: filtrage.c $(DEPS) geometry.o: geometry.c $(DEPS) gcc $(COPT) -c $< +rotate.o: rotate.c $(DEPS) + gcc $(COPT) -DDEBUG_LEVEL=1 -c $< + sfx0.o: sfx0.c $(DEPS) gcc $(COPT) -c $< diff --git a/funcs/rotate.c b/funcs/rotate.c new file mode 100644 index 0000000..fd47b6b --- /dev/null +++ b/funcs/rotate.c @@ -0,0 +1,65 @@ +/* + * FLOATIMG + * rotation matricielle des images + * #coronamaison Mon 23 Mar 2020 11:45:59 AM CET + */ + +#include +#include + +#include "../floatimg.h" + +extern int verbosity; + +/* --------------------------------------------------------------------- */ +int fimg_rotate_90(FloatImg *src, FloatImg *dst, int notused) +{ +int foo; +int x, y; +float rgb[3]; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, + src, dst, notused); +#endif + +if (src->type != FIMG_TYPE_RGB) { + fprintf(stderr, "%s: src type %d not valid\n", __func__, + src->type); + return -6; + } + +/* check if dst pic is not allocated */ +if ( 0 == (dst->type | dst->width | dst->height) ) { + fprintf(stderr, "in %s, %p is empty\n", __func__, dst); + /* OK allocate a new fpic */ + foo = fimg_create(dst, src->height, src->width, src->type); + if (foo) { + fprintf(stderr, "%s: err %d create new pic\n", __func__, foo); + return -887; + } + if (verbosity) fimg_describe(dst, "new pic"); + } + +/* check if dst and src are conpatibles */ +if ( (src->type != dst->type) || + (src->width != dst->height) || (src->height != dst->width) ) { + fprintf(stderr, "%s: src & dst not compatibles\n", __func__); + return -888; + } + +/* + * THIS IS A CRUDE IMPLEMENTATION +*/ +for (y=0; yheight; y++) { + for (x=0; xwidth; x++) { + fimg_get_rgb(src, x, y, rgb); + fimg_plot_rgb(dst, y, x, rgb[0], rgb[1], rgb[2]); + } + } + +/* we don't have any cleanup to make */ + +return 0; +} +/* --------------------------------------------------------------------- */ diff --git a/funcs/sfx0.c b/funcs/sfx0.c index c91308f..6f1da28 100644 --- a/funcs/sfx0.c +++ b/funcs/sfx0.c @@ -4,6 +4,7 @@ */ #include +#include #include "../floatimg.h" diff --git a/funcs/t.c b/funcs/t.c index 31e010a..76ab01a 100644 --- a/funcs/t.c +++ b/funcs/t.c @@ -12,12 +12,43 @@ int verbosity; float global_fvalue; +/* --------------------------------------------------------------------- */ +int essai_rotate(char *infile) +{ +FloatImg src, dst; +int foo; + +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 : NOT INPUT FILE, FUBAR\n", __func__); + abort(); + } + +fimg_save_as_png(&src, "test.png", 0); + +foo = fimg_rotate_90(&src, &dst, 0); +fprintf(stderr, "rotate 90 -> %d\n", foo); + +foo = fimg_save_as_png(&dst, "rotated90.png", 0); +foo = fimg_save_as_pnm(&dst, "rotated90.pnm", 0); + +fimg_destroy(&src); + +return -1; +} /* --------------------------------------------------------------------- */ int essai_filtrage_3x3(char *infile) { FloatImg src, dst; -int foo, idx; -char buffer[100]; +int foo; /// , idx; +// char buffer[100]; FimgFilter3x3 filter_a = { @@ -54,7 +85,10 @@ else { fimg_save_as_png(&src, "test.png", 0); foo = fimg_clone(&src, &dst, 0); - +if (foo) { + fprintf(stderr, "%s: err clone %p\n", __func__, &src); + return -44; + } fimg_filter_3x3(&src, &dst, &filter_a); foo = fimg_clamp_negativ(&dst); if (foo) { @@ -310,9 +344,9 @@ if (foo) { } */ -foo = essai_filtrage_3x3(filename); +foo = essai_rotate(filename); if (foo) { - fprintf(stderr, "Filtre 3x3 ====> %d\n", foo); + fprintf(stderr, "Essai ====> %d\n", foo); } fprintf(stderr, "++++++++++++++ end of pid %d\n", getpid());