Skip to content

Commit

Permalink
Merge pull request #91788 from akien-mga/thorvg-0.13.3
Browse files Browse the repository at this point in the history
thorvg: Update to 0.13.3, add webp loader
  • Loading branch information
akien-mga committed May 11, 2024
2 parents 65f81e4 + 1cf9f37 commit 1cf283d
Show file tree
Hide file tree
Showing 37 changed files with 630 additions and 3,037 deletions.
7 changes: 6 additions & 1 deletion modules/svg/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ thirdparty_obj = []
thirdparty_dir = "#thirdparty/thorvg/"
thirdparty_sources = [
# common
"src/common/tvgBezier.cpp",
"src/common/tvgCompressor.cpp",
"src/common/tvgLines.cpp",
"src/common/tvgMath.cpp",
"src/common/tvgStr.cpp",
# SVG parser
Expand All @@ -24,7 +24,9 @@ thirdparty_sources = [
"src/loaders/svg/tvgSvgUtil.cpp",
"src/loaders/svg/tvgXmlParser.cpp",
"src/loaders/raw/tvgRawLoader.cpp",
# image loaders
"src/loaders/external_png/tvgPngLoader.cpp",
"src/loaders/external_webp/tvgWebpLoader.cpp",
"src/loaders/jpg/tvgJpgd.cpp",
"src/loaders/jpg/tvgJpgLoader.cpp",
# renderer common
Expand Down Expand Up @@ -74,7 +76,10 @@ env_thirdparty.Prepend(
thirdparty_dir + "src/renderer/sw_engine",
thirdparty_dir + "src/loaders/raw",
thirdparty_dir + "src/loaders/external_png",
thirdparty_dir + "src/loaders/external_webp",
thirdparty_dir + "src/loaders/jpg",
"#thirdparty/libpng",
"#thirdparty/libwebp/src",
]
)

Expand Down
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.12.9 (afa6d8499bd49141d99d5e40a4620bd9f6bc0467, 2024)
- Version: 0.13.3 (6235068cad8cad176ccd0cbcf82f25e985fbc258, 2024)
- License: MIT

Files extracted from upstream source:
Expand Down
8 changes: 5 additions & 3 deletions thirdparty/thorvg/AUTHORS
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Hermet Park <[email protected]>
Hermet Park <[email protected]>, <[email protected]>
Prudhvi Raj Vasireddi <[email protected]>
Junsu Choi <[email protected]>
Pranay Samanta <[email protected]>
Mateusz Palkowski <[email protected]>
Subhransu Mohanty <[email protected]>
Mira Grudzinska <[email protected]>
Mira Grudzinska <[email protected]>, <[email protected]>
Michal Szczecinski <[email protected]>
Shinwoo Kim <[email protected]>
Piotr Kalota <[email protected]>
Expand All @@ -18,10 +18,12 @@ Rémi Verschelde <[email protected]>
Martin Liska <[email protected]>
Vincenzo Pupillo <[email protected]>
EunSik Jeong <[email protected]>
Samsung Electronics Co., Ltd
Rafał Mikrut <[email protected]>
Martin Capitanio <[email protected]>
RuiwenTang <[email protected]>
YouJin Lee <[email protected]>
SergeyLebedkin <[email protected]>
Jinny You <[email protected]>
Nattu Adnan <[email protected]>
Gabor Kiss-Vamosi <[email protected]>
Lorcán Mc Donagh <[email protected]>
3 changes: 2 additions & 1 deletion thirdparty/thorvg/inc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
#define THORVG_SVG_LOADER_SUPPORT
#define THORVG_PNG_LOADER_SUPPORT
#define THORVG_JPG_LOADER_SUPPORT
#define THORVG_WEBP_LOADER_SUPPORT
#define THORVG_THREAD_SUPPORT

// For internal debugging:
//#define THORVG_LOG_ENABLED

#define THORVG_VERSION_STRING "0.12.10"
#define THORVG_VERSION_STRING "0.13.3"
#endif
68 changes: 56 additions & 12 deletions thirdparty/thorvg/inc/thorvg.h
Original file line number Diff line number Diff line change
Expand Up @@ -1645,7 +1645,7 @@ class TVG_API SwCanvas final : public Canvas
};

/**
* @brief Sets the target buffer for the rasterization.
* @brief Sets the drawing target for the rasterization.
*
* The buffer of a desirable size should be allocated and owned by the caller.
*
Expand Down Expand Up @@ -1714,13 +1714,22 @@ class TVG_API GlCanvas final : public Canvas
~GlCanvas();

/**
* @brief Sets the target buffer for the rasterization.
* @brief Sets the drawing target for rasterization.
*
* @warning Please do not use it, this API is not official one. It could be modified in the next version.
* This function specifies the drawing target where the rasterization will occur. It can target
* a specific framebuffer object (FBO) or the main surface.
*
* @param[in] id The GL target ID, usually indicating the FBO ID. A value of @c 0 specifies the main surface.
* @param[in] w The width (in pixels) of the raster image.
* @param[in] h The height (in pixels) of the raster image.
*
* @warning This API is experimental and not officially supported. It may be modified or removed in future versions.
* @warning Drawing on the main surface is currently not permitted. If the identifier (@p id) is set to @c 0, the operation will be aborted.
*
* @note Currently, this only allows the GL_RGBA8 color space format.
* @note Experimental API
*/
Result target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h) noexcept;
*/
Result target(int32_t id, uint32_t w, uint32_t h) noexcept;

/**
* @brief Creates a new GlCanvas object.
Expand Down Expand Up @@ -1828,7 +1837,7 @@ class TVG_API Initializer final
*
* This class supports the display and control of animation frames.
*
* @note Experimental API
* @since 0.13
*/

class TVG_API Animation
Expand All @@ -1845,9 +1854,11 @@ class TVG_API Animation
* @retval Result::InsufficientCondition if the given @p no is the same as the current frame value.
* @retval Result::NonSupport The current Picture data does not support animations.
*
* @note For efficiency, ThorVG ignores updates to the new frame value if the difference from the current frame value
* is less than 0.001. In such cases, it returns @c Result::InsufficientCondition.
*
* @see totalFrame()
*
* @note Experimental API
*/
Result frame(float no) noexcept;

Expand All @@ -1862,7 +1873,6 @@ class TVG_API Animation
*
* @warning The picture instance is owned by Animation. It should not be deleted manually.
*
* @note Experimental API
*/
Picture* picture() const noexcept;

Expand All @@ -1876,7 +1886,6 @@ class TVG_API Animation
* @see Animation::frame(float no)
* @see Animation::totalFrame()
*
* @note Experimental API
*/
float curFrame() const noexcept;

Expand All @@ -1888,7 +1897,6 @@ class TVG_API Animation
* @note Frame numbering starts from 0.
* @note If the Picture is not properly configured, this function will return 0.
*
* @note Experimental API
*/
float totalFrame() const noexcept;

Expand All @@ -1899,16 +1907,52 @@ class TVG_API Animation
*
* @note If the Picture is not properly configured, this function will return 0.
*
* @% Experimental API
*/
float duration() const noexcept;

/**
* @brief Specifies the playback segment of the animation.
*
* The set segment is designated as the play area of the animation.
* This is useful for playing a specific segment within the entire animation.
* After setting, the number of animation frames and the playback time are calculated
* by mapping the playback segment as the entire range.
*
* @param[in] begin segment start.
* @param[in] end segment end.
*
* @retval Result::Success When succeed.
* @retval Result::InsufficientCondition In case the animation is not loaded.
* @retval Result::InvalidArguments When the given parameter is invalid.
* @retval Result::NonSupport When it's not animatable.
*
* @note Range from 0.0~1.0
* @note If a marker has been specified, its range will be disregarded.
* @see LottieAnimation::segment(const char* marker)
* @note Experimental API
*/
Result segment(float begin, float end) noexcept;

/**
* @brief Gets the current segment.
*
* @param[out] begin segment start.
* @param[out] end segment end.
*
* @retval Result::Success When succeed.
* @retval Result::InsufficientCondition In case the animation is not loaded.
* @retval Result::InvalidArguments When the given parameter is invalid.
* @retval Result::NonSupport When it's not animatable.
*
* @note Experimental API
*/
Result segment(float* begin, float* end = nullptr) noexcept;

/**
* @brief Creates a new Animation object.
*
* @return A new Animation object.
*
* @note Experimental API
*/
static std::unique_ptr<Animation> gen() noexcept;

Expand Down
1 change: 1 addition & 0 deletions thirdparty/thorvg/src/common/tvgArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ struct Array

void push(Array<T>& rhs)
{
if (rhs.count == 0) return;
grow(rhs.count);
memcpy(data + count, rhs.data, rhs.count * sizeof(T));
count += rhs.count;
Expand Down
4 changes: 2 additions & 2 deletions thirdparty/thorvg/src/common/tvgCompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,11 @@ size_t b64Decode(const char* encoded, const size_t len, char** decoded)
auto value2 = B64_INDEX[(size_t)encoded[1]];
output[idx++] = (value1 << 2) + ((value2 & 0x30) >> 4);

if (!encoded[2] || encoded[2] == '=' || encoded[2] == '.') break;
if (!encoded[2] || encoded[3] < 0 || encoded[2] == '=' || encoded[2] == '.') break;
auto value3 = B64_INDEX[(size_t)encoded[2]];
output[idx++] = ((value2 & 0x0f) << 4) + ((value3 & 0x3c) >> 2);

if (!encoded[3] || encoded[3] == '=' || encoded[3] == '.') break;
if (!encoded[3] || encoded[3] < 0 || encoded[3] == '=' || encoded[3] == '.') break;
auto value4 = B64_INDEX[(size_t)encoded[3]];
output[idx++] = ((value3 & 0x03) << 6) + value4;
encoded += 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
*/

#include "tvgMath.h"
#include "tvgBezier.h"
#include "tvgLines.h"

#define BEZIER_EPSILON 1e-4f
#define BEZIER_EPSILON 1e-2f

/************************************************************************/
/* Internal Class Implementation */
Expand Down Expand Up @@ -101,6 +101,25 @@ float _bezAt(const Bezier& bz, float at, float length, LengthFunc lineLengthFunc
namespace tvg
{

float lineLength(const Point& pt1, const Point& pt2)
{
return _lineLength(pt1, pt2);
}


void lineSplitAt(const Line& cur, float at, Line& left, Line& right)
{
auto len = lineLength(cur.pt1, cur.pt2);
auto dx = ((cur.pt2.x - cur.pt1.x) / len) * at;
auto dy = ((cur.pt2.y - cur.pt1.y) / len) * at;
left.pt1 = cur.pt1;
left.pt2.x = left.pt1.x + dx;
left.pt2.y = left.pt1.y + dy;
right.pt1 = left.pt2;
right.pt2 = cur.pt2;
}


void bezSplit(const Bezier& cur, Bezier& left, Bezier& right)
{
auto c = (cur.ctrl1.x + cur.ctrl2.x) * 0.5f;
Expand Down Expand Up @@ -219,7 +238,7 @@ float bezAngleAt(const Bezier& bz, float t)
pt.x *= 3;
pt.y *= 3;

return atan2(pt.x, pt.y) * 180.0f / 3.141592f;
return mathRad2Deg(atan2(pt.x, pt.y));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,24 @@
* SOFTWARE.
*/

#ifndef _TVG_BEZIER_H_
#define _TVG_BEZIER_H_
#ifndef _TVG_LINES_H_
#define _TVG_LINES_H_

#include "tvgCommon.h"

namespace tvg
{

struct Line
{
Point pt1;
Point pt2;
};

float lineLength(const Point& pt1, const Point& pt2);
void lineSplitAt(const Line& cur, float at, Line& left, Line& right);


struct Bezier
{
Point start;
Expand All @@ -48,4 +58,4 @@ float bezLengthApprox(const Bezier& cur);
float bezAtApprox(const Bezier& bz, float at, float length);
}

#endif //_TVG_BEZIER_H_
#endif //_TVG_LINES_H_
12 changes: 12 additions & 0 deletions thirdparty/thorvg/src/common/tvgMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ bool mathIdentity(const Matrix* m);
void mathMultiply(Point* pt, const Matrix* transform);


static inline float mathDeg2Rad(float degree)
{
return degree * (MATH_PI / 180.0f);
}


static inline float mathRad2Deg(float radian)
{
return radian * (180.0f / MATH_PI);
}


static inline bool mathZero(float a)
{
return (fabsf(a) < FLT_EPSILON) ? true : false;
Expand Down
3 changes: 3 additions & 0 deletions thirdparty/thorvg/src/common/tvgStr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

#include "config.h"
#include <cmath>
#include <cstring>
#include <memory.h>
#include "tvgMath.h"
Expand Down Expand Up @@ -197,6 +198,8 @@ float strToFloat(const char *nPtr, char **endPtr)

success:
if (endPtr) *endPtr = (char *)(a);
if (!std::isfinite(val)) return 0.0f;

return minus * val;

error:
Expand Down
Loading

0 comments on commit 1cf283d

Please sign in to comment.