mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
sw_engine raster: ++ precise alpha multiplying
previously alpha multiplying operation doesn't have perfect precision, could loss 1 pixel since it divides 255 values by 256. This improved operation comply with both precision & performance.
This commit is contained in:
parent
9a1d7ec841
commit
9a40b64261
2 changed files with 11 additions and 7 deletions
|
@ -274,7 +274,7 @@ static inline uint32_t COLOR_INTERPOLATE(uint32_t c1, uint32_t a1, uint32_t c2,
|
||||||
|
|
||||||
static inline uint8_t ALPHA_MULTIPLY(uint32_t c, uint32_t a)
|
static inline uint8_t ALPHA_MULTIPLY(uint32_t c, uint32_t a)
|
||||||
{
|
{
|
||||||
return (c * a) >> 8;
|
return ((c * a + 0xff) >> 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline SwCoord HALF_STROKE(float width)
|
static inline SwCoord HALF_STROKE(float width)
|
||||||
|
|
|
@ -851,9 +851,11 @@ bool rasterGradientShape(SwSurface* surface, SwShape* shape, unsigned id)
|
||||||
|
|
||||||
bool rasterSolidShape(SwSurface* surface, SwShape* shape, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
|
bool rasterSolidShape(SwSurface* surface, SwShape* shape, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
|
||||||
{
|
{
|
||||||
r = ALPHA_MULTIPLY(r, a);
|
if (a < 255) {
|
||||||
g = ALPHA_MULTIPLY(g, a);
|
r = ALPHA_MULTIPLY(r, a);
|
||||||
b = ALPHA_MULTIPLY(b, a);
|
g = ALPHA_MULTIPLY(g, a);
|
||||||
|
b = ALPHA_MULTIPLY(b, a);
|
||||||
|
}
|
||||||
|
|
||||||
auto color = surface->blender.join(r, g, b, a);
|
auto color = surface->blender.join(r, g, b, a);
|
||||||
auto translucent = _translucent(surface, a);
|
auto translucent = _translucent(surface, a);
|
||||||
|
@ -872,9 +874,11 @@ bool rasterSolidShape(SwSurface* surface, SwShape* shape, uint8_t r, uint8_t g,
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
r = ALPHA_MULTIPLY(r, a);
|
if (a < 255) {
|
||||||
g = ALPHA_MULTIPLY(g, a);
|
r = ALPHA_MULTIPLY(r, a);
|
||||||
b = ALPHA_MULTIPLY(b, a);
|
g = ALPHA_MULTIPLY(g, a);
|
||||||
|
b = ALPHA_MULTIPLY(b, a);
|
||||||
|
}
|
||||||
|
|
||||||
auto color = surface->blender.join(r, g, b, a);
|
auto color = surface->blender.join(r, g, b, a);
|
||||||
auto translucent = _translucent(surface, a);
|
auto translucent = _translucent(surface, a);
|
||||||
|
|
Loading…
Add table
Reference in a new issue