This is an automated email from the git hooks/post-receive script. thansen pushed a commit to branch master in repository aseprite.
commit 8c883654187c2afac7719d8629cb9f3ae3909d42 Author: David Capello <[email protected]> Date: Mon May 9 19:03:12 2016 -0300 Fix size calculation for Cmd with a std::stringstream --- src/app/cmd/add_cel.cpp | 5 ++++- src/app/cmd/add_cel.h | 6 +++--- src/app/cmd/add_frame_tag.cpp | 11 ++++------- src/app/cmd/add_frame_tag.h | 7 +++++-- src/app/cmd/add_layer.cpp | 5 ++++- src/app/cmd/add_layer.h | 6 +++--- src/app/cmd/add_palette.cpp | 4 +++- src/app/cmd/add_palette.h | 6 +++--- src/app/cmd/copy_region.cpp | 6 +++++- src/app/cmd/copy_region.h | 7 ++++--- 10 files changed, 38 insertions(+), 25 deletions(-) diff --git a/src/app/cmd/add_cel.cpp b/src/app/cmd/add_cel.cpp index 2fc378f..0c7448a 100644 --- a/src/app/cmd/add_cel.cpp +++ b/src/app/cmd/add_cel.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2015 David Capello +// Copyright (C) 2001-2016 David Capello // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -31,6 +31,7 @@ using namespace doc; AddCel::AddCel(Layer* layer, Cel* cel) : WithLayer(layer) , WithCel(cel) + , m_size(0) { } @@ -55,6 +56,7 @@ void AddCel::onUndo() write_celdata(m_stream, cel->data()); } write_cel(m_stream, cel); + m_size = size_t(m_stream.tellp()); removeCel(layer, cel); } @@ -78,6 +80,7 @@ void AddCel::onRedo() m_stream.str(std::string()); m_stream.clear(); + m_size = 0; } void AddCel::addCel(Layer* layer, Cel* cel) diff --git a/src/app/cmd/add_cel.h b/src/app/cmd/add_cel.h index a14bcdb..1b6d640 100644 --- a/src/app/cmd/add_cel.h +++ b/src/app/cmd/add_cel.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2015 David Capello +// Copyright (C) 2001-2016 David Capello // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -35,14 +35,14 @@ namespace cmd { void onUndo() override; void onRedo() override; size_t onMemSize() const override { - return sizeof(*this) + - (size_t)const_cast<std::stringstream*>(&m_stream)->tellp(); + return sizeof(*this) + m_size; } private: void addCel(Layer* layer, Cel* cel); void removeCel(Layer* layer, Cel* cel); + size_t m_size; std::stringstream m_stream; }; diff --git a/src/app/cmd/add_frame_tag.cpp b/src/app/cmd/add_frame_tag.cpp index d702520..4fcb3b1 100644 --- a/src/app/cmd/add_frame_tag.cpp +++ b/src/app/cmd/add_frame_tag.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2015 David Capello +// Copyright (C) 2001-2016 David Capello // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -23,6 +23,7 @@ using namespace doc; AddFrameTag::AddFrameTag(Sprite* sprite, FrameTag* frameTag) : WithSprite(sprite) , WithFrameTag(frameTag) + , m_size(0) { } @@ -40,6 +41,7 @@ void AddFrameTag::onUndo() Sprite* sprite = this->sprite(); FrameTag* frameTag = this->frameTag(); write_frame_tag(m_stream, frameTag); + m_size = size_t(m_stream.tellp()); sprite->frameTags().remove(frameTag); sprite->incrementVersion(); @@ -56,12 +58,7 @@ void AddFrameTag::onRedo() m_stream.str(std::string()); m_stream.clear(); -} - -size_t AddFrameTag::onMemSize() const -{ - return sizeof(*this) - + (size_t)const_cast<std::stringstream*>(&m_stream)->tellp(); + m_size = 0; } } // namespace cmd diff --git a/src/app/cmd/add_frame_tag.h b/src/app/cmd/add_frame_tag.h index 4494690..6011f6e 100644 --- a/src/app/cmd/add_frame_tag.h +++ b/src/app/cmd/add_frame_tag.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2015 David Capello +// Copyright (C) 2001-2016 David Capello // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -29,9 +29,12 @@ namespace cmd { void onExecute() override; void onUndo() override; void onRedo() override; - size_t onMemSize() const override; + size_t onMemSize() const override { + return sizeof(*this) + m_size; + } private: + size_t m_size; std::stringstream m_stream; }; diff --git a/src/app/cmd/add_layer.cpp b/src/app/cmd/add_layer.cpp index 8ddb778..3d9241f 100644 --- a/src/app/cmd/add_layer.cpp +++ b/src/app/cmd/add_layer.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2015 David Capello +// Copyright (C) 2001-2016 David Capello // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -26,6 +26,7 @@ AddLayer::AddLayer(Layer* folder, Layer* newLayer, Layer* afterThis) : m_folder(folder) , m_newLayer(newLayer) , m_afterThis(afterThis) + , m_size(0) { } @@ -44,6 +45,7 @@ void AddLayer::onUndo() Layer* layer = m_newLayer.layer(); write_layer(m_stream, layer); + m_size = size_t(m_stream.tellp()); removeLayer(folder, layer); } @@ -59,6 +61,7 @@ void AddLayer::onRedo() m_stream.str(std::string()); m_stream.clear(); + m_size = 0; } void AddLayer::addLayer(Layer* folder, Layer* newLayer, Layer* afterThis) diff --git a/src/app/cmd/add_layer.h b/src/app/cmd/add_layer.h index 3dfccf9..d9f52f1 100644 --- a/src/app/cmd/add_layer.h +++ b/src/app/cmd/add_layer.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2015 David Capello +// Copyright (C) 2001-2016 David Capello // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -31,8 +31,7 @@ namespace cmd { void onUndo() override; void onRedo() override; size_t onMemSize() const override { - return sizeof(*this) + - (size_t)const_cast<std::stringstream*>(&m_stream)->tellp(); + return sizeof(*this) + m_size; } private: @@ -42,6 +41,7 @@ namespace cmd { WithLayer m_folder; WithLayer m_newLayer; WithLayer m_afterThis; + size_t m_size; std::stringstream m_stream; }; diff --git a/src/app/cmd/add_palette.cpp b/src/app/cmd/add_palette.cpp index b0c9aef..c989451 100644 --- a/src/app/cmd/add_palette.cpp +++ b/src/app/cmd/add_palette.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2015 David Capello +// Copyright (C) 2001-2016 David Capello // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -22,9 +22,11 @@ using namespace doc; AddPalette::AddPalette(Sprite* sprite, Palette* pal) : WithSprite(sprite) + , m_size(0) , m_frame(pal->frame()) { write_palette(m_stream, pal); + m_size = size_t(m_stream.tellp()); } void AddPalette::onExecute() diff --git a/src/app/cmd/add_palette.h b/src/app/cmd/add_palette.h index 8ef0f85..d229832 100644 --- a/src/app/cmd/add_palette.h +++ b/src/app/cmd/add_palette.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2015 David Capello +// Copyright (C) 2001-2016 David Capello // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -33,11 +33,11 @@ namespace cmd { void onExecute() override; void onUndo() override; size_t onMemSize() const override { - return sizeof(*this) + - (size_t)const_cast<std::stringstream*>(&m_stream)->tellp(); + return sizeof(*this) + m_size; } private: + size_t m_size; std::stringstream m_stream; frame_t m_frame; }; diff --git a/src/app/cmd/copy_region.cpp b/src/app/cmd/copy_region.cpp index 5a9d550..152dd40 100644 --- a/src/app/cmd/copy_region.cpp +++ b/src/app/cmd/copy_region.cpp @@ -23,6 +23,7 @@ CopyRegion::CopyRegion(Image* dst, const Image* src, int dst_dx, int dst_dy, bool alreadyCopied) : WithImage(dst) + , m_size(0) , m_alreadyCopied(alreadyCopied) { // Create region to save/swap later @@ -40,11 +41,13 @@ CopyRegion::CopyRegion(Image* dst, const Image* src, // Save region pixels for (const auto& rc : m_region) { - for (int y=0; y<rc.h; ++y) + for (int y=0; y<rc.h; ++y) { m_stream.write( (const char*)src->getPixelAddress(rc.x, rc.y+y), src->getRowStrideSize(rc.w)); + } } + m_size = size_t(m_stream.tellp()); } void CopyRegion::onExecute() @@ -76,6 +79,7 @@ void CopyRegion::swap() image->getRowStrideSize(rc.w)); // Restore m_stream into the image + m_stream.seekg(0, std::ios_base::beg); for (const auto& rc : m_region) { for (int y=0; y<rc.h; ++y) { m_stream.read( diff --git a/src/app/cmd/copy_region.h b/src/app/cmd/copy_region.h index 84ae13b..3340024 100644 --- a/src/app/cmd/copy_region.h +++ b/src/app/cmd/copy_region.h @@ -27,7 +27,8 @@ namespace cmd { // should do nothing, because modified pixels are alreadt on "dst" // (so we use "src" as the original image). CopyRegion(Image* dst, const Image* src, - const gfx::Region& region, int src_dx, int src_dy, + const gfx::Region& region, + int dst_dx, int dst_dy, bool alreadyCopied = false); protected: @@ -35,13 +36,13 @@ namespace cmd { void onUndo() override; void onRedo() override; size_t onMemSize() const override { - return sizeof(*this) + - (size_t)const_cast<std::stringstream*>(&m_stream)->tellp(); + return sizeof(*this) + m_size; } private: void swap(); + size_t m_size; bool m_alreadyCopied; gfx::Region m_region; std::stringstream m_stream; -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git _______________________________________________ Pkg-games-commits mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-games-commits

