From bec63e97f5ec85efaea434a51f9fab05737f7f79 Mon Sep 17 00:00:00 2001 From: le vieux Date: Thu, 12 Nov 2020 23:36:06 +0100 Subject: [PATCH] first semi-good run of the Interpolator --- Fonderie/glitches.c | 23 ++++++--- Fonderie/interpolator.c | 109 ++++++++++++++++++++++++++++++++++------ Fonderie/metriques.c | 42 +++++++++++++--- Fonderie/metriques.h | 5 +- 4 files changed, 151 insertions(+), 28 deletions(-) diff --git a/Fonderie/glitches.c b/Fonderie/glitches.c index d9a40ef..3781428 100644 --- a/Fonderie/glitches.c +++ b/Fonderie/glitches.c @@ -1,18 +1,25 @@ /* * glitches.c + * ---------- + * + * initially developped for the interpolator */ #include #include +#include #include "../floatimg.h" +#include "glitches.h" + extern int verbosity; /* -------------------------------------------------------------- */ int kill_a_random_line(FloatImg *pvictime, float fval, int bits) { int line, xpos, offset; +float ftmp; #if DEBUG_LEVEL fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pvictime, bits); @@ -27,11 +34,14 @@ if (verbosity > 1) { offset = pvictime->width * line; for (xpos=0; xposwidth; xpos++) { - if (bits & 1) pvictime->R[offset+xpos] = fval; + if (bits & 1) { ftmp = pvictime->R[offset+xpos] * fval; + pvictime->R[offset+xpos] = sqrt(ftmp); } else pvictime->R[offset+xpos] = 0.0; - if (bits & 2) pvictime->G[offset+xpos] = fval; + if (bits & 2) { ftmp = pvictime->G[offset+xpos] * fval; + pvictime->G[offset+xpos] = sqrt(ftmp); } else pvictime->G[offset+xpos] = 0.0; - if (bits & 4) pvictime->B[offset+xpos] = fval; + if (bits & 4) { ftmp = pvictime->B[offset+xpos] * fval; + pvictime->B[offset+xpos] = sqrt(ftmp); } else pvictime->B[offset+xpos] = 0.0; } @@ -59,7 +69,6 @@ int x, y, off; /* * please add boundary check ? */ - sr = sg = sb = 0.0; for (y=0; y<8; y++) { off = xpos + (picture->width * (y+ypos)); @@ -80,7 +89,6 @@ for (y=0; y<8; y++) { off++; } } - return 0; } /* -------------------------------------------------------------- */ @@ -88,12 +96,15 @@ int un_moyen_flou_8x8(FloatImg *picture, int xpos, int ypos) { int i, j, x, y; +/* + * please add boundary check ? + */ for (i=y=0; i<8; i++, y+=8) { for (j=x=0; j<8; j++, x+=8 ) { un_petit_flou_8x8(picture, x+xpos, y+ypos); } } -return -1; +return 0; } /* -------------------------------------------------------------- */ int poke_a_random_pixel(FloatImg *picz, float fval, int kaboo) diff --git a/Fonderie/interpolator.c b/Fonderie/interpolator.c index 758a3d2..864e626 100644 --- a/Fonderie/interpolator.c +++ b/Fonderie/interpolator.c @@ -1,7 +1,9 @@ /* * INTERPOLATOR 2070 * - * Don't use that software in real life ! + * +---------------------------------------+ + * ! Do not use that software in real life ! + * +---------------------------------------+ * * imported in FloatImg Mon Nov 9 19:08:57 CET 2020 * @@ -16,6 +18,7 @@ #include "glitches.h" #include "crapulator.h" +#include "metriques.h" // XXX #include "fonctions.h" @@ -23,16 +26,85 @@ int verbosity; int convert_to_gray; /* needed by fonctions.c */ /* -------------------------------------------------------------- */ -int interpolator(char *pattern, char *outdir, int Nsteps) +/* on va essayer de trier l'ordre d'apparition des images + * selon une metrique approximative + */ +typedef struct { + int idx; /* in globbuf.gl_pathv[n] */ + float value; /* from metric analyse */ + } IdxValue; + +static int cmp_idxvalues(const void *pa, const void *pb) +{ +return ( ((IdxValue *)pa)->value > ((IdxValue *)pb)->value); +} + +int tentative_triage(glob_t *ptr_glob, IdxValue **ptr_idxval) +{ +int idx, foo, nombre; +float metrique; +char *filename; +IdxValue *idxvalues; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %p %p )\n", __func__, ptr_glob, ptr_idxval); +#endif + +nombre = ptr_glob->gl_pathc; + +/* allocate the array for the sorting action */ +idxvalues = calloc(nombre, sizeof(IdxValue)); +if (NULL==idxvalues) { + fprintf(stderr, "MEMORY ERROR in %s\n", __func__); + exit(1); + } +fprintf(stderr, "IdxValues array at %p\n", idxvalues); + +*ptr_idxval = idxvalues; + +/* compute all the needed values */ +for (idx=0; idxgl_pathv[idx]; + foo = get_float_metric_from_file(filename, &metrique); + if (foo) { + fprintf(stderr, "%s: err %d get metric of '%s'\n", __func__, + foo, filename); + return -1; + } + fprintf(stderr, "%5d %s %f\n", idx, filename, metrique); + idxvalues[idx].idx = idx; + idxvalues[idx].value = metrique; + } + +/* and now, we can massage all our datas */ +qsort(idxvalues, nombre, sizeof(IdxValue), cmp_idxvalues); + +for (idx=0; idx %d\n\n", idx_values, foo); + foo = fimg_fileinfos(globbuf.gl_pathv[0], iarray); if (FIMG_TYPE_RGB != iarray[2]) { fprintf(stderr, "can work only on RGB fimg picture, was %d\n", @@ -60,33 +136,37 @@ fimg_create(&Out, w, h, 3); ipng = 0; for (idx=0; idx %d\n", idx, foo); + fprintf(stderr, "load %s from dump -> %d\n", cptr, foo); continue; } + value = idx_values[idx].value; /* here, we can insert the input filter */ /* OK try it ... */ - foo = crapulator(&B, 0, 256.7); + foo = crapulator(&B, infx, value/2.0); if (foo) { fprintf(stderr, "crapulator failure %d\n", foo); exit(1); } - un_moyen_flou_8x8(&B, 20, 20); - un_moyen_flou_8x8(&B, 220, 20); - un_moyen_flou_8x8(&B, 420, 20); for (step=0; step - +#include #include "../floatimg.h" +#include "metriques.h" extern int verbosity; /* -------------------------------------------------------------- */ - -int get_float_metric(FloatImg *pimg, float *where, int whot) +/* + * premier essai... + */ +int get_float_metric(FloatImg *pimg, float *where) { +float means[4]; +int foo; #if DEBUG_LEVEL fprintf(stderr, ">>> %s ( %p %f %d )\n", __func__, pimg, where, whot); #endif -*where = 0; - -return -1; +foo = fimg_meanvalues(pimg, means); +if (foo) { + fprintf(stderr, "fatal error in %s\n", __func__); + exit(1); + } +*where = means[0] + means[1] + means[2]; +return 0; +} +/* -------------------------------------------------------------- */ +int get_float_metric_from_file(char *fname, float *where) +{ +FloatImg image; +int foo; +float fval; + +foo = fimg_create_from_dump(fname, &image); +if (foo) { + fprintf(stderr, "%s: err %d loading %s\n", __func__, foo, fname); + return foo; + } +fval = -1.0; /* sensible default value */ +foo = get_float_metric(&image, &fval); +*where = fval; + +// fprintf(stderr, "metric of '%s' = %f\n", fname, fval); +fimg_destroy(&image); + +return 0; } /* -------------------------------------------------------------- */ diff --git a/Fonderie/metriques.h b/Fonderie/metriques.h index 1743d2b..e4fcadb 100644 --- a/Fonderie/metriques.h +++ b/Fonderie/metriques.h @@ -4,8 +4,9 @@ /* -------------------------------------------------------------- */ -/* first experiment */ +/* first experiments */ -int get_float_metric(FloatImg *pimg, float *where, int whot) +int get_float_metric(FloatImg *pimg, float *where); +int get_float_metric_from_file(char *imgname, float *where); /* -------------------------------------------------------------- */