diff --git a/docs/ase-file-specs.md b/docs/ase-file-specs.md index 8442ca9bb..18ff5b247 100644 --- a/docs/ase-file-specs.md +++ b/docs/ase-file-specs.md @@ -126,9 +126,12 @@ at least. ### Old palette chunk (0x0004) -Ignore this chunk if you find the new palette chunk (0x2019) Aseprite -v1.1 saves both chunks 0x0004 and 0x2019 just for backward -compatibility. +Ignore this chunk if you find the new palette chunk (0x2019). Aseprite +v1.1 saves both chunks (0x0004 and 0x2019) just for backward +compatibility. Aseprite v1.3.5 writes this chunk if the palette +doesn't have alpha channel and contains 256 colors or less (because +this chunk is smaller), in other case the new palette chunk (0x2019) +will be used (and the old one is not saved anymore). WORD Number of packets + For each packet diff --git a/src/app/file/ase_format.cpp b/src/app/file/ase_format.cpp index 8ca37ff26..20fd02588 100644 --- a/src/app/file/ase_format.cpp +++ b/src/app/file/ase_format.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2023 Igara Studio S.A. +// Copyright (C) 2018-2024 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -355,7 +355,7 @@ bool AseFormat::onSave(FileOp* fop) bool require_new_palette_chunk = false; for (Palette* pal : sprite->getPalettes()) { - if (pal->size() != 256 || pal->hasAlpha()) { + if (pal->size() > 256 || pal->hasAlpha()) { require_new_palette_chunk = true; break; } @@ -393,9 +393,12 @@ bool AseFormat::onSave(FileOp* fop) ase_file_write_palette_chunk(f, &frame_header, pal, palFrom, palTo); } - - // Write color chunk for backward compatibility only - ase_file_write_color2_chunk(f, &frame_header, pal); + else { + // Use old color chunk only when the palette has 256 or less + // colors, and we don't need the alpha channel (as this chunk + // is smaller than the new palette chunk). + ase_file_write_color2_chunk(f, &frame_header, pal); + } } // Write extra chunks in the first frame @@ -676,6 +679,7 @@ static void ase_file_write_color2_chunk(FILE* f, dio::AsepriteFrameHeader* frame // First packet fputc(0, f); // skip 0 colors + ASSERT(pal->size() <= 256); // For >256 we use the palette chunk fputc(pal->size() == 256 ? 0: pal->size(), f); // number of colors for (c=0; csize(); c++) { color = pal->getEntry(c);