Fix problem saving transparent GIF and PNG files when the background layer is hidden

This commit is contained in:
David Capello 2015-04-21 10:01:28 -03:00
parent e17804e9ff
commit 9fa26dc2f4
3 changed files with 10 additions and 7 deletions

View File

@ -535,7 +535,7 @@ bool GifFormat::onSave(FileOp* fop)
PixelFormat sprite_format = sprite->pixelFormat(); PixelFormat sprite_format = sprite->pixelFormat();
bool interlaced = gif_options->interlaced(); bool interlaced = gif_options->interlaced();
int loop = (gif_options->loop() ? 0: -1); int loop = (gif_options->loop() ? 0: -1);
bool has_background = (sprite->backgroundLayer() ? true: false); bool has_background = (sprite->backgroundLayer() && sprite->backgroundLayer()->isVisible());
int background_color = (sprite_format == IMAGE_INDEXED ? sprite->transparentColor(): 0); int background_color = (sprite_format == IMAGE_INDEXED ? sprite->transparentColor(): 0);
int transparent_index = (has_background ? -1: sprite->transparentColor()); int transparent_index = (has_background ? -1: sprite->transparentColor());

View File

@ -414,10 +414,11 @@ bool PngFormat::onSave(FileOp* fop)
png_set_PLTE(png_ptr, info_ptr, palette, PNG_MAX_PALETTE_LENGTH); png_set_PLTE(png_ptr, info_ptr, palette, PNG_MAX_PALETTE_LENGTH);
// If the sprite does not have a background layer, we include the // If the sprite does not have a (visible) background layer, we
// alpha information of palette entries to indicate which is the // include the alpha information of palette entries to indicate
// transparent color. // which is the transparent color.
if (fop->document->sprite()->backgroundLayer() == NULL) { if (fop->document->sprite()->backgroundLayer() == NULL ||
!fop->document->sprite()->backgroundLayer()->isVisible()) {
int mask_entry = fop->document->sprite()->transparentColor(); int mask_entry = fop->document->sprite()->transparentColor();
int num_trans = mask_entry+1; int num_trans = mask_entry+1;
png_bytep trans = (png_bytep)png_malloc(png_ptr, num_trans); png_bytep trans = (png_bytep)png_malloc(png_ptr, num_trans);

View File

@ -150,8 +150,10 @@ bool Sprite::needAlpha() const
{ {
switch (m_format) { switch (m_format) {
case IMAGE_RGB: case IMAGE_RGB:
case IMAGE_GRAYSCALE: case IMAGE_GRAYSCALE: {
return (backgroundLayer() == NULL); Layer* bg = backgroundLayer();
return (!bg || !bg->isVisible());
}
} }
return false; return false;
} }