13 bool parse_gif(
const char *source,
int length, mpfr_t cx, mpfr_t cy, mpfr_t cz) {
15 const char *gif =
"GIF";
16 const int gif_length = 3;
17 const char *fractint001 =
"fractint001";
18 const int fractint001_length = 11;
19 const char *info_id =
"Fractal";
20 const int info_id_length = 8;
22 const int length_b = 1;
23 const int version_lsb = 79;
24 const int version_msb = 80;
25 const int type_lsb = 11;
26 const int type_msb = 12;
27 const int coord_doubles = 13;
28 const int max_offset = 81;
30 const int type_mandelbrot1 = 0;
31 const int type_mandelbrot2 = 4;
33 if (0 != memcmp(source, gif, gif_length)) {
38 for (
int offset = 0; offset < length - fractint001_length; ++offset) {
39 if (0 == memcmp(source + offset, fractint001, fractint001_length)) {
44 const unsigned char *info = (
const unsigned char *) source + offset + fractint001_length;
47 while (info < (
const unsigned char *) source + length - max_offset && (info_length = info[0])) {
49 if (0 == memcmp((
const char *) info + length_b, info_id, info_id_length)) {
53 int version = info[version_lsb] | (info[version_msb] << 8);
56 int type = info[type_lsb] | (info[type_msb] << 8);
58 if (type == type_mandelbrot1 || type == type_mandelbrot2) {
60 double coords[6]; memcpy(coords, info + coord_doubles,
sizeof(coords));
61 double xmin = coords[0];
62 double xmax = coords[1];
63 double ymin = coords[2];
64 double ymax = coords[3];
65 double creal = coords[4];
66 double cimag = coords[5];
67 debug_message(
"fractint gif coords %e %e %e %e %e %e\n", xmin, xmax, ymin, ymax, creal, cimag);
69 double x = (xmin + xmax) / 2.0;
70 double y = (ymin + ymax) / 2.0;
71 double z = fabs(ymax - ymin) / 2.0;
75 mpfr_set_prec(cx, 53);
76 mpfr_set_prec(cy, 53);
77 mpfr_set_d(cx, x, MPFR_RNDN);
78 mpfr_set_d(cy, y, MPFR_RNDN);
79 mpfr_set_d(cz, z, MPFR_RNDN);
85 info += 1 + info_length;