Skip to content

Commit

Permalink
Merge pull request #94258 from capnm/240712_tvg_v0.14.2
Browse files Browse the repository at this point in the history
ThorVG: Update to 0.14.2
  • Loading branch information
akien-mga committed Jul 17, 2024
2 parents ab67408 + bf44454 commit 13dffe2
Show file tree
Hide file tree
Showing 20 changed files with 164 additions and 135 deletions.
2 changes: 1 addition & 1 deletion thirdparty/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ instead of `miniz.h` as an external dependency.
## thorvg

- Upstream: https://github.com/thorvg/thorvg
- Version: 0.14.1 (70b2f2dad158316dd08166d613b425248b36fd27, 2024)
- Version: 0.14.2 (f6c4d8a94e0b2194fe911d6e19a550683055dd50, 2024)
- License: MIT

Files extracted from upstream source:
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/thorvg/inc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
// For internal debugging:
//#define THORVG_LOG_ENABLED

#define THORVG_VERSION_STRING "0.14.1"
#define THORVG_VERSION_STRING "0.14.2"
#endif
9 changes: 9 additions & 0 deletions thirdparty/thorvg/inc/thorvg.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,19 @@ class TVG_API Paint
* The rotational axis passes through the point on the object with zero coordinates.
*
* @param[in] degree The value of the angle in degrees.
*
* @retval Result::InsufficientCondition in case a custom transform is applied.
* @see Paint::transform()
*/
Result rotate(float degree) noexcept;

/**
* @brief Sets the scale value of the object.
*
* @param[in] factor The value of the scaling factor. The default value is 1.
*
* @retval Result::InsufficientCondition in case a custom transform is applied.
* @see Paint::transform()
*/
Result scale(float factor) noexcept;

Expand All @@ -299,6 +305,9 @@ class TVG_API Paint
*
* @param[in] x The value of the horizontal shift.
* @param[in] y The value of the vertical shift.
*
* @retval Result::InsufficientCondition in case a custom transform is applied.
* @see Paint::transform()
*/
Result translate(float x, float y) noexcept;

Expand Down
2 changes: 1 addition & 1 deletion thirdparty/thorvg/src/common/tvgLines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ float bezAngleAt(const Bezier& bz, float t)
pt.x *= 3;
pt.y *= 3;

return mathRad2Deg(atan2(pt.x, pt.y));
return mathRad2Deg(mathAtan2(pt.y, pt.x));
}


Expand Down
11 changes: 8 additions & 3 deletions thirdparty/thorvg/src/common/tvgLock.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#define _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR

#include <mutex>
#include "tvgTaskScheduler.h"

namespace tvg {

Expand All @@ -42,13 +43,17 @@ namespace tvg {

ScopedLock(Key& k)
{
k.mtx.lock();
key = &k;
if (TaskScheduler::threads() > 0) {
k.mtx.lock();
key = &k;
}
}

~ScopedLock()
{
key->mtx.unlock();
if (TaskScheduler::threads() > 0) {
key->mtx.unlock();
}
}
};

Expand Down
14 changes: 14 additions & 0 deletions thirdparty/thorvg/src/common/tvgMath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@

#include "tvgMath.h"

//see: https://en.wikipedia.org/wiki/Remez_algorithm
float mathAtan2(float y, float x)
{
if (y == 0.0f && x == 0.0f) return 0.0f;

auto a = std::min(fabsf(x), fabsf(y)) / std::max(fabsf(x), fabsf(y));
auto s = a * a;
auto r = ((-0.0464964749f * s + 0.15931422f) * s - 0.327622764f) * s * a + a;
if (fabsf(y) > fabsf(x)) r = 1.57079637f - r;
if (x < 0) r = 3.14159274f - r;
if (y < 0) return -r;
return r;
}


bool mathInverse(const Matrix* m, Matrix* out)
{
Expand Down
3 changes: 2 additions & 1 deletion thirdparty/thorvg/src/common/tvgMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
/* General functions */
/************************************************************************/

float mathAtan2(float y, float x);

static inline float mathDeg2Rad(float degree)
{
Expand Down Expand Up @@ -79,7 +80,7 @@ bool operator==(const Matrix& lhs, const Matrix& rhs);

static inline bool mathRightAngle(const Matrix* m)
{
auto radian = fabsf(atan2f(m->e21, m->e11));
auto radian = fabsf(mathAtan2(m->e21, m->e11));
if (radian < FLOAT_EPSILON || mathEqual(radian, MATH_PI2) || mathEqual(radian, MATH_PI)) return true;
return false;
}
Expand Down
29 changes: 22 additions & 7 deletions thirdparty/thorvg/src/loaders/svg/tvgSvgLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,9 +647,9 @@ static bool _hslToRgb(float hue, float saturation, float brightness, uint8_t* re
}
}

*red = static_cast<uint8_t>(ceil(_red * 255.0f));
*green = static_cast<uint8_t>(ceil(_green * 255.0f));
*blue = static_cast<uint8_t>(ceil(_blue * 255.0f));
*red = (uint8_t)nearbyint(_red * 255.0f);
*green = (uint8_t)nearbyint(_green * 255.0f);
*blue = (uint8_t)nearbyint(_blue * 255.0f);

return true;
}
Expand Down Expand Up @@ -3254,19 +3254,34 @@ static void _clonePostponedNodes(Array<SvgNodeIdPair>* cloneNodes, SvgNode* doc)
}


static void _svgLoaderParserXmlClose(SvgLoaderData* loader, const char* content)
static void _svgLoaderParserXmlClose(SvgLoaderData* loader, const char* content, unsigned int length)
{
const char* itr = nullptr;
int sz = length;
char tagName[20] = "";

content = _skipSpace(content, nullptr);
itr = content;
while ((itr != nullptr) && *itr != '>') itr++;

if (itr) {
sz = itr - content;
while ((sz > 0) && (isspace(content[sz - 1]))) sz--;
if ((unsigned int)sz >= sizeof(tagName)) sz = sizeof(tagName) - 1;
strncpy(tagName, content, sz);
tagName[sz] = '\0';
}
else return;

for (unsigned int i = 0; i < sizeof(groupTags) / sizeof(groupTags[0]); i++) {
if (!strncmp(content, groupTags[i].tag, groupTags[i].sz - 1)) {
if (!strncmp(tagName, groupTags[i].tag, sz)) {
loader->stack.pop();
break;
}
}

for (unsigned int i = 0; i < sizeof(graphicsTags) / sizeof(graphicsTags[0]); i++) {
if (!strncmp(content, graphicsTags[i].tag, graphicsTags[i].sz - 1)) {
if (!strncmp(tagName, graphicsTags[i].tag, sz)) {
loader->currentGraphicsNode = nullptr;
loader->stack.pop();
break;
Expand Down Expand Up @@ -3437,7 +3452,7 @@ static bool _svgLoaderParser(void* data, SimpleXMLType type, const char* content
break;
}
case SimpleXMLType::Close: {
_svgLoaderParserXmlClose(loader, content);
_svgLoaderParserXmlClose(loader, content, length);
break;
}
case SimpleXMLType::Data:
Expand Down
4 changes: 2 additions & 2 deletions thirdparty/thorvg/src/loaders/svg/tvgSvgPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ void _pathAppendArcTo(Array<PathCommand>* cmds, Array<Point>* pts, Point* cur, P
//We dont' use arccos (as per w3c doc), see
//http://www.euclideanspace.com/maths/algebra/vectors/angleBetween/index.htm
//Note: atan2 (0.0, 1.0) == 0.0
at = atan2(((y1p - cyp) / ry), ((x1p - cxp) / rx));
at = mathAtan2(((y1p - cyp) / ry), ((x1p - cxp) / rx));
theta1 = (at < 0.0f) ? 2.0f * MATH_PI + at : at;

nat = atan2(((-y1p - cyp) / ry), ((-x1p - cxp) / rx));
nat = mathAtan2(((-y1p - cyp) / ry), ((-x1p - cxp) / rx));
deltaTheta = (nat < at) ? 2.0f * MATH_PI - at + nat : nat - at;

if (sweep) {
Expand Down
4 changes: 2 additions & 2 deletions thirdparty/thorvg/src/renderer/sw_engine/tvgSwImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ bool imagePrepare(SwImage* image, const RenderMesh* mesh, const Matrix* transfor

//Fast track: Non-transformed image but just shifted.
if (image->direct) {
image->ox = -static_cast<int32_t>(round(transform->e13));
image->oy = -static_cast<int32_t>(round(transform->e23));
image->ox = -static_cast<int32_t>(nearbyint(transform->e13));
image->oy = -static_cast<int32_t>(nearbyint(transform->e23));
//Figure out the scale factor by transform matrix
} else {
auto scaleX = sqrtf((transform->e11 * transform->e11) + (transform->e21 * transform->e21));
Expand Down
14 changes: 7 additions & 7 deletions thirdparty/thorvg/src/renderer/sw_engine/tvgSwMath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ void mathRotate(SwPoint& pt, SwFixed angle)
auto cosv = cosf(radian);
auto sinv = sinf(radian);

pt.x = SwCoord(roundf((v.x * cosv - v.y * sinv) * 64.0f));
pt.y = SwCoord(roundf((v.x * sinv + v.y * cosv) * 64.0f));
pt.x = SwCoord(nearbyint((v.x * cosv - v.y * sinv) * 64.0f));
pt.y = SwCoord(nearbyint((v.x * sinv + v.y * cosv) * 64.0f));
}


Expand All @@ -179,7 +179,7 @@ SwFixed mathTan(SwFixed angle)
SwFixed mathAtan(const SwPoint& pt)
{
if (pt.zero()) return 0;
return SwFixed(atan2f(TO_FLOAT(pt.y), TO_FLOAT(pt.x)) * (180.0f / MATH_PI) * 65536.0f);
return SwFixed(mathAtan2(TO_FLOAT(pt.y), TO_FLOAT(pt.x)) * (180.0f / MATH_PI) * 65536.0f);
}


Expand Down Expand Up @@ -309,10 +309,10 @@ bool mathUpdateOutlineBBox(const SwOutline* outline, const SwBBox& clipRegion, S
//the rasterization region has to be rearranged.
//https://github.com/Samsung/thorvg/issues/916
if (fastTrack) {
renderRegion.min.x = static_cast<SwCoord>(round(xMin / 64.0f));
renderRegion.max.x = static_cast<SwCoord>(round(xMax / 64.0f));
renderRegion.min.y = static_cast<SwCoord>(round(yMin / 64.0f));
renderRegion.max.y = static_cast<SwCoord>(round(yMax / 64.0f));
renderRegion.min.x = static_cast<SwCoord>(nearbyint(xMin / 64.0f));
renderRegion.max.x = static_cast<SwCoord>(nearbyint(xMax / 64.0f));
renderRegion.min.y = static_cast<SwCoord>(nearbyint(yMin / 64.0f));
renderRegion.max.y = static_cast<SwCoord>(nearbyint(yMax / 64.0f));
} else {
renderRegion.min.x = xMin >> 6;
renderRegion.max.x = (xMax + 63) >> 6;
Expand Down
5 changes: 3 additions & 2 deletions thirdparty/thorvg/src/renderer/sw_engine/tvgSwRaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ static bool _rasterMattedRect(SwSurface* surface, const SwBBox& region, uint8_t
auto dst = &buffer[y * surface->stride];
auto cmp = &cbuffer[y * surface->compositor->image.stride * csize];
for (uint32_t x = 0; x < w; ++x, ++dst, cmp += csize) {
*dst = INTERPOLATE(color, *dst, alpha(cmp));
auto tmp = ALPHA_BLEND(color, alpha(cmp));
*dst = tmp + ALPHA_BLEND(*dst, IA(tmp));
}
}
//8bits grayscale
Expand Down Expand Up @@ -674,7 +675,7 @@ static bool _rasterRle(SwSurface* surface, SwRleData* rle, uint8_t r, uint8_t g,
auto sy = (y) * itransform->e22 + itransform->e23 - 0.49f; \
if (sy <= -0.5f || (uint32_t)(sy + 0.5f) >= image->h) continue; \
if (scaleMethod == _interpDownScaler) { \
auto my = (int32_t)round(sy); \
auto my = (int32_t)nearbyint(sy); \
miny = my - (int32_t)sampleSize; \
if (miny < 0) miny = 0; \
maxy = my + (int32_t)sampleSize; \
Expand Down
Loading

0 comments on commit 13dffe2

Please sign in to comment.