diff --git a/src/app/cmd/set_palette.cpp b/src/app/cmd/set_palette.cpp index aa8b1be10..bfda55dd5 100644 --- a/src/app/cmd/set_palette.cpp +++ b/src/app/cmd/set_palette.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2020 Igara Studio S.A. +// Copyright (C) 2019-2021 Igara Studio S.A. // Copyright (C) 2001-2015 David Capello // // This program is distributed under the terms of @@ -53,6 +53,13 @@ SetPalette::SetPalette(Sprite* sprite, frame_t frame, const Palette* newPalette) m_newColors[i] = newPalette->getEntry(m_from+i); } } + if (sprite->pixelFormat() == IMAGE_INDEXED) { + m_oldTransparentIndex = sprite->transparentColor(); + if (m_oldTransparentIndex >= newPalette->size()) + m_newTransparentIndex = newPalette->size() -1; + else + m_newTransparentIndex = m_oldTransparentIndex; + } } void SetPalette::onExecute() @@ -64,6 +71,7 @@ void SetPalette::onExecute() for (size_t i=0; isetEntry(m_from+i, m_newColors[i]); + sprite->setTransparentColor(m_newTransparentIndex); palette->incrementVersion(); } @@ -76,6 +84,7 @@ void SetPalette::onUndo() for (size_t i=0; isetEntry(m_from+i, m_oldColors[i]); + sprite->setTransparentColor(m_oldTransparentIndex); palette->incrementVersion(); } diff --git a/src/app/cmd/set_palette.h b/src/app/cmd/set_palette.h index bd8a6a9a9..9bcab58e3 100644 --- a/src/app/cmd/set_palette.h +++ b/src/app/cmd/set_palette.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019 Igara Studio S.A. +// Copyright (C) 2019-2021 Igara Studio S.A. // Copyright (C) 2001-2015 David Capello // // This program is distributed under the terms of @@ -45,6 +45,8 @@ namespace cmd { int m_from, m_to; int m_oldNColors; int m_newNColors; + int m_oldTransparentIndex; + int m_newTransparentIndex; std::vector m_oldColors; std::vector m_newColors; }; diff --git a/src/app/ui/color_bar.cpp b/src/app/ui/color_bar.cpp index 7435600da..c235e95c0 100644 --- a/src/app/ui/color_bar.cpp +++ b/src/app/ui/color_bar.cpp @@ -578,7 +578,9 @@ void ColorBar::onRemapButtonClick() } color_t oldTransparent = sprite->transparentColor(); - color_t newTransparent = remap[oldTransparent]; + color_t newTransparent = (remap[oldTransparent] >= 0) ? remap[oldTransparent] : oldTransparent; + if (newTransparent >= get_current_palette()->size()) + newTransparent = get_current_palette()->size() - 1; if (oldTransparent != newTransparent) tx(new cmd::SetTransparentColor(sprite, newTransparent));