diff --git a/src/libImaging/Convert.c b/src/libImaging/Convert.c index 5dc17db60..f0d42f7ff 100644 --- a/src/libImaging/Convert.c +++ b/src/libImaging/Convert.c @@ -1026,6 +1026,14 @@ pa2l(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) { } } +static void +pa2p(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) { + int x; + for (x = 0; x < xsize; x++, in += 4) { + *out++ = in[0]; + } +} + static void p2pa(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) { int x; @@ -1209,6 +1217,8 @@ frompalette(Imaging imOut, Imaging imIn, const char *mode) { convert = alpha ? pa2l : p2l; } else if (strcmp(mode, "LA") == 0) { convert = alpha ? pa2la : p2la; + } else if (strcmp(mode, "P") == 0) { + convert = pa2p; } else if (strcmp(mode, "PA") == 0) { convert = p2pa; } else if (strcmp(mode, "I") == 0) { @@ -1233,6 +1243,10 @@ frompalette(Imaging imOut, Imaging imIn, const char *mode) { if (!imOut) { return NULL; } + if (strcmp(mode, "P") == 0) { + ImagingPaletteDelete(imOut->palette); + imOut->palette = ImagingPaletteDuplicate(imIn->palette); + } ImagingSectionEnter(&cookie); for (y = 0; y < imIn->ysize; y++) {