FloatImg/Fonderie/singlepass.c

228 lines
5.2 KiB
C
Raw Normal View History

2021-01-13 14:06:13 +01:00
/*
* +-------------------------+
* | S I N G L E P A S S |
* +-------------------------+
*/
#include <stdio.h>
#include <stdlib.h>
2021-05-20 09:31:28 +02:00
#include <stdint.h>
2021-01-13 14:06:13 +01:00
#include <unistd.h>
2021-01-13 16:09:27 +01:00
#include <string.h>
#include <glob.h>
2021-01-13 14:06:13 +01:00
#include "../floatimg.h"
2021-01-13 16:09:27 +01:00
#include "crapulator.h"
#include "filterstack.h"
2021-01-13 14:06:13 +01:00
#include "single.h"
2021-05-11 10:36:55 +02:00
#include "glitches.h"
2021-01-13 14:06:13 +01:00
/* ----------------------------------------------------------- */
2021-01-13 16:09:27 +01:00
#define FILTERS 0
2021-01-13 14:06:13 +01:00
int verbosity;
/* ----------------------------------------------------------- */
2023-07-04 17:26:46 +02:00
/*
* parameter 'duplic' is the repetition factor
*/
2021-05-11 10:36:55 +02:00
int run_the_singlepass(char *globber, char *destdir, int duplic,
2021-04-18 11:55:59 +02:00
int fchain, int outfmt)
2021-01-13 16:09:27 +01:00
{
FloatImg image = { 0 };
2021-05-11 10:36:55 +02:00
int idx, foo, loop;
2021-01-13 16:09:27 +01:00
glob_t globbuf;
char *fname;
2021-01-14 14:15:42 +01:00
double elapsed;
2021-01-13 16:09:27 +01:00
#if DEBUG_LEVEL
2023-07-04 17:26:46 +02:00
fprintf(stderr, ">>> %s ( '%s' '%s' %d %d %d )\n", __func__,
globber, destdir, duplic, fchain, outfmt);
2021-01-13 16:09:27 +01:00
#endif
2023-06-26 17:34:53 +02:00
if (verbosity) filterstack_list(fchain, "Run the single pass");
2021-01-13 16:09:27 +01:00
2021-01-14 14:15:42 +01:00
(void)fimg_timer_set(0);
2021-04-18 11:55:59 +02:00
foo = single_init(0, destdir, fchain, outfmt);
2021-01-13 16:09:27 +01:00
if (foo) {
fprintf(stderr, "erreur %d single_init\n", foo);
return foo;
}
// single_print_state("just after init", 0);
memset(&globbuf, 0, sizeof(glob_t));
foo = glob(globber, 0, NULL, &globbuf);
// fprintf(stderr, "globbing '%s' -> %d, %d files found\n",
// globber, foo, (int)globbuf.gl_pathc);
switch (foo) {
case GLOB_NOSPACE:
fprintf(stderr, "%s: glob run out of memory\n", __func__);
break;
case GLOB_ABORTED:
fprintf(stderr, "%s: glob read error\n", __func__);
break;
case GLOB_NOMATCH:
fprintf(stderr, "%s: glob found no matches\n", __func__);
break;
}
if (0 == globbuf.gl_pathc) {
fprintf(stderr, "%s: no file found, aborting\n", __func__);
return -1;
}
for (idx=0; idx<globbuf.gl_pathc; idx++) {
fname = globbuf.gl_pathv[idx]; /* alias of filename */
if (0==image.width && 0==image.height) {
foo = fimg_create_from_dump(fname, &image);
}
else {
foo = fimg_load_from_dump(fname, &image);
}
2024-03-31 00:15:47 +01:00
if (verbosity > 1) {
fprintf(stderr, "%s: image '%s' loaded in %p\n",
__func__, fname, &image);
}
2021-01-13 16:09:27 +01:00
if (foo) {
fprintf(stderr, "get image -> %d\n", foo);
return -1;
}
2021-01-13 14:06:13 +01:00
2024-03-25 12:45:15 +01:00
if (0==idx && verbosity) {
2024-05-01 12:32:06 +02:00
fprintf(stderr, "\tfirst image size %dx%d\n",
2021-03-30 10:47:44 +02:00
image.width, image.height);
}
2024-03-27 12:19:41 +01:00
// fprintf(stderr, " %6ld %s\r", (long)globbuf.gl_pathc-idx, fname);
2021-03-30 10:47:44 +02:00
2021-01-13 16:09:27 +01:00
foo = filterstack_run(fchain, &image, 0);
if (foo) {
fprintf(stderr, "%s: filterstack run --> %d\n",
__func__, foo);
return foo;
}
2021-05-11 10:36:55 +02:00
/* HERE WE CAN REPEAT THE INSERT OF THE PICZ */
for (loop=0; loop<duplic; loop++) {
foo = single_push_picture(&image);
if (foo) {
fprintf(stderr, "error %d on push_picture\n", foo);
return foo;
}
2021-01-13 16:09:27 +01:00
}
}
2024-03-25 12:45:15 +01:00
fprintf(stderr, "\n");
2021-01-13 16:09:27 +01:00
2021-04-18 11:55:59 +02:00
globfree(&globbuf);
2021-01-13 16:09:27 +01:00
fimg_destroy(&image);
2023-04-09 05:28:07 +02:00
// single_print_state("end of run", 0);
2021-01-14 14:15:42 +01:00
elapsed = fimg_timer_get(0);
2021-03-17 11:34:11 +01:00
fprintf(stderr, "%s: %ld frames, elapsed %.3f s, %.3f fps\n",
2021-01-14 19:06:09 +01:00
__func__,
2021-03-17 11:34:11 +01:00
(long)globbuf.gl_pathc, elapsed,
2021-01-14 14:15:42 +01:00
(double)globbuf.gl_pathc/elapsed);
2021-01-13 16:09:27 +01:00
2021-01-14 14:15:42 +01:00
return 0;
2021-01-13 16:09:27 +01:00
}
2021-01-13 14:06:13 +01:00
/* ----------------------------------------------------------- */
static void help(void)
{
2021-01-14 14:15:42 +01:00
puts("------ Single pass serial filter ------\nusage:");
2021-01-13 14:06:13 +01:00
puts("\t-F\tdefine:the:filter:chain");
puts("\t-g\tinput glob pattern");
puts("\t-L\tlist available filters");
2021-03-30 10:47:44 +02:00
puts("\t-O\t/output/directory (default ./p8)");
2021-05-11 10:36:55 +02:00
puts("\t-r N\trepetiiing factor");
2021-01-13 14:06:13 +01:00
// puts("\t-s\tdo single test");
puts("\t-v\tspit more messages");
exit(0);
}
/* ----------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo, opt;
char *filterchain = "none";
char *globbing = "./capture/?????.fimg";
2021-01-13 16:09:27 +01:00
char *outdir = "./p8";
2021-04-24 00:16:23 +02:00
// char *outtype = ".png";
2021-01-13 14:06:13 +01:00
int do_xper = 0;
2021-05-11 10:36:55 +02:00
int repeat = 1;
2021-01-13 14:06:13 +01:00
2023-07-04 17:26:46 +02:00
fprintf(stderr, "*** %s\n\tcompiled %s %s\n", argv[0],
2021-01-13 14:06:13 +01:00
__DATE__, __TIME__);
2024-03-25 12:45:15 +01:00
if (verbosity) fimg_print_version(2);
2021-01-13 14:06:13 +01:00
2021-04-18 11:55:59 +02:00
if (argc < 2) {
fprintf(stderr, "\t/!\\ %s is option driven\n", argv[0]);
help();
}
2021-05-11 10:36:55 +02:00
while ((opt = getopt(argc, argv, "hF:g:LO:r:svx")) != -1) {
2021-01-13 14:06:13 +01:00
switch (opt) {
case 'h': help(); break;
case 'F': filterchain = optarg; break;
case 'g': globbing = optarg; break;
case 'L':
list_crapulors("available filters");
exit(0);
case 'O': outdir = optarg; break;
2021-05-11 10:36:55 +02:00
case 'r': repeat = atoi(optarg); break;
2021-01-13 14:06:13 +01:00
case 'v': verbosity++; break;
case 'x': do_xper = 1; break;
2021-03-17 11:34:11 +01:00
default:
fprintf(stderr, "%s ABEND\n", argv[0]);
exit(1);
2021-01-13 14:06:13 +01:00
}
}
2021-05-11 10:36:55 +02:00
if (repeat < 1) {
fprintf(stderr, "%s: loop %d invalid\n", argv[0], repeat);
exit(2);
}
2021-01-13 16:09:27 +01:00
foo = parse_filter_chain(FILTERS, filterchain);
if (foo) {
fprintf(stderr, "err %d in parse_filter_chain\n", foo);
exit(1);
}
2021-02-24 17:48:16 +01:00
if (verbosity) {
2021-02-25 12:16:07 +01:00
fprintf(stderr, "\tpid %d\n", getpid());
fprintf(stderr, "\tinput glob %s\n", globbing);
fprintf(stderr, "\tfilter chain %s\n", filterchain);
2021-04-18 11:55:59 +02:00
fprintf(stderr, "\toutput dir %s\n", outdir);
2021-05-11 10:36:55 +02:00
fprintf(stderr, "\trepeat %d\n", repeat);
2021-04-24 00:16:23 +02:00
// fprintf(stderr, "\toutput type %s\n", outtype);
2021-02-25 12:16:07 +01:00
fprintf(stderr, "\tdo xper %d\n", do_xper);
2021-02-24 17:48:16 +01:00
}
2023-07-04 17:26:46 +02:00
/*
* REAL action here
*/
2021-05-11 10:36:55 +02:00
foo = run_the_singlepass(globbing, outdir, repeat,
FILTERS, FILE_TYPE_PNG);
2024-03-25 12:45:15 +01:00
fprintf(stderr, "\tRun the single pass --> %d\n", foo);
2021-01-13 16:09:27 +01:00
2021-01-13 14:06:13 +01:00
return 0;
}
/* ----------------------------------------------------------- */