Browse Source

first run of the filterstack

master
tonton th 2 years ago
parent
commit
77a137a168
  1. 14
      Fonderie/Makefile
  2. 109
      Fonderie/filterstack.c
  3. 18
      Fonderie/filterstack.h
  4. 82
      Fonderie/t.c

14
Fonderie/Makefile

@ -6,15 +6,18 @@ @@ -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 @@ -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

@ -0,0 +1,109 @@ @@ -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

@ -0,0 +1,18 @@ @@ -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);

82
Fonderie/t.c

@ -9,10 +9,12 @@ @@ -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; @@ -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) { @@ -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);

Loading…
Cancel
Save