1 /*
2  *     XaoS, a fast portable realtime fractal zoomer
3  *                  Copyright (C) 1996,1997 by
4  *
5  *      Jan Hubicka          (hubicka@paru.cas.cz)
6  *      Thomas Marsh         (tmarsh@austin.ibm.com)
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22 #ifndef FRACTAL1_H
23 #define FRACTAL1_H
24 
25 #include "config.h"
26 #ifdef USE_SFFE
27 #include "sffe.h"
28 #endif
29 
30 #define INCOLORING 11
31 #define OUTCOLORING 11
32 #define TCOLOR 15
33 
34 typedef struct {
35     number_t y0, k;
36 } symmetrytype;
37 
38 struct symmetryinfo {
39     number_t xsym, ysym;
40     int nsymmetries;
41     const symmetrytype *symmetry;
42 };
43 typedef struct {
44     number_t mc, nc;
45     number_t mi, ni;
46 } vrect;
47 typedef struct {
48     number_t cr, ci;
49     number_t rr, ri;
50 } vinfo;
51 typedef unsigned int (*iterationfunc)(number_t, number_t, number_t, number_t);
52 struct formula {
53     int magic;
54     iterationfunc calculate, calculate_periodicity, smooth_calculate,
55         smooth_calculate_periodicity;
56     void (*calculate_julia)(struct image *img, number_t pre, number_t pim);
57     const char *name[2];
58     const char *shortname;
59     vinfo v;
60     int hasperiodicity;
61     int mandelbrot;
62     number_t pre, pim;
63     struct symmetryinfo out[OUTCOLORING + 1];
64     struct symmetryinfo in[INCOLORING + 1];
65     int flags;
66 };
67 
68 struct fractal_context {
69     number_t pre, pim;
70     number_t bre, bim;
71     const struct formula *currentformula;
72 #ifdef USE_SFFE
73     sffe *userformula;
74     sffe *userinitial;
75 #endif
76     number_t angle;
77     int periodicity;
78     unsigned int maxiter;
79     number_t bailout;
80     int coloringmode, incoloringmode;
81     int intcolor, outtcolor;
82     int mandelbrot;
83     int plane;
84     int version;
85     int range;
86     float windowwidth, windowheight;
87     vinfo s;
88     vrect rs;
89     number_t sin, cos;
90     int slowmode; /* 1 in case we want to be exact, not fast */
91     /*values temporary filled by set_fractal_context */
92     iterationfunc calculate[2];
93     number_t periodicity_limit;
94     struct palette *palette; /*fractal's palette */
95 };
96 typedef struct fractal_context fractal_context;
97 typedef struct {
98     double y0, k, kk, y0k;
99 } symmetry2;
100 
101 struct symmetryinfo2 {
102     number_t xsym, ysym;
103     int nsymmetries;
104     symmetry2 *symmetry;
105     number_t xmul, ymul, xdist, ydist;
106 };
107 #define STARTZERO 1
108 #define JULIA_BTRACE 2
109 #define MANDEL_BTRACE 4
110 #ifdef USE_SFFE
111 #define SFFE_FRACTAL 8
112 #endif
113 
114 #define BTRACEOK                                                               \
115     ((cformula.flags & (2 << cfractalc.mandelbrot)) &&                         \
116      !cfractalc.incoloringmode && cfractalc.coloringmode != 7)
117 #define rotate(f, x, y)                                                        \
118     {                                                                          \
119         number_t tmp;                                                          \
120         tmp = (x) * (f).cos - (y) * (f).sin;                                   \
121         y = (x) * (f).sin + (y) * (f).cos;                                     \
122         x = tmp;                                                               \
123     }
124 #define rotateback(f, x, y)                                                    \
125     {                                                                          \
126         number_t tmp;                                                          \
127         tmp = (x) * (f).cos + (y) * (f).sin;                                   \
128         y = -(x) * (f).sin + (y) * (f).cos;                                    \
129         x = tmp;                                                               \
130     }
131 
132 #ifdef USE_SFFE
133 void sffe_setlocal(fractal_context *c);
134 #endif
135 
136 extern struct symmetryinfo2 cursymmetry;
137 extern struct fractal_context cfractalc;
138 extern struct formula cformula;
139 extern struct palette cpalette;
140 extern struct image cimage;
141 
142 #ifdef STATISTICS
143 /*This is an statistics variables printed from various parts
144  *of XaoS.
145  */
146 extern int nadded2, nsymmetry2, nskipped2;
147 extern int tocalculate2, avoided2, frames2;
148 extern int ncalculated2, ninside2;
149 extern int niter2, niter1;
150 extern int nperi;
151 
152 extern int iters2, guessed2, unguessed2, total2;
153 
154 #endif
155 
156 void set_formula(fractal_context *, int);
157 void set_fractalc(fractal_context *, struct image *img);
158 void fractalc_resize_to(fractal_context *, float, float);
159 void update_view(fractal_context *);
160 void free_fractalc(fractal_context *);
161 fractal_context *make_fractalc(const int, float, float);
162 void speed_test(fractal_context *, struct image *img);
163 unsigned int calculateswitch(number_t x1, number_t y1, number_t x2, number_t y2,
164                              int periodicity);
165 
166 /* needs struct formula */
167 #include "formulas.h"
168 
169 #endif /* FRACTAL_H */
170