Merge branch 'main' into beta

This commit is contained in:
David Capello 2021-05-23 13:16:36 -03:00
commit 963602444f
8 changed files with 58 additions and 27 deletions

View File

@ -53,7 +53,7 @@ Aseprite is being developed by [Igara Studio](https://www.igarastudio.com/):
* [David Capello](https://davidcapello.com/) * [David Capello](https://davidcapello.com/)
* [Gaspar Capello](https://github.com/Gasparoken) * [Gaspar Capello](https://github.com/Gasparoken)
* [Martin Capello](https://github.com/martincapello) * [Martín Capello](https://github.com/martincapello)
## Credits ## Credits

View File

@ -12,7 +12,7 @@
<separator text="Developer Team" horizontal="true" /> <separator text="Developer Team" horizontal="true" />
<link text="David Capello" url="https://twitter.com/davidcapello" /> <link text="David Capello" url="https://twitter.com/davidcapello" />
<link text="Gaspar Capello" url="https://twitter.com/Gasparoken" /> <link text="Gaspar Capello" url="https://twitter.com/Gasparoken" />
<link text="Martin Capello" url="https://twitter.com/martincapell0" /> <link text="Martín Capello" url="https://twitter.com/martincapell0" />
<vbox minheight="8" /> <vbox minheight="8" />
</vbox> </vbox>
<separator vertical="true" /> <separator vertical="true" />

View File

@ -831,6 +831,12 @@ void ColorBar::onRemapPalButtonClick()
} }
if (remap.isInvertible(usedEntries)) { 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)); tx(new cmd::RemapColors(sprite, remap));
remapPixels = false; remapPixels = false;
} }

View File

@ -119,6 +119,9 @@ void ColorButton::onInitTheme(InitThemeEvent& ev)
{ {
ButtonBase::onInitTheme(ev); ButtonBase::onInitTheme(ev);
setStyle(SkinTheme::instance()->styles.colorButton()); setStyle(SkinTheme::instance()->styles.colorButton());
if (m_window)
m_window->initTheme();
} }
bool ColorButton::onProcessMessage(Message* msg) bool ColorButton::onProcessMessage(Message* msg)

View File

@ -806,7 +806,7 @@ static void remove_unused_tiles_from_tileset(
modifiedTileIndexes[ti]) { modifiedTileIndexes[ti]) {
cmds->executeAndAdd(new cmd::RemoveTile(tileset, tj)); cmds->executeAndAdd(new cmd::RemoveTile(tileset, tj));
// Map to nothing, so the map can be invertible // Map to nothing, so the map can be invertible
remap.map(ti, doc::Remap::kNoMap); remap.notile(ti);
} }
else { else {
remap.map(ti, tj++); remap.map(ti, tj++);

View File

@ -423,17 +423,24 @@ void remap_image(Image* image, const Remap& remap)
case IMAGE_INDEXED: case IMAGE_INDEXED:
transform_image<IndexedTraits>( transform_image<IndexedTraits>(
image, [&remap](color_t c) -> color_t { image, [&remap](color_t c) -> color_t {
return remap[c]; auto to = remap[c];
}); if (to != Remap::kUnused)
return to;
else
return c;
});
break; break;
case IMAGE_TILEMAP: case IMAGE_TILEMAP:
transform_image<TilemapTraits>( transform_image<TilemapTraits>(
image, [&remap](color_t c) -> color_t { image, [&remap](color_t c) -> color_t {
if (c == notile || remap[c] == Remap::kNoMap) auto to = remap[c];
return notile; if (c == notile || to == Remap::kNoTile)
else return notile;
return remap[c]; else if (to != Remap::kUnused)
}); return to;
else
return c;
});
break; break;
} }
} }

View File

@ -139,21 +139,19 @@ Remap Remap::invert() const
Remap inv(size()); Remap inv(size());
for (int i=0; i<size(); ++i) for (int i=0; i<size(); ++i)
inv.m_map[i] = kNoMap; inv.unused(i);
for (int i=0; i<size(); ++i) { for (int i=0; i<size(); ++i) {
int j = m_map[i]; int j = m_map[i];
if (j == kNoMap || if (j == kUnused ||
// Already mapped j == kNoTile ||
inv.m_map[j] != kNoMap) inv.m_map[j] != kUnused) { // Already mapped (strange case, we
// cannot invert this Remap)
continue; continue;
}
inv.map(j, i); inv.map(j, i);
} }
for (int i=0; i<size(); ++i)
if (inv.m_map[i] == kNoMap)
inv.m_map[i] = i;
return inv; return inv;
} }
@ -178,8 +176,10 @@ bool Remap::isInvertible(const PalettePicks& usedEntries) const
continue; continue;
int j = m_map[i]; int j = m_map[i];
if (j == kNoMap) if (j == kUnused ||
j == kNoTile) {
continue; continue;
}
if (picks[j]) if (picks[j])
return false; return false;
@ -192,8 +192,11 @@ bool Remap::isInvertible(const PalettePicks& usedEntries) const
bool Remap::isIdentity() const bool Remap::isIdentity() const
{ {
for (int i=0; i<size(); ++i) { for (int i=0; i<size(); ++i) {
if (m_map[i] != i) int j = m_map[i];
if (j != i &&
j != kUnused) {
return false; return false;
}
} }
return true; return true;
} }

View File

@ -1,5 +1,5 @@
// Aseprite Document Library // Aseprite Document Library
// Copyright (C) 2019 Igara Studio S.A. // Copyright (C) 2019-2021 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2017 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -19,7 +19,13 @@ namespace doc {
class Remap { class Remap {
public: public:
static const int kNoMap = -1; // Unused is like a "no map" operation, we don't want to remap
// this entry.
constexpr static const int kUnused = -1;
// NoTile is to specify that we want to remap a tile to the
// doc::notile value.
constexpr static const int kNoTile = -2;
Remap(int entries = 1) : m_map(entries, 0) { } Remap(int entries = 1) : m_map(entries, 0) { }
@ -30,14 +36,20 @@ namespace doc {
// Maps input "fromIndex" value, to "toIndex" output. // Maps input "fromIndex" value, to "toIndex" output.
void map(int fromIndex, int toIndex) { void map(int fromIndex, int toIndex) {
ASSERT(fromIndex >= 0 && fromIndex < size()); ASSERT(fromIndex >= 0 && fromIndex < size());
// toIndex = kNoMap means (there is no remap for this value, useful ASSERT(toIndex >= 0 && toIndex < size());
// to ignore this entry when we invert the map)
ASSERT((toIndex == kNoMap) ||
(toIndex >= 0 && toIndex < size()));
m_map[fromIndex] = toIndex; m_map[fromIndex] = toIndex;
} }
void unused(int i) {
ASSERT(i >= 0 && i < size());
m_map[i] = kUnused;
}
void notile(int i) {
ASSERT(i >= 0 && i < size());
m_map[i] = kNoTile;
}
int operator[](int index) const { int operator[](int index) const {
//ASSERT(index >= 0 && index < size()); //ASSERT(index >= 0 && index < size());
if (index >= 0 && index < size()) if (index >= 0 && index < size())