first run of the filterstack

This commit is contained in:
tonton th 2020-12-03 21:56:45 +01:00
parent 3fb8dfcdb7
commit 77a137a168
4 changed files with 184 additions and 39 deletions

View File

@ -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...

109
Fonderie/filterstack.c Normal file
View File

@ -0,0 +1,109 @@
/*
* filterstack.c
*/
#include <stdio.h>
#include <stdlib.h>
#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<idx_slot; idx++) {
fprintf(stderr, "%3d %3d %3d %f\n", idx,
stack_slots[idx].numero,
stack_slots[idx].ival,
stack_slots[idx].fval);
}
return 0;
}
/* -------------------------------------------------------------- */
int filterstack_run(FloatImg *target, int notused)
{
int idx, foo;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %d)\n", __func__, target, notused);
#endif
for (idx=0; idx<idx_slot; idx++) {
fprintf(stderr, "%d : effect %2d on %p\n",
idx, stack_slots[idx].numero, target);
foo = crapulator(target, stack_slots[idx].numero, 0.0);
if (foo) {
fprintf(stderr, "crapulator error %d\n", foo);
return foo;
}
}
return 0;
}
/* -------------------------------------------------------------- */

18
Fonderie/filterstack.h Normal file
View File

@ -0,0 +1,18 @@
/*
* filterstack.h
*/
typedef struct {
int numero;
int ival;
float fval;
} FilterSlot;
int filterstack_init(int nbre);
int filterstack_add(int code, int ival, float fval);
int filterstack_list(void);
int filterstack_run(FloatImg *target, int notused);

View File

@ -9,10 +9,12 @@
#include "../floatimg.h"
#include "glitches.h"
#include "sfx.h"
#include "filterstack.h"
/* ----------------------------------------------------------- */
int verbosity;
int convert_to_gray; /* WTF ? */
#define PNG "out.png"
#define W 512
@ -20,16 +22,48 @@ int verbosity;
#define LMAX 249.9999
#define TIMER 1
/* ----------------------------------------------------------- */
int essai_filterstack(FloatImg *pimg)
{
int foo;
foo = filterstack_init(4);
if (foo) {
fprintf(stderr, "filterstack init --> %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);