Skip to content

Commit

Permalink
ThorVG: Update to 0.13.7
Browse files Browse the repository at this point in the history
  • Loading branch information
capnm committed Jun 8, 2024
1 parent 5833f59 commit 18650de
Show file tree
Hide file tree
Showing 21 changed files with 350 additions and 243 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.13.3 (6235068cad8cad176ccd0cbcf82f25e985fbc258, 2024)
- Version: 0.13.7 (d2c0428a99f7305c086caffe0c730add601ebd6e, 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 @@ -13,5 +13,5 @@
// For internal debugging:
//#define THORVG_LOG_ENABLED

#define THORVG_VERSION_STRING "0.13.5"
#define THORVG_VERSION_STRING "0.13.7"
#endif
48 changes: 36 additions & 12 deletions thirdparty/thorvg/inc/thorvg.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ enum class Result
InsufficientCondition, ///< The value returned in case the request cannot be processed - e.g. asking for properties of an object, which does not exist.
FailedAllocation, ///< The value returned in case of unsuccessful memory allocation.
MemoryCorruption, ///< The value returned in the event of bad memory handling - e.g. failing in pointer releasing or casting
NonSupport, ///< The value returned in case of choosing unsupported options.
NonSupport, ///< The value returned in case of choosing unsupported engine features(options).
Unknown ///< The value returned in all other cases.
};

Expand Down Expand Up @@ -982,7 +982,7 @@ class TVG_API Shape final : public Paint
*
* @param[in] width The width of the stroke. The default value is 0.
*
* @retval Result::Success when succeed, Result::FailedAllocation otherwise.
* @retval Result::Success when succeed.
*/
Result stroke(float width) noexcept;

Expand All @@ -994,7 +994,7 @@ class TVG_API Shape final : public Paint
* @param[in] b The blue color channel value in the range [0 ~ 255]. The default value is 0.
* @param[in] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. The default value is 0.
*
* @retval Result::Success when succeed, Result::FailedAllocation otherwise.
* @retval Result::Success when succeed.
*/
Result stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) noexcept;

Expand All @@ -1004,8 +1004,7 @@ class TVG_API Shape final : public Paint
* @param[in] f The gradient fill.
*
* @retval Result::Success When succeed.
* @retval Result::FailedAllocation An internal error with a memory allocation for an object to be filled.
* @retval Result::MemoryCorruption In case a @c nullptr is passed as the argument.
* @retval Result::MemoryCorruption In case a @c nullptr is passed as the argument or an error with accessing it.
*/
Result stroke(std::unique_ptr<Fill> f) noexcept;

Expand All @@ -1029,7 +1028,7 @@ class TVG_API Shape final : public Paint
*
* @param[in] cap The cap style value. The default value is @c StrokeCap::Square.
*
* @retval Result::Success when succeed, Result::FailedAllocation otherwise.
* @retval Result::Success when succeed.
*/
Result stroke(StrokeCap cap) noexcept;

Expand All @@ -1040,22 +1039,37 @@ class TVG_API Shape final : public Paint
*
* @param[in] join The join style value. The default value is @c StrokeJoin::Bevel.
*
* @retval Result::Success when succeed, Result::FailedAllocation otherwise.
* @retval Result::Success when succeed.
*/
Result stroke(StrokeJoin join) noexcept;


/**
* @brief Sets the stroke miterlimit.
*
* @param[in] miterlimit The miterlimit imposes a limit on the extent of the stroke join, when the @c StrokeJoin::Miter join style is set. The default value is 4.
*
* @retval Result::Success when succeed, Result::NonSupport unsupported value, Result::FailedAllocation otherwise.
* @retval Result::Success when succeed or Result::InvalidArgument for @p miterlimit values less than zero.
*
* @since 0.11
*/
Result strokeMiterlimit(float miterlimit) noexcept;

/**
* @brief Sets the trim of the stroke along the defined path segment, allowing control over which part of the stroke is visible.
*
* The values of the arguments @p begin, @p end, and @p offset are in the range of 0.0 to 1.0, representing the beginning of the path and the end, respectively.
*
* @param[in] begin Specifies the start of the segment to display along the path.
* @param[in] end Specifies the end of the segment to display along the path.
* @param[in] simultaneous Determines how to trim multiple paths within a single shape. If set to @c true (default), trimming is applied simultaneously to all paths;
* Otherwise, all paths are treated as a single entity with a combined length equal to the sum of their individual lengths and are trimmed as such.
*
* @retval Result::Success when succeed.
*
* @note Experimental API
*/
Result strokeTrim(float begin, float end, bool simultaneous = true) noexcept;

/**
* @brief Sets the solid color for all of the figures from the path.
*
Expand Down Expand Up @@ -1095,19 +1109,17 @@ class TVG_API Shape final : public Paint
*/
Result fill(FillRule r) noexcept;


/**
* @brief Sets the rendering order of the stroke and the fill.
*
* @param[in] strokeFirst If @c true the stroke is rendered before the fill, otherwise the stroke is rendered as the second one (the default option).
*
* @retval Result::Success when succeed, Result::FailedAllocation otherwise.
* @retval Result::Success when succeed.
*
* @since 0.10
*/
Result order(bool strokeFirst) noexcept;


/**
* @brief Gets the commands data of the path.
*
Expand Down Expand Up @@ -1210,6 +1222,18 @@ class TVG_API Shape final : public Paint
*/
float strokeMiterlimit() const noexcept;

/**
* @brief Gets the trim of the stroke along the defined path segment.
*
* @param[out] begin The starting point of the segment to display along the path.
* @param[out] end Specifies the end of the segment to display along the path.
*
* @retval @c true if trimming is applied simultaneously to all paths of the shape, @c false otherwise.
*
* @note Experimental API
*/
bool strokeTrim(float* begin, float* end) const noexcept;

/**
* @brief Creates a new Shape object.
*
Expand Down
15 changes: 15 additions & 0 deletions thirdparty/thorvg/src/common/tvgCompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,4 +472,19 @@ size_t b64Decode(const char* encoded, const size_t len, char** decoded)
}


/************************************************************************/
/* DJB2 Implementation */
/************************************************************************/

unsigned long djb2Encode(const char* str)
{
unsigned long hash = 5381;
int c;

while ((c = *str++)) {
hash = ((hash << 5) + hash) + c; // hash * 33 + c
}
return hash;
}

}
1 change: 1 addition & 0 deletions thirdparty/thorvg/src/common/tvgCompressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace tvg
uint8_t* lzwEncode(const uint8_t* uncompressed, uint32_t uncompressedSizeBytes, uint32_t* compressedSizeBytes, uint32_t* compressedSizeBits);
uint8_t* lzwDecode(const uint8_t* compressed, uint32_t compressedSizeBytes, uint32_t compressedSizeBits, uint32_t uncompressedSizeBytes);
size_t b64Decode(const char* encoded, const size_t len, char** decoded);
unsigned long djb2Encode(const char* str);
}

#endif //_TVG_COMPRESSOR_H_
63 changes: 37 additions & 26 deletions thirdparty/thorvg/src/common/tvgMath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,14 @@ bool mathInverse(const Matrix* m, Matrix* out)
}


Matrix mathMultiply(const Matrix* lhs, const Matrix* rhs)
bool mathIdentity(const Matrix* m)
{
Matrix m;

m.e11 = lhs->e11 * rhs->e11 + lhs->e12 * rhs->e21 + lhs->e13 * rhs->e31;
m.e12 = lhs->e11 * rhs->e12 + lhs->e12 * rhs->e22 + lhs->e13 * rhs->e32;
m.e13 = lhs->e11 * rhs->e13 + lhs->e12 * rhs->e23 + lhs->e13 * rhs->e33;

m.e21 = lhs->e21 * rhs->e11 + lhs->e22 * rhs->e21 + lhs->e23 * rhs->e31;
m.e22 = lhs->e21 * rhs->e12 + lhs->e22 * rhs->e22 + lhs->e23 * rhs->e32;
m.e23 = lhs->e21 * rhs->e13 + lhs->e22 * rhs->e23 + lhs->e23 * rhs->e33;

m.e31 = lhs->e31 * rhs->e11 + lhs->e32 * rhs->e21 + lhs->e33 * rhs->e31;
m.e32 = lhs->e31 * rhs->e12 + lhs->e32 * rhs->e22 + lhs->e33 * rhs->e32;
m.e33 = lhs->e31 * rhs->e13 + lhs->e32 * rhs->e23 + lhs->e33 * rhs->e33;

return m;
if (m->e11 != 1.0f || m->e12 != 0.0f || m->e13 != 0.0f ||
m->e21 != 0.0f || m->e22 != 1.0f || m->e23 != 0.0f ||
m->e31 != 0.0f || m->e32 != 0.0f || m->e33 != 1.0f) {
return false;
}
return true;
}


Expand All @@ -82,21 +73,41 @@ void mathRotate(Matrix* m, float degree)
}


bool mathIdentity(const Matrix* m)
Matrix operator*(const Matrix& lhs, const Matrix& rhs)
{
if (m->e11 != 1.0f || m->e12 != 0.0f || m->e13 != 0.0f ||
m->e21 != 0.0f || m->e22 != 1.0f || m->e23 != 0.0f ||
m->e31 != 0.0f || m->e32 != 0.0f || m->e33 != 1.0f) {
return false;
Matrix m;

m.e11 = lhs.e11 * rhs.e11 + lhs.e12 * rhs.e21 + lhs.e13 * rhs.e31;
m.e12 = lhs.e11 * rhs.e12 + lhs.e12 * rhs.e22 + lhs.e13 * rhs.e32;
m.e13 = lhs.e11 * rhs.e13 + lhs.e12 * rhs.e23 + lhs.e13 * rhs.e33;

m.e21 = lhs.e21 * rhs.e11 + lhs.e22 * rhs.e21 + lhs.e23 * rhs.e31;
m.e22 = lhs.e21 * rhs.e12 + lhs.e22 * rhs.e22 + lhs.e23 * rhs.e32;
m.e23 = lhs.e21 * rhs.e13 + lhs.e22 * rhs.e23 + lhs.e23 * rhs.e33;

m.e31 = lhs.e31 * rhs.e11 + lhs.e32 * rhs.e21 + lhs.e33 * rhs.e31;
m.e32 = lhs.e31 * rhs.e12 + lhs.e32 * rhs.e22 + lhs.e33 * rhs.e32;
m.e33 = lhs.e31 * rhs.e13 + lhs.e32 * rhs.e23 + lhs.e33 * rhs.e33;

return m;
}


bool operator==(const Matrix& lhs, const Matrix& rhs)
{
if (!mathEqual(lhs.e11, rhs.e11) || !mathEqual(lhs.e12, rhs.e12) || !mathEqual(lhs.e13, rhs.e13) ||
!mathEqual(lhs.e21, rhs.e21) || !mathEqual(lhs.e22, rhs.e22) || !mathEqual(lhs.e23, rhs.e23) ||
!mathEqual(lhs.e31, rhs.e31) || !mathEqual(lhs.e32, rhs.e32) || !mathEqual(lhs.e33, rhs.e33)) {
return false;
}
return true;
}


void mathMultiply(Point* pt, const Matrix* transform)
void operator*=(Point& pt, const Matrix& m)
{
auto tx = pt->x * transform->e11 + pt->y * transform->e12 + transform->e13;
auto ty = pt->x * transform->e21 + pt->y * transform->e22 + transform->e23;
pt->x = tx;
pt->y = ty;
auto tx = pt.x * m.e11 + pt.y * m.e12 + m.e13;
auto ty = pt.x * m.e21 + pt.y * m.e22 + m.e23;
pt.x = tx;
pt.y = ty;
}
81 changes: 52 additions & 29 deletions thirdparty/thorvg/src/common/tvgMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@
#define mathMax(x, y) (((x) > (y)) ? (x) : (y))


bool mathInverse(const Matrix* m, Matrix* out);
Matrix mathMultiply(const Matrix* lhs, const Matrix* rhs);
void mathRotate(Matrix* m, float degree);
bool mathIdentity(const Matrix* m);
void mathMultiply(Point* pt, const Matrix* transform);
/************************************************************************/
/* General functions */
/************************************************************************/


static inline float mathDeg2Rad(float degree)
Expand All @@ -63,28 +61,21 @@ static inline bool mathZero(float a)
}


static inline bool mathZero(const Point& p)
{
return mathZero(p.x) && mathZero(p.y);
}


static inline bool mathEqual(float a, float b)
{
return mathZero(a - b);
}


static inline bool mathEqual(const Matrix& a, const Matrix& b)
{
if (!mathEqual(a.e11, b.e11) || !mathEqual(a.e12, b.e12) || !mathEqual(a.e13, b.e13) ||
!mathEqual(a.e21, b.e21) || !mathEqual(a.e22, b.e22) || !mathEqual(a.e23, b.e23) ||
!mathEqual(a.e31, b.e31) || !mathEqual(a.e32, b.e32) || !mathEqual(a.e33, b.e33)) {
return false;
}
return true;
}
/************************************************************************/
/* Matrix functions */
/************************************************************************/

void mathRotate(Matrix* m, float degree);
bool mathInverse(const Matrix* m, Matrix* out);
bool mathIdentity(const Matrix* m);
Matrix operator*(const Matrix& lhs, const Matrix& rhs);
bool operator==(const Matrix& lhs, const Matrix& rhs);

static inline bool mathRightAngle(const Matrix* m)
{
Expand Down Expand Up @@ -114,15 +105,6 @@ static inline void mathIdentity(Matrix* m)
}


static inline void mathTransform(Matrix* transform, Point* coord)
{
auto x = coord->x;
auto y = coord->y;
coord->x = x * transform->e11 + y * transform->e12 + transform->e13;
coord->y = x * transform->e21 + y * transform->e22 + transform->e23;
}


static inline void mathScale(Matrix* m, float sx, float sy)
{
m->e11 *= sx;
Expand Down Expand Up @@ -158,12 +140,37 @@ static inline void mathTranslateR(Matrix* m, float x, float y)
}


static inline bool operator!=(const Matrix& lhs, const Matrix& rhs)
{
return !(lhs == rhs);
}


static inline void operator*=(Matrix& lhs, const Matrix& rhs)
{
lhs = lhs * rhs;
}


static inline void mathLog(Matrix* m)
{
TVGLOG("MATH", "Matrix: [%f %f %f] [%f %f %f] [%f %f %f]", m->e11, m->e12, m->e13, m->e21, m->e22, m->e23, m->e31, m->e32, m->e33);
}


/************************************************************************/
/* Point functions */
/************************************************************************/

void operator*=(Point& pt, const Matrix& m);


static inline bool mathZero(const Point& p)
{
return mathZero(p.x) && mathZero(p.y);
}


static inline float mathLength(const Point* a, const Point* b)
{
auto x = b->x - a->x;
Expand All @@ -182,6 +189,18 @@ static inline float mathLength(const Point& a)
}


static inline bool operator==(const Point& lhs, const Point& rhs)
{
return mathEqual(lhs.x, rhs.x) && mathEqual(lhs.y, rhs.y);
}


static inline bool operator!=(const Point& lhs, const Point& rhs)
{
return !(lhs == rhs);
}


static inline Point operator-(const Point& lhs, const Point& rhs)
{
return {lhs.x - rhs.x, lhs.y - rhs.y};
Expand Down Expand Up @@ -212,6 +231,10 @@ static inline Point operator/(const Point& lhs, const float rhs)
}


/************************************************************************/
/* Interpolation functions */
/************************************************************************/

template <typename T>
static inline T mathLerp(const T &start, const T &end, float t)
{
Expand Down
Loading

0 comments on commit 18650de

Please sign in to comment.