mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-09 14:13:43 +00:00
sw_engine: fixing linear gradient rastering for shapes with composition
Masking and Inverse masking are for now rastered properly only for the linear gradients without the opacity.
This commit is contained in:
parent
cd6fb4f483
commit
fe32ca8de7
1 changed files with 42 additions and 35 deletions
|
@ -616,7 +616,6 @@ static bool _rasterLinearGradientRect(SwSurface* surface, const SwBBox& region,
|
||||||
|
|
||||||
//Translucent Gradient
|
//Translucent Gradient
|
||||||
if (fill->translucent) {
|
if (fill->translucent) {
|
||||||
|
|
||||||
auto tmpBuf = static_cast<uint32_t*>(alloca(surface->w * sizeof(uint32_t)));
|
auto tmpBuf = static_cast<uint32_t*>(alloca(surface->w * sizeof(uint32_t)));
|
||||||
if (!tmpBuf) return false;
|
if (!tmpBuf) return false;
|
||||||
|
|
||||||
|
@ -631,24 +630,35 @@ static bool _rasterLinearGradientRect(SwSurface* surface, const SwBBox& region,
|
||||||
} else {
|
} else {
|
||||||
if (surface->compositor) {
|
if (surface->compositor) {
|
||||||
auto method = surface->compositor->method;
|
auto method = surface->compositor->method;
|
||||||
uint32_t *shape = fill->ctable;
|
|
||||||
auto cbuffer = surface->compositor->image.data + (region.min.y * surface->stride) + region.min.x;
|
auto cbuffer = surface->compositor->image.data + (region.min.y * surface->stride) + region.min.x;
|
||||||
auto sbuffer = shape + (region.min.y ) + region.min.x;
|
auto sbuffer = static_cast<uint32_t*>(alloca(w * sizeof(uint32_t)));
|
||||||
for (uint32_t y = 0; y < h; ++y) {
|
if (!sbuffer) return false;
|
||||||
auto dst = &buffer[y * surface->stride];
|
|
||||||
auto cmp = &cbuffer[y * surface->stride];
|
|
||||||
auto src = &sbuffer[y];
|
|
||||||
if (method == CompositeMethod::AlphaMask) {
|
if (method == CompositeMethod::AlphaMask) {
|
||||||
for (uint32_t x = 0; x < w; ++x, ++dst, ++cmp) {
|
for (uint32_t y = 0; y < h; ++y) {
|
||||||
|
fillFetchLinear(fill, sbuffer, region.min.y + y, region.min.x, 0, w);
|
||||||
|
auto dst = buffer;
|
||||||
|
auto cmp = cbuffer;
|
||||||
|
auto src = sbuffer;
|
||||||
|
for (uint32_t x = 0; x < w; ++x, ++dst, ++cmp, ++src) {
|
||||||
auto tmp = ALPHA_BLEND(*src, surface->blender.alpha(*cmp));
|
auto tmp = ALPHA_BLEND(*src, surface->blender.alpha(*cmp));
|
||||||
*dst = tmp + ALPHA_BLEND(*dst, surface->blender.alpha(tmp));
|
*dst = tmp + ALPHA_BLEND(*dst, 255 - surface->blender.alpha(tmp));
|
||||||
}
|
}
|
||||||
|
buffer += surface->stride;
|
||||||
|
cbuffer += surface->stride;
|
||||||
}
|
}
|
||||||
if (method == CompositeMethod::InvAlphaMask) {
|
} else if (method == CompositeMethod::InvAlphaMask) {
|
||||||
for (uint32_t x = 0; x < w; ++x, ++dst, ++cmp) {
|
for (uint32_t y = 0; y < h; ++y) {
|
||||||
|
fillFetchLinear(fill, sbuffer, region.min.y + y, region.min.x, 0, w);
|
||||||
|
auto dst = buffer;
|
||||||
|
auto cmp = cbuffer;
|
||||||
|
auto src = sbuffer;
|
||||||
|
for (uint32_t x = 0; x < w; ++x, ++dst, ++cmp, ++src) {
|
||||||
auto tmp = ALPHA_BLEND(*src, 255 - surface->blender.alpha(*cmp));
|
auto tmp = ALPHA_BLEND(*src, 255 - surface->blender.alpha(*cmp));
|
||||||
*dst = tmp + ALPHA_BLEND(*dst, 255 - surface->blender.alpha(tmp));
|
*dst = tmp + ALPHA_BLEND(*dst, 255 - surface->blender.alpha(tmp));
|
||||||
}
|
}
|
||||||
|
buffer += surface->stride;
|
||||||
|
cbuffer += surface->stride;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -724,32 +734,29 @@ static bool _rasterLinearGradientRle(SwSurface* surface, const SwRleData* rle, c
|
||||||
if (surface->compositor) {
|
if (surface->compositor) {
|
||||||
auto method = surface->compositor->method;
|
auto method = surface->compositor->method;
|
||||||
auto cbuffer = surface->compositor->image.data;
|
auto cbuffer = surface->compositor->image.data;
|
||||||
auto tbuffer = static_cast<uint32_t*>(alloca(sizeof(uint32_t) * surface->w));
|
|
||||||
auto sbuffer = fill->ctable;
|
if (method == CompositeMethod::AlphaMask) {
|
||||||
for (uint32_t i = 0; i < rle->size; ++i) {
|
for (uint32_t i = 0; i < rle->size; ++i, ++span) {
|
||||||
|
fillFetchLinear(fill, buf, span->y, span->x, 0, span->len);
|
||||||
auto dst = &surface->buffer[span->y * surface->stride + span->x];
|
auto dst = &surface->buffer[span->y * surface->stride + span->x];
|
||||||
auto cmp = &cbuffer[span->y * surface->stride + span->x];
|
auto cmp = &cbuffer[span->y * surface->stride + span->x];
|
||||||
auto tmp = tbuffer;
|
auto src = buf;
|
||||||
auto src = &sbuffer[span->y];
|
for (uint32_t x = 0; x < span->len; ++x, ++dst, ++cmp, ++src) {
|
||||||
if (method == CompositeMethod::AlphaMask) {
|
auto tmp = ALPHA_BLEND(*src, surface->blender.alpha(*cmp));
|
||||||
for (uint32_t x = 0; x < span->len; ++x) {
|
*dst = tmp + ALPHA_BLEND(*dst, 255 - surface->blender.alpha(tmp));
|
||||||
auto ialpha = surface->blender.alpha(*cmp);
|
|
||||||
*tmp = ALPHA_BLEND(*src, ialpha);
|
|
||||||
dst[x] = *tmp + ALPHA_BLEND(dst[x], 255 - surface->blender.alpha(*tmp));
|
|
||||||
++tmp;
|
|
||||||
++cmp;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (method == CompositeMethod::InvAlphaMask) {
|
} else if (method == CompositeMethod::InvAlphaMask) {
|
||||||
for (uint32_t x = 0; x < span->len; ++x) {
|
for (uint32_t i = 0; i < rle->size; ++i, ++span) {
|
||||||
auto ialpha = 255 - surface->blender.alpha(*cmp);
|
fillFetchLinear(fill, buf, span->y, span->x, 0, span->len);
|
||||||
*tmp = ALPHA_BLEND(*src, ialpha);
|
auto dst = &surface->buffer[span->y * surface->stride + span->x];
|
||||||
dst[x] = *tmp + ALPHA_BLEND(dst[x], 255 - surface->blender.alpha(*tmp));
|
auto cmp = &cbuffer[span->y * surface->stride + span->x];
|
||||||
++tmp;
|
auto src = buf;
|
||||||
++cmp;
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
++span;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (uint32_t i = 0; i < rle->size; ++i) {
|
for (uint32_t i = 0; i < rle->size; ++i) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue