[gimp/gimp-2-10] app: make sure image colormaps always have at least one color
- From: Ell <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-2-10] app: make sure image colormaps always have at least one color
- Date: Thu, 14 Jun 2018 07:20:23 +0000 (UTC)
commit 5e53d06f74b3ad3e807d6bfff7d9854143ca9f73
Author: Ell <ell_se yahoo com>
Date: Thu Jun 14 03:12:35 2018 -0400
app: make sure image colormaps always have at least one color
In gimp_image_set_colormap(), make sure the image's colormap always
has at least one color -- babl palette formats must have at least
one color.
If the function is called with 0 colors, use black. We still need
to support this case, in particular, since existing XCFs may have
an empty colormap, and since plug-ins can call
gimp-image-set-colormap with 0 colors.
(cherry picked from commit c16c68e63eded16ec631eed2c0290dfadfaade83)
app/core/gimpimage-colormap.c | 36 +++++++++++++++---------------------
1 file changed, 15 insertions(+), 21 deletions(-)
---
diff --git a/app/core/gimpimage-colormap.c b/app/core/gimpimage-colormap.c
index 7a4b1478a0..615e0465d6 100644
--- a/app/core/gimpimage-colormap.c
+++ b/app/core/gimpimage-colormap.c
@@ -182,6 +182,8 @@ gimp_image_set_colormap (GimpImage *image,
gboolean push_undo)
{
GimpImagePrivate *private;
+ GimpPaletteEntry *entry;
+ gint i;
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (colormap != NULL || n_colors == 0);
@@ -194,34 +196,26 @@ gimp_image_set_colormap (GimpImage *image,
if (private->colormap)
memset (private->colormap, 0, GIMP_IMAGE_COLORMAP_SIZE);
+ else
+ gimp_image_colormap_init (image);
if (colormap)
- {
- if (! private->colormap)
- {
- gimp_image_colormap_init (image);
- }
-
- memcpy (private->colormap, colormap, n_colors * 3);
- }
-
- private->n_colors = n_colors;
+ memcpy (private->colormap, colormap, n_colors * 3);
- if (private->palette)
- {
- GimpPaletteEntry *entry;
- gint i;
+ /* make sure the image's colormap always has at least one color. when
+ * n_colors == 0, use black.
+ */
+ private->n_colors = MAX (n_colors, 1);
- gimp_data_freeze (GIMP_DATA (private->palette));
+ gimp_data_freeze (GIMP_DATA (private->palette));
- while ((entry = gimp_palette_get_entry (private->palette, 0)))
- gimp_palette_delete_entry (private->palette, entry);
+ while ((entry = gimp_palette_get_entry (private->palette, 0)))
+ gimp_palette_delete_entry (private->palette, entry);
- for (i = 0; i < private->n_colors; i++)
- gimp_image_colormap_set_palette_entry (image, i);
+ for (i = 0; i < private->n_colors; i++)
+ gimp_image_colormap_set_palette_entry (image, i);
- gimp_data_thaw (GIMP_DATA (private->palette));
- }
+ gimp_data_thaw (GIMP_DATA (private->palette));
gimp_image_colormap_changed (image, -1);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]