FloatImg/Fonderie/fonderie.c

192 lines
4.0 KiB
C

/*
* FONDERIE
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <glob.h>
#include <floatimg.h>
#include "fonctions.h"
#include "crapulator.h"
int verbosity;
int convert_to_gray;
/* -------------------------------------------------------------- */
int traite_une_image(FloatImg *image, int proc, int step)
{
static int numero;
int foo;
char ligne[200];
/* here, we put the picz in the fifo machinery */
foo = insert_picture(image);
if (foo) {
fprintf(stderr, "%s : err %d on insert\n", __func__, foo);
return foo;
}
sprintf(ligne, "p8/%05d.png", numero);
foo = export_fifo(ligne, proc, step);
if (foo) {
fprintf(stderr, "%s : err %d on export\n", __func__, foo);
return foo;
}
numero++; /* VERY IMPORTANT :) */
return 0;
}
/* -------------------------------------------------------------- */
int insert_blank(FloatImg *image, int nbre, int pproc)
{
int idx, foo;
fimg_clear(image);
for (idx=0; idx<nbre; idx++) {
fimg_hdeg_a(image, 16.64);
brotche_rand48_b(image, drand48()*0.10, 1e5);
if ((foo=traite_une_image(image, pproc, 1))) {
fprintf(stderr, "%s : err %d from 'traite_une_image'\n",
__func__, foo);
break;
}
printf("\t%c\r", "ABCDEF"[idx%6]); fflush(stdout);
}
puts("");
return 0;
}
/* -------------------------------------------------------------- */
#define BLANK 30
int demarre_la_machine(char *pattern, char *outdir, int szfifo,
int outfx, int step)
{
int foo, idx;
glob_t globbuf;
char *cptr;
FloatImg input;
double fin;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' -> '%s' %d )\n", __func__,
pattern, outdir, szfifo);
#endif
fprintf(stderr, "\tstep is %d\n", step);
(void)fimg_timer_set(0);
if (outfx) fprintf(stderr, "\tout fx #%d\n", outfx);
else fprintf(stderr, "\tno out fx\n");
foo = create_fifo(szfifo, 640, 480, FIMG_TYPE_RGB);
fprintf(stderr, "init fifo (%d slots) --> %d\n", szfifo, foo);
fimg_create(&input, 640, 480, 3);
/* XXX inject a few stange pics in the fifo */
insert_blank(&input, BLANK, outfx);
memset(&globbuf, 0, sizeof(glob_t));
foo = glob(pattern, 0, NULL, &globbuf);
fprintf(stderr, "glob '%s' -> %d, %ld files found\n", pattern, foo,
globbuf.gl_pathc);
for (idx=0; idx<globbuf.gl_pathc; idx++) {
cptr = globbuf.gl_pathv[idx];
/* first step : read the current grabed picz from disk,
and put it in our private buffer */
foo = fimg_load_from_dump(cptr, &input);
if (foo) {
fprintf(stderr, "load #%d from dump -> %d\n", idx, foo);
continue;
}
/* ========================= */
/* FSCKING INPUT FILTER HERE */
foo = crapulator(&input, idx);
if (foo) {
fprintf(stderr, "%s crapulator -> %d\n", __func__, foo);
exit(1);
}
foo = traite_une_image(&input, outfx, step);
if (foo) {
fprintf(stderr, "traitement %s -> %d WTF?\n", cptr, foo);
break;
}
fprintf(stderr, "\t%5d\r", idx);
}
fputs("\n", stderr);
insert_blank(&input, BLANK, outfx);
fin = fimg_timer_get(0);
if (idx) {
fprintf(stderr, "\nelapsed %.2f seconds, %.2f s/pic\n", fin, fin/idx);
}
else {
fprintf(stderr, "\nelapsed %.2f seconds\n", fin);
}
return 8;
}
/* -------------------------------------------------------------- */
int main (int argc, char *argv[])
{
int foo, opt;
int fifosize = 10;
char *in_pattern = "capture/?????.fimg";
char *out_dir = "p8";
int out_effect = 0;
int steps = 1;
// float maxlevel = 2500.0;
fprintf(stderr, "*** %s : compiled by tTh, %s %s\n", argv[0],
__DATE__, __TIME__);
fimg_print_version(2);
while ((opt = getopt(argc, argv, "gI:O:s:T:vx:")) != -1) {
switch(opt) {
case 'g': convert_to_gray = 1;
break;
case 'I': in_pattern = optarg;
break;
case 'O': out_dir = optarg;
break;
case 'T': fifosize = atoi(optarg);
break;
case 'v': verbosity++;
break;
case 'x': out_effect = atoi(optarg);
break;
case 's': steps = atoi(optarg);
break;
}
}
foo = demarre_la_machine(in_pattern, out_dir, fifosize, out_effect, steps);
fprintf(stderr, "retour du big-run de la machine -> %d\n", foo);
return 0;
}
/* -------------------------------------------------------------- */