FloatImg/Fonderie/t.c

137 lines
2.6 KiB
C
Raw Normal View History

2020-11-16 07:31:02 +11:00
/*
* test des trucs
*/
#include <stdio.h>
#include <stdlib.h>
2020-11-16 21:12:29 +11:00
#include <unistd.h>
2020-12-05 05:55:34 +11:00
#include <string.h>
2020-11-16 07:31:02 +11:00
#include "../floatimg.h"
#include "glitches.h"
2020-12-03 05:24:54 +11:00
#include "sfx.h"
2020-12-04 07:56:45 +11:00
#include "filterstack.h"
2020-11-16 07:31:02 +11:00
/* ----------------------------------------------------------- */
int verbosity;
2020-12-04 07:56:45 +11:00
int convert_to_gray; /* WTF ? */
2020-11-16 07:31:02 +11:00
#define PNG "out.png"
2020-12-05 05:55:34 +11:00
#define W 800
#define H 600
#define LMAX 255.0
2020-11-16 07:31:02 +11:00
#define TIMER 1
2020-12-04 07:56:45 +11:00
/* ----------------------------------------------------------- */
int essai_filterstack(FloatImg *pimg)
{
int foo;
2020-12-05 05:55:34 +11:00
filterstack_list(__func__);
foo = filterstack_run(pimg, 0);
2020-12-04 07:56:45 +11:00
if (foo) {
2020-12-05 05:55:34 +11:00
fprintf(stderr, "filterstack run --> %d\n", foo);
2020-12-04 07:56:45 +11:00
return foo;
}
2020-12-05 05:55:34 +11:00
return 0;
}
/* ----------------------------------------------------------- */
2020-12-05 09:14:44 +11:00
int parse_filter_chain(const char *argument)
2020-12-05 05:55:34 +11:00
{
char *cptr;
int value, foo;
2020-12-04 07:56:45 +11:00
2020-12-05 05:55:34 +11:00
fprintf(stderr, "\n%s: arg = '%s'\n", __func__, argument);
foo = filterstack_init(4);
2020-12-04 07:56:45 +11:00
if (foo) {
2020-12-05 05:55:34 +11:00
fprintf(stderr, "%s: filterstack init --> %d\n", __func__, foo);
2020-12-04 07:56:45 +11:00
return foo;
}
2020-12-05 05:55:34 +11:00
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);
}
}
}
2020-12-05 09:14:44 +11:00
if (verbosity) filterstack_list(__func__);
2020-12-04 07:56:45 +11:00
return 0;
}
/* ----------------------------------------------------------- */
2020-12-05 05:55:34 +11:00
int help(void)
{
puts("yolo!");
exit(0);
}
/* ----------------------------------------------------------- */
2020-12-04 07:56:45 +11:00
2020-11-16 07:31:02 +11:00
int main(int argc, char *argv[])
{
2020-12-04 07:56:45 +11:00
int foo;
2020-11-16 07:31:02 +11:00
FloatImg image;
double debut, fin;
2020-12-05 05:55:34 +11:00
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
2020-11-26 00:38:39 +11:00
2020-12-05 05:55:34 +11:00
parse_filter_chain(filterchain);
2020-11-16 07:31:02 +11:00
2020-12-05 09:14:44 +11:00
foo = fimg_create_from_dump("mire.fimg", &image);
2020-11-16 07:31:02 +11:00
if (foo) {
fprintf(stderr, "err %d create image\n", foo);
exit(1);
}
2020-11-16 21:12:29 +11:00
srand(getpid());
2020-11-16 07:31:02 +11:00
debut = fimg_timer_set(TIMER);
2020-12-04 07:56:45 +11:00
foo = essai_filterstack(&image);
if (foo) {
fprintf(stderr, "essai filterstack --> %d\n", foo);
}
fin = fimg_timer_set(TIMER);
2020-11-16 07:31:02 +11:00
2020-12-04 07:56:45 +11:00
foo = fimg_save_as_png(&image, "foo.png", 0);
if (foo) {
fprintf(stderr, "erreur export %d\n", foo);
2020-11-16 07:31:02 +11:00
}
fprintf(stderr, "elapsed %f\n", fin-debut);
2020-11-26 00:38:39 +11:00
fimg_destroy(&image);
2020-11-16 07:31:02 +11:00
return 0;
}
/* ----------------------------------------------------------- */