forked from tTh/FloatImg
130 lines
2.6 KiB
C
130 lines
2.6 KiB
C
/*
|
|
SINGLE
|
|
experimental and/or testing code, do not use in
|
|
production.
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <sys/stat.h>
|
|
|
|
#include "../floatimg.h"
|
|
|
|
#include "sfx.h"
|
|
#include "filterstack.h"
|
|
#include "crapulator.h"
|
|
#include "single.h"
|
|
|
|
/* -------------------------------------------------------------- */
|
|
/*
|
|
* singleton/private variables
|
|
*/
|
|
|
|
static int nextpng, counter;
|
|
static char *destination;
|
|
|
|
/* -------------------------------------------------------------- */
|
|
int single_init(int next, char *dest, char *sfxchain)
|
|
{
|
|
int foo;
|
|
struct stat stbuf;
|
|
|
|
fprintf(stderr, ">>> %s ( %d '%s' )\n", __func__, next, dest);
|
|
|
|
nextpng = next;
|
|
|
|
foo = stat(dest, &stbuf);
|
|
if (foo) {
|
|
perror("stat dest dir");
|
|
return -2;
|
|
}
|
|
// fprintf(stderr, "\t%s type = %04x\n", dest, stbuf.st_mode & S_IFMT);
|
|
if (S_IFDIR != (stbuf.st_mode & S_IFMT)) {
|
|
fprintf(stderr, "! %s must be a directory\n", dest);
|
|
return -3;
|
|
}
|
|
|
|
destination = dest;
|
|
|
|
return 0;
|
|
}
|
|
/* -------------------------------------------------------------- */
|
|
int single_push_picture(FloatImg *pimg)
|
|
{
|
|
int foo;
|
|
char line[1000], buff[100];
|
|
|
|
#if DEBUG_LEVEL
|
|
fprintf(stderr, ">>> %s ( %p )\n", __func__, pimg);
|
|
#endif
|
|
|
|
strncpy(line, destination, 100);
|
|
if ('/' != line[strlen(line)-1]) {
|
|
fprintf(stderr, "adding '/'\n");
|
|
strcat(line, "/");
|
|
}
|
|
|
|
// fprintf(stderr, " destdir = '%s'\n", line);
|
|
sprintf(buff, "%05d.png", nextpng);
|
|
strcat(line, buff);
|
|
|
|
// fprintf(stderr, "writing %p to '%s'\n", pimg, line);
|
|
foo = fimg_export_picture(pimg, line, 0);
|
|
if (foo) {
|
|
fprintf(stderr, "%s: err %d on export\n", __func__, foo);
|
|
return foo;
|
|
}
|
|
|
|
nextpng++;
|
|
|
|
return 0;
|
|
}
|
|
/* -------------------------------------------------------------- */
|
|
/*
|
|
* test-only function !
|
|
*/
|
|
int essayer_single(char *globpattern, char *destdir, int chain)
|
|
{
|
|
FloatImg image;
|
|
int idx, foo;
|
|
|
|
fprintf(stderr, ">>> %s ( '%s' '%s' %d )\n", __func__,
|
|
globpattern, destdir, chain);
|
|
|
|
foo = fimg_create(&image, 640, 480, 3);
|
|
if (foo) {
|
|
fprintf(stderr, "erreur %d creation image\n", foo);
|
|
return foo;
|
|
}
|
|
fimg_vdeg_a(&image, (double)3.141592654);
|
|
|
|
foo = single_init(0, destdir, "none");
|
|
if (foo) {
|
|
fprintf(stderr, "erreur %d single_init\n", foo);
|
|
return foo;
|
|
}
|
|
|
|
filterstack_list(chain, "essai du single");
|
|
|
|
for (idx=0; idx<666; idx++) {
|
|
|
|
foo = filterstack_run(chain, &image, 0);
|
|
if (foo) {
|
|
fprintf(stderr, "%s: filterstack run --> %d\n",
|
|
__func__, foo);
|
|
return foo;
|
|
}
|
|
|
|
foo = single_push_picture(&image);
|
|
if (foo) {
|
|
fprintf(stderr, "erreur %d push picture\n", foo);
|
|
return foo;
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
/* -------------------------------------------------------------- */
|