2020-11-16 07:31:02 +11:00
|
|
|
/*
|
|
|
|
* test des trucs
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2021-05-20 18:31:28 +11:00
|
|
|
#include <stdint.h>
|
2020-11-16 21:12:29 +11:00
|
|
|
#include <unistd.h>
|
2020-12-05 05:55:34 +11:00
|
|
|
#include <string.h>
|
2021-01-12 08:22:03 +11:00
|
|
|
#include <glob.h>
|
2020-11-16 07:31:02 +11:00
|
|
|
|
|
|
|
#include "../floatimg.h"
|
|
|
|
#include "glitches.h"
|
2020-12-03 05:24:54 +11:00
|
|
|
#include "sfx.h"
|
2020-12-04 07:56:45 +11:00
|
|
|
#include "filterstack.h"
|
2020-12-30 02:40:26 +11:00
|
|
|
#include "crapulator.h"
|
2021-01-09 08:57:45 +11:00
|
|
|
#include "single.h"
|
2020-11-16 07:31:02 +11:00
|
|
|
|
2024-11-10 23:55:25 +11:00
|
|
|
#include "utilfuncs.h"
|
|
|
|
|
2020-11-16 07:31:02 +11:00
|
|
|
/* ----------------------------------------------------------- */
|
|
|
|
|
|
|
|
int verbosity;
|
|
|
|
|
|
|
|
#define PNG "out.png"
|
2020-12-05 05:55:34 +11:00
|
|
|
#define W 800
|
|
|
|
#define H 600
|
|
|
|
#define LMAX 255.0
|
2020-11-16 07:31:02 +11:00
|
|
|
#define TIMER 1
|
|
|
|
|
2020-12-16 03:49:12 +11:00
|
|
|
#define STK 6
|
2020-12-11 05:19:35 +11:00
|
|
|
|
2024-11-10 23:55:25 +11:00
|
|
|
/* ----------------------------------------------------------- */
|
|
|
|
/* new Sat Nov 9 22:17:46 UTC 2024 */
|
|
|
|
int essai_test_export_dir(char *footxt)
|
|
|
|
{
|
|
|
|
int foo;
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, footxt);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
foo = check_if_export_dir_is_valid("/tmp/quux", 0);
|
|
|
|
fprintf(stderr, " got %d\n\n", foo);
|
|
|
|
|
|
|
|
foo = check_if_export_dir_is_valid("/home", 0);
|
|
|
|
fprintf(stderr, " got %d\n\n", foo);
|
|
|
|
|
|
|
|
foo = check_if_export_dir_is_valid("./", 0);
|
|
|
|
fprintf(stderr, " got %d\n\n", foo);
|
|
|
|
|
|
|
|
foo = check_if_export_dir_is_valid("Makefile", 0);
|
|
|
|
fprintf(stderr, " got %d\n\n", foo);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2020-12-04 07:56:45 +11:00
|
|
|
/* ----------------------------------------------------------- */
|
|
|
|
|
2020-12-31 00:42:44 +11:00
|
|
|
int essai_filterstack(char *fIname, char *fOname)
|
2020-12-04 07:56:45 +11:00
|
|
|
{
|
|
|
|
int foo;
|
2020-12-07 14:45:51 +11:00
|
|
|
FloatImg image;
|
|
|
|
double debut, fin;
|
2020-12-04 07:56:45 +11:00
|
|
|
|
2024-11-10 23:55:25 +11:00
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( '%s' '%s' )\n", __func__, fIname, fOname);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2020-12-31 00:42:44 +11:00
|
|
|
// filterstack_list(STK, __func__);
|
2020-12-05 05:55:34 +11:00
|
|
|
|
2020-12-31 00:42:44 +11:00
|
|
|
foo = fimg_create_from_dump(fIname, &image);
|
2020-12-04 07:56:45 +11:00
|
|
|
if (foo) {
|
2023-07-16 21:39:49 +11:00
|
|
|
fprintf(stderr, "%s: err %d create from dump\n", __func__, foo);
|
2020-12-07 14:45:51 +11:00
|
|
|
exit(1);
|
2020-12-04 07:56:45 +11:00
|
|
|
}
|
|
|
|
|
2020-12-07 14:45:51 +11:00
|
|
|
srand(getpid()); srand48(getpid());
|
2020-12-04 07:56:45 +11:00
|
|
|
|
2020-12-07 14:45:51 +11:00
|
|
|
debut = fimg_timer_set(TIMER);
|
2020-12-05 05:55:34 +11:00
|
|
|
|
2020-12-11 05:19:35 +11:00
|
|
|
foo = filterstack_run(STK, &image, 0);
|
2020-12-04 07:56:45 +11:00
|
|
|
if (foo) {
|
2020-12-07 14:45:51 +11:00
|
|
|
fprintf(stderr, "filterstack run --> %d\n", foo);
|
2020-12-04 07:56:45 +11:00
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
|
2020-12-07 14:45:51 +11:00
|
|
|
fin = fimg_timer_set(TIMER);
|
|
|
|
|
2020-12-31 00:42:44 +11:00
|
|
|
foo = fimg_export_picture(&image, fOname, 0);
|
2020-12-07 14:45:51 +11:00
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "erreur export %d\n", foo);
|
2020-12-05 05:55:34 +11:00
|
|
|
}
|
|
|
|
|
2020-12-07 14:45:51 +11:00
|
|
|
fprintf(stderr, "elapsed %f\n", fin-debut);
|
|
|
|
|
|
|
|
fimg_destroy(&image);
|
|
|
|
|
2020-12-04 07:56:45 +11:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* ----------------------------------------------------------- */
|
2021-01-11 08:52:33 +11:00
|
|
|
/*
|
|
|
|
* test-only function !
|
|
|
|
|
|
|
|
foo = essayer_single("capture/???42.fimg", "/tmp/x8/", STK);
|
|
|
|
fprintf(stderr, "essayer single -> %d\n", foo);
|
|
|
|
*/
|
|
|
|
int essayer_single(char *globpattern, char *destdir, int chain)
|
|
|
|
{
|
2021-01-12 08:22:03 +11:00
|
|
|
FloatImg image = { 0 };
|
2021-01-11 08:52:33 +11:00
|
|
|
int idx, foo;
|
2021-01-12 08:22:03 +11:00
|
|
|
glob_t globbuf;
|
|
|
|
char *fname;
|
2021-01-11 08:52:33 +11:00
|
|
|
|
2021-01-14 02:09:27 +11:00
|
|
|
#if DEBUG_LEVEL
|
2021-01-11 08:52:33 +11:00
|
|
|
fprintf(stderr, ">>> %s ( '%s' '%s' %d )\n", __func__,
|
|
|
|
globpattern, destdir, chain);
|
2021-01-14 02:09:27 +11:00
|
|
|
#endif
|
2021-01-11 08:52:33 +11:00
|
|
|
|
2021-01-12 08:22:03 +11:00
|
|
|
filterstack_list(chain, "essai du single");
|
|
|
|
|
2021-04-18 20:55:59 +11:00
|
|
|
foo = single_init(0, destdir, chain, -1);
|
2021-01-11 08:52:33 +11:00
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "erreur %d single_init\n", foo);
|
|
|
|
return foo;
|
|
|
|
}
|
2021-01-12 08:22:03 +11:00
|
|
|
single_print_state("just after init", 0);
|
|
|
|
|
|
|
|
memset(&globbuf, 0, sizeof(glob_t));
|
|
|
|
foo = glob(globpattern, 0, NULL, &globbuf);
|
|
|
|
fprintf(stderr, "globbing '%s' -> %d, %d files found\n",
|
|
|
|
globpattern, foo, (int)globbuf.gl_pathc);
|
|
|
|
if (0 == globbuf.gl_pathc) {
|
|
|
|
fprintf(stderr, "%s : no file found, aborting\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
2021-01-11 08:52:33 +11:00
|
|
|
|
2021-01-12 08:22:03 +11:00
|
|
|
for (idx=0; idx<globbuf.gl_pathc; idx++) {
|
2021-01-11 08:52:33 +11:00
|
|
|
|
2021-01-12 08:22:03 +11:00
|
|
|
fname = globbuf.gl_pathv[idx]; /* alias of filename */
|
|
|
|
fprintf(stderr, "%s %6d %s\r", __func__, idx, fname);
|
|
|
|
|
|
|
|
if (0==image.width && 0==image.height) {
|
|
|
|
foo = fimg_create_from_dump(fname, &image);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foo = fimg_load_from_dump(fname, &image);
|
|
|
|
}
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "get image -> %d\n", foo);
|
|
|
|
return -1;
|
|
|
|
}
|
2021-01-11 08:52:33 +11:00
|
|
|
|
|
|
|
foo = filterstack_run(chain, &image, 0);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "%s: filterstack run --> %d\n",
|
|
|
|
__func__, foo);
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
|
|
|
|
foo = single_push_picture(&image);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "erreur %d push picture\n", foo);
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-12 08:22:03 +11:00
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
2021-01-14 02:09:27 +11:00
|
|
|
single_print_state("end of run :)", 0);
|
2021-01-12 08:22:03 +11:00
|
|
|
|
|
|
|
fimg_destroy(&image);
|
|
|
|
|
2021-01-14 02:09:27 +11:00
|
|
|
return 0;
|
2021-01-11 08:52:33 +11:00
|
|
|
}
|
|
|
|
/* ----------------------------------------------------------- */
|
|
|
|
|
2020-12-05 05:55:34 +11:00
|
|
|
int help(void)
|
|
|
|
{
|
2021-01-12 08:22:03 +11:00
|
|
|
puts("Yolo!");
|
2020-12-31 10:46:12 +11:00
|
|
|
|
2021-01-11 08:52:33 +11:00
|
|
|
puts("\t-F\tdefine:the:filter:chain");
|
2021-01-12 08:22:03 +11:00
|
|
|
puts("\t-g\tinput glob pattern");
|
2021-01-11 08:52:33 +11:00
|
|
|
puts("\t-i\tinfile.fimg");
|
2021-01-12 08:22:03 +11:00
|
|
|
puts("\t-L\tlist available filters");
|
2021-01-16 21:29:40 +11:00
|
|
|
puts("\t-o\toutfile.xxx");
|
2021-01-12 08:22:03 +11:00
|
|
|
puts("\t-O\t/output/directory");
|
|
|
|
puts("\t-s\tdo single test");
|
2020-12-31 10:46:12 +11:00
|
|
|
|
2020-12-05 05:55:34 +11:00
|
|
|
exit(0);
|
2020-12-30 02:40:26 +11:00
|
|
|
}
|
|
|
|
/* ----------------------------------------------------------- */
|
2023-07-16 21:39:49 +11:00
|
|
|
int experiment(char *fname)
|
2020-12-30 02:40:26 +11:00
|
|
|
{
|
2020-12-31 00:42:44 +11:00
|
|
|
int foo;
|
2021-01-11 08:52:33 +11:00
|
|
|
FloatImg image, dest;
|
2020-12-31 00:42:44 +11:00
|
|
|
|
2023-07-16 21:39:49 +11:00
|
|
|
fprintf(stderr, "----- EXPERIMENT on '%s' -----\n", fname);
|
2020-12-30 02:40:26 +11:00
|
|
|
|
2023-07-16 21:39:49 +11:00
|
|
|
foo = fimg_create_from_dump(fname, &image);
|
2021-01-11 08:52:33 +11:00
|
|
|
if (foo) {
|
2021-10-05 09:35:56 +11:00
|
|
|
fprintf(stderr, "%s: err %d on create_from_dump\n",
|
|
|
|
__func__, foo);
|
2021-01-11 08:52:33 +11:00
|
|
|
return -1;
|
|
|
|
}
|
2020-12-30 02:40:26 +11:00
|
|
|
|
2022-05-15 05:49:59 +11:00
|
|
|
foo = fimg_clone(&image, &dest, 0);
|
2021-01-11 08:52:33 +11:00
|
|
|
|
2023-07-16 21:39:49 +11:00
|
|
|
foo = poke_sup_rb_g(&image, &dest);
|
|
|
|
fprintf(stderr, "poke sup rb g --> %d\n", foo);
|
2021-01-11 08:52:33 +11:00
|
|
|
|
|
|
|
fimg_export_picture(&dest, "foo.png", 0);
|
2020-12-31 00:42:44 +11:00
|
|
|
|
|
|
|
exit(0); /* back to real world */
|
2020-12-05 05:55:34 +11:00
|
|
|
}
|
|
|
|
/* ----------------------------------------------------------- */
|
2020-12-04 07:56:45 +11:00
|
|
|
|
2020-11-16 07:31:02 +11:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2021-01-12 08:22:03 +11:00
|
|
|
int foo, opt;
|
|
|
|
int do_xper = 0;
|
|
|
|
int do_single = 0;
|
2020-12-31 00:42:44 +11:00
|
|
|
char *filterchain = "0";
|
2020-12-30 02:40:26 +11:00
|
|
|
char *infile = "mire.fimg";
|
2021-01-11 08:52:33 +11:00
|
|
|
char *outfile = PNG;
|
2021-01-09 08:57:45 +11:00
|
|
|
char *outdir = "/tmp/x8/";
|
2021-01-12 08:22:03 +11:00
|
|
|
char *globstr = "capture/????7.fimg";
|
2020-12-05 05:55:34 +11:00
|
|
|
|
|
|
|
fprintf(stderr, "*** %s : compiled by tTh, %s %s\n", __FILE__,
|
|
|
|
__DATE__, __TIME__);
|
|
|
|
fimg_print_version(2);
|
|
|
|
|
2021-01-12 08:22:03 +11:00
|
|
|
while ((opt = getopt(argc, argv, "hF:g:i:Lo:O:svx")) != -1) {
|
2020-12-05 05:55:34 +11:00
|
|
|
switch(opt) {
|
|
|
|
case 'h': help(); break;
|
2020-12-07 14:45:51 +11:00
|
|
|
case 'F': filterchain = optarg; break;
|
2021-01-12 08:22:03 +11:00
|
|
|
case 'g': globstr = optarg; break;
|
2020-12-31 00:42:44 +11:00
|
|
|
case 'i': infile = optarg; break;
|
2020-12-31 10:46:12 +11:00
|
|
|
case 'L':
|
|
|
|
list_crapulors("available filters");
|
|
|
|
exit(0);
|
2020-12-31 00:42:44 +11:00
|
|
|
case 'o': outfile = optarg; break;
|
2021-01-12 08:22:03 +11:00
|
|
|
case 'O': outdir = optarg; break;
|
|
|
|
case 's': do_single = 1; break;
|
2020-12-05 05:55:34 +11:00
|
|
|
case 'v': verbosity++; break;
|
2021-01-09 08:57:45 +11:00
|
|
|
case 'x': do_xper = 1; break;
|
2020-12-30 02:40:26 +11:00
|
|
|
default: exit(1);
|
2020-12-05 05:55:34 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
2024-11-10 23:55:25 +11:00
|
|
|
fprintf(stderr, ">>> %s : argc=%d, optind=%d\n", argv[0], argc, optind);
|
2020-12-05 05:55:34 +11:00
|
|
|
#endif
|
2020-11-26 00:38:39 +11:00
|
|
|
|
2024-11-10 23:55:25 +11:00
|
|
|
foo = essai_test_export_dir("bla bla");
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "err %d in essai_test_export_dir\n", foo);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
|
2020-12-11 05:19:35 +11:00
|
|
|
foo = parse_filter_chain(STK, filterchain);
|
2020-11-16 07:31:02 +11:00
|
|
|
if (foo) {
|
2020-12-07 14:45:51 +11:00
|
|
|
fprintf(stderr, "err %d in parse_filter_chain\n", foo);
|
2020-11-16 07:31:02 +11:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2024-11-10 23:55:25 +11:00
|
|
|
|
2021-01-09 08:57:45 +11:00
|
|
|
if (do_xper) {
|
2023-07-16 21:39:49 +11:00
|
|
|
experiment(infile);
|
2021-01-11 08:52:33 +11:00
|
|
|
return 0;
|
2021-01-09 08:57:45 +11:00
|
|
|
}
|
2021-01-12 08:22:03 +11:00
|
|
|
if (do_single) {
|
|
|
|
fprintf(stderr, "Globbing '%s'\n", globstr);
|
|
|
|
essayer_single(globstr, outdir, STK);
|
|
|
|
return 0;
|
|
|
|
}
|
2021-01-09 08:57:45 +11:00
|
|
|
|
2020-12-31 00:42:44 +11:00
|
|
|
foo = essai_filterstack(infile, outfile);
|
2020-12-04 07:56:45 +11:00
|
|
|
if (foo) {
|
2020-12-07 14:45:51 +11:00
|
|
|
fprintf(stderr, "err %d in essai_filterstack\n", foo);
|
|
|
|
exit(1);
|
2020-11-16 07:31:02 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------- */
|