From 8e2feb31bd2a047ff8c1580174571df85deeb7b3 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 28 Jul 2015 10:45:35 -0300 Subject: [PATCH] Implement LockAlphaInkProcessing for indexed images --- src/app/tools/ink_processing.h | 55 ++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/src/app/tools/ink_processing.h b/src/app/tools/ink_processing.h index 1d7d41809..f03e9af45 100644 --- a/src/app/tools/ink_processing.h +++ b/src/app/tools/ink_processing.h @@ -135,9 +135,9 @@ private: template class LockAlphaInkProcessing : public DoubleInkProcessing, ImageTraits> { public: - LockAlphaInkProcessing(ToolLoop* loop) { - m_color = loop->getPrimaryColor(); - m_opacity = loop->getOpacity(); + LockAlphaInkProcessing(ToolLoop* loop) + : m_color(loop->getPrimaryColor()) + , m_opacity(loop->getOpacity()) { } void processPixel(int x, int y) { @@ -145,8 +145,8 @@ public: } private: - color_t m_color; - int m_opacity; + const color_t m_color; + const int m_opacity; }; template<> @@ -168,9 +168,38 @@ void LockAlphaInkProcessing::processPixel(int x, int y) { } template<> -void LockAlphaInkProcessing::processPixel(int x, int y) { - *m_dstAddress = m_color; -} +class LockAlphaInkProcessing : public DoubleInkProcessing, IndexedTraits> { +public: + LockAlphaInkProcessing(ToolLoop* loop) + : m_palette(get_current_palette()) + , m_rgbmap(loop->getRgbMap()) + , m_color(m_palette->getEntry(loop->getPrimaryColor())) + , m_opacity(loop->getOpacity()) + , m_maskIndex(loop->getLayer()->isBackground() ? -1: loop->sprite()->transparentColor()) { + } + + void processPixel(int x, int y) { + color_t c = *m_srcAddress; + if (c == m_maskIndex) + c = m_palette->getEntry(c) & rgba_rgb_mask; // Alpha = 0 + else + c = m_palette->getEntry(c); + + color_t result = rgba_blender_normal(c, m_color, m_opacity); + *m_dstAddress = m_palette->findBestfit( + rgba_getr(result), + rgba_getg(result), + rgba_getb(result), + rgba_geta(c), m_maskIndex); + } + +private: + const Palette* m_palette; + const RgbMap* m_rgbmap; + const color_t m_color; + const int m_opacity; + const int m_maskIndex; +}; ////////////////////////////////////////////////////////////////////// // Transparent Ink @@ -211,12 +240,12 @@ public: m_rgbmap(loop->getRgbMap()), m_opacity(loop->getOpacity()), m_color(m_palette->getEntry(loop->getPrimaryColor())), - m_maskColor(loop->getLayer()->isBackground() ? -1: loop->sprite()->transparentColor()) { + m_maskIndex(loop->getLayer()->isBackground() ? -1: loop->sprite()->transparentColor()) { } void processPixel(int x, int y) { color_t c = *m_srcAddress; - if (c == m_maskColor) + if (c == m_maskIndex) c = m_palette->getEntry(c) & rgba_rgb_mask; // Alpha = 0 else c = m_palette->getEntry(c); @@ -231,9 +260,9 @@ public: private: const Palette* m_palette; const RgbMap* m_rgbmap; - int m_opacity; - color_t m_color; - color_t m_maskColor; + const int m_opacity; + const color_t m_color; + const int m_maskIndex; }; //////////////////////////////////////////////////////////////////////