Fix saving/loading .gif files w/completely opaque images but with local transparent index

There are .gif files that specified a local transparent index
but the frame pixels don't use that index (i.e. the frame is completely
opaque anyway). The same happens when we use a transparent layer but the
transparent color is not used (i.e. the layer is completely opaque anyway).
With this patch we fix loading/saving correctly this kind of files/sprites.

Fix #800
This commit is contained in:
David Capello 2015-09-22 14:39:47 -03:00
parent bab13c4739
commit 3dfd6de4f0

View File

@ -434,6 +434,14 @@ private:
// Get the list of used palette entries
PalettePicks usedEntries(ncolors);
if (isLocalColormap) {
// With this we avoid discarding the transparent index when a
// frame indicates that it uses a specific index as transparent
// but the image is completely opaque anyway.
if (m_localTransparentIndex >= 0 &&
m_localTransparentIndex < ncolors) {
usedEntries[m_localTransparentIndex] = true;
}
for (const auto& i : LockImageBits<IndexedTraits>(frameImage)) {
if (i >= 0 && i < ncolors)
usedEntries[i] = true;
@ -1021,6 +1029,18 @@ private:
// Convert the frameBounds area of m_currentImage (RGB) to frameImage (Indexed)
// bool needsTransparent = false;
PalettePicks usedColors(framePalette->size());
// If the sprite needs a transparent color we mark it as used so
// the palette includes a spot for it. It doesn't matter if the
// image doesn't use the transparent index, if the sprite isn't
// opaque we need the transparent index anyway.
if (m_transparentIndex >= 0) {
int i = m_transparentIndex;
if (i >= usedColors.size())
usedColors.resize(i+1);
usedColors[i] = true;
}
{
LockImageBits<RgbTraits> bits(m_currentImage, frameBounds);
auto it = bits.begin();