2828#include " app/modules/gui.h"
2929#include " app/undo_transaction.h"
3030#include " app/undoers/add_cel.h"
31- #include " app/undoers/add_image.h"
3231#include " app/undoers/remove_layer.h"
3332#include " app/undoers/replace_image.h"
3433#include " app/undoers/set_cel_position.h"
3837#include " doc/layer.h"
3938#include " doc/primitives.h"
4039#include " doc/sprite.h"
41- #include " doc/stock.h"
4240#include " render/render.h"
4341#include " ui/ui.h"
4442
@@ -87,7 +85,6 @@ void MergeDownLayerCommand::onExecute(Context* context)
8785 UndoTransaction undo (writer.context (), " Merge Down Layer" , undo::ModifyDocument);
8886 Layer* src_layer = writer.layer ();
8987 Layer* dst_layer = src_layer->getPrevious ();
90- int index;
9188
9289 for (frame_t frpos = 0 ; frpos<sprite->totalFrames (); ++frpos) {
9390 // Get frames
@@ -101,29 +98,21 @@ void MergeDownLayerCommand::onExecute(Context* context)
10198 else
10299 src_image = NULL ;
103100
104- Image* dst_image;
105- if (dst_cel != NULL )
106- dst_image = dst_cel->image ();
107- else
108- dst_image = NULL ;
101+ ImageRef dst_image;
102+ if (dst_cel)
103+ dst_image = dst_cel->imageRef ();
109104
110105 // With source image?
111- if (src_image != NULL ) {
106+ if (src_image) {
112107 // No destination image
113108 if (dst_image == NULL ) { // Only a transparent layer can have a null cel
114109 // Copy this cel to the destination layer...
115110
116111 // Creating a copy of the image
117- dst_image = Image::createCopy (src_image);
118-
119- // Adding it in the stock of images
120- index = sprite->stock ()->addImage (dst_image);
121- if (undo.isEnabled ())
122- undo.pushUndoer (new undoers::AddImage (
123- undo.getObjects (), sprite->stock (), index));
112+ dst_image.reset (Image::createCopy (src_image));
124113
125114 // Creating a copy of the cell
126- dst_cel = new Cel (frpos, index );
115+ dst_cel = new Cel (frpos, dst_image );
127116 dst_cel->setPosition (src_cel->x (), src_cel->y ());
128117 dst_cel->setOpacity (src_cel->opacity ());
129118
@@ -153,10 +142,10 @@ void MergeDownLayerCommand::onExecute(Context* context)
153142
154143 doc::color_t bgcolor = app_get_color_to_clear_layer (dst_layer);
155144
156- Image* new_image = doc::crop_image (dst_image,
157- x1-dst_cel->x (),
158- y1-dst_cel->y (),
159- x2-x1+1 , y2-y1+1 , bgcolor);
145+ ImageRef new_image ( doc::crop_image (dst_image,
146+ x1-dst_cel->x (),
147+ y1-dst_cel->y (),
148+ x2-x1+1 , y2-y1+1 , bgcolor) );
160149
161150 // Merge src_image in new_image
162151 render::composite_image (new_image, src_image,
@@ -172,10 +161,9 @@ void MergeDownLayerCommand::onExecute(Context* context)
172161
173162 if (undo.isEnabled ())
174163 undo.pushUndoer (new undoers::ReplaceImage (undo.getObjects (),
175- sprite-> stock () , dst_cel->imageIndex () ));
164+ sprite, dst_cel->image (), new_image ));
176165
177- sprite->stock ()->replaceImage (dst_cel->imageIndex (), new_image);
178- delete dst_image;
166+ sprite->replaceImage (dst_cel->image ()->id (), new_image);
179167 }
180168 }
181169 }
0 commit comments