mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-14 04:19:12 +00:00
Fix bug undoing a Remap operation when several colors are removed from the palette
This commit is contained in:
parent
83a6797d20
commit
141bc434bf
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2018-2020 Igara Studio S.A.
|
||||
// Copyright (C) 2018-2021 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -553,6 +553,12 @@ void ColorBar::onRemapButtonClick()
|
||||
}
|
||||
|
||||
if (remap.isInvertible(usedEntries)) {
|
||||
for (int i=0; i<remap.size(); ++i) {
|
||||
if (i >= usedEntries.size() || !usedEntries[i]) {
|
||||
remap.unused(i);
|
||||
}
|
||||
}
|
||||
|
||||
tx(new cmd::RemapColors(sprite, remap));
|
||||
remapPixels = false;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite Document Library
|
||||
// Copyright (c) 2018-2019 Igara Studio S.A.
|
||||
// Copyright (c) 2018-2021 Igara Studio S.A.
|
||||
// Copyright (c) 2001-2016 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -407,13 +407,11 @@ void remap_image(Image* image, const Remap& remap)
|
||||
if (image->pixelFormat() != IMAGE_INDEXED)
|
||||
return;
|
||||
|
||||
LockImageBits<IndexedTraits> bits(image);
|
||||
LockImageBits<IndexedTraits>::iterator
|
||||
it = bits.begin(),
|
||||
end = bits.end();
|
||||
|
||||
for (; it != end; ++it)
|
||||
*it = remap[*it];
|
||||
for (auto& pixel : LockImageBits<IndexedTraits>(image)) {
|
||||
auto to = remap[pixel];
|
||||
if (to != Remap::kUnused)
|
||||
pixel = to;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO test this hash routine and find a better alternative
|
||||
|
@ -138,7 +138,11 @@ Remap Remap::invert() const
|
||||
{
|
||||
Remap inv(size());
|
||||
for (int i=0; i<size(); ++i)
|
||||
inv.map(operator[](i), i);
|
||||
inv.unused(i);
|
||||
for (int i=0; i<size(); ++i) {
|
||||
if (operator[](i) != kUnused)
|
||||
inv.map(operator[](i), i);
|
||||
}
|
||||
return inv;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite Document Library
|
||||
// Copyright (c) 2021 Igara Studio S.A.
|
||||
// Copyright (c) 2001-2017 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -18,6 +19,8 @@ namespace doc {
|
||||
|
||||
class Remap {
|
||||
public:
|
||||
constexpr static const int kUnused = -1;
|
||||
|
||||
Remap(int entries = 1) : m_map(entries, 0) { }
|
||||
|
||||
int size() const {
|
||||
@ -32,6 +35,11 @@ namespace doc {
|
||||
m_map[fromIndex] = toIndex;
|
||||
}
|
||||
|
||||
void unused(int i) {
|
||||
ASSERT(i >= 0 && i < size());
|
||||
m_map[i] = kUnused;
|
||||
}
|
||||
|
||||
int operator[](int index) const {
|
||||
//ASSERT(index >= 0 && index < size());
|
||||
if (index >= 0 && index < size())
|
||||
|
Loading…
x
Reference in New Issue
Block a user