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,58 +1349,67 @@ static bool _rasterRGBAImage(SwSurface* surface, SwImage* image, const Matrix* t
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
|
||||||
template<typename fillMethod>
|
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 h = static_cast<uint32_t>(region.max.y - region.min.y);
|
||||||
auto w = static_cast<uint32_t>(region.max.x - region.min.x);
|
auto w = static_cast<uint32_t>(region.max.x - region.min.x);
|
||||||
auto cstride = surface->compositor->image.stride;
|
auto cstride = surface->compositor->image.stride;
|
||||||
auto cbuffer = surface->compositor->image.buf32 + (region.min.y * cstride + region.min.x);
|
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);
|
for (uint32_t y = 0; y < h; ++y) {
|
||||||
|
fillMethod()(fill, cbuffer, region.min.y + y, region.min.x, w, maskOp, 255);
|
||||||
|
cbuffer += surface->stride;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (method == CompositeMethod::AddMask) {
|
|
||||||
for (uint32_t y = 0; y < h; ++y) {
|
template<typename fillMethod>
|
||||||
fillMethod()(fill, cbuffer, region.min.y + y, region.min.x, w, opAddMask, 255);
|
static void _rasterGradientMaskedRectInt(SwSurface* surface, const SwBBox& region, const SwFill* fill)
|
||||||
cbuffer += surface->stride;
|
{
|
||||||
}
|
auto h = static_cast<uint32_t>(region.max.y - region.min.y);
|
||||||
} else if (method == CompositeMethod::SubtractMask) {
|
auto w = static_cast<uint32_t>(region.max.x - region.min.x);
|
||||||
for (uint32_t y = 0; y < h; ++y) {
|
auto cstride = surface->compositor->image.stride;
|
||||||
fillMethod()(fill, cbuffer, region.min.y + y, region.min.x, w, opSubMask, 255);
|
|
||||||
cbuffer += surface->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);
|
||||||
} else if (method == CompositeMethod::IntersectMask) {
|
if (y == region.min.y) {
|
||||||
for (uint32_t y = surface->compositor->bbox.min.y; y < surface->compositor->bbox.max.y; ++y) {
|
for (uint32_t y2 = y; y2 < region.max.y; ++y2) {
|
||||||
auto cmp = surface->compositor->image.buf32 + (y * cstride + surface->compositor->bbox.min.x);
|
auto tmp = cmp;
|
||||||
if (y == region.min.y) {
|
auto x = surface->compositor->bbox.min.x;
|
||||||
for (uint32_t y2 = y; y2 < region.max.y; ++y2) {
|
while (x < surface->compositor->bbox.max.x) {
|
||||||
auto tmp = cmp;
|
if (x == region.min.x) {
|
||||||
auto x = surface->compositor->bbox.min.x;
|
fillMethod()(fill, tmp, y2, x, w, opIntMask, 255);
|
||||||
while (x < surface->compositor->bbox.max.x) {
|
x += w;
|
||||||
if (x == region.min.x) {
|
tmp += w;
|
||||||
fillMethod()(fill, tmp, y2, x, w, opIntMask, 255);
|
} else {
|
||||||
x += w;
|
*tmp = 0;
|
||||||
tmp += w;
|
++tmp;
|
||||||
} else {
|
++x;
|
||||||
*tmp = 0;
|
|
||||||
++tmp;
|
|
||||||
++x;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
cmp += cstride;
|
|
||||||
}
|
}
|
||||||
y += (h - 1);
|
|
||||||
} else {
|
|
||||||
rasterRGBA32(cmp, 0x00000000, 0, surface->compositor->bbox.max.x -surface->compositor->bbox.min.x);
|
|
||||||
cmp += cstride;
|
cmp += cstride;
|
||||||
}
|
}
|
||||||
|
y += (h - 1);
|
||||||
|
} else {
|
||||||
|
rasterRGBA32(cmp, 0x00000000, 0, surface->compositor->bbox.max.x -surface->compositor->bbox.min.x);
|
||||||
|
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;
|
|
||||||
}
|
template<typename fillMethod>
|
||||||
} else return false;
|
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
|
//Masking Composition
|
||||||
return _rasterDirectRGBAImage(surface, &surface->compositor->image, surface->compositor->bbox, 255);
|
return _rasterDirectRGBAImage(surface, &surface->compositor->image, surface->compositor->bbox, 255);
|
||||||
|
@ -1492,47 +1501,56 @@ static bool _rasterRadialGradientRect(SwSurface* surface, const SwBBox& region,
|
||||||
/* Rle Gradient */
|
/* Rle Gradient */
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
|
||||||
|
template<typename fillMethod>
|
||||||
|
static void _rasterGradientMaskedRleDup(SwSurface* surface, const SwRleData* rle, const SwFill* fill, SwBlendOp maskOp)
|
||||||
|
{
|
||||||
|
auto span = rle->spans;
|
||||||
|
auto cstride = surface->compositor->image.stride;
|
||||||
|
auto cbuffer = surface->compositor->image.buf32;
|
||||||
|
|
||||||
|
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, maskOp, span->coverage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
while (x < surface->compositor->bbox.max.x) {
|
||||||
|
if (y == span->y && x == span->x && x + span->len <= surface->compositor->bbox.max.x) {
|
||||||
|
fillMethod()(fill, cmp, span->y, span->x, span->len, opIntMask, span->coverage);
|
||||||
|
x += span->len;
|
||||||
|
++span;
|
||||||
|
} else {
|
||||||
|
cmp[x] = 0;
|
||||||
|
++x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename fillMethod>
|
template<typename fillMethod>
|
||||||
static bool _rasterGradientMaskedRle(SwSurface* surface, const SwRleData* rle, const SwFill* fill)
|
static bool _rasterGradientMaskedRle(SwSurface* surface, const SwRleData* rle, const SwFill* fill)
|
||||||
{
|
{
|
||||||
TVGLOG("SW_ENGINE", "Masked(%d) Rle Linear Gradient", (int)surface->compositor->method);
|
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;
|
auto method = surface->compositor->method;
|
||||||
|
|
||||||
if (method == CompositeMethod::AddMask) {
|
if (method == CompositeMethod::AddMask) _rasterGradientMaskedRleDup<fillMethod>(surface, rle, fill, opAddMask);
|
||||||
for (uint32_t i = 0; i < rle->size; ++i, ++span) {
|
else if (method == CompositeMethod::SubtractMask) _rasterGradientMaskedRleDup<fillMethod>(surface, rle, fill, opSubMask);
|
||||||
auto cmp = &cbuffer[span->y * cstride + span->x];
|
else if (method == CompositeMethod::DifferenceMask) _rasterGradientMaskedRleDup<fillMethod>(surface, rle, fill, opDifMask);
|
||||||
fillMethod()(fill, cmp, span->y, span->x, span->len, opAddMask, span->coverage);
|
else if (method == CompositeMethod::IntersectMask) _rasterGradientMaskedRleInt<fillMethod>(surface, rle, fill);
|
||||||
}
|
else return false;
|
||||||
} 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) {
|
|
||||||
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;
|
|
||||||
while (x < surface->compositor->bbox.max.x) {
|
|
||||||
if (y == span->y && x == span->x && x + span->len <= surface->compositor->bbox.max.x) {
|
|
||||||
fillMethod()(fill, cmp, span->y, span->x, span->len, opIntMask, span->coverage);
|
|
||||||
x += span->len;
|
|
||||||
++span;
|
|
||||||
} else {
|
|
||||||
cmp[x] = 0;
|
|
||||||
++x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} 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;
|
|
||||||
|
|
||||||
//Masking Composition
|
//Masking Composition
|
||||||
return _rasterDirectRGBAImage(surface, &surface->compositor->image, surface->compositor->bbox, 255);
|
return _rasterDirectRGBAImage(surface, &surface->compositor->image, surface->compositor->bbox, 255);
|
||||||
|
|
Loading…
Add table
Reference in a new issue