importing the Interpolator for R325 project

This commit is contained in:
le vieux 2020-11-09 20:27:57 +01:00
parent 6b424ea72a
commit 538a8ffa82
6 changed files with 154 additions and 13 deletions

1
.gitignore vendored
View File

@ -65,4 +65,5 @@ tools/*.tiff
Fonderie/*.o
Fonderie/fonderie
Fonderie/interpolator

View File

@ -20,11 +20,10 @@ sfx.o: sfx.c ${DEPS} Makefile
gcc ${COPT} -c $<
# ---------------------------------------------------------
#
# another way...
TOTAR = *.c *.h Makefile \
*.sh
interpolator: interpolator.c Makefile
gcc ${COPT} $< ${LIBS} -lz -o $@
# ---------------------------------------------------------

View File

@ -1,11 +1,11 @@
# Fonderie
# Fonderie et Interpolator
Avec toutes ces fonctions disponibles et `grabvidseq`, nous
savons faire des images **floues***. L'étape suivante, les plus
pervers d'entre vous le savent déja, est celle de la création
de **films flous**.
## fonderie
## Fonderie
Le programme principal, utilisé à partir de la ligne de commande
avec une foule d'options aux mnémoniques abscons.
@ -65,5 +65,8 @@ aussi bien en entrée qu'en sortie. Il est, à l'heure actuelle,
assez rudimentaire, avec un paramétrage simpliste, et un manque
criant de documentation...
## Interpolator
**Use the source, Luke**

118
Fonderie/interpolator.c Normal file
View File

@ -0,0 +1,118 @@
/*
* 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"
// XXX #include "fonctions.h"
int verbosity;
/* -------------------------------------------------------------- */
int interpolator(char *pattern, char *outdir, int Nsteps)
{
FloatImg A, B, Out, *pFirst, *pSecond, *pTmp;
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);
pTmp = NULL;
ipng = 0;
for (idx=0; idx<globbuf.gl_pathc; idx++) {
cptr = globbuf.gl_pathv[idx];
/* read the next file in B */
fprintf(stderr, "loading %s\n", cptr);
foo = fimg_load_from_dump(cptr, &B);
if (foo) {
fprintf(stderr, "load #%d from dump -> %d\n", idx, foo);
continue;
}
for (step=0; step<Nsteps; step++) {
coef = (float)step / (float)Nsteps;
fimg_interpolate(pSecond, pFirst, &Out, coef);
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;
/* THIS CODE DON'T WORK !!! */
#endif
}
fprintf(stderr, "generated %d png files\n", ipng);
return 0;
}
/* -------------------------------------------------------------- */
int main (int argc, char *argv[])
{
int foo;
int nbrsteps = 9;
fprintf(stderr, "*** %s : compiled by tTh, %s %s\n", __FILE__,
__DATE__, __TIME__);
fimg_print_version(2);
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);
fprintf(stderr, "interpolator -> %d\n", foo);
return 0;
}
/* -------------------------------------------------------------- */

View File

@ -56,6 +56,7 @@ int to_gray = 0;
char *output_file = "out.fimg";
FloatImg accu, temp;
int src_loaded = 0;
float vals[6];
g_width = g_height = 0;
@ -74,11 +75,9 @@ fprintf(stderr, "argc = %d, optind = %d\n", argc, optind);
#endif
for (idx=optind; idx<argc; idx++) {
#if DEBUG_LEVEL
fprintf(stderr, "%5d %s\n", idx, argv[idx]);
#endif
foo = testfile(argv[idx]);
if (foo) {
fprintf(stderr, "testfile %s -> %d\n", argv[idx],foo);
@ -98,12 +97,9 @@ for (idx=optind; idx<argc; idx++) {
}
fimg_add_2(&temp, &accu);
}
}
if (to_gray) {
foo = fimg_desaturate(&accu, &accu, 0);
if (foo) {
fprintf(stderr, "desaturate: error %d\n", foo);
@ -116,6 +112,21 @@ if (foo) {
exit(1);
}
if (verbosity) {
/* show some numbers about resultant picture */
foo = fimg_get_minmax_rgb(&accu, vals);
if (foo) {
fprintf(stderr, "err %d on fimg_get_minmax_rgb\n", foo);
return foo;
}
printf("Rmin %12.4g Rmax %12.4g delta %12g\n",
vals[0], vals[1], vals[1]-vals[0]);
printf("Gmin %12.4g Gmax %12.4g %12g\n",
vals[2], vals[3], vals[3]-vals[2]);
printf("Bmin %12.4g Bmax %12.4g %12g\n",
vals[4], vals[5], vals[5]-vals[4]);
}
return 0;
}
/* --------------------------------------------------------------------- */

View File

@ -1,5 +1,10 @@
/*
* PNG ---> FIMG
*
* Attention : certains fichiers PNG ne passent pas cette
* moulinette, mais le bug est dans la bibliotheque de
* fonctions 'libpnglite'. Une solution de remplacement
* devrait etre a l'etude un de ces jours...
*/
#include <stdio.h>
@ -17,6 +22,10 @@ int main(int argc, char *argv[])
FloatImg fimg;
int foo;
/*
* pas de traitement des options ?
*/
if (3 != argc) {
fimg_print_version(1);
fprintf(stderr, "usage:\n\t%s foo.png bar.fimg\n", argv[0]);
@ -31,7 +40,7 @@ if (foo) {
exit(1);
}
fimg_describe(&fimg, argv[2]);
if (verbosity) fimg_describe(&fimg, argv[2]);
foo = fimg_dump_to_file(&fimg, argv[2], 0);
fprintf(stderr, "save as fimg -> %d\n", foo);