FloatImg4PythonBinding/Fonderie/t.c
2020-12-04 23:14:44 +01:00

137 lines
2.6 KiB
C

/*
* test des trucs
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#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 800
#define H 600
#define LMAX 255.0
#define TIMER 1
/* ----------------------------------------------------------- */
int essai_filterstack(FloatImg *pimg)
{
int foo;
filterstack_list(__func__);
foo = filterstack_run(pimg, 0);
if (foo) {
fprintf(stderr, "filterstack run --> %d\n", foo);
return foo;
}
return 0;
}
/* ----------------------------------------------------------- */
int parse_filter_chain(const 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);
}
}
}
if (verbosity) 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";
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_from_dump("mire.fimg", &image);
if (foo) {
fprintf(stderr, "err %d create image\n", foo);
exit(1);
}
srand(getpid());
debut = fimg_timer_set(TIMER);
foo = essai_filterstack(&image);
if (foo) {
fprintf(stderr, "essai filterstack --> %d\n", foo);
}
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);
return 0;
}
/* ----------------------------------------------------------- */