From 503fabfb573778bd335ca820596fb88edb82c733 Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Thu, 4 Feb 2021 02:10:14 +0100 Subject: [PATCH] sw_engine raster: adding rastering functions for image without transformation Added rastering functions for the image (transparent and not) for the fast track option - identity transform. --- src/lib/sw_engine/tvgSwRaster.cpp | 40 +++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/lib/sw_engine/tvgSwRaster.cpp b/src/lib/sw_engine/tvgSwRaster.cpp index 27245d0..fb8fb2f 100644 --- a/src/lib/sw_engine/tvgSwRaster.cpp +++ b/src/lib/sw_engine/tvgSwRaster.cpp @@ -321,6 +321,22 @@ static bool _rasterSolidRle(SwSurface* surface, SwRleData* rle, uint32_t color) /* Image */ /************************************************************************/ +static bool _rasterTranslucentImageRle(SwSurface* surface, SwRleData* rle, uint32_t *img, uint32_t w, uint32_t h, uint32_t opacity) +{ + auto span = rle->spans; + + for (uint32_t i = 0; i < rle->size; ++i, ++span) { + auto dst = &surface->buffer[span->y * surface->stride + span->x]; + auto src = img + span->x + span->y * w; //TODO: need to use image's stride + for (uint32_t x = 0; x < span->len; ++x, ++dst, ++src) { + auto alpha = ALPHA_MULTIPLY(span->coverage, opacity); + *src = ALPHA_BLEND(*src, alpha); + *dst = *src + ALPHA_BLEND(*dst, 255 - surface->blender.alpha(*src)); + } + } + return true; +} + static bool _rasterTranslucentImageRle(SwSurface* surface, SwRleData* rle, uint32_t *img, uint32_t w, uint32_t h, uint32_t opacity, const Matrix* invTransform) { @@ -344,6 +360,22 @@ static bool _rasterTranslucentImageRle(SwSurface* surface, SwRleData* rle, uint3 } +static bool _rasterImageRle(SwSurface* surface, SwRleData* rle, uint32_t *img, uint32_t w, uint32_t h) +{ + auto span = rle->spans; + + for (uint32_t i = 0; i < rle->size; ++i, ++span) { + auto dst = &surface->buffer[span->y * surface->stride + span->x]; + auto src = img + span->x + span->y * w; //TODO: need to use image's stride + for (uint32_t x = 0; x < span->len; ++x, ++dst, ++src) { + *src = ALPHA_BLEND(*src, span->coverage); + *dst = *src + ALPHA_BLEND(*dst, 255 - surface->blender.alpha(*src)); + } + } + return true; +} + + static bool _rasterImageRle(SwSurface* surface, SwRleData* rle, uint32_t *img, uint32_t w, uint32_t h, const Matrix* invTransform) { auto span = rle->spans; @@ -809,12 +841,8 @@ bool rasterImage(SwSurface* surface, SwImage* image, const Matrix* transform, Sw //Fast track if (_identify(transform)) { //OPTIMIZE ME: Support non transformed image. Only shifted image can use these routines. -#ifdef THORVG_LOG_ENABLED - printf("SW_ENGINE: implementation is missing!\n"); -#endif - //if (translucent) return _rasterTranslucentImageRle(surface, image->rle, image->data, image->w, image->h, opacity); - //return _rasterImageRle(surface, image->rle, image->data, image->w, image->h); - return false; + if (translucent) return _rasterTranslucentImageRle(surface, image->rle, image->data, image->w, image->h, opacity); + return _rasterImageRle(surface, image->rle, image->data, image->w, image->h); } else { if (translucent) return _rasterTranslucentImageRle(surface, image->rle, image->data, image->w, image->h, opacity, &invTransform); return _rasterImageRle(surface, image->rle, image->data, image->w, image->h, &invTransform); -- 2.7.4