mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-10 15:40:31 +00:00
Fix export sprite sheet to RGB is not exporting the palette (fix #3881)
This commit is contained in:
parent
81b5378f25
commit
309a64de9f
@ -1180,10 +1180,13 @@ Doc* DocExporter::createEmptyTexture(const Samples& samples,
|
||||
base::task_token& token) const
|
||||
{
|
||||
ColorMode colorMode = ColorMode::INDEXED;
|
||||
Palette* palette = nullptr;
|
||||
Palette palette(0, 0);
|
||||
int maxColors = 256;
|
||||
gfx::ColorSpaceRef colorSpace;
|
||||
color_t transparentColor = 0;
|
||||
const bool textureSupportsPalette =
|
||||
(m_textureFilename.empty() || // This is the preview and we create the palette anyway
|
||||
format_supports_palette(m_textureFilename));
|
||||
|
||||
for (const auto& sample : samples) {
|
||||
if (token.canceled())
|
||||
@ -1210,15 +1213,22 @@ Doc* DocExporter::createEmptyTexture(const Samples& samples,
|
||||
else if (sample.sprite()->getPalettes().size() > 1) {
|
||||
colorMode = ColorMode::RGB;
|
||||
}
|
||||
else if (palette &&
|
||||
palette->countDiff(sample.sprite()->palette(frame_t(0)),
|
||||
nullptr, nullptr) > 0) {
|
||||
else if (palette.size() > 0 &&
|
||||
palette.countDiff(sample.sprite()->palette(frame_t(0)),
|
||||
nullptr, nullptr) > 0) {
|
||||
colorMode = ColorMode::RGB;
|
||||
}
|
||||
else if (!palette) {
|
||||
palette = sample.sprite()->palette(frame_t(0));
|
||||
else if (palette.size() == 0) {
|
||||
palette = *sample.sprite()->palette(frame_t(0));
|
||||
transparentColor = sample.sprite()->transparentColor();
|
||||
}
|
||||
if (colorMode == ColorMode::RGB &&
|
||||
textureSupportsPalette &&
|
||||
sample.sprite() &&
|
||||
sample.sprite()->getPalettes()[0]) {
|
||||
Palette* samplePalette = sample.sprite()->getPalettes()[0];
|
||||
palette.addNonRepeatedColors(samplePalette);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1236,8 +1246,8 @@ Doc* DocExporter::createEmptyTexture(const Samples& samples,
|
||||
maxColors,
|
||||
m_docBuf));
|
||||
|
||||
if (palette)
|
||||
sprite->setPalette(palette, false);
|
||||
if (palette.size() > 0)
|
||||
sprite->setPalette(&palette, false);
|
||||
|
||||
std::unique_ptr<Doc> document(new Doc(sprite.get()));
|
||||
sprite.release();
|
||||
|
@ -286,6 +286,16 @@ bool is_static_image_format(const std::string& filename)
|
||||
return (format && format->support(FILE_SUPPORT_SEQUENCES));
|
||||
}
|
||||
|
||||
bool format_supports_palette(const std::string& filename)
|
||||
{
|
||||
// Get the format through the extension of the filename
|
||||
FileFormat* format =
|
||||
FileFormatsManager::instance()
|
||||
->getFileFormat(dio::detect_format_by_file_extension(filename));
|
||||
|
||||
return (format && format->support(FILE_SUPPORT_PALETTES));
|
||||
}
|
||||
|
||||
FileOpROI::FileOpROI()
|
||||
: m_document(nullptr)
|
||||
, m_slice(nullptr)
|
||||
|
@ -365,6 +365,9 @@ namespace app {
|
||||
// as sequence of files).
|
||||
bool is_static_image_format(const std::string& filename);
|
||||
|
||||
// Returns true if the given file format supports palette/s
|
||||
bool format_supports_palette(const std::string& filename);
|
||||
|
||||
} // namespace app
|
||||
|
||||
#endif
|
||||
|
@ -175,6 +175,22 @@ int Palette::countDiff(const Palette* other, int* from, int* to) const
|
||||
return diff;
|
||||
}
|
||||
|
||||
void Palette::addNonRepeatedColors(const Palette* palette,
|
||||
const int max)
|
||||
{
|
||||
ASSERT(palette);
|
||||
if (!palette || size() >= max)
|
||||
return;
|
||||
for (int i=0; i < palette->size(); i++) {
|
||||
color_t newColor = palette->getEntry(i);
|
||||
if (!findExactMatch(newColor)) {
|
||||
addEntry(newColor);
|
||||
if (size() >= max)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Palette::isBlack() const
|
||||
{
|
||||
for (std::size_t c=0; c<m_colors.size(); ++c)
|
||||
|
@ -86,6 +86,9 @@ namespace doc {
|
||||
|
||||
int countDiff(const Palette* other, int* from, int* to) const;
|
||||
|
||||
void addNonRepeatedColors(const Palette* palette,
|
||||
const int max = 256);
|
||||
|
||||
bool operator==(const Palette& other) const {
|
||||
return (countDiff(&other, nullptr, nullptr) == 0);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user