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 */
/************************************************************************/
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)
{
return (((((color >> 8) & 0x00ff00ff) * alpha) & 0xff00ff00) +
@ -33,15 +39,18 @@ static inline size_t COLOR_ALPHA_BLEND(size_t color, size_t alpha)
static inline size_t COLOR_ARGB_JOIN(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
return (a << 24 | r << 16 | g << 8 | b);
return (a << 24 | r << 16 | g << 8 | b);
}
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
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) {
dst[i] = color + COLOR_ALPHA_BLEND(dst[i], ialpha);
}
@ -49,11 +58,20 @@ _drawTranslucentSpan(uint32_t* dst, size_t len, size_t color, size_t alpha)
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
for (size_t i = 0; i < len; ++i) {
dst[i] = color;
//Fully Opaque
if (cov == 255) {
for (size_t i = 0; i < len; ++i) {
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);
auto dst = &surface.buffer[span->y * stride + span->x];
assert(dst);
if (a == 255) _drawSolidSpan(dst, span->len, color);
else _drawTranslucentSpan(dst, span->len, color, a);
if (a == 255) _rasterSolid(dst, span->len, color, span->coverage);
else _rasterTranslucent(dst, span->len, color, span->coverage);
++span;
}

View file

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