mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
sw_engine: skip AA if texture are orthogonally rotated.
there is no necessary applying AA for 0/90/180/270 degree rotation issue: https://github.com/thorvg/thorvg/issues/3452
This commit is contained in:
parent
ae97f5f20f
commit
8eb046c318
2 changed files with 21 additions and 24 deletions
|
@ -90,7 +90,7 @@ bool operator==(const Matrix& lhs, const Matrix& rhs);
|
||||||
static inline bool rightAngle(const Matrix& m)
|
static inline bool rightAngle(const Matrix& m)
|
||||||
{
|
{
|
||||||
auto radian = fabsf(tvg::atan2(m.e21, m.e11));
|
auto radian = fabsf(tvg::atan2(m.e21, m.e11));
|
||||||
if (radian < FLOAT_EPSILON || tvg::equal(radian, MATH_PI2) || tvg::equal(radian, MATH_PI)) return true;
|
if (tvg::zero(radian) || tvg::zero(radian - MATH_PI2) || tvg::zero(radian - MATH_PI)) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -131,9 +131,11 @@ static void _rasterBlendingPolygonImageSegment(SwSurface* surface, const SwImage
|
||||||
if (x2 > maxx) x2 = maxx;
|
if (x2 > maxx) x2 = maxx;
|
||||||
|
|
||||||
//Anti-Aliasing frames
|
//Anti-Aliasing frames
|
||||||
ay = y - aaSpans->yStart;
|
if (aaSpans) {
|
||||||
if (aaSpans->lines[ay].x[0] > x1) aaSpans->lines[ay].x[0] = x1;
|
ay = y - aaSpans->yStart;
|
||||||
if (aaSpans->lines[ay].x[1] < x2) aaSpans->lines[ay].x[1] = x2;
|
if (aaSpans->lines[ay].x[0] > x1) aaSpans->lines[ay].x[0] = x1;
|
||||||
|
if (aaSpans->lines[ay].x[1] < x2) aaSpans->lines[ay].x[1] = x2;
|
||||||
|
}
|
||||||
|
|
||||||
//Range allowed
|
//Range allowed
|
||||||
if ((x2 - x1) >= 1 && (x1 < maxx) && (x2 > minx)) {
|
if ((x2 - x1) >= 1 && (x1 < maxx) && (x2 > minx)) {
|
||||||
|
@ -264,20 +266,19 @@ static void _rasterPolygonImageSegment(SwSurface* surface, const SwImage* image,
|
||||||
if (x2 > maxx) x2 = maxx;
|
if (x2 > maxx) x2 = maxx;
|
||||||
|
|
||||||
//Anti-Aliasing frames
|
//Anti-Aliasing frames
|
||||||
ay = y - aaSpans->yStart;
|
if (aaSpans) {
|
||||||
if (aaSpans->lines[ay].x[0] > x1) aaSpans->lines[ay].x[0] = x1;
|
ay = y - aaSpans->yStart;
|
||||||
if (aaSpans->lines[ay].x[1] < x2) aaSpans->lines[ay].x[1] = x2;
|
if (aaSpans->lines[ay].x[0] > x1) aaSpans->lines[ay].x[0] = x1;
|
||||||
|
if (aaSpans->lines[ay].x[1] < x2) aaSpans->lines[ay].x[1] = x2;
|
||||||
|
}
|
||||||
|
|
||||||
//Range allowed
|
//Range allowed
|
||||||
if ((x2 - x1) >= 1 && (x1 < maxx) && (x2 > minx)) {
|
if ((x2 - x1) >= 1 && (x1 < maxx) && (x2 > minx)) {
|
||||||
|
|
||||||
//Perform subtexel pre-stepping on UV
|
//Perform subtexel pre-stepping on UV
|
||||||
dx = 1 - (_xa - x1);
|
dx = 1 - (_xa - x1);
|
||||||
u = _ua + dx * _dudx;
|
u = _ua + dx * _dudx;
|
||||||
v = _va + dx * _dvdx;
|
v = _va + dx * _dvdx;
|
||||||
|
|
||||||
buf = dbuf + ((y * surface->stride) + x1);
|
buf = dbuf + ((y * surface->stride) + x1);
|
||||||
|
|
||||||
x = x1;
|
x = x1;
|
||||||
|
|
||||||
if (matting) cmp = &surface->compositor->image.buf8[(y * surface->compositor->image.stride + x1) * csize];
|
if (matting) cmp = &surface->compositor->image.buf8[(y * surface->compositor->image.stride + x1) * csize];
|
||||||
|
@ -576,13 +577,8 @@ static void _rasterPolygonImage(SwSurface* surface, const SwImage* image, const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static AASpans* _AASpans(float ymin, float ymax, const SwImage* image, const RenderRegion* bbox)
|
static AASpans* _AASpans(int yStart, int yEnd)
|
||||||
{
|
{
|
||||||
auto yStart = static_cast<int>(ymin);
|
|
||||||
auto yEnd = static_cast<int>(ymax);
|
|
||||||
|
|
||||||
if (!_arrange(image, bbox, yStart, yEnd)) return nullptr;
|
|
||||||
|
|
||||||
auto aaSpans = tvg::malloc<AASpans*>(sizeof(AASpans));
|
auto aaSpans = tvg::malloc<AASpans*>(sizeof(AASpans));
|
||||||
aaSpans->yStart = yStart;
|
aaSpans->yStart = yStart;
|
||||||
aaSpans->yEnd = yEnd;
|
aaSpans->yEnd = yEnd;
|
||||||
|
@ -791,7 +787,7 @@ static void _calcAAEdge(AASpans *aaSpans, int32_t eidx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool _apply(SwSurface* surface, AASpans* aaSpans)
|
static void _apply(SwSurface* surface, AASpans* aaSpans)
|
||||||
{
|
{
|
||||||
auto end = surface->buf32 + surface->h * surface->stride;
|
auto end = surface->buf32 + surface->h * surface->stride;
|
||||||
auto y = aaSpans->yStart;
|
auto y = aaSpans->yStart;
|
||||||
|
@ -848,8 +844,6 @@ static bool _apply(SwSurface* surface, AASpans* aaSpans)
|
||||||
|
|
||||||
tvg::free(aaSpans->lines);
|
tvg::free(aaSpans->lines);
|
||||||
tvg::free(aaSpans);
|
tvg::free(aaSpans);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -873,8 +867,7 @@ static bool _rasterTexmapPolygon(SwSurface* surface, const SwImage* image, const
|
||||||
//Exceptions: No dedicated drawing area?
|
//Exceptions: No dedicated drawing area?
|
||||||
if ((!image->rle && !bbox) || (image->rle && image->rle->size() == 0)) return true;
|
if ((!image->rle && !bbox) || (image->rle && image->rle->size() == 0)) return true;
|
||||||
|
|
||||||
/* Prepare vertices.
|
//Prepare vertices. Shift XY coordinates to match the sub-pixeling technique.
|
||||||
shift XY coordinates to match the sub-pixeling technique. */
|
|
||||||
Vertex vertices[4];
|
Vertex vertices[4];
|
||||||
vertices[0] = {{0.0f, 0.0f}, {0.0f, 0.0f}};
|
vertices[0] = {{0.0f, 0.0f}, {0.0f, 0.0f}};
|
||||||
vertices[1] = {{float(image->w), 0.0f}, {float(image->w), 0.0f}};
|
vertices[1] = {{float(image->w), 0.0f}, {float(image->w), 0.0f}};
|
||||||
|
@ -888,8 +881,11 @@ static bool _rasterTexmapPolygon(SwSurface* surface, const SwImage* image, const
|
||||||
if (vertices[i].pt.y > ye) ye = vertices[i].pt.y;
|
if (vertices[i].pt.y > ye) ye = vertices[i].pt.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto aaSpans = _AASpans(ys, ye, image, bbox);
|
auto yStart = static_cast<int>(ys);
|
||||||
if (!aaSpans) return true;
|
auto yEnd = static_cast<int>(ye);
|
||||||
|
|
||||||
|
if (!_arrange(image, bbox, yStart, yEnd)) return true;
|
||||||
|
auto aaSpans = rightAngle(transform) ? nullptr : _AASpans(yStart, yEnd);
|
||||||
|
|
||||||
Polygon polygon;
|
Polygon polygon;
|
||||||
|
|
||||||
|
@ -912,5 +908,6 @@ static bool _rasterTexmapPolygon(SwSurface* surface, const SwImage* image, const
|
||||||
_compositeMaskImage(surface, &surface->compositor->image, surface->compositor->bbox);
|
_compositeMaskImage(surface, &surface->compositor->image, surface->compositor->bbox);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return _apply(surface, aaSpans);
|
if (aaSpans) _apply(surface, aaSpans);
|
||||||
|
return true;
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue