[gimp] plug-ins: port file-xpm to GEGL
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] plug-ins: port file-xpm to GEGL
- Date: Mon, 26 Nov 2012 01:40:29 +0000 (UTC)
commit 9247c898522e102f0f520315f4c953f036043c37
Author: Michael Natterer <mitch gimp org>
Date: Mon Nov 26 02:39:44 2012 +0100
plug-ins: port file-xpm to GEGL
plug-ins/common/Makefile.am | 1 +
plug-ins/common/file-xpm.c | 177 ++++++++++++++++++++++------------------
plug-ins/common/plugin-defs.pl | 2 +-
3 files changed, 98 insertions(+), 82 deletions(-)
---
diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am
index c879d33..2a3d485 100644
--- a/plug-ins/common/Makefile.am
+++ b/plug-ins/common/Makefile.am
@@ -1584,6 +1584,7 @@ file_xpm_LDADD = \
$(libgimpcolor) \
$(libgimpbase) \
$(GTK_LIBS) \
+ $(GEGL_LIBS) \
$(XPM_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \
diff --git a/plug-ins/common/file-xpm.c b/plug-ins/common/file-xpm.c
index 2a8ed67..e093d1e 100644
--- a/plug-ins/common/file-xpm.c
+++ b/plug-ins/common/file-xpm.c
@@ -221,9 +221,10 @@ run (const gchar *name,
GimpExportReturn export = GIMP_EXPORT_CANCEL;
GError *error = NULL;
- run_mode = param[0].data.d_int32;
-
INIT_I18N ();
+ gegl_init (NULL, NULL);
+
+ run_mode = param[0].data.d_int32;
*nreturn_vals = 1;
*return_vals = values;
@@ -259,10 +260,10 @@ run (const gchar *name,
case GIMP_RUN_INTERACTIVE:
case GIMP_RUN_WITH_LAST_VALS:
export = gimp_export_image (&image_ID, &drawable_ID, NULL,
- (GIMP_EXPORT_CAN_HANDLE_RGB |
- GIMP_EXPORT_CAN_HANDLE_GRAY |
- GIMP_EXPORT_CAN_HANDLE_INDEXED |
- GIMP_EXPORT_CAN_HANDLE_ALPHA ));
+ GIMP_EXPORT_CAN_HANDLE_RGB |
+ GIMP_EXPORT_CAN_HANDLE_GRAY |
+ GIMP_EXPORT_CAN_HANDLE_INDEXED |
+ GIMP_EXPORT_CAN_HANDLE_ALPHA);
if (export == GIMP_EXPORT_CANCEL)
{
values[0].data.d_status = GIMP_PDB_CANCEL;
@@ -464,16 +465,15 @@ parse_image (gint32 image_ID,
XpmImage *xpm_image,
guchar *cmap)
{
- gint tile_height;
- gint scanlines;
- gint val;
- guchar *buf;
- guchar *dest;
- guint *src;
- GimpPixelRgn pixel_rgn;
- GimpDrawable *drawable;
- gint32 layer_ID;
- gint i, j;
+ GeglBuffer *buffer;
+ gint tile_height;
+ gint scanlines;
+ gint val;
+ guchar *buf;
+ guchar *dest;
+ guint *src;
+ gint32 layer_ID;
+ gint i;
layer_ID = gimp_layer_new (image_ID,
_("Color"),
@@ -485,47 +485,44 @@ parse_image (gint32 image_ID,
gimp_image_insert_layer (image_ID, layer_ID, -1, 0);
- drawable = gimp_drawable_get (layer_ID);
-
- gimp_pixel_rgn_init (&pixel_rgn, drawable,
- 0, 0,
- drawable->width, drawable->height,
- TRUE, FALSE);
+ buffer = gimp_drawable_get_buffer (layer_ID);
tile_height = gimp_tile_height ();
buf = g_new (guchar, tile_height * xpm_image->width * 4);
src = xpm_image->data;
- for (i = 0; i < xpm_image->height; i+=tile_height)
+ for (i = 0; i < xpm_image->height; i += tile_height)
{
+ gint j;
+
dest = buf;
- scanlines = MIN(tile_height, xpm_image->height - i);
+ scanlines = MIN (tile_height, xpm_image->height - i);
j = scanlines * xpm_image->width;
- while (j--) {
+ while (j--)
{
- val = *(src++) * 4;
- *(dest) = cmap[val];
- *(dest+1) = cmap[val+1];
- *(dest+2) = cmap[val+2];
- *(dest+3) = cmap[val+3];
- dest += 4;
+ {
+ val = *(src++) * 4;
+ *(dest) = cmap[val];
+ *(dest+1) = cmap[val+1];
+ *(dest+2) = cmap[val+2];
+ *(dest+3) = cmap[val+3];
+ dest += 4;
+ }
+
+ if ((j % 100) == 0)
+ gimp_progress_update ((double) i / (double) xpm_image->height);
}
- if ((j % 100) == 0)
- gimp_progress_update ((double) i / (double) xpm_image->height);
- }
-
- gimp_pixel_rgn_set_rect (&pixel_rgn, buf,
- 0, i,
- drawable->width, scanlines);
-
+ gegl_buffer_set (buffer,
+ GEGL_RECTANGLE (0, i, xpm_image->width, scanlines), 0,
+ NULL, buf, GEGL_AUTO_ROWSTRIDE);
}
- gimp_progress_update (1.0);
- g_free(buf);
+ g_free (buf);
+ g_object_unref (buffer);
- gimp_drawable_detach (drawable);
+ gimp_progress_update (1.0);
}
static guint
@@ -547,7 +544,7 @@ set_XpmImage (XpmColor *array,
gchar *colorstring)
{
gchar *p;
- gint i, charnum, indtemp;
+ gint i, charnum, indtemp;
indtemp=index;
array[index].string = p = g_new (gchar, cpp+1);
@@ -597,38 +594,56 @@ save_image (const gchar *filename,
gint32 drawable_ID,
GError **error)
{
- GimpDrawable *drawable;
- GimpPixelRgn pixel_rgn;
-
- gint width;
- gint height;
- gint ncolors = 1;
- gint *indexno;
- gboolean indexed;
- gboolean alpha;
-
- XpmColor *colormap;
- XpmImage *image;
-
- guint *ibuff = NULL;
- guchar *buffer;
- guchar *data;
-
+ GeglBuffer *buffer;
+ const Babl *format;
+ gint width;
+ gint height;
+ gint ncolors = 1;
+ gint *indexno;
+ gboolean indexed;
+ gboolean alpha;
+ XpmColor *colormap;
+ XpmImage *image;
+ guint *ibuff = NULL;
+ guchar *buf;
+ guchar *data;
GHashTable *hash = NULL;
+ gint i, j, k;
+ gint threshold = xpmvals.threshold;
+ gboolean success = FALSE;
- gint i, j, k;
- gint threshold = xpmvals.threshold;
+ buffer = gimp_drawable_get_buffer (drawable_ID);
- gboolean success = FALSE;
+ width = gegl_buffer_get_width (buffer);
+ height = gegl_buffer_get_height (buffer);
- /* get some basic stats about the image */
alpha = gimp_drawable_has_alpha (drawable_ID);
color = !gimp_drawable_is_gray (drawable_ID);
indexed = gimp_drawable_is_indexed (drawable_ID);
- drawable = gimp_drawable_get (drawable_ID);
- width = drawable->width;
- height = drawable->height;
+ switch (gimp_drawable_type (drawable_ID))
+ {
+ case GIMP_RGB_IMAGE:
+ format = babl_format ("R'G'B' u8");
+ break;
+
+ case GIMP_RGBA_IMAGE:
+ format = babl_format ("R'G'B'A u8");
+ break;
+
+ case GIMP_GRAY_IMAGE:
+ format = babl_format ("Y' u8");
+ break;
+
+ case GIMP_GRAYA_IMAGE:
+ format = babl_format ("Y'A u8");
+ break;
+
+ case GIMP_INDEXED_IMAGE:
+ case GIMP_INDEXEDA_IMAGE:
+ format = gegl_buffer_get_format (buffer);
+ break;
+ }
/* allocate buffer making the assumption that ibuff is 32 bit aligned... */
ibuff = g_new (guint, width * height);
@@ -641,22 +656,23 @@ save_image (const gchar *filename,
ncolors = alpha ? 1 : 0;
/* allocate a pixel region to work with */
- buffer = g_new (guchar, gimp_tile_height() * width * drawable->bpp);
-
- gimp_pixel_rgn_init (&pixel_rgn, drawable,
- 0, 0,
- width, height,
- TRUE, FALSE);
+ buf = g_new (guchar,
+ gimp_tile_height () * width *
+ babl_format_get_bytes_per_pixel (format));
/* process each row of tiles */
- for (i = 0; i < height; i+=gimp_tile_height())
+ for (i = 0; i < height; i += gimp_tile_height ())
{
gint scanlines;
/* read the next row of tiles */
scanlines = MIN (gimp_tile_height(), height - i);
- gimp_pixel_rgn_get_rect (&pixel_rgn, buffer, 0, i, width, scanlines);
- data = buffer;
+
+ gegl_buffer_get (buffer, GEGL_RECTANGLE (0, i, width, scanlines), 1.0,
+ format, buf,
+ GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
+
+ data = buf;
/* process each pixel row */
for (j = 0; j < scanlines; j++)
@@ -705,9 +721,8 @@ save_image (const gchar *filename,
gimp_progress_update ((gdouble) (i+j) / (gdouble) height);
}
}
- gimp_progress_update (1.0);
- g_free (buffer);
+ g_free (buf);
if (indexed)
{
@@ -785,14 +800,14 @@ save_image (const gchar *filename,
break;
}
- /* clean up resources */
- gimp_drawable_detach (drawable);
-
+ g_object_unref (buffer);
g_free (ibuff);
if (hash)
g_hash_table_destroy (hash);
+ gimp_progress_update (1.0);
+
return success;
}
diff --git a/plug-ins/common/plugin-defs.pl b/plug-ins/common/plugin-defs.pl
index 220f3f2..3468471 100644
--- a/plug-ins/common/plugin-defs.pl
+++ b/plug-ins/common/plugin-defs.pl
@@ -77,7 +77,7 @@
'file-wmf' => { ui => 1, optional => 1, libs => 'WMF_LIBS', cflags => 'WMF_CFLAGS' },
'file-xbm' => { ui => 1, gegl => 1 },
'file-xmc' => { ui => 1, optional => 1, libs => 'XMC_LIBS' },
- 'file-xpm' => { ui => 1, optional => 1, libs => 'XPM_LIBS' },
+ 'file-xpm' => { ui => 1, gegl => 1, optional => 1, libs => 'XPM_LIBS' },
'file-xwd' => { ui => 1 },
'film' => { ui => 1 },
'filter-pack' => { ui => 1 },
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]