[gimp/gimp-2-8] Bug 742821 - Grayscale-mode image malformed when exported as planar raw image data
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-2-8] Bug 742821 - Grayscale-mode image malformed when exported as planar raw image data
- Date: Wed, 4 Mar 2015 21:48:47 +0000 (UTC)
commit 39007dd2aac8186ffeb1b26639e48963f606fe9c
Author: Michael Natterer <mitch gimp org>
Date: Wed Mar 4 22:32:07 2015 +0100
Bug 742821 - Grayscale-mode image malformed when exported as planar raw image data
Fix saving of planar data by taking the actual number of components of
the drawable into account, instead of always assuming 3 (RGB).
(cherry picked from commit e1baaa0677591ac61f7c28cd653ec2b5f5ed8a05)
plug-ins/common/file-raw.c | 47 +++++++++++++++-----------------------------
1 files changed, 16 insertions(+), 31 deletions(-)
---
diff --git a/plug-ins/common/file-raw.c b/plug-ins/common/file-raw.c
index 3984ff7..c0c233a 100644
--- a/plug-ins/common/file-raw.c
+++ b/plug-ins/common/file-raw.c
@@ -573,19 +573,19 @@ save_image (const gchar *filename,
GimpPixelRgn pixel_rgn;
guchar *cmap = NULL; /* colormap for indexed images */
guchar *buf;
- guchar *red, *green, *blue, *alpha = NULL;
- gint32 width, height, bpp = 0;
- gboolean have_alpha = 0;
+ guchar *components[4] = { 0, };
+ gint n_components;
+ gint32 width, height, bpp;
FILE *fp;
- gint i, j = 0;
+ gint i, j, c;
gint palsize = 0;
GimpPDBStatusType ret = GIMP_PDB_EXECUTION_ERROR;
/* get info about the current image */
drawable = gimp_drawable_get (drawable_id);
- bpp = gimp_drawable_bpp (drawable_id);
- have_alpha = gimp_drawable_has_alpha (drawable_id);
+ bpp = gimp_drawable_bpp (drawable_id);
+ n_components = bpp;
if (gimp_drawable_is_indexed (drawable_id))
cmap = gimp_image_get_colormap (image_id, &palsize);
@@ -666,39 +666,24 @@ save_image (const gchar *filename,
break;
case RAW_PLANAR:
- red = g_new (guchar, width * height);
- green = g_new (guchar, width * height);
- blue = g_new (guchar, width * height);
- if (have_alpha)
- alpha = g_new (guchar, width * height);
+ for (c = 0; c < n_components; c++)
+ components[c] = g_new (guchar, width * height);
- for (i = 0; i < width * height * bpp; i += bpp)
+ for (i = 0, j = 0; i < width * height * bpp; i += bpp, j++)
{
- red[j] = buf[i + 0];
- green[j] = buf[i + 1];
- blue[j] = buf[i + 2];
- if (have_alpha)
- alpha[j] = buf[i + 3];
- j++;
+ for (c = 0; c < n_components; c++)
+ components[c][j] = buf[i + c];
}
ret = GIMP_PDB_SUCCESS;
- if (!fwrite (red, width * height, 1, fp))
- ret = GIMP_PDB_EXECUTION_ERROR;
- if (!fwrite (green, width * height, 1, fp))
- ret = GIMP_PDB_EXECUTION_ERROR;
- if (!fwrite (blue, width * height, 1, fp))
- ret = GIMP_PDB_EXECUTION_ERROR;
- if (have_alpha)
+ for (c = 0; c < n_components; c++)
{
- if (!fwrite (alpha, width * height, 1, fp))
+ if (! fwrite (components[c], width * height, 1, fp))
ret = GIMP_PDB_EXECUTION_ERROR;
+
+ g_free (components[c]);
}
- g_free (red);
- g_free (green);
- g_free (blue);
- if (have_alpha)
- g_free (alpha);
+
fclose (fp);
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]