mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-30 15:32:38 +00:00
Fix size calculation for Cmd with a std::stringstream
This commit is contained in:
parent
d13862599e
commit
8c88365418
@ -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)
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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(
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user