mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
sw_engine raster: adding antialiasing to the gradient rastering functions
The gradient rastering functions with composition did not take antialiasing into account. The missing part has been added.
This commit is contained in:
parent
9d7a264610
commit
fcad63ec1f
1 changed files with 49 additions and 13 deletions
|
@ -789,10 +789,19 @@ static bool _rasterOpaqueLinearGradientRle(SwSurface* surface, const SwRleData*
|
|||
auto dst = &surface->buffer[span->y * surface->stride + span->x];
|
||||
auto cmp = &cbuffer[span->y * surface->stride + span->x];
|
||||
auto src = buf;
|
||||
if (span->coverage == 255) {
|
||||
for (uint32_t x = 0; x < span->len; ++x, ++dst, ++cmp, ++src) {
|
||||
auto tmp = ALPHA_BLEND(*src, surface->blender.alpha(*cmp));
|
||||
*dst = tmp + ALPHA_BLEND(*dst, 255 - surface->blender.alpha(tmp));
|
||||
}
|
||||
} else {
|
||||
auto ialpha = 255 - span->coverage;
|
||||
for (uint32_t x = 0; x < span->len; ++x, ++dst, ++cmp, ++src) {
|
||||
auto tmp = ALPHA_BLEND(*src, surface->blender.alpha(*cmp));
|
||||
tmp = ALPHA_BLEND(tmp, span->coverage) + ALPHA_BLEND(*dst, ialpha);
|
||||
*dst = tmp + ALPHA_BLEND(*dst, 255 - surface->blender.alpha(tmp));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (method == CompositeMethod::InvAlphaMask) {
|
||||
for (uint32_t i = 0; i < rle->size; ++i, ++span) {
|
||||
|
@ -800,10 +809,19 @@ static bool _rasterOpaqueLinearGradientRle(SwSurface* surface, const SwRleData*
|
|||
auto dst = &surface->buffer[span->y * surface->stride + span->x];
|
||||
auto cmp = &cbuffer[span->y * surface->stride + span->x];
|
||||
auto src = buf;
|
||||
if (span->coverage == 255) {
|
||||
for (uint32_t x = 0; x < span->len; ++x, ++dst, ++cmp, ++src) {
|
||||
auto tmp = ALPHA_BLEND(*src, 255 - surface->blender.alpha(*cmp));
|
||||
*dst = tmp + ALPHA_BLEND(*dst, 255 - surface->blender.alpha(tmp));
|
||||
}
|
||||
} else {
|
||||
auto ialpha = 255 - span->coverage;
|
||||
for (uint32_t x = 0; x < span->len; ++x, ++dst, ++cmp, ++src) {
|
||||
auto tmp = ALPHA_BLEND(*src, 255 - surface->blender.alpha(*cmp));
|
||||
tmp = ALPHA_BLEND(tmp, span->coverage) + ALPHA_BLEND(*dst, ialpha);
|
||||
*dst = tmp + ALPHA_BLEND(*dst, 255 - surface->blender.alpha(tmp));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -872,10 +890,19 @@ static bool _rasterOpaqueRadialGradientRle(SwSurface* surface, const SwRleData*
|
|||
auto dst = &surface->buffer[span->y * surface->stride + span->x];
|
||||
auto cmp = &cbuffer[span->y * surface->stride + span->x];
|
||||
auto src = buf;
|
||||
if (span->coverage == 255) {
|
||||
for (uint32_t x = 0; x < span->len; ++x, ++dst, ++cmp, ++src) {
|
||||
auto tmp = ALPHA_BLEND(*src, surface->blender.alpha(*cmp));
|
||||
*dst = tmp + ALPHA_BLEND(*dst, 255 - surface->blender.alpha(tmp));
|
||||
}
|
||||
} else {
|
||||
auto ialpha = 255 - span->coverage;
|
||||
for (uint32_t x = 0; x < span->len; ++x, ++dst, ++cmp, ++src) {
|
||||
auto tmp = ALPHA_BLEND(*src, surface->blender.alpha(*cmp));
|
||||
tmp = ALPHA_BLEND(tmp, span->coverage) + ALPHA_BLEND(*dst, ialpha);
|
||||
*dst = tmp + ALPHA_BLEND(*dst, 255 - surface->blender.alpha(tmp));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (method == CompositeMethod::InvAlphaMask) {
|
||||
for (uint32_t i = 0; i < rle->size; ++i, ++span) {
|
||||
|
@ -883,10 +910,19 @@ static bool _rasterOpaqueRadialGradientRle(SwSurface* surface, const SwRleData*
|
|||
auto dst = &surface->buffer[span->y * surface->stride + span->x];
|
||||
auto cmp = &cbuffer[span->y * surface->stride + span->x];
|
||||
auto src = buf;
|
||||
if (span->coverage == 255) {
|
||||
for (uint32_t x = 0; x < span->len; ++x, ++dst, ++cmp, ++src) {
|
||||
auto tmp = ALPHA_BLEND(*src, 255 - surface->blender.alpha(*cmp));
|
||||
*dst = tmp + ALPHA_BLEND(*dst, 255 - surface->blender.alpha(tmp));
|
||||
}
|
||||
} else {
|
||||
auto ialpha = 255 - span->coverage;
|
||||
for (uint32_t x = 0; x < span->len; ++x, ++dst, ++cmp, ++src) {
|
||||
auto tmp = ALPHA_BLEND(*src, 255 - surface->blender.alpha(*cmp));
|
||||
tmp = ALPHA_BLEND(tmp, span->coverage) + ALPHA_BLEND(*dst, ialpha);
|
||||
*dst = tmp + ALPHA_BLEND(*dst, 255 - surface->blender.alpha(tmp));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue