Commit 5e53d06f authored by Ell's avatar Ell

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 c16c68e6)
parent f6347572
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment