[gimp/metadata-browser] libgimp: add GEGL branch to gimp_layer_new_from_surface()
- From: Roman Joost <romanofski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/metadata-browser] libgimp: add GEGL branch to gimp_layer_new_from_surface()
- Date: Thu, 13 Sep 2012 00:04:08 +0000 (UTC)
commit 7b6fce59d35b2a789d4f73c8b3e90ccc7fd5493e
Author: Michael Natterer <mitch gimp org>
Date: Thu May 3 04:13:39 2012 +0200
libgimp: add GEGL branch to gimp_layer_new_from_surface()
libgimp/gimplayer.c | 148 ++++++++++++++++++++++++++++----------------------
1 files changed, 83 insertions(+), 65 deletions(-)
---
diff --git a/libgimp/gimplayer.c b/libgimp/gimplayer.c
index 32b26af..43c9b8f 100644
--- a/libgimp/gimplayer.c
+++ b/libgimp/gimplayer.c
@@ -22,8 +22,9 @@
#include <string.h>
+#define GIMP_DISABLE_DEPRECATION_WARNINGS
+
#include "gimp.h"
-#include "gimplayer.h"
/**
@@ -243,18 +244,11 @@ gimp_layer_new_from_surface (gint32 image_ID,
gdouble progress_start,
gdouble progress_end)
{
- GimpDrawable *drawable;
- GimpPixelRgn rgn;
- const guchar *pixels;
- gpointer pr;
- gint32 layer;
- cairo_format_t format;
- gint width;
- gint height;
- gint rowstride;
- gdouble range = progress_end - progress_start;
- guint count = 0;
- guint done = 0;
+ gint32 layer;
+ gint width;
+ gint height;
+ cairo_format_t format;
+ gdouble range = progress_end - progress_start;
g_return_val_if_fail (surface != NULL, -1);
g_return_val_if_fail (cairo_surface_get_type (surface) ==
@@ -285,82 +279,106 @@ gimp_layer_new_from_surface (gint32 image_ID,
if (layer == -1)
return -1;
- drawable = gimp_drawable_get (layer);
+ if (gimp_plugin_precision_enabled ())
+ {
+ GeglBuffer *src_buffer;
+ GeglBuffer *dest_buffer;
- gimp_pixel_rgn_init (&rgn, drawable, 0, 0, width, height, TRUE, FALSE);
+ src_buffer = gimp_cairo_surface_create_buffer (surface);
+ dest_buffer = gimp_drawable_get_buffer (layer);
- rowstride = cairo_image_surface_get_stride (surface);
- pixels = cairo_image_surface_get_data (surface);
+ gegl_buffer_copy (src_buffer, NULL, dest_buffer, NULL);
- for (pr = gimp_pixel_rgns_register (1, &rgn);
- pr != NULL;
- pr = gimp_pixel_rgns_process (pr))
+ g_object_unref (src_buffer);
+ g_object_unref (dest_buffer);
+ }
+ else
{
- const guchar *src = pixels + rgn.y * rowstride + rgn.x * 4;
- guchar *dest = rgn.data;
- gint y;
+ GimpDrawable *drawable;
+ GimpPixelRgn rgn;
+ const guchar *pixels;
+ gpointer pr;
+ gint rowstride;
+ guint count = 0;
+ guint done = 0;
+
+ drawable = gimp_drawable_get (layer);
- switch (format)
+ gimp_pixel_rgn_init (&rgn, drawable, 0, 0, width, height, TRUE, FALSE);
+
+ rowstride = cairo_image_surface_get_stride (surface);
+ pixels = cairo_image_surface_get_data (surface);
+
+ for (pr = gimp_pixel_rgns_register (1, &rgn);
+ pr != NULL;
+ pr = gimp_pixel_rgns_process (pr))
{
- case CAIRO_FORMAT_RGB24:
- for (y = 0; y < rgn.h; y++)
- {
- const guchar *s = src;
- guchar *d = dest;
- gint w = rgn.w;
+ const guchar *src = pixels + rgn.y * rowstride + rgn.x * 4;
+ guchar *dest = rgn.data;
+ gint y;
- while (w--)
+ switch (format)
+ {
+ case CAIRO_FORMAT_RGB24:
+ for (y = 0; y < rgn.h; y++)
{
- GIMP_CAIRO_RGB24_GET_PIXEL (s, d[0], d[1], d[2]);
+ const guchar *s = src;
+ guchar *d = dest;
+ gint w = rgn.w;
- s += 4;
- d += 3;
- }
+ while (w--)
+ {
+ GIMP_CAIRO_RGB24_GET_PIXEL (s, d[0], d[1], d[2]);
- src += rowstride;
- dest += rgn.rowstride;
- }
- break;
+ s += 4;
+ d += 3;
+ }
- case CAIRO_FORMAT_ARGB32:
- for (y = 0; y < rgn.h; y++)
- {
- const guchar *s = src;
- guchar *d = dest;
- gint w = rgn.w;
+ src += rowstride;
+ dest += rgn.rowstride;
+ }
+ break;
- while (w--)
+ case CAIRO_FORMAT_ARGB32:
+ for (y = 0; y < rgn.h; y++)
{
- GIMP_CAIRO_ARGB32_GET_PIXEL (s, d[0], d[1], d[2], d[3]);
+ const guchar *s = src;
+ guchar *d = dest;
+ gint w = rgn.w;
- s += 4;
- d += 4;
+ while (w--)
+ {
+ GIMP_CAIRO_ARGB32_GET_PIXEL (s, d[0], d[1], d[2], d[3]);
+
+ s += 4;
+ d += 4;
+ }
+
+ src += rowstride;
+ dest += rgn.rowstride;
}
+ break;
- src += rowstride;
- dest += rgn.rowstride;
+ default:
+ break;
}
- break;
-
- default:
- break;
- }
- if (range > 0.0)
- {
- done += rgn.h * rgn.w;
+ if (range > 0.0)
+ {
+ done += rgn.h * rgn.w;
- if (count++ % 32 == 0)
- gimp_progress_update (progress_start +
- (gdouble) done / (width * height) * range);
+ if (count++ % 32 == 0)
+ gimp_progress_update (progress_start +
+ (gdouble) done / (width * height) * range);
+ }
}
- }
+
+ gimp_drawable_detach (drawable);
+ }
if (range > 0.0)
gimp_progress_update (progress_end);
- gimp_drawable_detach (drawable);
-
return layer;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]