1 /*
2 FLAM3 - cosmic recursive fractal flames
3 Copyright (C) 1992-2009 Spotworks LLC
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "private.h"
20
21
22 #define MAXARGS 1000
23 #define streql(x,y) (!strcmp(x,y))
24
25
26 /*
27 * split a string passed in ss into tokens on whitespace.
28 * # comments to end of line. ; terminates the record
29 */
tokenize(ss,argv,argc)30 void tokenize(ss, argv, argc)
31 char **ss;
32 char *argv[];
33 int *argc;
34 {
35 char *s = *ss;
36 int i = 0, state = 0;
37
38 while (*s != ';') {
39 char c = *s;
40 switch (state) {
41 case 0:
42 if ('#' == c)
43 state = 2;
44 else if (!isspace(c)) {
45 argv[i] = s;
46 i++;
47 state = 1;
48 }
49 case 1:
50 if (isspace(c)) {
51 *s = 0;
52 state = 0;
53 }
54 case 2:
55 if ('\n' == c)
56 state = 0;
57 }
58 s++;
59 }
60 *s = 0;
61 *ss = s+1;
62 *argc = i;
63 }
64
65 /*
66 * given a pointer to a string SS, fill fields of a control point CP.
67 * return a pointer to the first unused char in SS. totally barfucious,
68 * must integrate with tcl soon...
69 */
70
parse_control_point_old(char ** ss,flam3_genome * cp)71 void parse_control_point_old(char **ss, flam3_genome *cp) {
72 char *argv[MAXARGS];
73 int argc, i, j;
74 int set_cm = 0, set_image_size = 0, set_nbatches = 0, set_white_level = 0;
75 int set_spatial_oversample = 0, set_hr = 0;
76 double *slot = NULL, xf, cm, t, nbatches, white_level, spatial_oversample, cmap_inter;
77 double image_size[2];
78
79 memset(cp, 0, sizeof(flam3_genome));
80
81 flam3_add_xforms(cp, flam3_nxforms, 0, 0);
82
83 for (i = 0; i < flam3_nxforms; i++) {
84 cp->xform[i].density = 0.0;
85 cp->xform[i].color = i&1;
86 cp->xform[i].color_speed = 0.5;
87 cp->xform[i].animate = 1.0;
88 cp->xform[i].var[0] = 1.0;
89 for (j = 1; j < flam3_nvariations; j++)
90 cp->xform[i].var[j] = 0.0;
91 cp->xform[i].c[0][0] = 1.0;
92 cp->xform[i].c[0][1] = 0.0;
93 cp->xform[i].c[1][0] = 0.0;
94 cp->xform[i].c[1][1] = 1.0;
95 cp->xform[i].c[2][0] = 0.0;
96 cp->xform[i].c[2][1] = 0.0;
97 }
98
99 tokenize(ss, argv, &argc);
100 for (i = 0; i < argc; i++) {
101 if (streql("xform", argv[i]))
102 slot = &xf;
103 else if (streql("time", argv[i]))
104 slot = &cp->time;
105 else if (streql("brightness", argv[i]))
106 slot = &cp->brightness;
107 else if (streql("contrast", argv[i]))
108 slot = &cp->contrast;
109 else if (streql("gamma", argv[i]))
110 slot = &cp->gamma;
111 else if (streql("vibrancy", argv[i]))
112 slot = &cp->vibrancy;
113 else if (streql("hue_rotation", argv[i])) {
114 slot = &cp->hue_rotation;
115 set_hr = 1;
116 } else if (streql("zoom", argv[i]))
117 slot = &cp->zoom;
118 else if (streql("image_size", argv[i])) {
119 slot = image_size;
120 set_image_size = 1;
121 } else if (streql("center", argv[i]))
122 slot = cp->center;
123 else if (streql("background", argv[i]))
124 slot = cp->background;
125 else if (streql("pixels_per_unit", argv[i]))
126 slot = &cp->pixels_per_unit;
127 else if (streql("spatial_filter_radius", argv[i]))
128 slot = &cp->spatial_filter_radius;
129 else if (streql("sample_density", argv[i]))
130 slot = &cp->sample_density;
131 else if (streql("nbatches", argv[i])) {
132 slot = &nbatches;
133 set_nbatches = 1;
134 } else if (streql("white_level", argv[i])) {
135 slot = &white_level;
136 set_white_level = 1;
137 } else if (streql("spatial_oversample", argv[i])) {
138 slot = &spatial_oversample;
139 set_spatial_oversample = 1;
140 } else if (streql("cmap", argv[i])) {
141 slot = &cm;
142 set_cm = 1;
143 } else if (streql("palette", argv[i])) {
144 slot = &cp->palette[0].color[0];
145 } else if (streql("density", argv[i]))
146 slot = &cp->xform[(int)xf].density;
147 else if (streql("color", argv[i]))
148 slot = &cp->xform[(int)xf].color;
149 else if (streql("coefs", argv[i])) {
150 slot = cp->xform[(int)xf].c[0];
151 cp->xform[(int)xf].density = 1.0;
152 } else if (streql("var", argv[i]))
153 slot = cp->xform[(int)xf].var;
154 else if (streql("cmap_inter", argv[i])) {
155 slot = &cmap_inter;
156 } else
157 *slot++ = atof(argv[i]);
158 }
159 if (set_cm) {
160 double hr = set_hr ? cp->hue_rotation : 0.0;
161 cp->palette_index = (int) cm;
162 flam3_get_palette(cp->palette_index, cp->palette, hr);
163 }
164 if (set_image_size) {
165 cp->width = (int) image_size[0];
166 cp->height = (int) image_size[1];
167 }
168 if (set_nbatches)
169 cp->nbatches = (int) nbatches;
170 if (set_spatial_oversample)
171 cp->spatial_oversample = (int) spatial_oversample;
172 if (set_white_level) {
173 /* ignore */
174 }
175 for (i = 0; i < flam3_nxforms; i++) {
176 t = 0.0;
177 for (j = 0; j < flam3_nvariations; j++)
178 t += cp->xform[i].var[j];
179 t = 1.0 / t;
180 for (j = 0; j < flam3_nvariations; j++)
181 cp->xform[i].var[j] *= t;
182 }
183 }
184
185 int
main(int argc,char ** argv)186 main(int argc, char **argv)
187 {
188 char *s, *ss;
189
190 #ifdef WIN32
191
192 char *slashloc;
193 char palpath[256],exepath[256];
194
195 slashloc = strrchr(argv[0],'\\');
196 if (NULL==slashloc) {
197 sprintf(palpath,"flam3_palettes=flam3-palettes.xml");
198 } else {
199 strncpy(exepath,argv[0],slashloc-argv[0]+1);
200 sprintf(palpath,"flam3_palettes=%sflam3-palettes.xml",exepath);
201 }
202 putenv(palpath);
203
204 #endif
205
206 if (1 != argc) {
207 docstring();
208 exit(0);
209 }
210
211 {
212 int i, c, slen = 5000;
213 s = malloc(slen);
214 i = 0;
215 do {
216 c = getchar();
217 if (EOF == c) goto done_reading;
218 s[i++] = c;
219 if (i == slen-1) {
220 slen *= 2;
221 s = realloc(s, slen);
222 }
223 } while (1);
224 done_reading:
225 s[i] = 0;
226 }
227
228 ss = s;
229 s += strlen(s);
230 printf("<conversions>\n");
231 while (strchr(ss, ';')) {
232 flam3_genome cp;
233 parse_control_point_old(&ss, &cp);
234 flam3_print(stdout, &cp, NULL, flam3_print_edits);
235 }
236 printf("</conversions>\n");
237 return 0;
238 }
239