Commit 0462734f authored by Ell's avatar Ell

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.

(cherry picked from commit 68bf99e806ba38a06df92d736dab65e6cd17a44c)
parent 59682a1c
......@@ -339,6 +339,11 @@ static const GimpRadioActionEntry gradient_editor_blending_actions[] =
GIMP_GRADIENT_SEGMENT_SPHERE_DECREASING,
GIMP_HELP_GRADIENT_EDITOR_BLENDING },
{ "gradient-editor-blending-step", NULL,
NC_("gradient-editor-blending", "S_tep"), NULL, NULL,
GIMP_GRADIENT_SEGMENT_STEP,
GIMP_HELP_GRADIENT_EDITOR_BLENDING },
{ "gradient-editor-blending-varies", NULL,
NC_("gradient-editor-blending", "(Varies)"), NULL, NULL,
-1,
......@@ -826,6 +831,7 @@ gradient_editor_actions_update (GimpActionGroup *group,
SET_SENSITIVE ("gradient-editor-blending-sine", editable);
SET_SENSITIVE ("gradient-editor-blending-sphere-increasing", editable);
SET_SENSITIVE ("gradient-editor-blending-sphere-decreasing", editable);
SET_SENSITIVE ("gradient-editor-blending-step", editable);
if (blending_equal && gradient)
{
......@@ -846,6 +852,9 @@ gradient_editor_actions_update (GimpActionGroup *group,
case GIMP_GRADIENT_SEGMENT_SPHERE_DECREASING:
SET_ACTIVE ("gradient-editor-blending-sphere-decreasing", TRUE);
break;
case GIMP_GRADIENT_SEGMENT_STEP:
SET_ACTIVE ("gradient-editor-blending-step", TRUE);
break;
}
}
else
......
......@@ -199,7 +199,7 @@ gimp_gradient_load (GimpContext *context,
case 2:
seg->type = (GimpGradientSegmentType) type;
if (seg->type < GIMP_GRADIENT_SEGMENT_LINEAR ||
seg->type > GIMP_GRADIENT_SEGMENT_SPHERE_DECREASING)
seg->type > GIMP_GRADIENT_SEGMENT_STEP)
{
g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
_("Corrupt segment %d."), i);
......
......@@ -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;
}
......@@ -708,6 +708,7 @@ gimp_gradient_segment_type_get_type (void)
{ GIMP_GRADIENT_SEGMENT_SINE, "GIMP_GRADIENT_SEGMENT_SINE", "sine" },
{ GIMP_GRADIENT_SEGMENT_SPHERE_INCREASING, "GIMP_GRADIENT_SEGMENT_SPHERE_INCREASING", "sphere-increasing" },
{ GIMP_GRADIENT_SEGMENT_SPHERE_DECREASING, "GIMP_GRADIENT_SEGMENT_SPHERE_DECREASING", "sphere-decreasing" },
{ GIMP_GRADIENT_SEGMENT_STEP, "GIMP_GRADIENT_SEGMENT_STEP", "step" },
{ 0, NULL, NULL }
};
......@@ -724,6 +725,7 @@ gimp_gradient_segment_type_get_type (void)
/* Translators: this is an abbreviated version of "Spherical (decreasing)".
Keep it short. */
{ GIMP_GRADIENT_SEGMENT_SPHERE_DECREASING, NC_("gradient-segment-type", "Spherical (dec)"), NULL },
{ GIMP_GRADIENT_SEGMENT_STEP, NC_("gradient-segment-type", "Step"), NULL },
{ 0, NULL, NULL }
};
......
......@@ -616,7 +616,8 @@ typedef enum
GIMP_GRADIENT_SEGMENT_CURVED, /*< desc="Curved" >*/
GIMP_GRADIENT_SEGMENT_SINE, /*< desc="Sinusoidal" >*/
GIMP_GRADIENT_SEGMENT_SPHERE_INCREASING, /*< desc="Spherical (increasing)", abbrev="Spherical (inc)" >*/
GIMP_GRADIENT_SEGMENT_SPHERE_DECREASING /*< desc="Spherical (decreasing)", abbrev="Spherical (dec)" >*/
GIMP_GRADIENT_SEGMENT_SPHERE_DECREASING, /*< desc="Spherical (decreasing)", abbrev="Spherical (dec)" >*/
GIMP_GRADIENT_SEGMENT_STEP /*< desc="Step" >*/
} GimpGradientSegmentType;
......
......@@ -85,6 +85,7 @@
<menuitem action="gradient-editor-blending-sine" />
<menuitem action="gradient-editor-blending-sphere-increasing" />
<menuitem action="gradient-editor-blending-sphere-decreasing" />
<menuitem action="gradient-editor-blending-step" />
<menuitem action="gradient-editor-blending-varies" />
</menu>
<menu action="gradient-editor-coloring-type">
......
......@@ -230,12 +230,14 @@ package Gimp::CodeGen::enums;
GIMP_GRADIENT_SEGMENT_CURVED
GIMP_GRADIENT_SEGMENT_SINE
GIMP_GRADIENT_SEGMENT_SPHERE_INCREASING
GIMP_GRADIENT_SEGMENT_SPHERE_DECREASING) ],
GIMP_GRADIENT_SEGMENT_SPHERE_DECREASING
GIMP_GRADIENT_SEGMENT_STEP) ],
mapping => { GIMP_GRADIENT_SEGMENT_LINEAR => '0',
GIMP_GRADIENT_SEGMENT_CURVED => '1',
GIMP_GRADIENT_SEGMENT_SINE => '2',
GIMP_GRADIENT_SEGMENT_SPHERE_INCREASING => '3',
GIMP_GRADIENT_SEGMENT_SPHERE_DECREASING => '4' }
GIMP_GRADIENT_SEGMENT_SPHERE_DECREASING => '4',
GIMP_GRADIENT_SEGMENT_STEP => '5' }
},
GimpGradientType =>
{ contig => 1,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment