From 9dfec919e4b35502fdeb88ca5c10b41af3faa9a5 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 9 Jun 2014 22:36:42 -0300 Subject: [PATCH] Fix issue merging frames that weren't rendered on any editor at least once This bug is because the mask color of cel images were fixed when they were used in the rendering process. Now, the mask color is fixed when the image is added to the raster::Stock structure. --- src/app/CMakeLists.txt | 1 - src/app/document_api.cpp | 7 --- src/app/undoers/set_stock_pixel_format.cpp | 57 ---------------------- src/app/undoers/set_stock_pixel_format.h | 51 ------------------- src/app/util/render.cpp | 2 +- src/raster/layer.cpp | 2 +- src/raster/sprite.cpp | 3 +- src/raster/stock.cpp | 49 ++++++------------- src/raster/stock.h | 16 ++++-- 9 files changed, 31 insertions(+), 157 deletions(-) delete mode 100644 src/app/undoers/set_stock_pixel_format.cpp delete mode 100644 src/app/undoers/set_stock_pixel_format.h diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 547dc28b5..787d9c4fe 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -234,7 +234,6 @@ add_library(app-lib undoers/set_sprite_pixel_format.cpp undoers/set_sprite_size.cpp undoers/set_sprite_transparent_color.cpp - undoers/set_stock_pixel_format.cpp undoers/set_total_frames.cpp util/autocrop.cpp util/boundary.cpp diff --git a/src/app/document_api.cpp b/src/app/document_api.cpp index 56b0508c0..3c8141208 100644 --- a/src/app/document_api.cpp +++ b/src/app/document_api.cpp @@ -56,7 +56,6 @@ #include "app/undoers/set_sprite_pixel_format.h" #include "app/undoers/set_sprite_size.h" #include "app/undoers/set_sprite_transparent_color.h" -#include "app/undoers/set_stock_pixel_format.h" #include "app/undoers/set_total_frames.h" #include "base/unique_ptr.h" #include "raster/algorithm/flip_image.h" @@ -161,12 +160,6 @@ void DocumentApi::setPixelFormat(Sprite* sprite, PixelFormat newFormat, Ditherin if (sprite->getPixelFormat() == newFormat) return; - // Change pixel format of the stock of images. - if (undoEnabled()) - m_undoers->pushUndoer(new undoers::SetStockPixelFormat(getObjects(), sprite->getStock())); - - sprite->getStock()->setPixelFormat(newFormat); - // TODO Review this, why we use the palette in frame 0? FrameNumber frame(0); diff --git a/src/app/undoers/set_stock_pixel_format.cpp b/src/app/undoers/set_stock_pixel_format.cpp deleted file mode 100644 index 60afabca4..000000000 --- a/src/app/undoers/set_stock_pixel_format.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* Aseprite - * Copyright (C) 2001-2013 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 - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "app/undoers/set_stock_pixel_format.h" - -#include "raster/stock.h" -#include "undo/objects_container.h" -#include "undo/undoers_collector.h" - -namespace app { -namespace undoers { - -using namespace raster; -using namespace undo; - -SetStockPixelFormat::SetStockPixelFormat(ObjectsContainer* objects, Stock* stock) - : m_stockId(objects->addObject(stock)) - , m_format(stock->getPixelFormat()) -{ -} - -void SetStockPixelFormat::dispose() -{ - delete this; -} - -void SetStockPixelFormat::revert(ObjectsContainer* objects, UndoersCollector* redoers) -{ - Stock* stock = objects->getObjectT(m_stockId); - - // Push another SetStockPixelFormat as redoer - redoers->pushUndoer(new SetStockPixelFormat(objects, stock)); - - stock->setPixelFormat(static_cast(m_format)); -} - -} // namespace undoers -} // namespace app diff --git a/src/app/undoers/set_stock_pixel_format.h b/src/app/undoers/set_stock_pixel_format.h deleted file mode 100644 index 0c91f8134..000000000 --- a/src/app/undoers/set_stock_pixel_format.h +++ /dev/null @@ -1,51 +0,0 @@ -/* Aseprite - * Copyright (C) 2001-2013 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 - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef APP_UNDOERS_SET_STOCK_PIXEL_FORMAT_H_INCLUDED -#define APP_UNDOERS_SET_STOCK_PIXEL_FORMAT_H_INCLUDED -#pragma once - -#include "app/undoers/undoer_base.h" -#include "undo/object_id.h" - -namespace raster { - class Stock; -} - -namespace app { - namespace undoers { - using namespace raster; - using namespace undo; - - class SetStockPixelFormat : public UndoerBase { - public: - SetStockPixelFormat(ObjectsContainer* objects, Stock* stock); - - void dispose() OVERRIDE; - size_t getMemSize() const OVERRIDE { return sizeof(*this); } - void revert(ObjectsContainer* objects, UndoersCollector* redoers) OVERRIDE; - - private: - ObjectId m_stockId; - uint32_t m_format; - }; - - } // namespace undoers -} // namespace app - -#endif // UNDOERS_SET_STOCK_PIXEL_FORMAT_H_INCLUDED diff --git a/src/app/util/render.cpp b/src/app/util/render.cpp index 18cdc9f6d..2b43af1ef 100644 --- a/src/app/util/render.cpp +++ b/src/app/util/render.cpp @@ -600,7 +600,7 @@ void RenderEngine::renderLayer( output_opacity = MID(0, cel->getOpacity(), 255); output_opacity = INT_MULT(output_opacity, global_opacity, t); - src_image->setMaskColor(m_sprite->getTransparentColor()); + ASSERT(src_image->getMaskColor() == m_sprite->getTransparentColor()); (*zoomed_func)(image, src_image, m_sprite->getPalette(frame), (cel->getX() << zoom) - source_x, diff --git a/src/raster/layer.cpp b/src/raster/layer.cpp index 6e7fd3f05..9f7208042 100644 --- a/src/raster/layer.cpp +++ b/src/raster/layer.cpp @@ -325,7 +325,7 @@ void layer_render(const Layer* layer, Image* image, int x, int y, FrameNumber fr src_image = layer->getSprite()->getStock()->getImage(cel->getImage()); ASSERT(src_image != NULL); - src_image->setMaskColor(layer->getSprite()->getTransparentColor()); + ASSERT(src_image->getMaskColor() == layer->getSprite()->getTransparentColor()); composite_image(image, src_image, cel->getX() + x, diff --git a/src/raster/sprite.cpp b/src/raster/sprite.cpp index bbd9e6149..bd832c7d3 100644 --- a/src/raster/sprite.cpp +++ b/src/raster/sprite.cpp @@ -50,7 +50,7 @@ Sprite::Sprite(PixelFormat format, int width, int height, int ncolors) ASSERT(width > 0 && height > 0); m_frlens.push_back(100); // First frame with 100 msecs of duration - m_stock = new Stock(format); + m_stock = new Stock(this, format); m_folder = new LayerFolder(this); // Generate palette @@ -136,6 +136,7 @@ void Sprite::setTransparentColor(color_t color) { m_transparentColor = color; + // Change the mask color of all images. for (int i=0; isize(); i++) { Image* image = m_stock->getImage(i); if (image != NULL) diff --git a/src/raster/stock.cpp b/src/raster/stock.cpp index f2635f265..42002aa3f 100644 --- a/src/raster/stock.cpp +++ b/src/raster/stock.cpp @@ -23,44 +23,21 @@ #include "raster/stock.h" #include "raster/image.h" +#include "raster/sprite.h" #include namespace raster { -Stock::Stock(PixelFormat format) +Stock::Stock(Sprite* sprite, PixelFormat format) : Object(OBJECT_STOCK) + , m_sprite(sprite) , m_format(format) { // Image with index=0 is always NULL. m_image.push_back(NULL); } -Stock::Stock(const Stock& stock) - : Object(stock) - , m_format(stock.getPixelFormat()) -{ - try { - for (int i=0; i 0) && (index < size())); m_image[index] = image; + + fixupImage(image); +} + +void Stock::fixupImage(Image* image) +{ + // Change the mask color of the added image to the sprite mask color. + if (image) + image->setMaskColor(m_sprite->getTransparentColor()); } } // namespace raster diff --git a/src/raster/stock.h b/src/raster/stock.h index 0c8c94aac..b556ec8e4 100644 --- a/src/raster/stock.h +++ b/src/raster/stock.h @@ -20,6 +20,7 @@ #define RASTER_STOCK_H_INCLUDED #pragma once +#include "base/disable_copying.h" #include "raster/object.h" #include "raster/pixel_format.h" @@ -28,17 +29,16 @@ namespace raster { class Image; + class Sprite; typedef std::vector ImagesList; class Stock : public Object { public: - Stock(PixelFormat format); - Stock(const Stock& stock); + Stock(Sprite* sprite, PixelFormat format); virtual ~Stock(); - PixelFormat getPixelFormat() const; - void setPixelFormat(PixelFormat format); + Sprite* getSprite() const; // Returns the number of image in the stock. int size() const { @@ -66,9 +66,15 @@ namespace raster { // void replaceImage(int index, Image* image); - //private: TODO uncomment this line + private: + void fixupImage(Image* image); + PixelFormat m_format; // Type of images (all images in the stock must be of this type). ImagesList m_image; // The images-array where the images are. + Sprite* m_sprite; + + Stock(); + DISABLE_COPYING(Stock); }; } // namespace raster