mirror of
https://github.com/aseprite/aseprite.git
synced 2024-10-06 06:50:07 +00:00
Fix crash converting sprite to grayscale
This commit is contained in:
parent
13a977f0e6
commit
43a0279a24
@ -116,7 +116,6 @@ add_library(app-lib
|
||||
cmd/with_frame_tag.cpp
|
||||
cmd/with_image.cpp
|
||||
cmd/with_layer.cpp
|
||||
cmd/with_palette.cpp
|
||||
cmd/with_sprite.cpp
|
||||
cmd_sequence.cpp
|
||||
cmd_transaction.cpp
|
||||
|
@ -22,41 +22,28 @@ using namespace doc;
|
||||
|
||||
AddPalette::AddPalette(Sprite* sprite, Palette* pal)
|
||||
: WithSprite(sprite)
|
||||
, WithPalette(pal)
|
||||
, m_frame(pal->frame())
|
||||
{
|
||||
write_palette(m_stream, pal);
|
||||
}
|
||||
|
||||
void AddPalette::onExecute()
|
||||
{
|
||||
Sprite* sprite = this->sprite();
|
||||
Palette* palette = this->palette();
|
||||
m_stream.seekp(0);
|
||||
|
||||
sprite->setPalette(palette, true);
|
||||
Sprite* sprite = this->sprite();
|
||||
Palette* pal = read_palette(m_stream);
|
||||
|
||||
sprite->setPalette(pal, true);
|
||||
sprite->incrementVersion();
|
||||
}
|
||||
|
||||
void AddPalette::onUndo()
|
||||
{
|
||||
Sprite* sprite = this->sprite();
|
||||
Palette* pal = this->palette();
|
||||
|
||||
write_palette(m_stream, pal);
|
||||
|
||||
sprite->deletePalette(pal);
|
||||
sprite->deletePalette(m_frame);
|
||||
sprite->incrementVersion();
|
||||
delete pal;
|
||||
}
|
||||
|
||||
void AddPalette::onRedo()
|
||||
{
|
||||
Sprite* sprite = this->sprite();
|
||||
Palette* pal = read_palette(m_stream);
|
||||
|
||||
sprite->setPalette(pal, true);
|
||||
sprite->incrementVersion();
|
||||
|
||||
m_stream.str(std::string());
|
||||
m_stream.clear();
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
|
@ -10,13 +10,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "app/cmd.h"
|
||||
#include "app/cmd/with_palette.h"
|
||||
#include "app/cmd/with_sprite.h"
|
||||
#include "doc/frame.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace doc {
|
||||
class Palette;
|
||||
class Sprite;
|
||||
}
|
||||
|
||||
@ -25,15 +25,13 @@ namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class AddPalette : public Cmd
|
||||
, public WithSprite
|
||||
, public WithPalette {
|
||||
, public WithSprite {
|
||||
public:
|
||||
AddPalette(Sprite* sprite, Palette* pal);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
void onRedo() override;
|
||||
size_t onMemSize() const override {
|
||||
return sizeof(*this) +
|
||||
(size_t)const_cast<std::stringstream*>(&m_stream)->tellp();
|
||||
@ -41,6 +39,7 @@ namespace cmd {
|
||||
|
||||
private:
|
||||
std::stringstream m_stream;
|
||||
frame_t m_frame;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
|
@ -31,10 +31,5 @@ void RemovePalette::onUndo()
|
||||
AddPalette::onRedo();
|
||||
}
|
||||
|
||||
void RemovePalette::onRedo()
|
||||
{
|
||||
AddPalette::onUndo();
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
@ -22,7 +22,6 @@ namespace cmd {
|
||||
protected:
|
||||
void onExecute() override;
|
||||
void onUndo() override;
|
||||
void onRedo() override;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
|
@ -11,10 +11,10 @@
|
||||
|
||||
#include "app/cmd/set_pixel_format.h"
|
||||
|
||||
#include "app/cmd/add_palette.h"
|
||||
#include "app/cmd/remove_palette.h"
|
||||
#include "app/cmd/replace_image.h"
|
||||
#include "app/cmd/set_cel_opacity.h"
|
||||
#include "app/cmd/set_palette.h"
|
||||
#include "app/document.h"
|
||||
#include "base/unique_ptr.h"
|
||||
#include "doc/cel.h"
|
||||
@ -85,14 +85,14 @@ SetPixelFormat::SetPixelFormat(Sprite* sprite,
|
||||
// all palettes and put only one grayscaled-palette at the first
|
||||
// frame.
|
||||
if (newFormat == IMAGE_GRAYSCALE) {
|
||||
// Add undoers to revert all palette changes.
|
||||
// Add cmds to revert all palette changes.
|
||||
PalettesList palettes = sprite->getPalettes();
|
||||
for (Palette* pal : palettes)
|
||||
m_seq.add(new cmd::RemovePalette(sprite, pal));
|
||||
if (pal->frame() != 0)
|
||||
m_seq.add(new cmd::RemovePalette(sprite, pal));
|
||||
|
||||
base::UniquePtr<Palette> graypal(Palette::createGrayscale());
|
||||
graypal->setFrame(0);
|
||||
m_seq.add(new cmd::AddPalette(sprite, graypal));
|
||||
m_seq.add(new cmd::SetPalette(sprite, 0, graypal));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,32 +0,0 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2015 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
|
||||
// published by the Free Software Foundation.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/cmd/with_palette.h"
|
||||
|
||||
#include "doc/palette.h"
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
|
||||
using namespace doc;
|
||||
|
||||
WithPalette::WithPalette(Palette* palette)
|
||||
: m_paletteId(palette->id())
|
||||
{
|
||||
}
|
||||
|
||||
Palette* WithPalette::palette()
|
||||
{
|
||||
return get<Palette>(m_paletteId);
|
||||
}
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
@ -1,34 +0,0 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2015 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
|
||||
// published by the Free Software Foundation.
|
||||
|
||||
#ifndef APP_CMD_WITH_PALETTE_H_INCLUDED
|
||||
#define APP_CMD_WITH_PALETTE_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "doc/object_id.h"
|
||||
|
||||
namespace doc {
|
||||
class Palette;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
namespace cmd {
|
||||
using namespace doc;
|
||||
|
||||
class WithPalette {
|
||||
public:
|
||||
WithPalette(Palette* palette);
|
||||
Palette* palette();
|
||||
|
||||
private:
|
||||
ObjectId m_paletteId;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
} // namespace app
|
||||
|
||||
#endif
|
@ -329,12 +329,18 @@ void Sprite::resetPalettes()
|
||||
}
|
||||
}
|
||||
|
||||
void Sprite::deletePalette(Palette* pal)
|
||||
void Sprite::deletePalette(frame_t frame)
|
||||
{
|
||||
ASSERT(pal != NULL);
|
||||
auto it = m_palettes.begin(), end = m_palettes.end();
|
||||
for (; it != end; ++it) {
|
||||
Palette* pal = *it;
|
||||
|
||||
base::remove_from_container(m_palettes, pal);
|
||||
delete pal; // palette
|
||||
if (pal->frame() == frame) {
|
||||
delete pal; // delete palette
|
||||
m_palettes.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RgbMap* Sprite::rgbMap(frame_t frame) const
|
||||
|
@ -102,7 +102,7 @@ namespace doc {
|
||||
// Removes all palettes from the sprites except the first one.
|
||||
void resetPalettes();
|
||||
|
||||
void deletePalette(Palette* pal);
|
||||
void deletePalette(frame_t frame);
|
||||
|
||||
RgbMap* rgbMap(frame_t frame) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user