2020-11-09 20:27:57 +01:00
|
|
|
/*
|
|
|
|
* INTERPOLATOR 2070
|
|
|
|
*
|
2020-11-12 23:36:06 +01:00
|
|
|
* +---------------------------------------+
|
|
|
|
* ! Do not use that software in real life !
|
|
|
|
* +---------------------------------------+
|
2020-11-09 20:27:57 +01:00
|
|
|
*
|
|
|
|
* imported in FloatImg Mon Nov 9 19:08:57 CET 2020
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <glob.h>
|
|
|
|
|
|
|
|
#include "../floatimg.h"
|
|
|
|
|
2020-11-10 03:58:18 +01:00
|
|
|
#include "glitches.h"
|
2020-11-10 00:50:25 +01:00
|
|
|
#include "crapulator.h"
|
2020-11-12 23:36:06 +01:00
|
|
|
#include "metriques.h"
|
2020-11-10 00:50:25 +01:00
|
|
|
|
2020-11-09 20:27:57 +01:00
|
|
|
// XXX #include "fonctions.h"
|
|
|
|
|
|
|
|
int verbosity;
|
2020-11-10 00:50:25 +01:00
|
|
|
int convert_to_gray; /* needed by fonctions.c */
|
2020-11-09 20:27:57 +01:00
|
|
|
|
|
|
|
/* -------------------------------------------------------------- */
|
2020-11-12 23:36:06 +01:00
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
|
2020-11-15 11:47:37 +01:00
|
|
|
int tentative_triage(glob_t *ptr_glob, IdxValue **ptr_idxval, int method)
|
2020-11-12 23:36:06 +01:00
|
|
|
{
|
|
|
|
int idx, foo, nombre;
|
|
|
|
float metrique;
|
|
|
|
char *filename;
|
|
|
|
IdxValue *idxvalues;
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
2020-11-15 11:47:37 +01:00
|
|
|
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, ptr_glob,
|
|
|
|
ptr_idxval, method);
|
2020-11-12 23:36:06 +01:00
|
|
|
#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;
|
|
|
|
}
|
2020-11-15 11:47:37 +01:00
|
|
|
if (verbosity)
|
|
|
|
fprintf(stderr, "%5d %s %f\n", idx, filename, metrique);
|
2020-11-12 23:36:06 +01:00
|
|
|
idxvalues[idx].idx = idx;
|
|
|
|
idxvalues[idx].value = metrique;
|
|
|
|
}
|
|
|
|
|
2020-11-15 11:47:37 +01:00
|
|
|
if (method) {
|
|
|
|
/* and now, we can massage all our datas */
|
|
|
|
qsort(idxvalues, nombre, sizeof(IdxValue), cmp_idxvalues);
|
|
|
|
}
|
2020-11-12 23:36:06 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
2020-11-15 11:47:37 +01:00
|
|
|
int interpolator(char *pattern, char *outdir, int Nsteps,
|
|
|
|
int infx, int outfx, int sort)
|
2020-11-09 20:27:57 +01:00
|
|
|
{
|
2020-11-10 03:58:18 +01:00
|
|
|
FloatImg A, B, Out, *pFirst, *pSecond;
|
2020-11-09 20:27:57 +01:00
|
|
|
glob_t globbuf;
|
|
|
|
int foo, idx, ipng, w, h, step;
|
2020-11-12 23:36:06 +01:00
|
|
|
int curpix;
|
2020-11-09 20:27:57 +01:00
|
|
|
int iarray[3];
|
|
|
|
char *cptr, line[200];
|
2020-11-12 23:36:06 +01:00
|
|
|
float coef, value;
|
|
|
|
IdxValue *idx_values;
|
2020-11-09 20:27:57 +01:00
|
|
|
|
2020-11-12 23:36:06 +01:00
|
|
|
fprintf(stderr, "\nfrom '%s' to '%s' with %d steps.\n",
|
|
|
|
pattern, outdir, Nsteps);
|
2020-11-09 20:27:57 +01:00
|
|
|
|
|
|
|
memset(&globbuf, 0, sizeof(glob_t));
|
|
|
|
foo = glob(pattern, 0, NULL, &globbuf);
|
|
|
|
fprintf(stderr, "globbing '%s' -> %d, %ld files found\n",
|
|
|
|
pattern, foo, globbuf.gl_pathc);
|
|
|
|
|
|
|
|
if (0 == globbuf.gl_pathc) {
|
|
|
|
fprintf(stderr, "%s : no file found, aborting\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-11-12 23:36:06 +01:00
|
|
|
idx_values = NULL;
|
2020-11-15 11:47:37 +01:00
|
|
|
foo = tentative_triage(&globbuf, &idx_values, sort);
|
2020-11-12 23:36:06 +01:00
|
|
|
fprintf(stderr, "\tTRI of %p -> %d\n\n", idx_values, foo);
|
|
|
|
|
2020-11-09 20:27:57 +01:00
|
|
|
foo = fimg_fileinfos(globbuf.gl_pathv[0], iarray);
|
2020-11-10 14:00:22 +01:00
|
|
|
if (FIMG_TYPE_RGB != iarray[2]) {
|
|
|
|
fprintf(stderr, "can work only on RGB fimg picture, was %d\n",
|
|
|
|
iarray[2]);
|
|
|
|
exit(1);
|
|
|
|
}
|
2020-11-09 20:27:57 +01:00
|
|
|
w = iarray[0], h = iarray[1];
|
2020-11-10 14:00:22 +01:00
|
|
|
fprintf(stderr, "first image size : %dx%d\n", w, h);
|
2020-11-09 20:27:57 +01:00
|
|
|
|
|
|
|
fimg_create(&A, w, h, 3); pFirst = &A;
|
|
|
|
fimg_create(&B, w, h, 3); pSecond = &B;
|
|
|
|
fimg_create(&Out, w, h, 3);
|
|
|
|
|
|
|
|
ipng = 0;
|
|
|
|
for (idx=0; idx<globbuf.gl_pathc; idx++) {
|
|
|
|
|
2020-11-12 23:36:06 +01:00
|
|
|
curpix = idx_values[idx].idx;
|
|
|
|
|
|
|
|
cptr = globbuf.gl_pathv[curpix]; /* aliasing filename */
|
2020-11-09 20:27:57 +01:00
|
|
|
|
|
|
|
/* read the next file in B */
|
2020-11-12 23:36:06 +01:00
|
|
|
fprintf(stderr, "%5d / %5ld : loading %s\r", idx,
|
|
|
|
globbuf.gl_pathc, cptr);
|
2020-11-09 20:27:57 +01:00
|
|
|
foo = fimg_load_from_dump(cptr, &B);
|
|
|
|
if (foo) {
|
2020-11-12 23:36:06 +01:00
|
|
|
fprintf(stderr, "load %s from dump -> %d\n", cptr, foo);
|
2020-11-09 20:27:57 +01:00
|
|
|
continue;
|
|
|
|
}
|
2020-11-12 23:36:06 +01:00
|
|
|
value = idx_values[idx].value;
|
2020-11-09 20:27:57 +01:00
|
|
|
|
2020-11-10 00:50:25 +01:00
|
|
|
/* here, we can insert the input filter */
|
2020-11-15 11:47:37 +01:00
|
|
|
/* OK try it ... */
|
2020-11-12 23:36:06 +01:00
|
|
|
foo = crapulator(&B, infx, value/2.0);
|
2020-11-10 00:50:25 +01:00
|
|
|
if (foo) {
|
2020-11-15 11:47:37 +01:00
|
|
|
fprintf(stderr, "in fx crapulator failure %d\n", foo);
|
2020-11-10 00:50:25 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2020-11-09 20:27:57 +01:00
|
|
|
for (step=0; step<Nsteps; step++) {
|
|
|
|
coef = (float)step / (float)Nsteps;
|
|
|
|
fimg_interpolate(pSecond, pFirst, &Out, coef);
|
|
|
|
|
2020-11-15 21:31:02 +01:00
|
|
|
/* here we can insert the OUTPUT filter */
|
2020-11-15 11:47:37 +01:00
|
|
|
foo = crapulator(&Out, outfx, value);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "\nout fx %d crapulator failure %d\n",
|
|
|
|
outfx, foo);
|
|
|
|
exit(1);
|
2020-11-12 23:36:06 +01:00
|
|
|
}
|
2020-11-10 00:50:25 +01:00
|
|
|
|
2020-11-09 20:27:57 +01:00
|
|
|
sprintf(line, "%s/%05d.png", outdir, ipng);
|
|
|
|
foo = fimg_save_as_png(&Out, line, 0);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "err saving %s\n", line);
|
|
|
|
return -8;
|
|
|
|
}
|
|
|
|
ipng++;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
/* temporary hack : move datas */
|
|
|
|
fimg_copy_data(&B, &A);
|
|
|
|
#else
|
|
|
|
/* swap pointers to the two picz */
|
|
|
|
pTmp = pSecond;
|
|
|
|
pSecond = pFirst;
|
|
|
|
pFirst = pTmp;
|
2020-11-10 00:50:25 +01:00
|
|
|
/* XXX THIS CODE DON'T WORK !!! */
|
2020-11-09 20:27:57 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-11-12 23:36:06 +01:00
|
|
|
fprintf(stderr, "\ngenerated %d png files\n", ipng);
|
2020-11-09 20:27:57 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
2020-11-10 03:58:18 +01:00
|
|
|
void help(void)
|
|
|
|
{
|
|
|
|
puts("\tINTERPOLATOR\noptions:");
|
|
|
|
|
|
|
|
/* may be we can make options incoherent, like
|
|
|
|
* the options of 'fonderie' software ?
|
|
|
|
*/
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
2020-11-09 20:27:57 +01:00
|
|
|
int main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int foo;
|
|
|
|
int nbrsteps = 9;
|
2020-11-10 03:58:18 +01:00
|
|
|
int opt;
|
2020-11-15 11:47:37 +01:00
|
|
|
int inFx = 0;
|
|
|
|
int outFx = 0;
|
|
|
|
int sort = 0;
|
2020-11-09 20:27:57 +01:00
|
|
|
|
|
|
|
fprintf(stderr, "*** %s : compiled by tTh, %s %s\n", __FILE__,
|
|
|
|
__DATE__, __TIME__);
|
|
|
|
fimg_print_version(2);
|
|
|
|
|
2020-11-15 11:47:37 +01:00
|
|
|
while ((opt = getopt(argc, argv, "hS:vw:x:")) != -1) {
|
2020-11-10 03:58:18 +01:00
|
|
|
switch(opt) {
|
2020-11-10 14:00:22 +01:00
|
|
|
case 'h': help(); break;
|
2020-11-15 11:47:37 +01:00
|
|
|
case 'S': sort = atoi(optarg); break;
|
2020-11-10 03:58:18 +01:00
|
|
|
case 'v': verbosity++; break;
|
2020-11-15 11:47:37 +01:00
|
|
|
case 'w': inFx = atoi(optarg); break;
|
|
|
|
case 'x': outFx = atoi(optarg); break;
|
2020-11-10 03:58:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-15 11:47:37 +01:00
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, "%s : argc = %d, optind = %d\n", argv[0], argc, optind);
|
|
|
|
#endif
|
2020-11-10 03:58:18 +01:00
|
|
|
|
2020-11-15 11:47:37 +01:00
|
|
|
if (3 != (argc-optind)) {
|
|
|
|
fprintf(stderr, "args: [options] <inglob> <outdir> <nbsteep>\n");
|
2020-11-09 20:27:57 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2020-11-15 11:47:37 +01:00
|
|
|
nbrsteps = atoi(argv[optind+2]);
|
|
|
|
foo = interpolator(argv[optind], argv[optind+1], nbrsteps,
|
|
|
|
inFx, outFx, sort);
|
2020-11-09 20:27:57 +01:00
|
|
|
|
2020-11-10 03:58:18 +01:00
|
|
|
fprintf(stderr, "interpolator give a %d score\n", foo);
|
2020-11-09 20:27:57 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|