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.
This commit is contained in:
David Capello 2014-06-09 22:36:42 -03:00
parent 47b5a973e9
commit 9dfec919e4
9 changed files with 31 additions and 157 deletions

View File

@ -234,7 +234,6 @@ add_library(app-lib
undoers/set_sprite_pixel_format.cpp undoers/set_sprite_pixel_format.cpp
undoers/set_sprite_size.cpp undoers/set_sprite_size.cpp
undoers/set_sprite_transparent_color.cpp undoers/set_sprite_transparent_color.cpp
undoers/set_stock_pixel_format.cpp
undoers/set_total_frames.cpp undoers/set_total_frames.cpp
util/autocrop.cpp util/autocrop.cpp
util/boundary.cpp util/boundary.cpp

View File

@ -56,7 +56,6 @@
#include "app/undoers/set_sprite_pixel_format.h" #include "app/undoers/set_sprite_pixel_format.h"
#include "app/undoers/set_sprite_size.h" #include "app/undoers/set_sprite_size.h"
#include "app/undoers/set_sprite_transparent_color.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 "app/undoers/set_total_frames.h"
#include "base/unique_ptr.h" #include "base/unique_ptr.h"
#include "raster/algorithm/flip_image.h" #include "raster/algorithm/flip_image.h"
@ -161,12 +160,6 @@ void DocumentApi::setPixelFormat(Sprite* sprite, PixelFormat newFormat, Ditherin
if (sprite->getPixelFormat() == newFormat) if (sprite->getPixelFormat() == newFormat)
return; 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? // TODO Review this, why we use the palette in frame 0?
FrameNumber frame(0); FrameNumber frame(0);

View File

@ -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<Stock>(m_stockId);
// Push another SetStockPixelFormat as redoer
redoers->pushUndoer(new SetStockPixelFormat(objects, stock));
stock->setPixelFormat(static_cast<PixelFormat>(m_format));
}
} // namespace undoers
} // namespace app

View File

@ -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

View File

@ -600,7 +600,7 @@ void RenderEngine::renderLayer(
output_opacity = MID(0, cel->getOpacity(), 255); output_opacity = MID(0, cel->getOpacity(), 255);
output_opacity = INT_MULT(output_opacity, global_opacity, t); 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), (*zoomed_func)(image, src_image, m_sprite->getPalette(frame),
(cel->getX() << zoom) - source_x, (cel->getX() << zoom) - source_x,

View File

@ -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()); src_image = layer->getSprite()->getStock()->getImage(cel->getImage());
ASSERT(src_image != NULL); ASSERT(src_image != NULL);
src_image->setMaskColor(layer->getSprite()->getTransparentColor()); ASSERT(src_image->getMaskColor() == layer->getSprite()->getTransparentColor());
composite_image(image, src_image, composite_image(image, src_image,
cel->getX() + x, cel->getX() + x,

View File

@ -50,7 +50,7 @@ Sprite::Sprite(PixelFormat format, int width, int height, int ncolors)
ASSERT(width > 0 && height > 0); ASSERT(width > 0 && height > 0);
m_frlens.push_back(100); // First frame with 100 msecs of duration 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); m_folder = new LayerFolder(this);
// Generate palette // Generate palette
@ -136,6 +136,7 @@ void Sprite::setTransparentColor(color_t color)
{ {
m_transparentColor = color; m_transparentColor = color;
// Change the mask color of all images.
for (int i=0; i<m_stock->size(); i++) { for (int i=0; i<m_stock->size(); i++) {
Image* image = m_stock->getImage(i); Image* image = m_stock->getImage(i);
if (image != NULL) if (image != NULL)

View File

@ -23,44 +23,21 @@
#include "raster/stock.h" #include "raster/stock.h"
#include "raster/image.h" #include "raster/image.h"
#include "raster/sprite.h"
#include <cstring> #include <cstring>
namespace raster { namespace raster {
Stock::Stock(PixelFormat format) Stock::Stock(Sprite* sprite, PixelFormat format)
: Object(OBJECT_STOCK) : Object(OBJECT_STOCK)
, m_sprite(sprite)
, m_format(format) , m_format(format)
{ {
// Image with index=0 is always NULL. // Image with index=0 is always NULL.
m_image.push_back(NULL); m_image.push_back(NULL);
} }
Stock::Stock(const Stock& stock)
: Object(stock)
, m_format(stock.getPixelFormat())
{
try {
for (int i=0; i<stock.size(); ++i) {
if (!stock.getImage(i))
addImage(NULL);
else {
Image* image_copy = Image::createCopy(stock.getImage(i));
addImage(image_copy);
}
}
}
catch (...) {
for (int i=0; i<size(); ++i) {
if (getImage(i))
delete getImage(i);
}
throw;
}
ASSERT(size() == stock.size());
}
Stock::~Stock() Stock::~Stock()
{ {
for (int i=0; i<size(); ++i) { for (int i=0; i<size(); ++i) {
@ -69,14 +46,9 @@ Stock::~Stock()
} }
} }
PixelFormat Stock::getPixelFormat() const Sprite* Stock::getSprite() const
{ {
return m_format; return m_sprite;
}
void Stock::setPixelFormat(PixelFormat pixelFormat)
{
m_format = pixelFormat;
} }
Image* Stock::getImage(int index) const Image* Stock::getImage(int index) const
@ -97,6 +69,8 @@ int Stock::addImage(Image* image)
throw; throw;
} }
m_image[i] = image; m_image[i] = image;
fixupImage(image);
return i; return i;
} }
@ -115,6 +89,15 @@ void Stock::replaceImage(int index, Image* image)
{ {
ASSERT((index > 0) && (index < size())); ASSERT((index > 0) && (index < size()));
m_image[index] = image; 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 } // namespace raster

View File

@ -20,6 +20,7 @@
#define RASTER_STOCK_H_INCLUDED #define RASTER_STOCK_H_INCLUDED
#pragma once #pragma once
#include "base/disable_copying.h"
#include "raster/object.h" #include "raster/object.h"
#include "raster/pixel_format.h" #include "raster/pixel_format.h"
@ -28,17 +29,16 @@
namespace raster { namespace raster {
class Image; class Image;
class Sprite;
typedef std::vector<Image*> ImagesList; typedef std::vector<Image*> ImagesList;
class Stock : public Object { class Stock : public Object {
public: public:
Stock(PixelFormat format); Stock(Sprite* sprite, PixelFormat format);
Stock(const Stock& stock);
virtual ~Stock(); virtual ~Stock();
PixelFormat getPixelFormat() const; Sprite* getSprite() const;
void setPixelFormat(PixelFormat format);
// Returns the number of image in the stock. // Returns the number of image in the stock.
int size() const { int size() const {
@ -66,9 +66,15 @@ namespace raster {
// //
void replaceImage(int index, Image* image); 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). 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. ImagesList m_image; // The images-array where the images are.
Sprite* m_sprite;
Stock();
DISABLE_COPYING(Stock);
}; };
} // namespace raster } // namespace raster