sw_engine image: code refactoring
authorHermet Park <chuneon.park@samsung.com>
Fri, 19 Nov 2021 04:22:32 +0000 (13:22 +0900)
committerJunsuChoi <jsuya.choi@samsung.com>
Fri, 19 Nov 2021 05:27:38 +0000 (14:27 +0900)
+++

src/lib/sw_engine/tvgSwCommon.h
src/lib/sw_engine/tvgSwImage.cpp
src/lib/sw_engine/tvgSwRaster.cpp

index 85974f5..e46eee7 100644 (file)
@@ -224,11 +224,11 @@ struct SwImage
     SwRleData*   rle = nullptr;
     uint32_t*    data = nullptr;
     uint32_t     w, h, stride;
-    int32_t      x = 0;         //shift x
-    int32_t      y = 0;         //shift y
+    int32_t      ox = 0;         //offset x
+    int32_t      oy = 0;         //offset y
     float        scale;
 
-    bool         transformed = false;
+    bool         direct = false;  //draw image directly (with offset)
 };
 
 struct SwBlender
index 096e734..76631cc 100644 (file)
 /* Internal Class Implementation                                        */
 /************************************************************************/
 
+static inline bool _onlyShifted(const Matrix* m)
+{
+    if (mathEqual(m->e11, 1.0f) && mathEqual(m->e22, 1.0f) && mathZero(m->e12) && mathZero(m->e21)) return true;
+    return false;
+}
+
+
 static bool _genOutline(SwImage* image, const Matrix* transform, SwMpool* mpool, unsigned tid)
 {
     image->outline = mpoolReqOutline(mpool, tid);
@@ -67,40 +74,27 @@ static bool _genOutline(SwImage* image, const Matrix* transform, SwMpool* mpool,
 }
 
 
-static inline bool _onlyShifted(const Matrix* m)
-{
-    if (mathEqual(m->e11, 1.0f) && mathEqual(m->e22, 1.0f) && mathZero(m->e12) && mathZero(m->e21)) return true;
-    return false;
-}
-
-
 /************************************************************************/
 /* External Class Implementation                                        */
 /************************************************************************/
 
-
 bool imagePrepare(SwImage* image, const Matrix* transform, const SwBBox& clipRegion, SwBBox& renderRegion, SwMpool* mpool, unsigned tid)
 {
-    image->transformed = !_onlyShifted(transform);
-    bool fastTrack;
+    image->direct = _onlyShifted(transform);
 
+    //Fast track: Non-transformed image but just shifted.
+    if (image->direct) {
+        image->ox = -static_cast<uint32_t>(round(transform->e13));
+        image->oy = -static_cast<uint32_t>(round(transform->e23));
     //Figure out the scale factor by transform matrix
-    if (image->transformed) {
+    } else {
         auto scaleX = sqrtf((transform->e11 * transform->e11) + (transform->e21 * transform->e21));
         auto scaleY = sqrtf((transform->e22 * transform->e22) + (transform->e12 * transform->e12));
-        //TODO:If the x and y axis scale is different, a separate interpolation algorithm for each axis should be applied.
         image->scale = (fabsf(scaleX - scaleY) > 0.01f) ? 1.0f : scaleX;
-        fastTrack = false;
-    //Fast track: Non-transformed image but just shifted.
-    } else {
-        image->scale = 1.0f;
-        image->x = -static_cast<uint32_t>(round(transform->e13));
-        image->y = -static_cast<uint32_t>(round(transform->e23));
-        fastTrack = true;
     }
 
     if (!_genOutline(image, transform, mpool, tid)) return false;
-    return mathUpdateOutlineBBox(image->outline, clipRegion, renderRegion, fastTrack);
+    return mathUpdateOutlineBBox(image->outline, clipRegion, renderRegion, image->direct);
 }
 
 
index ede7155..efecb63 100644 (file)
@@ -597,7 +597,7 @@ static bool _rasterDirectMaskedRleImage(SwSurface* surface, const SwImage* image
     for (uint32_t i = 0; i < image->rle->size; ++i, ++span) {
         auto dst = &surface->buffer[span->y * surface->stride + span->x];
         auto cmp = &cbuffer[span->y * surface->stride + span->x];
-        auto img = image->data + (span->y + image->y) * image->stride + (span->x + image->x);
+        auto img = image->data + (span->y + image->oy) * image->stride + (span->x + image->ox);
         auto alpha = _multiplyAlpha(span->coverage, opacity);
         if (alpha == 255) {
             for (uint32_t x = 0; x < span->len; ++x, ++dst, ++cmp, ++img) {
@@ -621,7 +621,7 @@ static bool __rasterDirectTranslucentRleImage(SwSurface* surface, const SwImage*
 
     for (uint32_t i = 0; i < image->rle->size; ++i, ++span) {
         auto dst = &surface->buffer[span->y * surface->stride + span->x];
-        auto img = image->data + (span->y + image->y) * image->stride + (span->x + image->x);
+        auto img = image->data + (span->y + image->oy) * image->stride + (span->x + image->ox);
         auto alpha = _multiplyAlpha(span->coverage, opacity);
         for (uint32_t x = 0; x < span->len; ++x, ++dst, ++img) {
             auto src = ALPHA_BLEND(*img, alpha);
@@ -651,7 +651,7 @@ static bool _rasterDirectSolidRleImage(SwSurface* surface, const SwImage* image)
 
     for (uint32_t i = 0; i < image->rle->size; ++i, ++span) {
         auto dst = &surface->buffer[span->y * surface->stride + span->x];
-        auto img = image->data + (span->y + image->y) * image->stride + (span->x + image->x);
+        auto img = image->data + (span->y + image->oy) * image->stride + (span->x + image->ox);
         if (span->coverage == 255) {
             for (uint32_t x = 0; x < span->len; ++x, ++dst, ++img) {
                 *dst = *img;
@@ -978,7 +978,7 @@ static bool _rasterDirectMaskedImage(SwSurface* surface, const SwImage* image, u
 
     TVGLOG("SW_ENGINE", "Direct Masked Image");
 
-    auto sbuffer = image->data + (region.min.y + image->y) * image->stride + (region.min.x + image->x);
+    auto sbuffer = image->data + (region.min.y + image->oy) * image->stride + (region.min.x + image->ox);
     auto cbuffer = surface->compositor->image.data + (region.min.y * surface->stride) + region.min.x;   //compositor buffer
 
     for (uint32_t y = 0; y < h2; ++y) {
@@ -1000,7 +1000,7 @@ static bool _rasterDirectMaskedImage(SwSurface* surface, const SwImage* image, u
 static bool __rasterDirectTranslucentImage(SwSurface* surface, const SwImage* image, uint32_t opacity, const SwBBox& region)
 {
     auto dbuffer = &surface->buffer[region.min.y * surface->stride + region.min.x];
-    auto sbuffer = image->data + (region.min.y + image->y) * image->stride + (region.min.x + image->x);
+    auto sbuffer = image->data + (region.min.y + image->oy) * image->stride + (region.min.x + image->ox);
 
     for (auto y = region.min.y; y < region.max.y; ++y) {
         auto dst = dbuffer;
@@ -1032,7 +1032,7 @@ static bool _rasterDirectTranslucentImage(SwSurface* surface, const SwImage* ima
 static bool _rasterDirectSolidImage(SwSurface* surface, const SwImage* image, const SwBBox& region)
 {
     auto dbuffer = &surface->buffer[region.min.y * surface->stride + region.min.x];
-    auto sbuffer = image->data + (region.min.y + image->y) * image->stride + (region.min.x + image->x);
+    auto sbuffer = image->data + (region.min.y + image->oy) * image->stride + (region.min.x + image->ox);
 
     for (auto y = region.min.y; y < region.max.y; ++y) {
         auto dst = dbuffer;
@@ -1592,21 +1592,21 @@ bool rasterImage(SwSurface* surface, SwImage* image, const Matrix* transform, co
 
     //Clipped Image
     if (image->rle) {
-        if (image->transformed) {
-            if (translucent) return _rasterTransformedTranslucentRleImage(surface, image, opacity, &itransform, halfScale);
-            else return _rasterTransformedSolidRleImage(surface, image, &itransform, halfScale);
-        } else {
+        if (image->direct) {
             if (translucent) return _rasterDirectTranslucentRleImage(surface, image, opacity);
             else return _rasterDirectSolidRleImage(surface, image);
+        } else {
+            if (translucent) return _rasterTransformedTranslucentRleImage(surface, image, opacity, &itransform, halfScale);
+            else return _rasterTransformedSolidRleImage(surface, image, &itransform, halfScale);
         }
     //Whole Image
     } else {
-        if (image->transformed) {
-            if (translucent) return _rasterTransformedTranslucentImage(surface, image, opacity, bbox, &itransform, halfScale);
-            else return _rasterTransformedSolidImage(surface, image, bbox, &itransform, halfScale);
-        } else {
+        if (image->direct) {
             if (translucent) return _rasterDirectTranslucentImage(surface, image, opacity, bbox);
             else return _rasterDirectSolidImage(surface, image, bbox);
+        } else {
+            if (translucent) return _rasterTransformedTranslucentImage(surface, image, opacity, bbox, &itransform, halfScale);
+            else return _rasterTransformedSolidImage(surface, image, bbox, &itransform, halfScale);
         }
     }
 }