[gimp] plug-ins: port print to GEGL
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] plug-ins: port print to GEGL
- Date: Fri, 21 Sep 2012 21:33:59 +0000 (UTC)
commit cc817670ed24de96a0fd7caa78fd5faa86be6c0b
Author: Michael Natterer <mitch gimp org>
Date: Fri Sep 21 23:33:01 2012 +0200
plug-ins: port print to GEGL
plug-ins/print/Makefile.am | 1 +
plug-ins/print/print-draw-page.c | 189 ++++++--------------------------------
plug-ins/print/print-preview.c | 28 ++----
plug-ins/print/print.c | 2 +
4 files changed, 44 insertions(+), 176 deletions(-)
---
diff --git a/plug-ins/print/Makefile.am b/plug-ins/print/Makefile.am
index ea2ea28..23b748a 100644
--- a/plug-ins/print/Makefile.am
+++ b/plug-ins/print/Makefile.am
@@ -34,6 +34,7 @@ LDADD = \
$(libgimpmath) \
$(libgimpbase) \
$(GTK_LIBS) \
+ $(GEGL_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \
$(print_RC)
diff --git a/plug-ins/print/print-draw-page.c b/plug-ins/print/print-draw-page.c
index 14de652..cc46507 100644
--- a/plug-ins/print/print-draw-page.c
+++ b/plug-ins/print/print-draw-page.c
@@ -71,129 +71,24 @@ print_draw_page (GtkPrintContext *context,
return TRUE;
}
-
-static inline void
-convert_from_rgb (const guchar *src,
- guchar *dest,
- gint pixels)
-{
- while (pixels--)
- {
- GIMP_CAIRO_RGB24_SET_PIXEL (dest,
- src[0], src[1], src[2]);
-
- src += 3;
- dest += 4;
- }
-}
-
-static inline void
-convert_from_rgba (const guchar *src,
- guchar *dest,
- gint pixels)
-{
- while (pixels--)
- {
- GIMP_CAIRO_ARGB32_SET_PIXEL (dest,
- src[0], src[1], src[2], src[3]);
-
- src += 4;
- dest += 4;
- }
-}
-
-static inline void
-convert_from_gray (const guchar *src,
- guchar *dest,
- gint pixels)
-{
- while (pixels--)
- {
- GIMP_CAIRO_RGB24_SET_PIXEL (dest,
- src[0], src[0], src[0]);
-
- src += 1;
- dest += 4;
- }
-}
-
-static inline void
-convert_from_graya (const guchar *src,
- guchar *dest,
- gint pixels)
-{
- while (pixels--)
- {
- GIMP_CAIRO_ARGB32_SET_PIXEL (dest,
- src[0], src[0], src[0], src[1]);
-
- src += 2;
- dest += 4;
- }
-}
-
-static inline void
-convert_from_indexed (const guchar *src,
- guchar *dest,
- gint pixels,
- const guchar *cmap)
-{
- while (pixels--)
- {
- const gint i = 3 * src[0];
-
- GIMP_CAIRO_RGB24_SET_PIXEL (dest,
- cmap[i], cmap[i + 1], cmap[i + 2]);
-
- src += 1;
- dest += 4;
- }
-}
-
-static inline void
-convert_from_indexeda (const guchar *src,
- guchar *dest,
- gint pixels,
- const guchar *cmap)
-{
- while (pixels--)
- {
- const gint i = 3 * src[0];
-
- GIMP_CAIRO_ARGB32_SET_PIXEL (dest,
- cmap[i], cmap[i + 1], cmap[i + 2], src[1]);
-
- src += 2;
- dest += 4;
- }
-}
-
static cairo_surface_t *
print_surface_from_drawable (gint32 drawable_ID)
{
- GimpDrawable *drawable = gimp_drawable_get (drawable_ID);
- GimpPixelRgn region;
- GimpImageType image_type = gimp_drawable_type (drawable_ID);
- cairo_surface_t *surface;
- const gint width = drawable->width;
- const gint height = drawable->height;
- guchar cmap[3 * 256] = { 0, };
- guchar *pixels;
- gint stride;
- guint count = 0;
- guint done = 0;
- gpointer pr;
-
- if (gimp_drawable_is_indexed (drawable_ID))
- {
- guchar *colors;
- gint num_colors;
-
- colors = gimp_image_get_colormap (gimp_item_get_image (drawable_ID),
- &num_colors);
- memcpy (cmap, colors, 3 * num_colors);
- g_free (colors);
- }
+ GeglBuffer *buffer = gimp_drawable_get_buffer (drawable_ID);
+ const Babl *format;
+ cairo_surface_t *surface;
+ const gint width = gimp_drawable_width (drawable_ID);
+ const gint height = gimp_drawable_height (drawable_ID);
+ GeglBufferIterator *iter;
+ guchar *pixels;
+ gint stride;
+ guint count = 0;
+ guint done = 0;
+
+ if (gimp_drawable_has_alpha (drawable_ID))
+ format = babl_format ("cairo-ARGB32");
+ else
+ format = babl_format ("cairo-RGB24");
surface = cairo_image_surface_create (gimp_drawable_has_alpha (drawable_ID) ?
CAIRO_FORMAT_ARGB32 :
@@ -203,61 +98,37 @@ print_surface_from_drawable (gint32 drawable_ID)
pixels = cairo_image_surface_get_data (surface);
stride = cairo_image_surface_get_stride (surface);
- gimp_pixel_rgn_init (®ion, drawable, 0, 0, width, height, FALSE, FALSE);
+ iter = gegl_buffer_iterator_new (buffer,
+ GEGL_RECTANGLE (0, 0, width, height), 0,
+ format,
+ GEGL_BUFFER_READ, GEGL_ABYSS_NONE);
- for (pr = gimp_pixel_rgns_register (1, ®ion);
- pr != NULL;
- pr = gimp_pixel_rgns_process (pr))
+ while (gegl_buffer_iterator_next (iter))
{
- const guchar *src = region.data;
- guchar *dest = pixels + region.y * stride + region.x * 4;
+ const guchar *src = iter->data[0];
+ guchar *dest = pixels + iter->roi->y * stride + iter->roi->x * 4;
gint y;
- for (y = 0; y < region.h; y++)
+ for (y = 0; y < iter->roi->height; y++)
{
- switch (image_type)
- {
- case GIMP_RGB_IMAGE:
- convert_from_rgb (src, dest, region.w);
- break;
-
- case GIMP_RGBA_IMAGE:
- convert_from_rgba (src, dest, region.w);
- break;
-
- case GIMP_GRAY_IMAGE:
- convert_from_gray (src, dest, region.w);
- break;
-
- case GIMP_GRAYA_IMAGE:
- convert_from_graya (src, dest, region.w);
- break;
-
- case GIMP_INDEXED_IMAGE:
- convert_from_indexed (src, dest, region.w, cmap);
- break;
-
- case GIMP_INDEXEDA_IMAGE:
- convert_from_indexeda (src, dest, region.w, cmap);
- break;
- }
-
- src += region.rowstride;
+ memcpy (dest, src, iter->roi->width * 4);
+
+ src += iter->roi->width * 4;
dest += stride;
}
- done += region.h * region.w;
+ done += iter->roi->height * iter->roi->width;
if (count++ % 16 == 0)
gimp_progress_update ((gdouble) done / (width * height));
}
- gimp_progress_update (1.0);
-
- gimp_drawable_detach (drawable);
+ g_object_unref (buffer);
cairo_surface_mark_dirty (surface);
+ gimp_progress_update (1.0);
+
return surface;
}
diff --git a/plug-ins/print/print-preview.c b/plug-ins/print/print-preview.c
index d538483..3e58f55 100644
--- a/plug-ins/print/print-preview.c
+++ b/plug-ins/print/print-preview.c
@@ -44,7 +44,7 @@ struct _PrintPreview
gboolean dragging;
gboolean inside;
- GimpDrawable *drawable;
+ gint32 drawable_id;
gdouble image_offset_x;
gdouble image_offset_y;
@@ -107,7 +107,7 @@ static void print_preview_get_page_margins (PrintPreview *preview,
gdouble *right_margin,
gdouble *top_margin,
gdouble *bottom_margin);
-static cairo_surface_t * print_preview_get_thumbnail (GimpDrawable *drawable,
+static cairo_surface_t * print_preview_get_thumbnail (gint32 drawable_id,
gint width,
gint height);
@@ -208,12 +208,6 @@ print_preview_finalize (GObject *object)
{
PrintPreview *preview = PRINT_PREVIEW (object);
- if (preview->drawable)
- {
- gimp_drawable_detach (preview->drawable);
- preview->drawable = NULL;
- }
-
if (preview->thumbnail)
{
cairo_surface_destroy (preview->thumbnail);
@@ -481,10 +475,10 @@ print_preview_expose_event (GtkWidget *widget,
}
if (preview->thumbnail == NULL &&
- gimp_item_is_valid (preview->drawable->drawable_id))
+ gimp_item_is_valid (preview->drawable_id))
{
preview->thumbnail =
- print_preview_get_thumbnail (preview->drawable,
+ print_preview_get_thumbnail (preview->drawable_id,
MIN (allocation.width, 1024),
MIN (allocation.height, 1024));
}
@@ -531,7 +525,7 @@ print_preview_new (GtkPageSetup *page,
preview = g_object_new (PRINT_TYPE_PREVIEW, NULL);
- preview->drawable = gimp_drawable_get (drawable_id);
+ preview->drawable_id = drawable_id;
print_preview_set_page_setup (preview, page);
@@ -558,8 +552,8 @@ print_preview_set_image_dpi (PrintPreview *preview,
g_return_if_fail (PRINT_IS_PREVIEW (preview));
g_return_if_fail (xres > 0.0 && yres > 0.0);
- width = preview->drawable->width * 72.0 / xres;
- height = preview->drawable->height * 72.0 / yres;
+ width = gimp_drawable_width (preview->drawable_id) * 72.0 / xres;
+ height = gimp_drawable_height (preview->drawable_id) * 72.0 / yres;
if (width != preview->image_width || height != preview->image_height)
{
@@ -784,9 +778,9 @@ print_preview_get_page_margins (PrintPreview *preview,
/* This thumbnail code should eventually end up in libgimpui. */
static cairo_surface_t *
-print_preview_get_thumbnail (GimpDrawable *drawable,
- gint width,
- gint height)
+print_preview_get_thumbnail (gint32 drawable_id,
+ gint width,
+ gint height)
{
cairo_surface_t *surface;
cairo_format_t format;
@@ -801,7 +795,7 @@ print_preview_get_thumbnail (GimpDrawable *drawable,
g_return_val_if_fail (width > 0 && width <= 1024, NULL);
g_return_val_if_fail (height > 0 && height <= 1024, NULL);
- data = gimp_drawable_get_thumbnail_data (drawable->drawable_id,
+ data = gimp_drawable_get_thumbnail_data (drawable_id,
&width, &height, &bpp);
switch (bpp)
diff --git a/plug-ins/print/print.c b/plug-ins/print/print.c
index 9553b73..6d12942 100644
--- a/plug-ins/print/print.c
+++ b/plug-ins/print/print.c
@@ -156,6 +156,8 @@ run (const gchar *name,
INIT_I18N ();
+ gegl_init (NULL, NULL);
+
*nreturn_vals = 1;
*return_vals = values;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]