Compare commits

..

4 Commits

Author SHA1 Message Date
77a137a168 first run of the filterstack 2020-12-03 21:56:45 +01:00
3fb8dfcdb7 cleanup 2020-12-03 19:47:02 +01:00
3572966edb minor tweaks 2020-12-03 13:05:44 +01:00
160a4afe7b new: 3x3 smoother in crapulator 2020-12-03 11:47:44 +01:00
8 changed files with 241 additions and 64 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...

View File

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

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

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

View File

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

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);
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();
foo = essai_filterstack(&image);
if (foo) {
fprintf(stderr, "essai filterstack --> %d\n", foo);
}
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);
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);
fimg_destroy(&image);

View File

@ -6,8 +6,6 @@
#include "../floatimg.h"
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
int fimg_filter_3x3(FloatImg *src, FloatImg *dst, FimgFilter3x3 *filtr)
{
@ -20,6 +18,15 @@ double dval;
fprintf(stderr, ">>> %s ( %p %p %p)\n", __func__, src, dst, filtr);
#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 */
pr = src->R; pg = src->G; pb = src->B;
w = src->width; h = src->height;
@ -69,7 +76,7 @@ for (y=1; y < h-1; y++) {
}
}
return -1;
return 0;
}
/* -------------------------------------------------------------------- */
/*