mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-01 09:04:02 +00:00
Create an optimized palette if GifDecoder generates a RGB image with more than 256 colors
This commit is contained in:
parent
cd1ca4c68f
commit
a6c24ac768
@ -214,8 +214,15 @@ public:
|
||||
m_sprite->palette(0)->resize(m_bgIndex+1);
|
||||
|
||||
// Use the original global color map
|
||||
if (m_gifFile->SColorMap && !m_hasLocalColormaps)
|
||||
if (m_sprite->pixelFormat() == IMAGE_INDEXED &&
|
||||
m_gifFile->SColorMap && !m_hasLocalColormaps) {
|
||||
remapToGlobalColormap();
|
||||
}
|
||||
// Avoid huge color palettes
|
||||
else if (m_sprite->pixelFormat() == IMAGE_RGB &&
|
||||
m_sprite->palette(0)->size() > 256) {
|
||||
reduceToAnOptimizedPalette();
|
||||
}
|
||||
|
||||
if (m_layer && m_opaque)
|
||||
m_layer->configureAsBackground();
|
||||
@ -668,6 +675,20 @@ private:
|
||||
m_sprite->setPalette(&newPalette, false);
|
||||
}
|
||||
|
||||
void reduceToAnOptimizedPalette() {
|
||||
render::PaletteOptimizer optimizer;
|
||||
const Palette* palette = m_sprite->palette(0);
|
||||
|
||||
// Feed the palette optimizer with pixels inside frameBounds
|
||||
for (int i=0; i<palette->size(); ++i) {
|
||||
optimizer.feedWithRgbaColor(palette->getEntry(i));
|
||||
}
|
||||
|
||||
Palette newPalette(0, 256);
|
||||
optimizer.calculate(&newPalette, m_bgIndex, nullptr);
|
||||
m_sprite->setPalette(&newPalette, false);
|
||||
}
|
||||
|
||||
FileOp* m_fop;
|
||||
GifFileType* m_gifFile;
|
||||
int m_fd;
|
||||
|
Loading…
Reference in New Issue
Block a user