water patch

This commit is contained in:
tonton th 2020-12-10 19:19:35 +01:00
parent b03e674056
commit 966ae9e465
10 changed files with 160 additions and 69 deletions

View File

@ -165,6 +165,7 @@ switch (idFx) {
break; break;
case 12: case 12:
retval = fimg_lissage_2x2(image); retval = fimg_lissage_2x2(image);
(void)fimg_killborders(image);
break; break;
case 13: case 13:
retval = insitu_filtre3x3(image); retval = insitu_filtre3x3(image);
@ -176,6 +177,12 @@ switch (idFx) {
retval = kill_a_few_lines(image, fval, retval = kill_a_few_lines(image, fval,
image->height/20); image->height/20);
break; break;
case 16:
retval = bouger_les_pixels(image, 6);
break;
case 17:
retval = mirror_split(image, 0);
break;
/* here are the glitches */ /* here are the glitches */
case 24: /* experiment ! */ case 24: /* experiment ! */

View File

@ -17,107 +17,105 @@
extern int verbosity; extern int verbosity;
static FilterSlot *stack_slots; static FilterStack f_stacks[NUMBER_OF_STACK];
static int nbre_filters, idx_slot;
/* -------------------------------------------------------------- */
int filterstack_init(int nbre)
{
FilterSlot *fsptr;
/* -------------------------------------------------------------- */
int filterstack_init(int numid, int nbre)
{
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %d )\n", __func__, nbre); fprintf(stderr, ">>> %s ( %d %d )\n", __func__, numid, nbre);
#endif #endif
if (NULL != stack_slots) { if (numid < 0 || numid > NUMBER_OF_STACK) {
fprintf(stderr, "ERR stack_slots = %p\n",stack_slots); fprintf(stderr, "%s: slot number %d invalid\n", __func__, numid);
return -1;
}
fsptr = calloc(nbre, sizeof(FilterSlot));
if (NULL == fsptr) {
fprintf(stderr, "%s : no memory\n", __func__);
exit(1); exit(1);
} }
stack_slots = fsptr; memset(&f_stacks[numid], 0, sizeof(FilterSlot));
nbre_filters = nbre;
idx_slot = 0;
fprintf(stderr, "%s: stack at %p\n", __func__, stack_slots);
return 0; return 0;
} }
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
int filterstack_add(int code, int ival, float fval) int filterstack_add(int numid, int code, int ival, float fval)
{ {
int idxsl;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %d %d %f )\n", __func__, code, ival, fval); fprintf(stderr, ">>> %s ( %d %d %f )\n", __func__, code, ival, fval);
#endif #endif
if (NULL==stack_slots) { if (numid < 0 || numid > NUMBER_OF_STACK) {
fprintf(stderr, "%s: NULL statck !\n", __func__); fprintf(stderr, "%s: slot number %d invalid\n", __func__, numid);
exit(1); exit(1);
} }
if (idx_slot == nbre_filters) {
if (f_stacks[numid].count == FILTER_BY_STACK) {
fprintf(stderr, "%s: stack is full\n", __func__); fprintf(stderr, "%s: stack is full\n", __func__);
return -1; return -1;
} }
stack_slots[idx_slot].numero = code; idxsl = f_stacks[numid].count; /* aliasing */
stack_slots[idx_slot].ival = ival;
stack_slots[idx_slot].fval = fval;
idx_slot++; f_stacks[numid].slots[idxsl].numero = code;
f_stacks[numid].slots[idxsl].ival = ival;
f_stacks[numid].slots[idxsl].fval = fval;
f_stacks[numid].count++;
return 0; return 0;
} }
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
int filterstack_list(const char *txt) int filterstack_list(int numid, const char *txt)
{ {
int idx; int idx;
if (NULL==stack_slots) { if (numid < 0 || numid > NUMBER_OF_STACK) {
fprintf(stderr, "%s: NULL statck !\n", __func__); fprintf(stderr, "%s: slot number %d invalid\n", __func__, numid);
exit(1); exit(1);
} }
fprintf(stderr, "------- %-20s --------\n", txt); fprintf(stderr, "--- %2d -- %-20s --------\n", numid, txt);
fprintf(stderr, "stack at %p, size %d, current %d\n", // fprintf(stderr, "stack at %p, size %d, current %d\n",
stack_slots, nbre_filters, idx_slot); // f_slots, nbre_filters, idx_slot);
fprintf(stderr, "idx fx# name ival fval\n"); fprintf(stderr, "idx fx# name ival fval\n");
for (idx=0; idx<idx_slot; idx++) {
for (idx=0; idx<f_stacks[numid].count; idx++) {
fprintf(stderr, "%3d %3d %-10s %3d %f\n", idx, fprintf(stderr, "%3d %3d %-10s %3d %f\n", idx,
stack_slots[idx].numero, f_stacks[numid].slots[idx].numero,
crap_name_from_number(stack_slots[idx].numero), crap_name_from_number(f_stacks[numid].slots[idx].numero),
stack_slots[idx].ival, f_stacks[numid].slots[idx].ival,
stack_slots[idx].fval); f_stacks[numid].slots[idx].fval);
} }
return 0; return 0;
} }
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
int filterstack_run(FloatImg *target, int notused) int filterstack_run(int numid, FloatImg *target, int notused)
{ {
int idx, foo; int idx, foo, eff;
float fv;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, target, notused); fprintf(stderr, ">>> %s ( %p %d )\n", __func__, target, notused);
#endif #endif
if (NULL==stack_slots) { if (numid < 0 || numid > NUMBER_OF_STACK) {
fprintf(stderr, "%s: NULL statck !\n", __func__); fprintf(stderr, "%s: slot number %d invalid\n", __func__, numid);
exit(1); exit(1);
} }
for (idx=0; idx<idx_slot; idx++) { for (idx=0; idx<f_stacks[numid].count; idx++) {
eff = f_stacks[numid].slots[idx].numero;
fv = f_stacks[numid].slots[idx].fval;
if (verbosity > 1) if (verbosity > 1)
fprintf(stderr, "%d : effect %2d on %p\n", fprintf(stderr, "%d : effect %2d on %p\n",
idx, stack_slots[idx].numero, target); idx, eff, target);
foo = crapulator(target, eff, fv);
foo = crapulator(target, stack_slots[idx].numero,
stack_slots[idx].fval);
if (foo) { if (foo) {
fprintf(stderr, "crapulator error %d\n", foo); fprintf(stderr, "crapulator error %d\n", foo);
return foo; return foo;
@ -127,7 +125,7 @@ for (idx=0; idx<idx_slot; idx++) {
return 0; return 0;
} }
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
int load_stack_from_file(char *fname, int notused) int load_stack_from_file(int numid, char *fname, int notused)
{ {
FILE *fp; FILE *fp;
// int a, b; // int a, b;
@ -138,8 +136,8 @@ FILE *fp;
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, notused); fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, notused);
#endif #endif
if (NULL==stack_slots) { if (numid < 0 || numid > NUMBER_OF_STACK) {
fprintf(stderr, "%s: NULL statck !\n", __func__); fprintf(stderr, "%s: slot number %d invalid\n", __func__, numid);
exit(1); exit(1);
} }
@ -151,8 +149,6 @@ if (NULL==(fp=fopen(fname, "r"))) {
/* /*
* here was dragons * here was dragons
*/ */
/* hadoc parser ? */ /* hadoc parser ? */
fclose(fp); fclose(fp);
@ -160,14 +156,19 @@ fclose(fp);
return -1; return -1;
} }
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
int parse_filter_chain(const char *argument) int parse_filter_chain(int numid, char *argument)
{ {
char *cptr; char *cptr;
int value, foo; int value, foo;
if (numid < 0 || numid > NUMBER_OF_STACK) {
fprintf(stderr, "%s: slot number %d invalid\n", __func__, numid);
exit(1);
}
fprintf(stderr, "\n%s: arg = '%s'\n", __func__, argument); fprintf(stderr, "\n%s: arg = '%s'\n", __func__, argument);
foo = filterstack_init(8); foo = filterstack_init(numid, 8);
if (foo) { if (foo) {
fprintf(stderr, "%s: filterstack init --> %d\n", __func__, foo); fprintf(stderr, "%s: filterstack init --> %d\n", __func__, foo);
return foo; return foo;
@ -180,7 +181,7 @@ for (;;) {
argument = NULL; argument = NULL;
// fprintf(stderr, " parsing '%s'\n", cptr); // fprintf(stderr, " parsing '%s'\n", cptr);
if (1 == sscanf(cptr, "%d", &value)) { if (1 == sscanf(cptr, "%d", &value)) {
foo = filterstack_add(value, 1, 1.0); foo = filterstack_add(numid, value, 1, 1.0);
if (foo) { if (foo) {
fprintf(stderr, "%s: err %d add\n", fprintf(stderr, "%s: err %d add\n",
__func__, foo); __func__, foo);
@ -188,7 +189,7 @@ for (;;) {
} }
} }
if (verbosity) filterstack_list(__func__); if (verbosity) filterstack_list(numid, __func__);
return 0; return 0;
} }
/* ----------------------------------------------------------- */ /* ----------------------------------------------------------- */

View File

@ -8,16 +8,23 @@ typedef struct {
float fval; float fval;
} FilterSlot; } FilterSlot;
#define NUMBER_OF_STACK 8
#define FILTER_BY_STACK 8
int filterstack_init(int nbre); typedef struct {
int count;
FilterSlot slots[FILTER_BY_STACK];
} FilterStack;
int filterstack_add(int code, int ival, float fval); int filterstack_init(int numid, int nbre);
int filterstack_list(const char *txt); /* XXX */ int filterstack_add(int numid, int code, int ival, float fval);
int filterstack_run(FloatImg *target, int notused); int filterstack_list(int numid, const char *txt); /* XXX */
int load_stack_from_file(char *fname, int notused); int filterstack_run(int numid, FloatImg *target, int notused);
int parse_filter_chain(const char *argument); int load_stack_from_file(int numid, char *fname, int notused);
int parse_filter_chain(int numid, char *argument);

View File

@ -120,7 +120,7 @@ return -1;
/* /*
* used by vertical_singlitch() * used by vertical_singlitch()
*/ */
int x_delta(float dy, float phy) static int x_delta(float dy, float phy)
{ {
float param, fv; float param, fv;
param = dy + phy; param = dy + phy;

View File

@ -181,7 +181,7 @@ for (idx=0; idx<globbuf.gl_pathc; idx++) {
// exit(1); // exit(1);
// } // }
foo = filterstack_run(&Out, 0); foo = filterstack_run(0, &Out, 0);
if (foo) { if (foo) {
fprintf(stderr, "run filt stk--> %d\n", foo); fprintf(stderr, "run filt stk--> %d\n", foo);
return foo; return foo;
@ -269,7 +269,7 @@ if (3 != (argc-optind)) {
exit(1); exit(1);
} }
foo = parse_filter_chain(filterchain); foo = parse_filter_chain(0, filterchain);
if (foo) { if (foo) {
fprintf(stderr, "err %d parsing '%s'\n", foo, filterchain); fprintf(stderr, "err %d parsing '%s'\n", foo, filterchain);
exit(1); exit(1);

View File

@ -59,7 +59,20 @@ if (foo) {
return foo; return foo;
} }
fval = -1.0; /* sensible default value */ fval = -1.0; /* sensible default value */
foo = get_float_metric_b(&image, &fval); switch (mode) {
case 1:
foo = get_float_metric_a(&image, &fval);
break;
case 2:
foo = get_float_metric_b(&image, &fval);
break;
default:
fprintf(stderr, "%s: method %d invalid\n",
__func__, mode);
exit(1);
break; /* not reached */
}
*where = fval; *where = fval;
fimg_destroy(&image); fimg_destroy(&image);

View File

@ -18,6 +18,63 @@
*/ */
extern int verbosity; extern int verbosity;
/* -------------------------------------------------------------- */
/* nouveau du 9 decembre 2020, en ecoutant le Fermion raconter du
superbe portnawak */
int bouger_les_pixels(FloatImg *pimg, int intensite)
{
int x, y, nx, ny;
float rgb[3];
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pimg, intensite);
#endif
if (intensite < 1) {
fprintf(stderr, "%s: %d bad intensity\n", __func__, intensite);
return -1;
}
for (x=0; x<pimg->width; x++) {
for (y=0; y<pimg->height; y++) {
nx = x+(rand()%intensite)-(intensite/2);
ny = y+(rand()%intensite)-(intensite/2);
if ( nx<0 || ny<0 || nx>=pimg->width
|| ny>=pimg->height )
continue;
fimg_get_rgb(pimg, nx, ny, rgb);
fimg_put_rgb(pimg, x, y, rgb);
}
}
return 0;
}
/* -------------------------------------------------------------- */
/* nouveau du 9 decembre 2020, en ecoutant les Cernettes */
int mirror_split(FloatImg *pimg, int kaboo)
{
int line, x, xs, xd;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pimg, kaboo);
#endif
for (line=0; line<pimg->height; line++) {
for (x=0; x<pimg->width/2; x++) {
xs = (pimg->width * line) + x;
xd = (pimg->width * line) + (pimg->width -x);
pimg->R[xd] = pimg->R[xs];
pimg->G[xd] = pimg->G[xs];
pimg->B[xd] = pimg->B[xs];
}
}
return 0;
}
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
/* nouveau du 20 novembre 2020, pour encoder une vidz du vernissage /* nouveau du 20 novembre 2020, pour encoder une vidz du vernissage
* du festival Sauvageonnes de Mixart-Myrys */ * du festival Sauvageonnes de Mixart-Myrys */

View File

@ -3,6 +3,10 @@
*/ */
int bouger_les_pixels(FloatImg *pimg, int kaboo);
int mirror_split(FloatImg *pimg, int kaboo);
int des_bords_sombres_a(FloatImg *pimg, int offset); int des_bords_sombres_a(FloatImg *pimg, int offset);
int trinarize(FloatImg *pimg, int notused); // in sfx.c int trinarize(FloatImg *pimg, int notused); // in sfx.c

View File

@ -23,6 +23,8 @@ int convert_to_gray; /* WTF ? */
#define LMAX 255.0 #define LMAX 255.0
#define TIMER 1 #define TIMER 1
#define STK 0
/* ----------------------------------------------------------- */ /* ----------------------------------------------------------- */
int essai_filterstack(char *fname) int essai_filterstack(char *fname)
@ -31,7 +33,7 @@ int foo;
FloatImg image; FloatImg image;
double debut, fin; double debut, fin;
filterstack_list(__func__); filterstack_list(STK, __func__);
foo = fimg_create_from_dump(fname, &image); foo = fimg_create_from_dump(fname, &image);
if (foo) { if (foo) {
@ -43,7 +45,7 @@ srand(getpid()); srand48(getpid());
debut = fimg_timer_set(TIMER); debut = fimg_timer_set(TIMER);
foo = filterstack_run(&image, 0); foo = filterstack_run(STK, &image, 0);
if (foo) { if (foo) {
fprintf(stderr, "filterstack run --> %d\n", foo); fprintf(stderr, "filterstack run --> %d\n", foo);
return foo; return foo;
@ -92,7 +94,7 @@ while ((opt = getopt(argc, argv, "hF:v")) != -1) {
fprintf(stderr, "%s : argc = %d, optind = %d\n", argv[0], argc, optind); fprintf(stderr, "%s : argc = %d, optind = %d\n", argv[0], argc, optind);
#endif #endif
foo = parse_filter_chain(filterchain); foo = parse_filter_chain(STK, filterchain);
if (foo) { if (foo) {
fprintf(stderr, "err %d in parse_filter_chain\n", foo); fprintf(stderr, "err %d in parse_filter_chain\n", foo);
exit(1); exit(1);