is filterstack ok ?

This commit is contained in:
tonton th 2020-12-04 19:55:34 +01:00
parent 11b1d996e8
commit 8009acc0d1
3 changed files with 80 additions and 27 deletions

View File

@ -9,8 +9,8 @@
#include "crapulator.h"
#include "filterstack.h"
#undef DEBUG_LEVEL
#define DEBUG_LEVEL 1
// #undef DEBUG_LEVEL
// #define DEBUG_LEVEL 1
/* -------------------------------------------------------------- */
static FilterSlot *stack_slots;
@ -67,12 +67,14 @@ idx_slot++;
return 0;
}
/* -------------------------------------------------------------- */
int filterstack_list(void)
int filterstack_list(char *txt)
{
int idx;
fprintf(stderr, "------- %-20s --------\n", txt);
fprintf(stderr, "stack at %p, size %d, current %d\n",
stack_slots, nbre_filters, idx_slot);
fprintf(stderr, "idx fx# ival fval\n");
for (idx=0; idx<idx_slot; idx++) {
fprintf(stderr, "%3d %3d %3d %f\n", idx,
@ -98,7 +100,8 @@ 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);
foo = crapulator(target, stack_slots[idx].numero,
stack_slots[idx].fval);
if (foo) {
fprintf(stderr, "crapulator error %d\n", foo);
return foo;
@ -108,3 +111,9 @@ for (idx=0; idx<idx_slot; idx++) {
return 0;
}
/* -------------------------------------------------------------- */
int load_stack_from_file(char *fname, int notused)
{
return -1;
}
/* -------------------------------------------------------------- */

View File

@ -13,6 +13,9 @@ int filterstack_init(int nbre);
int filterstack_add(int code, int ival, float fval);
int filterstack_list(void);
int filterstack_list(char *txt); /* XXX */
int filterstack_run(FloatImg *target, int notused);
int load_stack_from_file(char *fname, int notused);

View File

@ -5,6 +5,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "../floatimg.h"
#include "glitches.h"
@ -17,9 +18,9 @@ int verbosity;
int convert_to_gray; /* WTF ? */
#define PNG "out.png"
#define W 512
#define H 256
#define LMAX 249.9999
#define W 800
#define H 600
#define LMAX 255.0
#define TIMER 1
/* ----------------------------------------------------------- */
@ -28,24 +29,8 @@ 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();
filterstack_list(__func__);
foo = filterstack_run(pimg, 0);
if (foo) {
@ -56,15 +41,71 @@ if (foo) {
return 0;
}
/* ----------------------------------------------------------- */
int parse_filter_chain(char *argument)
{
char *cptr;
int value, foo;
fprintf(stderr, "\n%s: arg = '%s'\n", __func__, argument);
foo = filterstack_init(4);
if (foo) {
fprintf(stderr, "%s: filterstack init --> %d\n", __func__, foo);
return foo;
}
for (;;) {
cptr = strtok(argument, ":");
fprintf(stderr, "cptr %p\n", cptr);
if (NULL==cptr) break;
argument = NULL;
fprintf(stderr, " parsing '%s'\n", cptr);
if (1 == sscanf(cptr, "%d", &value)) {
foo = filterstack_add(value, 1, 1.0);
if (foo) {
fprintf(stderr, "%s: err %d add\n",
__func__, foo);
}
}
}
filterstack_list(__func__);
return 0;
}
/* ----------------------------------------------------------- */
int help(void)
{
puts("yolo!");
exit(0);
}
/* ----------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo;
FloatImg image;
double debut, fin;
int opt;
char *filterchain = "0";
verbosity = 2;
fimg_print_version(1);
fprintf(stderr, "*** %s : compiled by tTh, %s %s\n", __FILE__,
__DATE__, __TIME__);
fimg_print_version(2);
while ((opt = getopt(argc, argv, "hF:v")) != -1) {
switch(opt) {
case 'h': help(); break;
case 'F': filterchain = optarg;
break;
case 'v': verbosity++; break;
}
}
#if DEBUG_LEVEL
fprintf(stderr, "%s : argc = %d, optind = %d\n", argv[0], argc, optind);
#endif
parse_filter_chain(filterchain);
foo = fimg_create(&image, W, H, FIMG_TYPE_RGB);
if (foo) {