mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
sw_engine raster: refactoring the gradient rastering functions
The gradient rastering functions have been splitted into translucent and opaque.
This commit is contained in:
parent
6b5db72f67
commit
9d7a264610
1 changed files with 263 additions and 217 deletions
|
@ -596,7 +596,7 @@ static bool _rasterImage(SwSurface* surface, const uint32_t *img, uint32_t w, ui
|
|||
/* Gradient */
|
||||
/************************************************************************/
|
||||
|
||||
static bool _rasterLinearGradientRect(SwSurface* surface, const SwBBox& region, const SwFill* fill)
|
||||
static bool _rasterTranslucentLinearGradientRect(SwSurface* surface, const SwBBox& region, const SwFill* fill)
|
||||
{
|
||||
if (!fill || fill->linear.len < FLT_EPSILON) return false;
|
||||
|
||||
|
@ -604,8 +604,6 @@ static bool _rasterLinearGradientRect(SwSurface* surface, const SwBBox& region,
|
|||
auto h = static_cast<uint32_t>(region.max.y - region.min.y);
|
||||
auto w = static_cast<uint32_t>(region.max.x - region.min.x);
|
||||
|
||||
//Translucent Gradient
|
||||
if (fill->translucent) {
|
||||
auto tmpBuf = static_cast<uint32_t*>(alloca(surface->w * sizeof(uint32_t)));
|
||||
if (!tmpBuf) return false;
|
||||
|
||||
|
@ -616,8 +614,18 @@ static bool _rasterLinearGradientRect(SwSurface* surface, const SwBBox& region,
|
|||
dst[x] = tmpBuf[x] + ALPHA_BLEND(dst[x], 255 - surface->blender.alpha(tmpBuf[x]));
|
||||
}
|
||||
}
|
||||
//Opaque Gradient
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool _rasterOpaqueLinearGradientRect(SwSurface* surface, const SwBBox& region, const SwFill* fill)
|
||||
{
|
||||
if (!fill || fill->linear.len < FLT_EPSILON) return false;
|
||||
|
||||
auto buffer = surface->buffer + (region.min.y * surface->stride) + region.min.x;
|
||||
auto h = static_cast<uint32_t>(region.max.y - region.min.y);
|
||||
auto w = static_cast<uint32_t>(region.max.x - region.min.x);
|
||||
|
||||
if (surface->compositor) {
|
||||
auto method = surface->compositor->method;
|
||||
auto cbuffer = surface->compositor->image.data + (region.min.y * surface->stride) + region.min.x;
|
||||
|
@ -656,12 +664,11 @@ static bool _rasterLinearGradientRect(SwSurface* surface, const SwBBox& region,
|
|||
fillFetchLinear(fill, buffer + y * surface->stride, region.min.y + y, region.min.x, w);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool _rasterRadialGradientRect(SwSurface* surface, const SwBBox& region, const SwFill* fill)
|
||||
static bool _rasterTranslucentRadialGradientRect(SwSurface* surface, const SwBBox& region, const SwFill* fill)
|
||||
{
|
||||
if (!fill || fill->radial.a < FLT_EPSILON) return false;
|
||||
|
||||
|
@ -669,8 +676,6 @@ static bool _rasterRadialGradientRect(SwSurface* surface, const SwBBox& region,
|
|||
auto h = static_cast<uint32_t>(region.max.y - region.min.y);
|
||||
auto w = static_cast<uint32_t>(region.max.x - region.min.x);
|
||||
|
||||
//Translucent Gradient
|
||||
if (fill->translucent) {
|
||||
auto tmpBuf = static_cast<uint32_t*>(alloca(surface->w * sizeof(uint32_t)));
|
||||
if (!tmpBuf) return false;
|
||||
|
||||
|
@ -681,8 +686,18 @@ static bool _rasterRadialGradientRect(SwSurface* surface, const SwBBox& region,
|
|||
dst[x] = tmpBuf[x] + ALPHA_BLEND(dst[x], 255 - surface->blender.alpha(tmpBuf[x]));
|
||||
}
|
||||
}
|
||||
//Opaque Gradient
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool _rasterOpaqueRadialGradientRect(SwSurface* surface, const SwBBox& region, const SwFill* fill)
|
||||
{
|
||||
if (!fill || fill->radial.a < FLT_EPSILON) return false;
|
||||
|
||||
auto buffer = surface->buffer + (region.min.y * surface->stride) + region.min.x;
|
||||
auto h = static_cast<uint32_t>(region.max.y - region.min.y);
|
||||
auto w = static_cast<uint32_t>(region.max.x - region.min.x);
|
||||
|
||||
if (surface->compositor) {
|
||||
auto method = surface->compositor->method;
|
||||
auto cbuffer = surface->compositor->image.data + (region.min.y * surface->stride) + region.min.x;
|
||||
|
@ -722,12 +737,12 @@ static bool _rasterRadialGradientRect(SwSurface* surface, const SwBBox& region,
|
|||
fillFetchRadial(fill, dst, region.min.y + y, region.min.x, w);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool _rasterLinearGradientRle(SwSurface* surface, const SwRleData* rle, const SwFill* fill)
|
||||
static bool _rasterTranslucentLinearGradientRle(SwSurface* surface, const SwRleData* rle, const SwFill* fill)
|
||||
{
|
||||
if (!rle || !fill || fill->linear.len < FLT_EPSILON) return false;
|
||||
|
||||
|
@ -736,8 +751,6 @@ static bool _rasterLinearGradientRle(SwSurface* surface, const SwRleData* rle, c
|
|||
|
||||
auto span = rle->spans;
|
||||
|
||||
//Translucent Gradient
|
||||
if (fill->translucent) {
|
||||
for (uint32_t i = 0; i < rle->size; ++i) {
|
||||
auto dst = &surface->buffer[span->y * surface->stride + span->x];
|
||||
fillFetchLinear(fill, buf, span->y, span->x, span->len);
|
||||
|
@ -753,8 +766,19 @@ static bool _rasterLinearGradientRle(SwSurface* surface, const SwRleData* rle, c
|
|||
}
|
||||
++span;
|
||||
}
|
||||
//Opaque Gradient
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool _rasterOpaqueLinearGradientRle(SwSurface* surface, const SwRleData* rle, const SwFill* fill)
|
||||
{
|
||||
if (!rle || !fill || fill->linear.len < FLT_EPSILON) return false;
|
||||
|
||||
auto buf = static_cast<uint32_t*>(alloca(surface->w * sizeof(uint32_t)));
|
||||
if (!buf) return false;
|
||||
|
||||
auto span = rle->spans;
|
||||
|
||||
if (surface->compositor) {
|
||||
auto method = surface->compositor->method;
|
||||
auto cbuffer = surface->compositor->image.data;
|
||||
|
@ -797,12 +821,11 @@ static bool _rasterLinearGradientRle(SwSurface* surface, const SwRleData* rle, c
|
|||
++span;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool _rasterRadialGradientRle(SwSurface* surface, const SwRleData* rle, const SwFill* fill)
|
||||
static bool _rasterTranslucentRadialGradientRle(SwSurface* surface, const SwRleData* rle, const SwFill* fill)
|
||||
{
|
||||
if (!rle || !fill || fill->radial.a < FLT_EPSILON) return false;
|
||||
|
||||
|
@ -811,8 +834,6 @@ static bool _rasterRadialGradientRle(SwSurface* surface, const SwRleData* rle, c
|
|||
|
||||
auto span = rle->spans;
|
||||
|
||||
//Translucent Gradient
|
||||
if (fill->translucent) {
|
||||
for (uint32_t i = 0; i < rle->size; ++i) {
|
||||
auto dst = &surface->buffer[span->y * surface->stride + span->x];
|
||||
fillFetchRadial(fill, buf, span->y, span->x, span->len);
|
||||
|
@ -828,8 +849,19 @@ static bool _rasterRadialGradientRle(SwSurface* surface, const SwRleData* rle, c
|
|||
}
|
||||
++span;
|
||||
}
|
||||
//Opaque Gradient
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool _rasterOpaqueRadialGradientRle(SwSurface* surface, const SwRleData* rle, const SwFill* fill)
|
||||
{
|
||||
if (!rle || !fill || fill->radial.a < FLT_EPSILON) return false;
|
||||
|
||||
auto buf = static_cast<uint32_t*>(alloca(surface->w * sizeof(uint32_t)));
|
||||
if (!buf) return false;
|
||||
|
||||
auto span = rle->spans;
|
||||
|
||||
if (surface->compositor) {
|
||||
auto method = surface->compositor->method;
|
||||
auto cbuffer = surface->compositor->image.data;
|
||||
|
@ -872,7 +904,6 @@ static bool _rasterRadialGradientRle(SwSurface* surface, const SwRleData* rle, c
|
|||
++span;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -902,11 +933,21 @@ bool rasterGradientShape(SwSurface* surface, SwShape* shape, unsigned id)
|
|||
{
|
||||
//Fast Track
|
||||
if (shape->rect) {
|
||||
if (id == FILL_ID_LINEAR) return _rasterLinearGradientRect(surface, shape->bbox, shape->fill);
|
||||
return _rasterRadialGradientRect(surface, shape->bbox, shape->fill);
|
||||
if (id == FILL_ID_LINEAR) {
|
||||
if (shape->fill->translucent) return _rasterTranslucentLinearGradientRect(surface, shape->bbox, shape->fill);
|
||||
return _rasterOpaqueLinearGradientRect(surface, shape->bbox, shape->fill);
|
||||
} else {
|
||||
if (id == FILL_ID_LINEAR) return _rasterLinearGradientRle(surface, shape->rle, shape->fill);
|
||||
return _rasterRadialGradientRle(surface, shape->rle, shape->fill);
|
||||
if (shape->fill->translucent) return _rasterTranslucentRadialGradientRect(surface, shape->bbox, shape->fill);
|
||||
return _rasterOpaqueRadialGradientRect(surface, shape->bbox, shape->fill);
|
||||
}
|
||||
} else {
|
||||
if (id == FILL_ID_LINEAR) {
|
||||
if (shape->fill->translucent) return _rasterTranslucentLinearGradientRle(surface, shape->rle, shape->fill);
|
||||
return _rasterOpaqueLinearGradientRle(surface, shape->rle, shape->fill);
|
||||
} else {
|
||||
if (shape->fill->translucent) return _rasterTranslucentRadialGradientRle(surface, shape->rle, shape->fill);
|
||||
return _rasterOpaqueRadialGradientRle(surface, shape->rle, shape->fill);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -953,8 +994,13 @@ bool rasterStroke(SwSurface* surface, SwShape* shape, uint8_t r, uint8_t g, uint
|
|||
|
||||
bool rasterGradientStroke(SwSurface* surface, SwShape* shape, unsigned id)
|
||||
{
|
||||
if (id == FILL_ID_LINEAR) return _rasterLinearGradientRle(surface, shape->strokeRle, shape->stroke->fill);
|
||||
return _rasterRadialGradientRle(surface, shape->strokeRle, shape->stroke->fill);
|
||||
if (id == FILL_ID_LINEAR) {
|
||||
if (shape->fill->translucent) return _rasterTranslucentLinearGradientRle(surface, shape->strokeRle, shape->stroke->fill);
|
||||
return _rasterOpaqueLinearGradientRle(surface, shape->strokeRle, shape->stroke->fill);
|
||||
} else {
|
||||
if (shape->fill->translucent) return _rasterTranslucentRadialGradientRle(surface, shape->strokeRle, shape->stroke->fill);
|
||||
return _rasterOpaqueRadialGradientRle(surface, shape->strokeRle, shape->stroke->fill);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue