Compare commits

...

3 Commits

Author SHA1 Message Date
2d75f70215 un peu de blabla dans la doc 2020-01-10 17:22:58 +01:00
360c2e113a added gray conversion to fimgfx 2020-01-10 14:18:38 +01:00
0104a736ea some tests added... 2020-01-10 12:01:12 +01:00
9 changed files with 108 additions and 22 deletions

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash -v
DOC=the_floatimg_hack DOC=the_floatimg_hack

View File

@ -312,6 +312,7 @@ maximale \textsl{supposée} de l'image source.
int fimg_square_root(FloatImg *s, FloatImg *d, double maxval); int fimg_square_root(FloatImg *s, FloatImg *d, double maxval);
int fimg_power_2(FloatImg *s, FloatImg *d, double maxval); int fimg_power_2(FloatImg *s, FloatImg *d, double maxval);
int fimg_cos_01(FloatImg *s, FloatImg *d, double maxval); int fimg_cos_01(FloatImg *s, FloatImg *d, double maxval);
int fimg_cos_010(FloatImg *s, FloatImg *d, double maxval);
\end{verbatim} \end{verbatim}
Rappelons qu'il est possible pour un logiciel applicatif Rappelons qu'il est possible pour un logiciel applicatif
@ -324,6 +325,14 @@ maximale du capteur, et le second sert à compter le
nombre de capture\footnote{Et c'est bien géré aussi nombre de capture\footnote{Et c'est bien géré aussi
dans l'upscaling.} effectuées. dans l'upscaling.} effectuées.
La fonction
\texttt{fimg\_normalize(FloatImg *fi, double maxima, int notused);}
tente de gérer ce cas d'utilisation. Son ajout au captureur d'images
floues sera probablement le bienvenue. Je me suis bien rendu compte
à l'usage\footnote{Une histoire de \textit{fonderie}, un logiciel
censé faire des films flous à partir d'images floues} en situation
festive qu'il manquait des données dans la chaine de traitement.
\vspace{1em} \vspace{1em}
L'autre façon de procéder est d'explorer notre image à la L'autre façon de procéder est d'explorer notre image à la
@ -331,7 +340,7 @@ recherche de la valeur maximale.
La fonction \texttt{float fimg\_get\_maxvalue(\&fimg)} est La fonction \texttt{float fimg\_get\_maxvalue(\&fimg)} est
faite pour ça. faite pour ça.
C'est actuellement la méthode utilisée par l'outil qui C'est actuellement la méthode utilisée par l'outil qui
sert à faire les modifications de contraste (page \pageref{fimgfx}. sert à faire les modifications de contraste (page \pageref{fimgfx}).
\vspace{1em} \vspace{1em}
@ -535,7 +544,7 @@ Il reste plein de choses à faire pour que ce soit vraiment utilisable.
\item Remplacer le « fait-maison » par \textsc{libnetpnm}\index{pnm}. \item Remplacer le « fait-maison » par \textsc{libnetpnm}\index{pnm}.
\textsl{[en cours]}. \textsl{[en cours]}.
\item Compléter les traitements mathémathiques (eg le gamma\index{gamma}). \item Compléter les traitements mathémathiques (eg le gamma\index{gamma}).
\item Formaliser les codes d'erreur. \item Formaliser les codes d'erreur. \textbf{Urgent}.
\end{itemize} \end{itemize}

View File

@ -2,7 +2,7 @@
# building the base library # building the base library
# #
COPT = -Wall -fpic -g -pg -no-pie -DDEBUG_LEVEL=0 COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=0
OBJS = fimg-core.o fimg-pnm.o fimg-file.o fimg-math.o \ OBJS = fimg-core.o fimg-pnm.o fimg-file.o fimg-math.o \
fimg-timers.o operators.o fimg-2gray.o \ fimg-timers.o operators.o fimg-2gray.o \

View File

@ -15,7 +15,7 @@ extern int verbosity; /* must be declared around main() */
/* /*
* floating imgs MUST be allocated before calling this func. * floating imgs MUST be allocated before calling this func.
*/ */
int fimg_mk_gray_from(FloatImg *src, FloatImg*dst, int k) int fimg_mk_gray_from(FloatImg *src, FloatImg *dst, int k)
{ {
float kr, kg, kb, kdiv; float kr, kg, kb, kdiv;
int nbb, foo; int nbb, foo;

View File

@ -91,6 +91,11 @@ if ( ! fimg_type_is_valid(t) ) {
return -2; return -2;
} }
/*
* what to do if we've got a descriptor for an image
* already allocated ?
*/
memset(fimg, 0, sizeof(FloatImg)); memset(fimg, 0, sizeof(FloatImg));
surface = w * h; surface = w * h;

View File

@ -163,14 +163,14 @@ fprintf(stderr, ">>> %-25s ( '%s' %p )\n", __func__, fname, head);
fp = fopen(fname, "r"); fp = fopen(fname, "r");
if (NULL==fp) { if (NULL==fp) {
perror(fname); perror(fname);
exit(1); return -15;
} }
foo = fread(&filehead, sizeof(FimgFileHead), 1, fp); foo = fread(&filehead, sizeof(FimgFileHead), 1, fp);
if (1 != foo) { if (1 != foo) {
fprintf(stderr, "%s : short read\n", fname); fprintf(stderr, "%s : short read\n", fname);
fclose(fp); fclose(fp);
return -1; return -16;
} }
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, "%s : got [ %d %d %d ] from '%s'\n", __func__, fprintf(stderr, "%s : got [ %d %d %d ] from '%s'\n", __func__,

View File

@ -151,7 +151,7 @@ void fimg_mul_cste(FloatImg *fi, float value)
{ {
int nbre, idx; int nbre, idx;
if (fi->type != FIMG_TYPE_RGB) { if ( (fi->type != FIMG_TYPE_RGB) && (fi->type != FIMG_TYPE_GRAY) ) {
fprintf(stderr, "%s : type %d invalide\n", fprintf(stderr, "%s : type %d invalide\n",
__func__, fi->type); __func__, fi->type);
return; return;
@ -183,6 +183,7 @@ if (fi->count < 1) {
/* /*
* mmmm, is this real ? * mmmm, is this real ?
* how to accuratly check the value of 'I.fval' ?
*/ */
coef = 1.0 / ((double)fi->count * (double)fi->fval); coef = 1.0 / ((double)fi->count * (double)fi->fval);

88
lib/t.c
View File

@ -41,6 +41,50 @@ if (foo) {
val = fimg_get_maxvalue(&A); val = fimg_get_maxvalue(&A);
fprintf(stderr, "AFTER max pixel %f\n", val); fprintf(stderr, "AFTER max pixel %f\n", val);
fimg_destroy(&A);
return 0;
}
/* ---------------------------------------------------------------- */
#define WI 1024
#define HI 768
#define KDEG 3.141592654 /* secret magic number */
int essai_interpolate(int k)
{
FloatImg A, B, C;
int foo;
foo = fimg_create(&A, WI, HI, FIMG_TYPE_RGB);
if (foo) {
fprintf(stderr, "%s err create A %d\n", __func__, foo);
return foo;
}
fimg_hdeg_a(&A, KDEG);
foo = fimg_create(&B, WI, HI, FIMG_TYPE_RGB);
if (foo) {
fprintf(stderr, "%s err create B %d\n", __func__, foo);
return foo;
}
fimg_vdeg_a(&B, KDEG);
foo = fimg_create(&C, WI, HI, FIMG_TYPE_RGB);
if (foo) {
fprintf(stderr, "%s err create C %d\n", __func__, foo);
return foo;
}
foo = fimg_interpolate(&A, &B, &C, 0.5);
if (foo) {
fprintf(stderr, "%s err interpolate %d\n", __func__, foo);
return foo;
}
foo = fimg_save_as_pnm(&C, "interpolate.pnm", 0);
fimg_destroy(&A); fimg_destroy(&B); fimg_destroy(&C);
return 0; return 0;
} }
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
@ -74,13 +118,14 @@ fimg_destroy(&gray);
return 0; return 0;
} }
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
#define TAILLE 1024
int essai_clone_et_copy(int unused) int essai_clone_et_copy(int unused)
{ {
FloatImg A, B, C; FloatImg A, B, C;
int foo; int foo;
foo = fimg_create(&A, 512, 512, FIMG_TYPE_RGB); foo = fimg_create(&A, TAILLE, TAILLE, FIMG_TYPE_RGB);
if (foo) { if (foo) {
fprintf(stderr, "%s err create A %d\n", __func__, foo); fprintf(stderr, "%s err create A %d\n", __func__, foo);
return foo; return foo;
@ -90,8 +135,8 @@ if (foo) {
fprintf(stderr, "%s err drawing A %d\n", __func__, foo); fprintf(stderr, "%s err drawing A %d\n", __func__, foo);
return foo; return foo;
} }
foo = fimg_save_as_pnm(&A, "A.pnm", 0);
foo = fimg_save_as_pnm(&A, "A.pnm", 0);
if (foo) { if (foo) {
fprintf(stderr, "%s : err %d on save_as_pnm\n", __func__, foo); fprintf(stderr, "%s : err %d on save_as_pnm\n", __func__, foo);
exit(1); exit(1);
@ -103,7 +148,7 @@ if (foo) {
return foo; return foo;
} }
foo = fimg_create(&C, 512, 512, FIMG_TYPE_RGB); foo = fimg_create(&C, TAILLE, TAILLE, FIMG_TYPE_RGB);
if (foo) { if (foo) {
fprintf(stderr, "%s err create A %d\n", __func__, foo); fprintf(stderr, "%s err create A %d\n", __func__, foo);
return foo; return foo;
@ -115,9 +160,13 @@ if (foo) {
} }
foo = fimg_save_as_pnm(&C, "C.pnm", 0); foo = fimg_save_as_pnm(&C, "C.pnm", 0);
fimg_destroy(&A); fimg_destroy(&B); fimg_destroy(&C);
return 0; return 0;
} }
#undef TAILLE
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
int essai_contraste(char *fname) int essai_contraste(char *fname)
@ -127,38 +176,42 @@ FloatImg dessin, copy;
double maxi; double maxi;
foo = fimg_create_from_dump(fname, &dessin); foo = fimg_create_from_dump(fname, &dessin);
if (foo) {
fprintf(stderr, "in %s, error %d loading '%s'\n",
__func__, foo, fname);
return foo;
}
foo = fimg_clone(&dessin, &copy, 0); foo = fimg_clone(&dessin, &copy, 0);
maxi = (double)fimg_get_maxvalue(&dessin); maxi = (double)fimg_get_maxvalue(&dessin);
fprintf(stderr, "image source valeur maxi = %f\n", maxi); fprintf(stderr, "image source valeur maxi = %f\n", maxi);
fimg_power_2(&dessin, &copy, maxi); fimg_power_2(&dessin, &copy, maxi);
maxi = (double)fimg_get_maxvalue(&copy); maxi = (double)fimg_get_maxvalue(&copy);
fprintf(stderr, "apres power_2 valeur maxi = %f\n", maxi); fprintf(stderr, "apres power_2 valeur maxi = %f\n", maxi);
fimg_dump_to_file(&copy, "power2.fimg", 0); fimg_save_as_pnm(&copy, "power2.pnm", 0);
fimg_square_root(&dessin, &copy, maxi); fimg_square_root(&dessin, &copy, maxi);
maxi = (double)fimg_get_maxvalue(&copy); maxi = (double)fimg_get_maxvalue(&copy);
fprintf(stderr, "apres square_root valeur maxi = %f\n", maxi); fprintf(stderr, "apres square_root valeur maxi = %f\n", maxi);
fimg_dump_to_file(&copy, "squareroot.fimg", 0); fimg_save_as_pnm(&copy, "squareroot.pnm", 0);
fimg_cos_01(&dessin, &copy, maxi); fimg_cos_01(&dessin, &copy, maxi);
maxi = (double)fimg_get_maxvalue(&copy); maxi = (double)fimg_get_maxvalue(&copy);
fprintf(stderr, "apres cos 01 valeur maxi = %f\n", maxi); fprintf(stderr, "apres cos 01 valeur maxi = %f\n", maxi);
fimg_dump_to_file(&copy, "cos_01.fimg", 0); fimg_save_as_pnm(&copy, "cos_01.pnm", 0);
fimg_cos_010(&dessin, &copy, maxi); fimg_cos_010(&dessin, &copy, maxi);
maxi = (double)fimg_get_maxvalue(&copy); maxi = (double)fimg_get_maxvalue(&copy);
fprintf(stderr, "apres cos 010 valeur maxi = %f\n", maxi); fprintf(stderr, "apres cos 010 valeur maxi = %f\n", maxi);
fimg_dump_to_file(&copy, "cos_010.fimg", 0); fimg_save_as_pnm(&copy, "cos_010.pnm", 0);
fimg_destroy(&dessin); fimg_destroy(&dessin); fimg_destroy(&copy);
return -1; return 0;
} }
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
#define W 320
#define H 240
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int foo, opt; int foo, opt;
@ -178,5 +231,14 @@ if (verbosity) fimg_print_version(0);
foo = essai_normalize(); foo = essai_normalize();
fprintf(stderr, "retour essai normalize -> %d\n", foo); fprintf(stderr, "retour essai normalize -> %d\n", foo);
foo = essai_contraste("quux.fimg");
fprintf(stderr, "retour essai contraste -> %d\n", foo);
foo = essai_clone_et_copy(0);
fprintf(stderr, "retour essai clone'n'copy -> %d\n", foo);
foo = essai_interpolate(0);
fprintf(stderr, "retour essai interpolate -> %d\n", foo);
return 0; return 0;
} }

View File

@ -19,13 +19,14 @@ typedef struct {
int nbarg; int nbarg;
} Fx; } Fx;
enum fxid { Fx_cos01, Fx_cos010, Fx_pow2, Fx_sqrt }; enum fxid { Fx_cos01, Fx_cos010, Fx_pow2, Fx_sqrt, Fx_gray0 };
Fx fx_list[] = { Fx fx_list[] = {
{ "cos01", Fx_cos01, 0 }, { "cos01", Fx_cos01, 0 },
{ "cos010", Fx_cos010, 0 }, { "cos010", Fx_cos010, 0 },
{ "pow2", Fx_pow2, 0 }, { "pow2", Fx_pow2, 0 },
{ "sqrt", Fx_sqrt, 0 }, { "sqrt", Fx_sqrt, 0 },
{ "gray0", Fx_gray0, 0 },
{ NULL, 0, 0 } { NULL, 0, 0 }
}; };
@ -59,6 +60,10 @@ puts("------ fimg special effects ------");
puts("usage:"); puts("usage:");
puts("\tfimgfix [options] <effect> source.fimg resultat.fimg"); puts("\tfimgfix [options] <effect> source.fimg resultat.fimg");
puts("options:");
puts("\t-k N.N\tset the floating value");
puts("\t-v\tincrease verbosity");
puts("effects:"); puts("effects:");
printf("\t"); printf("\t");
for (fx=fx_list; fx->name; fx++) { for (fx=fx_list; fx->name; fx++) {
@ -103,6 +108,10 @@ switch (act) {
case Fx_sqrt: case Fx_sqrt:
fimg_square_root(&src, &dest, maxval); break; fimg_square_root(&src, &dest, maxval); break;
case Fx_gray0: /* new 2020 01 10 */
fimg_to_gray(&src); fimg_copy_data(&src, &dest);
break;
default: default:
fprintf(stderr, "*** %s : %d is bad action\n", __func__, act); fprintf(stderr, "*** %s : %d is bad action\n", __func__, act);
break; break;