plug-ins: get rid of all remaining usage of gimp_image_[gs]et_colormap().

When I see that we are just using R'G'B' format with no space
everywhere, I'm pretty sure some of this code must be wrong (even though
for some formats, maybe only sRGB is supported, I am guessing that for
some others, the palette may be in specific color spaces).
This will have to be improved with time.
This commit is contained in:
Jehan 2024-09-23 15:17:04 +02:00
parent 8fff258286
commit 2e1bf0e44c
26 changed files with 92 additions and 64 deletions

View file

@ -615,7 +615,7 @@ load_image (GFile *file,
} }
} }
gimp_image_set_colormap (image, palette + 3, colors - 1); gimp_palette_set_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), palette + 3, (colors - 1) * 3);
} }
/* Now get everything redrawn and hand back the finished image */ /* Now get everything redrawn and hand back the finished image */

View file

@ -878,7 +878,7 @@ export_image (GFile *file,
GeglColor *background; GeglColor *background;
guchar bg[3]; guchar bg[3];
cmap = gimp_image_get_colormap (image, NULL, &colors); cmap = gimp_palette_get_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), &colors, NULL);
background = gimp_context_get_background (); background = gimp_context_get_background ();
gegl_color_get_pixel (background, babl_format_with_space ("R'G'B' u8", NULL), bg); gegl_color_get_pixel (background, babl_format_with_space ("R'G'B' u8", NULL), bg);

View file

@ -257,8 +257,8 @@ gif_load (GimpProcedure *procedure,
#endif #endif
if (! promote_to_rgb) if (! promote_to_rgb)
gimp_image_set_colormap (image, gimp_palette_set_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"),
gimp_cmap, highest_used_index); gimp_cmap, highest_used_index * 3);
return_vals = gimp_procedure_new_return_values (procedure, return_vals = gimp_procedure_new_return_values (procedure,
GIMP_PDB_SUCCESS, GIMP_PDB_SUCCESS,
@ -291,7 +291,7 @@ gif_load_thumb (GimpProcedure *procedure,
error); error);
if (! promote_to_rgb) if (! promote_to_rgb)
gimp_image_set_colormap (image, gimp_cmap, highest_used_index); gimp_palette_set_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), gimp_cmap, highest_used_index * 3);
return_vals = gimp_procedure_new_return_values (procedure, return_vals = gimp_procedure_new_return_values (procedure,
GIMP_PDB_SUCCESS, GIMP_PDB_SUCCESS,
@ -1141,7 +1141,7 @@ ReadImage (FILE *fd,
used_cmap[2][i] = gimp_cmap[j++] = cmap[2][i]; used_cmap[2][i] = gimp_cmap[j++] = cmap[2][i];
} }
gimp_image_set_colormap (*image, gimp_cmap, ncols); gimp_palette_set_colormap (gimp_image_get_palette (*image), babl_format ("R'G'B' u8"), gimp_cmap, ncols * 3);
if (Gif89.delayTime < 0) if (Gif89.delayTime < 0)
framename = g_strdup (_("Background")); framename = g_strdup (_("Background"));

View file

@ -317,7 +317,7 @@ export_image (GFile *file,
} }
/* save colormap */ /* save colormap */
cmap = gimp_image_get_colormap (image, NULL, &colors); cmap = gimp_palette_get_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), &colors, NULL);
if (! print (output, error, if (! print (output, error,
"static unsigned char header_data_cmap[256][3] = {") || "static unsigned char header_data_cmap[256][3] = {") ||

View file

@ -396,7 +396,7 @@ load_image (GFile *file,
} }
if (pixel_size == 1) if (pixel_size == 1)
gimp_image_set_colormap (image, gimp_cmap, palette_size); gimp_palette_set_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), gimp_cmap, palette_size * 3);
g_object_unref (buffer); g_object_unref (buffer);
} }

View file

@ -654,7 +654,7 @@ respin_cmap (png_structp pp,
gint transparent; gint transparent;
gint cols, rows; gint cols, rows;
before = gimp_image_get_colormap (image, NULL, &colors); before = gimp_palette_get_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), &colors, NULL);
/* Make sure there is something in the colormap */ /* Make sure there is something in the colormap */
if (colors == 0) if (colors == 0)
@ -1033,7 +1033,7 @@ mng_export_image (GFile *file,
guchar *palette; guchar *palette;
gint numcolors; gint numcolors;
palette = gimp_image_get_colormap (image, NULL, &numcolors); palette = gimp_palette_get_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), &numcolors, NULL);
if ((numcolors != 0) && if ((numcolors != 0) &&
(mng_putchunk_plte_wrapper (handle, numcolors, (mng_putchunk_plte_wrapper (handle, numcolors,
@ -1285,7 +1285,7 @@ mng_export_image (GFile *file,
mngg.has_plte = TRUE; mngg.has_plte = TRUE;
mngg.palette = (png_colorp) mngg.palette = (png_colorp)
gimp_image_get_colormap (image, NULL, &mngg.num_palette); gimp_palette_get_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), &mngg.num_palette, NULL);
bit_depth = get_bit_depth_for_palette (mngg.num_palette); bit_depth = get_bit_depth_for_palette (mngg.num_palette);
break; break;

View file

@ -777,37 +777,49 @@ load_image (GimpProcedure *procedure,
255, 255, 255}; 255, 255, 255};
colormap = bw_colormap; colormap = bw_colormap;
} }
gimp_image_set_colormap (image, colormap, 2); gimp_palette_set_colormap (gimp_image_get_palette (image),
babl_format ("R'G'B' u8"),
(guint8 *) colormap, 6);
} }
else if (pcx_header.bpp == 1 && pcx_header.planes == 2) else if (pcx_header.bpp == 1 && pcx_header.planes == 2)
{ {
dest = g_new (guchar, ((gsize) width) * height); dest = g_new (guchar, ((gsize) width) * height);
load_sub_8 (fd, width, height, 1, 2, dest, bytesperline); load_sub_8 (fd, width, height, 1, 2, dest, bytesperline);
gimp_image_set_colormap (image, pcx_header.colormap, 4); gimp_palette_set_colormap (gimp_image_get_palette (image),
babl_format ("R'G'B' u8"),
pcx_header.colormap, 4 * 3);
} }
else if (pcx_header.bpp == 2 && pcx_header.planes == 1) else if (pcx_header.bpp == 2 && pcx_header.planes == 1)
{ {
dest = g_new (guchar, ((gsize) width) * height); dest = g_new (guchar, ((gsize) width) * height);
load_sub_8 (fd, width, height, 2, 1, dest, bytesperline); load_sub_8 (fd, width, height, 2, 1, dest, bytesperline);
gimp_image_set_colormap (image, pcx_header.colormap, 4); gimp_palette_set_colormap (gimp_image_get_palette (image),
babl_format ("R'G'B' u8"),
pcx_header.colormap, 4 * 3);
} }
else if (pcx_header.bpp == 1 && pcx_header.planes == 3) else if (pcx_header.bpp == 1 && pcx_header.planes == 3)
{ {
dest = g_new (guchar, ((gsize) width) * height); dest = g_new (guchar, ((gsize) width) * height);
load_sub_8 (fd, width, height, 1, 3, dest, bytesperline); load_sub_8 (fd, width, height, 1, 3, dest, bytesperline);
gimp_image_set_colormap (image, pcx_header.colormap, 8); gimp_palette_set_colormap (gimp_image_get_palette (image),
babl_format ("R'G'B' u8"),
pcx_header.colormap, 8 * 3);
} }
else if (pcx_header.bpp == 1 && pcx_header.planes == 4) else if (pcx_header.bpp == 1 && pcx_header.planes == 4)
{ {
dest = g_new (guchar, ((gsize) width) * height); dest = g_new (guchar, ((gsize) width) * height);
load_4 (fd, width, height, dest, bytesperline); load_4 (fd, width, height, dest, bytesperline);
gimp_image_set_colormap (image, pcx_header.colormap, 16); gimp_palette_set_colormap (gimp_image_get_palette (image),
babl_format ("R'G'B' u8"),
pcx_header.colormap, 16 * 3);
} }
else if (pcx_header.bpp == 4 && pcx_header.planes == 1) else if (pcx_header.bpp == 4 && pcx_header.planes == 1)
{ {
dest = g_new (guchar, ((gsize) width) * height); dest = g_new (guchar, ((gsize) width) * height);
load_sub_8 (fd, width, height, 4, 1, dest, bytesperline); load_sub_8 (fd, width, height, 4, 1, dest, bytesperline);
gimp_image_set_colormap (image, pcx_header.colormap, 16); gimp_palette_set_colormap (gimp_image_get_palette (image),
babl_format ("R'G'B' u8"),
pcx_header.colormap, 16 * 3);
} }
else if (pcx_header.bpp == 8 && pcx_header.planes == 1) else if (pcx_header.bpp == 8 && pcx_header.planes == 1)
{ {
@ -815,7 +827,9 @@ load_image (GimpProcedure *procedure,
load_8 (fd, width, height, dest, bytesperline); load_8 (fd, width, height, dest, bytesperline);
fseek (fd, -768L, SEEK_END); fseek (fd, -768L, SEEK_END);
fread (cmap, 768, 1, fd); fread (cmap, 768, 1, fd);
gimp_image_set_colormap (image, cmap, 256); gimp_palette_set_colormap (gimp_image_get_palette (image),
babl_format ("R'G'B' u8"),
cmap, 256 * 3);
} }
else if (pcx_header.bpp == 8 && (pcx_header.planes == 3 || pcx_header.planes == 4)) else if (pcx_header.bpp == 8 && (pcx_header.planes == 3 || pcx_header.planes == 4))
{ {
@ -1077,7 +1091,8 @@ export_image (GFile *file,
switch (drawable_type) switch (drawable_type)
{ {
case GIMP_INDEXED_IMAGE: case GIMP_INDEXED_IMAGE:
cmap = gimp_image_get_colormap (image, NULL, &colors); cmap = gimp_palette_get_colormap (gimp_image_get_palette (image),
babl_format ("R'G'B' u8"), &colors, NULL);
if (colors > 16) if (colors > 16)
{ {

View file

@ -1012,8 +1012,8 @@ load_image (GFile *file,
int num_palette; int num_palette;
png_get_PLTE (pp, info, &palette, &num_palette); png_get_PLTE (pp, info, &palette, &num_palette);
gimp_image_set_colormap ((GimpImage *) image, (guchar *) palette, gimp_palette_set_colormap (gimp_image_get_palette ((GimpImage *) image), babl_format ("R'G'B' u8"),
num_palette); (guchar *) palette, num_palette * 3);
} }
bpp = babl_format_get_bytes_per_pixel (file_format); bpp = babl_format_get_bytes_per_pixel (file_format);
@ -1594,9 +1594,9 @@ export_image (GFile *file,
color_type = PNG_COLOR_TYPE_PALETTE; color_type = PNG_COLOR_TYPE_PALETTE;
file_format = gimp_drawable_get_format (drawable); file_format = gimp_drawable_get_format (drawable);
pngg.has_plte = TRUE; pngg.has_plte = TRUE;
pngg.palette = (png_colorp) gimp_image_get_colormap (image, pngg.palette = (png_colorp) gimp_palette_get_colormap (gimp_image_get_palette (image),
NULL, babl_format ("R'G'B' u8"),
&pngg.num_palette); &pngg.num_palette, NULL);
if (optimize_palette) if (optimize_palette)
bit_depth = get_bit_depth_for_palette (pngg.num_palette); bit_depth = get_bit_depth_for_palette (pngg.num_palette);
break; break;
@ -2248,7 +2248,7 @@ respin_cmap (png_structp pp,
gint colors; gint colors;
guchar *before; guchar *before;
before = gimp_image_get_colormap (image, NULL, &colors); before = gimp_palette_get_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), &colors, NULL);
buffer = gimp_drawable_get_buffer (drawable); buffer = gimp_drawable_get_buffer (drawable);
/* Make sure there is something in the colormap. /* Make sure there is something in the colormap.

View file

@ -1790,7 +1790,7 @@ export_image (GFile *file,
guchar *cmap; guchar *cmap;
gint num_colors; gint num_colors;
cmap = gimp_image_get_colormap (image, NULL, &num_colors); cmap = gimp_palette_get_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), &num_colors, NULL);
if (file_type == FILE_TYPE_PBM) if (file_type == FILE_TYPE_PBM)
{ {

View file

@ -2348,7 +2348,7 @@ load_ps (GFile *file,
{ {
const guchar BWColorMap[2*3] = { 255, 255, 255, 0, 0, 0 }; const guchar BWColorMap[2*3] = { 255, 255, 255, 0, 0, 0 };
gimp_image_set_colormap (image, BWColorMap, 2); gimp_palette_set_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), (guint8 *) BWColorMap, 2 * 3);
for (i = 0; i < height; i++) for (i = 0; i < height; i++)
{ {
@ -2823,9 +2823,8 @@ save_ps_preview (GOutputStream *output,
break; break;
case GIMP_INDEXED_IMAGE: case GIMP_INDEXED_IMAGE:
cmap = gimp_image_get_colormap (gimp_item_get_image (GIMP_ITEM (drawable)), cmap = gimp_palette_get_colormap (gimp_image_get_palette (gimp_item_get_image (GIMP_ITEM (drawable))),
NULL, babl_format ("R'G'B' u8"), &ncols, NULL);
&ncols);
format = gimp_drawable_get_format (drawable); format = gimp_drawable_get_format (drawable);
break; break;
@ -3138,7 +3137,7 @@ save_bw (GOutputStream *output,
"level", &level2, "level", &level2,
NULL); NULL);
cmap = gimp_image_get_colormap (image, NULL, &ncols); cmap = gimp_palette_get_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), &ncols, NULL);
buffer = gimp_drawable_get_buffer (drawable); buffer = gimp_drawable_get_buffer (drawable);
format = gimp_drawable_get_format (drawable); format = gimp_drawable_get_format (drawable);
@ -3327,7 +3326,7 @@ save_index (GOutputStream *output,
"level", &level2, "level", &level2,
NULL); NULL);
cmap = cmap_start = gimp_image_get_colormap (image, NULL, &ncols); cmap = cmap_start = gimp_palette_get_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), &ncols, NULL);
ct = coltab; ct = coltab;
bw = 1; bw = 1;

View file

@ -1301,7 +1301,7 @@ read_color_block (FILE *f,
memcpy (color_palette, tmpmap, color_palette_entries * 3); memcpy (color_palette, tmpmap, color_palette_entries * 3);
g_free (tmpmap); g_free (tmpmap);
gimp_image_set_colormap (image, color_palette, color_palette_entries); gimp_palette_set_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), color_palette, color_palette_entries * 3);
g_free (color_palette); g_free (color_palette);
} }

View file

@ -1314,7 +1314,7 @@ raw_load_palette (RawGimpData *data,
} }
} }
gimp_image_set_colormap (data->image, data->cmap, 256); gimp_palette_set_colormap (gimp_image_get_palette (data->image), babl_format ("R'G'B' u8"), data->cmap, 256 * 3);
return TRUE; return TRUE;
} }
@ -1357,7 +1357,7 @@ export_image (GFile *file,
g_return_val_if_fail (bpc * n_components == bpp, FALSE); g_return_val_if_fail (bpc * n_components == bpp, FALSE);
if (gimp_drawable_is_indexed (drawable)) if (gimp_drawable_is_indexed (drawable))
cmap = gimp_image_get_colormap (image, NULL, &palsize); cmap = gimp_palette_get_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), &palsize, NULL);
width = gegl_buffer_get_width (buffer); width = gegl_buffer_get_width (buffer);
height = gegl_buffer_get_height (buffer); height = gegl_buffer_get_height (buffer);

View file

@ -1022,7 +1022,7 @@ set_color_table (GimpImage *image,
ColorMap[j*3], ColorMap[j*3+1], ColorMap[j*3+2]); ColorMap[j*3], ColorMap[j*3+1], ColorMap[j*3+2]);
#endif #endif
gimp_image_set_colormap (image, ColorMap, ncols); gimp_palette_set_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), ColorMap, ncols * 3);
} }
@ -1505,7 +1505,7 @@ save_index (FILE *ofp,
} }
else else
{ {
cmap = gimp_image_get_colormap (image, NULL, &ncols); cmap = gimp_palette_get_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), &ncols, NULL);
for (j = 0; j < ncols; j++) for (j = 0; j < ncols; j++)
{ {

View file

@ -1097,7 +1097,7 @@ ReadImage (FILE *fp,
image = gimp_image_new (info->width, info->height, itype); image = gimp_image_new (info->width, info->height, itype);
if (gimp_cmap) if (gimp_cmap)
gimp_image_set_colormap (image, gimp_cmap, info->colorMapLength); gimp_palette_set_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), gimp_cmap, info->colorMapLength * 3);
layer = gimp_layer_new (image, layer = gimp_layer_new (image,
_("Background"), _("Background"),
@ -1231,7 +1231,7 @@ export_image (GFile *file,
if (dtype == GIMP_INDEXED_IMAGE) if (dtype == GIMP_INDEXED_IMAGE)
{ {
gimp_cmap = gimp_image_get_colormap (image, NULL, &num_colors); gimp_cmap = gimp_palette_get_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), &num_colors, NULL);
header[1] = 1; /* cmap type */ header[1] = 1; /* cmap type */
header[2] = rle ? 9 : 1; header[2] = rle ? 9 : 1;
@ -1242,7 +1242,7 @@ export_image (GFile *file,
} }
else if (dtype == GIMP_INDEXEDA_IMAGE) else if (dtype == GIMP_INDEXEDA_IMAGE)
{ {
gimp_cmap = gimp_image_get_colormap (image, NULL, &num_colors); gimp_cmap = gimp_palette_get_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), &num_colors, NULL);
header[1] = 1; /* cmap type */ header[1] = 1; /* cmap type */
header[2] = rle ? 9 : 1; header[2] = rle ? 9 : 1;

View file

@ -275,7 +275,8 @@ read_image (FILE *fd,
GIMP_INDEXED_IMAGE, 100, GIMP_INDEXED_IMAGE, 100,
gimp_image_get_default_new_layer_mode (image)); gimp_image_get_default_new_layer_mode (image));
gimp_image_set_colormap (image, mono, 2); gimp_palette_set_colormap (gimp_image_get_palette (image),
babl_format ("R'G'B' u8"), (guint8 *) mono, 6);
gimp_image_insert_layer (image, layer, NULL, 0); gimp_image_insert_layer (image, layer, NULL, 0);

View file

@ -881,7 +881,7 @@ load_image (GFile *file,
} }
/* Set a black-and-white colormap. */ /* Set a black-and-white colormap. */
gimp_image_set_colormap (image, cmap, 2); gimp_palette_set_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), (guint8 *) cmap, 2 * 3);
layer = gimp_layer_new (image, layer = gimp_layer_new (image,
_("Background"), _("Background"),
@ -982,7 +982,7 @@ export_image (GFile *file,
g_printerr ("%s: save_image '%s'\n", G_STRFUNC, prefix); g_printerr ("%s: save_image '%s'\n", G_STRFUNC, prefix);
#endif #endif
cmap = gimp_image_get_colormap (image, NULL, &colors); cmap = gimp_palette_get_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), &colors, NULL);
if (! gimp_drawable_is_indexed (drawable) || colors > 2) if (! gimp_drawable_is_indexed (drawable) || colors > 2)
{ {

View file

@ -767,7 +767,7 @@ export_image (GFile *file,
if (indexed) if (indexed)
{ {
guchar *cmap = gimp_image_get_colormap (image, NULL, &ncolors); guchar *cmap = gimp_palette_get_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), &ncolors, NULL);
guchar *c; guchar *c;
c = cmap; c = cmap;

View file

@ -516,7 +516,7 @@ load_image (GFile *file,
goto out; goto out;
} }
/* Guard against insanely huge color maps -- gimp_image_set_colormap() only /* Guard against insanely huge color maps -- gimp_palette_set_colormap() only
* accepts colormaps with 0..256 colors anyway. */ * accepts colormaps with 0..256 colors anyway. */
if (xwdhdr.l_colormap_entries > 256) if (xwdhdr.l_colormap_entries > 256)
{ {
@ -1319,7 +1319,7 @@ set_color_table (GimpImage *image,
ColorMap[j*3], ColorMap[j*3+1], ColorMap[j*3+2]); ColorMap[j*3], ColorMap[j*3+1], ColorMap[j*3+2]);
#endif #endif
gimp_image_set_colormap (image, ColorMap, 256); gimp_palette_set_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), ColorMap, 256 * 3);
} }
@ -2550,7 +2550,7 @@ save_index (GOutputStream *output,
else else
{ {
vclass = 3; vclass = 3;
cmap = gimp_image_get_colormap (image, NULL, &ncolors); cmap = gimp_palette_get_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), &ncolors, NULL);
for (j = 0; j < ncolors; j++) for (j = 0; j < ncolors; j++)
{ {

View file

@ -464,7 +464,7 @@ render_grid (GimpImage *image,
break; break;
case GIMP_INDEXED: case GIMP_INDEXED:
cmap = gimp_image_get_colormap (image, NULL, &ncolors); cmap = gimp_palette_get_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), &ncolors, NULL);
hcolor[0] = best_cmap_match (cmap, ncolors, hcolor_gegl); hcolor[0] = best_cmap_match (cmap, ncolors, hcolor_gegl);
vcolor[0] = best_cmap_match (cmap, ncolors, vcolor_gegl); vcolor[0] = best_cmap_match (cmap, ncolors, vcolor_gegl);

View file

@ -227,7 +227,7 @@ export_image (GFile *file,
case GIMP_INDEXED_IMAGE: case GIMP_INDEXED_IMAGE:
format = gimp_drawable_get_format (drawable); format = gimp_drawable_get_format (drawable);
cmap = gimp_image_get_colormap (image, NULL, &colors); cmap = gimp_palette_get_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), &colors, NULL);
MapSize = 4 * colors; MapSize = 4 * colors;
if (drawable_type == GIMP_INDEXEDA_IMAGE) if (drawable_type == GIMP_INDEXEDA_IMAGE)

View file

@ -1016,7 +1016,7 @@ ReadImage (FILE *fd,
g_free (dest); g_free (dest);
if ((! gray) && (bpp <= 8)) if ((! gray) && (bpp <= 8))
gimp_image_set_colormap (image, gimp_cmap, ncols); gimp_palette_set_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), gimp_cmap, ncols * 3);
gimp_progress_update (1.0); gimp_progress_update (1.0);

View file

@ -146,7 +146,7 @@ read_dds (GFile *file,
GimpPrecision precision = GIMP_PRECISION_U8_NON_LINEAR; GimpPrecision precision = GIMP_PRECISION_U8_NON_LINEAR;
gboolean read_mipmaps; gboolean read_mipmaps;
gboolean flip_import; gboolean flip_import;
gint i, j; gint i;
if (interactive) if (interactive)
{ {
@ -516,6 +516,10 @@ read_dds (GFile *file,
/* Read palette for indexed DDS */ /* Read palette for indexed DDS */
if (load_info.fmt_flags & DDPF_PALETTEINDEXED8) if (load_info.fmt_flags & DDPF_PALETTEINDEXED8)
{ {
const Babl *format = babl_format ("R'G'B' u8");
GimpPalette *palette = gimp_image_get_palette (image);
GeglColor *color = gegl_color_new (NULL);
load_info.palette = g_malloc (256 * 4); load_info.palette = g_malloc (256 * 4);
if (fread (load_info.palette, 1, 1024, fp) != 1024) if (fread (load_info.palette, 1, 1024, fp) != 1024)
{ {
@ -525,13 +529,19 @@ read_dds (GFile *file,
gimp_image_delete (image); gimp_image_delete (image);
return GIMP_PDB_EXECUTION_ERROR; return GIMP_PDB_EXECUTION_ERROR;
} }
for (i = j = 0; i < 768; i += 3, j += 4) for (i = 0; i < 1024; i += 4)
{ {
load_info.palette[i + 0] = load_info.palette[j + 0]; gint entry_num;
load_info.palette[i + 1] = load_info.palette[j + 1];
load_info.palette[i + 2] = load_info.palette[j + 2]; /* Looks like DDS indexed images have an alpha channel (or
* what else is this fourth byte?) and we just ignore it since
* our own palette colors are opaque?
*/
gegl_color_set_pixel (color, format, &load_info.palette[i]);
gimp_palette_add_entry (palette, NULL, color, &entry_num);
} }
gimp_image_set_colormap (image, load_info.palette, 256);
g_object_unref (color);
} }
load_info.tile_height = gimp_tile_height (); load_info.tile_height = gimp_tile_height ();

View file

@ -877,7 +877,7 @@ write_layer (FILE *fp,
if (basetype == GIMP_INDEXED) if (basetype == GIMP_INDEXED)
{ {
palette = gimp_image_get_colormap (image, NULL, &colors); palette = gimp_palette_get_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), &colors, NULL);
if (type == GIMP_INDEXEDA_IMAGE) if (type == GIMP_INDEXEDA_IMAGE)
{ {
@ -1206,7 +1206,7 @@ write_volume_mipmaps (FILE *fp,
format = babl_format ("R'G'B'A u8"); format = babl_format ("R'G'B'A u8");
if (gimp_image_get_base_type (image) == GIMP_INDEXED) if (gimp_image_get_base_type (image) == GIMP_INDEXED)
palette = gimp_image_get_colormap (image, NULL, &colors); palette = gimp_palette_get_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), &colors, NULL);
offset = 0; offset = 0;
for (i = 0, list = layers; for (i = 0, list = layers;
@ -1652,7 +1652,7 @@ write_image (FILE *fp,
(compression == DDS_COMPRESS_NONE)) (compression == DDS_COMPRESS_NONE))
{ {
const guchar zero[4] = {0, 0, 0, 0}; const guchar zero[4] = {0, 0, 0, 0};
cmap = gimp_image_get_colormap (image, NULL, &colors); cmap = gimp_palette_get_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), &colors, NULL);
for (i = 0; i < colors; ++i) for (i = 0; i < colors; ++i)
{ {

View file

@ -624,7 +624,7 @@ load_image (GFile *file,
gimp_progress_update ((double) cnt + 1 / (double)(to_frame - from_frame)); gimp_progress_update ((double) cnt + 1 / (double)(to_frame - from_frame));
} }
gimp_image_set_colormap (image, cm, 256); gimp_palette_set_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), cm, 256 * 3);
fclose (fp); fclose (fp);
@ -726,7 +726,7 @@ export_image (GFile *file,
case GIMP_INDEXED: case GIMP_INDEXED:
max = MAXDIFF; max = MAXDIFF;
bg = 0; bg = 0;
cmap = gimp_image_get_colormap (image, NULL, &colors); cmap = gimp_palette_get_colormap (gimp_image_get_palette (image), babl_format ("R'G'B' u8"), &colors, NULL);
for (i = 0; i < MIN (colors, 256); i++) for (i = 0; i < MIN (colors, 256); i++)
{ {
cm[i*3+0] = cmap[i*3+0]; cm[i*3+0] = cmap[i*3+0];

View file

@ -1635,8 +1635,9 @@ add_color_map (GimpImage *image,
{ {
if (img_a->color_mode != PSD_DUOTONE) if (img_a->color_mode != PSD_DUOTONE)
{ {
gimp_image_set_colormap (image, img_a->color_map, gimp_palette_set_colormap (gimp_image_get_palette (image),
img_a->color_map_entries); babl_format ("R'G'B' u8"),
img_a->color_map, img_a->color_map_len);
} }
else else
{ {

View file

@ -1504,7 +1504,9 @@ load_image (GimpProcedure *procedure,
} }
} }
gimp_image_set_colormap (*image, cmap, (1 << bps)); gimp_palette_set_colormap (gimp_image_get_palette (*image),
babl_format ("R'G'B' u8"),
cmap, (1 << bps) * 3);
} }
if (extra > 99) if (extra > 99)