sw_engine: code refactoring

unified the two color interpolate methods.
This commit is contained in:
Hermet Park 2021-11-25 17:25:25 +09:00 committed by Hermet Park
parent 2ca6f76d91
commit eddaf615c3
4 changed files with 9 additions and 20 deletions

View file

@ -274,11 +274,9 @@ static inline uint32_t ALPHA_BLEND(uint32_t c, uint32_t a)
((((c & 0x00ff00ff) * a + 0x00ff00ff) >> 8) & 0x00ff00ff)); ((((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; return (((((((c0 >> 8) & 0xff00ff) - ((c1 >> 8) & 0xff00ff)) * a) + (c1 & 0xff00ff00)) & 0xff00ff00) + ((((((c0 & 0xff00ff) - (c1 & 0xff00ff)) * a) >> 8) + (c1 & 0xff00ff)) & 0xff00ff));
c1 = (((c1 >> 8) & 0xff00ff) * a1 + ((c2 >> 8) & 0xff00ff) * a2) & 0xff00ff00;
return (c1 |= t);
} }
static inline SwCoord HALF_STROKE(float width) static inline SwCoord HALF_STROKE(float width)

View file

@ -79,7 +79,7 @@ static bool _updateColorTable(SwFill* fill, const Fill* fdata, const SwSurface*
auto dist = static_cast<int32_t>(255 * t); auto dist = static_cast<int32_t>(255 * t);
auto dist2 = 255 - dist; 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)); fill->ctable[i] = ALPHA_BLEND((color | 0xff000000), (color >> 24));
++i; ++i;

View 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 "tvgSwRasterTexmap.h"
#include "tvgSwRasterC.h" #include "tvgSwRasterC.h"
#include "tvgSwRasterAvx.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 c3 = img[(rx + 1) + ((ry + 1) * w)];
auto c4 = img[rx + ((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); fillFetchLinear(fill, surface->buffer + span->y * surface->stride + span->x, span->y, span->x, span->len);
} else { } else {
fillFetchLinear(fill, buf, span->y, span->x, span->len); fillFetchLinear(fill, buf, span->y, span->x, span->len);
auto ialpha = 255 - span->coverage;
auto dst = &surface->buffer[span->y * surface->stride + span->x]; auto dst = &surface->buffer[span->y * surface->stride + span->x];
for (uint32_t i = 0; i < span->len; ++i) { 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)); *dst = tmp + ALPHA_BLEND(*dst, surface->blender.ialpha(tmp));
} }
} else { } else {
auto ialpha = 255 - span->coverage;
for (uint32_t x = 0; x < span->len; ++x, ++dst, ++cmp, ++src) { for (uint32_t x = 0; x < span->len; ++x, ++dst, ++cmp, ++src) {
auto tmp = ALPHA_BLEND(*src, blendMethod(*cmp)); auto tmp = INTERPOLATE(span->coverage, ALPHA_BLEND(*src, blendMethod(*cmp)), *dst);
tmp = ALPHA_BLEND(tmp, span->coverage) + ALPHA_BLEND(*dst, ialpha);
*dst = tmp + ALPHA_BLEND(*dst, surface->blender.ialpha(tmp)); *dst = tmp + ALPHA_BLEND(*dst, surface->blender.ialpha(tmp));
} }
} }

View file

@ -114,7 +114,7 @@ static inline void _rasterRGBA(SwSurface* surface, const SwImage* image, const S
if (iru < sw) { if (iru < sw) {
/* right pixel */ /* right pixel */
int px2 = *(sbuf + (vv * sw) + iru); int px2 = *(sbuf + (vv * sw) + iru);
px = _interpolate(ar, px, px2); px = INTERPOLATE(ar, px, px2);
} }
/* vertical interpolate */ /* vertical interpolate */
if (irv < sh) { if (irv < sh) {
@ -125,9 +125,9 @@ static inline void _rasterRGBA(SwSurface* surface, const SwImage* image, const S
if (iru < sw) { if (iru < sw) {
/* bottom right pixel */ /* bottom right pixel */
int px3 = *(sbuf + (irv * sw) + iru); 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) #if defined(TEXMAP_MAKSING) && defined(TEXTMAP_TRANSLUCENT)
auto src = ALPHA_BLEND(px, _multiplyAlpha(opacity, blendMethod(*cmp))); auto src = ALPHA_BLEND(px, _multiplyAlpha(opacity, blendMethod(*cmp)));