From 06d8d06993118b386a40b341db92a567d662068e Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Wed, 19 Aug 2020 18:32:32 +0900 Subject: [PATCH] sw_engine: replace rgba8888 with abgr8888 Actually Dali rendering system requires abgr8888. We could add more colorspaces if it's necessary. Change-Id: Ia42a6575d1313629e55efc3077e302992c47b6c0 --- inc/thorvg.h | 2 +- inc/thorvg_capi.h | 2 +- src/lib/sw_engine/tvgSwCommon.h | 14 +++++------ src/lib/sw_engine/tvgSwFill.cpp | 2 +- src/lib/sw_engine/tvgSwRaster.cpp | 52 +++++++++++++++++---------------------- 5 files changed, 33 insertions(+), 39 deletions(-) diff --git a/inc/thorvg.h b/inc/thorvg.h index 9ed5498..18013fa 100644 --- a/inc/thorvg.h +++ b/inc/thorvg.h @@ -311,7 +311,7 @@ class TVG_EXPORT SwCanvas final : public Canvas public: ~SwCanvas(); - enum Colorspace { RGBA8888 = 0, ARGB8888 }; + enum Colorspace { ABGR8888 = 0, ARGB8888 }; Result target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h, Colorspace cs) noexcept; diff --git a/inc/thorvg_capi.h b/inc/thorvg_capi.h index 2f1bf96..811c82e 100644 --- a/inc/thorvg_capi.h +++ b/inc/thorvg_capi.h @@ -23,7 +23,7 @@ typedef struct _Tvg_Gradient Tvg_Gradient; #define TVG_ENGINE_SW (1 << 1) #define TVG_ENGINE_GL (1 << 2) -#define TVG_COLORSPACE_RGBA8888 0 +#define TVG_COLORSPACE_ABGR8888 0 #define TVG_COLORSPACE_ARGB8888 1 typedef enum { diff --git a/src/lib/sw_engine/tvgSwCommon.h b/src/lib/sw_engine/tvgSwCommon.h index ee70599..a600cb9 100644 --- a/src/lib/sw_engine/tvgSwCommon.h +++ b/src/lib/sw_engine/tvgSwCommon.h @@ -229,17 +229,17 @@ static inline SwCoord TO_SWCOORD(float val) return SwCoord(val * 64); } -static inline uint32_t RGBA_ALPHA_BLEND(uint32_t rgba, uint32_t alpha) +static inline uint32_t ALPHA_BLEND(uint32_t c, uint32_t a) { - return (((((rgba >> 8) & 0x00ff00ff) * alpha) & 0xff00ff00) + - ((((rgba & 0x00ff00ff) * alpha) >> 8) & 0x00ff00ff)); + return (((((c >> 8) & 0x00ff00ff) * a) & 0xff00ff00) + + ((((c & 0x00ff00ff) * a) >> 8) & 0x00ff00ff)); } -static inline uint32_t RGBA_INTERPOLATE(uint32_t rgba1, uint32_t a, uint32_t rgba2, uint32_t b) +static inline uint32_t COLOR_INTERPOLATE(uint32_t c1, uint32_t a1, uint32_t c2, uint32_t a2) { - auto t = (((rgba1 & 0xff00ff) * a + (rgba2 & 0xff00ff) * b) >> 8) & 0xff00ff; - rgba1 = (((rgba1 >> 8) & 0xff00ff) * a + ((rgba2 >> 8) & 0xff00ff) * b) & 0xff00ff00; - return (rgba1 |= t); + auto t = (((c1 & 0xff00ff) * a1 + (c2 & 0xff00ff) * a2) >> 8) & 0xff00ff; + c1 = (((c1 >> 8) & 0xff00ff) * a1 + ((c2 >> 8) & 0xff00ff) * a2) & 0xff00ff00; + return (c1 |= t); } static inline uint8_t ALPHA_MULTIPLY(uint32_t c, uint32_t a) diff --git a/src/lib/sw_engine/tvgSwFill.cpp b/src/lib/sw_engine/tvgSwFill.cpp index ccc0574..72e702b 100644 --- a/src/lib/sw_engine/tvgSwFill.cpp +++ b/src/lib/sw_engine/tvgSwFill.cpp @@ -82,7 +82,7 @@ static bool _updateColorTable(SwFill* fill, const Fill* fdata, SwSurface* surfac auto t = (pos - curr->offset) * delta; auto dist = static_cast(256 * t); auto dist2 = 256 - dist; - fill->ctable[i] = RGBA_INTERPOLATE(rgba, dist2, rgba2, dist); + fill->ctable[i] = COLOR_INTERPOLATE(rgba, dist2, rgba2, dist); ++i; pos += inc; } diff --git a/src/lib/sw_engine/tvgSwRaster.cpp b/src/lib/sw_engine/tvgSwRaster.cpp index 072c74c..3fec524 100644 --- a/src/lib/sw_engine/tvgSwRaster.cpp +++ b/src/lib/sw_engine/tvgSwRaster.cpp @@ -28,21 +28,15 @@ /* Internal Class Implementation */ /************************************************************************/ -static uint32_t _rgbaAlpha(uint32_t rgba) +static uint32_t _colorAlpha(uint32_t c) { - return rgba & 0x000000ff; + return (c >> 24) & 0xff; } -static uint32_t _argbAlpha(uint32_t argb) +static uint32_t _abgrJoin(uint8_t r, uint8_t g, uint8_t b, uint8_t a) { - return (argb >> 24) & 0xff; -} - - -static uint32_t _rgbaJoin(uint8_t r, uint8_t g, uint8_t b, uint8_t a) -{ - return (r << 24 | g << 16 | b << 8 | a); + return (a << 24 | b << 16 | g << 8 | r); } @@ -74,7 +68,7 @@ static bool _rasterTranslucentRect(SwSurface* surface, const SwBBox& region, uin for (uint32_t y = 0; y < h; ++y) { auto dst = &buffer[y * surface->stride]; for (uint32_t x = 0; x < w; ++x) { - dst[x] = color + RGBA_ALPHA_BLEND(dst[x], ialpha); + dst[x] = color + ALPHA_BLEND(dst[x], ialpha); } } return true; @@ -103,11 +97,11 @@ static bool _rasterTranslucentRle(SwSurface* surface, SwRleData* rle, uint32_t c for (uint32_t i = 0; i < rle->size; ++i) { auto dst = &surface->buffer[span->y * surface->stride + span->x]; - if (span->coverage < 255) src = RGBA_ALPHA_BLEND(color, span->coverage); + if (span->coverage < 255) src = ALPHA_BLEND(color, span->coverage); else src = color; auto ialpha = 255 - surface->comp.alpha(src); for (uint32_t i = 0; i < span->len; ++i) { - dst[i] = src + RGBA_ALPHA_BLEND(dst[i], ialpha); + dst[i] = src + ALPHA_BLEND(dst[i], ialpha); } ++span; } @@ -126,10 +120,10 @@ static bool _rasterSolidRle(SwSurface* surface, SwRleData* rle, uint32_t color) rasterRGBA32(surface->buffer + span->y * surface->stride, color, span->x, span->len); } else { auto dst = &surface->buffer[span->y * surface->stride + span->x]; - auto src = RGBA_ALPHA_BLEND(color, span->coverage); + auto src = ALPHA_BLEND(color, span->coverage); auto ialpha = 255 - span->coverage; for (uint32_t i = 0; i < span->len; ++i) { - dst[i] = src + RGBA_ALPHA_BLEND(dst[i], ialpha); + dst[i] = src + ALPHA_BLEND(dst[i], ialpha); } } ++span; @@ -156,7 +150,7 @@ static bool _rasterLinearGradientRect(SwSurface* surface, const SwBBox& region, auto dst = &buffer[y * surface->stride]; fillFetchLinear(fill, tmpBuf, region.min.y + y, region.min.x, 0, w); for (uint32_t x = 0; x < w; ++x) { - dst[x] = tmpBuf[x] + RGBA_ALPHA_BLEND(dst[x], 255 - surface->comp.alpha(tmpBuf[x])); + dst[x] = tmpBuf[x] + ALPHA_BLEND(dst[x], 255 - surface->comp.alpha(tmpBuf[x])); } } //Opaque Gradient @@ -187,7 +181,7 @@ static bool _rasterRadialGradientRect(SwSurface* surface, const SwBBox& region, auto dst = &buffer[y * surface->stride]; fillFetchRadial(fill, tmpBuf, region.min.y + y, region.min.x, w); for (uint32_t x = 0; x < w; ++x) { - dst[x] = tmpBuf[x] + RGBA_ALPHA_BLEND(dst[x], 255 - surface->comp.alpha(tmpBuf[x])); + dst[x] = tmpBuf[x] + ALPHA_BLEND(dst[x], 255 - surface->comp.alpha(tmpBuf[x])); } } //Opaque Gradient @@ -217,12 +211,12 @@ static bool _rasterLinearGradientRle(SwSurface* surface, SwRleData* rle, const S fillFetchLinear(fill, buf, span->y, span->x, 0, span->len); if (span->coverage == 255) { for (uint32_t i = 0; i < span->len; ++i) { - dst[i] = buf[i] + RGBA_ALPHA_BLEND(dst[i], 255 - surface->comp.alpha(buf[i])); + dst[i] = buf[i] + ALPHA_BLEND(dst[i], 255 - surface->comp.alpha(buf[i])); } } else { for (uint32_t i = 0; i < span->len; ++i) { - auto tmp = RGBA_ALPHA_BLEND(buf[i], span->coverage); - dst[i] = tmp + RGBA_ALPHA_BLEND(dst[i], 255 - surface->comp.alpha(tmp)); + auto tmp = ALPHA_BLEND(buf[i], span->coverage); + dst[i] = tmp + ALPHA_BLEND(dst[i], 255 - surface->comp.alpha(tmp)); } } ++span; @@ -237,7 +231,7 @@ static bool _rasterLinearGradientRle(SwSurface* surface, SwRleData* rle, const S fillFetchLinear(fill, buf, span->y, span->x, 0, span->len); auto ialpha = 255 - span->coverage; for (uint32_t i = 0; i < span->len; ++i) { - dst[i] = RGBA_ALPHA_BLEND(buf[i], span->coverage) + RGBA_ALPHA_BLEND(dst[i], ialpha); + dst[i] = ALPHA_BLEND(buf[i], span->coverage) + ALPHA_BLEND(dst[i], ialpha); } } ++span; @@ -263,12 +257,12 @@ static bool _rasterRadialGradientRle(SwSurface* surface, SwRleData* rle, const S fillFetchRadial(fill, buf, span->y, span->x, span->len); if (span->coverage == 255) { for (uint32_t i = 0; i < span->len; ++i) { - dst[i] = buf[i] + RGBA_ALPHA_BLEND(dst[i], 255 - surface->comp.alpha(buf[i])); + dst[i] = buf[i] + ALPHA_BLEND(dst[i], 255 - surface->comp.alpha(buf[i])); } } else { for (uint32_t i = 0; i < span->len; ++i) { - auto tmp = RGBA_ALPHA_BLEND(buf[i], span->coverage); - dst[i] = tmp + RGBA_ALPHA_BLEND(dst[i], 255 - surface->comp.alpha(tmp)); + auto tmp = ALPHA_BLEND(buf[i], span->coverage); + dst[i] = tmp + ALPHA_BLEND(dst[i], 255 - surface->comp.alpha(tmp)); } } ++span; @@ -283,7 +277,7 @@ static bool _rasterRadialGradientRle(SwSurface* surface, SwRleData* rle, const S fillFetchRadial(fill, buf, span->y, span->x, span->len); auto ialpha = 255 - span->coverage; for (uint32_t i = 0; i < span->len; ++i) { - dst[i] = RGBA_ALPHA_BLEND(buf[i], span->coverage) + RGBA_ALPHA_BLEND(dst[i], ialpha); + dst[i] = ALPHA_BLEND(buf[i], span->coverage) + ALPHA_BLEND(dst[i], ialpha); } } ++span; @@ -299,11 +293,11 @@ static bool _rasterRadialGradientRle(SwSurface* surface, SwRleData* rle, const S bool rasterCompositor(SwSurface* surface) { - if (surface->cs == SwCanvas::RGBA8888) { - surface->comp.alpha = _rgbaAlpha; - surface->comp.join = _rgbaJoin; + if (surface->cs == SwCanvas::ABGR8888) { + surface->comp.alpha = _colorAlpha; + surface->comp.join = _abgrJoin; } else if (surface->cs == SwCanvas::ARGB8888) { - surface->comp.alpha = _argbAlpha; + surface->comp.alpha = _colorAlpha; surface->comp.join = _argbJoin; } else { //What Color Space ??? -- 2.7.4