Fix remapping decoded gif files to the global colormap when mask != 0

This commit is contained in:
David Capello 2015-07-31 13:32:23 -03:00
parent 3d70c0193d
commit cc90c3e6f4
5 changed files with 55 additions and 16 deletions

View File

@ -669,7 +669,9 @@ private:
}
Remap remap = create_remap_to_change_palette(
oldPalette, &newPalette, m_bgIndex);
oldPalette, &newPalette, m_bgIndex,
false); // We cannot remap the transparent color, because we
// cannot write the header again
for (Cel* cel : m_sprite->uniqueCels())
doc::remap_image(cel->image(), remap);

View File

@ -445,7 +445,8 @@ void ColorBar::onRemapButtonClick()
return;
remap = create_remap_to_change_palette(
m_oldPalette, get_current_palette(), sprite->transparentColor());
m_oldPalette, get_current_palette(),
sprite->transparentColor(), true);
}
catch (base::Exception& e) {
Console::showException(e);

View File

@ -67,22 +67,30 @@ Remap create_remap_to_expand_palette(int size, int count, int beforeIndex)
Remap create_remap_to_change_palette(
const Palette* oldPalette, const Palette* newPalette,
const int oldMaskIndex)
const int oldMaskIndex,
const bool remapMaskIndex)
{
Remap remap(MAX(oldPalette->size(), newPalette->size()));
int maskIndex = oldMaskIndex;
if (maskIndex >= 0) {
color_t maskColor = oldPalette->getEntry(maskIndex);
int r = rgba_getr(maskColor);
int g = rgba_getg(maskColor);
int b = rgba_getb(maskColor);
int a = rgba_geta(maskColor);
if (remapMaskIndex &&
oldPalette->getEntry(maskIndex) !=
newPalette->getEntry(maskIndex)) {
color_t maskColor = oldPalette->getEntry(maskIndex);
int r = rgba_getr(maskColor);
int g = rgba_getg(maskColor);
int b = rgba_getb(maskColor);
int a = rgba_geta(maskColor);
// Find the new mask color
maskIndex = newPalette->findExactMatch(r, g, b, a, -1);
if (maskIndex >= 0)
remap.map(oldMaskIndex, maskIndex);
// Find the new mask color
maskIndex = newPalette->findExactMatch(r, g, b, a, -1);
if (maskIndex >= 0)
remap.map(oldMaskIndex, maskIndex);
}
else {
remap.map(maskIndex, maskIndex);
}
}
RgbMap rgbmap;

View File

@ -68,7 +68,8 @@ namespace doc {
Remap create_remap_to_change_palette(
const Palette* oldPalette, const Palette* newPalette,
const int oldMaskIndex);
const int oldMaskIndex,
const bool remapMaskIndex);
} // namespace doc

View File

@ -123,7 +123,7 @@ TEST(Remap, BetweenPalettesChangeMask)
b.setEntry(2, rgba(0, 0, 255, 255));
b.setEntry(3, rgba(255, 0, 0, 255));
Remap map = create_remap_to_change_palette(&a, &b, 0);
Remap map = create_remap_to_change_palette(&a, &b, 0, true);
EXPECT_EQ(3, map[0]);
EXPECT_EQ(1, map[1]);
@ -150,7 +150,34 @@ TEST(Remap, BetweenPalettesDontChangeMask)
b.setEntry(2, rgba(0, 0, 0, 255));
b.setEntry(3, rgba(0, 0, 0, 255));
Remap map = create_remap_to_change_palette(&a, &b, 2);
Remap map = create_remap_to_change_palette(&a, &b, 2, true);
EXPECT_EQ(3, map[0]);
EXPECT_EQ(1, map[1]);
EXPECT_EQ(2, map[2]);
EXPECT_EQ(0, map[3]);
PalettePicks all(map.size());
all.all();
EXPECT_TRUE(map.isInvertible(all));
}
TEST(Remap, BetweenPalettesDontChangeMaskForced)
{
Palette a(frame_t(0), 4);
Palette b(frame_t(0), 4);
a.setEntry(0, rgba(0, 0, 0, 255));
a.setEntry(1, rgba(0, 255, 255, 255));
a.setEntry(2, rgba(0, 0, 0, 255));
a.setEntry(3, rgba(255, 0, 0, 255));
b.setEntry(0, rgba(255, 0, 0, 255));
b.setEntry(1, rgba(0, 255, 255, 255));
b.setEntry(2, rgba(0, 0, 0, 255));
b.setEntry(3, rgba(0, 0, 0, 255));
Remap map = create_remap_to_change_palette(&a, &b, 2, false);
EXPECT_EQ(3, map[0]);
EXPECT_EQ(1, map[1]);
@ -176,7 +203,7 @@ TEST(Remap, BetweenPalettesNonInvertible)
b.setEntry(1, rgba(0, 0, 0, 255));
b.setEntry(2, rgba(64, 0, 0, 255));
Remap map = create_remap_to_change_palette(&a, &b, 0);
Remap map = create_remap_to_change_palette(&a, &b, 0, true);
EXPECT_EQ(1, map[0]);
EXPECT_EQ(2, map[1]);