Merge pull request #5 from EReckase/master

Short-way hue interpolation tweaks
This commit is contained in:
Scott Draves 2015-04-12 09:18:56 -04:00
commit 0eb68c545d
4 changed files with 38 additions and 30 deletions

View File

@ -480,7 +480,7 @@ flam3_genome *sheep_edge(flam3_genome *cp, double blend, int seqflag, double sta
flam3_rotate(&spun[0], blend*360.0, spun[0].interpolation_type);
flam3_rotate(&spun[1], blend*360.0, spun[0].interpolation_type);
fprintf(stderr, "xyzzy %d %d\n", spun[0].palette_interpolation, spun[1].palette_interpolation);
//fprintf(stderr, "xyzzy %d %d\n", spun[0].palette_interpolation, spun[1].palette_interpolation);
/* Now call the interpolation */
if (argi("unsmoother",0) == 0)
@ -1281,7 +1281,7 @@ void clear_cp(flam3_genome *cp, int default_flag) {
cp->rotate = 0.0;
cp->pixels_per_unit = 50;
cp->interpolation = flam3_interpolation_linear;
cp->palette_interpolation = flam3_palette_interpolation_hsv;
cp->palette_interpolation = flam3_palette_interpolation_hsv_circular;
cp->genome_index = 0;
memset(cp->parent_fname,0,flam3_parent_fn_len);

View File

@ -75,7 +75,7 @@ extern char *flam3_variation_names[];
#define flam3_palette_interpolation_hsv 0
#define flam3_palette_interpolation_sweep 1
#define flam3_palette_interpolation_rgb 2
#define flam3_palette_interpolation_hsv2 3
#define flam3_palette_interpolation_hsv_circular 3
#define flam3_max_action_length 10000

View File

@ -172,13 +172,15 @@ void interpolate_cmap(flam3_palette cmap, double blend,
t[4] = p1[i].index;
/* take the shorter way around the hue circle */
if (0 == i) {
fprintf(stderr, "xxx interpolating between hues, %g %g\n", s[0], t[0]);
}
if ((s[0] - t[0]) > 3.0)
// if (0 == i) {
// fprintf(stderr, "xxx interpolating between hues, %g %g\n", s[0], t[0]);
// }
/* Correct the first hue to go the short way around */
if ((s[0] - t[0]) > 3.0) /* first hue much bigger than second hue */
s[0] -= 6.0
if ((s[0] - t[0]) < -3.0) /* first hue much smaller than second hue */
s[0] += 6.0;
if ((t[0] - s[0]) > 3.0)
t[0] += 6.0;
for (j = 0; j < 5; j++)
t[j] = ((1.0-blend) * s[j]) + (blend * t[j]);
@ -372,7 +374,7 @@ void flam3_interpolate_n(flam3_genome *result, int ncp,
flam3_genome *cpi, double *c, double stagger) {
int i, j, k, numstd;
fprintf(stderr, "xxx pi=%d\n", cpi[0].palette_interpolation);
// fprintf(stderr, "xxx pi=%d\n", cpi[0].palette_interpolation);
if (flam3_palette_interpolation_sweep != cpi[0].palette_interpolation) {
@ -384,8 +386,8 @@ void flam3_interpolate_n(flam3_genome *result, int ncp,
for (k = 0; k < ncp; k++) {
if (i == 0) {
fprintf(stderr, "ncp=%d, k=%d\n", ncp, k);
fprintf(stderr, "rgb=%g %g %g\n", cpi[k].palette[i].color[0], cpi[k].palette[i].color[1], cpi[k].palette[i].color[2]);
// fprintf(stderr, "ncp=%d, k=%d\n", ncp, k);
// fprintf(stderr, "rgb=%g %g %g\n", cpi[k].palette[i].color[0], cpi[k].palette[i].color[1], cpi[k].palette[i].color[2]);
}
if (flam3_palette_interpolation_rgb != cpi[0].palette_interpolation)
rgb2hsv(cpi[k].palette[i].color, t);
@ -394,19 +396,25 @@ void flam3_interpolate_n(flam3_genome *result, int ncp,
for (l = 0; l < 3; l++)
t[l] = cpi[k].palette[i].color[l];
}
if (i == 0) {
fprintf(stderr, "hsv=%g %g %g\n", t[0], t[1], t[2]);
}
// if (i == 0) {
// fprintf(stderr, "hsv=%g %g %g\n", t[0], t[1], t[2]);
// }
if (2 == ncp && cpi[0].palette_interpolation == flam3_palette_interpolation_hsv2) {
if (2 == ncp && k == 0 &&cpi[0].palette_interpolation == flam3_palette_interpolation_hsv_circular) {
/* should also support blending between rgb and hsv,
and change the color of the cut, so we can keep
a dominant color but control what it is. */
double z[3];
rgb2hsv(cpi[1-k].palette[i].color, z);
if ((z[0] - t[0]) > 3.0) t[0] += 6.0;
if (i == 0)
fprintf(stderr, "adjusted %g %g\n", z[0], t[0]);
/* only adjust the first coordinate based on the other control point's hue */
double second_color[3];
rgb2hsv(cpi[1].palette[i].color, second_color);
/* Adjust the hue so that we go the shorter direction around the circle */
if ((second_color[0] - t[0]) > 3.0) {
t[0] += 6.0;
} else if ((second_color[0] - t[0]) < -3.0) {
t[0] -= 6.0;
}
}
for (j = 0; j < 3; j++)
@ -422,8 +430,8 @@ void flam3_interpolate_n(flam3_genome *result, int ncp,
if (alpha1 == 1)
s[3] = 1.0;
if (i == 0)
fprintf(stderr, "s0=%g\n", s[0]);
// if (i == 0)
// fprintf(stderr, "s0=%g\n", s[0]);
if (flam3_palette_interpolation_rgb != cpi[0].palette_interpolation)
hsv2rgb(s, result->palette[i].color);
@ -435,11 +443,11 @@ void flam3_interpolate_n(flam3_genome *result, int ncp,
result->palette[i].color[3] = s[3];
result->palette[i].index = s[4];
if (i == 0)
fprintf(stderr, "result rgb=%g %g %g\n",
result->palette[0].color[0],
result->palette[0].color[1],
result->palette[0].color[2]);
// if (i == 0)
// fprintf(stderr, "result rgb=%g %g %g\n",
// result->palette[0].color[0],
// result->palette[0].color[1],
// result->palette[0].color[2]);
for (j = 0; j < 4; j++) {
if (result->palette[i].color[j] < 0.0)

View File

@ -345,8 +345,8 @@ int parse_flame_element(xmlNode *flame_node, flam3_genome *loc_current_cp) {
cp->palette_interpolation = flam3_palette_interpolation_hsv;
} else if (!strcmp("sweep", att_str)) {
cp->palette_interpolation = flam3_palette_interpolation_sweep;
} else if (!strcmp("hsv2", att_str)) {
cp->palette_interpolation = flam3_palette_interpolation_hsv2;
} else if (!strcmp("hsv_circular", att_str)) {
cp->palette_interpolation = flam3_palette_interpolation_hsv_circular;
} else if (!strcmp("rgb", att_str)) {
cp->palette_interpolation = flam3_palette_interpolation_rgb;
} else {