mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-13 19:44:28 +00:00
sw_engine: code refactoring
Introduced a blender alpha() to maintain clean and organized code.
This commit is contained in:
parent
72f89fcf53
commit
5643ecabd8
4 changed files with 75 additions and 72 deletions
|
@ -238,10 +238,13 @@ struct SwImage
|
|||
bool scaled = false; //draw scaled image
|
||||
};
|
||||
|
||||
typedef uint32_t(*SwJoin)(uint8_t r, uint8_t g, uint8_t b, uint8_t a); //color channel join
|
||||
typedef uint8_t(*SwAlpha)(uint8_t*); //blending alpha
|
||||
|
||||
struct SwBlender
|
||||
{
|
||||
uint32_t (*join)(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
|
||||
uint8_t (*alpha[(int)CompositeMethod::InvLumaMask + 1])(uint8_t*);
|
||||
SwJoin join;
|
||||
SwAlpha alpha[(int)CompositeMethod::InvLumaMask + 1];
|
||||
};
|
||||
|
||||
struct SwCompositor;
|
||||
|
|
|
@ -177,7 +177,7 @@ void _rasterGrayscale8(uint8_t *dst, uint32_t val, uint32_t offset, int32_t len)
|
|||
/* Rect */
|
||||
/************************************************************************/
|
||||
|
||||
static bool _rasterMaskedRect(SwSurface* surface, const SwBBox& region, uint8_t r, uint8_t g, uint8_t b, uint8_t a, uint8_t(*blender)(uint8_t*))
|
||||
static bool _rasterMaskedRect(SwSurface* surface, const SwBBox& region, uint8_t r, uint8_t g, uint8_t b, uint8_t a, SwAlpha alpha)
|
||||
{
|
||||
auto w = static_cast<uint32_t>(region.max.x - region.min.x);
|
||||
auto h = static_cast<uint32_t>(region.max.y - region.min.y);
|
||||
|
@ -194,7 +194,7 @@ static bool _rasterMaskedRect(SwSurface* surface, const SwBBox& region, uint8_t
|
|||
auto dst = &buffer[y * surface->stride];
|
||||
auto cmp = &cbuffer[y * surface->stride * csize];
|
||||
for (uint32_t x = 0; x < w; ++x, ++dst, cmp += csize) {
|
||||
auto tmp = ALPHA_BLEND(color, blender(cmp));
|
||||
auto tmp = ALPHA_BLEND(color, alpha(cmp));
|
||||
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp));
|
||||
}
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ static bool _rasterMaskedRect(SwSurface* surface, const SwBBox& region, uint8_t
|
|||
auto dst = &buffer[y * surface->stride];
|
||||
auto cmp = &cbuffer[y * surface->stride * csize];
|
||||
for (uint32_t x = 0; x < w; ++x, ++dst, cmp += csize) {
|
||||
auto tmp = _multiply<uint8_t>(a, blender(cmp));
|
||||
auto tmp = _multiply<uint8_t>(a, alpha(cmp));
|
||||
*dst = tmp + _multiply<uint8_t>(*dst, _ialpha(tmp));
|
||||
}
|
||||
}
|
||||
|
@ -263,7 +263,7 @@ static bool _rasterRect(SwSurface* surface, const SwBBox& region, uint8_t r, uin
|
|||
/* Rle */
|
||||
/************************************************************************/
|
||||
|
||||
static bool _rasterMaskedRle(SwSurface* surface, SwRleData* rle, uint8_t r, uint8_t g, uint8_t b, uint8_t a, uint8_t(*blender)(uint8_t*))
|
||||
static bool _rasterMaskedRle(SwSurface* surface, SwRleData* rle, uint8_t r, uint8_t g, uint8_t b, uint8_t a, SwAlpha alpha)
|
||||
{
|
||||
TVGLOG("SW_ENGINE", "Masked Rle");
|
||||
|
||||
|
@ -281,7 +281,7 @@ static bool _rasterMaskedRle(SwSurface* surface, SwRleData* rle, uint8_t r, uint
|
|||
if (span->coverage == 255) src = color;
|
||||
else src = ALPHA_BLEND(color, span->coverage);
|
||||
for (uint32_t x = 0; x < span->len; ++x, ++dst, cmp += csize) {
|
||||
auto tmp = ALPHA_BLEND(src, blender(cmp));
|
||||
auto tmp = ALPHA_BLEND(src, alpha(cmp));
|
||||
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp));
|
||||
}
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ static bool _rasterMaskedRle(SwSurface* surface, SwRleData* rle, uint8_t r, uint
|
|||
if (span->coverage == 255) src = a;
|
||||
else src = _multiply<uint8_t>(a, span->coverage);
|
||||
for (uint32_t x = 0; x < span->len; ++x, ++dst, cmp += csize) {
|
||||
auto tmp = _multiply<uint8_t>(src, blender(cmp));
|
||||
auto tmp = _multiply<uint8_t>(src, alpha(cmp));
|
||||
*dst = tmp + _multiply<uint8_t>(*dst, _ialpha(tmp));
|
||||
}
|
||||
}
|
||||
|
@ -381,7 +381,7 @@ static bool _transformedRleRGBAImage(SwSurface* surface, const SwImage* image, c
|
|||
/* RLE Scaled RGBA Image */
|
||||
/************************************************************************/
|
||||
|
||||
static bool _rasterScaledMaskedTranslucentRleRGBAImage(SwSurface* surface, const SwImage* image, const Matrix* itransform, const SwBBox& region, uint32_t opacity, uint32_t halfScale, uint8_t(*blender)(uint8_t*))
|
||||
static bool _rasterScaledMaskedTranslucentRleRGBAImage(SwSurface* surface, const SwImage* image, const Matrix* itransform, const SwBBox& region, uint32_t opacity, uint32_t halfScale, SwAlpha alpha)
|
||||
{
|
||||
TVGLOG("SW_ENGINE", "Scaled Masked Translucent Rle Image");
|
||||
|
||||
|
@ -395,12 +395,12 @@ static bool _rasterScaledMaskedTranslucentRleRGBAImage(SwSurface* surface, const
|
|||
if (sy >= image->h) continue;
|
||||
auto dst = &surface->buf32[span->y * surface->stride + span->x];
|
||||
auto cmp = &surface->compositor->image.buf8[(span->y * surface->compositor->image.stride + span->x) * csize];
|
||||
auto alpha = _multiply<uint32_t>(span->coverage, opacity);
|
||||
auto a = _multiply<uint32_t>(span->coverage, opacity);
|
||||
for (uint32_t x = static_cast<uint32_t>(span->x); x < static_cast<uint32_t>(span->x) + span->len; ++x, ++dst, cmp += csize) {
|
||||
auto sx = (uint32_t)(x * itransform->e11 + itransform->e13);
|
||||
if (sx >= image->w) continue;
|
||||
auto src = ALPHA_BLEND(_interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale), alpha);
|
||||
auto tmp = ALPHA_BLEND(src, blender(cmp));
|
||||
auto src = ALPHA_BLEND(_interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale), a);
|
||||
auto tmp = ALPHA_BLEND(src, alpha(cmp));
|
||||
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp));
|
||||
}
|
||||
}
|
||||
|
@ -411,12 +411,12 @@ static bool _rasterScaledMaskedTranslucentRleRGBAImage(SwSurface* surface, const
|
|||
if ((uint32_t)sy >= image->h) continue;
|
||||
auto dst = &surface->buf32[span->y * surface->stride + span->x];
|
||||
auto cmp = &surface->compositor->image.buf8[(span->y * surface->compositor->image.stride + span->x) * csize];
|
||||
auto alpha = _multiply<uint32_t>(span->coverage, opacity);
|
||||
auto a = _multiply<uint32_t>(span->coverage, opacity);
|
||||
for (uint32_t x = static_cast<uint32_t>(span->x); x < static_cast<uint32_t>(span->x) + span->len; ++x, ++dst, cmp += csize) {
|
||||
auto sx = x * itransform->e11 + itransform->e13;
|
||||
if ((uint32_t)sx >= image->w) continue;
|
||||
auto src = ALPHA_BLEND(_interpUpScaler(image->buf32, image->w, image->h, sx, sy), alpha);
|
||||
auto tmp = ALPHA_BLEND(src, blender(cmp));
|
||||
auto src = ALPHA_BLEND(_interpUpScaler(image->buf32, image->w, image->h, sx, sy), a);
|
||||
auto tmp = ALPHA_BLEND(src, alpha(cmp));
|
||||
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp));
|
||||
}
|
||||
}
|
||||
|
@ -425,7 +425,7 @@ static bool _rasterScaledMaskedTranslucentRleRGBAImage(SwSurface* surface, const
|
|||
}
|
||||
|
||||
|
||||
static bool _rasterScaledMaskedRleRGBAImage(SwSurface* surface, const SwImage* image, const Matrix* itransform, const SwBBox& region, uint32_t halfScale, uint8_t(*blender)(uint8_t*))
|
||||
static bool _rasterScaledMaskedRleRGBAImage(SwSurface* surface, const SwImage* image, const Matrix* itransform, const SwBBox& region, uint32_t halfScale, SwAlpha alpha)
|
||||
{
|
||||
TVGLOG("SW_ENGINE", "Scaled Masked Rle Image");
|
||||
|
||||
|
@ -443,7 +443,7 @@ static bool _rasterScaledMaskedRleRGBAImage(SwSurface* surface, const SwImage* i
|
|||
for (uint32_t x = static_cast<uint32_t>(span->x); x < static_cast<uint32_t>(span->x) + span->len; ++x, ++dst, cmp += csize) {
|
||||
auto sx = (uint32_t)(x * itransform->e11 + itransform->e13);
|
||||
if (sx >= image->w) continue;
|
||||
auto tmp = ALPHA_BLEND(_interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale), blender(cmp));
|
||||
auto tmp = ALPHA_BLEND(_interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale), alpha(cmp));
|
||||
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp));
|
||||
}
|
||||
} else {
|
||||
|
@ -451,7 +451,7 @@ static bool _rasterScaledMaskedRleRGBAImage(SwSurface* surface, const SwImage* i
|
|||
auto sx = (uint32_t)(x * itransform->e11 + itransform->e13);
|
||||
if (sx >= image->w) continue;
|
||||
auto src = ALPHA_BLEND(_interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale), span->coverage);
|
||||
auto tmp = ALPHA_BLEND(src, blender(cmp));
|
||||
auto tmp = ALPHA_BLEND(src, alpha(cmp));
|
||||
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp));
|
||||
}
|
||||
}
|
||||
|
@ -467,7 +467,7 @@ static bool _rasterScaledMaskedRleRGBAImage(SwSurface* surface, const SwImage* i
|
|||
for (uint32_t x = static_cast<uint32_t>(span->x); x < static_cast<uint32_t>(span->x) + span->len; ++x, ++dst, cmp += csize) {
|
||||
auto sx = x * itransform->e11 + itransform->e13;
|
||||
if ((uint32_t)sx >= image->w) continue;
|
||||
auto tmp = ALPHA_BLEND(_interpUpScaler(image->buf32, image->w, image->h, sx, sy), blender(cmp));
|
||||
auto tmp = ALPHA_BLEND(_interpUpScaler(image->buf32, image->w, image->h, sx, sy), alpha(cmp));
|
||||
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp));
|
||||
}
|
||||
} else {
|
||||
|
@ -475,7 +475,7 @@ static bool _rasterScaledMaskedRleRGBAImage(SwSurface* surface, const SwImage* i
|
|||
auto sx = x * itransform->e11 + itransform->e13;
|
||||
if ((uint32_t)sx >= image->w) continue;
|
||||
auto src = ALPHA_BLEND(_interpUpScaler(image->buf32, image->w, image->h, sx, sy), span->coverage);
|
||||
auto tmp = ALPHA_BLEND(src, blender(cmp));
|
||||
auto tmp = ALPHA_BLEND(src, alpha(cmp));
|
||||
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp));
|
||||
}
|
||||
}
|
||||
|
@ -601,7 +601,7 @@ static bool _scaledRleRGBAImage(SwSurface* surface, const SwImage* image, const
|
|||
/* RLE Direct RGBA Image */
|
||||
/************************************************************************/
|
||||
|
||||
static bool _rasterDirectMaskedTranslucentRleRGBAImage(SwSurface* surface, const SwImage* image, uint32_t opacity, uint8_t(*blender)(uint8_t*))
|
||||
static bool _rasterDirectMaskedTranslucentRleRGBAImage(SwSurface* surface, const SwImage* image, uint32_t opacity, SwAlpha alpha)
|
||||
{
|
||||
TVGLOG("SW_ENGINE", "Direct Masked Rle Image");
|
||||
|
||||
|
@ -613,15 +613,15 @@ static bool _rasterDirectMaskedTranslucentRleRGBAImage(SwSurface* surface, const
|
|||
auto dst = &surface->buf32[span->y * surface->stride + span->x];
|
||||
auto cmp = &cbuffer[(span->y * surface->compositor->image.stride + span->x) * csize];
|
||||
auto img = image->buf32 + (span->y + image->oy) * image->stride + (span->x + image->ox);
|
||||
auto alpha = _multiply<uint32_t>(span->coverage, opacity);
|
||||
if (alpha == 255) {
|
||||
auto a = _multiply<uint32_t>(span->coverage, opacity);
|
||||
if (a == 255) {
|
||||
for (uint32_t x = 0; x < span->len; ++x, ++dst, ++img, cmp += csize) {
|
||||
auto tmp = ALPHA_BLEND(*img, blender(cmp));
|
||||
auto tmp = ALPHA_BLEND(*img, alpha(cmp));
|
||||
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp));
|
||||
}
|
||||
} else {
|
||||
for (uint32_t x = 0; x < span->len; ++x, ++dst, ++img, cmp += csize) {
|
||||
auto tmp = ALPHA_BLEND(*img, _multiply<uint32_t>(alpha, blender(cmp)));
|
||||
auto tmp = ALPHA_BLEND(*img, _multiply<uint32_t>(a, alpha(cmp)));
|
||||
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp));
|
||||
}
|
||||
}
|
||||
|
@ -630,7 +630,7 @@ static bool _rasterDirectMaskedTranslucentRleRGBAImage(SwSurface* surface, const
|
|||
}
|
||||
|
||||
|
||||
static bool _rasterDirectMaskedRleRGBAImage(SwSurface* surface, const SwImage* image, uint8_t(*blender)(uint8_t*))
|
||||
static bool _rasterDirectMaskedRleRGBAImage(SwSurface* surface, const SwImage* image, SwAlpha alpha)
|
||||
{
|
||||
TVGLOG("SW_ENGINE", "Direct Masked Rle Image");
|
||||
|
||||
|
@ -644,12 +644,12 @@ static bool _rasterDirectMaskedRleRGBAImage(SwSurface* surface, const SwImage* i
|
|||
auto img = image->buf32 + (span->y + image->oy) * image->stride + (span->x + image->ox);
|
||||
if (span->coverage == 255) {
|
||||
for (uint32_t x = 0; x < span->len; ++x, ++dst, ++img, cmp += csize) {
|
||||
auto tmp = ALPHA_BLEND(*img, blender(cmp));
|
||||
auto tmp = ALPHA_BLEND(*img, alpha(cmp));
|
||||
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp));
|
||||
}
|
||||
} else {
|
||||
for (uint32_t x = 0; x < span->len; ++x, ++dst, ++img, cmp += csize) {
|
||||
auto tmp = ALPHA_BLEND(*img, _multiply<uint32_t>(span->coverage, blender(cmp)));
|
||||
auto tmp = ALPHA_BLEND(*img, _multiply<uint32_t>(span->coverage, alpha(cmp)));
|
||||
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp));
|
||||
}
|
||||
}
|
||||
|
@ -742,7 +742,7 @@ static bool _transformedRGBAImageMesh(SwSurface* surface, const SwImage* image,
|
|||
/*Scaled RGBA Image */
|
||||
/************************************************************************/
|
||||
|
||||
static bool _rasterScaledMaskedTranslucentRGBAImage(SwSurface* surface, const SwImage* image, const Matrix* itransform, const SwBBox& region, uint32_t opacity, uint32_t halfScale, uint8_t(*blender)(uint8_t*))
|
||||
static bool _rasterScaledMaskedTranslucentRGBAImage(SwSurface* surface, const SwImage* image, const Matrix* itransform, const SwBBox& region, uint32_t opacity, uint32_t halfScale, SwAlpha alpha)
|
||||
{
|
||||
TVGLOG("SW_ENGINE", "Scaled Masked Image");
|
||||
|
||||
|
@ -760,8 +760,8 @@ static bool _rasterScaledMaskedTranslucentRGBAImage(SwSurface* surface, const Sw
|
|||
for (auto x = region.min.x; x < region.max.x; ++x, ++dst, cmp += csize) {
|
||||
auto sx = (uint32_t)(x * itransform->e11 + itransform->e13);
|
||||
if (sx >= image->w) continue;
|
||||
auto alpha = _multiply<uint32_t>(opacity, blender(cmp));
|
||||
auto src = ALPHA_BLEND(_interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale), alpha);
|
||||
auto a = _multiply<uint32_t>(opacity, alpha(cmp));
|
||||
auto src = ALPHA_BLEND(_interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale), a);
|
||||
*dst = src + ALPHA_BLEND(*dst, _ialpha(src));
|
||||
}
|
||||
dbuffer += surface->stride;
|
||||
|
@ -777,8 +777,8 @@ static bool _rasterScaledMaskedTranslucentRGBAImage(SwSurface* surface, const Sw
|
|||
for (auto x = region.min.x; x < region.max.x; ++x, ++dst, cmp += csize) {
|
||||
auto sx = x * itransform->e11 + itransform->e13;
|
||||
if ((uint32_t)sx >= image->w) continue;
|
||||
auto alpha = _multiply<uint32_t>(opacity, blender(cmp));
|
||||
auto src = ALPHA_BLEND(_interpUpScaler(image->buf32, image->w, image->h, sx, sy), alpha);
|
||||
auto a = _multiply<uint32_t>(opacity, alpha(cmp));
|
||||
auto src = ALPHA_BLEND(_interpUpScaler(image->buf32, image->w, image->h, sx, sy), a);
|
||||
*dst = src + ALPHA_BLEND(*dst, _ialpha(src));
|
||||
}
|
||||
dbuffer += surface->stride;
|
||||
|
@ -789,7 +789,7 @@ static bool _rasterScaledMaskedTranslucentRGBAImage(SwSurface* surface, const Sw
|
|||
}
|
||||
|
||||
|
||||
static bool _rasterScaledMaskedRGBAImage(SwSurface* surface, const SwImage* image, const Matrix* itransform, const SwBBox& region, uint32_t halfScale, uint8_t (*blender)(uint8_t*))
|
||||
static bool _rasterScaledMaskedRGBAImage(SwSurface* surface, const SwImage* image, const Matrix* itransform, const SwBBox& region, uint32_t halfScale, SwAlpha alpha)
|
||||
{
|
||||
TVGLOG("SW_ENGINE", "Scaled Masked Image");
|
||||
|
||||
|
@ -807,7 +807,7 @@ static bool _rasterScaledMaskedRGBAImage(SwSurface* surface, const SwImage* imag
|
|||
for (auto x = region.min.x; x < region.max.x; ++x, ++dst, cmp += csize) {
|
||||
auto sx = (uint32_t)(x * itransform->e11 + itransform->e13);
|
||||
if (sx >= image->w) continue;
|
||||
auto src = ALPHA_BLEND(_interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale), blender(cmp));
|
||||
auto src = ALPHA_BLEND(_interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale), alpha(cmp));
|
||||
*dst = src + ALPHA_BLEND(*dst, _ialpha(src));
|
||||
}
|
||||
dbuffer += surface->stride;
|
||||
|
@ -823,7 +823,7 @@ static bool _rasterScaledMaskedRGBAImage(SwSurface* surface, const SwImage* imag
|
|||
for (auto x = region.min.x; x < region.max.x; ++x, ++dst, cmp += csize) {
|
||||
auto sx = x * itransform->e11 + itransform->e13;
|
||||
if ((uint32_t)sx >= image->w) continue;
|
||||
auto src = ALPHA_BLEND(_interpUpScaler(image->buf32, image->w, image->h, sx, sy), blender(cmp));
|
||||
auto src = ALPHA_BLEND(_interpUpScaler(image->buf32, image->w, image->h, sx, sy), alpha(cmp));
|
||||
*dst = src + ALPHA_BLEND(*dst, _ialpha(src));
|
||||
}
|
||||
dbuffer += surface->stride;
|
||||
|
@ -930,7 +930,7 @@ static bool _scaledRGBAImage(SwSurface* surface, const SwImage* image, const Mat
|
|||
/* Direct RGBA Image */
|
||||
/************************************************************************/
|
||||
|
||||
static bool _rasterDirectMaskedRGBAImage(SwSurface* surface, const SwImage* image, const SwBBox& region, uint8_t (*blender)(uint8_t*))
|
||||
static bool _rasterDirectMaskedRGBAImage(SwSurface* surface, const SwImage* image, const SwBBox& region, SwAlpha alpha)
|
||||
{
|
||||
TVGLOG("SW_ENGINE", "Direct Masked Image");
|
||||
|
||||
|
@ -947,7 +947,7 @@ static bool _rasterDirectMaskedRGBAImage(SwSurface* surface, const SwImage* imag
|
|||
auto cmp = cbuffer;
|
||||
auto src = sbuffer;
|
||||
for (uint32_t x = 0; x < w2; ++x, ++dst, ++src, cmp += csize) {
|
||||
auto tmp = ALPHA_BLEND(*src, blender(cmp));
|
||||
auto tmp = ALPHA_BLEND(*src, alpha(cmp));
|
||||
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp));
|
||||
}
|
||||
buffer += surface->stride;
|
||||
|
@ -958,7 +958,7 @@ static bool _rasterDirectMaskedRGBAImage(SwSurface* surface, const SwImage* imag
|
|||
}
|
||||
|
||||
|
||||
static bool _rasterDirectMaskedTranslucentRGBAImage(SwSurface* surface, const SwImage* image, const SwBBox& region, uint32_t opacity, uint8_t (*blender)(uint8_t*))
|
||||
static bool _rasterDirectMaskedTranslucentRGBAImage(SwSurface* surface, const SwImage* image, const SwBBox& region, uint32_t opacity, SwAlpha alpha)
|
||||
{
|
||||
TVGLOG("SW_ENGINE", "Direct Masked Translucent Image");
|
||||
|
||||
|
@ -975,7 +975,7 @@ static bool _rasterDirectMaskedTranslucentRGBAImage(SwSurface* surface, const Sw
|
|||
auto cmp = cbuffer;
|
||||
auto src = sbuffer;
|
||||
for (uint32_t x = 0; x < w2; ++x, ++dst, ++src, cmp += csize) {
|
||||
auto tmp = ALPHA_BLEND(*src, _multiply<uint32_t>(opacity, blender(cmp)));
|
||||
auto tmp = ALPHA_BLEND(*src, _multiply<uint32_t>(opacity, alpha(cmp)));
|
||||
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp));
|
||||
}
|
||||
buffer += surface->stride;
|
||||
|
@ -1059,7 +1059,7 @@ static bool _rasterRGBAImage(SwSurface* surface, SwImage* image, const Matrix* t
|
|||
/* Rect Linear Gradient */
|
||||
/************************************************************************/
|
||||
|
||||
static bool _rasterLinearGradientMaskedRect(SwSurface* surface, const SwBBox& region, const SwFill* fill, uint8_t (*blender)(uint8_t*))
|
||||
static bool _rasterLinearGradientMaskedRect(SwSurface* surface, const SwBBox& region, const SwFill* fill, SwAlpha alpha)
|
||||
{
|
||||
if (fill->linear.len < FLT_EPSILON) return false;
|
||||
|
||||
|
@ -1078,7 +1078,7 @@ static bool _rasterLinearGradientMaskedRect(SwSurface* surface, const SwBBox& re
|
|||
auto cmp = cbuffer;
|
||||
auto src = sbuffer;
|
||||
for (uint32_t x = 0; x < w; ++x, ++dst, ++src, cmp += csize) {
|
||||
auto tmp = ALPHA_BLEND(*src, blender(cmp));
|
||||
auto tmp = ALPHA_BLEND(*src, alpha(cmp));
|
||||
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp));
|
||||
}
|
||||
buffer += surface->stride;
|
||||
|
@ -1143,7 +1143,7 @@ static bool _rasterLinearGradientRect(SwSurface* surface, const SwBBox& region,
|
|||
/* Rle Linear Gradient */
|
||||
/************************************************************************/
|
||||
|
||||
static bool _rasterLinearGradientMaskedRle(SwSurface* surface, const SwRleData* rle, const SwFill* fill, uint8_t (*blender)(uint8_t*))
|
||||
static bool _rasterLinearGradientMaskedRle(SwSurface* surface, const SwRleData* rle, const SwFill* fill, SwAlpha alpha)
|
||||
{
|
||||
if (fill->linear.len < FLT_EPSILON) return false;
|
||||
|
||||
|
@ -1160,13 +1160,13 @@ static bool _rasterLinearGradientMaskedRle(SwSurface* surface, const SwRleData*
|
|||
auto src = buffer;
|
||||
if (span->coverage == 255) {
|
||||
for (uint32_t x = 0; x < span->len; ++x, ++dst, ++src, cmp += csize) {
|
||||
auto tmp = ALPHA_BLEND(*src, blender(cmp));
|
||||
auto tmp = ALPHA_BLEND(*src, alpha(cmp));
|
||||
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp));
|
||||
}
|
||||
} else {
|
||||
auto ialpha = 255 - span->coverage;
|
||||
for (uint32_t x = 0; x < span->len; ++x, ++dst, ++src, cmp += csize) {
|
||||
auto tmp = ALPHA_BLEND(*src, blender(cmp));
|
||||
auto tmp = ALPHA_BLEND(*src, alpha(cmp));
|
||||
tmp = ALPHA_BLEND(tmp, span->coverage) + ALPHA_BLEND(*dst, ialpha);
|
||||
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp));
|
||||
}
|
||||
|
@ -1245,7 +1245,7 @@ static bool _rasterLinearGradientRle(SwSurface* surface, const SwRleData* rle, c
|
|||
/* Rect Radial Gradient */
|
||||
/************************************************************************/
|
||||
|
||||
static bool _rasterRadialGradientMaskedRect(SwSurface* surface, const SwBBox& region, const SwFill* fill, uint8_t(*blender)(uint8_t*))
|
||||
static bool _rasterRadialGradientMaskedRect(SwSurface* surface, const SwBBox& region, const SwFill* fill, SwAlpha alpha)
|
||||
{
|
||||
if (fill->radial.a < FLT_EPSILON) return false;
|
||||
|
||||
|
@ -1264,7 +1264,7 @@ static bool _rasterRadialGradientMaskedRect(SwSurface* surface, const SwBBox& re
|
|||
auto cmp = cbuffer;
|
||||
auto src = sbuffer;
|
||||
for (uint32_t x = 0; x < w; ++x, ++dst, ++src, cmp += csize) {
|
||||
auto tmp = ALPHA_BLEND(*src, blender(cmp));
|
||||
auto tmp = ALPHA_BLEND(*src, alpha(cmp));
|
||||
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp));
|
||||
}
|
||||
buffer += surface->stride;
|
||||
|
@ -1330,7 +1330,7 @@ static bool _rasterRadialGradientRect(SwSurface* surface, const SwBBox& region,
|
|||
/* RLE Radial Gradient */
|
||||
/************************************************************************/
|
||||
|
||||
static bool _rasterRadialGradientMaskedRle(SwSurface* surface, const SwRleData* rle, const SwFill* fill, uint8_t(*blender)(uint8_t*))
|
||||
static bool _rasterRadialGradientMaskedRle(SwSurface* surface, const SwRleData* rle, const SwFill* fill, SwAlpha alpha)
|
||||
{
|
||||
if (fill->radial.a < FLT_EPSILON) return false;
|
||||
|
||||
|
@ -1347,12 +1347,12 @@ static bool _rasterRadialGradientMaskedRle(SwSurface* surface, const SwRleData*
|
|||
auto src = buffer;
|
||||
if (span->coverage == 255) {
|
||||
for (uint32_t x = 0; x < span->len; ++x, ++dst, ++src, cmp += csize) {
|
||||
auto tmp = ALPHA_BLEND(*src, blender(cmp));
|
||||
auto tmp = ALPHA_BLEND(*src, alpha(cmp));
|
||||
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp));
|
||||
}
|
||||
} else {
|
||||
for (uint32_t x = 0; x < span->len; ++x, ++dst, ++src, cmp += csize) {
|
||||
auto tmp = INTERPOLATE(span->coverage, ALPHA_BLEND(*src, blender(cmp)), *dst);
|
||||
auto tmp = INTERPOLATE(span->coverage, ALPHA_BLEND(*src, alpha(cmp)), *dst);
|
||||
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ static bool _arrange(const SwImage* image, const SwBBox* region, int& yStart, in
|
|||
}
|
||||
|
||||
|
||||
static void _rasterPolygonImageSegment(SwSurface* surface, const SwImage* image, const SwBBox* region, int yStart, int yEnd, uint32_t opacity, uint8_t(*blender)(uint8_t*), AASpans* aaSpans)
|
||||
static void _rasterPolygonImageSegment(SwSurface* surface, const SwImage* image, const SwBBox* region, int yStart, int yEnd, uint32_t opacity, SwAlpha alpha, AASpans* aaSpans)
|
||||
{
|
||||
#define TEXMAP_TRANSLUCENT
|
||||
#define TEXMAP_MASKING
|
||||
|
@ -79,7 +79,7 @@ static void _rasterPolygonImageSegment(SwSurface* surface, const SwImage* image,
|
|||
}
|
||||
|
||||
|
||||
static void _rasterPolygonImageSegment(SwSurface* surface, const SwImage* image, const SwBBox* region, int yStart, int yEnd, uint8_t(*blender)(uint8_t*), AASpans* aaSpans)
|
||||
static void _rasterPolygonImageSegment(SwSurface* surface, const SwImage* image, const SwBBox* region, int yStart, int yEnd, SwAlpha alpha, AASpans* aaSpans)
|
||||
{
|
||||
#define TEXMAP_MASKING
|
||||
#include "tvgSwRasterTexmapInternal.h"
|
||||
|
@ -102,7 +102,7 @@ static void _rasterPolygonImageSegment(SwSurface* surface, const SwImage* image,
|
|||
|
||||
|
||||
/* This mapping algorithm is based on Mikael Kalms's. */
|
||||
static void _rasterPolygonImage(SwSurface* surface, const SwImage* image, const SwBBox* region, uint32_t opacity, Polygon& polygon, uint8_t(*blender)(uint8_t*), AASpans* aaSpans)
|
||||
static void _rasterPolygonImage(SwSurface* surface, const SwImage* image, const SwBBox* region, uint32_t opacity, Polygon& polygon, SwAlpha alpha, AASpans* aaSpans)
|
||||
{
|
||||
float x[3] = {polygon.vertex[0].pt.x, polygon.vertex[1].pt.x, polygon.vertex[2].pt.x};
|
||||
float y[3] = {polygon.vertex[0].pt.y, polygon.vertex[1].pt.y, polygon.vertex[2].pt.y};
|
||||
|
@ -190,9 +190,9 @@ static void _rasterPolygonImage(SwSurface* surface, const SwImage* image, const
|
|||
dxdyb = dxdy[0];
|
||||
xb = x[0] + dy * dxdyb + (off_y * dxdyb);
|
||||
|
||||
if (blender) {
|
||||
if (opacity == 255) _rasterPolygonImageSegment(surface, image, region, yi[0], yi[1], blender, aaSpans);
|
||||
else _rasterPolygonImageSegment(surface, image, region, yi[0], yi[1], opacity, blender, aaSpans);
|
||||
if (alpha) {
|
||||
if (opacity == 255) _rasterPolygonImageSegment(surface, image, region, yi[0], yi[1], alpha, aaSpans);
|
||||
else _rasterPolygonImageSegment(surface, image, region, yi[0], yi[1], opacity, alpha, aaSpans);
|
||||
} else {
|
||||
if (opacity == 255) _rasterPolygonImageSegment(surface, image, region, yi[0], yi[1], aaSpans);
|
||||
else _rasterPolygonImageSegment(surface, image, region, yi[0], yi[1], opacity, aaSpans);
|
||||
|
@ -211,9 +211,9 @@ static void _rasterPolygonImage(SwSurface* surface, const SwImage* image, const
|
|||
// Set right edge X-slope and perform subpixel pre-stepping
|
||||
dxdyb = dxdy[2];
|
||||
xb = x[1] + (1 - (y[1] - yi[1])) * dxdyb + (off_y * dxdyb);
|
||||
if (blender) {
|
||||
if (opacity == 255) _rasterPolygonImageSegment(surface, image, region, yi[1], yi[2], blender, aaSpans);
|
||||
else _rasterPolygonImageSegment(surface, image, region, yi[1], yi[2], opacity, blender, aaSpans);
|
||||
if (alpha) {
|
||||
if (opacity == 255) _rasterPolygonImageSegment(surface, image, region, yi[1], yi[2], alpha, aaSpans);
|
||||
else _rasterPolygonImageSegment(surface, image, region, yi[1], yi[2], opacity, alpha, aaSpans);
|
||||
} else {
|
||||
if (opacity == 255) _rasterPolygonImageSegment(surface, image, region, yi[1], yi[2], aaSpans);
|
||||
else _rasterPolygonImageSegment(surface, image, region, yi[1], yi[2], opacity, aaSpans);
|
||||
|
@ -240,9 +240,9 @@ static void _rasterPolygonImage(SwSurface* surface, const SwImage* image, const
|
|||
ua = u[0] + dy * dudya + (off_y * dudya);
|
||||
va = v[0] + dy * dvdya + (off_y * dvdya);
|
||||
|
||||
if (blender) {
|
||||
if (opacity == 255) _rasterPolygonImageSegment(surface, image, region, yi[0], yi[1], blender, aaSpans);
|
||||
else _rasterPolygonImageSegment(surface, image, region, yi[0], yi[1], opacity, blender, aaSpans);
|
||||
if (alpha) {
|
||||
if (opacity == 255) _rasterPolygonImageSegment(surface, image, region, yi[0], yi[1], alpha, aaSpans);
|
||||
else _rasterPolygonImageSegment(surface, image, region, yi[0], yi[1], opacity, alpha, aaSpans);
|
||||
} else {
|
||||
if (opacity == 255) _rasterPolygonImageSegment(surface, image, region, yi[0], yi[1], aaSpans);
|
||||
else _rasterPolygonImageSegment(surface, image, region, yi[0], yi[1], opacity, aaSpans);
|
||||
|
@ -264,9 +264,9 @@ static void _rasterPolygonImage(SwSurface* surface, const SwImage* image, const
|
|||
ua = u[1] + dy * dudya + (off_y * dudya);
|
||||
va = v[1] + dy * dvdya + (off_y * dvdya);
|
||||
|
||||
if (blender) {
|
||||
if (opacity == 255) _rasterPolygonImageSegment(surface, image, region, yi[1], yi[2], blender, aaSpans);
|
||||
else _rasterPolygonImageSegment(surface, image, region, yi[1], yi[2], opacity, blender, aaSpans);
|
||||
if (alpha) {
|
||||
if (opacity == 255) _rasterPolygonImageSegment(surface, image, region, yi[1], yi[2], alpha, aaSpans);
|
||||
else _rasterPolygonImageSegment(surface, image, region, yi[1], yi[2], opacity, alpha, aaSpans);
|
||||
} else {
|
||||
if (opacity == 255) _rasterPolygonImageSegment(surface, image, region, yi[1], yi[2], aaSpans);
|
||||
else _rasterPolygonImageSegment(surface, image, region, yi[1], yi[2], opacity, aaSpans);
|
||||
|
@ -545,7 +545,7 @@ static bool _apply(SwSurface* surface, AASpans* aaSpans)
|
|||
| / |
|
||||
3 -- 2
|
||||
*/
|
||||
static bool _rasterTexmapPolygon(SwSurface* surface, const SwImage* image, const Matrix* transform, const SwBBox* region, uint32_t opacity, uint8_t(*blender)(uint8_t*))
|
||||
static bool _rasterTexmapPolygon(SwSurface* surface, const SwImage* image, const Matrix* transform, const SwBBox* region, uint32_t opacity, SwAlpha alpha)
|
||||
{
|
||||
//Exceptions: No dedicated drawing area?
|
||||
if ((!image->rle && !region) || (image->rle && image->rle->size == 0)) return false;
|
||||
|
@ -576,14 +576,14 @@ static bool _rasterTexmapPolygon(SwSurface* surface, const SwImage* image, const
|
|||
polygon.vertex[1] = vertices[1];
|
||||
polygon.vertex[2] = vertices[3];
|
||||
|
||||
_rasterPolygonImage(surface, image, region, opacity, polygon, blender, aaSpans);
|
||||
_rasterPolygonImage(surface, image, region, opacity, polygon, alpha, aaSpans);
|
||||
|
||||
//Draw the second polygon
|
||||
polygon.vertex[0] = vertices[1];
|
||||
polygon.vertex[1] = vertices[2];
|
||||
polygon.vertex[2] = vertices[3];
|
||||
|
||||
_rasterPolygonImage(surface, image, region, opacity, polygon, blender, aaSpans);
|
||||
_rasterPolygonImage(surface, image, region, opacity, polygon, alpha, aaSpans);
|
||||
|
||||
return _apply(surface, aaSpans);
|
||||
}
|
||||
|
@ -602,7 +602,7 @@ static bool _rasterTexmapPolygon(SwSurface* surface, const SwImage* image, const
|
|||
Should provide two Polygons, one for each triangle.
|
||||
// TODO: region?
|
||||
*/
|
||||
static bool _rasterTexmapPolygonMesh(SwSurface* surface, const SwImage* image, const RenderMesh* mesh, const Matrix* transform, const SwBBox* region, uint32_t opacity, uint8_t(*blender)(uint8_t*))
|
||||
static bool _rasterTexmapPolygonMesh(SwSurface* surface, const SwImage* image, const RenderMesh* mesh, const Matrix* transform, const SwBBox* region, uint32_t opacity, SwAlpha alpha)
|
||||
{
|
||||
//Exceptions: No dedicated drawing area?
|
||||
if ((!image->rle && !region) || (image->rle && image->rle->size == 0)) return false;
|
||||
|
@ -636,7 +636,7 @@ static bool _rasterTexmapPolygonMesh(SwSurface* surface, const SwImage* image, c
|
|||
auto aaSpans = _AASpans(ys, ye, image, region);
|
||||
if (aaSpans) {
|
||||
for (uint32_t i = 0; i < mesh->triangleCnt; i++) {
|
||||
_rasterPolygonImage(surface, image, region, opacity, transformedTris[i], blender, aaSpans);
|
||||
_rasterPolygonImage(surface, image, region, opacity, transformedTris[i], alpha, aaSpans);
|
||||
}
|
||||
// Apply to surface (note: frees the AA spans)
|
||||
_apply(surface, aaSpans);
|
||||
|
|
|
@ -131,9 +131,9 @@
|
|||
px = INTERPOLATE(ab, px, px2);
|
||||
}
|
||||
#if defined(TEXMAP_MASKING) && defined(TEXMAP_TRANSLUCENT)
|
||||
auto src = ALPHA_BLEND(px, _multiply<uint32_t>(opacity, blender(cmp)));
|
||||
auto src = ALPHA_BLEND(px, _multiply<uint32_t>(opacity, alpha(cmp)));
|
||||
#elif defined(TEXMAP_MASKING)
|
||||
auto src = ALPHA_BLEND(px, blender(cmp));
|
||||
auto src = ALPHA_BLEND(px, alpha(cmp));
|
||||
#elif defined(TEXMAP_TRANSLUCENT)
|
||||
auto src = ALPHA_BLEND(px, opacity);
|
||||
#else
|
||||
|
|
Loading…
Add table
Reference in a new issue