Compare commits

..

No commits in common. "e1e32b1a99b886becb68e472f99974f0ce6a5224" and "f2e170c7d2c0eb003aaefa2d7b1f19441e76bfa8" have entirely different histories.

5 changed files with 30 additions and 157 deletions

View File

@ -67,12 +67,8 @@ criant de documentation...
## Interpolator ## Interpolator
Un logiciel dont l'inspiration vient du passé et d'importantes Un logiciel dont l'inspiration vient de Terre-Blanque, ça ne peut
amélioration de Terre-Blanque, ça ne peut pas être complètement malsain :)
pas être complètement malsain.
Mais il reste encore pas mal de choses à faire pour le mettre
en prod' un trolldi soir.
## Conclusion ## Conclusion

View File

@ -1,25 +1,18 @@
/* /*
* glitches.c * glitches.c
* ----------
*
* initially developped for the interpolator
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h>
#include "../floatimg.h" #include "../floatimg.h"
#include "glitches.h"
extern int verbosity; extern int verbosity;
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
int kill_a_random_line(FloatImg *pvictime, float fval, int bits) int kill_a_random_line(FloatImg *pvictime, float fval, int bits)
{ {
int line, xpos, offset; int line, xpos, offset;
float ftmp;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pvictime, bits); fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pvictime, bits);
@ -34,14 +27,11 @@ if (verbosity > 1) {
offset = pvictime->width * line; offset = pvictime->width * line;
for (xpos=0; xpos<pvictime->width; xpos++) { for (xpos=0; xpos<pvictime->width; xpos++) {
if (bits & 1) { ftmp = pvictime->R[offset+xpos] * fval; if (bits & 1) pvictime->R[offset+xpos] = fval;
pvictime->R[offset+xpos] = sqrt(ftmp); }
else pvictime->R[offset+xpos] = 0.0; else pvictime->R[offset+xpos] = 0.0;
if (bits & 2) { ftmp = pvictime->G[offset+xpos] * fval; if (bits & 2) pvictime->G[offset+xpos] = fval;
pvictime->G[offset+xpos] = sqrt(ftmp); }
else pvictime->G[offset+xpos] = 0.0; else pvictime->G[offset+xpos] = 0.0;
if (bits & 4) { ftmp = pvictime->B[offset+xpos] * fval; if (bits & 4) pvictime->B[offset+xpos] = fval;
pvictime->B[offset+xpos] = sqrt(ftmp); }
else pvictime->B[offset+xpos] = 0.0; else pvictime->B[offset+xpos] = 0.0;
} }
@ -69,6 +59,7 @@ int x, y, off;
/* /*
* please add boundary check ? * please add boundary check ?
*/ */
sr = sg = sb = 0.0; sr = sg = sb = 0.0;
for (y=0; y<8; y++) { for (y=0; y<8; y++) {
off = xpos + (picture->width * (y+ypos)); off = xpos + (picture->width * (y+ypos));
@ -89,6 +80,7 @@ for (y=0; y<8; y++) {
off++; off++;
} }
} }
return 0; return 0;
} }
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
@ -96,15 +88,12 @@ int un_moyen_flou_8x8(FloatImg *picture, int xpos, int ypos)
{ {
int i, j, x, y; int i, j, x, y;
/*
* please add boundary check ?
*/
for (i=y=0; i<8; i++, y+=8) { for (i=y=0; i<8; i++, y+=8) {
for (j=x=0; j<8; j++, x+=8 ) { for (j=x=0; j<8; j++, x+=8 ) {
un_petit_flou_8x8(picture, x+xpos, y+ypos); un_petit_flou_8x8(picture, x+xpos, y+ypos);
} }
} }
return 0; return -1;
} }
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
int poke_a_random_pixel(FloatImg *picz, float fval, int kaboo) int poke_a_random_pixel(FloatImg *picz, float fval, int kaboo)

View File

@ -1,9 +1,7 @@
/* /*
* INTERPOLATOR 2070 * 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 * imported in FloatImg Mon Nov 9 19:08:57 CET 2020
* *
@ -18,7 +16,6 @@
#include "glitches.h" #include "glitches.h"
#include "crapulator.h" #include "crapulator.h"
#include "metriques.h"
// XXX #include "fonctions.h" // XXX #include "fonctions.h"
@ -26,85 +23,16 @@ int verbosity;
int convert_to_gray; /* needed by fonctions.c */ int convert_to_gray; /* needed by fonctions.c */
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
/* on va essayer de trier l'ordre d'apparition des images int interpolator(char *pattern, char *outdir, int Nsteps)
* 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; idx<nombre; idx++) {
filename = ptr_glob->gl_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<nombre; idx++) {
printf("%5d %9.6f %5d\n", idx,
idxvalues[idx].value, idxvalues[idx].idx);
fflush(stdout);
}
return 0;
}
/* -------------------------------------------------------------- */
/*
* This is the mega working loop
*/
int interpolator(char *pattern, char *outdir, int Nsteps, int infx)
{ {
FloatImg A, B, Out, *pFirst, *pSecond; FloatImg A, B, Out, *pFirst, *pSecond;
glob_t globbuf; glob_t globbuf;
int foo, idx, ipng, w, h, step; int foo, idx, ipng, w, h, step;
int curpix;
int iarray[3]; int iarray[3];
char *cptr, line[200]; char *cptr, line[200];
float coef, value; float coef;
IdxValue *idx_values;
fprintf(stderr, "\nfrom '%s' to '%s' with %d steps.\n", fprintf(stderr, "\nfrom %s to %s with %d steps.\n", pattern, outdir, Nsteps);
pattern, outdir, Nsteps);
memset(&globbuf, 0, sizeof(glob_t)); memset(&globbuf, 0, sizeof(glob_t));
foo = glob(pattern, 0, NULL, &globbuf); foo = glob(pattern, 0, NULL, &globbuf);
@ -116,10 +44,6 @@ if (0 == globbuf.gl_pathc) {
return -1; return -1;
} }
idx_values = NULL;
foo = tentative_triage(&globbuf, &idx_values);
fprintf(stderr, "\tTRI of %p -> %d\n\n", idx_values, foo);
foo = fimg_fileinfos(globbuf.gl_pathv[0], iarray); foo = fimg_fileinfos(globbuf.gl_pathv[0], iarray);
if (FIMG_TYPE_RGB != iarray[2]) { if (FIMG_TYPE_RGB != iarray[2]) {
fprintf(stderr, "can work only on RGB fimg picture, was %d\n", fprintf(stderr, "can work only on RGB fimg picture, was %d\n",
@ -136,37 +60,33 @@ fimg_create(&Out, w, h, 3);
ipng = 0; ipng = 0;
for (idx=0; idx<globbuf.gl_pathc; idx++) { for (idx=0; idx<globbuf.gl_pathc; idx++) {
curpix = idx_values[idx].idx; cptr = globbuf.gl_pathv[idx];
cptr = globbuf.gl_pathv[curpix]; /* aliasing filename */
/* read the next file in B */ /* read the next file in B */
fprintf(stderr, "%5d / %5ld : loading %s\r", idx, fprintf(stderr, "loading %s\r", cptr);
globbuf.gl_pathc, cptr);
foo = fimg_load_from_dump(cptr, &B); foo = fimg_load_from_dump(cptr, &B);
if (foo) { if (foo) {
fprintf(stderr, "load %s from dump -> %d\n", cptr, foo); fprintf(stderr, "load #%d from dump -> %d\n", idx, foo);
continue; continue;
} }
value = idx_values[idx].value;
/* here, we can insert the input filter */ /* here, we can insert the input filter */
/* OK try it ... */ /* OK try it ... */
foo = crapulator(&B, infx, value/2.0); foo = crapulator(&B, 0, 256.7);
if (foo) { if (foo) {
fprintf(stderr, "crapulator failure %d\n", foo); fprintf(stderr, "crapulator failure %d\n", foo);
exit(1); 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<Nsteps; step++) { for (step=0; step<Nsteps; step++) {
coef = (float)step / (float)Nsteps; coef = (float)step / (float)Nsteps;
fimg_interpolate(pSecond, pFirst, &Out, coef); fimg_interpolate(pSecond, pFirst, &Out, coef);
/* here we can insert the output filter */ /* here we can insert the output filter */
if (rand() & 0x55) { kill_a_few_lines(&Out, 150.5, 5+(rand()%20));
kill_a_few_lines(&Out, value/2.0, 5+(rand()%20));
kill_a_few_lines(&Out, 0.0, 5+(rand()%20));
}
sprintf(line, "%s/%05d.png", outdir, ipng); sprintf(line, "%s/%05d.png", outdir, ipng);
foo = fimg_save_as_png(&Out, line, 0); foo = fimg_save_as_png(&Out, line, 0);
@ -189,7 +109,7 @@ for (idx=0; idx<globbuf.gl_pathc; idx++) {
#endif #endif
} }
fprintf(stderr, "\ngenerated %d png files\n", ipng); fprintf(stderr, "generated %d png files\n", ipng);
return 0; return 0;
} }
@ -231,8 +151,7 @@ if (4 != argc) {
nbrsteps = atoi(argv[3]); nbrsteps = atoi(argv[3]);
#define EFFECT 7 foo = interpolator(argv[1], argv[2], nbrsteps);
foo = interpolator(argv[1], argv[2], nbrsteps, EFFECT);
fprintf(stderr, "interpolator give a %d score\n", foo); fprintf(stderr, "interpolator give a %d score\n", foo);

View File

@ -3,52 +3,22 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include "../floatimg.h" #include "../floatimg.h"
#include "metriques.h"
extern int verbosity; extern int verbosity;
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
/*
* premier essai... int get_float_metric(FloatImg *pimg, float *where, int whot)
*/
int get_float_metric(FloatImg *pimg, float *where)
{ {
float means[4];
int foo;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %f %d )\n", __func__, pimg, where, whot); fprintf(stderr, ">>> %s ( %p %f %d )\n", __func__, pimg, where, whot);
#endif #endif
foo = fimg_meanvalues(pimg, means); *where = 0;
if (foo) {
fprintf(stderr, "fatal error in %s\n", __func__); return -1;
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;
} }
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */

View File

@ -4,9 +4,8 @@
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
/* first experiments */ /* first experiment */
int get_float_metric(FloatImg *pimg, float *where); int get_float_metric(FloatImg *pimg, float *where, int whot)
int get_float_metric_from_file(char *imgname, float *where);
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */