Compare commits

...

4 Commits

Author SHA1 Message Date
62aa91e434 is filterstack really ok ? 2020-12-07 04:45:51 +01:00
b1e613276d kill this warning 2020-12-06 11:13:06 +01:00
d5ccf30dcc testing filter chain 2020-12-04 23:14:44 +01:00
8009acc0d1 is filterstack ok ? 2020-12-04 19:55:34 +01:00
6 changed files with 214 additions and 78 deletions

View File

@ -1,17 +1,22 @@
#!/bin/bash
OUTF='/tmp/out_a*.png'
FILTRES="5:6:13 2:2 5:9:8 4:25 8:13:13:7 10:1 25:25:25:25"
rm $OUTF
make t && ./t
A_PART=$(ls -1 $OUTF)
Z_PART=$(ls -r1 $OUTF)
convert -delay 10 ${A_PART} ${Z_PART} foo.gif
rm /tmp/fstack*.png
for F in $FILTRES
do
I="/tmp/fstack-"$F".png"
echo ; echo $I
./t -F $F
txt=$(printf "[%-10s]" $F)
convert foo.png -pointsize 28 -kerning 0 \
-fill Gray80 -undercolor Gray20 \
-font Courier-Bold \
-annotate +0+25 "$txt" \
$I
done
convert -delay 150 /tmp/fstack*.png foo.gif

View File

@ -4,15 +4,19 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../floatimg.h"
#include "crapulator.h"
#include "filterstack.h"
#undef DEBUG_LEVEL
#define DEBUG_LEVEL 1
// #undef DEBUG_LEVEL
// #define DEBUG_LEVEL 1
/* -------------------------------------------------------------- */
extern int verbosity;
static FilterSlot *stack_slots;
static int nbre_filters, idx_slot;
/* -------------------------------------------------------------- */
@ -67,12 +71,19 @@ idx_slot++;
return 0;
}
/* -------------------------------------------------------------- */
int filterstack_list(void)
int filterstack_list(const char *txt)
{
int idx;
if (NULL==stack_slots) {
fprintf(stderr, "%s: NULL statck !\n", __func__);
exit(1);
}
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,
@ -90,15 +101,22 @@ int filterstack_run(FloatImg *target, int notused)
int idx, foo;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %d)\n", __func__, target, notused);
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, target, notused);
#endif
if (NULL==stack_slots) {
fprintf(stderr, "%s: NULL statck !\n", __func__);
exit(1);
}
for (idx=0; idx<idx_slot; idx++) {
if (verbosity > 1)
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 +126,68 @@ for (idx=0; idx<idx_slot; idx++) {
return 0;
}
/* -------------------------------------------------------------- */
int load_stack_from_file(char *fname, int notused)
{
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);
return -1;
}
/* -------------------------------------------------------------- */
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;
}
/* ----------------------------------------------------------- */

View File

@ -3,7 +3,7 @@
*/
typedef struct {
int numero;
int numero; /* id in rapulator */
int ival;
float fval;
} FilterSlot;
@ -13,6 +13,11 @@ int filterstack_init(int nbre);
int filterstack_add(int code, int ival, float fval);
int filterstack_list(void);
int filterstack_list(const char *txt); /* XXX */
int filterstack_run(FloatImg *target, int notused);
int load_stack_from_file(char *fname, int notused);
int parse_filter_chain(const char *argument);

View File

@ -93,8 +93,8 @@ if (foo) {
exit(1);
}
fprintf(stderr, "glob '%s' -> %d, %ld files found\n", pattern, foo,
globbuf.gl_pathc);
fprintf(stderr, "glob '%s' -> %d, %d files found\n", pattern, foo,
(int)globbuf.gl_pathc);
/* get the size of the inputs images */
foo = fimg_fileinfos(globbuf.gl_pathv[0], datas);
@ -140,7 +140,7 @@ for (idx=0; idx<globbuf.gl_pathc; idx++) {
fprintf(stderr, "traitement %s -> %d WTF?\n", cptr, foo);
break;
}
fprintf(stderr, "\t%5d / %5ld\r", idx, globbuf.gl_pathc);
fprintf(stderr, "\t%5d / %5d\r", idx, (int)globbuf.gl_pathc);
}
fputs("\n", stderr);

View File

@ -20,8 +20,7 @@
#include "glitches.h"
#include "crapulator.h"
#include "metriques.h"
// XXX #include "fonctions.h"
#include "filterstack.h"
int verbosity;
int convert_to_gray; /* needed by fonctions.c */
@ -73,14 +72,15 @@ for (idx=0; idx<nombre; idx++) {
foo, filename);
return -1;
}
if (verbosity > 1)
fprintf(stderr, "%5d %s %f\n", idx, filename, metrique);
if (verbosity)
fprintf(stderr, "%5d %s %f\r", idx, filename, metrique);
idxvalues[idx].idx = idx;
idxvalues[idx].value = metrique;
}
if (method) {
/* and now, we can massage all our datas */
fprintf(stderr, "sorting %d ...\n", method);
qsort(idxvalues, nombre, sizeof(IdxValue), cmp_idxvalues);
}
@ -116,8 +116,8 @@ fprintf(stderr, " interpolate from '%s' to '%s' with %d steps.\n",
memset(&globbuf, 0, sizeof(glob_t));
foo = glob(pattern, 0, NULL, &globbuf);
fprintf(stderr, "globbing '%s' -> %d, %ld files found\n",
pattern, foo, globbuf.gl_pathc);
fprintf(stderr, "globbing '%s' -> %d, %d files found\n",
pattern, foo, (int)globbuf.gl_pathc);
if (0 == globbuf.gl_pathc) {
fprintf(stderr, "%s : no file found, aborting\n", __func__);
return -1;
@ -125,7 +125,10 @@ if (0 == globbuf.gl_pathc) {
idx_values = NULL;
foo = tentative_triage(&globbuf, &idx_values, sort);
fprintf(stderr, "\tTRI of %p -> %d\n\n", idx_values, foo);
if (foo) {
fprintf(stderr, "sort of %p -> %d\n\n", idx_values, foo);
return foo;
}
foo = fimg_fileinfos(globbuf.gl_pathv[0], iarray);
if (FIMG_TYPE_RGB != iarray[2]) {
@ -148,8 +151,8 @@ 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 %s\r", idx,
globbuf.gl_pathc, cptr);
fprintf(stderr, "%5d / %5d %s\r", idx,
(int)globbuf.gl_pathc, cptr);
foo = fimg_load_from_dump(cptr, &B);
if (foo) {
fprintf(stderr, "load %s from dump -> %d\n", cptr, foo);
@ -169,7 +172,19 @@ for (idx=0; idx<globbuf.gl_pathc; idx++) {
fimg_interpolate(pSecond, pFirst, &Out, coef);
/* here we can insert the OUTPUT filter */
foo = crapulator(&Out, outfx, value);
// foo = crapulator(&Out, outfx, value);
//if (foo) {
// fprintf(stderr, "\n%s: out fx %d failure %d\n",
// __func__, outfx, foo);
// exit(1);
// }
foo = filterstack_run(&Out, 0);
if (foo) {
fprintf(stderr, "run filt stk--> %d\n", foo);
return foo;
}
if (foo) {
fprintf(stderr, "\n%s: out fx %d failure %d\n",
__func__, outfx, foo);
@ -195,6 +210,10 @@ for (idx=0; idx<globbuf.gl_pathc; idx++) {
pFirst = pTmp;
/* XXX THIS CODE DON'T WORK !!! */
#endif
}
fprintf(stderr, "\ngenerated %d png files\n", ipng);
@ -212,9 +231,10 @@ puts("usage:\n\tinterpolator [options] <inglob> <outdir> <nbsteep>");
*/
puts("options:");
puts("\t-S nn\tmysterious sort");
puts("\t-v\tincrease verbosity");
puts("\t-F i:j\tfilter chain");
puts("\t-w nn\tinput effect");
puts("\t-x nn\toutput effect");
puts("\t-v\tincrease verbosity");
exit(0);
}
@ -227,13 +247,15 @@ int opt;
int inFx = 0;
int outFx = 0;
int sort = 0;
char *filterchain = "0";
fprintf(stderr, "*** %s : compiled by tTh, %s %s\n", __FILE__,
__DATE__, __TIME__);
fimg_print_version(2);
while ((opt = getopt(argc, argv, "hS:vw:x:")) != -1) {
while ((opt = getopt(argc, argv, "F:hS:vw:x:")) != -1) {
switch(opt) {
case 'F': filterchain = optarg; break;
case 'h': help(); break;
case 'S': sort = atoi(optarg); break;
case 'v': verbosity++; break;
@ -251,6 +273,14 @@ if (3 != (argc-optind)) {
exit(1);
}
foo = parse_filter_chain(filterchain);
if (foo) {
fprintf(stderr, "err %d parsing '%s'\n", foo, filterchain);
exit(1);
}
// filterstack_list(__FILE__);
nbrsteps = atoi(argv[optind+2]);
foo = interpolator(argv[optind], argv[optind+1], nbrsteps,
inFx, outFx, sort);

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,69 +18,37 @@ 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
/* ----------------------------------------------------------- */
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 essai_filterstack(void)
{
int foo;
FloatImg image;
double debut, fin;
verbosity = 2;
fimg_print_version(1);
filterstack_list(__func__);
foo = fimg_create(&image, W, H, FIMG_TYPE_RGB);
foo = fimg_create_from_dump("mire.fimg", &image);
if (foo) {
fprintf(stderr, "err %d create image\n", foo);
exit(1);
}
fimg_vdeg_a(&image, 255);
srand(getpid()); srand48(getpid());
srand(getpid());
debut = fimg_timer_set(TIMER);
foo = essai_filterstack(&image);
foo = filterstack_run(&image, 0);
if (foo) {
fprintf(stderr, "essai filterstack --> %d\n", foo);
fprintf(stderr, "filterstack run --> %d\n", foo);
return foo;
}
fin = fimg_timer_set(TIMER);
foo = fimg_save_as_png(&image, "foo.png", 0);
@ -91,6 +60,50 @@ fprintf(stderr, "elapsed %f\n", fin-debut);
fimg_destroy(&image);
return 0;
}
/* ----------------------------------------------------------- */
int help(void)
{
puts("yolo!");
exit(0);
}
/* ----------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo;
int opt;
char *filterchain = "0";
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
foo = parse_filter_chain(filterchain);
if (foo) {
fprintf(stderr, "err %d in parse_filter_chain\n", foo);
exit(1);
}
foo = essai_filterstack();
if (foo) {
fprintf(stderr, "err %d in essai_filterstack\n", foo);
exit(1);
}
return 0;
}