From 0d5ba77ba4306181d7f4c34caa84fa8a33dd000f Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 20 Aug 2015 12:37:58 -0300 Subject: [PATCH] Add support to create palettes for Indexed images (fix #751) --- src/app/commands/cmd_color_quantization.cpp | 11 ++++------- src/app/file/file.cpp | 2 +- src/app/ui/color_bar.cpp | 3 ++- src/render/quantization.cpp | 2 +- src/render/quantization.h | 2 +- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/app/commands/cmd_color_quantization.cpp b/src/app/commands/cmd_color_quantization.cpp index d872eb0a7..45b39719e 100644 --- a/src/app/commands/cmd_color_quantization.cpp +++ b/src/app/commands/cmd_color_quantization.cpp @@ -55,10 +55,9 @@ public: private: void onJob() override { - render::create_palette_from_rgb(m_sprite, - 0, m_sprite->lastFrame(), - m_withAlpha, m_palette, - this); + render::create_palette_from_sprite( + m_sprite, 0, m_sprite->lastFrame(), + m_withAlpha, m_palette, this); } bool onPaletteOptimizerContinue() override { @@ -83,9 +82,7 @@ ColorQuantizationCommand::ColorQuantizationCommand() bool ColorQuantizationCommand::onEnabled(Context* context) { - ContextWriter writer(context); - Sprite* sprite(writer.sprite()); - return (sprite && sprite->pixelFormat() == IMAGE_RGB); + return context->checkFlags(ContextFlags::ActiveDocumentIsWritable); } void ColorQuantizationCommand::onExecute(Context* context) diff --git a/src/app/file/file.cpp b/src/app/file/file.cpp index ebaf83e3f..838b940c3 100644 --- a/src/app/file/file.cpp +++ b/src/app/file/file.cpp @@ -739,7 +739,7 @@ void fop_post_load(FileOp* fop) sprite->getPalettes().size() <= 1 && sprite->palette(frame_t(0))->isBlack()) { base::SharedPtr palette( - render::create_palette_from_rgb( + render::create_palette_from_sprite( sprite, frame_t(0), sprite->lastFrame(), true, nullptr, nullptr)); diff --git a/src/app/ui/color_bar.cpp b/src/app/ui/color_bar.cpp index 2131c601c..fbc345e43 100644 --- a/src/app/ui/color_bar.cpp +++ b/src/app/ui/color_bar.cpp @@ -369,7 +369,8 @@ void ColorBar::onFocusPaletteView() void ColorBar::onBeforeExecuteCommand(CommandExecutionEvent& ev) { if (ev.command()->id() == CommandId::SetPalette || - ev.command()->id() == CommandId::LoadPalette) + ev.command()->id() == CommandId::LoadPalette || + ev.command()->id() == CommandId::ColorQuantization) showRemap(); } diff --git a/src/render/quantization.cpp b/src/render/quantization.cpp index 553d72447..a52d13c55 100644 --- a/src/render/quantization.cpp +++ b/src/render/quantization.cpp @@ -33,7 +33,7 @@ namespace render { using namespace doc; using namespace gfx; -Palette* create_palette_from_rgb( +Palette* create_palette_from_sprite( const Sprite* sprite, frame_t fromFrame, frame_t toFrame, diff --git a/src/render/quantization.h b/src/render/quantization.h index 2d943d0f0..ce5b1a12d 100644 --- a/src/render/quantization.h +++ b/src/render/quantization.h @@ -44,7 +44,7 @@ namespace render { }; // Creates a new palette suitable to quantize the given RGB sprite to Indexed color. - Palette* create_palette_from_rgb( + Palette* create_palette_from_sprite( const Sprite* sprite, frame_t fromFrame, frame_t toFrame,