From 77a137a168b1c353617139dded547b3a2284a01c Mon Sep 17 00:00:00 2001 From: tonton th Date: Thu, 3 Dec 2020 21:56:45 +0100 Subject: [PATCH] first run of the filterstack --- Fonderie/Makefile | 14 ++++-- Fonderie/filterstack.c | 109 +++++++++++++++++++++++++++++++++++++++++ Fonderie/filterstack.h | 18 +++++++ Fonderie/t.c | 82 ++++++++++++++++++------------- 4 files changed, 184 insertions(+), 39 deletions(-) create mode 100644 Fonderie/filterstack.c create mode 100644 Fonderie/filterstack.h diff --git a/Fonderie/Makefile b/Fonderie/Makefile index 67f209d..91fb45c 100644 --- a/Fonderie/Makefile +++ b/Fonderie/Makefile @@ -6,15 +6,18 @@ COPT = -g -fpic -no-pie -Wall -DDEBUG_LEVEL=0 -Werror=parentheses LIBS = ../libfloatimg.a -lpnglite -lm -OBJS = fonctions.o sfx.o crapulator.o glitches.o metriques.o -DEPS = fonctions.h crapulator.h metriques.h glitches.h sfx.h +OBJS = fonctions.o sfx.o crapulator.o glitches.o metriques.o \ + filterstack.o + +DEPS = fonctions.h crapulator.h metriques.h glitches.h sfx.h \ + filterstack.h all: fonderie interpolator t # --------------------------------------------------------- -t: t.c Makefile glitches.o sfx.o - gcc ${COPT} $< glitches.o sfx.o ${LIBS} -lz -o $@ +t: t.c Makefile ${OBJS} + gcc ${COPT} $< ${OBJS} ${LIBS} -lz -o $@ # --------------------------------------------------------- @@ -31,6 +34,9 @@ fonctions.o: fonctions.c fonctions.h Makefile sfx.o: sfx.c ${DEPS} Makefile gcc ${COPT} -c $< +filterstack.o: filterstack.c ${DEPS} Makefile + gcc ${COPT} -c $< + # --------------------------------------------------------- # # another way to brotch some pics... diff --git a/Fonderie/filterstack.c b/Fonderie/filterstack.c new file mode 100644 index 0000000..c932d72 --- /dev/null +++ b/Fonderie/filterstack.c @@ -0,0 +1,109 @@ +/* + * filterstack.c + */ + +#include +#include + +#include "../floatimg.h" +#include "filterstack.h" + +#undef DEBUG_LEVEL +#define DEBUG_LEVEL 1 + +/* -------------------------------------------------------------- */ +static FilterSlot *stack_slots; +static int nbre_filters, idx_slot; +/* -------------------------------------------------------------- */ +int filterstack_init(int nbre) +{ +FilterSlot *fsptr; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %d )\n", __func__, nbre); +#endif + +if (NULL != stack_slots) { + fprintf(stderr, "ERR stack_slots = %p\n",stack_slots); + return -1; + } +fsptr = calloc(nbre, sizeof(FilterSlot)); +if (NULL == fsptr) { + fprintf(stderr, "%s : no memory\n", __func__); + exit(1); + } + +stack_slots = fsptr; +nbre_filters = nbre; +idx_slot = 0; + +fprintf(stderr, "%s: stack at %p\n", __func__, stack_slots); + +return 0; +} +/* -------------------------------------------------------------- */ +int filterstack_add(int code, int ival, float fval) +{ +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %d %d %f )\n", __func__, code, ival, fval); +#endif + +if (NULL==stack_slots) { + fprintf(stderr, "%s: NULL statck !\n", __func__); + exit(1); + } +if (idx_slot == nbre_filters) { + fprintf(stderr, "%s: stack is full\n", __func__); + return -1; + } + +stack_slots[idx_slot].numero = code; +stack_slots[idx_slot].ival = ival; +stack_slots[idx_slot].fval = fval; + +idx_slot++; + +return 0; +} +/* -------------------------------------------------------------- */ +int filterstack_list(void) +{ +int idx; + +fprintf(stderr, "stack at %p, size %d, current %d\n", + stack_slots, nbre_filters, idx_slot); +for (idx=0; idx>> %s ( %p %d)\n", __func__, target, notused); +#endif + +for (idx=0; idx %d\n", foo); + return foo; + } + +foo = filterstack_add(5, 1, 1.0); +if (foo) { + fprintf(stderr, "filterstack add 1 --> %d\n", foo); + return foo; + } +foo = filterstack_add(13, 1, 1.0); +if (foo) { + fprintf(stderr, "filterstack add 2 --> %d\n", foo); + return foo; + } + +filterstack_list(); + +foo = filterstack_run(pimg, 0); +if (foo) { + fprintf(stderr, "filterstack run --> %d\n", foo); + return foo; + } + +return 0; +} +/* ----------------------------------------------------------- */ + int main(int argc, char *argv[]) { -int foo, iter, xloc, bloub; +int foo; FloatImg image; -char buff[1000]; double debut, fin; -float omega; verbosity = 2; - fimg_print_version(1); foo = fimg_create(&image, W, H, FIMG_TYPE_RGB); @@ -38,43 +72,21 @@ if (foo) { exit(1); } -// fimg_printhead(&image); +fimg_vdeg_a(&image, 255); srand(getpid()); debut = fimg_timer_set(TIMER); +foo = essai_filterstack(&image); +if (foo) { + fprintf(stderr, "essai filterstack --> %d\n", foo); + } +fin = fimg_timer_set(TIMER); -fimg_hdeg_a(&image, LMAX); - -for (iter=0; iter<32; iter++) { - - for (bloub=0; bloub<6; bloub++) { - xloc = rand() % W; - omega = (float)(0.1 + drand48()*0.6) * 0.4; - foo = vertical_singlitch(&image, xloc, LMAX, - omega, (float)iter); - if (foo) abort(); - } - - sprintf(buff, "/tmp/out_a%03d.png", iter); - foo = fimg_save_as_png(&image, buff, 0); - if (foo) { - fprintf(stderr, "err %d saving to '%s'\n", foo, buff); - exit(1); - } - -#if 0 - foo = trinarize(&image, 0); /* XXX */ - - sprintf(buff, "/tmp/out_b%03d.png", iter); - foo = fimg_save_as_png(&image, buff, 0); - if (foo) { - fprintf(stderr, "err %d saving to '%s'\n", foo, buff); - exit(1); - } -#endif +foo = fimg_save_as_png(&image, "foo.png", 0); +if (foo) { + fprintf(stderr, "erreur export %d\n", foo); } -fin = fimg_timer_set(TIMER); fprintf(stderr, "elapsed %f\n", fin-debut); fimg_destroy(&image);