2015-02-12 23:16:25 +08:00
|
|
|
// 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.
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2012-01-06 06:45:03 +08:00
|
|
|
#include "config.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "app/app.h"
|
|
|
|
#include "app/commands/command.h"
|
|
|
|
#include "app/commands/params.h"
|
|
|
|
#include "app/context_access.h"
|
|
|
|
#include "app/document_api.h"
|
|
|
|
#include "app/modules/gui.h"
|
|
|
|
#include "app/modules/palettes.h"
|
2015-01-19 09:05:33 +08:00
|
|
|
#include "app/transaction.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/dithering_method.h"
|
|
|
|
#include "doc/image.h"
|
|
|
|
#include "doc/sprite.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
2015-02-12 23:16:25 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
class ChangePixelFormatCommand : public Command {
|
2012-02-13 10:21:06 +08:00
|
|
|
PixelFormat m_format;
|
2012-01-06 06:45:03 +08:00
|
|
|
DitheringMethod m_dithering;
|
|
|
|
public:
|
2012-02-13 10:21:06 +08:00
|
|
|
ChangePixelFormatCommand();
|
2014-08-15 10:07:47 +08:00
|
|
|
Command* clone() const override { return new ChangePixelFormatCommand(*this); }
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void onLoadParams(Params* params);
|
|
|
|
bool onEnabled(Context* context);
|
|
|
|
bool onChecked(Context* context);
|
|
|
|
void onExecute(Context* context);
|
|
|
|
};
|
|
|
|
|
2012-02-13 10:21:06 +08:00
|
|
|
ChangePixelFormatCommand::ChangePixelFormatCommand()
|
|
|
|
: Command("ChangePixelFormat",
|
|
|
|
"Change Pixel Format",
|
2012-01-06 06:45:03 +08:00
|
|
|
CmdUIOnlyFlag)
|
|
|
|
{
|
2012-02-13 10:21:06 +08:00
|
|
|
m_format = IMAGE_RGB;
|
2014-12-28 22:06:11 +08:00
|
|
|
m_dithering = DitheringMethod::NONE;
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
2012-02-13 10:21:06 +08:00
|
|
|
void ChangePixelFormatCommand::onLoadParams(Params* params)
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
2012-02-13 10:21:06 +08:00
|
|
|
std::string format = params->get("format");
|
|
|
|
if (format == "rgb") m_format = IMAGE_RGB;
|
|
|
|
else if (format == "grayscale") m_format = IMAGE_GRAYSCALE;
|
|
|
|
else if (format == "indexed") m_format = IMAGE_INDEXED;
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
std::string dithering = params->get("dithering");
|
|
|
|
if (dithering == "ordered")
|
2014-12-28 22:06:11 +08:00
|
|
|
m_dithering = DitheringMethod::ORDERED;
|
2012-01-06 06:45:03 +08:00
|
|
|
else
|
2014-12-28 22:06:11 +08:00
|
|
|
m_dithering = DitheringMethod::NONE;
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
2012-02-13 10:21:06 +08:00
|
|
|
bool ChangePixelFormatCommand::onEnabled(Context* context)
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
2013-03-12 07:29:45 +08:00
|
|
|
ContextWriter writer(context);
|
|
|
|
Sprite* sprite(writer.sprite());
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
if (sprite != NULL &&
|
2014-07-30 12:28:15 +08:00
|
|
|
sprite->pixelFormat() == IMAGE_INDEXED &&
|
2012-02-13 10:21:06 +08:00
|
|
|
m_format == IMAGE_INDEXED &&
|
2014-12-28 22:06:11 +08:00
|
|
|
m_dithering == DitheringMethod::ORDERED)
|
2012-01-06 06:45:03 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return sprite != NULL;
|
|
|
|
}
|
|
|
|
|
2012-02-13 10:21:06 +08:00
|
|
|
bool ChangePixelFormatCommand::onChecked(Context* context)
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
2013-03-12 07:29:45 +08:00
|
|
|
const ContextReader reader(context);
|
|
|
|
const Sprite* sprite = reader.sprite();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
if (sprite != NULL &&
|
2014-07-30 12:28:15 +08:00
|
|
|
sprite->pixelFormat() == IMAGE_INDEXED &&
|
2012-02-13 10:21:06 +08:00
|
|
|
m_format == IMAGE_INDEXED &&
|
2014-12-28 22:06:11 +08:00
|
|
|
m_dithering == DitheringMethod::ORDERED)
|
2012-01-06 06:45:03 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return
|
|
|
|
sprite != NULL &&
|
2014-07-30 12:28:15 +08:00
|
|
|
sprite->pixelFormat() == m_format;
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
2012-02-13 10:21:06 +08:00
|
|
|
void ChangePixelFormatCommand::onExecute(Context* context)
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
|
|
|
{
|
2013-03-12 07:29:45 +08:00
|
|
|
ContextWriter writer(context);
|
2015-01-19 09:05:33 +08:00
|
|
|
Transaction transaction(writer.context(), "Color Mode Change");
|
2013-03-12 07:29:45 +08:00
|
|
|
Document* document(writer.document());
|
|
|
|
Sprite* sprite(writer.sprite());
|
|
|
|
|
2015-01-19 09:05:33 +08:00
|
|
|
document->getApi(transaction).setPixelFormat(sprite, m_format, m_dithering);
|
|
|
|
transaction.commit();
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
2013-03-12 07:29:45 +08:00
|
|
|
app_refresh_screen();
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
2012-02-13 10:21:06 +08:00
|
|
|
Command* CommandFactory::createChangePixelFormatCommand()
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
2012-02-13 10:21:06 +08:00
|
|
|
return new ChangePixelFormatCommand;
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
} // namespace app
|