mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-29 19:20:09 +00:00
Add --color-mode CLI option
This commit is contained in:
parent
1b57bb8ac3
commit
e4a4f44127
@ -34,6 +34,7 @@ AppOptions::AppOptions(int argc, const char* argv[])
|
||||
, m_saveAs(m_po.add("save-as").requiresValue("<filename>").description("Save the last given sprite with other format"))
|
||||
, m_palette(m_po.add("palette").requiresValue("<filename>").description("Change the palette of the last given sprite"))
|
||||
, m_scale(m_po.add("scale").requiresValue("<factor>").description("Resize all previously opened sprites"))
|
||||
, m_colorMode(m_po.add("color-mode").requiresValue("<mode>").description("Change color mode of all previously\nopened sprites:\n rgb\n grayscale\n indexed\n indexed-ordered-dithering"))
|
||||
, m_shrinkTo(m_po.add("shrink-to").requiresValue("width,height").description("Shrink each sprite if it is\nlarger than width or height"))
|
||||
, m_data(m_po.add("data").requiresValue("<filename.json>").description("File to store the sprite sheet metadata"))
|
||||
, m_format(m_po.add("format").requiresValue("<format>").description("Format to export the data file\n(json-hash, json-array)"))
|
||||
|
@ -48,6 +48,7 @@ public:
|
||||
const Option& saveAs() const { return m_saveAs; }
|
||||
const Option& palette() const { return m_palette; }
|
||||
const Option& scale() const { return m_scale; }
|
||||
const Option& colorMode() const { return m_colorMode; }
|
||||
const Option& shrinkTo() const { return m_shrinkTo; }
|
||||
const Option& data() const { return m_data; }
|
||||
const Option& format() const { return m_format; }
|
||||
@ -100,6 +101,7 @@ private:
|
||||
Option& m_saveAs;
|
||||
Option& m_palette;
|
||||
Option& m_scale;
|
||||
Option& m_colorMode;
|
||||
Option& m_shrinkTo;
|
||||
Option& m_data;
|
||||
Option& m_format;
|
||||
|
@ -342,6 +342,34 @@ void CliProcessor::process()
|
||||
ctx->executeCommand(command);
|
||||
}
|
||||
}
|
||||
// --color-mode <mode>
|
||||
else if (opt == &m_options.colorMode()) {
|
||||
Command* command = CommandsModule::instance()->getCommandByName(CommandId::ChangePixelFormat);
|
||||
Params params;
|
||||
if (value.value() == "rgb") {
|
||||
params.set("format", "rgb");
|
||||
}
|
||||
else if (value.value() == "grayscale") {
|
||||
params.set("format", "grayscale");
|
||||
}
|
||||
else if (value.value() == "indexed") {
|
||||
params.set("format", "indexed");
|
||||
}
|
||||
else if (value.value() == "indexed-ordered-dithering") {
|
||||
params.set("format", "indexed");
|
||||
params.set("dithering", "ordered");
|
||||
}
|
||||
else {
|
||||
throw std::runtime_error("--color-mode needs a valid color mode for conversion\n"
|
||||
"Usage: --color-mode <mode>\n"
|
||||
"Where <mode> can be rgb, grayscale, indexed, or indexed-ordered-dithering");
|
||||
}
|
||||
|
||||
for (auto doc : ctx->documents()) {
|
||||
ctx->setActiveDocument(static_cast<app::Document*>(doc));
|
||||
ctx->executeCommand(command, params);
|
||||
}
|
||||
}
|
||||
// --shrink-to <width,height>
|
||||
else if (opt == &m_options.shrinkTo()) {
|
||||
std::vector<std::string> dimensions;
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -100,7 +100,9 @@ void ChangePixelFormatCommand::onExecute(Context* context)
|
||||
document->getApi(transaction).setPixelFormat(sprite, m_format, m_dithering);
|
||||
transaction.commit();
|
||||
}
|
||||
app_refresh_screen();
|
||||
|
||||
if (context->isUIAvailable())
|
||||
app_refresh_screen();
|
||||
}
|
||||
|
||||
Command* CommandFactory::createChangePixelFormatCommand()
|
||||
|
Loading…
x
Reference in New Issue
Block a user