app: add offset support to shaped gradients
In gimp:gradient, handle the "offset" property in shaped gradients.
(cherry picked from commit 6bd5deea89
)
This commit is contained in:
@ -139,12 +139,15 @@ static gdouble gradient_calc_spiral_factor (gdouble
|
|||||||
gboolean clockwise);
|
gboolean clockwise);
|
||||||
|
|
||||||
static gdouble gradient_calc_shapeburst_angular_factor (GeglSampler *dist_sampler,
|
static gdouble gradient_calc_shapeburst_angular_factor (GeglSampler *dist_sampler,
|
||||||
|
gdouble offset,
|
||||||
gdouble x,
|
gdouble x,
|
||||||
gdouble y);
|
gdouble y);
|
||||||
static gdouble gradient_calc_shapeburst_spherical_factor (GeglSampler *dist_sampler,
|
static gdouble gradient_calc_shapeburst_spherical_factor (GeglSampler *dist_sampler,
|
||||||
|
gdouble offset,
|
||||||
gdouble x,
|
gdouble x,
|
||||||
gdouble y);
|
gdouble y);
|
||||||
static gdouble gradient_calc_shapeburst_dimpled_factor (GeglSampler *dist_sampler,
|
static gdouble gradient_calc_shapeburst_dimpled_factor (GeglSampler *dist_sampler,
|
||||||
|
gdouble offset,
|
||||||
gdouble x,
|
gdouble x,
|
||||||
gdouble y);
|
gdouble y);
|
||||||
|
|
||||||
@ -797,28 +800,48 @@ gradient_calc_spiral_factor (gdouble dist,
|
|||||||
|
|
||||||
static gdouble
|
static gdouble
|
||||||
gradient_calc_shapeburst_angular_factor (GeglSampler *dist_sampler,
|
gradient_calc_shapeburst_angular_factor (GeglSampler *dist_sampler,
|
||||||
|
gdouble offset,
|
||||||
gdouble x,
|
gdouble x,
|
||||||
gdouble y)
|
gdouble y)
|
||||||
{
|
{
|
||||||
gfloat value;
|
gfloat value;
|
||||||
|
|
||||||
|
offset = offset / 100.0;
|
||||||
|
|
||||||
gegl_sampler_get (dist_sampler, x, y, NULL, &value, GEGL_ABYSS_NONE);
|
gegl_sampler_get (dist_sampler, x, y, NULL, &value, GEGL_ABYSS_NONE);
|
||||||
|
|
||||||
value = 1.0 - value;
|
value = 1.0 - value;
|
||||||
|
|
||||||
|
if (value < offset)
|
||||||
|
value = 0.0;
|
||||||
|
else if (offset == 1.0)
|
||||||
|
value = (value >= 1.0) ? 1.0 : 0.0;
|
||||||
|
else
|
||||||
|
value = (value - offset) / (1.0 - offset);
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static gdouble
|
static gdouble
|
||||||
gradient_calc_shapeburst_spherical_factor (GeglSampler *dist_sampler,
|
gradient_calc_shapeburst_spherical_factor (GeglSampler *dist_sampler,
|
||||||
|
gdouble offset,
|
||||||
gdouble x,
|
gdouble x,
|
||||||
gdouble y)
|
gdouble y)
|
||||||
{
|
{
|
||||||
gfloat value;
|
gfloat value;
|
||||||
|
|
||||||
|
offset = 1.0 - offset / 100.0;
|
||||||
|
|
||||||
gegl_sampler_get (dist_sampler, x, y, NULL, &value, GEGL_ABYSS_NONE);
|
gegl_sampler_get (dist_sampler, x, y, NULL, &value, GEGL_ABYSS_NONE);
|
||||||
|
|
||||||
|
if (value > offset)
|
||||||
|
value = 1.0;
|
||||||
|
else if (offset == 0.0)
|
||||||
|
value = (value <= 0.0) ? 0.0 : 1.0;
|
||||||
|
else
|
||||||
|
value = value / offset;
|
||||||
|
|
||||||
value = 1.0 - sin (0.5 * G_PI * value);
|
value = 1.0 - sin (0.5 * G_PI * value);
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
@ -827,13 +850,23 @@ gradient_calc_shapeburst_spherical_factor (GeglSampler *dist_sampler,
|
|||||||
|
|
||||||
static gdouble
|
static gdouble
|
||||||
gradient_calc_shapeburst_dimpled_factor (GeglSampler *dist_sampler,
|
gradient_calc_shapeburst_dimpled_factor (GeglSampler *dist_sampler,
|
||||||
|
gdouble offset,
|
||||||
gdouble x,
|
gdouble x,
|
||||||
gdouble y)
|
gdouble y)
|
||||||
{
|
{
|
||||||
gfloat value;
|
gfloat value;
|
||||||
|
|
||||||
|
offset = 1.0 - offset / 100.0;
|
||||||
|
|
||||||
gegl_sampler_get (dist_sampler, x, y, NULL, &value, GEGL_ABYSS_NONE);
|
gegl_sampler_get (dist_sampler, x, y, NULL, &value, GEGL_ABYSS_NONE);
|
||||||
|
|
||||||
|
if (value > offset)
|
||||||
|
value = 1.0;
|
||||||
|
else if (offset == 0.0)
|
||||||
|
value = (value <= 0.0) ? 0.0 : 1.0;
|
||||||
|
else
|
||||||
|
value = value / offset;
|
||||||
|
|
||||||
value = cos (0.5 * G_PI * value);
|
value = cos (0.5 * G_PI * value);
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
@ -893,16 +926,19 @@ gradient_render_pixel (gdouble x,
|
|||||||
|
|
||||||
case GIMP_GRADIENT_SHAPEBURST_ANGULAR:
|
case GIMP_GRADIENT_SHAPEBURST_ANGULAR:
|
||||||
factor = gradient_calc_shapeburst_angular_factor (rbd->dist_sampler,
|
factor = gradient_calc_shapeburst_angular_factor (rbd->dist_sampler,
|
||||||
|
rbd->offset,
|
||||||
x, y);
|
x, y);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GIMP_GRADIENT_SHAPEBURST_SPHERICAL:
|
case GIMP_GRADIENT_SHAPEBURST_SPHERICAL:
|
||||||
factor = gradient_calc_shapeburst_spherical_factor (rbd->dist_sampler,
|
factor = gradient_calc_shapeburst_spherical_factor (rbd->dist_sampler,
|
||||||
|
rbd->offset,
|
||||||
x, y);
|
x, y);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GIMP_GRADIENT_SHAPEBURST_DIMPLED:
|
case GIMP_GRADIENT_SHAPEBURST_DIMPLED:
|
||||||
factor = gradient_calc_shapeburst_dimpled_factor (rbd->dist_sampler,
|
factor = gradient_calc_shapeburst_dimpled_factor (rbd->dist_sampler,
|
||||||
|
rbd->offset,
|
||||||
x, y);
|
x, y);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user