GitLab repository storage has been migrated to hashed layout. Please contact Infrastructure team if you notice any issues with repositories or hooks.

Commit 0a4e1383 authored by Michael Natterer's avatar Michael Natterer 😴

app: port gradient rendering with supersampling to GEGL, always use float

parent f857f1f5
...@@ -65,11 +65,10 @@ typedef struct ...@@ -65,11 +65,10 @@ typedef struct
typedef struct typedef struct
{ {
PixelRegion *PR; GeglBuffer *buffer;
guchar *row_data; gfloat *row_data;
gint bytes; gint width;
gint width; GRand *dither_rand;
GRand *dither_rand;
} PutPixelData; } PutPixelData;
...@@ -138,6 +137,7 @@ static void gradient_put_pixel (gint x, ...@@ -138,6 +137,7 @@ static void gradient_put_pixel (gint x,
static void gradient_fill_region (GimpImage *image, static void gradient_fill_region (GimpImage *image,
GimpDrawable *drawable, GimpDrawable *drawable,
GimpContext *context, GimpContext *context,
GeglBuffer *buffer,
PixelRegion *PR, PixelRegion *PR,
gint width, gint width,
gint height, gint height,
...@@ -213,6 +213,7 @@ gimp_drawable_blend (GimpDrawable *drawable, ...@@ -213,6 +213,7 @@ gimp_drawable_blend (GimpDrawable *drawable,
0, 0, width, height, TRUE); 0, 0, width, height, TRUE);
gradient_fill_region (image, drawable, context, gradient_fill_region (image, drawable, context,
buffer,
&bufPR, width, height, &bufPR, width, height,
blend_mode, gradient_type, offset, repeat, reverse, blend_mode, gradient_type, offset, repeat, reverse,
supersample, max_depth, threshold, dither, supersample, max_depth, threshold, dither,
...@@ -220,8 +221,6 @@ gimp_drawable_blend (GimpDrawable *drawable, ...@@ -220,8 +221,6 @@ gimp_drawable_blend (GimpDrawable *drawable,
(endx - x), (endy - y), (endx - x), (endy - y),
progress); progress);
gimp_gegl_buffer_refetch_tiles (buffer);
gimp_drawable_apply_buffer (drawable, buffer, gimp_drawable_apply_buffer (drawable, buffer,
GEGL_RECTANGLE (0, 0, width, height), GEGL_RECTANGLE (0, 0, width, height),
TRUE, C_("undo-type", "Blend"), TRUE, C_("undo-type", "Blend"),
...@@ -788,57 +787,39 @@ gradient_put_pixel (gint x, ...@@ -788,57 +787,39 @@ gradient_put_pixel (gint x,
GimpRGB *color, GimpRGB *color,
gpointer put_pixel_data) gpointer put_pixel_data)
{ {
PutPixelData *ppd = put_pixel_data; PutPixelData *ppd = put_pixel_data;
guchar *dest = ppd->row_data + ppd->bytes * x; gfloat *dest = ppd->row_data + 4 * x;
if (ppd->bytes >= 3) if (ppd->dither_rand)
{ {
if (ppd->dither_rand) gint i = g_rand_int (ppd->dither_rand);
{
gint i = g_rand_int (ppd->dither_rand);
*dest++ = color->r * 255.0 + (gdouble) (i & 0xff) / 256.0; i >>= 8; *dest++ = color->r + (gdouble) (i & 0xff) / 256.0 / 256.0; i >>= 8;
*dest++ = color->g * 255.0 + (gdouble) (i & 0xff) / 256.0; i >>= 8; *dest++ = color->g + (gdouble) (i & 0xff) / 256.0 / 256.0; i >>= 8;
*dest++ = color->b * 255.0 + (gdouble) (i & 0xff) / 256.0; i >>= 8; *dest++ = color->b + (gdouble) (i & 0xff) / 256.0 / 256.0; i >>= 8;
*dest++ = color->a * 255.0 + (gdouble) (i & 0xff) / 256.0; *dest++ = color->a + (gdouble) (i & 0xff) / 256.0 / 256.0;
}
else
{
*dest++ = ROUND (color->r * 255.0);
*dest++ = ROUND (color->g * 255.0);
*dest++ = ROUND (color->b * 255.0);
*dest++ = ROUND (color->a * 255.0);
}
} }
else else
{ {
/* Convert to grayscale */ *dest++ = color->r;
gdouble gray = gimp_rgb_luminance (color); *dest++ = color->g;
*dest++ = color->b;
if (ppd->dither_rand) *dest++ = color->a;
{
gint i = g_rand_int (ppd->dither_rand);
*dest++ = gray * 255.0 + (gdouble) (i & 0xff) / 256.0; i >>= 8;
*dest++ = color->a * 255.0 + (gdouble) (i & 0xff) / 256.0;
}
else
{
*dest++ = ROUND (gray * 255.0);
*dest++ = ROUND (color->a * 255.0);
}
} }
/* Paint whole row if we are on the rightmost pixel */ /* Paint whole row if we are on the rightmost pixel */
if (x == (ppd->width - 1)) if (x == (ppd->width - 1))
pixel_region_set_row (ppd->PR, 0, y, ppd->width, ppd->row_data); gegl_buffer_set (ppd->buffer, GEGL_RECTANGLE (0, y, ppd->width, 1),
0, babl_format ("R'G'B'A float"), ppd->row_data,
GEGL_AUTO_ROWSTRIDE);
} }
static void static void
gradient_fill_region (GimpImage *image, gradient_fill_region (GimpImage *image,
GimpDrawable *drawable, GimpDrawable *drawable,
GimpContext *context, GimpContext *context,
GeglBuffer *buffer,
PixelRegion *PR, PixelRegion *PR,
gint width, gint width,
gint height, gint height,
...@@ -962,9 +943,8 @@ gradient_fill_region (GimpImage *image, ...@@ -962,9 +943,8 @@ gradient_fill_region (GimpImage *image,
{ {
PutPixelData ppd; PutPixelData ppd;
ppd.PR = PR; ppd.buffer = buffer;
ppd.row_data = g_malloc (width * PR->bytes); ppd.row_data = g_malloc (sizeof (float) * 4 * width);
ppd.bytes = PR->bytes;
ppd.width = width; ppd.width = width;
ppd.dither_rand = g_rand_new (); ppd.dither_rand = g_rand_new ();
...@@ -1010,6 +990,8 @@ gradient_fill_region (GimpImage *image, ...@@ -1010,6 +990,8 @@ gradient_fill_region (GimpImage *image,
if (dither) if (dither)
g_rand_free (rbd.seed); g_rand_free (rbd.seed);
gimp_gegl_buffer_refetch_tiles (buffer);
} }
g_object_unref (rbd.gradient); g_object_unref (rbd.gradient);
......
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