mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
sw_engine raster: code clean up.
eliminate logic duplication by introducing functions.
This commit is contained in:
parent
92265ef0f1
commit
fbe1b1fb5f
1 changed files with 92 additions and 74 deletions
|
@ -1349,27 +1349,27 @@ static bool _rasterRGBAImage(SwSurface* surface, SwImage* image, const Matrix* t
|
|||
/************************************************************************/
|
||||
|
||||
template<typename fillMethod>
|
||||
static bool _rasterGradientMaskedRect(SwSurface* surface, const SwBBox& region, const SwFill* fill)
|
||||
static void _rasterGradientMaskedRectDup(SwSurface* surface, const SwBBox& region, const SwFill* fill, SwBlendOp maskOp)
|
||||
{
|
||||
auto h = static_cast<uint32_t>(region.max.y - region.min.y);
|
||||
auto w = static_cast<uint32_t>(region.max.x - region.min.x);
|
||||
auto cstride = surface->compositor->image.stride;
|
||||
auto cbuffer = surface->compositor->image.buf32 + (region.min.y * cstride + region.min.x);
|
||||
auto method = surface->compositor->method;
|
||||
|
||||
TVGLOG("SW_ENGINE", "Masked(%d) Gradient [Region: %lu %lu %u %u]", (int)surface->compositor->method, region.min.x, region.min.y, w, h);
|
||||
|
||||
if (method == CompositeMethod::AddMask) {
|
||||
for (uint32_t y = 0; y < h; ++y) {
|
||||
fillMethod()(fill, cbuffer, region.min.y + y, region.min.x, w, opAddMask, 255);
|
||||
fillMethod()(fill, cbuffer, region.min.y + y, region.min.x, w, maskOp, 255);
|
||||
cbuffer += surface->stride;
|
||||
}
|
||||
} else if (method == CompositeMethod::SubtractMask) {
|
||||
for (uint32_t y = 0; y < h; ++y) {
|
||||
fillMethod()(fill, cbuffer, region.min.y + y, region.min.x, w, opSubMask, 255);
|
||||
cbuffer += surface->stride;
|
||||
}
|
||||
} else if (method == CompositeMethod::IntersectMask) {
|
||||
|
||||
|
||||
template<typename fillMethod>
|
||||
static void _rasterGradientMaskedRectInt(SwSurface* surface, const SwBBox& region, const SwFill* fill)
|
||||
{
|
||||
auto h = static_cast<uint32_t>(region.max.y - region.min.y);
|
||||
auto w = static_cast<uint32_t>(region.max.x - region.min.x);
|
||||
auto cstride = surface->compositor->image.stride;
|
||||
|
||||
for (uint32_t y = surface->compositor->bbox.min.y; y < surface->compositor->bbox.max.y; ++y) {
|
||||
auto cmp = surface->compositor->image.buf32 + (y * cstride + surface->compositor->bbox.min.x);
|
||||
if (y == region.min.y) {
|
||||
|
@ -1395,12 +1395,21 @@ static bool _rasterGradientMaskedRect(SwSurface* surface, const SwBBox& region,
|
|||
cmp += cstride;
|
||||
}
|
||||
}
|
||||
} else if (method == CompositeMethod::DifferenceMask) {
|
||||
for (uint32_t y = 0; y < h; ++y) {
|
||||
fillMethod()(fill, cbuffer, region.min.y + y, region.min.x, w, opDifMask, 255);
|
||||
cbuffer += surface->stride;
|
||||
}
|
||||
} else return false;
|
||||
|
||||
|
||||
template<typename fillMethod>
|
||||
static bool _rasterGradientMaskedRect(SwSurface* surface, const SwBBox& region, const SwFill* fill)
|
||||
{
|
||||
auto method = surface->compositor->method;
|
||||
|
||||
TVGLOG("SW_ENGINE", "Masked(%d) Gradient [Region: %lu %lu %lu %lu]", (int)surface->compositor->method, region.min.x, region.min.y, region.max.x - region.min.x, region.max.y - region.min.y);
|
||||
|
||||
if (method == CompositeMethod::AddMask) _rasterGradientMaskedRectDup<fillMethod>(surface, region, fill, opAddMask);
|
||||
else if (method == CompositeMethod::SubtractMask) _rasterGradientMaskedRectDup<fillMethod>(surface, region, fill, opSubMask);
|
||||
else if (method == CompositeMethod::DifferenceMask) _rasterGradientMaskedRectDup<fillMethod>(surface, region, fill, opDifMask);
|
||||
else if (method == CompositeMethod::IntersectMask) _rasterGradientMaskedRectInt<fillMethod>(surface, region, fill);
|
||||
else return false;
|
||||
|
||||
//Masking Composition
|
||||
return _rasterDirectRGBAImage(surface, &surface->compositor->image, surface->compositor->bbox, 255);
|
||||
|
@ -1493,26 +1502,26 @@ static bool _rasterRadialGradientRect(SwSurface* surface, const SwBBox& region,
|
|||
/************************************************************************/
|
||||
|
||||
template<typename fillMethod>
|
||||
static bool _rasterGradientMaskedRle(SwSurface* surface, const SwRleData* rle, const SwFill* fill)
|
||||
static void _rasterGradientMaskedRleDup(SwSurface* surface, const SwRleData* rle, const SwFill* fill, SwBlendOp maskOp)
|
||||
{
|
||||
TVGLOG("SW_ENGINE", "Masked(%d) Rle Linear Gradient", (int)surface->compositor->method);
|
||||
|
||||
auto span = rle->spans;
|
||||
auto cstride = surface->compositor->image.stride;
|
||||
auto cbuffer = surface->compositor->image.buf32;
|
||||
auto method = surface->compositor->method;
|
||||
|
||||
if (method == CompositeMethod::AddMask) {
|
||||
for (uint32_t i = 0; i < rle->size; ++i, ++span) {
|
||||
auto cmp = &cbuffer[span->y * cstride + span->x];
|
||||
fillMethod()(fill, cmp, span->y, span->x, span->len, opAddMask, span->coverage);
|
||||
fillMethod()(fill, cmp, span->y, span->x, span->len, maskOp, span->coverage);
|
||||
}
|
||||
} else if (method == CompositeMethod::SubtractMask) {
|
||||
for (uint32_t i = 0; i < rle->size; ++i, ++span) {
|
||||
auto cmp = &cbuffer[span->y * cstride + span->x];
|
||||
fillMethod()(fill, cmp, span->y, span->x, span->len, opSubMask, span->coverage);
|
||||
}
|
||||
} else if (method == CompositeMethod::IntersectMask) {
|
||||
|
||||
|
||||
template<typename fillMethod>
|
||||
static void _rasterGradientMaskedRleInt(SwSurface* surface, const SwRleData* rle, const SwFill* fill)
|
||||
{
|
||||
auto span = rle->spans;
|
||||
auto cstride = surface->compositor->image.stride;
|
||||
auto cbuffer = surface->compositor->image.buf32;
|
||||
|
||||
for (uint32_t y = surface->compositor->bbox.min.y; y < surface->compositor->bbox.max.y; ++y) {
|
||||
auto cmp = &cbuffer[y * cstride];
|
||||
uint32_t x = surface->compositor->bbox.min.x;
|
||||
|
@ -1527,12 +1536,21 @@ static bool _rasterGradientMaskedRle(SwSurface* surface, const SwRleData* rle, c
|
|||
}
|
||||
}
|
||||
}
|
||||
} else if (method == CompositeMethod::DifferenceMask) {
|
||||
for (uint32_t i = 0; i < rle->size; ++i, ++span) {
|
||||
auto cmp = &cbuffer[span->y * cstride + span->x];
|
||||
fillMethod()(fill, cmp, span->y, span->x, span->len, opDifMask, span->coverage);
|
||||
}
|
||||
} else return false;
|
||||
|
||||
|
||||
template<typename fillMethod>
|
||||
static bool _rasterGradientMaskedRle(SwSurface* surface, const SwRleData* rle, const SwFill* fill)
|
||||
{
|
||||
TVGLOG("SW_ENGINE", "Masked(%d) Rle Linear Gradient", (int)surface->compositor->method);
|
||||
|
||||
auto method = surface->compositor->method;
|
||||
|
||||
if (method == CompositeMethod::AddMask) _rasterGradientMaskedRleDup<fillMethod>(surface, rle, fill, opAddMask);
|
||||
else if (method == CompositeMethod::SubtractMask) _rasterGradientMaskedRleDup<fillMethod>(surface, rle, fill, opSubMask);
|
||||
else if (method == CompositeMethod::DifferenceMask) _rasterGradientMaskedRleDup<fillMethod>(surface, rle, fill, opDifMask);
|
||||
else if (method == CompositeMethod::IntersectMask) _rasterGradientMaskedRleInt<fillMethod>(surface, rle, fill);
|
||||
else return false;
|
||||
|
||||
//Masking Composition
|
||||
return _rasterDirectRGBAImage(surface, &surface->compositor->image, surface->compositor->bbox, 255);
|
||||
|
|
Loading…
Add table
Reference in a new issue