sw_engine: support anti-aliasing

Change-Id: I9b79c8b4022ddf2ae4fe980f480ba3ec140750d3
This commit is contained in:
Hermet Park 2020-05-01 17:15:31 +09:00
parent 74d2f275e7
commit 11e070d167
2 changed files with 28 additions and 11 deletions

View file

@ -24,6 +24,12 @@
/* Internal Class Implementation */ /* Internal Class Implementation */
/************************************************************************/ /************************************************************************/
static inline size_t COLOR_ALPHA(size_t color)
{
return (color >> 24) & 0xff;
}
static inline size_t COLOR_ALPHA_BLEND(size_t color, size_t alpha) static inline size_t COLOR_ALPHA_BLEND(size_t color, size_t alpha)
{ {
return (((((color >> 8) & 0x00ff00ff) * alpha) & 0xff00ff00) + return (((((color >> 8) & 0x00ff00ff) * alpha) & 0xff00ff00) +
@ -38,10 +44,13 @@ static inline size_t COLOR_ARGB_JOIN(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
static void static void
_drawTranslucentSpan(uint32_t* dst, size_t len, size_t color, size_t alpha) _rasterTranslucent(uint32_t* dst, size_t len, size_t color, size_t cov)
{ {
//OPTIMIZE ME: SIMD //OPTIMIZE ME: SIMD
auto ialpha = 255 - alpha;
if (cov < 255) color = COLOR_ALPHA_BLEND(color, cov);
auto ialpha = 255 - COLOR_ALPHA(color);
for (size_t i = 0; i < len; ++i) { for (size_t i = 0; i < len; ++i) {
dst[i] = color + COLOR_ALPHA_BLEND(dst[i], ialpha); dst[i] = color + COLOR_ALPHA_BLEND(dst[i], ialpha);
} }
@ -49,12 +58,21 @@ _drawTranslucentSpan(uint32_t* dst, size_t len, size_t color, size_t alpha)
static void static void
_drawSolidSpan(uint32_t* dst, size_t len, size_t color) _rasterSolid(uint32_t* dst, size_t len, size_t color, size_t cov)
{ {
//OPTIMIZE ME: SIMD //OPTIMIZE ME: SIMD
//Fully Opaque
if (cov == 255) {
for (size_t i = 0; i < len; ++i) { for (size_t i = 0; i < len; ++i) {
dst[i] = color; dst[i] = color;
} }
} else {
auto ialpha = 255 - cov;
for (size_t i = 0; i < len; ++i) {
dst[i] = COLOR_ALPHA_BLEND(color, cov) + COLOR_ALPHA_BLEND(dst[i], ialpha);
}
}
} }
@ -75,10 +93,9 @@ bool rasterShape(Surface& surface, SwShape& sdata, uint8_t r, uint8_t g, uint8_t
assert(span); assert(span);
auto dst = &surface.buffer[span->y * stride + span->x]; auto dst = &surface.buffer[span->y * stride + span->x];
assert(dst);
if (a == 255) _drawSolidSpan(dst, span->len, color); if (a == 255) _rasterSolid(dst, span->len, color, span->coverage);
else _drawTranslucentSpan(dst, span->len, color, a); else _rasterTranslucent(dst, span->len, color, span->coverage);
++span; ++span;
} }

View file

@ -434,8 +434,8 @@ static void _lineTo(RleWorker& rw, const SwPoint& to)
/* These macros speed up repetitive divisions by replacing them /* These macros speed up repetitive divisions by replacing them
with multiplications and right shifts. */ with multiplications and right shifts. */
auto dx_r = (ULONG_MAX >> PIXEL_BITS) / (diff.x); auto dx_r = static_cast<long>(ULONG_MAX >> PIXEL_BITS) / (diff.x);
auto dy_r = (ULONG_MAX >> PIXEL_BITS) / (diff.y); auto dy_r = static_cast<long>(ULONG_MAX >> PIXEL_BITS) / (diff.y);
/* The fundamental value `prod' determines which side and the */ /* The fundamental value `prod' determines which side and the */
/* exact coordinate where the line exits current cell. It is */ /* exact coordinate where the line exits current cell. It is */