GRAPHICS: Make convertTo() work with incomplete palettes

We we always assuming that the provided palette is 256 bytes long,
up to the point that we hardcoded this value and skipped this parameter
almost everywhere.

This changes the default parameter to 256 and allows the lesser values
be passed.
This commit is contained in:
Eugene Sandulenko 2024-05-01 22:39:16 +02:00
parent 5642e2cead
commit ff24083fd4
No known key found for this signature in database
GPG Key ID: 014D387312D34F08
2 changed files with 2 additions and 2 deletions

View File

@ -565,7 +565,7 @@ Graphics::Surface *Surface::convertTo(const PixelFormat &dstFormat, const byte *
assert(srcPalette);
uint32 map[256];
convertPaletteToMap(map, srcPalette, 256, dstFormat);
convertPaletteToMap(map, srcPalette, srcPaletteCount, dstFormat);
crossBlitMap(dst, src, surface->pitch, pitch, w, h, dstFormat.bytesPerPixel, map);
} else {
// Converting from high color to high color

View File

@ -388,7 +388,7 @@ public:
* @param dstaletteCount The color count in the for the dstPalette.
* @param method The dithering method if destination format has a bpp of 1. Default is Floyd-Steinberg.
*/
Graphics::Surface *convertTo(const PixelFormat &dstFormat, const byte *srcPalette = 0, int srcPaletteCount = 0, const byte *dstPalette = 0, int dstPaletteCount = 0, DitherMethod method = kDitherFloyd) const;
Graphics::Surface *convertTo(const PixelFormat &dstFormat, const byte *srcPalette = 0, int srcPaletteCount = 256, const byte *dstPalette = 0, int dstPaletteCount = 0, DitherMethod method = kDitherFloyd) const;
protected:
void ditherFloyd(const byte *srcPalette, int srcPaletteCount, Surface *dstSurf, const byte *dstPalette, int dstPaletteCount, DitherMethod method, const PixelFormat &dstFormat) const;