plug-ins: Replace GimpRGB in Page Curl plug-in

Since no conversion operations are performed, just getting the
RGBA values from the gradient and then using them, this replaces
GimpRGB and GimpRGB * with gdouble * equivalents.
This commit is contained in:
Alx Sa 2024-09-05 03:55:28 +00:00
parent 77b3635401
commit 118ae3a3db
1 changed files with 28 additions and 37 deletions

View File

@ -134,7 +134,7 @@ static void clear_curled_region (GimpDrawable *drawabl
GimpProcedureConfig *config);
static GimpLayer * page_curl (GimpDrawable *drawable,
GimpProcedureConfig *config);
static GimpRGB * get_gradient_samples (GimpDrawable *drawable,
static gdouble * get_gradient_samples (GimpDrawable *drawable,
gboolean reverse);
@ -172,8 +172,8 @@ static gdouble diagm_slope;
/* User-configured parameters */
static GimpRGB fg_color;
static GimpRGB bg_color;
static gdouble fg_color[4];
static gdouble bg_color[4];
static void
@ -549,10 +549,10 @@ init_calculation (GimpDrawable *drawable,
/* Colors */
color = gimp_context_get_foreground ();
gegl_color_get_rgba_with_space (color, &fg_color.r, &fg_color.g, &fg_color.b, &fg_color.a, NULL);
gegl_color_get_pixel (color, babl_format ("R'G'B'A double"), fg_color);
g_object_unref (color);
color = gimp_context_get_background ();
gegl_color_get_rgba_with_space (color, &bg_color.r, &bg_color.g, &bg_color.b, &bg_color.a, NULL);
gegl_color_get_pixel (color, babl_format ("R'G'B'A double"), bg_color);
g_object_unref (color);
}
@ -570,7 +570,7 @@ do_curl_effect (GimpDrawable *drawable,
gdouble dl_mag, dr_mag, angle, factor;
GeglBuffer *curl_buffer;
GimpLayer *curl_layer;
GimpRGB *grad_samples = NULL;
gdouble *grad_samples = NULL;
gint width, height, n_ch;
GeglRectangle *roi;
GeglBufferIterator *iter;
@ -656,7 +656,7 @@ do_curl_effect (GimpDrawable *drawable,
for (y1 = roi->y; y1 < roi->y + roi->height; y1++)
{
GimpRGB color;
gdouble color[4] = { 0, 0, 0, 0 };
for (x1 = roi->x; x1 < roi->x + roi->width; x1++)
{
@ -676,7 +676,8 @@ do_curl_effect (GimpDrawable *drawable,
if (left_of_diagl (x, y))
{ /* uncurled region: transparent black */
gimp_rgba_set (&color, 0, 0, 0, 0);
for (gint i = 0; i < 4; i++)
color[i] = 0;
}
else if (right_of_diagr (x, y) ||
(right_of_diagm (x, y) &&
@ -684,7 +685,8 @@ do_curl_effect (GimpDrawable *drawable,
!inside_circle (x, y)))
{
/* curled region: transparent black */
gimp_rgba_set (&color, 0, 0, 0, 0);
for (gint i = 0; i < 4; i++)
color[i] = 0;
}
else
{
@ -697,22 +699,24 @@ do_curl_effect (GimpDrawable *drawable,
{
/* Below the curl. */
factor = angle / alpha;
gimp_rgba_set (&color, 0, 0, 0, shade ? factor : 0);
for (gint i = 0; i < 3; i++)
color[i] = 0;
color[3] = shade ? factor : 0;
}
else
{
GimpRGB *gradrgb;
guint rgb_index;
/* On the curl */
switch (colors)
{
case CURL_COLORS_FG_BG:
intensity = pow (sin (G_PI * angle / alpha), 1.5);
gimp_rgba_set (&color,
intensity * bg_color.r + (1.0 - intensity) * fg_color.r,
intensity * bg_color.g + (1.0 - intensity) * fg_color.g,
intensity * bg_color.b + (1.0 - intensity) * fg_color.b,
(1.0 - intensity * (1.0 - opacity)));
for (gint i = 0; i < 3; i++)
color[i] = intensity * bg_color[i] + (1.0 - intensity) * fg_color[i];
color[3] = 1.0 - intensity * (1.0 - opacity);
break;
case CURL_COLORS_GRADIENT:
@ -720,21 +724,20 @@ do_curl_effect (GimpDrawable *drawable,
/* Calculate position in Gradient */
intensity = (angle/alpha) + sin (G_PI*2 * angle/alpha) * 0.075;
gradrgb = grad_samples + ((guint) (intensity * NGRADSAMPLES));
rgb_index = ((guint) (intensity * NGRADSAMPLES));
/* Check boundaries */
intensity = CLAMP (intensity, 0.0, 1.0);
color = *gradrgb;
color.a = gradrgb->a * (1.0 - intensity * (1.0 - opacity));
for (gint i = 0; i < 4; i++)
color[i] = grad_samples[(rgb_index * 4) + i];
color[3] = grad_samples[(rgb_index * 4) + 3] * (1.0 - intensity * (1.0 - opacity));
break;
}
}
}
dest[0] = color.r;
dest[1] = color.g;
dest[2] = color.b;
dest[3] = color.a;
for (gint i = 0; i < 4; i++)
dest[i] = color[i];
dest += n_ch;
}
@ -882,7 +885,7 @@ page_curl (GimpDrawable *drawable,
Each sample has (gimp_drawable_get_bpp (drawable)) bytes.
"ripped" from gradmap.c.
*/
static GimpRGB *
static gdouble *
get_gradient_samples (GimpDrawable *drawable,
gboolean reverse)
{
@ -890,23 +893,11 @@ get_gradient_samples (GimpDrawable *drawable,
gint n_d_samples;
gdouble *d_samples = NULL;
GimpRGB *rgba;
gint i;
gradient = gimp_context_get_gradient ();
gimp_gradient_get_uniform_samples (gradient, NGRADSAMPLES, reverse,
&n_d_samples, &d_samples);
rgba = g_new0 (GimpRGB, NGRADSAMPLES);
for (i = 0; i < NGRADSAMPLES; i++)
{
gimp_rgba_set (rgba + i,
d_samples[i*4 + 0],
d_samples[i*4 + 1],
d_samples[i*4 + 2],
d_samples[i*4 + 3]);
}
return rgba;
return d_samples;
}