first semi-good run of the Interpolator
This commit is contained in:
@@ -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; 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;
|
||||
glob_t globbuf;
|
||||
int foo, idx, ipng, w, h, step;
|
||||
int curpix;
|
||||
int iarray[3];
|
||||
char *cptr, line[200];
|
||||
float coef;
|
||||
float coef, value;
|
||||
IdxValue *idx_values;
|
||||
|
||||
fprintf(stderr, "\nfrom %s to %s with %d steps.\n", pattern, outdir, Nsteps);
|
||||
fprintf(stderr, "\nfrom '%s' to '%s' with %d steps.\n",
|
||||
pattern, outdir, Nsteps);
|
||||
|
||||
memset(&globbuf, 0, sizeof(glob_t));
|
||||
foo = glob(pattern, 0, NULL, &globbuf);
|
||||
@@ -44,6 +116,10 @@ if (0 == globbuf.gl_pathc) {
|
||||
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);
|
||||
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<globbuf.gl_pathc; idx++) {
|
||||
|
||||
cptr = globbuf.gl_pathv[idx];
|
||||
curpix = idx_values[idx].idx;
|
||||
|
||||
cptr = globbuf.gl_pathv[curpix]; /* aliasing filename */
|
||||
|
||||
/* read the next file in B */
|
||||
fprintf(stderr, "loading %s\r", cptr);
|
||||
fprintf(stderr, "%5d / %5ld : loading %s\r", idx,
|
||||
globbuf.gl_pathc, cptr);
|
||||
foo = fimg_load_from_dump(cptr, &B);
|
||||
if (foo) {
|
||||
fprintf(stderr, "load #%d from dump -> %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<Nsteps; step++) {
|
||||
coef = (float)step / (float)Nsteps;
|
||||
fimg_interpolate(pSecond, pFirst, &Out, coef);
|
||||
|
||||
/* here we can insert the output filter */
|
||||
kill_a_few_lines(&Out, 150.5, 5+(rand()%20));
|
||||
if (rand() & 0x55) {
|
||||
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);
|
||||
foo = fimg_save_as_png(&Out, line, 0);
|
||||
@@ -109,7 +189,7 @@ for (idx=0; idx<globbuf.gl_pathc; idx++) {
|
||||
#endif
|
||||
}
|
||||
|
||||
fprintf(stderr, "generated %d png files\n", ipng);
|
||||
fprintf(stderr, "\ngenerated %d png files\n", ipng);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -151,7 +231,8 @@ if (4 != argc) {
|
||||
|
||||
nbrsteps = atoi(argv[3]);
|
||||
|
||||
foo = interpolator(argv[1], argv[2], nbrsteps);
|
||||
#define EFFECT 7
|
||||
foo = interpolator(argv[1], argv[2], nbrsteps, EFFECT);
|
||||
|
||||
fprintf(stderr, "interpolator give a %d score\n", foo);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user