Issue #2303 - Please add Constant type of gradient interpolation ...

... to make multi-color hard-edge gradient fills possible

Add a new "step" gradient-segment blending function, which is 0
before the midpoint, and 1 at, and after, the midpoint.  This
creates a hard-edge transition between the two adjacent color stops
at the midpoint.  Creating such a transition was already possible,
but required duplicating the same color at the opposing ends of two
adjacent stops, which is cumbersome.
This commit is contained in:
Ell
2018-10-02 21:13:16 -04:00
parent be84c6e766
commit 68bf99e806
7 changed files with 32 additions and 4 deletions

View File

@ -90,6 +90,8 @@ static inline gdouble gimp_gradient_calc_sphere_increasing_factor (gdouble mid
gdouble pos);
static inline gdouble gimp_gradient_calc_sphere_decreasing_factor (gdouble middle,
gdouble pos);
static inline gdouble gimp_gradient_calc_step_factor (gdouble middle,
gdouble pos);
G_DEFINE_TYPE_WITH_CODE (GimpGradient, gimp_gradient, GIMP_TYPE_DATA,
@ -503,6 +505,10 @@ gimp_gradient_get_color_at (GimpGradient *gradient,
factor = gimp_gradient_calc_sphere_decreasing_factor (middle, pos);
break;
case GIMP_GRADIENT_SEGMENT_STEP:
factor = gimp_gradient_calc_step_factor (middle, pos);
break;
default:
g_warning ("%s: Unknown gradient type %d.", G_STRFUNC, seg->type);
break;
@ -2273,3 +2279,10 @@ gimp_gradient_calc_sphere_decreasing_factor (gdouble middle,
/* Works for convex decreasing and concave increasing */
return 1.0 - sqrt(1.0 - pos * pos);
}
static inline gdouble
gimp_gradient_calc_step_factor (gdouble middle,
gdouble pos)
{
return pos >= middle;
}