diff --git a/src/lib/sw_engine/tvgSwCommon.h b/src/lib/sw_engine/tvgSwCommon.h index be72e4e6..5b371aaf 100644 --- a/src/lib/sw_engine/tvgSwCommon.h +++ b/src/lib/sw_engine/tvgSwCommon.h @@ -240,7 +240,6 @@ struct SwImage 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 -typedef uint32_t(*SwBlendOp)(uint32_t s, uint32_t d, uint8_t a); //src, dst, alpha struct SwBlender { @@ -303,30 +302,33 @@ static inline SwCoord HALF_STROKE(float width) return TO_SWCOORD(width * 0.5f); } -static inline uint8_t _multiply(uint8_t c, uint8_t a) +static inline uint8_t MULTIPLY(uint8_t c, uint8_t a) { return ((c * a + 0xff) >> 8); } -static inline uint8_t _alpha(uint32_t c) +static inline uint8_t ALPHA(uint32_t c) { return (c >> 24); } -static inline uint8_t _ialpha(uint32_t c) +static inline uint8_t IALPHA(uint32_t c) { return (~c >> 24); } + +typedef uint32_t(*SwBlendOp)(uint32_t s, uint32_t d, uint8_t a); //src, dst, alpha + static inline uint32_t opAlphaBlend(uint32_t s, uint32_t d, uint8_t a) { auto t = ALPHA_BLEND(s, a); - return t + ALPHA_BLEND(d, _ialpha(t)); + return t + ALPHA_BLEND(d, IALPHA(t)); } static inline uint32_t opBlend(uint32_t s, uint32_t d, TVG_UNUSED uint8_t a) { - return s + ALPHA_BLEND(d, _ialpha(s)); + return s + ALPHA_BLEND(d, IALPHA(s)); } static inline uint32_t opInterpolate(uint32_t s, uint32_t d, uint8_t a) @@ -382,10 +384,10 @@ void imageFree(SwImage* image); bool fillGenColorTable(SwFill* fill, const Fill* fdata, const Matrix* transform, SwSurface* surface, uint32_t opacity, bool ctable); void fillReset(SwFill* fill); void fillFree(SwFill* fill); -void fillRasterLinear(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, SwBlendOp op = nullptr, uint8_t a = 255); //blending ver. -void fillRasterLinear(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, uint8_t* cmp, SwAlpha alpha, uint8_t csize, uint8_t opacity); //masking ver. -void fillRasterRadial(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, SwBlendOp op = nullptr, uint8_t a = 255); //blending ver. -void fillRasterRadial(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, uint8_t* cmp, SwAlpha alpha, uint8_t csize, uint8_t opacity); //masking ver. +void fillLinear(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, SwBlendOp op = nullptr, uint8_t a = 255); //blending ver. +void fillLinear(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, uint8_t* cmp, SwAlpha alpha, uint8_t csize, uint8_t opacity); //masking ver. +void fillRadial(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, SwBlendOp op = nullptr, uint8_t a = 255); //blending ver. +void fillRadial(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, uint8_t* cmp, SwAlpha alpha, uint8_t csize, uint8_t opacity); //masking ver. SwRleData* rleRender(SwRleData* rle, const SwOutline* outline, const SwBBox& renderRegion, bool antiAlias); SwRleData* rleRender(const SwBBox* bbox); diff --git a/src/lib/sw_engine/tvgSwFill.cpp b/src/lib/sw_engine/tvgSwFill.cpp index df7a1b57..1a432ea8 100644 --- a/src/lib/sw_engine/tvgSwFill.cpp +++ b/src/lib/sw_engine/tvgSwFill.cpp @@ -233,7 +233,7 @@ static inline uint32_t _pixel(const SwFill* fill, float pos) /* External Class Implementation */ /************************************************************************/ -void fillRasterRadial(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, uint8_t* cmp, SwAlpha alpha, uint8_t csize, uint8_t opacity) +void fillRadial(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, uint8_t* cmp, SwAlpha alpha, uint8_t csize, uint8_t opacity) { auto rx = (x + 0.5f) * fill->radial.a11 + (y + 0.5f) * fill->radial.a12 + fill->radial.shiftX; auto ry = (x + 0.5f) * fill->radial.a21 + (y + 0.5f) * fill->radial.a22 + fill->radial.shiftY; @@ -252,16 +252,15 @@ void fillRasterRadial(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, } } else { for (uint32_t i = 0 ; i < len ; ++i, ++dst, cmp += csize) { - *dst = opAlphaBlend(_pixel(fill, sqrtf(det)), *dst, _multiply(opacity, alpha(cmp))); + *dst = opAlphaBlend(_pixel(fill, sqrtf(det)), *dst, MULTIPLY(opacity, alpha(cmp))); det += detFirstDerivative; detFirstDerivative += detSecondDerivative; } } - } -void fillRasterRadial(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, SwBlendOp op, uint8_t a) +void fillRadial(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, SwBlendOp op, uint8_t a) { auto rx = (x + 0.5f) * fill->radial.a11 + (y + 0.5f) * fill->radial.a12 + fill->radial.shiftX; auto ry = (x + 0.5f) * fill->radial.a21 + (y + 0.5f) * fill->radial.a22 + fill->radial.shiftY; @@ -288,7 +287,7 @@ void fillRasterRadial(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, } -void fillRasterLinear(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, uint8_t* cmp, SwAlpha alpha, uint8_t csize, uint8_t opacity) +void fillLinear(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, uint8_t* cmp, SwAlpha alpha, uint8_t csize, uint8_t opacity) { //Rotation float rx = x + 0.5f; @@ -331,7 +330,7 @@ void fillRasterLinear(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, if (mathZero(inc)) { auto color = _fixedPixel(fill, static_cast(t * FIXPT_SIZE)); for (uint32_t i = 0; i < len; ++i, ++dst, cmp += csize) { - *dst = opAlphaBlend(color, *dst, _multiply(alpha(cmp), opacity)); + *dst = opAlphaBlend(color, *dst, MULTIPLY(alpha(cmp), opacity)); } return; } @@ -345,14 +344,14 @@ void fillRasterLinear(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, auto t2 = static_cast(t * FIXPT_SIZE); auto inc2 = static_cast(inc * FIXPT_SIZE); for (uint32_t j = 0; j < len; ++j, ++dst, cmp += csize) { - *dst = opAlphaBlend(_fixedPixel(fill, t2), *dst, _multiply(alpha(cmp), opacity)); + *dst = opAlphaBlend(_fixedPixel(fill, t2), *dst, MULTIPLY(alpha(cmp), opacity)); t2 += inc2; } //we have to fallback to float math } else { uint32_t counter = 0; while (counter++ < len) { - *dst = opAlphaBlend(_pixel(fill, t / GRADIENT_STOP_SIZE), *dst, _multiply(opacity, alpha(cmp))); + *dst = opAlphaBlend(_pixel(fill, t / GRADIENT_STOP_SIZE), *dst, MULTIPLY(opacity, alpha(cmp))); ++dst; t += inc; cmp += csize; @@ -362,7 +361,7 @@ void fillRasterLinear(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, } -void fillRasterLinear(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, SwBlendOp op, uint8_t a) +void fillLinear(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x, uint32_t len, SwBlendOp op, uint8_t a) { //Rotation float rx = x + 0.5f; diff --git a/src/lib/sw_engine/tvgSwRaster.cpp b/src/lib/sw_engine/tvgSwRaster.cpp index c8ba4764..c87f2f15 100644 --- a/src/lib/sw_engine/tvgSwRaster.cpp +++ b/src/lib/sw_engine/tvgSwRaster.cpp @@ -38,13 +38,13 @@ constexpr auto DOWN_SCALE_TOLERANCE = 0.5f; -static inline uint8_t _alpha(uint8_t* a) +static inline uint8_t ALPHA(uint8_t* a) { return *a; } -static inline uint8_t _ialpha(uint8_t* a) +static inline uint8_t IALPHA(uint8_t* a) { return ~(*a); } @@ -278,7 +278,7 @@ static bool _rasterMaskedRle(SwSurface* surface, SwRleData* rle, uint8_t r, uint auto dst = &surface->buf8[span->y * surface->stride + span->x]; auto cmp = &cbuffer[(span->y * surface->compositor->image.stride + span->x) * csize]; if (span->coverage == 255) src = a; - else src = _multiply(a, span->coverage); + else src = MULTIPLY(a, span->coverage); for (uint32_t x = 0; x < span->len; ++x, ++dst, cmp += csize) { *dst = INTERPOLATE8(src, *dst, alpha(cmp)); } @@ -376,21 +376,21 @@ static bool _rasterScaledMaskedRleRGBAImage(SwSurface* surface, const SwImage* i 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 a = _multiply(span->coverage, opacity); + auto a = MULTIPLY(span->coverage, opacity); if (a == 255) { for (uint32_t x = static_cast(span->x); x < static_cast(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), alpha(cmp)); - *dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp)); + *dst = tmp + ALPHA_BLEND(*dst, IALPHA(tmp)); } } else { for (uint32_t x = static_cast(span->x); x < static_cast(span->x) + span->len; ++x, ++dst, cmp += csize) { auto sx = (uint32_t)(x * itransform->e11 + itransform->e13); if (sx >= image->w) continue; auto src = _interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale); - auto tmp = ALPHA_BLEND(src, _multiply(alpha(cmp), a)); - *dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp)); + auto tmp = ALPHA_BLEND(src, MULTIPLY(alpha(cmp), a)); + *dst = tmp + ALPHA_BLEND(*dst, IALPHA(tmp)); } } } @@ -401,21 +401,21 @@ static bool _rasterScaledMaskedRleRGBAImage(SwSurface* surface, const SwImage* i 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 a = _multiply(span->coverage, opacity); + auto a = MULTIPLY(span->coverage, opacity); if (a == 255) { for (uint32_t x = static_cast(span->x); x < static_cast(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), alpha(cmp)); - *dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp)); + *dst = tmp + ALPHA_BLEND(*dst, IALPHA(tmp)); } } else { for (uint32_t x = static_cast(span->x); x < static_cast(span->x) + span->len; ++x, ++dst, cmp += csize) { auto sx = x * itransform->e11 + itransform->e13; if ((uint32_t)sx >= image->w) continue; auto src = _interpUpScaler(image->buf32, image->w, image->h, sx, sy); - auto tmp = ALPHA_BLEND(src, _multiply(alpha(cmp), a)); - *dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp)); + auto tmp = ALPHA_BLEND(src, MULTIPLY(alpha(cmp), a)); + *dst = tmp + ALPHA_BLEND(*dst, IALPHA(tmp)); } } } @@ -434,20 +434,20 @@ static bool _rasterScaledRleRGBAImage(SwSurface* surface, const SwImage* image, auto sy = (uint32_t)(span->y * itransform->e22 + itransform->e23); if (sy >= image->h) continue; auto dst = &surface->buf32[span->y * surface->stride + span->x]; - auto alpha = _multiply(span->coverage, opacity); + auto alpha = MULTIPLY(span->coverage, opacity); if (alpha == 255) { for (uint32_t x = static_cast(span->x); x < static_cast(span->x) + span->len; ++x, ++dst) { auto sx = (uint32_t)(x * itransform->e11 + itransform->e13); if (sx >= image->w) continue; auto src = _interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale); - *dst = src + ALPHA_BLEND(*dst, _ialpha(src)); + *dst = src + ALPHA_BLEND(*dst, IALPHA(src)); } } else { for (uint32_t x = static_cast(span->x); x < static_cast(span->x) + span->len; ++x, ++dst) { 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); - *dst = src + ALPHA_BLEND(*dst, _ialpha(src)); + *dst = src + ALPHA_BLEND(*dst, IALPHA(src)); } } } @@ -457,20 +457,20 @@ static bool _rasterScaledRleRGBAImage(SwSurface* surface, const SwImage* image, auto sy = span->y * itransform->e22 + itransform->e23; if ((uint32_t)sy >= image->h) continue; auto dst = &surface->buf32[span->y * surface->stride + span->x]; - auto alpha = _multiply(span->coverage, opacity); + auto alpha = MULTIPLY(span->coverage, opacity); if (alpha == 255) { for (uint32_t x = static_cast(span->x); x < static_cast(span->x) + span->len; ++x, ++dst) { auto sx = x * itransform->e11 + itransform->e13; if ((uint32_t)sx >= image->w) continue; auto src = _interpUpScaler(image->buf32, image->w, image->h, sx, sy); - *dst = src + ALPHA_BLEND(*dst, _ialpha(src)); + *dst = src + ALPHA_BLEND(*dst, IALPHA(src)); } } else { for (uint32_t x = static_cast(span->x); x < static_cast(span->x) + span->len; ++x, ++dst) { 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); - *dst = src + ALPHA_BLEND(*dst, _ialpha(src)); + *dst = src + ALPHA_BLEND(*dst, IALPHA(src)); } } } @@ -515,16 +515,16 @@ static bool _rasterDirectMaskedRleRGBAImage(SwSurface* surface, const SwImage* i 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 a = _multiply(span->coverage, opacity); + auto a = MULTIPLY(span->coverage, opacity); if (a == 255) { for (uint32_t x = 0; x < span->len; ++x, ++dst, ++img, cmp += csize) { auto tmp = ALPHA_BLEND(*img, alpha(cmp)); - *dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp)); + *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(a, alpha(cmp))); - *dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp)); + auto tmp = ALPHA_BLEND(*img, MULTIPLY(a, alpha(cmp))); + *dst = tmp + ALPHA_BLEND(*dst, IALPHA(tmp)); } } } @@ -539,13 +539,13 @@ static bool _rasterDirectRleRGBAImage(SwSurface* surface, const SwImage* image, for (uint32_t i = 0; i < image->rle->size; ++i, ++span) { auto dst = &surface->buf32[span->y * surface->stride + span->x]; auto img = image->buf32 + (span->y + image->oy) * image->stride + (span->x + image->ox); - auto alpha = _multiply(span->coverage, opacity); + auto alpha = MULTIPLY(span->coverage, opacity); if (alpha == 255) { - *dst = *img + ALPHA_BLEND(*dst, _ialpha(*img)); + *dst = *img + ALPHA_BLEND(*dst, IALPHA(*img)); } else { for (uint32_t x = 0; x < span->len; ++x, ++dst, ++img) { auto src = ALPHA_BLEND(*img, alpha); - *dst = src + ALPHA_BLEND(*dst, _ialpha(src)); + *dst = src + ALPHA_BLEND(*dst, IALPHA(src)); } } } @@ -603,8 +603,8 @@ static bool _rasterScaledMaskedTranslucentRGBAImage(SwSurface* surface, const Sw auto sx = (uint32_t)(x * itransform->e11 + itransform->e13); if (sx >= image->w) continue; auto src = _interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale); - auto temp = ALPHA_BLEND(src, _multiply(opacity, alpha(cmp))); - *dst = temp + ALPHA_BLEND(*dst, _ialpha(temp)); + auto temp = ALPHA_BLEND(src, MULTIPLY(opacity, alpha(cmp))); + *dst = temp + ALPHA_BLEND(*dst, IALPHA(temp)); } dbuffer += surface->stride; cbuffer += surface->compositor->image.stride * csize; @@ -620,8 +620,8 @@ static bool _rasterScaledMaskedTranslucentRGBAImage(SwSurface* surface, const Sw auto sx = x * itransform->e11 + itransform->e13; if ((uint32_t)sx >= image->w) continue; auto src = _interpUpScaler(image->buf32, image->w, image->h, sx, sy); - auto temp = ALPHA_BLEND(src, _multiply(opacity, alpha(cmp))); - *dst = temp + ALPHA_BLEND(*dst, _ialpha(temp)); + auto temp = ALPHA_BLEND(src, MULTIPLY(opacity, alpha(cmp))); + *dst = temp + ALPHA_BLEND(*dst, IALPHA(temp)); } dbuffer += surface->stride; cbuffer += surface->compositor->image.stride * csize; @@ -652,7 +652,7 @@ static bool _rasterScaledMaskedRGBAImage(SwSurface* surface, const SwImage* imag if (sx >= image->w) continue; auto src = _interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale); auto temp = ALPHA_BLEND(src, alpha(cmp)); - *dst = temp + ALPHA_BLEND(*dst, _ialpha(temp)); + *dst = temp + ALPHA_BLEND(*dst, IALPHA(temp)); } dbuffer += surface->stride; cbuffer += surface->compositor->image.stride * csize; @@ -669,7 +669,7 @@ static bool _rasterScaledMaskedRGBAImage(SwSurface* surface, const SwImage* imag if ((uint32_t)sx >= image->w) continue; auto src = _interpUpScaler(image->buf32, image->w, image->h, sx, sy); auto temp = ALPHA_BLEND(src, alpha(cmp)); - *dst = temp + ALPHA_BLEND(*dst, _ialpha(temp)); + *dst = temp + ALPHA_BLEND(*dst, IALPHA(temp)); } dbuffer += surface->stride; cbuffer += surface->compositor->image.stride * csize; @@ -693,7 +693,7 @@ static bool _rasterScaledTranslucentRGBAImage(SwSurface* surface, const SwImage* 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), opacity); - *dst = src + ALPHA_BLEND(*dst, _ialpha(src)); + *dst = src + ALPHA_BLEND(*dst, IALPHA(src)); } } // Up-Scaled @@ -706,7 +706,7 @@ static bool _rasterScaledTranslucentRGBAImage(SwSurface* surface, const SwImage* 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), opacity); - *dst = src + ALPHA_BLEND(*dst, _ialpha(src)); + *dst = src + ALPHA_BLEND(*dst, IALPHA(src)); } } } @@ -728,7 +728,7 @@ static bool _rasterScaledRGBAImage(SwSurface* surface, const SwImage* image, con auto sx = (uint32_t)(x * itransform->e11 + itransform->e13); if (sx >= image->w) continue; auto src = _interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale); - *dst = src + ALPHA_BLEND(*dst, _ialpha(src)); + *dst = src + ALPHA_BLEND(*dst, IALPHA(src)); } } // Up-Scaled @@ -741,7 +741,7 @@ static bool _rasterScaledRGBAImage(SwSurface* surface, const SwImage* image, con auto sx = x * itransform->e11 + itransform->e13; if ((uint32_t)sx >= image->w) continue; auto src = _interpUpScaler(image->buf32, image->w, image->h, sx, sy); - *dst = src + ALPHA_BLEND(*dst, _ialpha(src)); + *dst = src + ALPHA_BLEND(*dst, IALPHA(src)); } } } @@ -793,7 +793,7 @@ static bool _rasterDirectMaskedRGBAImage(SwSurface* surface, const SwImage* imag auto src = sbuffer; for (uint32_t x = 0; x < w2; ++x, ++dst, ++src, cmp += csize) { auto tmp = ALPHA_BLEND(*src, alpha(cmp)); - *dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp)); + *dst = tmp + ALPHA_BLEND(*dst, IALPHA(tmp)); } buffer += surface->stride; cbuffer += surface->compositor->image.stride * csize; @@ -821,8 +821,8 @@ 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(opacity, alpha(cmp))); - *dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp)); + auto tmp = ALPHA_BLEND(*src, MULTIPLY(opacity, alpha(cmp))); + *dst = tmp + ALPHA_BLEND(*dst, IALPHA(tmp)); } buffer += surface->stride; cbuffer += surface->compositor->image.stride * csize; @@ -842,7 +842,7 @@ static bool _rasterDirectTranslucentRGBAImage(SwSurface* surface, const SwImage* auto src = sbuffer; for (auto x = region.min.x; x < region.max.x; ++x, ++dst, ++src) { auto tmp = ALPHA_BLEND(*src, opacity); - *dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp)); + *dst = tmp + ALPHA_BLEND(*dst, IALPHA(tmp)); } dbuffer += surface->stride; sbuffer += image->stride; @@ -860,7 +860,7 @@ static bool _rasterDirectRGBAImage(SwSurface* surface, const SwImage* image, con auto dst = dbuffer; auto src = sbuffer; for (auto x = region.min.x; x < region.max.x; x++, dst++, src++) { - *dst = *src + ALPHA_BLEND(*dst, _ialpha(*src)); + *dst = *src + ALPHA_BLEND(*dst, IALPHA(*src)); } dbuffer += surface->stride; sbuffer += image->stride; @@ -916,7 +916,7 @@ static bool _rasterLinearGradientMaskedRect(SwSurface* surface, const SwBBox& re auto alpha = surface->blender.alpha(surface->compositor->method); for (uint32_t y = 0; y < h; ++y) { - fillRasterLinear(fill, buffer, region.min.y + y, region.min.x, w, cbuffer, alpha, csize, 255); + fillLinear(fill, buffer, region.min.y + y, region.min.x, w, cbuffer, alpha, csize, 255); buffer += surface->stride; cbuffer += surface->stride * csize; } @@ -933,8 +933,7 @@ static bool _rasterTranslucentLinearGradientRect(SwSurface* surface, const SwBBo auto w = static_cast(region.max.x - region.min.x); for (uint32_t y = 0; y < h; ++y) { - auto dst = buffer; - fillRasterLinear(fill, dst, region.min.y + y, region.min.x, w, opBlend); + fillLinear(fill, buffer, region.min.y + y, region.min.x, w, opBlend); buffer += surface->stride; } return true; @@ -950,7 +949,7 @@ static bool _rasterSolidLinearGradientRect(SwSurface* surface, const SwBBox& reg auto h = static_cast(region.max.y - region.min.y); for (uint32_t y = 0; y < h; ++y) { - fillRasterLinear(fill, buffer + y * surface->stride, region.min.y + y, region.min.x, w); + fillLinear(fill, buffer + y * surface->stride, region.min.y + y, region.min.x, w); } return true; } @@ -961,7 +960,6 @@ static bool _rasterLinearGradientRect(SwSurface* surface, const SwBBox& region, if (_compositing(surface)) { return _rasterLinearGradientMaskedRect(surface, region, fill); } else { - //OPTIMIZE_ME: Unity branches. if (fill->translucent) return _rasterTranslucentLinearGradientRect(surface, region, fill); else _rasterSolidLinearGradientRect(surface, region, fill); } @@ -985,7 +983,7 @@ static bool _rasterLinearGradientMaskedRle(SwSurface* surface, const SwRleData* for (uint32_t i = 0; i < rle->size; ++i, ++span) { auto dst = &surface->buf32[span->y * surface->stride + span->x]; auto cmp = &cbuffer[(span->y * surface->compositor->image.stride + span->x) * csize]; - fillRasterLinear(fill, dst, span->y, span->x, span->len, cmp, alpha, csize, span->coverage); + fillLinear(fill, dst, span->y, span->x, span->len, cmp, alpha, csize, span->coverage); } return true; } @@ -999,8 +997,8 @@ static bool _rasterTranslucentLinearGradientRle(SwSurface* surface, const SwRleD for (uint32_t i = 0; i < rle->size; ++i, ++span) { auto dst = &surface->buf32[span->y * surface->stride + span->x]; - if (span->coverage == 255) fillRasterLinear(fill, dst, span->y, span->x, span->len, opBlend); - else fillRasterLinear(fill, dst, span->y, span->x, span->len, opAlphaBlend, span->coverage); + if (span->coverage == 255) fillLinear(fill, dst, span->y, span->x, span->len, opBlend); + else fillLinear(fill, dst, span->y, span->x, span->len, opAlphaBlend, span->coverage); } return true; } @@ -1014,8 +1012,8 @@ static bool _rasterSolidLinearGradientRle(SwSurface* surface, const SwRleData* r for (uint32_t i = 0; i < rle->size; ++i, ++span) { auto dst = &surface->buf32[span->y * surface->stride + span->x]; - if (span->coverage == 255) fillRasterLinear(fill, dst, span->y, span->x, span->len); - else fillRasterLinear(fill, dst, span->y, span->x, span->len, opInterpolate, span->coverage); + if (span->coverage == 255) fillLinear(fill, dst, span->y, span->x, span->len); + else fillLinear(fill, dst, span->y, span->x, span->len, opInterpolate, span->coverage); } return true; } @@ -1028,7 +1026,6 @@ static bool _rasterLinearGradientRle(SwSurface* surface, const SwRleData* rle, c if (_compositing(surface)) { return _rasterLinearGradientMaskedRle(surface, rle, fill); } else { - //OPTIMIZE_ME: Unify branches if (fill->translucent) return _rasterTranslucentLinearGradientRle(surface, rle, fill); else return _rasterSolidLinearGradientRle(surface, rle, fill); } @@ -1052,7 +1049,7 @@ static bool _rasterRadialGradientMaskedRect(SwSurface* surface, const SwBBox& re auto alpha = surface->blender.alpha(surface->compositor->method); for (uint32_t y = 0; y < h; ++y) { - fillRasterRadial(fill, buffer, region.min.y + y, region.min.x, w, cbuffer, alpha, csize, 255); + fillRadial(fill, buffer, region.min.y + y, region.min.x, w, cbuffer, alpha, csize, 255); buffer += surface->stride; cbuffer += surface->stride * csize; } @@ -1070,7 +1067,7 @@ static bool _rasterTranslucentRadialGradientRect(SwSurface* surface, const SwBBo for (uint32_t y = 0; y < h; ++y) { auto dst = buffer; - fillRasterRadial(fill, dst, region.min.y + y, region.min.x, w, opBlend); + fillRadial(fill, dst, region.min.y + y, region.min.x, w, opBlend); buffer += surface->stride; } return true; @@ -1086,7 +1083,7 @@ static bool _rasterSolidRadialGradientRect(SwSurface* surface, const SwBBox& reg auto w = static_cast(region.max.x - region.min.x); for (uint32_t y = 0; y < h; ++y) { - fillRasterRadial(fill, &buffer[y * surface->stride], region.min.y + y, region.min.x, w); + fillRadial(fill, &buffer[y * surface->stride], region.min.y + y, region.min.x, w); } return true; } @@ -1097,7 +1094,6 @@ static bool _rasterRadialGradientRect(SwSurface* surface, const SwBBox& region, if (_compositing(surface)) { return _rasterRadialGradientMaskedRect(surface, region, fill); } else { - //OPTIMIZE_ME: Unity branches. if (fill->translucent) return _rasterTranslucentRadialGradientRect(surface, region, fill); else return _rasterSolidRadialGradientRect(surface, region, fill); } @@ -1121,7 +1117,7 @@ static bool _rasterRadialGradientMaskedRle(SwSurface* surface, const SwRleData* for (uint32_t i = 0; i < rle->size; ++i, ++span) { auto dst = &surface->buf32[span->y * surface->stride + span->x]; auto cmp = &cbuffer[(span->y * surface->compositor->image.stride + span->x) * csize]; - fillRasterRadial(fill, dst, span->y, span->x, span->len, cmp, alpha, csize, span->coverage); + fillRadial(fill, dst, span->y, span->x, span->len, cmp, alpha, csize, span->coverage); } return true; } @@ -1135,8 +1131,8 @@ static bool _rasterTranslucentRadialGradientRle(SwSurface* surface, const SwRleD for (uint32_t i = 0; i < rle->size; ++i, ++span) { auto dst = &surface->buf32[span->y * surface->stride + span->x]; - if (span->coverage == 255) fillRasterRadial(fill, dst, span->y, span->x, span->len, opBlend); - else fillRasterRadial(fill, dst, span->y, span->x, span->len, opAlphaBlend, span->coverage); + if (span->coverage == 255) fillRadial(fill, dst, span->y, span->x, span->len, opBlend); + else fillRadial(fill, dst, span->y, span->x, span->len, opAlphaBlend, span->coverage); } return true; } @@ -1150,8 +1146,8 @@ static bool _rasterSolidRadialGradientRle(SwSurface* surface, const SwRleData* r for (uint32_t i = 0; i < rle->size; ++i, ++span) { auto dst = &surface->buf32[span->y * surface->stride + span->x]; - if (span->coverage == 255) fillRasterRadial(fill, dst, span->y, span->x, span->len); - else fillRasterRadial(fill, dst, span->y, span->x, span->len, opInterpolate, span->coverage); + if (span->coverage == 255) fillRadial(fill, dst, span->y, span->x, span->len); + else fillRadial(fill, dst, span->y, span->x, span->len, opInterpolate, span->coverage); } return true; } @@ -1164,7 +1160,6 @@ static bool _rasterRadialGradientRle(SwSurface* surface, const SwRleData* rle, c if (_compositing(surface)) { return _rasterRadialGradientMaskedRle(surface, rle, fill); } else { - //OPTIMIZE_ME: Unity branches. if (fill->translucent) _rasterTranslucentRadialGradientRle(surface, rle, fill); else return _rasterSolidRadialGradientRle(surface, rle, fill); } @@ -1190,8 +1185,8 @@ void rasterRGBA32(uint32_t *dst, uint32_t val, uint32_t offset, int32_t len) bool rasterCompositor(SwSurface* surface) { //See CompositeMethod, Alpha:3, InvAlpha:4, Luma:5, InvLuma:6 - surface->blender.alphas[0] = _alpha; - surface->blender.alphas[1] = _ialpha; + surface->blender.alphas[0] = ALPHA; + surface->blender.alphas[1] = IALPHA; if (surface->cs == ColorSpace::ABGR8888 || surface->cs == ColorSpace::ABGR8888S) { surface->blender.join = _abgrJoin; @@ -1327,9 +1322,9 @@ bool rasterGradientStroke(SwSurface* surface, SwShape* shape, unsigned id) bool rasterShape(SwSurface* surface, SwShape* shape, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { if (a < 255) { - r = _multiply(r, a); - g = _multiply(g, a); - b = _multiply(b, a); + r = MULTIPLY(r, a); + g = MULTIPLY(g, a); + b = MULTIPLY(b, a); } if (shape->fastTrack) return _rasterRect(surface, shape->bbox, r, g, b, a); @@ -1340,9 +1335,9 @@ bool rasterShape(SwSurface* surface, SwShape* shape, uint8_t r, uint8_t g, uint8 bool rasterStroke(SwSurface* surface, SwShape* shape, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { if (a < 255) { - r = _multiply(r, a); - g = _multiply(g, a); - b = _multiply(b, a); + r = MULTIPLY(r, a); + g = MULTIPLY(g, a); + b = MULTIPLY(b, a); } return _rasterRle(surface, shape->strokeRle, r, g, b, a); diff --git a/src/lib/sw_engine/tvgSwRasterAvx.h b/src/lib/sw_engine/tvgSwRasterAvx.h index 59a83ab0..a7376805 100644 --- a/src/lib/sw_engine/tvgSwRasterAvx.h +++ b/src/lib/sw_engine/tvgSwRasterAvx.h @@ -148,7 +148,7 @@ static bool avxRasterTranslucentRle(SwSurface* surface, const SwRleData* rle, ui if (span->coverage < 255) src = ALPHA_BLEND(color, span->coverage); else src = color; - auto ialpha = _ialpha(src); + auto ialpha = IALPHA(src); //1. fill the not aligned memory (for 128-bit registers a 16-bytes alignment is required) auto notAligned = ((uintptr_t)dst & 0xf) / 4; diff --git a/src/lib/sw_engine/tvgSwRasterC.h b/src/lib/sw_engine/tvgSwRasterC.h index 592d2ab7..a040269f 100644 --- a/src/lib/sw_engine/tvgSwRasterC.h +++ b/src/lib/sw_engine/tvgSwRasterC.h @@ -40,8 +40,9 @@ static bool inline cRasterTranslucentRle(SwSurface* surface, const SwRleData* rl auto dst = &surface->buf32[span->y * surface->stride + span->x]; if (span->coverage < 255) src = ALPHA_BLEND(color, span->coverage); else src = color; + auto ialpha = IALPHA(src); for (uint32_t x = 0; x < span->len; ++x, ++dst) { - *dst = src + ALPHA_BLEND(*dst, _ialpha(src)); + *dst = src + ALPHA_BLEND(*dst, ialpha); } } //8bit grayscale @@ -49,10 +50,11 @@ static bool inline cRasterTranslucentRle(SwSurface* surface, const SwRleData* rl uint8_t src; for (uint32_t i = 0; i < rle->size; ++i, ++span) { auto dst = &surface->buf8[span->y * surface->stride + span->x]; - if (span->coverage < 255) src = _multiply(span->coverage, a); + if (span->coverage < 255) src = MULTIPLY(span->coverage, a); else src = a; + auto ialpha = ~a; for (uint32_t x = 0; x < span->len; ++x, ++dst) { - *dst = src + _multiply(*dst, ~src); + *dst = src + MULTIPLY(*dst, ialpha); } } } @@ -69,7 +71,7 @@ static bool inline cRasterTranslucentRect(SwSurface* surface, const SwBBox& regi if (surface->channelSize == sizeof(uint32_t)) { auto color = surface->blender.join(r, g, b, a); auto buffer = surface->buf32 + (region.min.y * surface->stride) + region.min.x; - auto ialpha = _ialpha(color); + auto ialpha = IALPHA(color); for (uint32_t y = 0; y < h; ++y) { auto dst = &buffer[y * surface->stride]; for (uint32_t x = 0; x < w; ++x, ++dst) { @@ -79,10 +81,11 @@ static bool inline cRasterTranslucentRect(SwSurface* surface, const SwBBox& regi //8bit grayscale } else if (surface->channelSize == sizeof(uint8_t)) { auto buffer = surface->buf8 + (region.min.y * surface->stride) + region.min.x; + auto ialpha = ~a; for (uint32_t y = 0; y < h; ++y) { auto dst = &buffer[y * surface->stride]; for (uint32_t x = 0; x < w; ++x, ++dst) { - *dst = a + _multiply(*dst, ~a); + *dst = a + MULTIPLY(*dst, ialpha); } } } diff --git a/src/lib/sw_engine/tvgSwRasterNeon.h b/src/lib/sw_engine/tvgSwRasterNeon.h index 33c3d181..e3e68437 100644 --- a/src/lib/sw_engine/tvgSwRasterNeon.h +++ b/src/lib/sw_engine/tvgSwRasterNeon.h @@ -67,7 +67,7 @@ static bool neonRasterTranslucentRle(SwSurface* surface, const SwRleData* rle, u else src = color; auto dst = &surface->buf32[span->y * surface->stride + span->x]; - auto ialpha = 255 - _alpha(src); + auto ialpha = IALPHA(src); if ((((uint32_t) dst) & 0x7) != 0) { //fill not aligned byte @@ -105,7 +105,7 @@ static bool neonRasterTranslucentRect(SwSurface* surface, const SwBBox& region, auto buffer = surface->buf32 + (region.min.y * surface->stride) + region.min.x; auto h = static_cast(region.max.y - region.min.y); auto w = static_cast(region.max.x - region.min.x); - auto ialpha = 255 - _alpha(color); + auto ialpha = IALPHA(color); auto vColor = vdup_n_u32(color); auto vIalpha = vdup_n_u8((uint8_t) ialpha); diff --git a/src/lib/sw_engine/tvgSwRasterTexmapInternal.h b/src/lib/sw_engine/tvgSwRasterTexmapInternal.h index a74f2751..750f7520 100644 --- a/src/lib/sw_engine/tvgSwRasterTexmapInternal.h +++ b/src/lib/sw_engine/tvgSwRasterTexmapInternal.h @@ -133,7 +133,7 @@ } #if defined(TEXMAP_MASKING) && defined(TEXMAP_TRANSLUCENT) - auto src = ALPHA_BLEND(px, _multiply(opacity, alpha(cmp))); + auto src = ALPHA_BLEND(px, MULTIPLY(opacity, alpha(cmp))); cmp += csize; #elif defined(TEXMAP_MASKING) auto src = ALPHA_BLEND(px, alpha(cmp)); @@ -143,7 +143,7 @@ #else auto src = px; #endif - *buf = src + ALPHA_BLEND(*buf, _ialpha(src)); + *buf = src + ALPHA_BLEND(*buf, IALPHA(src)); ++buf; //Step UV horizontally