common: fix composition while masking

Using a mask (any type) with alpha set to less
than 255 through the fill(r, g, b, a) API resulted
in incorrect compositions of fill and stroke.
Incorrect results were also observed for luma masks,
as their alpha is calculated based on the other color
channels.

@issue: https://github.com/thorvg/thorvg/issues/1653
This commit is contained in:
Mira Grudzinska 2024-04-19 01:42:05 +02:00 committed by Hermet Park
parent 18a0c5e16e
commit 5ba9f17a97

View file

@ -76,8 +76,21 @@ struct Shape::Impl
//Composition test
const Paint* target;
auto method = shape->composite(&target);
if (!target || method == tvg::CompositeMethod::ClipPath) return false;
if (target->pImpl->opacity == 255 || target->pImpl->opacity == 0) return false;
if (!target || method == CompositeMethod::ClipPath) return false;
if (target->pImpl->opacity == 255 || target->pImpl->opacity == 0) {
if (target->identifier() == TVG_CLASS_ID_SHAPE) {
auto shape = static_cast<const Shape*>(target);
if (!shape->fill()) {
uint8_t r, g, b, a;
shape->fillColor(&r, &g, &b, &a);
if (a == 0 || a == 255) {
if (method == CompositeMethod::LumaMask || method == CompositeMethod::InvLumaMask) {
if ((r == 255 && g == 255 && b == 255) || (r == 0 && g == 0 && b == 0)) return false;
} else return false;
}
}
}
}
return true;
}