mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-05 21:57:20 +00:00
Fix alpha compositing on background layer using colors with alpha < 255
This commit is contained in:
parent
0f38a7dace
commit
940dd5f45c
@ -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
|
||||
|
@ -111,6 +111,13 @@ class OpaqueInkProcessing : public SimpleInkProcessing<OpaqueInkProcessing<Image
|
||||
public:
|
||||
OpaqueInkProcessing(ToolLoop* loop) {
|
||||
m_color = loop->getPrimaryColor();
|
||||
|
||||
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) {
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user