From 5ba9f17a97a6a9d763f438f27f669dcb55d59523 Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Fri, 19 Apr 2024 01:42:05 +0200 Subject: [PATCH] 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 --- src/renderer/tvgShape.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/renderer/tvgShape.h b/src/renderer/tvgShape.h index 582bea68..813cf9e2 100644 --- a/src/renderer/tvgShape.h +++ b/src/renderer/tvgShape.h @@ -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(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; }