Debian Codegraph @

palettes.c

raw symbols SCIP
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"cxx . . $ `<file>/private.h`/
20 #include "palettes.h"cxx . . $ `<file>/palettes.h`/
21
22 lib_palettecxx . . $ lib_palette# *the_palettescxx . . $ the_palettes. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
23 int npalettescxx . . $ npalettes.;
24
25 static void parse_palettescxx . . $ parse_palettes(5712c9d4a25253).(xmlNodecxx . . $ xmlNode# *node) {
26 xmlAttrPtrcxx . . $ xmlAttrPtr# attr;
27 char *val;
28 lib_palettecxx . . $ lib_palette# *pal;
29 int hex_error = 0;
30
31 while (node) {
32 if (node->typecxx . . $ _xmlNode#type. == XML_ELEMENT_NODEcxx . . $ XML_ELEMENT_NODE. && !xmlStrcmpcxx . . $ xmlStrcmp(e46526da1a64e2fc).(node->namecxx . . $ _xmlNode#name., (const xmlCharcxx . . $ xmlChar# *)"palette")) {
33 attr = node->propertiescxx . . $ _xmlNode#properties.;
34 pal = &the_palettescxx . . $ the_palettes.[npalettescxx . . $ npalettes.];
35 memsetcxx . . $ memset(d1de1e4fb215f1c6).(pal, 0, sizeof(lib_palettecxx . . $ lib_palette#));
36
37 while (attr) {
38 val = (char *) xmlGetPropcxx . . $ xmlGetProp(9828664f081b7881).(node, attr->namecxx . . $ _xmlAttr#name.);
39 if (!xmlStrcmpcxx . . $ xmlStrcmp(e46526da1a64e2fc).(attr->namecxx . . $ _xmlAttr#name., (const xmlCharcxx . . $ xmlChar# *)"data")) {
40 int count = 256;
41 int c_idx = 0;
42 int r,g,b;
43 int col_count = 0;
44 int sscanf_ret;
45
46 c_idx=0;
47 col_count = 0;
48 hex_error = 0;
49
50 do {
51 sscanf_ret = sscanfcxx . . $ sscanf(5e8a2c12db2ea735).((char *)&(val[c_idx]),"00%2x%2x%2x",&r,&g,&b);
52 if (sscanf_ret != 3) {
53 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"error: problem reading hexadecimal color data '%8s'\n",&val[c_idx]);
54 hex_error = 1;
55 break;
56 }
57 c_idx += 8;
58 while (isspacecxx . . $ `<external>/17904084882347303253/ctype.h:197:10`!( (int)val[c_idx]))
59 c_idx++;
60
61 pal->colorscxx . . $ $anonymous_type_3637ff619aa80f6f_0#colors.[col_count][0] = r;
62 pal->colorscxx . . $ $anonymous_type_3637ff619aa80f6f_0#colors.[col_count][1] = g;
63 pal->colorscxx . . $ $anonymous_type_3637ff619aa80f6f_0#colors.[col_count][2] = b;
64
65 col_count++;
66 } while (col_count<count);
67 } else if (!xmlStrcmpcxx . . $ xmlStrcmp(e46526da1a64e2fc).(attr->namecxx . . $ _xmlAttr#name., (const xmlCharcxx . . $ xmlChar# *)"number")) {
68 pal->numbercxx . . $ $anonymous_type_3637ff619aa80f6f_0#number. = atoicxx . . $ atoi(5c4306d8553b3696).(val);
69 } else if (!xmlStrcmpcxx . . $ xmlStrcmp(e46526da1a64e2fc).(attr->namecxx . . $ _xmlAttr#name., (const xmlCharcxx . . $ xmlChar# *)"name")) {
70 strncpycxx . . $ strncpy(255158a415b673b0).(pal->namecxx . . $ $anonymous_type_3637ff619aa80f6f_0#name., val, flam3_name_lencxx . . $ `flam3.h:51:9`!);
71 pal->namecxx . . $ $anonymous_type_3637ff619aa80f6f_0#name.[flam3_name_lencxx . . $ `flam3.h:51:9`!-1] = 0;
72 }
73
74 xmlFreecxx . . $ xmlFree.(val);
75 attr = attr->nextcxx . . $ _xmlAttr#next.;
76 }
77
78 if (hex_error == 0) {
79 npalettescxx . . $ npalettes.++;
80 the_palettescxx . . $ the_palettes. = realloccxx . . $ realloc(417ab160f6baadc6).(the_palettescxx . . $ the_palettes., (1 + npalettescxx . . $ npalettes.) * sizeof(lib_palettecxx . . $ lib_palette#));
81 }
82 } else
83 parse_palettescxx . . $ parse_palettes(5712c9d4a25253).(node->childrencxx . . $ _xmlNode#children.);
84
85 node = node->nextcxx . . $ _xmlNode#next.;
86 }
87 }
88
89 static int init_palettescxx . . $ init_palettes(1ef8e6ec083aabb9).(char *filename) {
90 FILEcxx . . $ FILE# *fp;
91 xmlDocPtrcxx . . $ xmlDocPtr# doc;
92 xmlNodecxx . . $ xmlNode# *rootnode;
93 int i, c, slen = 5000;
94 char *s;
95
96 fp = fopencxx . . $ fopen(82ec0787cd37e0a3).(filename, "rb");
97 if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! == fp) {
98 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "flam3: could not open palette file ");
99 perrorcxx . . $ perror(85c52e162fed56f9).(filename);
100 return(-1);
101 }
102
103 /* Incrementally read XML file into a string */
104 s = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(slen);
105 i = 0;
106 do {
107 c = getccxx . . $ getc(89bc1efcdac0ca22).(fp);
108 if (EOFcxx . . $ `<external>/232824719582829767/stdio.h:105:9`! == c) {
109 if (ferrorcxx . . $ ferror(89bc1efcdac0ca22).(fp)) {
110 perrorcxx . . $ perror(85c52e162fed56f9).(filename);
111 return(-1);
112 }
113 break;
114 }
115 s[i++] = c;
116 if (i == slen-1) {
117 slen *= 2;
118 s = realloccxx . . $ realloc(417ab160f6baadc6).(s, slen);
119 }
120 } while (1);
121
122 fclosecxx . . $ fclose(89bc1efcdac0ca22).(fp);
123 s[i] = 0;
124
125 doc = xmlReadMemorycxx . . $ xmlReadMemory(be05adc870cf55a3).(s, (int)strlencxx . . $ strlen(751346f8406fd082).(s), filename, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, XML_PARSE_NONETcxx . . $ XML_PARSE_NONET.);
126 if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! == doc) {
127 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "error parsing %s (%s).\n", filename, s);
128 return(-1);
129 }
130 rootnode = xmlDocGetRootElementcxx . . $ xmlDocGetRootElement(53aa9a676bd496f2).(doc);
131 the_palettescxx . . $ the_palettes. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(lib_palettecxx . . $ lib_palette#));
132 npalettescxx . . $ npalettes. = 0;
133 parse_palettescxx . . $ parse_palettes(5712c9d4a25253).(rootnode);
134 xmlFreeDoccxx . . $ xmlFreeDoc(42de24d0ab3f771).(doc);
135
136 freecxx . . $ free(5d22bdacc48458e8).(s);
137 xmlCleanupParsercxx . . $ xmlCleanupParser(49f6e7a06ebc5aa8).();
138 return(1);
139 }
140
141 int flam3_get_palettecxx . . $ flam3_get_palette(4c7a1137c04ffabc).(int n, flam3_palettecxx . . $ flam3_palette# c, double hue_rotation) {
142 int cmap_len = 256;
143 int idx, i, j, rcode;
144
145 // set palette to all white in case there are problems
146 for (i = 0; i < cmap_len; i++) {
147 c[i].indexcxx . . $ $anonymous_type_d4ed57c78da46593_0#index. = i;
148 for (j = 0; j < 4; j++)
149 c[i].colorcxx . . $ $anonymous_type_d4ed57c78da46593_0#color.[j] = 1.0;
150 }
151
152 if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! == the_palettescxx . . $ the_palettes.) {
153 char *d = getenvcxx . . $ getenv(a8b8e32347182212).("flam3_palettes");
154 rcode = init_palettescxx . . $ init_palettes(1ef8e6ec083aabb9).(d ? d : (PACKAGE_DATA_DIRcxx . . $ `<built-in>:415:9`! "/flam3-palettes.xml"));
155 if (rcode<0) {
156 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"error reading xml palette file, setting to all white\n");
157 return(-1);
158 }
159 }
160
161 if (flam3_palette_randomcxx . . $ `flam3.h:45:9`! == n)
162 n = the_palettescxx . . $ the_palettes.[randomcxx . . $ random(da6335ded91d79c2).()%npalettescxx . . $ npalettes.].numbercxx . . $ $anonymous_type_3637ff619aa80f6f_0#number.;
163
164 for (idx = 0; idx < npalettescxx . . $ npalettes.; idx++) {
165
166 if (n == the_palettescxx . . $ the_palettes.[idx].numbercxx . . $ $anonymous_type_3637ff619aa80f6f_0#number.) {
167 /* Loop over elements of cmap */
168 for (i = 0; i < cmap_len; i++) {
169 int ii = (i * 256) / cmap_len;
170 double rgb[3], hsv[3];
171
172 /* Colors are in 0-1 space */
173 for (j = 0; j < 3; j++)
174 rgb[j] = the_palettescxx . . $ the_palettes.[idx].colorscxx . . $ $anonymous_type_3637ff619aa80f6f_0#colors.[ii][j] / 255.0;
175
176 rgb2hsvcxx . . $ rgb2hsv(a695690fb8d46395).(rgb, hsv);
177 hsv[0] += hue_rotation * 6.0;
178 hsv2rgbcxx . . $ hsv2rgb(a695690fb8d46395).(hsv, rgb);
179
180 c[i].indexcxx . . $ $anonymous_type_d4ed57c78da46593_0#index. = i;
181
182 for (j = 0; j < 3; j++)
183 c[i].colorcxx . . $ $anonymous_type_d4ed57c78da46593_0#color.[j] = rgb[j];
184
185 c[i].colorcxx . . $ $anonymous_type_d4ed57c78da46593_0#color.[3] = 1.0;
186 }
187
188 return n;
189 }
190 }
191
192 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "warning: palette number %d not found, using white.\n", n);
193
194 return(-1);
195 }
196
197 /* rgb 0 - 1,
198 h 0 - 6, s 0 - 1, v 0 - 1 */
199 void rgb2hsvcxx . . $ rgb2hsv(a695690fb8d46395).(rgb, hsv)
200 double *rgb; double *hsv;
201 {
202 double rd, gd, bd, h, s, v, max, min, del, rc, gc, bc;
203
204 rd = rgb[0];
205 gd = rgb[1];
206 bd = rgb[2];
207
208 /* compute maximum of rd,gd,bd */
209 if (rd>=gd) { if (rd>=bd) max = rd; else max = bd; }
210 else { if (gd>=bd) max = gd; else max = bd; }
211
212 /* compute minimum of rd,gd,bd */
213 if (rd<=gd) { if (rd<=bd) min = rd; else min = bd; }
214 else { if (gd<=bd) min = gd; else min = bd; }
215
216 del = max - min;
217 v = max;
218 if (max != 0.0) s = (del) / max;
219 else s = 0.0;
220
221 h = 0;
222 if (s != 0.0) {
223 rc = (max - rd) / del;
224 gc = (max - gd) / del;
225 bc = (max - bd) / del;
226
227 if (rd==max) h = bc - gc;
228 else if (gd==max) h = 2 + rc - bc;
229 else if (bd==max) h = 4 + gc - rc;
230
231 if (h<0) h += 6;
232 }
233
234 hsv[0] = h;
235 hsv[1] = s;
236 hsv[2] = v;
237 }
238
239
240 /* h 0 - 6, s 0 - 1, v 0 - 1
241 rgb 0 - 1 */
242 void hsv2rgbcxx . . $ hsv2rgb(a695690fb8d46395).(hsv, rgb)
243 double *hsv;
244 double *rgb;
245 {
246 double h = hsv[0], s = hsv[1], v = hsv[2];
247 int j;
248 double rd, gd, bd;
249 double f, p, q, t;
250
251 while (h >= 6.0) h = h - 6.0;
252 while (h < 0.0) h = h + 6.0;
253 j = (int) floorcxx . . $ floor(447c67c6676f75c3).(h);
254 f = h - j;
255 p = v * (1-s);
256 q = v * (1 - (s*f));
257 t = v * (1 - (s*(1 - f)));
258
259 switch (j) {
260 case 0: rd = v; gd = t; bd = p; break;
261 case 1: rd = q; gd = v; bd = p; break;
262 case 2: rd = p; gd = v; bd = t; break;
263 case 3: rd = p; gd = q; bd = v; break;
264 case 4: rd = t; gd = p; bd = v; break;
265 case 5: rd = v; gd = p; bd = q; break;
266 default: rd = v; gd = t; bd = p; break;
267 }
268
269 rgb[0] = rd;
270 rgb[1] = gd;
271 rgb[2] = bd;
272 }
273
274 double flam3_calc_alphacxx . . $ flam3_calc_alpha(7678bba071383ab).(double density, double gamma, double linrange) {
275
276 double dnorm = density;
277 double funcval = powcxx . . $ pow(d8e7e0733fa41c87).(linrange, gamma);
278 double frac,alpha;
279
280 if (dnorm>0) {
281 if (dnorm < linrange) {
282 frac = dnorm/linrange;
283 alpha = (1.0-frac) * dnorm * (funcval / linrange) + frac * powcxx . . $ pow(d8e7e0733fa41c87).(dnorm,gamma);
284 } else
285 alpha = powcxx . . $ pow(d8e7e0733fa41c87).(dnorm,gamma);
286 } else
287 alpha = 0;
288
289 return(alpha);
290 }
291
292 void flam3_calc_newrgbcxx . . $ flam3_calc_newrgb(e3877e96178a2076).(double *cbuf, double ls, double highpow, double *newrgb) {
293
294 int rgbi;
295 double newls,lsratio;
296 double newhsv[3];
297 double a, maxa=-1.0, maxc=0;
298 double adjhlp;
299
300 if (ls==0.0 || (cbuf[0]==0.0 && cbuf[1]==0.0 && cbuf[2]==0.0)) {
301 newrgb[0] = 0.0;
302 newrgb[1] = 0.0;
303 newrgb[2] = 0.0;
304 return;
305 }
306
307 /* Identify the most saturated channel */
308 for (rgbi=0;rgbi<3;rgbi++) {
309 a = ls * (cbuf[rgbi]/PREFILTER_WHITEcxx . . $ `private.h:46:9`!);
310 if (a>maxa) {
311 maxa = a;
312 maxc = cbuf[rgbi]/PREFILTER_WHITEcxx . . $ `private.h:46:9`!;
313 }
314 }
315
316 /* If a channel is saturated and we have a non-negative highlight power */
317 /* modify the color to prevent hue shift */
318 if (maxa>255 && highpow>=0.0) {
319 newls = 255.0/maxc;
320 lsratio = powcxx . . $ pow(d8e7e0733fa41c87).(newls/ls,highpow);
321
322 /* Calculate the max-value color (ranged 0 - 1) */
323 for (rgbi=0;rgbi<3;rgbi++)
324 newrgb[rgbi] = newls*(cbuf[rgbi]/PREFILTER_WHITEcxx . . $ `private.h:46:9`!)/255.0;
325
326 /* Reduce saturation by the lsratio */
327 rgb2hsvcxx . . $ rgb2hsv(a695690fb8d46395).(newrgb,newhsv);
328 newhsv[1] *= lsratio;
329 hsv2rgbcxx . . $ hsv2rgb(a695690fb8d46395).(newhsv,newrgb);
330
331 for (rgbi=0;rgbi<3;rgbi++)
332 newrgb[rgbi] *= 255.0;
333
334 } else {
335 newls = 255.0/maxc;
336 adjhlp = -highpow;
337 if (adjhlp>1)
338 adjhlp=1;
339 if (maxa<=255)
340 adjhlp=1.0;
341
342 /* Calculate the max-value color (ranged 0 - 1) interpolated with the old behaviour */
343 for (rgbi=0;rgbi<3;rgbi++)
344 newrgb[rgbi] = ((1.0-adjhlp)*newls + adjhlp*ls)*(cbuf[rgbi]/PREFILTER_WHITEcxx . . $ `private.h:46:9`!);
345
346 // for (rgbi=0;rgbi<3;rgbi++)
347 // newrgb[rgbi] = ls*(cbuf[rgbi]/PREFILTER_WHITE);
348 }
349 }
350
351 static int random_xformcxx . . $ random_xform(164bf4c8a0c701ab).(flam3_genomecxx . . $ flam3_genome# *g, int excluded) {
352 int ntries = 0;
353 while (ntries++ < 100) {
354 int i = randomcxx . . $ random(da6335ded91d79c2).() % g->num_xformscxx . . $ $anonymous_type_d4ed57c78da46593_3#num_xforms.;
355 if (g->xformcxx . . $ $anonymous_type_d4ed57c78da46593_3#xform.[i].densitycxx . . $ xform#density. > 0.0 && i != excluded)
356 return i;
357 }
358 return -1;
359 }
360
361
362 static double try_colorscxx . . $ try_colors(11c663caa9b1156b).(flam3_genomecxx . . $ flam3_genome# *g, int color_resolution) {
363 int *hist;
364 int i, hits, res = color_resolution;
365 int res3 = res * res * res;
366 flam3_framecxx . . $ flam3_frame# f;
367 unsigned char *image, *p;
368 flam3_genomecxx . . $ flam3_genome# saved;
369 double scalar;
370 int pixtotal;
371 stat_structcxx . . $ stat_struct# stats;
372
373 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&saved, 0, sizeof(flam3_genomecxx . . $ flam3_genome#));
374
375 flam3_copycxx . . $ flam3_copy(30da8946c6598614).(&saved, g);
376
377 g->sample_densitycxx . . $ $anonymous_type_d4ed57c78da46593_3#sample_density. = 1;
378 g->spatial_oversamplecxx . . $ $anonymous_type_d4ed57c78da46593_3#spatial_oversample. = 1;
379 g->estimatorcxx . . $ $anonymous_type_d4ed57c78da46593_3#estimator. = 0.0;
380
381 /* Scale the image so that the total number of pixels is ~10000 */
382 pixtotal = g->widthcxx . . $ $anonymous_type_d4ed57c78da46593_3#width. * g->heightcxx . . $ $anonymous_type_d4ed57c78da46593_3#height.;
383 scalar = sqrtcxx . . $ sqrt(447c67c6676f75c3).( 10000.0 / (double)pixtotal);
384 g->widthcxx . . $ $anonymous_type_d4ed57c78da46593_3#width. *= scalar;
385 g->heightcxx . . $ $anonymous_type_d4ed57c78da46593_3#height. *= scalar;
386 g->pixels_per_unitcxx . . $ $anonymous_type_d4ed57c78da46593_3#pixels_per_unit. *= scalar;
387
388 // g->width = 100; // XXX keep aspect ratio
389 // g->height = 100;
390 // g->pixels_per_unit = 50;
391 g->nbatchescxx . . $ $anonymous_type_d4ed57c78da46593_3#nbatches. = 1;
392 g->ntemporal_samplescxx . . $ $anonymous_type_d4ed57c78da46593_3#ntemporal_samples. = 1;
393
394 // f.temporal_filter_radius = 0.0;
395 flam3_init_framecxx . . $ flam3_init_frame(4142e08dcdbbecd8).(&f);
396 f.bitscxx . . $ $anonymous_type_d4ed57c78da46593_5#bits. = 33;
397 f.bytes_per_channelcxx . . $ $anonymous_type_d4ed57c78da46593_5#bytes_per_channel.=1;
398 f.verbosecxx . . $ $anonymous_type_d4ed57c78da46593_5#verbose. = 0;
399 f.genomescxx . . $ $anonymous_type_d4ed57c78da46593_5#genomes. = g;
400 f.ngenomescxx . . $ $anonymous_type_d4ed57c78da46593_5#ngenomes. = 1;
401 f.earlyclipcxx . . $ $anonymous_type_d4ed57c78da46593_5#earlyclip. = 1;
402 f.pixel_aspect_ratiocxx . . $ $anonymous_type_d4ed57c78da46593_5#pixel_aspect_ratio. = 1.0;
403 f.progresscxx . . $ $anonymous_type_d4ed57c78da46593_5#progress. = 0;
404 f.nthreadscxx . . $ $anonymous_type_d4ed57c78da46593_5#nthreads. = 1;
405 f.sub_batch_sizecxx . . $ $anonymous_type_d4ed57c78da46593_5#sub_batch_size. = 10000;
406
407 image = (unsigned char *) calloccxx . . $ calloc(63a7bf2941bfcd7a).(g->widthcxx . . $ $anonymous_type_d4ed57c78da46593_3#width. * g->heightcxx . . $ $anonymous_type_d4ed57c78da46593_3#height., 3);
408 if (flam3_rendercxx . . $ flam3_render(65dcdf3bdd0e255d).(&f, image, flam3_field_bothcxx . . $ `flam3.h:626:9`!, 3, 0, &stats)) {
409 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Error rendering test image for trycolors. Aborting.\n");
410 return(-1);
411 }
412
413 hist = calloccxx . . $ calloc(63a7bf2941bfcd7a).(sizeof(int), res3);
414 p = image;
415 for (i = 0; i < g->heightcxx . . $ $anonymous_type_d4ed57c78da46593_3#height. * g->widthcxx . . $ $anonymous_type_d4ed57c78da46593_3#width.; i++) {
416 hist[(p[0] * res / 256) +
417 (p[1] * res / 256) * res +
418 (p[2] * res / 256) * res * res]++;
419 p += 3;
420 }
421
422 if (0) {
423 int j, k;
424 for (i = 0; i < res; i++) {
425 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\ni=%d: \n", i);
426 for (j = 0; j < res; j++) {
427 for (k = 0; k < res; k++) {
428 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " %5d", hist[i * res * res + j * res + k]);
429 }
430 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\n");
431 }
432 }
433 }
434
435 hits = 0;
436 for (i = 0; i < res3; i++) {
437 if (hist[i]) hits++;
438 }
439
440 freecxx . . $ free(5d22bdacc48458e8).(hist);
441 freecxx . . $ free(5d22bdacc48458e8).(image);
442
443 g->sample_densitycxx . . $ $anonymous_type_d4ed57c78da46593_3#sample_density. = saved.sample_densitycxx . . $ $anonymous_type_d4ed57c78da46593_3#sample_density.;
444 g->widthcxx . . $ $anonymous_type_d4ed57c78da46593_3#width. = saved.widthcxx . . $ $anonymous_type_d4ed57c78da46593_3#width.;
445 g->heightcxx . . $ $anonymous_type_d4ed57c78da46593_3#height. = saved.heightcxx . . $ $anonymous_type_d4ed57c78da46593_3#height.;
446 g->spatial_oversamplecxx . . $ $anonymous_type_d4ed57c78da46593_3#spatial_oversample. = saved.spatial_oversamplecxx . . $ $anonymous_type_d4ed57c78da46593_3#spatial_oversample.;
447 g->pixels_per_unitcxx . . $ $anonymous_type_d4ed57c78da46593_3#pixels_per_unit. = saved.pixels_per_unitcxx . . $ $anonymous_type_d4ed57c78da46593_3#pixels_per_unit.;
448 g->nbatchescxx . . $ $anonymous_type_d4ed57c78da46593_3#nbatches. = saved.nbatchescxx . . $ $anonymous_type_d4ed57c78da46593_3#nbatches.;
449 g->ntemporal_samplescxx . . $ $anonymous_type_d4ed57c78da46593_3#ntemporal_samples. = saved.ntemporal_samplescxx . . $ $anonymous_type_d4ed57c78da46593_3#ntemporal_samples.;
450 g->estimatorcxx . . $ $anonymous_type_d4ed57c78da46593_3#estimator. = saved.estimatorcxx . . $ $anonymous_type_d4ed57c78da46593_3#estimator.;
451
452 /* Free xform storage */
453 clear_cpcxx . . $ clear_cp(843ee1bb9c5f59ba).(&saved,flam3_defaults_oncxx . . $ `flam3.h:48:9`!);
454
455 return (double) (hits / res3);
456 }
457
458 static void change_colorscxx . . $ change_colors(843ee1bb9c5f59ba).(flam3_genomecxx . . $ flam3_genome# *g, int change_palette) {
459 int i;
460 int x0, x1;
461 if (change_palette) {
462 g->hue_rotationcxx . . $ $anonymous_type_d4ed57c78da46593_3#hue_rotation. = 0.0;
463 g->palette_indexcxx . . $ $anonymous_type_d4ed57c78da46593_3#palette_index. = flam3_get_palettecxx . . $ flam3_get_palette(4c7a1137c04ffabc).(flam3_palette_randomcxx . . $ `flam3.h:45:9`!, g->palettecxx . . $ $anonymous_type_d4ed57c78da46593_3#palette., 0.0);
464 if (g->palette_indexcxx . . $ $anonymous_type_d4ed57c78da46593_3#palette_index. < 0)
465 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"error retrieving random palette, setting to all white\n");
466 }
467 for (i = 0; i < g->num_xformscxx . . $ $anonymous_type_d4ed57c78da46593_3#num_xforms.; i++) {
468 g->xformcxx . . $ $anonymous_type_d4ed57c78da46593_3#xform.[i].colorcxx . . $ xform#color. = flam3_random01cxx . . $ flam3_random01(b7b5bf912346b3df).();
469 }
470 x0 = random_xformcxx . . $ random_xform(164bf4c8a0c701ab).(g, -1);
471 x1 = random_xformcxx . . $ random_xform(164bf4c8a0c701ab).(g, x0);
472 if (x0 >= 0 && (randomcxx . . $ random(da6335ded91d79c2).()&1)) g->xformcxx . . $ $anonymous_type_d4ed57c78da46593_3#xform.[x0].colorcxx . . $ xform#color. = 0.0;
473 if (x1 >= 0 && (randomcxx . . $ random(da6335ded91d79c2).()&1)) g->xformcxx . . $ $anonymous_type_d4ed57c78da46593_3#xform.[x1].colorcxx . . $ xform#color. = 1.0;
474 }
475
476 void flam3_improve_colorscxx . . $ flam3_improve_colors(62aa529b45550848).(flam3_genomecxx . . $ flam3_genome# *g, int ntries, int change_palette, int color_resolution) {
477 int i;
478 double best, b;
479 flam3_genomecxx . . $ flam3_genome# best_genome;
480
481 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&best_genome, 0, sizeof(flam3_genomecxx . . $ flam3_genome#));
482
483 best = try_colorscxx . . $ try_colors(11c663caa9b1156b).(g, color_resolution);
484 if (best<0) {
485 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"error in try_colors, skipping flam3_improve_colors\n");
486 return;
487 }
488
489 flam3_copycxx . . $ flam3_copy(30da8946c6598614).(&best_genome,g);
490 for (i = 0; i < ntries; i++) {
491 change_colorscxx . . $ change_colors(843ee1bb9c5f59ba).(g, change_palette);
492 b = try_colorscxx . . $ try_colors(11c663caa9b1156b).(g, color_resolution);
493 if (b < 0) {
494 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"error in try_colors, aborting tries\n");
495 break;
496 }
497 if (b > best) {
498 best = b;
499 flam3_copycxx . . $ flam3_copy(30da8946c6598614).(&best_genome,g);
500 }
501 }
502
503 flam3_copycxx . . $ flam3_copy(30da8946c6598614).(g,&best_genome);
504 clear_cpcxx . . $ clear_cp(843ee1bb9c5f59ba).(&best_genome,flam3_defaults_oncxx . . $ `flam3.h:48:9`!);
505 }
506