From d8fbddac62eea524daff6d1e1f9787864bfe4edd Mon Sep 17 00:00:00 2001 From: EReckase Date: Sat, 11 Apr 2015 17:44:36 -0600 Subject: [PATCH] still need to change interp mode to hsv_circular --- flam3.c | 2 +- interpolation.c | 58 ++++++++++++++++++++++++++++--------------------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/flam3.c b/flam3.c index e0e6aa5..370d14a 100644 --- a/flam3.c +++ b/flam3.c @@ -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) diff --git a/interpolation.c b/interpolation.c index 0cfe668..80da2be 100644 --- a/interpolation.c +++ b/interpolation.c @@ -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_hsv2) { /* 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)