mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +00:00
sw_engine/texmap: tuning the blending logic
Compromed the translucent/opaque logic by unifying them, for code size and maintenance.
This commit is contained in:
parent
abdb96b8a0
commit
ef41f3f79c
1 changed files with 30 additions and 74 deletions
|
@ -147,7 +147,6 @@ static void _rasterBlendingPolygonImageSegment(SwSurface* surface, const SwImage
|
||||||
|
|
||||||
x = x1;
|
x = x1;
|
||||||
|
|
||||||
if (opacity == 255) {
|
|
||||||
//Draw horizontal line
|
//Draw horizontal line
|
||||||
while (x++ < x2) {
|
while (x++ < x2) {
|
||||||
uu = (int) u;
|
uu = (int) u;
|
||||||
|
@ -172,7 +171,6 @@ static void _rasterBlendingPolygonImageSegment(SwSurface* surface, const SwImage
|
||||||
if (irv < sh) {
|
if (irv < sh) {
|
||||||
/* bottom pixel */
|
/* bottom pixel */
|
||||||
int px2 = *(sbuf + (irv * image->stride) + uu);
|
int px2 = *(sbuf + (irv * image->stride) + uu);
|
||||||
|
|
||||||
/* horizontal interpolate */
|
/* horizontal interpolate */
|
||||||
if (iru < sw) {
|
if (iru < sw) {
|
||||||
/* bottom right pixel */
|
/* bottom right pixel */
|
||||||
|
@ -181,56 +179,14 @@ static void _rasterBlendingPolygonImageSegment(SwSurface* surface, const SwImage
|
||||||
}
|
}
|
||||||
px = INTERPOLATE(px, px2, ab);
|
px = INTERPOLATE(px, px2, ab);
|
||||||
}
|
}
|
||||||
*buf = surface->blender(px, *buf, IA(px));
|
auto tmp = surface->blender(px, *buf, 255);
|
||||||
|
*buf = INTERPOLATE(tmp, *buf, MULTIPLY(opacity, A(px)));
|
||||||
++buf;
|
++buf;
|
||||||
|
|
||||||
//Step UV horizontally
|
//Step UV horizontally
|
||||||
u += _dudx;
|
u += _dudx;
|
||||||
v += _dvdx;
|
v += _dvdx;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
//Draw horizontal line
|
|
||||||
while (x++ < x2) {
|
|
||||||
uu = (int) u;
|
|
||||||
vv = (int) v;
|
|
||||||
|
|
||||||
if ((uint32_t) uu >= image->w || (uint32_t) vv >= image->h) continue;
|
|
||||||
|
|
||||||
ar = (int)(255 * (1 - modff(u, &iptr)));
|
|
||||||
ab = (int)(255 * (1 - modff(v, &iptr)));
|
|
||||||
iru = uu + 1;
|
|
||||||
irv = vv + 1;
|
|
||||||
|
|
||||||
px = *(sbuf + (vv * image->stride) + uu);
|
|
||||||
|
|
||||||
/* horizontal interpolate */
|
|
||||||
if (iru < sw) {
|
|
||||||
/* right pixel */
|
|
||||||
int px2 = *(sbuf + (vv * image->stride) + iru);
|
|
||||||
px = INTERPOLATE(px, px2, ar);
|
|
||||||
}
|
|
||||||
/* vertical interpolate */
|
|
||||||
if (irv < sh) {
|
|
||||||
/* bottom pixel */
|
|
||||||
int px2 = *(sbuf + (irv * image->stride) + uu);
|
|
||||||
|
|
||||||
/* horizontal interpolate */
|
|
||||||
if (iru < sw) {
|
|
||||||
/* bottom right pixel */
|
|
||||||
int px3 = *(sbuf + (irv * image->stride) + iru);
|
|
||||||
px2 = INTERPOLATE(px2, px3, ar);
|
|
||||||
}
|
|
||||||
px = INTERPOLATE(px, px2, ab);
|
|
||||||
}
|
|
||||||
auto src = ALPHA_BLEND(px, opacity);
|
|
||||||
*buf = surface->blender(src, *buf, IA(src));
|
|
||||||
++buf;
|
|
||||||
|
|
||||||
//Step UV horizontally
|
|
||||||
u += _dudx;
|
|
||||||
v += _dvdx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Step along both edges
|
//Step along both edges
|
||||||
|
|
Loading…
Add table
Reference in a new issue