From c3d36d35987350f9f0978b94a8e9eaec84cf3bc2 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 17 Sep 2014 10:08:19 -0300 Subject: [PATCH] Save color palette in RGB .ase files (fix #487) --- docs/files/ase.txt | 9 ++++----- src/app/file/ase_format.cpp | 33 +++++++++++++-------------------- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/docs/files/ase.txt b/docs/files/ase.txt index e3b8e2873..cb55ef088 100644 --- a/docs/files/ase.txt +++ b/docs/files/ase.txt @@ -1,5 +1,5 @@ ASE Files (.ASE) Format description -Copyright (C) 2001-2013 by David Capello +Copyright (C) 2001-2014 by David Capello ---------------------------------------------------------------------- 1. References @@ -39,10 +39,9 @@ PIXEL Pixel format: The format is much like FLI/FLC files, but with different magic number and differents chunks. Also, the color depth can be 8, 16 or 32 for Indexed, Grayscale and RGB respectively, and the images are more easy -to read (there aren't differences with old frames). The palette isn't -included for color depths more than 8, but when the sprite is 8 bpp, -the palette is in a FLI color chunk (it could be type=11 or type=4). -See fli.txt for details. +to read (there aren't differences with old frames). Color palettes +are in FLI color chunks (it could be type=11 or type=4). For color +depths more than 8bpp, palettes are optional. See fli.txt for details. To read the sprite, just do this: * Read the ASE header (section 3) diff --git a/src/app/file/ase_format.cpp b/src/app/file/ase_format.cpp index 5a781d914..9eb443c94 100644 --- a/src/app/file/ase_format.cpp +++ b/src/app/file/ase_format.cpp @@ -1,5 +1,5 @@ /* Aseprite - * Copyright (C) 2001-2013 David Capello + * Copyright (C) 2001-2014 David Capello * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -211,25 +211,19 @@ bool AseFormat::onLoad(FileOp* fop) /* only for 8 bpp images */ case ASE_FILE_CHUNK_FLI_COLOR: - case ASE_FILE_CHUNK_FLI_COLOR2: - /* fop_error(fop, "Color chunk\n"); */ + case ASE_FILE_CHUNK_FLI_COLOR2: { + Palette* prev_pal = sprite->getPalette(frame); + Palette* pal = + chunk_type == ASE_FILE_CHUNK_FLI_COLOR ? + ase_file_read_color_chunk(f, sprite, frame): + ase_file_read_color2_chunk(f, sprite, frame); - if (sprite->pixelFormat() == IMAGE_INDEXED) { - Palette* prev_pal = sprite->getPalette(frame); - Palette* pal = - chunk_type == ASE_FILE_CHUNK_FLI_COLOR ? - ase_file_read_color_chunk(f, sprite, frame): - ase_file_read_color2_chunk(f, sprite, frame); + if (prev_pal->countDiff(pal, NULL, NULL) > 0) + sprite->setPalette(pal, true); - if (prev_pal->countDiff(pal, NULL, NULL) > 0) { - sprite->setPalette(pal, true); - } - - delete pal; - } - else - fop_error(fop, "Warning: was found a color chunk in non-8bpp file\n"); + delete pal; break; + } case ASE_FILE_CHUNK_LAYER: { /* fop_error(fop, "Layer chunk\n"); */ @@ -320,9 +314,8 @@ bool AseFormat::onSave(FileOp* fop) // Frame duration frame_header.duration = sprite->getFrameDuration(frame); - // The sprite is indexed and the palette changes? (or is the first frame) - if (sprite->pixelFormat() == IMAGE_INDEXED && - (frame == 0 || + // is the first frame or did the palette change? + if ((frame == 0 || sprite->getPalette(frame.previous())->countDiff(sprite->getPalette(frame), NULL, NULL) > 0)) { // Write the color chunk ase_file_write_color2_chunk(f, &frame_header, sprite->getPalette(frame));