sw_engine: minor code clean up

keep code consistency, no logical changes.
This commit is contained in:
Hermet Park 2023-05-29 18:26:09 +09:00
parent eb8539e0b4
commit 86d287038b
7 changed files with 96 additions and 97 deletions

View file

@ -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 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 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 struct SwBlender
{ {
@ -303,30 +302,33 @@ static inline SwCoord HALF_STROKE(float width)
return TO_SWCOORD(width * 0.5f); 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); return ((c * a + 0xff) >> 8);
} }
static inline uint8_t _alpha(uint32_t c) static inline uint8_t ALPHA(uint32_t c)
{ {
return (c >> 24); return (c >> 24);
} }
static inline uint8_t _ialpha(uint32_t c) static inline uint8_t IALPHA(uint32_t c)
{ {
return (~c >> 24); 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) static inline uint32_t opAlphaBlend(uint32_t s, uint32_t d, uint8_t a)
{ {
auto t = ALPHA_BLEND(s, 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) 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) 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); bool fillGenColorTable(SwFill* fill, const Fill* fdata, const Matrix* transform, SwSurface* surface, uint32_t opacity, bool ctable);
void fillReset(SwFill* fill); void fillReset(SwFill* fill);
void fillFree(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 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 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 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 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 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 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 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(SwRleData* rle, const SwOutline* outline, const SwBBox& renderRegion, bool antiAlias);
SwRleData* rleRender(const SwBBox* bbox); SwRleData* rleRender(const SwBBox* bbox);

View file

@ -233,7 +233,7 @@ static inline uint32_t _pixel(const SwFill* fill, float pos)
/* External Class Implementation */ /* 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 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; 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 { } else {
for (uint32_t i = 0 ; i < len ; ++i, ++dst, cmp += csize) { 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; det += detFirstDerivative;
detFirstDerivative += detSecondDerivative; 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 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; 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 //Rotation
float rx = x + 0.5f; 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)) { if (mathZero(inc)) {
auto color = _fixedPixel(fill, static_cast<int32_t>(t * FIXPT_SIZE)); auto color = _fixedPixel(fill, static_cast<int32_t>(t * FIXPT_SIZE));
for (uint32_t i = 0; i < len; ++i, ++dst, cmp += csize) { 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; return;
} }
@ -345,14 +344,14 @@ void fillRasterLinear(const SwFill* fill, uint32_t* dst, uint32_t y, uint32_t x,
auto t2 = static_cast<int32_t>(t * FIXPT_SIZE); auto t2 = static_cast<int32_t>(t * FIXPT_SIZE);
auto inc2 = static_cast<int32_t>(inc * FIXPT_SIZE); auto inc2 = static_cast<int32_t>(inc * FIXPT_SIZE);
for (uint32_t j = 0; j < len; ++j, ++dst, cmp += csize) { 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; t2 += inc2;
} }
//we have to fallback to float math //we have to fallback to float math
} else { } else {
uint32_t counter = 0; uint32_t counter = 0;
while (counter++ < len) { 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; ++dst;
t += inc; t += inc;
cmp += csize; 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 //Rotation
float rx = x + 0.5f; float rx = x + 0.5f;

View file

@ -38,13 +38,13 @@
constexpr auto DOWN_SCALE_TOLERANCE = 0.5f; 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; return *a;
} }
static inline uint8_t _ialpha(uint8_t* a) static inline uint8_t IALPHA(uint8_t* a)
{ {
return ~(*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 dst = &surface->buf8[span->y * surface->stride + span->x];
auto cmp = &cbuffer[(span->y * surface->compositor->image.stride + span->x) * csize]; auto cmp = &cbuffer[(span->y * surface->compositor->image.stride + span->x) * csize];
if (span->coverage == 255) src = a; 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) { for (uint32_t x = 0; x < span->len; ++x, ++dst, cmp += csize) {
*dst = INTERPOLATE8(src, *dst, alpha(cmp)); *dst = INTERPOLATE8(src, *dst, alpha(cmp));
} }
@ -376,21 +376,21 @@ static bool _rasterScaledMaskedRleRGBAImage(SwSurface* surface, const SwImage* i
if (sy >= image->h) continue; if (sy >= image->h) continue;
auto dst = &surface->buf32[span->y * surface->stride + span->x]; 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 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) { if (a == 255) {
for (uint32_t x = static_cast<uint32_t>(span->x); x < static_cast<uint32_t>(span->x) + span->len; ++x, ++dst, cmp += csize) { 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); auto sx = (uint32_t)(x * itransform->e11 + itransform->e13);
if (sx >= image->w) continue; if (sx >= image->w) continue;
auto tmp = ALPHA_BLEND(_interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale), alpha(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)); *dst = tmp + ALPHA_BLEND(*dst, IALPHA(tmp));
} }
} else { } else {
for (uint32_t x = static_cast<uint32_t>(span->x); x < static_cast<uint32_t>(span->x) + span->len; ++x, ++dst, cmp += csize) { 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); auto sx = (uint32_t)(x * itransform->e11 + itransform->e13);
if (sx >= image->w) continue; if (sx >= image->w) continue;
auto src = _interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale); auto src = _interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale);
auto tmp = ALPHA_BLEND(src, _multiply(alpha(cmp), a)); auto tmp = ALPHA_BLEND(src, MULTIPLY(alpha(cmp), a));
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp)); *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; if ((uint32_t)sy >= image->h) continue;
auto dst = &surface->buf32[span->y * surface->stride + span->x]; 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 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) { if (a == 255) {
for (uint32_t x = static_cast<uint32_t>(span->x); x < static_cast<uint32_t>(span->x) + span->len; ++x, ++dst, cmp += csize) { 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; auto sx = x * itransform->e11 + itransform->e13;
if ((uint32_t)sx >= image->w) continue; if ((uint32_t)sx >= image->w) continue;
auto tmp = ALPHA_BLEND(_interpUpScaler(image->buf32, image->w, image->h, sx, sy), alpha(cmp)); 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 { } else {
for (uint32_t x = static_cast<uint32_t>(span->x); x < static_cast<uint32_t>(span->x) + span->len; ++x, ++dst, cmp += csize) { 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; auto sx = x * itransform->e11 + itransform->e13;
if ((uint32_t)sx >= image->w) continue; if ((uint32_t)sx >= image->w) continue;
auto src = _interpUpScaler(image->buf32, image->w, image->h, sx, sy); auto src = _interpUpScaler(image->buf32, image->w, image->h, sx, sy);
auto tmp = ALPHA_BLEND(src, _multiply(alpha(cmp), a)); auto tmp = ALPHA_BLEND(src, MULTIPLY(alpha(cmp), a));
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp)); *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); auto sy = (uint32_t)(span->y * itransform->e22 + itransform->e23);
if (sy >= image->h) continue; if (sy >= image->h) continue;
auto dst = &surface->buf32[span->y * surface->stride + span->x]; 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) { if (alpha == 255) {
for (uint32_t x = static_cast<uint32_t>(span->x); x < static_cast<uint32_t>(span->x) + span->len; ++x, ++dst) { for (uint32_t x = static_cast<uint32_t>(span->x); x < static_cast<uint32_t>(span->x) + span->len; ++x, ++dst) {
auto sx = (uint32_t)(x * itransform->e11 + itransform->e13); auto sx = (uint32_t)(x * itransform->e11 + itransform->e13);
if (sx >= image->w) continue; if (sx >= image->w) continue;
auto src = _interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale); 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 { } else {
for (uint32_t x = static_cast<uint32_t>(span->x); x < static_cast<uint32_t>(span->x) + span->len; ++x, ++dst) { for (uint32_t x = static_cast<uint32_t>(span->x); x < static_cast<uint32_t>(span->x) + span->len; ++x, ++dst) {
auto sx = (uint32_t)(x * itransform->e11 + itransform->e13); auto sx = (uint32_t)(x * itransform->e11 + itransform->e13);
if (sx >= image->w) continue; if (sx >= image->w) continue;
auto src = ALPHA_BLEND(_interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale), alpha); 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; auto sy = span->y * itransform->e22 + itransform->e23;
if ((uint32_t)sy >= image->h) continue; if ((uint32_t)sy >= image->h) continue;
auto dst = &surface->buf32[span->y * surface->stride + span->x]; 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) { if (alpha == 255) {
for (uint32_t x = static_cast<uint32_t>(span->x); x < static_cast<uint32_t>(span->x) + span->len; ++x, ++dst) { for (uint32_t x = static_cast<uint32_t>(span->x); x < static_cast<uint32_t>(span->x) + span->len; ++x, ++dst) {
auto sx = x * itransform->e11 + itransform->e13; auto sx = x * itransform->e11 + itransform->e13;
if ((uint32_t)sx >= image->w) continue; if ((uint32_t)sx >= image->w) continue;
auto src = _interpUpScaler(image->buf32, image->w, image->h, sx, sy); 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 { } else {
for (uint32_t x = static_cast<uint32_t>(span->x); x < static_cast<uint32_t>(span->x) + span->len; ++x, ++dst) { for (uint32_t x = static_cast<uint32_t>(span->x); x < static_cast<uint32_t>(span->x) + span->len; ++x, ++dst) {
auto sx = x * itransform->e11 + itransform->e13; auto sx = x * itransform->e11 + itransform->e13;
if ((uint32_t)sx >= image->w) continue; if ((uint32_t)sx >= image->w) continue;
auto src = ALPHA_BLEND(_interpUpScaler(image->buf32, image->w, image->h, sx, sy), alpha); 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 dst = &surface->buf32[span->y * surface->stride + span->x];
auto cmp = &cbuffer[(span->y * surface->compositor->image.stride + span->x) * csize]; 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 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) { if (a == 255) {
for (uint32_t x = 0; x < span->len; ++x, ++dst, ++img, cmp += csize) { for (uint32_t x = 0; x < span->len; ++x, ++dst, ++img, cmp += csize) {
auto tmp = ALPHA_BLEND(*img, alpha(cmp)); auto tmp = ALPHA_BLEND(*img, alpha(cmp));
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp)); *dst = tmp + ALPHA_BLEND(*dst, IALPHA(tmp));
} }
} else { } else {
for (uint32_t x = 0; x < span->len; ++x, ++dst, ++img, cmp += csize) { for (uint32_t x = 0; x < span->len; ++x, ++dst, ++img, cmp += csize) {
auto tmp = ALPHA_BLEND(*img, _multiply(a, alpha(cmp))); auto tmp = ALPHA_BLEND(*img, MULTIPLY(a, alpha(cmp)));
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp)); *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) { for (uint32_t i = 0; i < image->rle->size; ++i, ++span) {
auto dst = &surface->buf32[span->y * surface->stride + span->x]; 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 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) { if (alpha == 255) {
*dst = *img + ALPHA_BLEND(*dst, _ialpha(*img)); *dst = *img + ALPHA_BLEND(*dst, IALPHA(*img));
} else { } else {
for (uint32_t x = 0; x < span->len; ++x, ++dst, ++img) { for (uint32_t x = 0; x < span->len; ++x, ++dst, ++img) {
auto src = ALPHA_BLEND(*img, alpha); 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); auto sx = (uint32_t)(x * itransform->e11 + itransform->e13);
if (sx >= image->w) continue; if (sx >= image->w) continue;
auto src = _interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale); auto src = _interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale);
auto temp = ALPHA_BLEND(src, _multiply(opacity, alpha(cmp))); auto temp = ALPHA_BLEND(src, MULTIPLY(opacity, alpha(cmp)));
*dst = temp + ALPHA_BLEND(*dst, _ialpha(temp)); *dst = temp + ALPHA_BLEND(*dst, IALPHA(temp));
} }
dbuffer += surface->stride; dbuffer += surface->stride;
cbuffer += surface->compositor->image.stride * csize; cbuffer += surface->compositor->image.stride * csize;
@ -620,8 +620,8 @@ static bool _rasterScaledMaskedTranslucentRGBAImage(SwSurface* surface, const Sw
auto sx = x * itransform->e11 + itransform->e13; auto sx = x * itransform->e11 + itransform->e13;
if ((uint32_t)sx >= image->w) continue; if ((uint32_t)sx >= image->w) continue;
auto src = _interpUpScaler(image->buf32, image->w, image->h, sx, sy); auto src = _interpUpScaler(image->buf32, image->w, image->h, sx, sy);
auto temp = ALPHA_BLEND(src, _multiply(opacity, alpha(cmp))); auto temp = ALPHA_BLEND(src, MULTIPLY(opacity, alpha(cmp)));
*dst = temp + ALPHA_BLEND(*dst, _ialpha(temp)); *dst = temp + ALPHA_BLEND(*dst, IALPHA(temp));
} }
dbuffer += surface->stride; dbuffer += surface->stride;
cbuffer += surface->compositor->image.stride * csize; cbuffer += surface->compositor->image.stride * csize;
@ -652,7 +652,7 @@ static bool _rasterScaledMaskedRGBAImage(SwSurface* surface, const SwImage* imag
if (sx >= image->w) continue; if (sx >= image->w) continue;
auto src = _interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale); auto src = _interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale);
auto temp = ALPHA_BLEND(src, alpha(cmp)); auto temp = ALPHA_BLEND(src, alpha(cmp));
*dst = temp + ALPHA_BLEND(*dst, _ialpha(temp)); *dst = temp + ALPHA_BLEND(*dst, IALPHA(temp));
} }
dbuffer += surface->stride; dbuffer += surface->stride;
cbuffer += surface->compositor->image.stride * csize; 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; if ((uint32_t)sx >= image->w) continue;
auto src = _interpUpScaler(image->buf32, image->w, image->h, sx, sy); auto src = _interpUpScaler(image->buf32, image->w, image->h, sx, sy);
auto temp = ALPHA_BLEND(src, alpha(cmp)); auto temp = ALPHA_BLEND(src, alpha(cmp));
*dst = temp + ALPHA_BLEND(*dst, _ialpha(temp)); *dst = temp + ALPHA_BLEND(*dst, IALPHA(temp));
} }
dbuffer += surface->stride; dbuffer += surface->stride;
cbuffer += surface->compositor->image.stride * csize; 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); auto sx = (uint32_t)(x * itransform->e11 + itransform->e13);
if (sx >= image->w) continue; if (sx >= image->w) continue;
auto src = ALPHA_BLEND(_interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale), opacity); 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 // Up-Scaled
@ -706,7 +706,7 @@ static bool _rasterScaledTranslucentRGBAImage(SwSurface* surface, const SwImage*
auto sx = x * itransform->e11 + itransform->e13; auto sx = x * itransform->e11 + itransform->e13;
if ((uint32_t)sx >= image->w) continue; if ((uint32_t)sx >= image->w) continue;
auto src = ALPHA_BLEND(_interpUpScaler(image->buf32, image->w, image->h, sx, sy), opacity); 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); auto sx = (uint32_t)(x * itransform->e11 + itransform->e13);
if (sx >= image->w) continue; if (sx >= image->w) continue;
auto src = _interpDownScaler(image->buf32, image->stride, image->w, image->h, sx, sy, halfScale); 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 // Up-Scaled
@ -741,7 +741,7 @@ static bool _rasterScaledRGBAImage(SwSurface* surface, const SwImage* image, con
auto sx = x * itransform->e11 + itransform->e13; auto sx = x * itransform->e11 + itransform->e13;
if ((uint32_t)sx >= image->w) continue; if ((uint32_t)sx >= image->w) continue;
auto src = _interpUpScaler(image->buf32, image->w, image->h, sx, sy); 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; auto src = sbuffer;
for (uint32_t x = 0; x < w2; ++x, ++dst, ++src, cmp += csize) { for (uint32_t x = 0; x < w2; ++x, ++dst, ++src, cmp += csize) {
auto tmp = ALPHA_BLEND(*src, alpha(cmp)); auto tmp = ALPHA_BLEND(*src, alpha(cmp));
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp)); *dst = tmp + ALPHA_BLEND(*dst, IALPHA(tmp));
} }
buffer += surface->stride; buffer += surface->stride;
cbuffer += surface->compositor->image.stride * csize; cbuffer += surface->compositor->image.stride * csize;
@ -821,8 +821,8 @@ static bool _rasterDirectMaskedTranslucentRGBAImage(SwSurface* surface, const Sw
auto cmp = cbuffer; auto cmp = cbuffer;
auto src = sbuffer; auto src = sbuffer;
for (uint32_t x = 0; x < w2; ++x, ++dst, ++src, cmp += csize) { for (uint32_t x = 0; x < w2; ++x, ++dst, ++src, cmp += csize) {
auto tmp = ALPHA_BLEND(*src, _multiply(opacity, alpha(cmp))); auto tmp = ALPHA_BLEND(*src, MULTIPLY(opacity, alpha(cmp)));
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp)); *dst = tmp + ALPHA_BLEND(*dst, IALPHA(tmp));
} }
buffer += surface->stride; buffer += surface->stride;
cbuffer += surface->compositor->image.stride * csize; cbuffer += surface->compositor->image.stride * csize;
@ -842,7 +842,7 @@ static bool _rasterDirectTranslucentRGBAImage(SwSurface* surface, const SwImage*
auto src = sbuffer; auto src = sbuffer;
for (auto x = region.min.x; x < region.max.x; ++x, ++dst, ++src) { for (auto x = region.min.x; x < region.max.x; ++x, ++dst, ++src) {
auto tmp = ALPHA_BLEND(*src, opacity); auto tmp = ALPHA_BLEND(*src, opacity);
*dst = tmp + ALPHA_BLEND(*dst, _ialpha(tmp)); *dst = tmp + ALPHA_BLEND(*dst, IALPHA(tmp));
} }
dbuffer += surface->stride; dbuffer += surface->stride;
sbuffer += image->stride; sbuffer += image->stride;
@ -860,7 +860,7 @@ static bool _rasterDirectRGBAImage(SwSurface* surface, const SwImage* image, con
auto dst = dbuffer; auto dst = dbuffer;
auto src = sbuffer; auto src = sbuffer;
for (auto x = region.min.x; x < region.max.x; x++, dst++, src++) { 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; dbuffer += surface->stride;
sbuffer += image->stride; sbuffer += image->stride;
@ -916,7 +916,7 @@ static bool _rasterLinearGradientMaskedRect(SwSurface* surface, const SwBBox& re
auto alpha = surface->blender.alpha(surface->compositor->method); auto alpha = surface->blender.alpha(surface->compositor->method);
for (uint32_t y = 0; y < h; ++y) { 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; buffer += surface->stride;
cbuffer += surface->stride * csize; cbuffer += surface->stride * csize;
} }
@ -933,8 +933,7 @@ static bool _rasterTranslucentLinearGradientRect(SwSurface* surface, const SwBBo
auto w = static_cast<uint32_t>(region.max.x - region.min.x); auto w = static_cast<uint32_t>(region.max.x - region.min.x);
for (uint32_t y = 0; y < h; ++y) { for (uint32_t y = 0; y < h; ++y) {
auto dst = buffer; fillLinear(fill, buffer, region.min.y + y, region.min.x, w, opBlend);
fillRasterLinear(fill, dst, region.min.y + y, region.min.x, w, opBlend);
buffer += surface->stride; buffer += surface->stride;
} }
return true; return true;
@ -950,7 +949,7 @@ static bool _rasterSolidLinearGradientRect(SwSurface* surface, const SwBBox& reg
auto h = static_cast<uint32_t>(region.max.y - region.min.y); auto h = static_cast<uint32_t>(region.max.y - region.min.y);
for (uint32_t y = 0; y < h; ++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; return true;
} }
@ -961,7 +960,6 @@ static bool _rasterLinearGradientRect(SwSurface* surface, const SwBBox& region,
if (_compositing(surface)) { if (_compositing(surface)) {
return _rasterLinearGradientMaskedRect(surface, region, fill); return _rasterLinearGradientMaskedRect(surface, region, fill);
} else { } else {
//OPTIMIZE_ME: Unity branches.
if (fill->translucent) return _rasterTranslucentLinearGradientRect(surface, region, fill); if (fill->translucent) return _rasterTranslucentLinearGradientRect(surface, region, fill);
else _rasterSolidLinearGradientRect(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) { for (uint32_t i = 0; i < rle->size; ++i, ++span) {
auto dst = &surface->buf32[span->y * surface->stride + span->x]; auto dst = &surface->buf32[span->y * surface->stride + span->x];
auto cmp = &cbuffer[(span->y * surface->compositor->image.stride + span->x) * csize]; 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; return true;
} }
@ -999,8 +997,8 @@ static bool _rasterTranslucentLinearGradientRle(SwSurface* surface, const SwRleD
for (uint32_t i = 0; i < rle->size; ++i, ++span) { for (uint32_t i = 0; i < rle->size; ++i, ++span) {
auto dst = &surface->buf32[span->y * surface->stride + span->x]; auto dst = &surface->buf32[span->y * surface->stride + span->x];
if (span->coverage == 255) fillRasterLinear(fill, dst, span->y, span->x, span->len, opBlend); if (span->coverage == 255) fillLinear(fill, dst, span->y, span->x, span->len, opBlend);
else fillRasterLinear(fill, dst, span->y, span->x, span->len, opAlphaBlend, span->coverage); else fillLinear(fill, dst, span->y, span->x, span->len, opAlphaBlend, span->coverage);
} }
return true; return true;
} }
@ -1014,8 +1012,8 @@ static bool _rasterSolidLinearGradientRle(SwSurface* surface, const SwRleData* r
for (uint32_t i = 0; i < rle->size; ++i, ++span) { for (uint32_t i = 0; i < rle->size; ++i, ++span) {
auto dst = &surface->buf32[span->y * surface->stride + span->x]; auto dst = &surface->buf32[span->y * surface->stride + span->x];
if (span->coverage == 255) fillRasterLinear(fill, dst, span->y, span->x, span->len); if (span->coverage == 255) fillLinear(fill, dst, span->y, span->x, span->len);
else fillRasterLinear(fill, dst, span->y, span->x, span->len, opInterpolate, span->coverage); else fillLinear(fill, dst, span->y, span->x, span->len, opInterpolate, span->coverage);
} }
return true; return true;
} }
@ -1028,7 +1026,6 @@ static bool _rasterLinearGradientRle(SwSurface* surface, const SwRleData* rle, c
if (_compositing(surface)) { if (_compositing(surface)) {
return _rasterLinearGradientMaskedRle(surface, rle, fill); return _rasterLinearGradientMaskedRle(surface, rle, fill);
} else { } else {
//OPTIMIZE_ME: Unify branches
if (fill->translucent) return _rasterTranslucentLinearGradientRle(surface, rle, fill); if (fill->translucent) return _rasterTranslucentLinearGradientRle(surface, rle, fill);
else return _rasterSolidLinearGradientRle(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); auto alpha = surface->blender.alpha(surface->compositor->method);
for (uint32_t y = 0; y < h; ++y) { 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; buffer += surface->stride;
cbuffer += surface->stride * csize; cbuffer += surface->stride * csize;
} }
@ -1070,7 +1067,7 @@ static bool _rasterTranslucentRadialGradientRect(SwSurface* surface, const SwBBo
for (uint32_t y = 0; y < h; ++y) { for (uint32_t y = 0; y < h; ++y) {
auto dst = buffer; 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; buffer += surface->stride;
} }
return true; return true;
@ -1086,7 +1083,7 @@ static bool _rasterSolidRadialGradientRect(SwSurface* surface, const SwBBox& reg
auto w = static_cast<uint32_t>(region.max.x - region.min.x); auto w = static_cast<uint32_t>(region.max.x - region.min.x);
for (uint32_t y = 0; y < h; ++y) { 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; return true;
} }
@ -1097,7 +1094,6 @@ static bool _rasterRadialGradientRect(SwSurface* surface, const SwBBox& region,
if (_compositing(surface)) { if (_compositing(surface)) {
return _rasterRadialGradientMaskedRect(surface, region, fill); return _rasterRadialGradientMaskedRect(surface, region, fill);
} else { } else {
//OPTIMIZE_ME: Unity branches.
if (fill->translucent) return _rasterTranslucentRadialGradientRect(surface, region, fill); if (fill->translucent) return _rasterTranslucentRadialGradientRect(surface, region, fill);
else return _rasterSolidRadialGradientRect(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) { for (uint32_t i = 0; i < rle->size; ++i, ++span) {
auto dst = &surface->buf32[span->y * surface->stride + span->x]; auto dst = &surface->buf32[span->y * surface->stride + span->x];
auto cmp = &cbuffer[(span->y * surface->compositor->image.stride + span->x) * csize]; 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; return true;
} }
@ -1135,8 +1131,8 @@ static bool _rasterTranslucentRadialGradientRle(SwSurface* surface, const SwRleD
for (uint32_t i = 0; i < rle->size; ++i, ++span) { for (uint32_t i = 0; i < rle->size; ++i, ++span) {
auto dst = &surface->buf32[span->y * surface->stride + span->x]; auto dst = &surface->buf32[span->y * surface->stride + span->x];
if (span->coverage == 255) fillRasterRadial(fill, dst, span->y, span->x, span->len, opBlend); if (span->coverage == 255) fillRadial(fill, dst, span->y, span->x, span->len, opBlend);
else fillRasterRadial(fill, dst, span->y, span->x, span->len, opAlphaBlend, span->coverage); else fillRadial(fill, dst, span->y, span->x, span->len, opAlphaBlend, span->coverage);
} }
return true; return true;
} }
@ -1150,8 +1146,8 @@ static bool _rasterSolidRadialGradientRle(SwSurface* surface, const SwRleData* r
for (uint32_t i = 0; i < rle->size; ++i, ++span) { for (uint32_t i = 0; i < rle->size; ++i, ++span) {
auto dst = &surface->buf32[span->y * surface->stride + span->x]; auto dst = &surface->buf32[span->y * surface->stride + span->x];
if (span->coverage == 255) fillRasterRadial(fill, dst, span->y, span->x, span->len); if (span->coverage == 255) fillRadial(fill, dst, span->y, span->x, span->len);
else fillRasterRadial(fill, dst, span->y, span->x, span->len, opInterpolate, span->coverage); else fillRadial(fill, dst, span->y, span->x, span->len, opInterpolate, span->coverage);
} }
return true; return true;
} }
@ -1164,7 +1160,6 @@ static bool _rasterRadialGradientRle(SwSurface* surface, const SwRleData* rle, c
if (_compositing(surface)) { if (_compositing(surface)) {
return _rasterRadialGradientMaskedRle(surface, rle, fill); return _rasterRadialGradientMaskedRle(surface, rle, fill);
} else { } else {
//OPTIMIZE_ME: Unity branches.
if (fill->translucent) _rasterTranslucentRadialGradientRle(surface, rle, fill); if (fill->translucent) _rasterTranslucentRadialGradientRle(surface, rle, fill);
else return _rasterSolidRadialGradientRle(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) bool rasterCompositor(SwSurface* surface)
{ {
//See CompositeMethod, Alpha:3, InvAlpha:4, Luma:5, InvLuma:6 //See CompositeMethod, Alpha:3, InvAlpha:4, Luma:5, InvLuma:6
surface->blender.alphas[0] = _alpha; surface->blender.alphas[0] = ALPHA;
surface->blender.alphas[1] = _ialpha; surface->blender.alphas[1] = IALPHA;
if (surface->cs == ColorSpace::ABGR8888 || surface->cs == ColorSpace::ABGR8888S) { if (surface->cs == ColorSpace::ABGR8888 || surface->cs == ColorSpace::ABGR8888S) {
surface->blender.join = _abgrJoin; 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) bool rasterShape(SwSurface* surface, SwShape* shape, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{ {
if (a < 255) { if (a < 255) {
r = _multiply(r, a); r = MULTIPLY(r, a);
g = _multiply(g, a); g = MULTIPLY(g, a);
b = _multiply(b, a); b = MULTIPLY(b, a);
} }
if (shape->fastTrack) return _rasterRect(surface, shape->bbox, r, g, 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) bool rasterStroke(SwSurface* surface, SwShape* shape, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{ {
if (a < 255) { if (a < 255) {
r = _multiply(r, a); r = MULTIPLY(r, a);
g = _multiply(g, a); g = MULTIPLY(g, a);
b = _multiply(b, a); b = MULTIPLY(b, a);
} }
return _rasterRle(surface, shape->strokeRle, r, g, b, a); return _rasterRle(surface, shape->strokeRle, r, g, b, a);

View file

@ -148,7 +148,7 @@ static bool avxRasterTranslucentRle(SwSurface* surface, const SwRleData* rle, ui
if (span->coverage < 255) src = ALPHA_BLEND(color, span->coverage); if (span->coverage < 255) src = ALPHA_BLEND(color, span->coverage);
else src = color; 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) //1. fill the not aligned memory (for 128-bit registers a 16-bytes alignment is required)
auto notAligned = ((uintptr_t)dst & 0xf) / 4; auto notAligned = ((uintptr_t)dst & 0xf) / 4;

View file

@ -40,8 +40,9 @@ static bool inline cRasterTranslucentRle(SwSurface* surface, const SwRleData* rl
auto dst = &surface->buf32[span->y * surface->stride + span->x]; auto dst = &surface->buf32[span->y * surface->stride + span->x];
if (span->coverage < 255) src = ALPHA_BLEND(color, span->coverage); if (span->coverage < 255) src = ALPHA_BLEND(color, span->coverage);
else src = color; else src = color;
auto ialpha = IALPHA(src);
for (uint32_t x = 0; x < span->len; ++x, ++dst) { 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 //8bit grayscale
@ -49,10 +50,11 @@ static bool inline cRasterTranslucentRle(SwSurface* surface, const SwRleData* rl
uint8_t src; uint8_t src;
for (uint32_t i = 0; i < rle->size; ++i, ++span) { for (uint32_t i = 0; i < rle->size; ++i, ++span) {
auto dst = &surface->buf8[span->y * surface->stride + span->x]; 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; else src = a;
auto ialpha = ~a;
for (uint32_t x = 0; x < span->len; ++x, ++dst) { 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)) { if (surface->channelSize == sizeof(uint32_t)) {
auto color = surface->blender.join(r, g, b, a); auto color = surface->blender.join(r, g, b, a);
auto buffer = surface->buf32 + (region.min.y * surface->stride) + region.min.x; 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) { for (uint32_t y = 0; y < h; ++y) {
auto dst = &buffer[y * surface->stride]; auto dst = &buffer[y * surface->stride];
for (uint32_t x = 0; x < w; ++x, ++dst) { for (uint32_t x = 0; x < w; ++x, ++dst) {
@ -79,10 +81,11 @@ static bool inline cRasterTranslucentRect(SwSurface* surface, const SwBBox& regi
//8bit grayscale //8bit grayscale
} else if (surface->channelSize == sizeof(uint8_t)) { } else if (surface->channelSize == sizeof(uint8_t)) {
auto buffer = surface->buf8 + (region.min.y * surface->stride) + region.min.x; auto buffer = surface->buf8 + (region.min.y * surface->stride) + region.min.x;
auto ialpha = ~a;
for (uint32_t y = 0; y < h; ++y) { for (uint32_t y = 0; y < h; ++y) {
auto dst = &buffer[y * surface->stride]; auto dst = &buffer[y * surface->stride];
for (uint32_t x = 0; x < w; ++x, ++dst) { for (uint32_t x = 0; x < w; ++x, ++dst) {
*dst = a + _multiply(*dst, ~a); *dst = a + MULTIPLY(*dst, ialpha);
} }
} }
} }

View file

@ -67,7 +67,7 @@ static bool neonRasterTranslucentRle(SwSurface* surface, const SwRleData* rle, u
else src = color; else src = color;
auto dst = &surface->buf32[span->y * surface->stride + span->x]; 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) { if ((((uint32_t) dst) & 0x7) != 0) {
//fill not aligned byte //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 buffer = surface->buf32 + (region.min.y * surface->stride) + region.min.x;
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 ialpha = 255 - _alpha(color); auto ialpha = IALPHA(color);
auto vColor = vdup_n_u32(color); auto vColor = vdup_n_u32(color);
auto vIalpha = vdup_n_u8((uint8_t) ialpha); auto vIalpha = vdup_n_u8((uint8_t) ialpha);

View file

@ -133,7 +133,7 @@
} }
#if defined(TEXMAP_MASKING) && defined(TEXMAP_TRANSLUCENT) #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; cmp += csize;
#elif defined(TEXMAP_MASKING) #elif defined(TEXMAP_MASKING)
auto src = ALPHA_BLEND(px, alpha(cmp)); auto src = ALPHA_BLEND(px, alpha(cmp));
@ -143,7 +143,7 @@
#else #else
auto src = px; auto src = px;
#endif #endif
*buf = src + ALPHA_BLEND(*buf, _ialpha(src)); *buf = src + ALPHA_BLEND(*buf, IALPHA(src));
++buf; ++buf;
//Step UV horizontally //Step UV horizontally