Compare commits

..

No commits in common. "77a137a168b1c353617139dded547b3a2284a01c" and "8f29cb0db033b5171fc50a99e810c7182cef9970" have entirely different histories.

8 changed files with 65 additions and 242 deletions

View File

@ -6,18 +6,15 @@
COPT = -g -fpic -no-pie -Wall -DDEBUG_LEVEL=0 -Werror=parentheses COPT = -g -fpic -no-pie -Wall -DDEBUG_LEVEL=0 -Werror=parentheses
LIBS = ../libfloatimg.a -lpnglite -lm LIBS = ../libfloatimg.a -lpnglite -lm
OBJS = fonctions.o sfx.o crapulator.o glitches.o metriques.o \ OBJS = fonctions.o sfx.o crapulator.o glitches.o metriques.o
filterstack.o DEPS = fonctions.h crapulator.h metriques.h glitches.h sfx.h
DEPS = fonctions.h crapulator.h metriques.h glitches.h sfx.h \
filterstack.h
all: fonderie interpolator t all: fonderie interpolator t
# --------------------------------------------------------- # ---------------------------------------------------------
t: t.c Makefile ${OBJS} t: t.c Makefile glitches.o sfx.o
gcc ${COPT} $< ${OBJS} ${LIBS} -lz -o $@ gcc ${COPT} $< glitches.o sfx.o ${LIBS} -lz -o $@
# --------------------------------------------------------- # ---------------------------------------------------------
@ -34,9 +31,6 @@ fonctions.o: fonctions.c fonctions.h Makefile
sfx.o: sfx.c ${DEPS} Makefile sfx.o: sfx.c ${DEPS} Makefile
gcc ${COPT} -c $< gcc ${COPT} -c $<
filterstack.o: filterstack.c ${DEPS} Makefile
gcc ${COPT} -c $<
# --------------------------------------------------------- # ---------------------------------------------------------
# #
# another way to brotch some pics... # another way to brotch some pics...

View File

@ -37,6 +37,7 @@ FloatImg img;
int retval; int retval;
fimg_clone(pimg, &img, 0); fimg_clone(pimg, &img, 0);
// XXX fimg_clear(&img);
retval = fimg_contour_2x2(pimg, &img, 0); retval = fimg_contour_2x2(pimg, &img, 0);
if (retval) { if (retval) {
fprintf(stderr, "%s : err contour %d\n", fprintf(stderr, "%s : err contour %d\n",
@ -49,43 +50,19 @@ fimg_destroy(&img);
return 0; return 0;
} }
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
static int insitu_filtre3x3(FloatImg *pimg)
{
FloatImg img;
int retval;
FimgFilter3x3 filtre = {
{
1.0, 2.0, 1.0,
2.0, 4.0, 2.0,
1.0, 2.0, 1.0,
},
16.0, 0.0
};
fimg_clone(pimg, &img, 0);
retval = fimg_filter_3x3(pimg, &img, &filtre);
if (retval) {
fprintf(stderr, "%s error %d on filter\n", __func__, retval);
exit(1);
}
fimg_copy_data(&img, pimg);
fimg_destroy(&img);
return retval;
}
/* -------------------------------------------------------------- */
/* /*
* This is the main filter engine * This is the main filter engine
* used both for input and output * used both for input and output
*/ */
#define DEBUG_THIS_CRAP 0 #define DEBUG_THIS_CRAP 1
int crapulator(FloatImg *image, int idFx, float fval) int crapulator(FloatImg *image, int idFx, float fval)
{ {
int retval; int retval;
// FloatImg imgtmp; // FloatImg imgtmp;
static int count = 0;
int flag_debug = 0;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %d %f )\n", __func__, fprintf(stderr, ">>> %s ( %p %d %f )\n", __func__,
@ -95,8 +72,6 @@ fprintf(stderr, ">>> %s ( %p %d %f )\n", __func__,
retval = 0; retval = 0;
#if DEBUG_THIS_CRAP #if DEBUG_THIS_CRAP
static int count = 0;
int flag_debug = 0;
if (666==count) { if (666==count) {
flag_debug = 1; flag_debug = 1;
fprintf(stderr, "DEBUG PT 1 in %s:%d\n", __func__, __LINE__); fprintf(stderr, "DEBUG PT 1 in %s:%d\n", __func__, __LINE__);
@ -137,6 +112,10 @@ switch (idFx) {
break; break;
case 9: case 9:
retval = fimg_classif_trial(image, image, 0.37, 0); retval = fimg_classif_trial(image, image, 0.37, 0);
if (retval) {
fprintf(stderr, "err %d in classif\n", retval);
exit(1);
}
break; break;
case 10: case 10:
retval = binarize(image, 0); retval = binarize(image, 0);
@ -147,9 +126,6 @@ switch (idFx) {
case 12: case 12:
retval = fimg_lissage_2x2(image); retval = fimg_lissage_2x2(image);
break; break;
case 13:
retval = insitu_filtre3x3(image);
break;
case 24: /* experiment ! */ case 24: /* experiment ! */
retval = des_bords_sombres_a(image, 160); retval = des_bords_sombres_a(image, 160);
break; break;
@ -170,9 +146,10 @@ if (flag_debug) {
fimg_save_as_png(image, "crap_after.png", 0); fimg_save_as_png(image, "crap_after.png", 0);
flag_debug = 0; flag_debug = 0;
} }
count++;
#endif #endif
count++;
return retval; return retval;
} }
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */

View File

@ -1,109 +0,0 @@
/*
* 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;
}
/* -------------------------------------------------------------- */

View File

@ -1,18 +0,0 @@
/*
* 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

@ -99,7 +99,7 @@ fprintf(stderr, "glob '%s' -> %d, %ld files found\n", pattern, foo,
/* get the size of the inputs images */ /* get the size of the inputs images */
foo = fimg_fileinfos(globbuf.gl_pathv[0], datas); foo = fimg_fileinfos(globbuf.gl_pathv[0], datas);
width = datas[0]; height = datas[1]; width = datas[0]; height = datas[1];
fprintf(stderr, "first image size %dx%d\n", width, height); fprintf(stderr, "image size %dx%d\n", width, height);
fimg_create(&input, width, height, 3); fimg_create(&input, width, height, 3);
@ -111,7 +111,7 @@ if (foo) {
exit(1); exit(1);
} }
maxvalue = fimg_get_maxvalue(&input); maxvalue = fimg_get_maxvalue(&input);
fprintf(stderr, "first image maxvalue %f\n", maxvalue); fprintf(stderr, "maxvalue %f\n", maxvalue);
foo = create_fifo(szfifo, width, height, FIMG_TYPE_RGB); foo = create_fifo(szfifo, width, height, FIMG_TYPE_RGB);
fprintf(stderr, "init fifo (%d slots) --> %d\n", szfifo, foo); fprintf(stderr, "init fifo (%d slots) --> %d\n", szfifo, foo);

View File

@ -73,7 +73,7 @@ for (idx=0; idx<nombre; idx++) {
foo, filename); foo, filename);
return -1; return -1;
} }
if (verbosity > 1) if (verbosity)
fprintf(stderr, "%5d %s %f\n", idx, filename, metrique); fprintf(stderr, "%5d %s %f\n", idx, filename, metrique);
idxvalues[idx].idx = idx; idxvalues[idx].idx = idx;
idxvalues[idx].value = metrique; idxvalues[idx].value = metrique;
@ -84,7 +84,7 @@ if (method) {
qsort(idxvalues, nombre, sizeof(IdxValue), cmp_idxvalues); qsort(idxvalues, nombre, sizeof(IdxValue), cmp_idxvalues);
} }
if (verbosity > 1) { if (verbosity) {
for (idx=0; idx<nombre; idx++) { for (idx=0; idx<nombre; idx++) {
printf("%5d %9.6f %5d\n", idx, printf("%5d %9.6f %5d\n", idx,
idxvalues[idx].value, idxvalues[idx].idx); idxvalues[idx].value, idxvalues[idx].idx);
@ -111,7 +111,7 @@ char *cptr, line[200];
float coef, value; float coef, value;
IdxValue *idx_values; IdxValue *idx_values;
fprintf(stderr, " interpolate from '%s' to '%s' with %d steps.\n", fprintf(stderr, "\nfrom '%s' to '%s' with %d steps.\n",
pattern, outdir, Nsteps); pattern, outdir, Nsteps);
memset(&globbuf, 0, sizeof(glob_t)); memset(&globbuf, 0, sizeof(glob_t));
@ -137,8 +137,11 @@ w = iarray[0], h = iarray[1];
fprintf(stderr, "first image size : %dx%d\n", w, h); fprintf(stderr, "first image size : %dx%d\n", w, h);
fimg_create(&A, w, h, 3); pFirst = &A; fimg_create(&A, w, h, 3); pFirst = &A;
// brotche_rand48_a(&A, 0.10, 250.555);
fimg_create(&B, w, h, 3); pSecond = &B; fimg_create(&B, w, h, 3); pSecond = &B;
// brotche_rand48_a(&B, 0.10, 250.555);
fimg_create(&Out, w, h, 3); fimg_create(&Out, w, h, 3);
// brotche_rand48_a(&Out, 0.10, 250.555);
ipng = 0; ipng = 0;
for (idx=0; idx<globbuf.gl_pathc; idx++) { for (idx=0; idx<globbuf.gl_pathc; idx++) {
@ -148,7 +151,7 @@ for (idx=0; idx<globbuf.gl_pathc; idx++) {
cptr = globbuf.gl_pathv[curpix]; /* aliasing filename */ cptr = globbuf.gl_pathv[curpix]; /* aliasing filename */
/* read the next file in B */ /* read the next file in B */
fprintf(stderr, "%5d / %5ld %s\r", idx, fprintf(stderr, "%5d / %5ld : loading %s\r", idx,
globbuf.gl_pathc, cptr); globbuf.gl_pathc, cptr);
foo = fimg_load_from_dump(cptr, &B); foo = fimg_load_from_dump(cptr, &B);
if (foo) { if (foo) {
@ -157,7 +160,8 @@ for (idx=0; idx<globbuf.gl_pathc; idx++) {
} }
value = idx_values[idx].value; value = idx_values[idx].value;
/* here, insert the input filter */ /* here, we can insert the input filter */
/* OK try it ... */
foo = crapulator(&B, infx, value/2.0); foo = crapulator(&B, infx, value/2.0);
if (foo) { if (foo) {
fprintf(stderr, "%s: input fx fail %d\n", __func__, foo); fprintf(stderr, "%s: input fx fail %d\n", __func__, foo);
@ -204,17 +208,11 @@ return 0;
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
void help(void) void help(void)
{ {
puts("\tINTERPOLATOR"); puts("\tINTERPOLATOR\noptions:");
puts("usage:\n\tinterpolator [options] <inglob> <outdir> <nbsteep>");
/* may be we can make options incoherent, like /* may be we can make options incoherent, like
* the options of 'fonderie' software ? * the options of 'fonderie' software ?
*/ */
puts("options:");
puts("\t-S nn\tmysterious sort");
puts("\t-v\tincrease verbosity");
puts("\t-w nn\tinput effect");
puts("\t-x nn\toutput effect");
exit(0); exit(0);
} }

View File

@ -9,12 +9,10 @@
#include "../floatimg.h" #include "../floatimg.h"
#include "glitches.h" #include "glitches.h"
#include "sfx.h" #include "sfx.h"
#include "filterstack.h"
/* ----------------------------------------------------------- */ /* ----------------------------------------------------------- */
int verbosity; int verbosity;
int convert_to_gray; /* WTF ? */
#define PNG "out.png" #define PNG "out.png"
#define W 512 #define W 512
@ -22,48 +20,16 @@ int convert_to_gray; /* WTF ? */
#define LMAX 249.9999 #define LMAX 249.9999
#define TIMER 1 #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 main(int argc, char *argv[])
{ {
int foo; int foo, iter, xloc, bloub;
FloatImg image; FloatImg image;
char buff[1000];
double debut, fin; double debut, fin;
float omega;
verbosity = 2; verbosity = 2;
fimg_print_version(1); fimg_print_version(1);
foo = fimg_create(&image, W, H, FIMG_TYPE_RGB); foo = fimg_create(&image, W, H, FIMG_TYPE_RGB);
@ -72,21 +38,43 @@ if (foo) {
exit(1); exit(1);
} }
fimg_vdeg_a(&image, 255); // fimg_printhead(&image);
srand(getpid()); srand(getpid());
debut = fimg_timer_set(TIMER); debut = fimg_timer_set(TIMER);
foo = essai_filterstack(&image);
if (foo) { fimg_hdeg_a(&image, LMAX);
fprintf(stderr, "essai filterstack --> %d\n", foo);
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
}
fin = fimg_timer_set(TIMER); fin = fimg_timer_set(TIMER);
foo = fimg_save_as_png(&image, "foo.png", 0);
if (foo) {
fprintf(stderr, "erreur export %d\n", foo);
}
fprintf(stderr, "elapsed %f\n", fin-debut); fprintf(stderr, "elapsed %f\n", fin-debut);
fimg_destroy(&image); fimg_destroy(&image);

View File

@ -6,6 +6,8 @@
#include "../floatimg.h" #include "../floatimg.h"
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
int fimg_filter_3x3(FloatImg *src, FloatImg *dst, FimgFilter3x3 *filtr) int fimg_filter_3x3(FloatImg *src, FloatImg *dst, FimgFilter3x3 *filtr)
{ {
@ -18,15 +20,6 @@ double dval;
fprintf(stderr, ">>> %s ( %p %p %p)\n", __func__, src, dst, filtr); fprintf(stderr, ">>> %s ( %p %p %p)\n", __func__, src, dst, filtr);
#endif #endif
if (src->type != FIMG_TYPE_RGB) {
fprintf(stderr, "%s: src type %d invalid\n", __func__, src->type);
return -99;
}
if (dst->type != FIMG_TYPE_RGB) {
fprintf(stderr, "%s: dst type %d invalid\n", __func__, dst->type);
return -99;
}
/* aliasing some vars for cleaner code */ /* aliasing some vars for cleaner code */
pr = src->R; pg = src->G; pb = src->B; pr = src->R; pg = src->G; pb = src->B;
w = src->width; h = src->height; w = src->width; h = src->height;
@ -76,7 +69,7 @@ for (y=1; y < h-1; y++) {
} }
} }
return 0; return -1;
} }
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* /*