2020-11-02 01:25:00 +01:00
|
|
|
/*
|
|
|
|
* 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) {
|
2020-11-02 14:51:48 +01:00
|
|
|
fprintf(stderr, "%s: err %d on insert\n", __func__, foo);
|
2020-11-02 01:25:00 +01:00
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
sprintf(ligne, "p8/%05d.png", numero);
|
2020-11-02 22:20:54 +01:00
|
|
|
/* ^^^
|
|
|
|
XXX hardcoded value ? wtf ?
|
|
|
|
*/
|
2020-11-02 01:25:00 +01:00
|
|
|
foo = export_fifo(ligne, proc, step);
|
|
|
|
if (foo) {
|
2020-11-02 14:51:48 +01:00
|
|
|
fprintf(stderr, "%s: err %d on export\n", __func__, foo);
|
2020-11-02 01:25:00 +01:00
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
numero++; /* VERY IMPORTANT :) */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
2020-11-05 21:07:38 +01:00
|
|
|
int insert_blank(FloatImg *image, int nbre, int pproc, float fval)
|
2020-11-02 01:25:00 +01:00
|
|
|
{
|
|
|
|
int idx, foo;
|
|
|
|
|
|
|
|
fimg_clear(image);
|
|
|
|
for (idx=0; idx<nbre; idx++) {
|
2020-11-05 21:07:38 +01:00
|
|
|
fimg_vdeg_a(image, fval);
|
2020-11-04 17:18:58 +01:00
|
|
|
// brotche_rand48_b(image, drand48()*0.10, 1e5);
|
2020-11-02 01:25:00 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
2020-11-07 01:29:45 +01:00
|
|
|
#define BLANK 50
|
2020-11-02 01:25:00 +01:00
|
|
|
|
|
|
|
int demarre_la_machine(char *pattern, char *outdir, int szfifo,
|
2020-11-02 22:20:54 +01:00
|
|
|
int infx, int outfx, int step)
|
2020-11-02 01:25:00 +01:00
|
|
|
{
|
2020-11-04 17:18:58 +01:00
|
|
|
int foo, idx, width, height;
|
2020-11-02 01:25:00 +01:00
|
|
|
glob_t globbuf;
|
|
|
|
char *cptr;
|
|
|
|
FloatImg input;
|
|
|
|
double fin;
|
2020-11-05 21:07:38 +01:00
|
|
|
float maxvalue;
|
2020-11-04 17:18:58 +01:00
|
|
|
int datas[3];
|
2020-11-02 01:25:00 +01:00
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
2020-11-05 21:07:38 +01:00
|
|
|
fprintf(stderr, ">>> %s ( '%s' -> '%s' %d eff:%d:%d)\n", __func__,
|
|
|
|
pattern, outdir, szfifo, infx, outfx);
|
2020-11-02 01:25:00 +01:00
|
|
|
#endif
|
|
|
|
|
2020-11-04 10:42:02 +01:00
|
|
|
if (1 != step) fprintf(stderr, "\tstep is %d\n", step);
|
2020-11-02 01:25:00 +01:00
|
|
|
|
|
|
|
(void)fimg_timer_set(0);
|
|
|
|
|
2020-11-02 22:20:54 +01:00
|
|
|
if (infx) fprintf(stderr, "\tin fx #%d\n", infx);
|
|
|
|
else fprintf(stderr, "\tno in fx\n");
|
2020-11-02 01:25:00 +01:00
|
|
|
if (outfx) fprintf(stderr, "\tout fx #%d\n", outfx);
|
|
|
|
else fprintf(stderr, "\tno out fx\n");
|
|
|
|
|
2020-11-04 17:18:58 +01:00
|
|
|
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);
|
|
|
|
|
|
|
|
/* get the size of the inputs images */
|
|
|
|
foo = fimg_fileinfos(globbuf.gl_pathv[0], datas);
|
2020-11-05 21:07:38 +01:00
|
|
|
width = datas[0]; height = datas[1];
|
|
|
|
fprintf(stderr, "image size %dx%d\n", width, height);
|
|
|
|
|
|
|
|
fimg_create(&input, width, height, 3);
|
|
|
|
|
|
|
|
/* get the maximum value of the first pic */
|
|
|
|
foo = fimg_load_from_dump(globbuf.gl_pathv[0], &input);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "%s: err %d loading %s\n",
|
|
|
|
__func__, foo, globbuf.gl_pathv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
maxvalue = fimg_get_maxvalue(&input);
|
|
|
|
fprintf(stderr, "maxvalue %f\n", maxvalue);
|
2020-11-04 17:18:58 +01:00
|
|
|
|
|
|
|
foo = create_fifo(szfifo, width, height, FIMG_TYPE_RGB);
|
2020-11-02 01:25:00 +01:00
|
|
|
fprintf(stderr, "init fifo (%d slots) --> %d\n", szfifo, foo);
|
|
|
|
|
2020-11-05 21:07:38 +01:00
|
|
|
/* XXX inject a few strange pics in the fifo */
|
|
|
|
insert_blank(&input, BLANK, outfx, maxvalue);
|
2020-11-02 01:25:00 +01:00
|
|
|
|
|
|
|
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 */
|
2020-11-02 22:20:54 +01:00
|
|
|
foo = crapulator(&input, infx, 0.42);
|
2020-11-02 01:25:00 +01:00
|
|
|
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);
|
|
|
|
|
2020-11-05 21:07:38 +01:00
|
|
|
insert_blank(&input, BLANK*2, outfx, maxvalue);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PLEASE, FLUSH THE FIFO !
|
|
|
|
*/
|
2020-11-02 01:25:00 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-11-10 03:58:18 +01:00
|
|
|
return 8; /* why 9 ? */
|
2020-11-02 01:25:00 +01:00
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
2020-11-02 14:51:48 +01:00
|
|
|
void help(void)
|
|
|
|
{
|
|
|
|
puts("\tFONDERIE\noptions:");
|
|
|
|
|
|
|
|
puts("\t-g\tconvert to gray");
|
|
|
|
puts("\t-I\tinput glob pattern");
|
|
|
|
puts("\t-O\toutput directory");
|
|
|
|
puts("\t-T\tfifo size");
|
|
|
|
puts("\t-v\tincrease verbosity");
|
2020-11-02 22:20:54 +01:00
|
|
|
puts("\t-w\tinput effect");
|
2020-11-02 14:51:48 +01:00
|
|
|
puts("\t-x\toutput effect");
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
2020-11-02 01:25:00 +01:00
|
|
|
int main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int foo, opt;
|
|
|
|
int fifosize = 10;
|
|
|
|
char *in_pattern = "capture/?????.fimg";
|
|
|
|
char *out_dir = "p8";
|
2020-11-02 14:51:48 +01:00
|
|
|
int in_effect = 0;
|
2020-11-02 01:25:00 +01:00
|
|
|
int out_effect = 0;
|
|
|
|
int steps = 1;
|
|
|
|
|
2020-11-02 22:20:54 +01:00
|
|
|
fprintf(stderr, "*** %s :\n\tcompiled by tTh, %s %s\n\tpid %d\n",
|
|
|
|
argv[0], __DATE__, __TIME__, getpid());
|
2020-11-02 01:25:00 +01:00
|
|
|
fimg_print_version(2);
|
|
|
|
|
2020-11-04 10:42:02 +01:00
|
|
|
while ((opt = getopt(argc, argv, "ghI:O:s:T:vw:x:")) != -1) {
|
2020-11-02 01:25:00 +01:00
|
|
|
switch(opt) {
|
|
|
|
|
|
|
|
case 'g': convert_to_gray = 1;
|
|
|
|
break;
|
2020-11-02 14:51:48 +01:00
|
|
|
case 'h': help();
|
|
|
|
break;
|
2020-11-02 01:25:00 +01:00
|
|
|
case 'I': in_pattern = optarg;
|
|
|
|
break;
|
|
|
|
case 'O': out_dir = optarg;
|
|
|
|
break;
|
|
|
|
case 'T': fifosize = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'v': verbosity++;
|
|
|
|
break;
|
2020-11-02 22:20:54 +01:00
|
|
|
case 'w': in_effect = atoi(optarg);
|
|
|
|
break;
|
2020-11-02 01:25:00 +01:00
|
|
|
case 'x': out_effect = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 's': steps = atoi(optarg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-02 22:20:54 +01:00
|
|
|
foo = demarre_la_machine(in_pattern, out_dir, fifosize, in_effect,
|
|
|
|
out_effect, steps);
|
2020-11-02 01:25:00 +01:00
|
|
|
fprintf(stderr, "retour du big-run de la machine -> %d\n", foo);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|