[gimp/goat-invasion: 68/526] app: replace some color_region() and pattern_region() by GEGL code
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/goat-invasion: 68/526] app: replace some color_region() and pattern_region() by GEGL code
- Date: Sun, 22 Apr 2012 13:04:59 +0000 (UTC)
commit f53a22a6302940bdb371d24f7470f29e7945c3dc
Author: Michael Natterer <mitch gimp org>
Date: Fri Mar 16 02:21:26 2012 +0100
app: replace some color_region() and pattern_region() by GEGL code
app/core/gimp-edit.c | 30 +++++++++++++-
app/core/gimpdrawable.c | 77 ++++++++++++++++++++++----------------
app/core/gimpimage-merge.c | 22 ++++++----
app/widgets/gimptemplateeditor.c | 2 +-
4 files changed, 86 insertions(+), 45 deletions(-)
---
diff --git a/app/core/gimp-edit.c b/app/core/gimp-edit.c
index 80e8fae..68a5bd9 100644
--- a/app/core/gimp-edit.c
+++ b/app/core/gimp-edit.c
@@ -544,6 +544,7 @@ gimp_edit_fill_internal (GimpImage *image,
const gchar *undo_desc)
{
TileManager *buf_tiles;
+ GeglBuffer *dest_buffer;
PixelRegion bufPR;
gint x, y, width, height;
GimpImageType drawable_type;
@@ -597,23 +598,46 @@ gimp_edit_fill_internal (GimpImage *image,
buf_tiles = tile_manager_new (width, height, tiles_bytes);
- pixel_region_init (&bufPR, buf_tiles, 0, 0, width, height, TRUE);
+ dest_buffer = gimp_tile_manager_create_buffer (buf_tiles, TRUE);
if (pat_buf)
{
- pattern_region (&bufPR, NULL, pat_buf, 0, 0);
+ GeglBuffer *src_buffer;
+ GeglRectangle rect = { 0, };
+
+ rect.width = pat_buf->width;
+ rect.height = pat_buf->height;
+
+ src_buffer = gegl_buffer_linear_new_from_data (temp_buf_get_data (pat_buf),
+ gimp_bpp_to_babl_format (tiles_bytes, TRUE),
+ &rect,
+ rect.width * pat_buf->bytes,
+ NULL, NULL);
+
+ gegl_buffer_set_pattern (dest_buffer, NULL, src_buffer, 0, 0);
+
+ g_object_unref (src_buffer);
if (new_buf)
temp_buf_free (pat_buf);
}
else
{
+ GeglColor *color;
+
if (gimp_drawable_has_alpha (drawable))
col[gimp_drawable_bytes (drawable) - 1] = OPAQUE_OPACITY;
- color_region (&bufPR, col);
+ color = gegl_color_new (NULL);
+ gegl_color_set_pixel (color, gimp_drawable_get_babl_format (drawable), col);
+
+ gegl_buffer_set_color (dest_buffer, NULL, color);
+
+ g_object_unref (color);
}
+ g_object_unref (dest_buffer);
+
pixel_region_init (&bufPR, buf_tiles, 0, 0, width, height, FALSE);
gimp_drawable_apply_region (drawable, &bufPR,
TRUE, undo_desc,
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index 3c91194..b8221be 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -542,7 +542,7 @@ gimp_drawable_resize (GimpItem *item,
gint offset_y)
{
GimpDrawable *drawable = GIMP_DRAWABLE (item);
- PixelRegion destPR;
+ GeglBuffer *dest_buffer;
TileManager *new_tiles;
gint new_offset_x;
gint new_offset_y;
@@ -575,33 +575,35 @@ gimp_drawable_resize (GimpItem *item,
new_tiles = tile_manager_new (new_width, new_height,
gimp_drawable_bytes (drawable));
- /* Determine whether the new tiles need to be initially cleared */
+ dest_buffer = gimp_tile_manager_create_buffer (new_tiles, TRUE);
+
if (copy_width != new_width ||
copy_height != new_height)
{
- guchar bg[MAX_CHANNELS] = { 0, };
+ /* Clear the new tiles if needed */
- pixel_region_init (&destPR, new_tiles,
- 0, 0,
- new_width, new_height,
- TRUE);
+ GeglColor *col;
+ guchar bg[MAX_CHANNELS] = { 0, };
if (! gimp_drawable_has_alpha (drawable) && ! GIMP_IS_CHANNEL (drawable))
gimp_image_get_background (gimp_item_get_image (item), context,
gimp_drawable_type (drawable), bg);
- color_region (&destPR, bg);
+ col = gegl_color_new (NULL);
+ gegl_color_set_pixel (col, gimp_drawable_get_babl_format (drawable), bg);
+
+ gegl_buffer_set_color (dest_buffer, NULL, col);
+
+ g_object_unref (col);
}
- /* Determine whether anything needs to be copied */
if (copy_width && copy_height)
{
- GeglBuffer *dest_buffer;
+ /* Copy the pixels in the intersection */
+
GeglRectangle src_rect;
GeglRectangle dest_rect;
- dest_buffer = gimp_tile_manager_create_buffer (new_tiles, TRUE);
-
src_rect.x = copy_x - gimp_item_get_offset_x (item);
src_rect.y = copy_y - gimp_item_get_offset_y (item);
src_rect.width = copy_width;
@@ -613,9 +615,10 @@ gimp_drawable_resize (GimpItem *item,
gegl_buffer_copy (gimp_drawable_get_read_buffer (drawable), &src_rect,
dest_buffer, &dest_rect);
- g_object_unref (dest_buffer);
}
+ g_object_unref (dest_buffer);
+
gimp_drawable_set_tiles_full (drawable, gimp_item_is_attached (item), NULL,
new_tiles, gimp_drawable_type (drawable),
new_offset_x, new_offset_y);
@@ -1714,7 +1717,6 @@ gimp_drawable_fill (GimpDrawable *drawable,
GimpItem *item;
GimpImage *image;
GimpImageType drawable_type;
- PixelRegion destPR;
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
g_return_if_fail (color != NULL || pattern != NULL);
@@ -1725,39 +1727,50 @@ gimp_drawable_fill (GimpDrawable *drawable,
drawable_type = gimp_drawable_type (drawable);
- pixel_region_init (&destPR, gimp_drawable_get_tiles (drawable),
- 0, 0, gimp_item_get_width (item), gimp_item_get_height (item),
- TRUE);
-
if (color)
{
- guchar tmp[MAX_CHANNELS];
- guchar c[MAX_CHANNELS];
+ GeglColor *col;
+ guchar c[MAX_CHANNELS];
- gimp_rgba_get_uchar (color,
- &tmp[RED],
- &tmp[GREEN],
- &tmp[BLUE],
- &tmp[ALPHA]);
-
- gimp_image_transform_color (image, drawable_type, c, GIMP_RGB, tmp);
+ gimp_image_transform_rgb (image, drawable_type, color, c);
if (GIMP_IMAGE_TYPE_HAS_ALPHA (drawable_type))
- c[GIMP_IMAGE_TYPE_BYTES (drawable_type) - 1] = tmp[ALPHA];
+ gimp_rgba_get_uchar (color, NULL, NULL, NULL,
+ c + GIMP_IMAGE_TYPE_BYTES (drawable_type) - 1);
else
c[GIMP_IMAGE_TYPE_BYTES (drawable_type)] = OPAQUE_OPACITY;
- color_region (&destPR, c);
+ col = gegl_color_new (NULL);
+ gegl_color_set_pixel (col, gimp_drawable_get_babl_format (drawable), c);
+
+ gegl_buffer_set_color (gimp_drawable_get_write_buffer (drawable),
+ NULL, col);
+
+ g_object_unref (col);
}
else
{
- TempBuf *pat_buf;
- gboolean new_buf;
+ GeglBuffer *src_buffer;
+ GeglRectangle rect = { 0, };
+ TempBuf *pat_buf;
+ gboolean new_buf;
pat_buf = gimp_image_transform_temp_buf (image, drawable_type,
pattern->mask, &new_buf);
- pattern_region (&destPR, NULL, pat_buf, 0, 0);
+ rect.width = pat_buf->width;
+ rect.height = pat_buf->height;
+
+ src_buffer = gegl_buffer_linear_new_from_data (temp_buf_get_data (pat_buf),
+ gimp_bpp_to_babl_format (pat_buf->bytes, TRUE),
+ &rect,
+ rect.width * pat_buf->bytes,
+ NULL, NULL);
+
+ gegl_buffer_set_pattern (gimp_drawable_get_write_buffer (drawable),
+ NULL, src_buffer, 0, 0);
+
+ g_object_unref (src_buffer);
if (new_buf)
temp_buf_free (pat_buf);
diff --git a/app/core/gimpimage-merge.c b/app/core/gimpimage-merge.c
index 9acc356..23453fc 100644
--- a/app/core/gimpimage-merge.c
+++ b/app/core/gimpimage-merge.c
@@ -521,8 +521,10 @@ gimp_image_merge_layers (GimpImage *image,
if (merge_type == GIMP_FLATTEN_IMAGE ||
gimp_drawable_type (GIMP_DRAWABLE (layer)) == GIMP_INDEXED_IMAGE)
{
- GimpImageType type;
- guchar bg[4] = { 0, 0, 0, 0 };
+ GeglColor *color;
+ GeglRectangle rect = { 0, };
+ GimpImageType type;
+ guchar bg[4] = { 0, 0, 0, 0 };
type = GIMP_IMAGE_TYPE_FROM_BASE_TYPE (gimp_image_base_type (image));
@@ -543,14 +545,16 @@ gimp_image_merge_layers (GimpImage *image,
gimp_drawable_type (GIMP_DRAWABLE (merge_layer)),
bg);
- /* init the pixel region */
- pixel_region_init (&src1PR,
- gimp_drawable_get_tiles (GIMP_DRAWABLE (merge_layer)),
- 0, 0, (x2 - x1), (y2 - y1),
- TRUE);
+ rect.width = x2 - x1;
+ rect.height = y2 - y1;
+
+ color = gegl_color_new (NULL);
+ gegl_color_set_pixel (color, gimp_drawable_get_babl_format (GIMP_DRAWABLE (merge_layer)), bg);
+
+ gegl_buffer_set_color (gimp_drawable_get_write_buffer (GIMP_DRAWABLE (merge_layer)),
+ &rect, color);
- /* set the region to the background color */
- color_region (&src1PR, bg);
+ g_object_unref (color);
position = 0;
}
diff --git a/app/widgets/gimptemplateeditor.c b/app/widgets/gimptemplateeditor.c
index 6c6dfbd..53166c0 100644
--- a/app/widgets/gimptemplateeditor.c
+++ b/app/widgets/gimptemplateeditor.c
@@ -390,7 +390,7 @@ gimp_template_editor_constructed (GObject *object)
combo = gimp_prop_enum_combo_box_new (G_OBJECT (template),
"fill-type",
GIMP_FOREGROUND_FILL,
- GIMP_TRANSPARENT_FILL);
+ GIMP_PATTERN_FILL);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 3,
_("_Fill with:"), 0.0, 0.5,
combo, 1, FALSE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]