FloatImg/extras/Fonderie/single.c

111 lines
2.3 KiB
C
Raw Normal View History

2021-01-09 08:57:45 +11:00
/*
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;
2021-01-12 08:22:03 +11:00
static int chainfilter;
2021-04-24 09:11:37 +11:00
static int outtype;
2021-01-09 08:57:45 +11:00
2021-04-18 20:55:59 +11:00
/* and the classic global var */
extern int verbosity;
2021-01-09 08:57:45 +11:00
/* -------------------------------------------------------------- */
2021-04-18 20:55:59 +11:00
int single_init(int next, char *dest, int fxchain, int outfmt)
2021-01-09 08:57:45 +11:00
{
int foo;
struct stat stbuf;
2021-01-14 02:09:27 +11:00
#if DEBUG_LEVEL
2021-04-18 20:55:59 +11:00
fprintf(stderr, ">>> %s ( %d '%s' %d %d )\n", __func__,
next, dest, fxchain, outfmt);
2021-01-14 02:09:27 +11:00
#endif
2021-01-09 08:57:45 +11:00
nextpng = next;
2021-01-12 08:22:03 +11:00
chainfilter = fxchain;
2021-01-09 08:57:45 +11:00
foo = stat(dest, &stbuf);
if (foo) {
perror("stat dest dir");
return -2;
}
if (S_IFDIR != (stbuf.st_mode & S_IFMT)) {
fprintf(stderr, "! %s must be a directory\n", dest);
return -3;
}
2021-01-12 08:22:03 +11:00
destination = strdup(dest); /* have a static copy */
2021-01-09 08:57:45 +11:00
return 0;
}
/* -------------------------------------------------------------- */
int single_push_picture(FloatImg *pimg)
{
int foo;
char line[1000], buff[100];
2021-05-10 09:03:28 +11:00
char *extension = "png";
2021-01-09 08:57:45 +11:00
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p )\n", __func__, pimg);
#endif
strncpy(line, destination, 100);
if ('/' != line[strlen(line)-1]) {
2021-01-15 00:15:42 +11:00
// fprintf(stderr, "adding '/'\n");
2021-01-09 08:57:45 +11:00
strcat(line, "/");
}
2021-04-24 09:11:37 +11:00
sprintf(buff, "%05d.%s", nextpng, extension);
2021-01-09 08:57:45 +11:00
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;
}
2021-01-12 08:22:03 +11:00
nextpng++; counter++;
2021-01-09 08:57:45 +11:00
return 0;
}
/* -------------------------------------------------------------- */
2021-01-11 08:52:33 +11:00
int single_print_state(char *title, int k)
2021-01-09 08:57:45 +11:00
{
2021-01-11 08:52:33 +11:00
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, title, k);
#endif
2021-01-09 08:57:45 +11:00
2021-01-12 08:22:03 +11:00
fprintf(stderr, "%s : %s\n", __FILE__, title);
fprintf(stderr, " nextpng %d\n", nextpng);
fprintf(stderr, " counter %d\n", counter);
fprintf(stderr, " chainfilter %d\n", chainfilter);
fprintf(stderr, " destination %s\n", destination);
2021-01-09 08:57:45 +11:00
2021-01-14 02:09:27 +11:00
if (k) {
2021-03-21 19:02:55 +11:00
/* XXX */
2021-01-14 02:09:27 +11:00
}
2021-01-09 08:57:45 +11:00
return -1;
}
/* -------------------------------------------------------------- */