diff --git a/src/app/document_api.cpp b/src/app/document_api.cpp index 3374d27ef..56b0508c0 100644 --- a/src/app/document_api.cpp +++ b/src/app/document_api.cpp @@ -173,15 +173,30 @@ void DocumentApi::setPixelFormat(Sprite* sprite, PixelFormat newFormat, Ditherin // Use the rgbmap for the specified sprite const RgbMap* rgbmap = sprite->getRgbMap(frame); + // Get the list of cels from the background layer (if it + // exists). This list will be used to check if each image belong to + // the background layer. + CelList bgCels; + if (sprite->getBackgroundLayer() != NULL) + sprite->getBackgroundLayer()->getCels(bgCels); + for (c=0; cgetStock()->size(); c++) { old_image = sprite->getStock()->getImage(c); if (!old_image) continue; + bool is_image_from_background = false; + for (CelList::iterator it=bgCels.begin(), end=bgCels.end(); it != end; ++it) { + if ((*it)->getImage() == c) { + is_image_from_background = true; + break; + } + } + new_image = quantization::convert_pixel_format (old_image, newFormat, dithering_method, rgbmap, sprite->getPalette(frame), - sprite->getBackgroundLayer() != NULL); + is_image_from_background); replaceStockImage(sprite, c, new_image); } diff --git a/src/raster/quantization.cpp b/src/raster/quantization.cpp index 9d29a34e0..592d3b91f 100644 --- a/src/raster/quantization.cpp +++ b/src/raster/quantization.cpp @@ -89,7 +89,7 @@ Image* convert_pixel_format(const Image* image, DitheringMethod ditheringMethod, const RgbMap* rgbmap, const Palette* palette, - bool has_background_layer) + bool is_background_layer) { // RGB -> Indexed with ordered dithering if (image->getPixelFormat() == IMAGE_RGB && @@ -223,7 +223,7 @@ Image* convert_pixel_format(const Image* image, ASSERT(dst_it != dst_end); c = *src_it; - if (c == 0 && !has_background_layer) + if (!is_background_layer && c == image->getMaskColor()) *dst_it = 0; else *dst_it = rgba(rgba_getr(palette->getEntry(c)), @@ -243,7 +243,7 @@ Image* convert_pixel_format(const Image* image, ASSERT(dst_it != dst_end); c = *src_it; - if (c == 0 && !has_background_layer) + if (!is_background_layer && c == image->getMaskColor()) *dst_it = 0; else { r = rgba_getr(palette->getEntry(c)); @@ -268,7 +268,7 @@ Image* convert_pixel_format(const Image* image, ASSERT(dst_it != dst_end); c = *src_it; - if (c == image->getMaskColor()) + if (!is_background_layer && c == image->getMaskColor()) *dst_it = dstMaskColor; else { r = rgba_getr(palette->getEntry(c)); diff --git a/src/raster/quantization.h b/src/raster/quantization.h index f3aae6440..cb28e7bce 100644 --- a/src/raster/quantization.h +++ b/src/raster/quantization.h @@ -44,7 +44,7 @@ namespace raster { DitheringMethod ditheringMethod, const RgbMap* rgbmap, const Palette* palette, - bool has_background_layer); + bool is_background_layer); } // namespace quantization } // namespace raster diff --git a/src/raster/sprite.cpp b/src/raster/sprite.cpp index 5fe5f8193..bbd9e6149 100644 --- a/src/raster/sprite.cpp +++ b/src/raster/sprite.cpp @@ -135,15 +135,20 @@ bool Sprite::needAlpha() const void Sprite::setTransparentColor(color_t color) { m_transparentColor = color; + + for (int i=0; isize(); i++) { + Image* image = m_stock->getImage(i); + if (image != NULL) + image->setMaskColor(color); + } } int Sprite::getMemSize() const { - Image *image; - int i, size = 0; + int size = 0; - for (i=0; isize(); i++) { - image = m_stock->getImage(i); + for (int i=0; isize(); i++) { + Image* image = m_stock->getImage(i); if (image != NULL) size += image->getRowStrideSize() * image->getHeight(); }