2020-11-09 20:27:57 +01:00
|
|
|
/*
|
|
|
|
* INTERPOLATOR 2070
|
|
|
|
*
|
|
|
|
* Don't use that software in real life !
|
|
|
|
*
|
|
|
|
* 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-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
|
|
|
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
int interpolator(char *pattern, char *outdir, int Nsteps)
|
|
|
|
{
|
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;
|
|
|
|
int iarray[3];
|
|
|
|
char *cptr, line[200];
|
|
|
|
float coef;
|
|
|
|
|
|
|
|
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);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
foo = fimg_fileinfos(globbuf.gl_pathv[0], iarray);
|
|
|
|
w = iarray[0], h = iarray[1];
|
|
|
|
fprintf(stderr, "\tfirst image size : %dx%d\n", w, h);
|
|
|
|
|
|
|
|
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++) {
|
|
|
|
|
|
|
|
cptr = globbuf.gl_pathv[idx];
|
|
|
|
|
|
|
|
/* read the next file in B */
|
2020-11-10 03:58:18 +01:00
|
|
|
fprintf(stderr, "loading %s\r", cptr);
|
2020-11-09 20:27:57 +01:00
|
|
|
foo = fimg_load_from_dump(cptr, &B);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "load #%d from dump -> %d\n", idx, foo);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-11-10 00:50:25 +01:00
|
|
|
/* here, we can insert the input filter */
|
|
|
|
/* OK try it ... */
|
2020-11-10 03:58:18 +01:00
|
|
|
foo = crapulator(&B, 0, 256.7);
|
2020-11-10 00:50:25 +01:00
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "crapulator failure %d\n", foo);
|
|
|
|
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-10 00:50:25 +01:00
|
|
|
/* here we can insert the output filter */
|
2020-11-10 03:58:18 +01:00
|
|
|
kill_a_few_lines(&Out, 3.14159, 500);
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "generated %d png files\n", ipng);
|
|
|
|
|
|
|
|
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-09 20:27:57 +01:00
|
|
|
|
|
|
|
fprintf(stderr, "*** %s : compiled by tTh, %s %s\n", __FILE__,
|
|
|
|
__DATE__, __TIME__);
|
|
|
|
fimg_print_version(2);
|
|
|
|
|
2020-11-10 03:58:18 +01:00
|
|
|
while ((opt = getopt(argc, argv, "v")) != -1) {
|
|
|
|
switch(opt) {
|
|
|
|
case 'v': verbosity++; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TO BE CONTINUED *****/
|
|
|
|
|
2020-11-09 20:27:57 +01:00
|
|
|
if (4 != argc) {
|
|
|
|
fprintf(stderr, "args: <in globpattern> <out dir> <nbrsteep>\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
nbrsteps = atoi(argv[3]);
|
|
|
|
|
|
|
|
foo = interpolator(argv[1], argv[2], nbrsteps);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|