Skip to content

Commit f1f24cb

Browse files
committed
Replace doc::Stock with doc::ImageRef shared pointer
Changes: * Add doc::ImageRef to count references to the same image between Cels (at this moment we cannot generate linked cels anyway) * Remove doc:Stock class and doc::Sprite::m_stock member variable * Remove app::undoers::Add/RemoveImage * Add doc::SubObjectsIO and app::undoers::ObjectIO to replace doc::LayerSubObjectsSerializer
1 parent 1b55fe3 commit f1f24cb

61 files changed

Lines changed: 514 additions & 953 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/app/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ add_library(app-lib
265265
undo_transaction.cpp
266266
undoers/add_cel.cpp
267267
undoers/add_frame.cpp
268-
undoers/add_image.cpp
269268
undoers/add_layer.cpp
270269
undoers/add_palette.cpp
271270
undoers/close_group.cpp
@@ -274,11 +273,11 @@ add_library(app-lib
274273
undoers/image_area.cpp
275274
undoers/modified_region.cpp
276275
undoers/move_layer.cpp
276+
undoers/object_io.cpp
277277
undoers/open_group.cpp
278278
undoers/remap_palette.cpp
279279
undoers/remove_cel.cpp
280280
undoers/remove_frame.cpp
281-
undoers/remove_image.cpp
282281
undoers/remove_layer.cpp
283282
undoers/remove_palette.cpp
284283
undoers/replace_image.cpp

src/app/commands/cmd_cel_properties.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "doc/image.h"
3434
#include "doc/layer.h"
3535
#include "doc/sprite.h"
36-
#include "doc/stock.h"
3736
#include "ui/ui.h"
3837

3938
namespace app {

src/app/commands/cmd_export_sprite_sheet.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#include "doc/palette.h"
4646
#include "doc/primitives.h"
4747
#include "doc/sprite.h"
48-
#include "doc/stock.h"
4948
#include "ui/ui.h"
5049

5150
#include "generated_export_sprite_sheet.h"
@@ -327,7 +326,7 @@ void ExportSpriteSheetCommand::onExecute(Context* context)
327326
if (sheet_h == 0) sheet_h = sprite->height()*((nframes/columns)+((nframes%columns)>0?1:0));
328327
columns = sheet_w / sprite->width();
329328

330-
base::UniquePtr<Image> resultImage(Image::create(sprite->pixelFormat(), sheet_w, sheet_h));
329+
ImageRef resultImage(Image::create(sprite->pixelFormat(), sheet_w, sheet_h));
331330
doc::clear_image(resultImage, 0);
332331

333332
render::Render render;
@@ -360,12 +359,8 @@ void ExportSpriteSheetCommand::onExecute(Context* context)
360359
// Add the layer in the sprite.
361360
LayerImage* resultLayer = api.newLayer(sprite);
362361

363-
// Add the image into the sprite's stock
364-
int indexInStock = api.addImageInStock(sprite, resultImage);
365-
resultImage.release();
366-
367362
// Create the cel.
368-
base::UniquePtr<Cel> resultCel(new Cel(frame_t(0), indexInStock));
363+
base::UniquePtr<Cel> resultCel(new Cel(frame_t(0), resultImage));
369364

370365
// Add the cel in the layer.
371366
api.addCel(resultLayer, resultCel);

src/app/commands/cmd_flip.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#include "doc/layer.h"
4040
#include "doc/mask.h"
4141
#include "doc/sprite.h"
42-
#include "doc/stock.h"
4342

4443
namespace app {
4544

src/app/commands/cmd_import_sprite_sheet.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#include "doc/palette.h"
4646
#include "doc/primitives.h"
4747
#include "doc/sprite.h"
48-
#include "doc/stock.h"
4948
#include "ui/ui.h"
5049

5150
namespace app {
@@ -160,7 +159,7 @@ class ImportSpriteSheetWindow : public Window,
160159
}
161160

162161
// The list of frames imported from the sheet
163-
std::vector<Image*> animation;
162+
std::vector<ImageRef> animation;
164163

165164
try {
166165
Sprite* sprite = m_document->sprite();
@@ -170,15 +169,14 @@ class ImportSpriteSheetWindow : public Window,
170169
// As first step, we cut each tile and add them into "animation" list.
171170
for (int y=m_rect.y; y<sprite->height(); y += m_rect.h) {
172171
for (int x=m_rect.x; x<sprite->width(); x += m_rect.w) {
173-
base::UniquePtr<Image> resultImage(
172+
ImageRef resultImage(
174173
Image::create(sprite->pixelFormat(), m_rect.w, m_rect.h));
175174

176175
// Render the portion of sheet.
177176
render.renderSprite(resultImage, sprite, currentFrame,
178177
gfx::Clip(0, 0, x, y, m_rect.w, m_rect.h));
179178

180179
animation.push_back(resultImage);
181-
resultImage.release();
182180
}
183181
}
184182

@@ -201,14 +199,8 @@ class ImportSpriteSheetWindow : public Window,
201199

202200
// Add all frames+cels to the new layer
203201
for (size_t i=0; i<animation.size(); ++i) {
204-
int indexInStock;
205-
206-
// Add the image into the sprite's stock
207-
indexInStock = api.addImageInStock(sprite, animation[i]);
208-
animation[i] = NULL;
209-
210202
// Create the cel.
211-
base::UniquePtr<Cel> resultCel(new Cel(frame_t(i), indexInStock));
203+
base::UniquePtr<Cel> resultCel(new Cel(frame_t(i), animation[i]));
212204

213205
// Add the cel in the layer.
214206
api.addCel(resultLayer, resultCel);
@@ -233,8 +225,6 @@ class ImportSpriteSheetWindow : public Window,
233225
undoTransaction.commit();
234226
}
235227
catch (...) {
236-
for (size_t i=0; i<animation.size(); ++i)
237-
delete animation[i];
238228
throw;
239229
}
240230

src/app/commands/cmd_merge_down_layer.cpp

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
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"
@@ -38,7 +37,6 @@
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
}

src/app/commands/cmd_new_file.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
#include "doc/palette.h"
4343
#include "doc/primitives.h"
4444
#include "doc/sprite.h"
45-
#include "doc/stock.h"
4645
#include "ui/ui.h"
4746

4847
#include "generated_new_sprite.h"

src/app/commands/cmd_palette_editor.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
#include "doc/image.h"
5353
#include "doc/palette.h"
5454
#include "doc/sprite.h"
55-
#include "doc/stock.h"
5655
#include "gfx/hsv.h"
5756
#include "gfx/rgb.h"
5857
#include "gfx/size.h"

src/app/commands/cmd_rotate.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#include "doc/image.h"
3939
#include "doc/mask.h"
4040
#include "doc/sprite.h"
41-
#include "doc/stock.h"
4241
#include "ui/ui.h"
4342

4443
namespace app {
@@ -116,12 +115,12 @@ class RotateJob : public Job
116115
}
117116

118117
// rotate the image
119-
Image* new_image = Image::create(image->pixelFormat(),
120-
m_angle == 180 ? image->width(): image->height(),
121-
m_angle == 180 ? image->height(): image->width());
118+
ImageRef new_image(Image::create(image->pixelFormat(),
119+
m_angle == 180 ? image->width(): image->height(),
120+
m_angle == 180 ? image->height(): image->width()));
122121
doc::rotate_image(image, new_image, m_angle);
123122

124-
api.replaceStockImage(m_sprite, cel->imageIndex(), new_image);
123+
api.replaceImage(m_sprite, cel->imageRef(), new_image);
125124
}
126125

127126
jobProgress((float)i / m_cels.size());

src/app/commands/cmd_sprite_size.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
#include "doc/mask.h"
4242
#include "doc/primitives.h"
4343
#include "doc/sprite.h"
44-
#include "doc/stock.h"
4544
#include "ui/ui.h"
4645

4746
#define PERC_FORMAT "%.1f"
@@ -105,15 +104,15 @@ class SpriteSizeJob : public Job {
105104
// Resize the image
106105
int w = scale_x(image->width());
107106
int h = scale_y(image->height());
108-
Image* new_image = Image::create(image->pixelFormat(), MAX(1, w), MAX(1, h));
107+
ImageRef new_image(Image::create(image->pixelFormat(), MAX(1, w), MAX(1, h)));
109108

110109
doc::algorithm::fixup_image_transparent_colors(image);
111110
doc::algorithm::resize_image(image, new_image,
112-
m_resize_method,
113-
m_sprite->palette(cel->frame()),
114-
m_sprite->rgbMap(cel->frame()));
111+
m_resize_method,
112+
m_sprite->palette(cel->frame()),
113+
m_sprite->rgbMap(cel->frame()));
115114

116-
api.replaceStockImage(m_sprite, cel->imageIndex(), new_image);
115+
api.replaceImage(m_sprite, cel->imageRef(), new_image);
117116

118117
jobProgress((float)progress / cels.size());
119118

@@ -124,7 +123,7 @@ class SpriteSizeJob : public Job {
124123

125124
// Resize mask
126125
if (m_document->isMaskVisible()) {
127-
base::UniquePtr<Image> old_bitmap
126+
ImageRef old_bitmap
128127
(crop_image(m_document->mask()->bitmap(), -1, -1,
129128
m_document->mask()->bitmap()->width()+2,
130129
m_document->mask()->bitmap()->height()+2, 0));
@@ -137,9 +136,9 @@ class SpriteSizeJob : public Job {
137136
scale_x(m_document->mask()->bounds().x-1),
138137
scale_y(m_document->mask()->bounds().y-1), MAX(1, w), MAX(1, h)));
139138
algorithm::resize_image(old_bitmap, new_mask->bitmap(),
140-
m_resize_method,
141-
m_sprite->palette(0), // Ignored
142-
m_sprite->rgbMap(0)); // Ignored
139+
m_resize_method,
140+
m_sprite->palette(0), // Ignored
141+
m_sprite->rgbMap(0)); // Ignored
143142

144143
// Reshrink
145144
new_mask->intersect(new_mask->bounds());

0 commit comments

Comments
 (0)