diff --git a/src/app/color_utils.cpp b/src/app/color_utils.cpp index 5398184c0..5d3b334f9 100644 --- a/src/app/color_utils.cpp +++ b/src/app/color_utils.cpp @@ -111,7 +111,7 @@ doc::color_t color_utils::color_for_layer(const app::Color& color, Layer* layer) doc::color_t color_utils::color_for_target_mask(const app::Color& color, const ColorTarget& colorTarget) { - doc::color_t c = -1; + int c = -1; if (color.getType() == app::Color::MaskType) { c = colorTarget.maskColor(); @@ -129,38 +129,38 @@ doc::color_t color_utils::color_for_target_mask(const app::Color& color, const C c = color.getIndex(); } else { - c = get_current_palette()->findBestfit( - color.getRed(), - color.getGreen(), - color.getBlue(), - color.getAlpha(), - colorTarget.isTransparent() ? - colorTarget.maskColor(): // Don't return the mask color - -1); // Return any color, we are in a background layer. + int r = color.getRed(); + int g = color.getGreen(); + int b = color.getBlue(); + int a = color.getAlpha(); + int mask = (colorTarget.isTransparent() ? + colorTarget.maskColor(): // Don't return the mask color + -1); + + c = get_current_palette()->findExactMatch(r, g, b, a, mask); + if (c < 0) + c = get_current_palette()->findBestfit(r, g, b, a, mask); } break; } } + return (doc::color_t)c; +} + +// TODO remove this function using a special RGB background layer (24bpp or 32bpp ignoring alpha) +doc::color_t color_utils::color_for_target(const app::Color& color, const ColorTarget& colorTarget) +{ + doc::color_t c = color_utils::color_for_target_mask(color, colorTarget); + + if (colorTarget.isBackground()) { + switch (colorTarget.pixelFormat()) { + case IMAGE_RGB: c |= doc::rgba_a_mask; break; + case IMAGE_GRAYSCALE: c |= doc::graya_a_mask; break; + } + } + return c; } -doc::color_t color_utils::color_for_target(const app::Color& color, const ColorTarget& colorTarget) -{ - doc::color_t c = color_utils::color_for_target_mask(color, colorTarget); - - switch (colorTarget.pixelFormat()) { - case IMAGE_RGB: - if (colorTarget.isBackground()) - c |= doc::rgba(0, 0, 0, 255); - break; - case IMAGE_GRAYSCALE: - if (colorTarget.isBackground()) - c |= doc::graya(0, 255); - break; - } - - return c; -} - } // namespace app diff --git a/src/app/tools/ink_processing.h b/src/app/tools/ink_processing.h index 36ec7fe83..1d7b4e6b4 100644 --- a/src/app/tools/ink_processing.h +++ b/src/app/tools/ink_processing.h @@ -111,6 +111,13 @@ class OpaqueInkProcessing : public SimpleInkProcessinggetPrimaryColor(); + + if (loop->getLayer()->isBackground()) { + switch (loop->sprite()->pixelFormat()) { + case IMAGE_RGB: m_color |= rgba_a_mask; break; + case IMAGE_GRAYSCALE: m_color |= graya_a_mask; break; + } + } } void processPixel(int x, int y) { diff --git a/src/app/ui/editor/tool_loop_impl.cpp b/src/app/ui/editor/tool_loop_impl.cpp index bacacb26b..1b7b81927 100644 --- a/src/app/ui/editor/tool_loop_impl.cpp +++ b/src/app/ui/editor/tool_loop_impl.cpp @@ -108,8 +108,8 @@ public: , m_pointShape(m_tool->getPointShape(m_button)) , m_intertwine(m_tool->getIntertwine(m_button)) , m_tracePolicy(m_tool->getTracePolicy(m_button)) - , m_fgColor(color_utils::color_for_layer(fgColor, m_layer)) - , m_bgColor(color_utils::color_for_layer(bgColor, m_layer)) + , m_fgColor(color_utils::color_for_target_mask(fgColor, ColorTarget(m_layer))) + , m_bgColor(color_utils::color_for_target_mask(bgColor, ColorTarget(m_layer))) , m_primaryColor(button == tools::ToolLoop::Left ? m_fgColor: m_bgColor) , m_secondaryColor(button == tools::ToolLoop::Left ? m_bgColor: m_fgColor) {