mirror of
https://github.com/aseprite/aseprite.git
synced 2024-12-29 18:20:44 +00:00
Add combobox to select RGB5A5/Octree algorithms in ColorQuantization dialog
This commit is contained in:
parent
696bb9a537
commit
80cbb2caf5
@ -258,6 +258,7 @@
|
||||
<option id="with_alpha" type="bool" default="true" />
|
||||
<option id="dithering_algorithm" type="std::string" />
|
||||
<option id="dithering_factor" type="int" default="100" />
|
||||
<option id="advanced" type="bool" default="false" />
|
||||
</section>
|
||||
<section id="eyedropper" text="Editor">
|
||||
<option id="channel" type="EyedropperChannel" default="EyedropperChannel::COLOR_ALPHA" />
|
||||
|
@ -1258,10 +1258,11 @@ bg_color = Background Color:
|
||||
|
||||
[palette_from_sprite]
|
||||
title = Palette from Sprite
|
||||
new_palette = Create a new palette with a specific number of colors (or less):
|
||||
new_palette = Create new palette, color count limit:
|
||||
replace_palette = Replace current palette
|
||||
replace_range = Replace current range
|
||||
alpha_channel = Create entries with alpha component
|
||||
advanced_options = Advanced Options
|
||||
|
||||
[palette_popup]
|
||||
load = &Load
|
||||
|
@ -1,5 +1,6 @@
|
||||
<!-- Aseprite -->
|
||||
<!-- Copyright (C) 2015-2018 by David Capello -->
|
||||
<!-- Copyright (c) 2020 Igara Studio S.A. -->
|
||||
<!-- Copyright (c) 2015-2018 David Capello -->
|
||||
<gui>
|
||||
<window id="palette_from_sprite" text="@.title">
|
||||
<grid columns="2">
|
||||
@ -7,7 +8,15 @@
|
||||
<expr expansive="true" id="ncolors" magnet="true" />
|
||||
<radio id="current_palette" text="@.replace_palette" group="1" cell_hspan="2" />
|
||||
<radio id="current_range" text="@.replace_range" group="1" cell_hspan="2" />
|
||||
|
||||
<separator horizontal="true" cell_hspan="2" />
|
||||
|
||||
<check id="alpha_channel" text="@.alpha_channel" cell_hspan="2" />
|
||||
<check id="advanced_check" text="@.advanced_options" cell_hspan="2" />
|
||||
<hbox id="advanced" cell_hspan="2">
|
||||
<label text="@rgbmap_algorithm_selector.label" />
|
||||
<hbox id="rgbmap_algorithm_placeholder" />
|
||||
</hbox>
|
||||
|
||||
<separator horizontal="true" cell_hspan="2" />
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2019-2020 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -20,10 +20,12 @@
|
||||
#include "app/sprite_job.h"
|
||||
#include "app/transaction.h"
|
||||
#include "app/ui/color_bar.h"
|
||||
#include "app/ui/rgbmap_algorithm_selector.h"
|
||||
#include "app/ui_context.h"
|
||||
#include "doc/palette.h"
|
||||
#include "doc/sprite.h"
|
||||
#include "render/quantization.h"
|
||||
#include "ui/manager.h"
|
||||
|
||||
#include "palette_from_sprite.xml.h"
|
||||
|
||||
@ -36,8 +38,53 @@ struct ColorQuantizationParams : public NewParams {
|
||||
Param<bool> withAlpha { this, true, "withAlpha" };
|
||||
Param<int> maxColors { this, 256, "maxColors" };
|
||||
Param<bool> useRange { this, false, "useRange" };
|
||||
Param<RgbMapAlgorithm> algorithm { this, RgbMapAlgorithm::DEFAULT, "algorithm" };
|
||||
};
|
||||
|
||||
#if ENABLE_UI
|
||||
|
||||
class PaletteFromSpriteWindow : public app::gen::PaletteFromSprite {
|
||||
public:
|
||||
PaletteFromSpriteWindow() {
|
||||
rgbmapAlgorithmPlaceholder()->addChild(&m_algoSelector);
|
||||
|
||||
advancedCheck()->Click.connect(
|
||||
[this](ui::Event&){
|
||||
advanced()->setVisible(advancedCheck()->isSelected());
|
||||
|
||||
const gfx::Rect origBounds = bounds();
|
||||
setBounds(gfx::Rect(bounds().origin(), sizeHint()));
|
||||
manager()->invalidateRect(origBounds);
|
||||
});
|
||||
|
||||
m_algoSelector.Change.connect(
|
||||
[this](){
|
||||
switch (algorithm()) {
|
||||
case RgbMapAlgorithm::RGB5A3:
|
||||
alphaChannel()->setEnabled(true);
|
||||
break;
|
||||
case RgbMapAlgorithm::OCTREE:
|
||||
alphaChannel()->setSelected(false);
|
||||
alphaChannel()->setEnabled(false);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
doc::RgbMapAlgorithm algorithm() {
|
||||
return m_algoSelector.algorithm();
|
||||
}
|
||||
|
||||
void algorithm(const doc::RgbMapAlgorithm mapAlgo) {
|
||||
m_algoSelector.algorithm(mapAlgo);
|
||||
}
|
||||
|
||||
private:
|
||||
RgbMapAlgorithmSelector m_algoSelector;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
class ColorQuantizationCommand : public CommandWithNewParams<ColorQuantizationParams> {
|
||||
public:
|
||||
ColorQuantizationCommand();
|
||||
@ -65,8 +112,10 @@ void ColorQuantizationCommand::onExecute(Context* ctx)
|
||||
const bool ui = (params().ui() && ctx->isUIAvailable());
|
||||
#endif
|
||||
|
||||
auto& pref = Preferences::instance();
|
||||
bool withAlpha = params().withAlpha();
|
||||
int maxColors = params().maxColors();
|
||||
RgbMapAlgorithm algorithm = params().algorithm();
|
||||
bool createPal;
|
||||
|
||||
Site site = ctx->activeSite();
|
||||
@ -74,16 +123,22 @@ void ColorQuantizationCommand::onExecute(Context* ctx)
|
||||
|
||||
#ifdef ENABLE_UI
|
||||
if (ui) {
|
||||
app::gen::PaletteFromSprite window;
|
||||
PaletteFromSpriteWindow window;
|
||||
{
|
||||
ContextReader reader(ctx);
|
||||
const Palette* curPalette = site.sprite()->palette(site.frame());
|
||||
|
||||
if (!params().algorithm.isSet())
|
||||
algorithm = pref.experimental.rgbmapAlgorithm();
|
||||
if (!params().withAlpha.isSet())
|
||||
withAlpha = App::instance()->preferences().quantization.withAlpha();
|
||||
withAlpha = pref.quantization.withAlpha();
|
||||
|
||||
const bool advanced = pref.quantization.advanced();
|
||||
window.advancedCheck()->setSelected(advanced);
|
||||
window.advanced()->setVisible(advanced);
|
||||
|
||||
window.algorithm(algorithm);
|
||||
window.newPalette()->setSelected(true);
|
||||
window.alphaChannel()->setSelected(withAlpha);
|
||||
window.ncolors()->setTextf("%d", maxColors);
|
||||
|
||||
if (entries.picks() > 1) {
|
||||
@ -107,7 +162,10 @@ void ColorQuantizationCommand::onExecute(Context* ctx)
|
||||
|
||||
maxColors = window.ncolors()->textInt();
|
||||
withAlpha = window.alphaChannel()->isSelected();
|
||||
App::instance()->preferences().quantization.withAlpha(withAlpha);
|
||||
algorithm = window.algorithm();
|
||||
|
||||
pref.quantization.withAlpha(withAlpha);
|
||||
pref.quantization.advanced(window.advancedCheck()->isSelected());
|
||||
|
||||
if (window.newPalette()->isSelected()) {
|
||||
createPal = true;
|
||||
@ -139,8 +197,7 @@ void ColorQuantizationCommand::onExecute(Context* ctx)
|
||||
Palette tmpPalette(frame, entries.picks());
|
||||
|
||||
SpriteJob job(reader, "Color Quantization");
|
||||
const bool newBlend = Preferences::instance().experimental.newBlend();
|
||||
const RgbMapAlgorithm algorithm = Preferences::instance().experimental.rgbmapAlgorithm();
|
||||
const bool newBlend = pref.experimental.newBlend();
|
||||
job.startJobWithCallback(
|
||||
[sprite, withAlpha, &tmpPalette, &job, newBlend, algorithm]{
|
||||
render::create_palette_from_sprite(
|
||||
|
Loading…
Reference in New Issue
Block a user