2020-12-03 21:56:45 +01:00
|
|
|
/*
|
|
|
|
* filterstack.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2020-12-07 04:45:51 +01:00
|
|
|
#include <string.h>
|
2020-12-03 21:56:45 +01:00
|
|
|
|
|
|
|
#include "../floatimg.h"
|
2020-12-03 22:05:21 +01:00
|
|
|
#include "crapulator.h"
|
2020-12-03 21:56:45 +01:00
|
|
|
#include "filterstack.h"
|
|
|
|
|
2020-12-04 19:55:34 +01:00
|
|
|
// #undef DEBUG_LEVEL
|
|
|
|
// #define DEBUG_LEVEL 1
|
2020-12-03 21:56:45 +01:00
|
|
|
|
|
|
|
/* -------------------------------------------------------------- */
|
2020-12-07 04:45:51 +01:00
|
|
|
|
|
|
|
extern int verbosity;
|
|
|
|
|
2020-12-03 21:56:45 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
2020-12-07 04:45:51 +01:00
|
|
|
int filterstack_list(const char *txt)
|
2020-12-03 21:56:45 +01:00
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
|
2020-12-07 04:45:51 +01:00
|
|
|
if (NULL==stack_slots) {
|
|
|
|
fprintf(stderr, "%s: NULL statck !\n", __func__);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2020-12-04 19:55:34 +01:00
|
|
|
fprintf(stderr, "------- %-20s --------\n", txt);
|
2020-12-03 21:56:45 +01:00
|
|
|
fprintf(stderr, "stack at %p, size %d, current %d\n",
|
|
|
|
stack_slots, nbre_filters, idx_slot);
|
2020-12-08 15:51:07 +01:00
|
|
|
fprintf(stderr, "idx fx# name ival fval\n");
|
2020-12-03 21:56:45 +01:00
|
|
|
for (idx=0; idx<idx_slot; idx++) {
|
|
|
|
|
2020-12-08 15:51:07 +01:00
|
|
|
fprintf(stderr, "%3d %3d %-10s %3d %f\n", idx,
|
2020-12-03 21:56:45 +01:00
|
|
|
stack_slots[idx].numero,
|
2020-12-08 15:51:07 +01:00
|
|
|
crap_name_from_number(stack_slots[idx].numero),
|
2020-12-03 21:56:45 +01:00
|
|
|
stack_slots[idx].ival,
|
|
|
|
stack_slots[idx].fval);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
int filterstack_run(FloatImg *target, int notused)
|
|
|
|
{
|
|
|
|
int idx, foo;
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
2020-12-07 04:45:51 +01:00
|
|
|
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, target, notused);
|
2020-12-03 21:56:45 +01:00
|
|
|
#endif
|
|
|
|
|
2020-12-07 04:45:51 +01:00
|
|
|
if (NULL==stack_slots) {
|
|
|
|
fprintf(stderr, "%s: NULL statck !\n", __func__);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2020-12-03 21:56:45 +01:00
|
|
|
for (idx=0; idx<idx_slot; idx++) {
|
|
|
|
|
2020-12-07 04:45:51 +01:00
|
|
|
if (verbosity > 1)
|
|
|
|
fprintf(stderr, "%d : effect %2d on %p\n",
|
|
|
|
idx, stack_slots[idx].numero, target);
|
2020-12-03 21:56:45 +01:00
|
|
|
|
2020-12-04 19:55:34 +01:00
|
|
|
foo = crapulator(target, stack_slots[idx].numero,
|
|
|
|
stack_slots[idx].fval);
|
2020-12-03 21:56:45 +01:00
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "crapulator error %d\n", foo);
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
2020-12-04 19:55:34 +01:00
|
|
|
int load_stack_from_file(char *fname, int notused)
|
|
|
|
{
|
2020-12-07 04:45:51 +01:00
|
|
|
FILE *fp;
|
|
|
|
// int a, b;
|
|
|
|
// float f;
|
|
|
|
// char line[100];
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, notused);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (NULL==stack_slots) {
|
|
|
|
fprintf(stderr, "%s: NULL statck !\n", __func__);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL==(fp=fopen(fname, "r"))) {
|
|
|
|
perror(fname);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* here was dragons
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/* hadoc parser ? */
|
|
|
|
|
|
|
|
fclose(fp);
|
2020-12-04 19:55:34 +01:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
2020-12-07 04:45:51 +01:00
|
|
|
int parse_filter_chain(const char *argument)
|
|
|
|
{
|
|
|
|
char *cptr;
|
|
|
|
int value, foo;
|
|
|
|
|
|
|
|
fprintf(stderr, "\n%s: arg = '%s'\n", __func__, argument);
|
|
|
|
|
|
|
|
foo = filterstack_init(8);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (verbosity) filterstack_list(__func__);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* ----------------------------------------------------------- */
|