diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c index 6d9af71813..ae4d5dd305 100644 --- a/app/core/gimpdrawable.c +++ b/app/core/gimpdrawable.c @@ -1867,7 +1867,7 @@ gimp_drawable_get_component_index (GimpDrawable *drawable, return -1; } -const guchar * +guchar * gimp_drawable_get_colormap (GimpDrawable *drawable) { GimpImage *image; diff --git a/app/core/gimpdrawable.h b/app/core/gimpdrawable.h index eb8000241a..a80f1dcfbc 100644 --- a/app/core/gimpdrawable.h +++ b/app/core/gimpdrawable.h @@ -224,7 +224,7 @@ const Babl * gimp_drawable_get_component_format (GimpDrawable *drawable, gint gimp_drawable_get_component_index (GimpDrawable *drawable, GimpChannelType channel); -const guchar * gimp_drawable_get_colormap (GimpDrawable *drawable); +guchar * gimp_drawable_get_colormap (GimpDrawable *drawable); void gimp_drawable_start_paint (GimpDrawable *drawable); gboolean gimp_drawable_end_paint (GimpDrawable *drawable); diff --git a/app/core/gimpimage-color-profile.c b/app/core/gimpimage-color-profile.c index a8dff7c922..f3e5c8dfdd 100644 --- a/app/core/gimpimage-color-profile.c +++ b/app/core/gimpimage-color-profile.c @@ -909,7 +909,7 @@ gimp_image_convert_profile_colormap (GimpImage *image, gint n_colors; n_colors = gimp_image_get_colormap_size (image); - cmap = g_memdup2 (gimp_image_get_colormap (image), n_colors * 3); + cmap = gimp_image_get_colormap (image); if (bpc) flags |= GIMP_COLOR_TRANSFORM_FLAGS_BLACK_POINT_COMPENSATION; diff --git a/app/core/gimpimage-colormap.c b/app/core/gimpimage-colormap.c index 2647e37aea..b880b6b552 100644 --- a/app/core/gimpimage-colormap.c +++ b/app/core/gimpimage-colormap.c @@ -62,7 +62,6 @@ gimp_image_colormap_init (GimpImage *image) private = GIMP_IMAGE_GET_PRIVATE (image); - g_return_if_fail (private->colormap == NULL); g_return_if_fail (private->palette == NULL); palette_name = g_strdup_printf (_("Colormap of Image #%d (%s)"), @@ -71,8 +70,6 @@ gimp_image_colormap_init (GimpImage *image) palette_id = g_strdup_printf ("gimp-indexed-image-palette-%d", gimp_image_get_id (image)); - private->n_colors = 0; - private->colormap = g_new0 (guchar, GIMP_IMAGE_COLORMAP_SIZE); private->palette = GIMP_PALETTE (gimp_palette_new (NULL, palette_name)); gimp_image_colormap_update_formats (image); @@ -99,7 +96,6 @@ gimp_image_colormap_dispose (GimpImage *image) private = GIMP_IMAGE_GET_PRIVATE (image); - g_return_if_fail (private->colormap != NULL); g_return_if_fail (GIMP_IS_PALETTE (private->palette)); palettes = gimp_data_factory_get_container (image->gimp->palette_factory); @@ -116,10 +112,8 @@ gimp_image_colormap_free (GimpImage *image) private = GIMP_IMAGE_GET_PRIVATE (image); - g_return_if_fail (private->colormap != NULL); g_return_if_fail (GIMP_IS_PALETTE (private->palette)); - g_clear_pointer (&private->colormap, g_free); g_clear_object (&private->palette); /* don't touch the image's babl_palettes because we might still have @@ -150,20 +144,28 @@ gimp_image_colormap_update_formats (GimpImage *image) g_free (format_name); - if (private->colormap && private->n_colors > 0) + if (private->palette) { + guchar *colormap; + gint n_colors; + + colormap = gimp_image_get_colormap (image); + n_colors = gimp_image_get_colormap_size (image); + babl_palette_set_palette (private->babl_palette_rgb, gimp_babl_format (GIMP_RGB, private->precision, FALSE, space), - private->colormap, - private->n_colors); + colormap, + n_colors); babl_palette_set_palette (private->babl_palette_rgba, gimp_babl_format (GIMP_RGB, private->precision, FALSE, space), - private->colormap, - private->n_colors); + colormap, + n_colors); + + g_free (colormap); } } @@ -191,20 +193,84 @@ gimp_image_get_colormap_palette (GimpImage *image) return GIMP_IMAGE_GET_PRIVATE (image)->palette; } -const guchar * +void +gimp_image_set_colormap_palette (GimpImage *image, + GimpPalette *palette, + gboolean push_undo) +{ + GimpImagePrivate *private; + GimpPaletteEntry *entry; + gint n_colors, i; + + g_return_if_fail (GIMP_IS_IMAGE (image)); + g_return_if_fail (palette != NULL); + n_colors = gimp_palette_get_n_colors (palette); + g_return_if_fail (n_colors >= 0 && n_colors <= 256); + + private = GIMP_IMAGE_GET_PRIVATE (image); + + if (push_undo) + gimp_image_undo_push_image_colormap (image, C_("undo-type", "Set Colormap")); + + if (!private->palette) + gimp_image_colormap_init (image); + + gimp_data_freeze (GIMP_DATA (private->palette)); + + while ((entry = gimp_palette_get_entry (private->palette, 0))) + gimp_palette_delete_entry (private->palette, entry); + + for (i = 0; i < n_colors; i++) + { + GimpPaletteEntry *entry = gimp_palette_get_entry (palette, i); + gimp_image_colormap_set_palette_entry (image, &entry->color, i); + } + + gimp_data_thaw (GIMP_DATA (private->palette)); + + gimp_image_colormap_changed (image, -1); +} + +guchar * gimp_image_get_colormap (GimpImage *image) { - g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); + GimpImagePrivate *private; + guchar *colormap; + gint n_colors, i; - return GIMP_IMAGE_GET_PRIVATE (image)->colormap; + g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); + private = GIMP_IMAGE_GET_PRIVATE (image); + + if (private->palette == NULL) + return NULL; + + n_colors = gimp_palette_get_n_colors (private->palette); + colormap = g_new0 (guchar, GIMP_IMAGE_COLORMAP_SIZE); + + for (i = 0; i < n_colors; i++) + { + GimpPaletteEntry *entry = gimp_palette_get_entry (private->palette, i); + gimp_rgb_get_uchar (&entry->color, + &colormap[i * 3], + &colormap[i * 3 + 1], + &colormap[i * 3 + 2]); + } + + return colormap; } gint gimp_image_get_colormap_size (GimpImage *image) { - g_return_val_if_fail (GIMP_IS_IMAGE (image), 0); + GimpImagePrivate *private; - return GIMP_IMAGE_GET_PRIVATE (image)->n_colors; + g_return_val_if_fail (GIMP_IS_IMAGE (image), 0); + private = GIMP_IMAGE_GET_PRIVATE (image); + + if (private->palette == NULL) + return 0; + + return gimp_palette_get_n_colors (private->palette); } void @@ -226,26 +292,24 @@ gimp_image_set_colormap (GimpImage *image, if (push_undo) gimp_image_undo_push_image_colormap (image, C_("undo-type", "Set Colormap")); - if (private->colormap) - memset (private->colormap, 0, GIMP_IMAGE_COLORMAP_SIZE); - else + if (!private->palette) gimp_image_colormap_init (image); - if (colormap) - memcpy (private->colormap, colormap, n_colors * 3); - - /* 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)); 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, NULL, i); + for (i = 0; i < n_colors; i++) + { + GimpRGB color; + gimp_rgba_set_uchar (&color, + colormap[3 * i + 0], + colormap[3 * i + 1], + colormap[3 * i + 2], + 255); + gimp_image_colormap_set_palette_entry (image, &color, i); + } gimp_data_thaw (GIMP_DATA (private->palette)); @@ -266,14 +330,12 @@ gimp_image_unset_colormap (GimpImage *image, gimp_image_undo_push_image_colormap (image, C_("undo-type", "Unset Colormap")); - if (private->colormap) + if (private->palette) { gimp_image_colormap_dispose (image); gimp_image_colormap_free (image); } - private->n_colors = 0; - gimp_image_colormap_changed (image, -1); } @@ -283,20 +345,22 @@ gimp_image_get_colormap_entry (GimpImage *image, GimpRGB *color) { GimpImagePrivate *private; + GimpPaletteEntry *entry; g_return_if_fail (GIMP_IS_IMAGE (image)); private = GIMP_IMAGE_GET_PRIVATE (image); - g_return_if_fail (private->colormap != NULL); - g_return_if_fail (color_index >= 0 && color_index < private->n_colors); + g_return_if_fail (private->palette != NULL); + g_return_if_fail (color_index >= 0 && + color_index < gimp_palette_get_n_colors (private->palette)); g_return_if_fail (color != NULL); - gimp_rgba_set_uchar (color, - private->colormap[color_index * 3], - private->colormap[color_index * 3 + 1], - private->colormap[color_index * 3 + 2], - 255); + entry = gimp_palette_get_entry (private->palette, color_index); + + g_return_if_fail (entry != NULL); + + *color = entry->color; } void @@ -311,21 +375,16 @@ gimp_image_set_colormap_entry (GimpImage *image, private = GIMP_IMAGE_GET_PRIVATE (image); - g_return_if_fail (private->colormap != NULL); - g_return_if_fail (color_index >= 0 && color_index < private->n_colors); + g_return_if_fail (private->palette != NULL); + g_return_if_fail (color_index >= 0 && + color_index < gimp_palette_get_n_colors (private->palette)); g_return_if_fail (color != NULL); if (push_undo) gimp_image_undo_push_image_colormap (image, C_("undo-type", "Change Colormap entry")); - gimp_rgb_get_uchar (color, - &private->colormap[color_index * 3], - &private->colormap[color_index * 3 + 1], - &private->colormap[color_index * 3 + 2]); - - if (private->palette) - gimp_image_colormap_set_palette_entry (image, color, color_index); + gimp_image_colormap_set_palette_entry (image, color, color_index); gimp_image_colormap_changed (image, color_index); } @@ -340,22 +399,15 @@ gimp_image_add_colormap_entry (GimpImage *image, private = GIMP_IMAGE_GET_PRIVATE (image); - g_return_if_fail (private->colormap != NULL); - g_return_if_fail (private->n_colors < 256); + g_return_if_fail (private->palette != NULL); + g_return_if_fail (gimp_palette_get_n_colors (private->palette) < 256); g_return_if_fail (color != NULL); gimp_image_undo_push_image_colormap (image, C_("undo-type", "Add Color to Colormap")); - gimp_rgb_get_uchar (color, - &private->colormap[private->n_colors * 3], - &private->colormap[private->n_colors * 3 + 1], - &private->colormap[private->n_colors * 3 + 2]); - - private->n_colors++; - - if (private->palette) - gimp_image_colormap_set_palette_entry (image, color, private->n_colors - 1); + gimp_image_colormap_set_palette_entry (image, color, + gimp_palette_get_n_colors (private->palette)); gimp_image_colormap_changed (image, -1); } @@ -365,29 +417,20 @@ gimp_image_add_colormap_entry (GimpImage *image, static void gimp_image_colormap_set_palette_entry (GimpImage *image, - const GimpRGB *c, + const GimpRGB *color, gint index) { GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image); - GimpRGB color; + GimpRGB black; gchar name[64]; - /* Avoid converting to char then back to double if we have the - * original GimpRGB color. - */ - if (c) - color = *c; - else - gimp_rgba_set_uchar (&color, - private->colormap[3 * index + 0], - private->colormap[3 * index + 1], - private->colormap[3 * index + 2], - 255); + g_return_if_fail (color != NULL); + + gimp_rgb_set (&black, 0, 0, 0); + while (gimp_palette_get_n_colors (private->palette) <= index) + gimp_palette_add_entry (private->palette, index, name, &black); g_snprintf (name, sizeof (name), "#%d", index); - if (gimp_palette_get_n_colors (private->palette) < private->n_colors) - gimp_palette_add_entry (private->palette, index, name, &color); - else - gimp_palette_set_entry (private->palette, index, name, &color); + gimp_palette_set_entry (private->palette, index, name, color); } diff --git a/app/core/gimpimage-colormap.h b/app/core/gimpimage-colormap.h index 917b4b14c3..b5a963b78a 100644 --- a/app/core/gimpimage-colormap.h +++ b/app/core/gimpimage-colormap.h @@ -32,8 +32,11 @@ const Babl * gimp_image_colormap_get_rgb_format (GimpImage *image); const Babl * gimp_image_colormap_get_rgba_format (GimpImage *image); GimpPalette * gimp_image_get_colormap_palette (GimpImage *image); +void gimp_image_set_colormap_palette (GimpImage *image, + GimpPalette *palette, + gboolean push_undo); -const guchar * gimp_image_get_colormap (GimpImage *image); +guchar * gimp_image_get_colormap (GimpImage *image); gint gimp_image_get_colormap_size (GimpImage *image); void gimp_image_set_colormap (GimpImage *image, const guchar *colormap, diff --git a/app/core/gimpimage-duplicate.c b/app/core/gimpimage-duplicate.c index 807412e26f..6bacd6564c 100644 --- a/app/core/gimpimage-duplicate.c +++ b/app/core/gimpimage-duplicate.c @@ -199,10 +199,9 @@ gimp_image_duplicate_colormap (GimpImage *image, GimpImage *new_image) { if (gimp_image_get_base_type (new_image) == GIMP_INDEXED) - gimp_image_set_colormap (new_image, - gimp_image_get_colormap (image), - gimp_image_get_colormap_size (image), - FALSE); + gimp_image_set_colormap_palette (new_image, + gimp_image_get_colormap_palette (image), + FALSE); } static GimpItem * diff --git a/app/core/gimpimage-new.c b/app/core/gimpimage-new.c index e9e7308a6a..bc8d50cdcf 100644 --- a/app/core/gimpimage-new.c +++ b/app/core/gimpimage-new.c @@ -193,10 +193,9 @@ gimp_image_new_from_drawable (Gimp *gimp, gimp_image_undo_disable (new_image); if (type == GIMP_INDEXED) - gimp_image_set_colormap (new_image, - gimp_image_get_colormap (image), - gimp_image_get_colormap_size (image), - FALSE); + gimp_image_set_colormap_palette (new_image, + gimp_image_get_colormap_palette (image), + FALSE); gimp_image_get_resolution (image, &xres, &yres); gimp_image_set_resolution (new_image, xres, yres); @@ -387,10 +386,9 @@ gimp_image_new_from_drawables (Gimp *gimp, gimp_image_undo_disable (new_image); if (type == GIMP_INDEXED) - gimp_image_set_colormap (new_image, - gimp_image_get_colormap (image), - gimp_image_get_colormap_size (image), - FALSE); + gimp_image_set_colormap_palette (new_image, + gimp_image_get_colormap_palette (image), + FALSE); gimp_image_get_resolution (image, &xres, &yres); gimp_image_set_resolution (new_image, xres, yres); diff --git a/app/core/gimpimage-private.h b/app/core/gimpimage-private.h index 0f7db76754..80e42dbd32 100644 --- a/app/core/gimpimage-private.h +++ b/app/core/gimpimage-private.h @@ -56,8 +56,6 @@ struct _GimpImagePrivate gboolean bounding_box_update_pending; GeglBuffer *pickable_buffer; - guchar *colormap; /* colormap (for indexed) */ - gint n_colors; /* # of colors (for indexed) */ GimpPalette *palette; /* palette of colormap */ const Babl *babl_palette_rgb; /* palette's RGB Babl format */ const Babl *babl_palette_rgba; /* palette's RGBA Babl format */ diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c index 38a0e9d9a5..22d1dfd04f 100644 --- a/app/core/gimpimage.c +++ b/app/core/gimpimage.c @@ -70,6 +70,7 @@ #include "gimplayermask.h" #include "gimplayerstack.h" #include "gimpmarshal.h" +#include "gimppalette.h" #include "gimpparasitelist.h" #include "gimppickable.h" #include "gimpprojectable.h" @@ -757,8 +758,6 @@ gimp_image_init (GimpImage *image) private->bounding_box.height = 0; private->pickable_buffer = NULL; - private->colormap = NULL; - private->n_colors = 0; private->palette = NULL; private->metadata = NULL; @@ -1070,7 +1069,7 @@ gimp_image_dispose (GObject *object) GimpImage *image = GIMP_IMAGE (object); GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image); - if (private->colormap) + if (private->palette) gimp_image_colormap_dispose (image); gimp_image_undo_free (image); @@ -1129,7 +1128,7 @@ gimp_image_finalize (GObject *object) g_clear_object (&private->graph); private->visible_mask = NULL; - if (private->colormap) + if (private->palette) gimp_image_colormap_free (image); _gimp_image_free_color_profile (image); @@ -1240,9 +1239,6 @@ gimp_image_get_memsize (GimpObject *object, GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image); gint64 memsize = 0; - if (gimp_image_get_colormap (image)) - memsize += GIMP_IMAGE_COLORMAP_SIZE; - memsize += gimp_object_get_memsize (GIMP_OBJECT (private->palette), gui_size); @@ -2723,7 +2719,7 @@ gimp_image_get_xcf_version (GimpImage *image, reasons = g_list_prepend (reasons, tmp); } /* need version 1 for colormaps */ - if (gimp_image_get_colormap (image)) + if (gimp_image_get_colormap_palette (image)) version = 1; items = gimp_image_get_layer_list (image); @@ -3775,9 +3771,13 @@ void gimp_image_colormap_changed (GimpImage *image, gint color_index) { + GimpPalette *palette; + gint n_colors; + g_return_if_fail (GIMP_IS_IMAGE (image)); - g_return_if_fail (color_index >= -1 && - color_index < GIMP_IMAGE_GET_PRIVATE (image)->n_colors); + palette = GIMP_IMAGE_GET_PRIVATE (image)->palette; + n_colors = palette ? gimp_palette_get_n_colors (palette) : 0; + g_return_if_fail (color_index >= -1 && color_index < n_colors); g_signal_emit (image, gimp_image_signals[COLORMAP_CHANGED], 0, color_index); diff --git a/app/core/gimpimageundo.c b/app/core/gimpimageundo.c index 28ffd9a7f2..c0b1048f12 100644 --- a/app/core/gimpimageundo.c +++ b/app/core/gimpimageundo.c @@ -183,8 +183,7 @@ gimp_image_undo_constructed (GObject *object) case GIMP_UNDO_IMAGE_COLORMAP: image_undo->num_colors = gimp_image_get_colormap_size (image); - image_undo->colormap = g_memdup2 (gimp_image_get_colormap (image), - GIMP_IMAGE_COLORMAP_SIZE); + image_undo->colormap = gimp_image_get_colormap (image); break; case GIMP_UNDO_IMAGE_HIDDEN_PROFILE: @@ -454,8 +453,7 @@ gimp_image_undo_pop (GimpUndo *undo, gint num_colors; num_colors = gimp_image_get_colormap_size (image); - colormap = g_memdup2 (gimp_image_get_colormap (image), - GIMP_IMAGE_COLORMAP_SIZE); + colormap = gimp_image_get_colormap (image); if (image_undo->colormap) gimp_image_set_colormap (image, diff --git a/app/core/gimppalette-import.c b/app/core/gimppalette-import.c index d2c7dc25d7..b6b3b0b19f 100644 --- a/app/core/gimppalette-import.c +++ b/app/core/gimppalette-import.c @@ -404,35 +404,15 @@ gimp_palette_import_from_indexed_image (GimpImage *image, const gchar *palette_name) { GimpPalette *palette; - const guchar *colormap; - guint n_colors; - gint count; - GimpRGB color; g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); g_return_val_if_fail (gimp_image_get_base_type (image) == GIMP_INDEXED, NULL); g_return_val_if_fail (palette_name != NULL, NULL); - palette = GIMP_PALETTE (gimp_palette_new (context, palette_name)); + palette = GIMP_PALETTE (gimp_data_duplicate (GIMP_DATA (gimp_image_get_colormap_palette (image)))); - colormap = gimp_image_get_colormap (image); - n_colors = gimp_image_get_colormap_size (image); - - for (count = 0; count < n_colors; ++count) - { - gchar name[256]; - - g_snprintf (name, sizeof (name), _("Index %d"), count); - - gimp_rgba_set_uchar (&color, - colormap[count * 3 + 0], - colormap[count * 3 + 1], - colormap[count * 3 + 2], - 255); - - gimp_palette_add_entry (palette, -1, name, &color); - } + gimp_object_set_name (GIMP_OBJECT (palette), palette_name); return palette; } diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c index bf2fb9e77a..3930f26c26 100644 --- a/app/pdb/image-cmds.c +++ b/app/pdb/image-cmds.c @@ -1557,7 +1557,7 @@ image_get_colormap_invoker (GimpProcedure *procedure, if (success) { num_bytes = 3 * gimp_image_get_colormap_size (image); - colormap = g_memdup2 (gimp_image_get_colormap (image), num_bytes); + colormap = gimp_image_get_colormap (image); } return_vals = gimp_procedure_get_return_values (procedure, success, diff --git a/app/widgets/gimpcolormapeditor.c b/app/widgets/gimpcolormapeditor.c index c27f5af97f..a6070aea16 100644 --- a/app/widgets/gimpcolormapeditor.c +++ b/app/widgets/gimpcolormapeditor.c @@ -214,11 +214,10 @@ gimp_colormap_editor_new (GimpMenuFactory *menu_factory) void gimp_colormap_editor_edit_color (GimpColormapEditor *editor) { - GimpImage *image; - const guchar *colormap; - GimpRGB color; - gchar *desc; - gint index; + GimpImage *image; + GimpRGB color; + gchar *desc; + gint index; g_return_if_fail (GIMP_IS_COLORMAP_EDITOR (editor)); @@ -230,13 +229,7 @@ gimp_colormap_editor_edit_color (GimpColormapEditor *editor) /* No colormap. */ return; - colormap = gimp_image_get_colormap (image); - - gimp_rgba_set_uchar (&color, - colormap[index * 3], - colormap[index * 3 + 1], - colormap[index * 3 + 2], - 255); + gimp_image_get_colormap_entry (image, index, &color); desc = g_strdup_printf (_("Edit colormap entry #%d"), index); diff --git a/app/widgets/gimpcolormapselection.c b/app/widgets/gimpcolormapselection.c index 22db9804b7..8e473e9744 100644 --- a/app/widgets/gimpcolormapselection.c +++ b/app/widgets/gimpcolormapselection.c @@ -69,7 +69,7 @@ enum #define HAVE_COLORMAP(image) \ (image != NULL && \ gimp_image_get_base_type (image) == GIMP_INDEXED && \ - gimp_image_get_colormap (image) != NULL) + gimp_image_get_colormap_palette (image) != NULL) static void gimp_colormap_selection_set_property (GObject *object, @@ -566,15 +566,16 @@ gimp_colormap_selection_update_entries (GimpColormapSelection *selection) } else { - const guchar *colormap = gimp_image_get_colormap (image); - const guchar *col; - gchar *string; + GimpRGB color; + guchar r, g, b; + gchar *string; - gtk_adjustment_set_value (selection->index_adjustment, selection->col_index); + gtk_adjustment_set_value (selection->index_adjustment, + selection->col_index); + gimp_image_get_colormap_entry (image, selection->col_index, &color); + gimp_rgb_get_uchar (&color, &r, &g, &b); - col = colormap + selection->col_index * 3; - - string = g_strdup_printf ("%02x%02x%02x", col[0], col[1], col[2]); + string = g_strdup_printf ("%02x%02x%02x", r, g, b); gtk_entry_set_text (GTK_ENTRY (selection->color_entry), string); g_free (string); diff --git a/app/xcf/xcf-save.c b/app/xcf/xcf-save.c index e268abe15e..851df3502b 100644 --- a/app/xcf/xcf-save.c +++ b/app/xcf/xcf-save.c @@ -371,10 +371,14 @@ xcf_save_image_props (XcfInfo *info, gimp_image_get_resolution (image, &xres, &yres); /* check and see if we should save the colormap property */ - if (gimp_image_get_colormap (image)) - xcf_check_error (xcf_save_prop (info, image, PROP_COLORMAP, error, - gimp_image_get_colormap_size (image), - gimp_image_get_colormap (image))); + if (gimp_image_get_colormap_palette (image)) + { + guint8 *colormap = gimp_image_get_colormap (image); + xcf_check_error (xcf_save_prop (info, image, PROP_COLORMAP, error, + gimp_image_get_colormap_size (image), + colormap)); + g_free (colormap); + } if (info->compression != COMPRESS_NONE) xcf_check_error (xcf_save_prop (info, image, PROP_COMPRESSION, error, diff --git a/pdb/groups/image.pdb b/pdb/groups/image.pdb index 981bd42966..f479c474a0 100644 --- a/pdb/groups/image.pdb +++ b/pdb/groups/image.pdb @@ -1546,7 +1546,7 @@ HELP code => <<'CODE' { num_bytes = 3 * gimp_image_get_colormap_size (image); - colormap = g_memdup2 (gimp_image_get_colormap (image), num_bytes); + colormap = gimp_image_get_colormap (image); } CODE );