mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-02 11:59:58 +00:00
Now DitheringSelector is used to select just a DitheringMatrix for gradients
This commit is contained in:
parent
317b493fb7
commit
2a15c58b5b
@ -183,7 +183,7 @@ public:
|
||||
if (from != IMAGE_INDEXED) {
|
||||
colorMode()->addChild(new ConversionItem(IMAGE_INDEXED));
|
||||
|
||||
m_ditheringSelector = new DitheringSelector;
|
||||
m_ditheringSelector = new DitheringSelector(DitheringSelector::SelectBoth);
|
||||
m_ditheringSelector->setExpansive(true);
|
||||
m_ditheringSelector->Change.connect(
|
||||
base::Bind<void>(&ColorModeWindow::onDithering, this));
|
||||
|
@ -1382,7 +1382,7 @@ ContextBar::ContextBar()
|
||||
addChild(m_tolerance = new ToleranceField());
|
||||
addChild(m_contiguous = new ContiguousField());
|
||||
addChild(m_paintBucketSettings = new PaintBucketSettingsField());
|
||||
addChild(m_ditheringSelector = new DitheringSelector());
|
||||
addChild(m_ditheringSelector = new DitheringSelector(DitheringSelector::SelectMatrix));
|
||||
m_ditheringSelector->setUseCustomWidget(false); // Disable custom widget because the context bar is too small
|
||||
|
||||
addChild(m_inkType = new InkTypeField(this));
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "doc/image.h"
|
||||
#include "doc/image_ref.h"
|
||||
#include "doc/primitives.h"
|
||||
#include "render/gradient.h"
|
||||
#include "render/quantization.h"
|
||||
#include "she/surface.h"
|
||||
#include "she/system.h"
|
||||
@ -33,10 +34,12 @@ namespace {
|
||||
|
||||
class DitherItem : public ListItem {
|
||||
public:
|
||||
|
||||
DitherItem(render::DitheringAlgorithm algo,
|
||||
const render::DitheringMatrix& matrix,
|
||||
const std::string& text)
|
||||
: ListItem(text)
|
||||
, m_matrixOnly(false)
|
||||
, m_algo(algo)
|
||||
, m_matrix(matrix)
|
||||
, m_preview(nullptr)
|
||||
@ -45,6 +48,18 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
DitherItem(const render::DitheringMatrix& matrix,
|
||||
const std::string& text)
|
||||
: ListItem(text)
|
||||
, m_matrixOnly(true)
|
||||
, m_algo(render::DitheringAlgorithm::None)
|
||||
, m_matrix(matrix)
|
||||
, m_preview(nullptr)
|
||||
, m_palId(0)
|
||||
, m_palMods(0)
|
||||
{
|
||||
}
|
||||
|
||||
render::DitheringAlgorithm algo() const { return m_algo; }
|
||||
render::DitheringMatrix matrix() const { return m_matrix; }
|
||||
|
||||
@ -66,18 +81,25 @@ private:
|
||||
|
||||
const int w = 128, h = 16;
|
||||
doc::ImageRef image1(doc::Image::create(doc::IMAGE_RGB, w, h));
|
||||
doc::clear_image(image1.get(), 0);
|
||||
for (int y=0; y<h; ++y)
|
||||
for (int x=0; x<w; ++x) {
|
||||
int v = 255 * x / (w-1);
|
||||
image1->putPixel(x, y, doc::rgba(v, v, v, 255));
|
||||
}
|
||||
render_rgba_linear_gradient(
|
||||
image1.get(),
|
||||
gfx::Point(0, 0),
|
||||
gfx::Point(w-1, 0),
|
||||
doc::rgba(0, 0, 0, 255),
|
||||
doc::rgba(255, 255, 255, 255),
|
||||
m_matrixOnly ? m_matrix: render::DitheringMatrix());
|
||||
|
||||
doc::ImageRef image2(doc::Image::create(doc::IMAGE_INDEXED, w, h));
|
||||
doc::clear_image(image2.get(), 0);
|
||||
render::convert_pixel_format(
|
||||
image1.get(), image2.get(), IMAGE_INDEXED,
|
||||
m_algo, m_matrix, nullptr, palette, true, -1, nullptr);
|
||||
doc::ImageRef image2;
|
||||
if (m_matrixOnly) {
|
||||
image2 = image1;
|
||||
}
|
||||
else {
|
||||
image2.reset(doc::Image::create(doc::IMAGE_INDEXED, w, h));
|
||||
doc::clear_image(image2.get(), 0);
|
||||
render::convert_pixel_format(
|
||||
image1.get(), image2.get(), IMAGE_INDEXED,
|
||||
m_algo, m_matrix, nullptr, palette, true, -1, nullptr);
|
||||
}
|
||||
|
||||
m_preview = she::instance()->createRgbaSurface(w, h);
|
||||
doc::convert_image_to_surface(image2.get(), palette, m_preview,
|
||||
@ -124,6 +146,7 @@ private:
|
||||
rc.y+4*guiscale()+textsz.h);
|
||||
}
|
||||
|
||||
bool m_matrixOnly;
|
||||
render::DitheringAlgorithm m_algo;
|
||||
render::DitheringMatrix m_matrix;
|
||||
she::Surface* m_preview;
|
||||
@ -133,24 +156,35 @@ private:
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
DitheringSelector::DitheringSelector()
|
||||
DitheringSelector::DitheringSelector(Type type)
|
||||
{
|
||||
setUseCustomWidget(true);
|
||||
|
||||
addItem(new DitherItem(render::DitheringAlgorithm::None,
|
||||
render::DitheringMatrix(), "No Dithering"));
|
||||
addItem(new DitherItem(render::DitheringAlgorithm::Ordered,
|
||||
render::BayerMatrix(8), "Ordered Dithering - Bayer Matrix 8x8"));
|
||||
addItem(new DitherItem(render::DitheringAlgorithm::Ordered,
|
||||
render::BayerMatrix(4), "Ordered Dithering - Bayer Matrix 4x4"));
|
||||
addItem(new DitherItem(render::DitheringAlgorithm::Ordered,
|
||||
render::BayerMatrix(2), "Ordered Dithering - Bayer Matrix 2x2"));
|
||||
addItem(new DitherItem(render::DitheringAlgorithm::Old,
|
||||
render::BayerMatrix(8), "Old Dithering - Bayer Matrix 8x8"));
|
||||
addItem(new DitherItem(render::DitheringAlgorithm::Old,
|
||||
render::BayerMatrix(4), "Old Dithering - Bayer Matrix 4x4"));
|
||||
addItem(new DitherItem(render::DitheringAlgorithm::Old,
|
||||
render::BayerMatrix(2), "Old Dithering - Bayer Matrix 2x2"));
|
||||
switch (type) {
|
||||
case SelectBoth:
|
||||
addItem(new DitherItem(render::DitheringAlgorithm::None,
|
||||
render::DitheringMatrix(), "No Dithering"));
|
||||
addItem(new DitherItem(render::DitheringAlgorithm::Ordered,
|
||||
render::BayerMatrix(8), "Ordered Dithering - Bayer Matrix 8x8"));
|
||||
addItem(new DitherItem(render::DitheringAlgorithm::Ordered,
|
||||
render::BayerMatrix(4), "Ordered Dithering - Bayer Matrix 4x4"));
|
||||
addItem(new DitherItem(render::DitheringAlgorithm::Ordered,
|
||||
render::BayerMatrix(2), "Ordered Dithering - Bayer Matrix 2x2"));
|
||||
addItem(new DitherItem(render::DitheringAlgorithm::Old,
|
||||
render::BayerMatrix(8), "Old Dithering - Bayer Matrix 8x8"));
|
||||
addItem(new DitherItem(render::DitheringAlgorithm::Old,
|
||||
render::BayerMatrix(4), "Old Dithering - Bayer Matrix 4x4"));
|
||||
addItem(new DitherItem(render::DitheringAlgorithm::Old,
|
||||
render::BayerMatrix(2), "Old Dithering - Bayer Matrix 2x2"));
|
||||
break;
|
||||
case SelectMatrix:
|
||||
addItem(new DitherItem(render::DitheringMatrix(), "No Dithering"));
|
||||
addItem(new DitherItem(render::BayerMatrix(8), "Bayer Matrix 8x8"));
|
||||
addItem(new DitherItem(render::BayerMatrix(4), "Bayer Matrix 4x4"));
|
||||
addItem(new DitherItem(render::BayerMatrix(2), "Bayer Matrix 2x2"));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
setSelectedItemIndex(0);
|
||||
setSizeHint(getItem(0)->sizeHint());
|
||||
|
@ -17,7 +17,12 @@ namespace app {
|
||||
|
||||
class DitheringSelector : public ui::ComboBox {
|
||||
public:
|
||||
DitheringSelector();
|
||||
enum Type {
|
||||
SelectBoth,
|
||||
SelectMatrix,
|
||||
};
|
||||
|
||||
DitheringSelector(Type type);
|
||||
|
||||
render::DitheringAlgorithm ditheringAlgorithm();
|
||||
render::DitheringMatrix ditheringMatrix();
|
||||
|
Loading…
Reference in New Issue
Block a user