From 62aa91e434d93412a2f9db5f2d5623d106ffb2c4 Mon Sep 17 00:00:00 2001 From: tonton th Date: Mon, 7 Dec 2020 04:45:51 +0100 Subject: [PATCH] is filterstack really ok ? --- Fonderie/essai.sh | 20 +++--- Fonderie/filterstack.c | 82 +++++++++++++++++++++++-- Fonderie/filterstack.h | 6 +- Fonderie/interpolator.c | 54 ++++++++++++---- Fonderie/t.c | 132 ++++++++++++++++------------------------ 5 files changed, 185 insertions(+), 109 deletions(-) diff --git a/Fonderie/essai.sh b/Fonderie/essai.sh index 64ca40be..6b545120 100755 --- a/Fonderie/essai.sh +++ b/Fonderie/essai.sh @@ -1,26 +1,22 @@ #!/bin/bash -FILTRES="5:6:13 2 5:6:8 4:25 8:13:13:7 10:1 25:25:25" +FILTRES="5:6:13 2:2 5:9:8 4:25 8:13:13:7 10:1 25:25:25:25" + +rm /tmp/fstack*.png for F in $FILTRES do - I="/tmp/fstack"$F".png" + I="/tmp/fstack-"$F".png" echo ; echo $I ./t -F $F txt=$(printf "[%-10s]" $F) - convert foo.png -pointsize 32 -kerning 0 \ - -fill Orange -undercolor Gray20 \ + convert foo.png -pointsize 28 -kerning 0 \ + -fill Gray80 -undercolor Gray20 \ -font Courier-Bold \ - -annotate +20+40 "$txt" \ + -annotate +0+25 "$txt" \ $I done -convert -delay 100 /tmp/fstack*.png foo.gif - - - - - - +convert -delay 150 /tmp/fstack*.png foo.gif diff --git a/Fonderie/filterstack.c b/Fonderie/filterstack.c index adc43a02..c7f382eb 100644 --- a/Fonderie/filterstack.c +++ b/Fonderie/filterstack.c @@ -4,6 +4,7 @@ #include #include +#include #include "../floatimg.h" #include "crapulator.h" @@ -13,6 +14,9 @@ // #define DEBUG_LEVEL 1 /* -------------------------------------------------------------- */ + +extern int verbosity; + static FilterSlot *stack_slots; static int nbre_filters, idx_slot; /* -------------------------------------------------------------- */ @@ -67,10 +71,15 @@ idx_slot++; return 0; } /* -------------------------------------------------------------- */ -int filterstack_list(char *txt) +int filterstack_list(const char *txt) { int idx; +if (NULL==stack_slots) { + fprintf(stderr, "%s: NULL statck !\n", __func__); + exit(1); + } + fprintf(stderr, "------- %-20s --------\n", txt); fprintf(stderr, "stack at %p, size %d, current %d\n", stack_slots, nbre_filters, idx_slot); @@ -92,13 +101,19 @@ int filterstack_run(FloatImg *target, int notused) int idx, foo; #if DEBUG_LEVEL -fprintf(stderr, ">>> %s ( %p %d)\n", __func__, target, notused); +fprintf(stderr, ">>> %s ( %p %d )\n", __func__, target, notused); #endif +if (NULL==stack_slots) { + fprintf(stderr, "%s: NULL statck !\n", __func__); + exit(1); + } + for (idx=0; idx 1) + fprintf(stderr, "%d : effect %2d on %p\n", + idx, stack_slots[idx].numero, target); foo = crapulator(target, stack_slots[idx].numero, stack_slots[idx].fval); @@ -113,7 +128,66 @@ return 0; /* -------------------------------------------------------------- */ int load_stack_from_file(char *fname, int notused) { +FILE *fp; +// int a, b; +// float f; +// char line[100]; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, notused); +#endif + +if (NULL==stack_slots) { + fprintf(stderr, "%s: NULL statck !\n", __func__); + exit(1); + } + +if (NULL==(fp=fopen(fname, "r"))) { + perror(fname); + return -1; + } + +/* + * here was dragons + */ + + + /* hadoc parser ? */ + +fclose(fp); return -1; } /* -------------------------------------------------------------- */ +int parse_filter_chain(const char *argument) +{ +char *cptr; +int value, foo; + +fprintf(stderr, "\n%s: arg = '%s'\n", __func__, argument); + +foo = filterstack_init(8); +if (foo) { + fprintf(stderr, "%s: filterstack init --> %d\n", __func__, foo); + return foo; + } + +for (;;) { + cptr = strtok(argument, ":"); + // fprintf(stderr, "cptr %p\n", cptr); + if (NULL==cptr) break; + argument = NULL; + // fprintf(stderr, " parsing '%s'\n", cptr); + if (1 == sscanf(cptr, "%d", &value)) { + foo = filterstack_add(value, 1, 1.0); + if (foo) { + fprintf(stderr, "%s: err %d add\n", + __func__, foo); + } + } + } + +if (verbosity) filterstack_list(__func__); +return 0; +} +/* ----------------------------------------------------------- */ diff --git a/Fonderie/filterstack.h b/Fonderie/filterstack.h index f3b2ee1f..18cb7d7c 100644 --- a/Fonderie/filterstack.h +++ b/Fonderie/filterstack.h @@ -3,7 +3,7 @@ */ typedef struct { - int numero; + int numero; /* id in rapulator */ int ival; float fval; } FilterSlot; @@ -13,9 +13,11 @@ int filterstack_init(int nbre); int filterstack_add(int code, int ival, float fval); -int filterstack_list(char *txt); /* XXX */ +int filterstack_list(const char *txt); /* XXX */ int filterstack_run(FloatImg *target, int notused); int load_stack_from_file(char *fname, int notused); +int parse_filter_chain(const char *argument); + diff --git a/Fonderie/interpolator.c b/Fonderie/interpolator.c index 0ad8230c..6c3956c3 100644 --- a/Fonderie/interpolator.c +++ b/Fonderie/interpolator.c @@ -20,8 +20,7 @@ #include "glitches.h" #include "crapulator.h" #include "metriques.h" - -// XXX #include "fonctions.h" +#include "filterstack.h" int verbosity; int convert_to_gray; /* needed by fonctions.c */ @@ -73,14 +72,15 @@ for (idx=0; idx 1) - fprintf(stderr, "%5d %s %f\n", idx, filename, metrique); + if (verbosity) + fprintf(stderr, "%5d %s %f\r", idx, filename, metrique); idxvalues[idx].idx = idx; idxvalues[idx].value = metrique; } if (method) { /* and now, we can massage all our datas */ + fprintf(stderr, "sorting %d ...\n", method); qsort(idxvalues, nombre, sizeof(IdxValue), cmp_idxvalues); } @@ -116,8 +116,8 @@ fprintf(stderr, " interpolate from '%s' to '%s' with %d steps.\n", memset(&globbuf, 0, sizeof(glob_t)); foo = glob(pattern, 0, NULL, &globbuf); -fprintf(stderr, "globbing '%s' -> %d, %ld files found\n", - pattern, foo, globbuf.gl_pathc); +fprintf(stderr, "globbing '%s' -> %d, %d files found\n", + pattern, foo, (int)globbuf.gl_pathc); if (0 == globbuf.gl_pathc) { fprintf(stderr, "%s : no file found, aborting\n", __func__); return -1; @@ -125,7 +125,10 @@ if (0 == globbuf.gl_pathc) { idx_values = NULL; foo = tentative_triage(&globbuf, &idx_values, sort); -fprintf(stderr, "\tTRI of %p -> %d\n\n", idx_values, foo); +if (foo) { + fprintf(stderr, "sort of %p -> %d\n\n", idx_values, foo); + return foo; + } foo = fimg_fileinfos(globbuf.gl_pathv[0], iarray); if (FIMG_TYPE_RGB != iarray[2]) { @@ -148,8 +151,8 @@ for (idx=0; idx %d\n", cptr, foo); @@ -169,7 +172,19 @@ for (idx=0; idx %d\n", foo); + return foo; + } + if (foo) { fprintf(stderr, "\n%s: out fx %d failure %d\n", __func__, outfx, foo); @@ -195,6 +210,10 @@ for (idx=0; idx "); */ puts("options:"); puts("\t-S nn\tmysterious sort"); -puts("\t-v\tincrease verbosity"); +puts("\t-F i:j\tfilter chain"); puts("\t-w nn\tinput effect"); puts("\t-x nn\toutput effect"); +puts("\t-v\tincrease verbosity"); exit(0); } @@ -227,13 +247,15 @@ int opt; int inFx = 0; int outFx = 0; int sort = 0; +char *filterchain = "0"; fprintf(stderr, "*** %s : compiled by tTh, %s %s\n", __FILE__, __DATE__, __TIME__); fimg_print_version(2); -while ((opt = getopt(argc, argv, "hS:vw:x:")) != -1) { +while ((opt = getopt(argc, argv, "F:hS:vw:x:")) != -1) { switch(opt) { + case 'F': filterchain = optarg; break; case 'h': help(); break; case 'S': sort = atoi(optarg); break; case 'v': verbosity++; break; @@ -251,6 +273,14 @@ if (3 != (argc-optind)) { exit(1); } +foo = parse_filter_chain(filterchain); +if (foo) { + fprintf(stderr, "err %d parsing '%s'\n", foo, filterchain); + exit(1); + } + +// filterstack_list(__FILE__); + nbrsteps = atoi(argv[optind+2]); foo = interpolator(argv[optind], argv[optind+1], nbrsteps, inFx, outFx, sort); diff --git a/Fonderie/t.c b/Fonderie/t.c index 5bcf58ac..91e051ee 100644 --- a/Fonderie/t.c +++ b/Fonderie/t.c @@ -25,87 +25,13 @@ int convert_to_gray; /* WTF ? */ /* ----------------------------------------------------------- */ -int essai_filterstack(FloatImg *pimg) -{ -int foo; - - -filterstack_list(__func__); - -foo = filterstack_run(pimg, 0); -if (foo) { - fprintf(stderr, "filterstack run --> %d\n", foo); - return foo; - } - -return 0; -} -/* ----------------------------------------------------------- */ -int parse_filter_chain(const char *argument) -{ -char *cptr; -int value, foo; - -fprintf(stderr, "\n%s: arg = '%s'\n", __func__, argument); - -foo = filterstack_init(4); -if (foo) { - fprintf(stderr, "%s: filterstack init --> %d\n", __func__, foo); - return foo; - } - -for (;;) { - cptr = strtok(argument, ":"); - fprintf(stderr, "cptr %p\n", cptr); - if (NULL==cptr) break; - argument = NULL; - fprintf(stderr, " parsing '%s'\n", cptr); - if (1 == sscanf(cptr, "%d", &value)) { - foo = filterstack_add(value, 1, 1.0); - if (foo) { - fprintf(stderr, "%s: err %d add\n", - __func__, foo); - } - } - } - -if (verbosity) filterstack_list(__func__); -return 0; -} -/* ----------------------------------------------------------- */ -int help(void) -{ -puts("yolo!"); -exit(0); -} -/* ----------------------------------------------------------- */ - -int main(int argc, char *argv[]) +int essai_filterstack(void) { int foo; FloatImg image; double debut, fin; -int opt; -char *filterchain = "0"; -fprintf(stderr, "*** %s : compiled by tTh, %s %s\n", __FILE__, - __DATE__, __TIME__); -fimg_print_version(2); - -while ((opt = getopt(argc, argv, "hF:v")) != -1) { - switch(opt) { - case 'h': help(); break; - case 'F': filterchain = optarg; - break; - case 'v': verbosity++; break; - } - } - -#if DEBUG_LEVEL -fprintf(stderr, "%s : argc = %d, optind = %d\n", argv[0], argc, optind); -#endif - -parse_filter_chain(filterchain); +filterstack_list(__func__); foo = fimg_create_from_dump("mire.fimg", &image); if (foo) { @@ -113,12 +39,16 @@ if (foo) { exit(1); } -srand(getpid()); +srand(getpid()); srand48(getpid()); + debut = fimg_timer_set(TIMER); -foo = essai_filterstack(&image); + +foo = filterstack_run(&image, 0); if (foo) { - fprintf(stderr, "essai filterstack --> %d\n", foo); + fprintf(stderr, "filterstack run --> %d\n", foo); + return foo; } + fin = fimg_timer_set(TIMER); foo = fimg_save_as_png(&image, "foo.png", 0); @@ -130,6 +60,50 @@ fprintf(stderr, "elapsed %f\n", fin-debut); fimg_destroy(&image); +return 0; +} +/* ----------------------------------------------------------- */ +int help(void) +{ +puts("yolo!"); +exit(0); +} +/* ----------------------------------------------------------- */ + +int main(int argc, char *argv[]) +{ +int foo; +int opt; +char *filterchain = "0"; + +fprintf(stderr, "*** %s : compiled by tTh, %s %s\n", __FILE__, + __DATE__, __TIME__); +fimg_print_version(2); + +while ((opt = getopt(argc, argv, "hF:v")) != -1) { + switch(opt) { + case 'h': help(); break; + case 'F': filterchain = optarg; break; + case 'v': verbosity++; break; + } + } + +#if DEBUG_LEVEL +fprintf(stderr, "%s : argc = %d, optind = %d\n", argv[0], argc, optind); +#endif + +foo = parse_filter_chain(filterchain); +if (foo) { + fprintf(stderr, "err %d in parse_filter_chain\n", foo); + exit(1); + } + +foo = essai_filterstack(); +if (foo) { + fprintf(stderr, "err %d in essai_filterstack\n", foo); + exit(1); + } + return 0; }