mirror of
https://github.com/thorvg/thorvg.git
synced 2025-07-23 22:58:44 +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
62a9e51016
commit
eae473b31a
2 changed files with 21 additions and 21 deletions
|
@ -88,7 +88,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,9 +133,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)) {
|
||||||
|
@ -310,9 +312,11 @@ 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)) {
|
||||||
|
@ -622,13 +626,8 @@ static void _rasterPolygonImage(SwSurface* surface, const SwImage* image, const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static AASpans* _AASpans(float ymin, float ymax, const SwImage* image, const SwBBox* region)
|
static AASpans* _AASpans(int yStart, int yEnd)
|
||||||
{
|
{
|
||||||
auto yStart = static_cast<int>(ymin);
|
|
||||||
auto yEnd = static_cast<int>(ymax);
|
|
||||||
|
|
||||||
if (!_arrange(image, region, yStart, yEnd)) return nullptr;
|
|
||||||
|
|
||||||
auto aaSpans = static_cast<AASpans*>(malloc(sizeof(AASpans)));
|
auto aaSpans = static_cast<AASpans*>(malloc(sizeof(AASpans)));
|
||||||
aaSpans->yStart = yStart;
|
aaSpans->yStart = yStart;
|
||||||
aaSpans->yEnd = yEnd;
|
aaSpans->yEnd = yEnd;
|
||||||
|
@ -837,7 +836,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;
|
||||||
|
@ -894,8 +893,6 @@ static bool _apply(SwSurface* surface, AASpans* aaSpans)
|
||||||
|
|
||||||
free(aaSpans->lines);
|
free(aaSpans->lines);
|
||||||
free(aaSpans);
|
free(aaSpans);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -919,8 +916,7 @@ static bool _rasterTexmapPolygon(SwSurface* surface, const SwImage* image, const
|
||||||
//Exceptions: No dedicated drawing area?
|
//Exceptions: No dedicated drawing area?
|
||||||
if ((!image->rle && !region) || (image->rle && image->rle->size == 0)) return true;
|
if ((!image->rle && !region) || (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}};
|
||||||
|
@ -934,8 +930,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, region);
|
auto yStart = static_cast<int>(ys);
|
||||||
if (!aaSpans) return true;
|
auto yEnd = static_cast<int>(ye);
|
||||||
|
|
||||||
|
if (!_arrange(image, region, yStart, yEnd)) return true;
|
||||||
|
auto aaSpans = rightAngle(transform) ? nullptr : _AASpans(yStart, yEnd);
|
||||||
|
|
||||||
Polygon polygon;
|
Polygon polygon;
|
||||||
|
|
||||||
|
@ -958,5 +957,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