sw_engine: code refactoring
authorHermet Park <chuneon.park@samsung.com>
Thu, 25 Nov 2021 08:25:25 +0000 (17:25 +0900)
committerHermet Park <chuneon.park@samsung.com>
Tue, 30 Nov 2021 03:47:23 +0000 (12:47 +0900)
unified the two color interpolate methods.

Change-Id: I7ff67af280fa78b11d3b083aec790ac043387b1a

src/lib/sw_engine/tvgSwCommon.h
src/lib/sw_engine/tvgSwFill.cpp
src/lib/sw_engine/tvgSwRaster.cpp
src/lib/sw_engine/tvgSwRasterTexmap.h

index ce69e37..87577f9 100644 (file)
@@ -274,11 +274,9 @@ static inline uint32_t ALPHA_BLEND(uint32_t c, uint32_t a)
             ((((c & 0x00ff00ff) * a + 0x00ff00ff) >> 8) & 0x00ff00ff));
 }
 
-static inline uint32_t COLOR_INTERPOLATE(uint32_t c1, uint32_t a1, uint32_t c2, uint32_t a2)
+static inline uint32_t INTERPOLATE(uint32_t a, uint32_t c0, uint32_t c1)
 {
-    auto t = (((c1 & 0xff00ff) * a1 + (c2 & 0xff00ff) * a2) >> 8) & 0xff00ff;
-    c1 = (((c1 >> 8) & 0xff00ff) * a1 + ((c2 >> 8) & 0xff00ff) * a2) & 0xff00ff00;
-    return (c1 |= t);
+    return (((((((c0 >> 8) & 0xff00ff) - ((c1 >> 8) & 0xff00ff)) * a) + (c1 & 0xff00ff00)) & 0xff00ff00) + ((((((c0 & 0xff00ff) - (c1 & 0xff00ff)) * a) >> 8) + (c1 & 0xff00ff)) & 0xff00ff));
 }
 
 static inline SwCoord HALF_STROKE(float width)
index 8afc2c0..0bf051c 100644 (file)
@@ -79,7 +79,7 @@ static bool _updateColorTable(SwFill* fill, const Fill* fdata, const SwSurface*
             auto dist = static_cast<int32_t>(255 * t);
             auto dist2 = 255 - dist;
 
-            auto color = COLOR_INTERPOLATE(rgba, dist2, rgba2, dist);
+            auto color = INTERPOLATE(dist2, rgba, rgba2);
             fill->ctable[i] = ALPHA_BLEND((color | 0xff000000), (color >> 24));
 
             ++i;
index 57adb7c..e531872 100644 (file)
@@ -59,12 +59,6 @@ static inline uint32_t _argbJoin(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
 }
 
 
-static inline uint32_t _interpolate(uint32_t a, uint32_t c0, uint32_t c1)
-{
-    return (((((((c0 >> 8) & 0xff00ff) - ((c1 >> 8) & 0xff00ff)) * a) + (c1 & 0xff00ff00)) & 0xff00ff00) + ((((((c0 & 0xff00ff) - (c1 & 0xff00ff)) * a) >> 8) + (c1 & 0xff00ff)) & 0xff00ff));
-}
-
-
 #include "tvgSwRasterTexmap.h"
 #include "tvgSwRasterC.h"
 #include "tvgSwRasterAvx.h"
@@ -99,7 +93,7 @@ static uint32_t _interpUpScaler(const uint32_t *img, uint32_t w, uint32_t h, flo
     auto c3 = img[(rx + 1) + ((ry + 1) * w)];
     auto c4 = img[rx + ((ry + 1) * w)];
 
-    return COLOR_INTERPOLATE(COLOR_INTERPOLATE(c1, 255 - dx, c2, dx), 255 - dy, COLOR_INTERPOLATE(c4, 255 - dx, c3, dx), dy);
+    return INTERPOLATE(dy, INTERPOLATE(dx, c3, c4), INTERPOLATE(dx, c2, c1));
 }
 
 
@@ -1659,10 +1653,9 @@ static bool _rasterSolidLinearGradientRle(SwSurface* surface, const SwRleData* r
             fillFetchLinear(fill, surface->buffer + span->y * surface->stride + span->x, span->y, span->x, span->len);
         } else {
             fillFetchLinear(fill, buf, span->y, span->x, span->len);
-            auto ialpha = 255 - span->coverage;
             auto dst = &surface->buffer[span->y * surface->stride + span->x];
             for (uint32_t i = 0; i < span->len; ++i) {
-                dst[i] = ALPHA_BLEND(buf[i], span->coverage) + ALPHA_BLEND(dst[i], ialpha);
+                dst[i] = INTERPOLATE(span->coverage, buf[i], dst[i]);
             }
         }
     }
@@ -1799,10 +1792,8 @@ static bool _rasterRadialGradientMaskedRle(SwSurface* surface, const SwRleData*
                 *dst = tmp + ALPHA_BLEND(*dst, surface->blender.ialpha(tmp));
             }
         } else {
-            auto ialpha = 255 - span->coverage;
             for (uint32_t x = 0; x < span->len; ++x, ++dst, ++cmp, ++src) {
-                auto tmp = ALPHA_BLEND(*src, blendMethod(*cmp));
-                tmp = ALPHA_BLEND(tmp, span->coverage) + ALPHA_BLEND(*dst, ialpha);
+                auto tmp = INTERPOLATE(span->coverage, ALPHA_BLEND(*src, blendMethod(*cmp)), *dst);
                 *dst = tmp + ALPHA_BLEND(*dst, surface->blender.ialpha(tmp));
             }
         }
index 3f9b777..c4ee7ce 100644 (file)
@@ -114,7 +114,7 @@ static inline void _rasterRGBA(SwSurface* surface, const SwImage* image, const S
             if (iru < sw) {
                 /* right pixel */
                 int px2 = *(sbuf + (vv * sw) + iru);
-                px = _interpolate(ar, px, px2);
+                px = INTERPOLATE(ar, px, px2);
             }
             /* vertical interpolate */
             if (irv < sh) {
@@ -125,9 +125,9 @@ static inline void _rasterRGBA(SwSurface* surface, const SwImage* image, const S
                 if (iru < sw) {
                     /* bottom right pixel */
                     int px3 = *(sbuf + (irv * sw) + iru);
-                    px2 = _interpolate(ar, px2, px3);
+                    px2 = INTERPOLATE(ar, px2, px3);
                 }
-                px = _interpolate(ab, px, px2);
+                px = INTERPOLATE(ab, px, px2);
             }
 #if defined(TEXMAP_MAKSING) && defined(TEXTMAP_TRANSLUCENT)
             auto src = ALPHA_BLEND(px, _multiplyAlpha(opacity, blendMethod(*cmp)));