summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--flam3.c6
-rw-r--r--flam3.h6
-rw-r--r--parser.c4
-rw-r--r--rect.c70
5 files changed, 47 insertions, 41 deletions
diff --git a/.gitignore b/.gitignore
index 98088bc..3bd2b31 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,4 @@
-*.o
*.sw?
-*.lo
waf
build/
.lock-*
diff --git a/flam3.c b/flam3.c
index 694868f..74a0c59 100644
--- a/flam3.c
+++ b/flam3.c
@@ -1074,7 +1074,7 @@ void clear_cp(flam3_genome *cp, int default_flag) {
cp->temporal_filter_type = flam3_temporal_box;
cp->temporal_filter_width = 1.0;
cp->temporal_filter_exp = 0.0;
- cp->palette_mode = flam3_palette_mode_step;
+ cp->palette_mode = PALETTE_MODE_STEP;
} else {
/* Defaults are off, so set to UN-reasonable values. */
@@ -1467,9 +1467,9 @@ void flam3_print(FILE *f, flam3_genome *cp, char *extra_attributes, int print_ed
fprintf(f, " vibrancy=\"%g\"", cp->vibrancy);
fprintf(f, " gamma_threshold=\"%g\"", cp->gam_lin_thresh);
- if (flam3_palette_mode_step == cp->palette_mode)
+ if (PALETTE_MODE_STEP == cp->palette_mode)
fprintf(f, " palette_mode=\"step\"");
- else if (flam3_palette_mode_linear == cp->palette_mode)
+ else if (PALETTE_MODE_LINEAR == cp->palette_mode)
fprintf(f, " palette_mode=\"linear\"");
if (flam3_interpolation_linear != cp->interpolation)
diff --git a/flam3.h b/flam3.h
index 2434a78..de2ad07 100644
--- a/flam3.h
+++ b/flam3.h
@@ -73,8 +73,10 @@ extern char *flam3_variation_names[];
#define flam3_max_action_length 10000
-#define flam3_palette_mode_step 0
-#define flam3_palette_mode_linear 1
+typedef enum {
+ PALETTE_MODE_STEP = 0,
+ PALETTE_MODE_LINEAR = 1,
+} color_palette_mode;
#define VAR_LINEAR 0
#define VAR_SINUSOIDAL 1
diff --git a/parser.c b/parser.c
index ee1aa18..1738925 100644
--- a/parser.c
+++ b/parser.c
@@ -442,9 +442,9 @@ int parse_flame_element(xmlNode *flame_node, flam3_genome *loc_current_cp,
cp->temporal_filter_exp = flam3_atof(att_str);
} else if (!xmlStrcmp(cur_att->name, (const xmlChar *)"palette_mode")) {
if (!strcmp("step", att_str))
- cp->palette_mode = flam3_palette_mode_step;
+ cp->palette_mode = PALETTE_MODE_STEP;
else if (!strcmp("linear", att_str))
- cp->palette_mode = flam3_palette_mode_linear;
+ cp->palette_mode = PALETTE_MODE_LINEAR;
else
fprintf(stderr,"warning: unrecognized palette mode %s. Using step.\n",att_str);
} else if (!xmlStrcmp(cur_att->name, (const xmlChar *)"quality")) {
diff --git a/rect.c b/rect.c
index 57234c5..d0b767e 100644
--- a/rect.c
+++ b/rect.c
@@ -42,6 +42,41 @@
#define FUSE_27 15
#define FUSE_28 100
+/* Lookup color [0,1]
+ */
+static double4 color_palette_lookup (const double color,
+ const color_palette_mode mode, const flam3_palette map,
+ const unsigned int map_count) {
+ assert (color >= 0.0 && color <= 1.0);
+
+ switch (mode) {
+ case PALETTE_MODE_LINEAR: {
+ const double ix = color * map_count;
+ const double bottomix = floor (ix);
+ const double frac = ix - bottomix;
+ const unsigned int intix = bottomix;
+
+ if (intix == map_count-1) {
+ return map[intix].color;
+ } else {
+ return map[intix].color * (1.0-frac) +
+ map[intix+1].color * frac;
+ }
+ break;
+ }
+
+ case PALETTE_MODE_STEP: {
+ const unsigned int intix = nearbyint (color * map_count);
+ return map[intix].color;
+ break;
+ }
+
+ default:
+ assert (0);
+ break;
+ }
+}
+
static void iter_thread(void *fth) {
double sub_batch;
int j;
@@ -51,7 +86,6 @@ static void iter_thread(void *fth) {
int SBS = ficp->spec->sub_batch_size;
int fuse;
int cmap_size = ficp->cmap_size;
- int cmap_size_m1 = ficp->cmap_size-1;
double eta = 0.0;
@@ -186,9 +220,6 @@ static void iter_thread(void *fth) {
/* Put them in the bucket accumulator */
for (j = 0; j < sub_batch_size; j++) {
double p0, p1, p00, p11;
- double dbl_index0,dbl_frac;
- double4 interpcolor;
- int color_index0;
const double4 p = fthp->iter_storage[j];
if (fthp->cp.rotate != 0.0) {
@@ -210,34 +241,9 @@ static void iter_thread(void *fth) {
continue;
else
logvis = p[3];
-
- dbl_index0 = p[2] * cmap_size;
- color_index0 = (int) (dbl_index0);
-
- if (flam3_palette_mode_linear == fthp->cp.palette_mode) {
- if (color_index0 < 0) {
- color_index0 = 0;
- dbl_frac = 0;
- } else if (color_index0 >= cmap_size_m1) {
- color_index0 = cmap_size_m1-1;
- dbl_frac = 1.0;
- } else {
- /* interpolate between color_index0 and color_index0+1 */
- dbl_frac = dbl_index0 - (double)color_index0;
- }
-
- interpcolor = ficp->dmap[color_index0].color * (1.0-dbl_frac) +
- ficp->dmap[color_index0+1].color * dbl_frac;
- } else { /* Palette mode step */
-
- if (color_index0 < 0) {
- color_index0 = 0;
- } else if (color_index0 >= cmap_size_m1) {
- color_index0 = cmap_size_m1;
- }
-
- interpcolor = ficp->dmap[color_index0].color;
- }
+
+ double4 interpcolor = color_palette_lookup (p[2],
+ fthp->cp.palette_mode, ficp->dmap, cmap_size);
if (p[3]!=1.0) {
interpcolor *= logvis;