2020-11-02 01:25:00 +01:00
|
|
|
/*
|
|
|
|
* FONDERIE
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2021-05-20 09:31:28 +02:00
|
|
|
#include <stdint.h>
|
2020-11-02 01:25:00 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <glob.h>
|
2021-01-25 17:18:44 +01:00
|
|
|
#include "../floatimg.h"
|
2020-11-02 01:25:00 +01:00
|
|
|
|
2021-04-02 19:25:20 +02:00
|
|
|
#include "fifo.h"
|
2020-11-15 11:47:37 +01:00
|
|
|
#include "glitches.h"
|
2020-11-02 01:25:00 +01:00
|
|
|
#include "crapulator.h"
|
2020-12-15 17:49:12 +01:00
|
|
|
#include "filterstack.h"
|
2020-11-02 01:25:00 +01:00
|
|
|
|
|
|
|
int verbosity;
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------- */
|
2021-04-03 05:37:03 +02:00
|
|
|
/*
|
|
|
|
* this is the real worker ? or just a wrapper ?
|
|
|
|
*/
|
|
|
|
int traite_une_image(FloatImg *image, char *outd)
|
2020-11-02 01:25:00 +01:00
|
|
|
{
|
|
|
|
static int numero;
|
|
|
|
int foo;
|
|
|
|
char ligne[200];
|
|
|
|
|
2021-04-03 05:37:03 +02:00
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, "\n>>> %s ( %p '%s' )\n", __func__, image, outd);
|
|
|
|
#endif
|
|
|
|
|
2020-11-02 01:25:00 +01:00
|
|
|
/* 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;
|
|
|
|
}
|
2021-04-02 04:16:26 +02:00
|
|
|
|
2021-04-03 05:37:03 +02:00
|
|
|
/* and now, we pull the result on the magic computation
|
|
|
|
*/
|
2020-11-20 19:06:08 +01:00
|
|
|
sprintf(ligne, "%s/%05d.png", outd, numero);
|
2021-04-03 05:37:03 +02:00
|
|
|
if (verbosity > 1) fprintf(stderr, " exporting to '%s'\n", ligne);
|
|
|
|
|
|
|
|
foo = export_fifo(ligne, 1);
|
2020-11-02 01:25:00 +01:00
|
|
|
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 :) */
|
2021-04-03 05:37:03 +02:00
|
|
|
|
2020-11-02 01:25:00 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
2021-04-03 05:37:03 +02:00
|
|
|
int insert_blank(FloatImg *image, int nbre, char *outd)
|
2020-11-02 01:25:00 +01:00
|
|
|
{
|
|
|
|
int idx, foo;
|
2021-02-22 14:44:02 +01:00
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
2021-04-03 05:37:03 +02:00
|
|
|
fprintf(stderr, ">>> %s ( %p %d '%s' )\n", __func__,
|
|
|
|
image, nbre, outd);
|
2021-02-22 14:44:02 +01:00
|
|
|
#endif
|
|
|
|
|
2020-11-02 01:25:00 +01:00
|
|
|
fimg_clear(image);
|
|
|
|
for (idx=0; idx<nbre; idx++) {
|
2021-04-03 05:37:03 +02:00
|
|
|
if ((foo=traite_une_image(image, outd))) {
|
2020-11-02 01:25:00 +01:00
|
|
|
fprintf(stderr, "%s : err %d from 'traite_une_image'\n",
|
|
|
|
__func__, foo);
|
|
|
|
break;
|
|
|
|
}
|
2021-02-22 14:44:02 +01:00
|
|
|
printf("\t%c\r", "ABCDEFGH"[idx%8]); fflush(stdout);
|
2020-11-02 01:25:00 +01:00
|
|
|
}
|
|
|
|
puts("");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int demarre_la_machine(char *pattern, char *outdir, int szfifo,
|
2021-04-24 00:16:23 +02:00
|
|
|
int outfmt, int blk)
|
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
|
2021-04-03 05:37:03 +02:00
|
|
|
fprintf(stderr, "\n>>> %s ( '%s' -> '%s' %d )\n", __func__,
|
|
|
|
pattern, outdir, szfifo);
|
2020-11-02 01:25:00 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
(void)fimg_timer_set(0);
|
|
|
|
|
2020-11-04 17:18:58 +01:00
|
|
|
memset(&globbuf, 0, sizeof(glob_t));
|
|
|
|
foo = glob(pattern, 0, NULL, &globbuf);
|
2020-11-20 22:25:30 +01:00
|
|
|
if (foo) {
|
2020-12-07 10:00:54 +01:00
|
|
|
fprintf(stderr, "glob (%s) failure %d\n", pattern, foo);
|
2020-11-20 22:25:30 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2020-12-06 11:13:06 +01:00
|
|
|
fprintf(stderr, "glob '%s' -> %d, %d files found\n", pattern, foo,
|
|
|
|
(int)globbuf.gl_pathc);
|
2020-11-04 17:18:58 +01:00
|
|
|
|
|
|
|
/* 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];
|
2024-03-25 12:45:15 +01:00
|
|
|
if (verbosity) fprintf(stderr, "first image size %dx%d\n", width, height);
|
2020-11-05 21:07:38 +01:00
|
|
|
|
|
|
|
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);
|
2024-03-25 12:45:15 +01:00
|
|
|
if (verbosity) fprintf(stderr, "first image maxvalue %f\n", maxvalue);
|
2020-11-04 17:18:58 +01:00
|
|
|
|
|
|
|
foo = create_fifo(szfifo, width, height, FIMG_TYPE_RGB);
|
2024-03-25 12:45:15 +01:00
|
|
|
if (verbosity) fprintf(stderr, "init fifo (%d slots) = %d\n", szfifo, foo);
|
2020-11-02 01:25:00 +01:00
|
|
|
|
2020-11-05 21:07:38 +01:00
|
|
|
/* XXX inject a few strange pics in the fifo */
|
2021-04-03 05:37:03 +02:00
|
|
|
insert_blank(&input, blk, outdir);
|
2020-11-02 01:25:00 +01:00
|
|
|
|
|
|
|
for (idx=0; idx<globbuf.gl_pathc; idx++) {
|
2021-04-03 05:37:03 +02:00
|
|
|
|
2020-11-02 01:25:00 +01:00
|
|
|
cptr = globbuf.gl_pathv[idx];
|
|
|
|
/* first step : read the current grabed picz from disk,
|
|
|
|
and put it in our private buffer */
|
2021-04-03 05:37:03 +02:00
|
|
|
// fprintf(stderr, "\n######### loading '%s'\n", cptr);
|
2020-11-02 01:25:00 +01:00
|
|
|
foo = fimg_load_from_dump(cptr, &input);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "load #%d from dump -> %d\n", idx, foo);
|
|
|
|
continue;
|
|
|
|
}
|
2020-11-15 20:15:56 +01:00
|
|
|
|
|
|
|
/* fscking input filter here */
|
2021-04-02 04:16:26 +02:00
|
|
|
foo = filterstack_run(0, &input, 0);
|
2020-11-02 01:25:00 +01:00
|
|
|
if (foo) {
|
2020-12-15 17:49:12 +01:00
|
|
|
fprintf(stderr, "%s: input filter -> %d\n", __func__, foo);
|
2020-11-02 01:25:00 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
2021-05-10 00:14:45 +02:00
|
|
|
#if 0
|
|
|
|
if (idx==42) fimg_dump_to_file(&input, "inputXXX.fimg", 0);
|
|
|
|
#endif
|
2021-04-03 05:37:03 +02:00
|
|
|
foo = traite_une_image(&input, outdir);
|
2021-04-02 04:16:26 +02:00
|
|
|
|
2020-11-02 01:25:00 +01:00
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "traitement %s -> %d WTF?\n", cptr, foo);
|
|
|
|
break;
|
|
|
|
}
|
2020-12-06 11:13:06 +01:00
|
|
|
fprintf(stderr, "\t%5d / %5d\r", idx, (int)globbuf.gl_pathc);
|
2020-11-02 01:25:00 +01:00
|
|
|
}
|
2021-04-02 04:16:26 +02:00
|
|
|
|
2020-11-02 01:25:00 +01:00
|
|
|
fputs("\n", stderr);
|
|
|
|
|
2021-04-03 05:37:03 +02:00
|
|
|
insert_blank(&input, blk, outdir);
|
2020-11-05 21:07:38 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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:");
|
|
|
|
|
2020-12-30 14:42:44 +01:00
|
|
|
puts("\t-E\tinput:filter:chain");
|
|
|
|
puts("\t-F\toutput:filter:chain");
|
2021-01-13 16:09:27 +01:00
|
|
|
// puts("\t-g\tconvert to gray");
|
2020-11-02 14:51:48 +01:00
|
|
|
puts("\t-I\tinput glob pattern");
|
2020-12-30 14:42:44 +01:00
|
|
|
puts("\t-L\tlist available filters");
|
2024-10-27 16:37:10 +01:00
|
|
|
puts("\t-O\toutput directory (default p8/)");
|
2020-11-02 14:51:48 +01:00
|
|
|
puts("\t-T\tfifo size");
|
|
|
|
puts("\t-v\tincrease verbosity");
|
|
|
|
|
|
|
|
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";
|
2021-04-24 00:16:23 +02:00
|
|
|
int outfmt = FILE_TYPE_PNG;
|
2023-07-17 09:47:56 +02:00
|
|
|
int blanks = 10;
|
2021-04-01 22:23:46 +02:00
|
|
|
char *InFchain = "none";
|
|
|
|
char *OutFchain = "none";
|
2020-11-02 01:25:00 +01:00
|
|
|
|
2021-02-26 22:31:28 +01:00
|
|
|
fprintf(stderr, "*** %s\n\tcompiled %s, %s, pid %d\n",
|
2020-11-02 22:20:54 +01:00
|
|
|
argv[0], __DATE__, __TIME__, getpid());
|
2024-03-25 12:45:15 +01:00
|
|
|
if (verbosity) fimg_print_version(2);
|
2020-11-02 01:25:00 +01:00
|
|
|
|
2021-04-24 00:16:23 +02:00
|
|
|
while ((opt = getopt(argc, argv, "B:E:F:ghI:LO:T:vw:x:")) != -1) {
|
2020-11-02 01:25:00 +01:00
|
|
|
switch(opt) {
|
2020-12-15 17:49:12 +01:00
|
|
|
case 'E': InFchain = optarg; break;
|
|
|
|
case 'F': OutFchain = optarg; break;
|
2020-12-01 15:26:15 +01:00
|
|
|
case 'B': blanks = atoi(optarg);
|
|
|
|
break;
|
2021-01-13 16:09:27 +01:00
|
|
|
case 'g': // convert_to_gray = 1;
|
2020-11-02 01:25:00 +01:00
|
|
|
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;
|
2020-12-30 14:42:44 +01:00
|
|
|
case 'L':
|
|
|
|
list_crapulors("available filters");
|
|
|
|
exit(0);
|
2020-11-02 01:25:00 +01:00
|
|
|
case 'O': out_dir = optarg;
|
|
|
|
break;
|
|
|
|
case 'T': fifosize = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'v': verbosity++;
|
|
|
|
break;
|
2023-05-28 10:49:12 +02:00
|
|
|
default: exit(1);
|
2020-11-02 01:25:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-20 19:06:08 +01:00
|
|
|
if (verbosity) {
|
2021-04-01 22:23:46 +02:00
|
|
|
fprintf(stderr, "\tinput glob '%s'\n", in_pattern);
|
|
|
|
fprintf(stderr, "\toutput dir '%s'\n", out_dir);
|
|
|
|
fprintf(stderr, "\tsrc filter '%s'\n", InFchain);
|
|
|
|
fprintf(stderr, "\tout filter '%s'\n", OutFchain);
|
2024-05-01 12:32:06 +02:00
|
|
|
fprintf(stderr, "\tfifo size %d\n", fifosize);
|
2020-11-20 19:06:08 +01:00
|
|
|
}
|
|
|
|
|
2020-12-15 17:49:12 +01:00
|
|
|
foo = parse_filter_chain(0, InFchain);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "err %d parsing '%s'\n", foo, InFchain);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
foo = parse_filter_chain(1, OutFchain);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "err %d parsing '%s'\n", foo, OutFchain);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2021-05-11 10:36:55 +02:00
|
|
|
if (verbosity > 1) {
|
2021-04-01 22:23:46 +02:00
|
|
|
filterstack_list(0, "input");
|
|
|
|
filterstack_list(1, "ouput");
|
|
|
|
fprintf(stderr, ".\n");
|
|
|
|
}
|
|
|
|
|
2021-04-24 00:16:23 +02:00
|
|
|
foo = demarre_la_machine(in_pattern, out_dir, fifosize, outfmt, blanks);
|
2021-04-02 04:16:26 +02:00
|
|
|
|
2024-03-24 15:07:29 +01:00
|
|
|
fprintf(stderr, "retour du bigrun de la machine -> %d\n", foo);
|
2020-11-02 01:25:00 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|