Permalink
Browse files

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
  • Loading branch information...
dacap committed Jan 4, 2015
1 parent 1b55fe3 commit f1f24cbcdd6d363ef8fa7090b0fe3bc99c514bd6
Showing with 514 additions and 953 deletions.
  1. +1 −2 src/app/CMakeLists.txt
  2. +0 −1 src/app/commands/cmd_cel_properties.cpp
  3. +2 −7 src/app/commands/cmd_export_sprite_sheet.cpp
  4. +0 −1 src/app/commands/cmd_flip.cpp
  5. +3 −13 src/app/commands/cmd_import_sprite_sheet.cpp
  6. +12 −24 src/app/commands/cmd_merge_down_layer.cpp
  7. +0 −1 src/app/commands/cmd_new_file.cpp
  8. +0 −1 src/app/commands/cmd_palette_editor.cpp
  9. +4 −5 src/app/commands/cmd_rotate.cpp
  10. +9 −10 src/app/commands/cmd_sprite_size.cpp
  11. +0 −1 src/app/commands/filters/filter_manager_impl.cpp
  12. +0 −1 src/app/context_flags.cpp
  13. +7 −11 src/app/document.cpp
  14. +2 −2 src/app/document.h
  15. +42 −101 src/app/document_api.cpp
  16. +5 −6 src/app/document_api.h
  17. +0 −1 src/app/document_exporter.cpp
  18. +0 −1 src/app/document_location.cpp
  19. +4 −5 src/app/document_range_tests.cpp
  20. +14 −11 src/app/file/ase_format.cpp
  21. +35 −46 src/app/file/file.cpp
  22. +2 −1 src/app/file/file.h
  23. +2 −4 src/app/file/fli_format.cpp
  24. +3 −4 src/app/file/gif_format.cpp
  25. +3 −4 src/app/file/gif_tests.cpp
  26. +2 −3 src/app/file/ico_format.cpp
  27. +2 −7 src/app/flatten.cpp
  28. +3 −7 src/app/ui/color_selector.cpp
  29. +6 −13 src/app/ui/timeline.cpp
  30. +0 −63 src/app/undoers/add_image.cpp
  31. +0 −51 src/app/undoers/add_image.h
  32. +86 −0 src/app/undoers/object_io.cpp
  33. +39 −8 src/app/undoers/object_io.h
  34. +2 −5 src/app/undoers/remove_cel.cpp
  35. +0 −65 src/app/undoers/remove_image.cpp
  36. +0 −58 src/app/undoers/remove_image.h
  37. +3 −59 src/app/undoers/remove_layer.cpp
  38. +18 −15 src/app/undoers/replace_image.cpp
  39. +6 −4 src/app/undoers/replace_image.h
  40. +0 −1 src/app/util/clipboard.cpp
  41. +17 −24 src/app/util/expand_cel_canvas.cpp
  42. +2 −1 src/app/util/expand_cel_canvas.h
  43. +1 −2 src/doc/CMakeLists.txt
  44. +38 −20 src/doc/cel.cpp
  45. +11 −10 src/doc/cel.h
  46. +19 −19 src/doc/cel_io.cpp
  47. +4 −2 src/doc/cel_io.h
  48. +0 −1 src/doc/doc.h
  49. +20 −0 src/doc/image_ref.h
  50. +0 −1 src/doc/images_collector.cpp
  51. +3 −8 src/doc/layer.cpp
  52. +3 −13 src/doc/layer_io.cpp
  53. +3 −18 src/doc/layer_io.h
  54. +0 −1 src/doc/object_type.h
  55. +35 −37 src/doc/sprite.cpp
  56. +4 −10 src/doc/sprite.h
  57. +0 −1 src/doc/sprites.cpp
  58. +0 −91 src/doc/stock.cpp
  59. +0 −70 src/doc/stock.h
  60. +37 −0 src/doc/subobjects_io.h
  61. +0 −1 src/render/quantization.h
View
@@ -265,7 +265,6 @@ add_library(app-lib
undo_transaction.cpp
undoers/add_cel.cpp
undoers/add_frame.cpp
undoers/add_image.cpp
undoers/add_layer.cpp
undoers/add_palette.cpp
undoers/close_group.cpp
@@ -274,11 +273,11 @@ add_library(app-lib
undoers/image_area.cpp
undoers/modified_region.cpp
undoers/move_layer.cpp
undoers/object_io.cpp
undoers/open_group.cpp
undoers/remap_palette.cpp
undoers/remove_cel.cpp
undoers/remove_frame.cpp
undoers/remove_image.cpp
undoers/remove_layer.cpp
undoers/remove_palette.cpp
undoers/replace_image.cpp
@@ -33,7 +33,6 @@
#include "doc/image.h"
#include "doc/layer.h"
#include "doc/sprite.h"
#include "doc/stock.h"
#include "ui/ui.h"
namespace app {
@@ -45,7 +45,6 @@
#include "doc/palette.h"
#include "doc/primitives.h"
#include "doc/sprite.h"
#include "doc/stock.h"
#include "ui/ui.h"
#include "generated_export_sprite_sheet.h"
@@ -327,7 +326,7 @@ void ExportSpriteSheetCommand::onExecute(Context* context)
if (sheet_h == 0) sheet_h = sprite->height()*((nframes/columns)+((nframes%columns)>0?1:0));
columns = sheet_w / sprite->width();
base::UniquePtr<Image> resultImage(Image::create(sprite->pixelFormat(), sheet_w, sheet_h));
ImageRef resultImage(Image::create(sprite->pixelFormat(), sheet_w, sheet_h));
doc::clear_image(resultImage, 0);
render::Render render;
@@ -360,12 +359,8 @@ void ExportSpriteSheetCommand::onExecute(Context* context)
// Add the layer in the sprite.
LayerImage* resultLayer = api.newLayer(sprite);
// Add the image into the sprite's stock
int indexInStock = api.addImageInStock(sprite, resultImage);
resultImage.release();
// Create the cel.
base::UniquePtr<Cel> resultCel(new Cel(frame_t(0), indexInStock));
base::UniquePtr<Cel> resultCel(new Cel(frame_t(0), resultImage));
// Add the cel in the layer.
api.addCel(resultLayer, resultCel);
@@ -39,7 +39,6 @@
#include "doc/layer.h"
#include "doc/mask.h"
#include "doc/sprite.h"
#include "doc/stock.h"
namespace app {
@@ -45,7 +45,6 @@
#include "doc/palette.h"
#include "doc/primitives.h"
#include "doc/sprite.h"
#include "doc/stock.h"
#include "ui/ui.h"
namespace app {
@@ -160,7 +159,7 @@ class ImportSpriteSheetWindow : public Window,
}
// The list of frames imported from the sheet
std::vector<Image*> animation;
std::vector<ImageRef> animation;
try {
Sprite* sprite = m_document->sprite();
@@ -170,15 +169,14 @@ class ImportSpriteSheetWindow : public Window,
// As first step, we cut each tile and add them into "animation" list.
for (int y=m_rect.y; y<sprite->height(); y += m_rect.h) {
for (int x=m_rect.x; x<sprite->width(); x += m_rect.w) {
base::UniquePtr<Image> resultImage(
ImageRef resultImage(
Image::create(sprite->pixelFormat(), m_rect.w, m_rect.h));
// Render the portion of sheet.
render.renderSprite(resultImage, sprite, currentFrame,
gfx::Clip(0, 0, x, y, m_rect.w, m_rect.h));
animation.push_back(resultImage);
resultImage.release();
}
}
@@ -201,14 +199,8 @@ class ImportSpriteSheetWindow : public Window,
// Add all frames+cels to the new layer
for (size_t i=0; i<animation.size(); ++i) {
int indexInStock;
// Add the image into the sprite's stock
indexInStock = api.addImageInStock(sprite, animation[i]);
animation[i] = NULL;
// Create the cel.
base::UniquePtr<Cel> resultCel(new Cel(frame_t(i), indexInStock));
base::UniquePtr<Cel> resultCel(new Cel(frame_t(i), animation[i]));
// Add the cel in the layer.
api.addCel(resultLayer, resultCel);
@@ -233,8 +225,6 @@ class ImportSpriteSheetWindow : public Window,
undoTransaction.commit();
}
catch (...) {
for (size_t i=0; i<animation.size(); ++i)
delete animation[i];
throw;
}
@@ -28,7 +28,6 @@
#include "app/modules/gui.h"
#include "app/undo_transaction.h"
#include "app/undoers/add_cel.h"
#include "app/undoers/add_image.h"
#include "app/undoers/remove_layer.h"
#include "app/undoers/replace_image.h"
#include "app/undoers/set_cel_position.h"
@@ -38,7 +37,6 @@
#include "doc/layer.h"
#include "doc/primitives.h"
#include "doc/sprite.h"
#include "doc/stock.h"
#include "render/render.h"
#include "ui/ui.h"
@@ -87,7 +85,6 @@ void MergeDownLayerCommand::onExecute(Context* context)
UndoTransaction undo(writer.context(), "Merge Down Layer", undo::ModifyDocument);
Layer* src_layer = writer.layer();
Layer* dst_layer = src_layer->getPrevious();
int index;
for (frame_t frpos = 0; frpos<sprite->totalFrames(); ++frpos) {
// Get frames
@@ -101,29 +98,21 @@ void MergeDownLayerCommand::onExecute(Context* context)
else
src_image = NULL;
Image* dst_image;
if (dst_cel != NULL)
dst_image = dst_cel->image();
else
dst_image = NULL;
ImageRef dst_image;
if (dst_cel)
dst_image = dst_cel->imageRef();
// With source image?
if (src_image != NULL) {
if (src_image) {
// No destination image
if (dst_image == NULL) { // Only a transparent layer can have a null cel
// Copy this cel to the destination layer...
// Creating a copy of the image
dst_image = Image::createCopy(src_image);
// Adding it in the stock of images
index = sprite->stock()->addImage(dst_image);
if (undo.isEnabled())
undo.pushUndoer(new undoers::AddImage(
undo.getObjects(), sprite->stock(), index));
dst_image.reset(Image::createCopy(src_image));
// Creating a copy of the cell
dst_cel = new Cel(frpos, index);
dst_cel = new Cel(frpos, dst_image);
dst_cel->setPosition(src_cel->x(), src_cel->y());
dst_cel->setOpacity(src_cel->opacity());
@@ -153,10 +142,10 @@ void MergeDownLayerCommand::onExecute(Context* context)
doc::color_t bgcolor = app_get_color_to_clear_layer(dst_layer);
Image* new_image = doc::crop_image(dst_image,
x1-dst_cel->x(),
y1-dst_cel->y(),
x2-x1+1, y2-y1+1, bgcolor);
ImageRef new_image(doc::crop_image(dst_image,
x1-dst_cel->x(),
y1-dst_cel->y(),
x2-x1+1, y2-y1+1, bgcolor));
// Merge src_image in new_image
render::composite_image(new_image, src_image,
@@ -172,10 +161,9 @@ void MergeDownLayerCommand::onExecute(Context* context)
if (undo.isEnabled())
undo.pushUndoer(new undoers::ReplaceImage(undo.getObjects(),
sprite->stock(), dst_cel->imageIndex()));
sprite, dst_cel->image(), new_image));
sprite->stock()->replaceImage(dst_cel->imageIndex(), new_image);
delete dst_image;
sprite->replaceImage(dst_cel->image()->id(), new_image);
}
}
}
@@ -42,7 +42,6 @@
#include "doc/palette.h"
#include "doc/primitives.h"
#include "doc/sprite.h"
#include "doc/stock.h"
#include "ui/ui.h"
#include "generated_new_sprite.h"
@@ -52,7 +52,6 @@
#include "doc/image.h"
#include "doc/palette.h"
#include "doc/sprite.h"
#include "doc/stock.h"
#include "gfx/hsv.h"
#include "gfx/rgb.h"
#include "gfx/size.h"
@@ -38,7 +38,6 @@
#include "doc/image.h"
#include "doc/mask.h"
#include "doc/sprite.h"
#include "doc/stock.h"
#include "ui/ui.h"
namespace app {
@@ -116,12 +115,12 @@ class RotateJob : public Job
}
// rotate the image
Image* new_image = Image::create(image->pixelFormat(),
m_angle == 180 ? image->width(): image->height(),
m_angle == 180 ? image->height(): image->width());
ImageRef new_image(Image::create(image->pixelFormat(),
m_angle == 180 ? image->width(): image->height(),
m_angle == 180 ? image->height(): image->width()));
doc::rotate_image(image, new_image, m_angle);
api.replaceStockImage(m_sprite, cel->imageIndex(), new_image);
api.replaceImage(m_sprite, cel->imageRef(), new_image);
}
jobProgress((float)i / m_cels.size());
@@ -41,7 +41,6 @@
#include "doc/mask.h"
#include "doc/primitives.h"
#include "doc/sprite.h"
#include "doc/stock.h"
#include "ui/ui.h"
#define PERC_FORMAT "%.1f"
@@ -105,15 +104,15 @@ class SpriteSizeJob : public Job {
// Resize the image
int w = scale_x(image->width());
int h = scale_y(image->height());
Image* new_image = Image::create(image->pixelFormat(), MAX(1, w), MAX(1, h));
ImageRef new_image(Image::create(image->pixelFormat(), MAX(1, w), MAX(1, h)));
doc::algorithm::fixup_image_transparent_colors(image);
doc::algorithm::resize_image(image, new_image,
m_resize_method,
m_sprite->palette(cel->frame()),
m_sprite->rgbMap(cel->frame()));
m_resize_method,
m_sprite->palette(cel->frame()),
m_sprite->rgbMap(cel->frame()));
api.replaceStockImage(m_sprite, cel->imageIndex(), new_image);
api.replaceImage(m_sprite, cel->imageRef(), new_image);
jobProgress((float)progress / cels.size());
@@ -124,7 +123,7 @@ class SpriteSizeJob : public Job {
// Resize mask
if (m_document->isMaskVisible()) {
base::UniquePtr<Image> old_bitmap
ImageRef old_bitmap
(crop_image(m_document->mask()->bitmap(), -1, -1,
m_document->mask()->bitmap()->width()+2,
m_document->mask()->bitmap()->height()+2, 0));
@@ -137,9 +136,9 @@ class SpriteSizeJob : public Job {
scale_x(m_document->mask()->bounds().x-1),
scale_y(m_document->mask()->bounds().y-1), MAX(1, w), MAX(1, h)));
algorithm::resize_image(old_bitmap, new_mask->bitmap(),
m_resize_method,
m_sprite->palette(0), // Ignored
m_sprite->rgbMap(0)); // Ignored
m_resize_method,
m_sprite->palette(0), // Ignored
m_sprite->rgbMap(0)); // Ignored
// Reshrink
new_mask->intersect(new_mask->bounds());
@@ -35,7 +35,6 @@
#include "doc/layer.h"
#include "doc/mask.h"
#include "doc/sprite.h"
#include "doc/stock.h"
#include "ui/manager.h"
#include "ui/view.h"
#include "ui/widget.h"
@@ -28,7 +28,6 @@
#include "doc/cel.h"
#include "doc/layer.h"
#include "doc/sprite.h"
#include "doc/stock.h"
namespace app {
View
@@ -27,7 +27,6 @@
#include "app/file/format_options.h"
#include "app/flatten.h"
#include "app/objects_container_impl.h"
#include "app/undoers/add_image.h"
#include "app/undoers/add_layer.h"
#include "app/util/boundary.h"
#include "base/memory.h"
@@ -41,7 +40,6 @@
#include "doc/mask.h"
#include "doc/palette.h"
#include "doc/sprite.h"
#include "doc/stock.h"
namespace app {
@@ -235,18 +233,17 @@ void Document::generateMaskBoundaries(Mask* mask)
void Document::destroyExtraCel()
{
delete m_extraCel;
delete m_extraImage;
m_extraCel = NULL;
m_extraImage = NULL;
m_extraImage.reset(NULL);
}
void Document::prepareExtraCel(const gfx::Rect& bounds, int opacity)
{
ASSERT(sprite() != NULL);
if (!m_extraCel)
m_extraCel = new Cel(frame_t(0), 0); // Ignored fields for this cell (frame, and image index)
m_extraCel = new Cel(frame_t(0), ImageRef(NULL)); // Ignored fields for this cel (frame, and image index)
m_extraCel->setPosition(bounds.getOrigin());
m_extraCel->setOpacity(opacity);
@@ -255,9 +252,8 @@ void Document::prepareExtraCel(const gfx::Rect& bounds, int opacity)
m_extraImage->pixelFormat() != sprite()->pixelFormat() ||
m_extraImage->width() != bounds.w ||
m_extraImage->height() != bounds.h) {
delete m_extraImage; // image
m_extraImage = Image::create(sprite()->pixelFormat(),
bounds.w, bounds.h);
m_extraImage.reset(Image::create(sprite()->pixelFormat(),
bounds.w, bounds.h));
}
}
@@ -268,7 +264,7 @@ Cel* Document::getExtraCel() const
Image* Document::getExtraCelImage() const
{
return m_extraImage;
return m_extraImage.get();
}
//////////////////////////////////////////////////////////////////////
@@ -342,8 +338,8 @@ void Document::copyLayerContent(const Layer* sourceLayer0, Document* destDoc, La
const Image* sourceImage = sourceCel->image();
ASSERT(sourceImage != NULL);
Image* newImage = Image::createCopy(sourceImage);
newCel->setImage(destLayer->sprite()->stock()->addImage(newImage));
ImageRef newImage(Image::createCopy(sourceImage));
newCel->setImage(newImage);
destLayer->addCel(newCel);
newCel.release();
Oops, something went wrong.

0 comments on commit f1f24cb

Please sign in to comment.