From edaafd99b31c48121b6b8951abd6b4d05d696cba Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Tue, 18 May 2021 02:57:48 +0200 Subject: [PATCH] sw_engine: fixing wrong 'if else' statement handling when gradient shapes rastered The cases when composition was applied were handled only for AlphaMask and InvAlphaMask. When opacity value was to be < 255, there was no code to handle this. --- src/lib/sw_engine/tvgSwRaster.cpp | 73 +++++++++++++++++-------------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/src/lib/sw_engine/tvgSwRaster.cpp b/src/lib/sw_engine/tvgSwRaster.cpp index f5cb6c94..872bd8a8 100644 --- a/src/lib/sw_engine/tvgSwRaster.cpp +++ b/src/lib/sw_engine/tvgSwRaster.cpp @@ -645,6 +645,7 @@ static bool _rasterOpaqueLinearGradientRect(SwSurface* surface, const SwBBox& re buffer += surface->stride; cbuffer += surface->stride; } + return true; } else if (method == CompositeMethod::InvAlphaMask) { for (uint32_t y = 0; y < h; ++y) { fillFetchLinear(fill, sbuffer, region.min.y + y, region.min.x, w); @@ -658,11 +659,12 @@ static bool _rasterOpaqueLinearGradientRect(SwSurface* surface, const SwBBox& re buffer += surface->stride; cbuffer += surface->stride; } + return true; } - } else { - for (uint32_t y = 0; y < h; ++y) { - fillFetchLinear(fill, buffer + y * surface->stride, region.min.y + y, region.min.x, w); - } + } + + for (uint32_t y = 0; y < h; ++y) { + fillFetchLinear(fill, buffer + y * surface->stride, region.min.y + y, region.min.x, w); } return true; } @@ -717,6 +719,7 @@ static bool _rasterOpaqueRadialGradientRect(SwSurface* surface, const SwBBox& re buffer += surface->stride; cbuffer += surface->stride; } + return true; } else if (method == CompositeMethod::InvAlphaMask) { for (uint32_t y = 0; y < h; ++y) { fillFetchRadial(fill, sbuffer, region.min.y + y, region.min.x, w); @@ -730,14 +733,14 @@ static bool _rasterOpaqueRadialGradientRect(SwSurface* surface, const SwBBox& re buffer += surface->stride; cbuffer += surface->stride; } - } - } else { - for (uint32_t y = 0; y < h; ++y) { - auto dst = &buffer[y * surface->stride]; - fillFetchRadial(fill, dst, region.min.y + y, region.min.x, w); + return true; } } + for (uint32_t y = 0; y < h; ++y) { + auto dst = &buffer[y * surface->stride]; + fillFetchRadial(fill, dst, region.min.y + y, region.min.x, w); + } return true; } @@ -803,6 +806,7 @@ static bool _rasterOpaqueLinearGradientRle(SwSurface* surface, const SwRleData* } } } + return true; } else if (method == CompositeMethod::InvAlphaMask) { for (uint32_t i = 0; i < rle->size; ++i, ++span) { fillFetchLinear(fill, buf, span->y, span->x, span->len); @@ -823,21 +827,22 @@ static bool _rasterOpaqueLinearGradientRle(SwSurface* surface, const SwRleData* } } } + return true; } - } else { - for (uint32_t i = 0; i < rle->size; ++i) { - if (span->coverage == 255) { - fillFetchLinear(fill, surface->buffer + span->y * surface->stride + span->x, span->y, span->x, span->len); - } else { - fillFetchLinear(fill, buf, span->y, span->x, span->len); - auto ialpha = 255 - span->coverage; - auto dst = &surface->buffer[span->y * surface->stride + span->x]; - for (uint32_t i = 0; i < span->len; ++i) { - dst[i] = ALPHA_BLEND(buf[i], span->coverage) + ALPHA_BLEND(dst[i], ialpha); - } + } + + for (uint32_t i = 0; i < rle->size; ++i) { + if (span->coverage == 255) { + fillFetchLinear(fill, surface->buffer + span->y * surface->stride + span->x, span->y, span->x, span->len); + } else { + fillFetchLinear(fill, buf, span->y, span->x, span->len); + auto ialpha = 255 - span->coverage; + auto dst = &surface->buffer[span->y * surface->stride + span->x]; + for (uint32_t i = 0; i < span->len; ++i) { + dst[i] = ALPHA_BLEND(buf[i], span->coverage) + ALPHA_BLEND(dst[i], ialpha); } - ++span; } + ++span; } return true; } @@ -904,6 +909,7 @@ static bool _rasterOpaqueRadialGradientRle(SwSurface* surface, const SwRleData* } } } + return true; } else if (method == CompositeMethod::InvAlphaMask) { for (uint32_t i = 0; i < rle->size; ++i, ++span) { fillFetchRadial(fill, buf, span->y, span->x, span->len); @@ -924,21 +930,22 @@ static bool _rasterOpaqueRadialGradientRle(SwSurface* surface, const SwRleData* } } } + return true; } - } else { - for (uint32_t i = 0; i < rle->size; ++i) { - auto dst = &surface->buffer[span->y * surface->stride + span->x]; - if (span->coverage == 255) { - fillFetchRadial(fill, dst, span->y, span->x, span->len); - } else { - fillFetchRadial(fill, buf, span->y, span->x, span->len); - auto ialpha = 255 - span->coverage; - for (uint32_t i = 0; i < span->len; ++i) { - dst[i] = ALPHA_BLEND(buf[i], span->coverage) + ALPHA_BLEND(dst[i], ialpha); - } + } + + for (uint32_t i = 0; i < rle->size; ++i) { + auto dst = &surface->buffer[span->y * surface->stride + span->x]; + if (span->coverage == 255) { + fillFetchRadial(fill, dst, span->y, span->x, span->len); + } else { + fillFetchRadial(fill, buf, span->y, span->x, span->len); + auto ialpha = 255 - span->coverage; + for (uint32_t i = 0; i < span->len; ++i) { + dst[i] = ALPHA_BLEND(buf[i], span->coverage) + ALPHA_BLEND(dst[i], ialpha); } - ++span; } + ++span; } return true; }