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 #ifndef private_included 20 #define private_included 21 22 #include "flam3.h" 23 #include "config.h" 24 #include <stdlib.h> 25 26 #include <ctype.h> 27 #include <time.h> 28 #include <string.h> 29 #include <libxml/parser.h> 30 31 #ifdef _WIN32 32 #define basename(x) strdup(x) 33 #define snprintf _snprintf 34 #define _USE_MATH_DEFINES 35 #else 36 #include <unistd.h> 37 #include <libgen.h> 38 #endif 39 40 #include <math.h> 41 42 #ifdef HAVE_LIBPTHREAD 43 #include <pthread.h> 44 #endif 45 46 #define PREFILTER_WHITE 255 47 #define EPS (1e-10) 48 #define CMAP_SIZE 256 49 #define CMAP_SIZE_M1 255 50 #define rbit() (flam3_random_bit()) 51 #define flam3_variation_none (-1) 52 #define max_specified_vars (100) 53 #define vlen(x) (sizeof(x)/sizeof(*x)) 54 55 56 #ifdef _WIN32 57 58 #ifndef M_PI 59 #define M_PI 3.1415926536 60 #define M_1_PI 0.3183098862 61 #define M_PI_4 0.7853981634 62 #endif 63 #define random() (rand() ^ (rand()<<15)) 64 #define srandom(x) (srand(x)) 65 extern int getpid(); 66 #define rint(A) floor((A)+(((A) < 0)? -0.5 : 0.5)) 67 #endif 68 69 #define argi(s,d) ((ai = getenv(s)) ? atoi(ai) : (d)) 70 #define argf(s,d) ((ai = getenv(s)) ? atof(ai) : (d)) 71 #define args(s,d) ((ai = getenv(s)) ? ai : (d)) 72 73 void docstring(); 74 75 /* Structures for passing parameters to iteration threads */ 76 typedef struct { 77 unsigned short *xform_distrib; /* Distribution of xforms based on weights */ 78 flam3_frame *spec; /* Frame contains timing information */ 79 double bounds[4]; /* Corner coords of viewable area */ 80 double rot[2][2]; /* Rotation transformation */ 81 double size[2]; 82 int width, height; /* buffer width/height */ 83 double ws0, wb0s0, hs1, hb1s1; /* shortcuts for indexing */ 84 flam3_palette_entry *dmap; /* palette */ 85 double color_scalar; /* <1.0 if non-uniform motion blur is set */ 86 void *buckets; /* Points to the first accumulator */ 87 double badvals; /* accumulates all badvalue resets */ 88 double batch_size; 89 int temporal_sample_num,ntemporal_samples; 90 int batch_num, nbatches, aborted, cmap_size; 91 time_t *progress_timer; 92 time_t *progress_timer_history; 93 double *progress_history; 94 int *progress_history_mark; 95 #ifdef HAVE_LIBPTHREAD 96 /* mutex for bucket accumulator */ 97 pthread_mutex_t bucket_mutex; 98 #endif 99 100 } flam3_iter_constants; 101 102 typedef struct { 103 104 double tx,ty; /* Starting coordinates */ 105 106 double precalc_atan, precalc_sina; /* Precalculated, if needed */ 107 double precalc_cosa, precalc_sqrt; 108 double precalc_sumsq,precalc_atanyx; 109 110 flam3_xform *xform; /* For the important values */ 111 112 /* Output Coords */ 113 114 double p0, p1; 115 116 /* Pointer to the isaac RNG state */ 117 randctx *rc; 118 119 } flam3_iter_helper; 120 121 typedef struct { 122 double *iter_storage; /* Storage for iteration coordinates */ 123 randctx rc; /* Thread-unique ISAAC seed */ 124 flam3_genome cp; /* Full copy of genome for use by the thread */ 125 int first_thread; 126 int timer_initialize; 127 flam3_iter_constants *fic; /* Constants for render */ 128 } flam3_thread_helper; 129 130 double flam3_sinc(double x); 131 132 #define flam3_num_spatialfilters 14 133 double flam3_gaussian_filter(double x); 134 double flam3_hermite_filter(double t); 135 double flam3_box_filter(double t); 136 double flam3_triangle_filter(double t); 137 double flam3_bell_filter(double t); 138 double flam3_b_spline_filter(double t); 139 double flam3_lanczos3_filter(double t); 140 double flam3_lanczos2_filter(double t); 141 double flam3_mitchell_filter(double t); 142 double flam3_blackman_filter(double x); 143 double flam3_catrom_filter(double x); 144 double flam3_hamming_filter(double x); 145 double flam3_hanning_filter(double x); 146 double flam3_quadratic_filter(double x); 147 148 double flam3_spatial_filter(int knum, double x); 149 150 #define flam3_mitchell_b (1.0 / 3.0) 151 #define flam3_mitchell_c (1.0 / 3.0) 152 153 154 #endif 155