-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefract.c
44 lines (40 loc) · 1.17 KB
/
makefract.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <limits.h>
#include <string.h>
#include "makefract.h"
int writefractal(const fe_opts_t *opts, const char *coeffstr, int maxval) {
fractalparams_t fractal;
char ofname[PATH_MAX+5];
void *pngwriter;
int cfret;
if (opts2fract(&fractal, opts) != 0) {
fprintf(stderr, "Couldn't init fractal from options\n");
return 1;
}
if (coeffstr != NULL)
if (initcoeffs_fromstring(&fractal, coeffstr) != 0) {
fprintf(stderr, "Couldn't init fractal from coeffstr\n");
return 1;
}
// special case - stdout
if (strcmp(opts->output, "-") == 0)
sprintf(ofname, "-");
else if (opts->random >= 0 && opts->output[0] != 0)
sprintf(ofname, "%s/%s.png", opts->output, coeffstr);
else if (opts->random < 0 && opts->output[0] != 0)
strcpy(ofname, opts->output);
else {
char ocstr[13];
coeffstring(&fractal, ocstr);
ocstr[12] = 0;
sprintf(ofname, "%s.png", ocstr);
}
if (maxval == 0) maxval = opts->maxval;
if ((pngwriter = init_pngwriter(&fractal, ofname, maxval)) == NULL) {
fprintf(stderr, "pngwriter init failed\n");
return 1;
}
cfret = computefractal(&fractal, pngwriter_pixelcb, pngwriter);
finish_pngwriter(pngwriter);
return cfret;
}