Skip to content

Commit

Permalink
ThorVG: Update source to tip
Browse files Browse the repository at this point in the history
  • Loading branch information
capnm committed Jan 25, 2024
1 parent d5fb73f commit d400a42
Show file tree
Hide file tree
Showing 37 changed files with 360 additions and 371 deletions.
7 changes: 4 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,11 @@ 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]>
123 changes: 36 additions & 87 deletions thirdparty/thorvg/inc/thorvg.h

Large diffs are not rendered by default.

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

#ifndef _TVG_BINARY_DESC_H_
#define _TVG_BINARY_DESC_H_
#ifndef _TVG_FORMAT_H_
#define _TVG_FORMAT_H_

/* TODO: Need to consider whether uin8_t is enough size for extension...
Rather than optimal data, we can use enough size and data compress? */
Expand All @@ -36,7 +36,7 @@ using TvgBinFlag = TvgBinByte;
#define TVG_HEADER_SIZE 33 //TVG_HEADER_SIGNATURE_LENGTH + TVG_HEADER_VERSION_LENGTH + 2*SIZE(float) + TVG_HEADER_RESERVED_LENGTH + TVG_HEADER_COMPRESS_SIZE
#define TVG_HEADER_SIGNATURE "ThorVG"
#define TVG_HEADER_SIGNATURE_LENGTH 6
#define TVG_HEADER_VERSION "001200" //Major 00, Minor 12, Micro 00
#define TVG_HEADER_VERSION "010000" //Major 01, Minor 00, Micro 00
#define TVG_HEADER_VERSION_LENGTH 6
#define TVG_HEADER_RESERVED_LENGTH 1 //Storing flags for extensions
#define TVG_HEADER_COMPRESS_SIZE 12 //TVG_HEADER_UNCOMPRESSED_SIZE + TVG_HEADER_COMPRESSED_SIZE + TVG_HEADER_COMPRESSED_SIZE_BITS
Expand All @@ -60,11 +60,6 @@ using TvgBinFlag = TvgBinByte;
#define TVG_TAG_PAINT_CMP_METHOD (TvgBinTag)0x20


//TODO: Keep this for the compatibility, Remove in TVG 1.0 release
//Scene
#define TVG_TAG_SCENE_RESERVEDCNT (TvgBinTag)0x30


//Shape
#define TVG_TAG_SHAPE_PATH (TvgBinTag)0x40
#define TVG_TAG_SHAPE_STROKE (TvgBinTag)0x41
Expand Down Expand Up @@ -97,4 +92,4 @@ using TvgBinFlag = TvgBinByte;
#define TVG_TAG_PICTURE_RAW_IMAGE (TvgBinTag)0x70
#define TVG_TAG_PICTURE_MESH (TvgBinTag)0x71

#endif //_TVG_BINARY_DESC_H_
#endif //_TVG_FORMAT_H_
70 changes: 70 additions & 0 deletions thirdparty/thorvg/src/common/tvgLock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2024 the ThorVG project. All rights reserved.
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _TVG_LOCK_H_
#define _TVG_LOCK_H_

#ifdef THORVG_THREAD_SUPPORT

#include <mutex>

namespace tvg {

struct Key
{
std::mutex mtx;
};

struct ScopedLock
{
Key* key = nullptr;

ScopedLock(Key& key)
{
key.mtx.lock();
this->key = &key;
}

~ScopedLock()
{
key->mtx.unlock();
}
};

}

#else //THORVG_THREAD_SUPPORT

namespace tvg {

struct Key {};

struct ScopedLock
{
ScopedLock(Key& key) {}
};

}

#endif //THORVG_THREAD_SUPPORT

#endif //_TVG_LOCK_H_
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ bool PngLoader::open(const string& path)
}


bool PngLoader::open(const char* data, uint32_t size, bool copy)
bool PngLoader::open(const char* data, uint32_t size, TVG_UNUSED const string& rpath, bool copy)
{
image->opaque = NULL;

Expand Down
2 changes: 1 addition & 1 deletion thirdparty/thorvg/src/loaders/external_png/tvgPngLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class PngLoader : public ImageLoader
~PngLoader();

bool open(const string& path) override;
bool open(const char* data, uint32_t size, bool copy) override;
bool open(const char* data, uint32_t size, const string& rpath, bool copy) override;
bool read() override;

private:
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/thorvg/src/loaders/jpg/tvgJpgLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ bool JpgLoader::open(const string& path)
}


bool JpgLoader::open(const char* data, uint32_t size, bool copy)
bool JpgLoader::open(const char* data, uint32_t size, TVG_UNUSED const string& rpath, bool copy)
{
if (copy) {
this->data = (char *) malloc(size);
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/thorvg/src/loaders/jpg/tvgJpgLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class JpgLoader : public ImageLoader, public Task
~JpgLoader();

bool open(const string& path) override;
bool open(const char* data, uint32_t size, bool copy) override;
bool open(const char* data, uint32_t size, const string& rpath, bool copy) override;
bool read() override;
bool close() override;

Expand Down
2 changes: 1 addition & 1 deletion thirdparty/thorvg/src/loaders/png/tvgPngLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ bool PngLoader::open(const string& path)
}


bool PngLoader::open(const char* data, uint32_t size, bool copy)
bool PngLoader::open(const char* data, uint32_t size, TVG_UNUSED const string& rpath, bool copy)
{
unsigned int width, height;
if (lodepng_inspect(&width, &height, &state, (unsigned char*)(data), size) > 0) return false;
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/thorvg/src/loaders/png/tvgPngLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PngLoader : public ImageLoader, public Task
~PngLoader();

bool open(const string& path) override;
bool open(const char* data, uint32_t size, bool copy) override;
bool open(const char* data, uint32_t size, const string& rpath, bool copy) override;
bool read() override;

Surface* bitmap() override;
Expand Down
4 changes: 2 additions & 2 deletions thirdparty/thorvg/src/loaders/raw/tvgRawLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ RawLoader::~RawLoader()
}


bool RawLoader::open(const uint32_t* data, uint32_t w, uint32_t h, bool copy)
bool RawLoader::open(const uint32_t* data, uint32_t w, uint32_t h, bool premultiplied, bool copy)
{
if (!LoadModule::read()) return true;

Expand All @@ -68,7 +68,7 @@ bool RawLoader::open(const uint32_t* data, uint32_t w, uint32_t h, bool copy)
surface.h = h;
surface.cs = ColorSpace::ARGB8888;
surface.channelSize = sizeof(uint32_t);
surface.premultiplied = true;
surface.premultiplied = premultiplied;

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/thorvg/src/loaders/raw/tvgRawLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class RawLoader : public ImageLoader
~RawLoader();

using LoadModule::open;
bool open(const uint32_t* data, uint32_t w, uint32_t h, bool copy);
bool open(const uint32_t* data, uint32_t w, uint32_t h, bool premultiplied, bool copy);
bool read() override;
};

Expand Down
54 changes: 19 additions & 35 deletions thirdparty/thorvg/src/loaders/svg/tvgSvgLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,32 +683,6 @@ static constexpr struct
};


static void _matrixCompose(const Matrix* m1, const Matrix* m2, Matrix* dst)
{
auto a11 = (m1->e11 * m2->e11) + (m1->e12 * m2->e21) + (m1->e13 * m2->e31);
auto a12 = (m1->e11 * m2->e12) + (m1->e12 * m2->e22) + (m1->e13 * m2->e32);
auto a13 = (m1->e11 * m2->e13) + (m1->e12 * m2->e23) + (m1->e13 * m2->e33);

auto a21 = (m1->e21 * m2->e11) + (m1->e22 * m2->e21) + (m1->e23 * m2->e31);
auto a22 = (m1->e21 * m2->e12) + (m1->e22 * m2->e22) + (m1->e23 * m2->e32);
auto a23 = (m1->e21 * m2->e13) + (m1->e22 * m2->e23) + (m1->e23 * m2->e33);

auto a31 = (m1->e31 * m2->e11) + (m1->e32 * m2->e21) + (m1->e33 * m2->e31);
auto a32 = (m1->e31 * m2->e12) + (m1->e32 * m2->e22) + (m1->e33 * m2->e32);
auto a33 = (m1->e31 * m2->e13) + (m1->e32 * m2->e23) + (m1->e33 * m2->e33);

dst->e11 = a11;
dst->e12 = a12;
dst->e13 = a13;
dst->e21 = a21;
dst->e22 = a22;
dst->e23 = a23;
dst->e31 = a31;
dst->e32 = a32;
dst->e33 = a33;
}


/* parse transform attribute
* https://www.w3.org/TR/SVG/coords.html#TransformAttribute
*/
Expand Down Expand Up @@ -751,14 +725,14 @@ static Matrix* _parseTransformationMatrix(const char* value)
if (state == MatrixState::Matrix) {
if (ptCount != 6) goto error;
Matrix tmp = {points[0], points[2], points[4], points[1], points[3], points[5], 0, 0, 1};
_matrixCompose(matrix, &tmp, matrix);
*matrix = mathMultiply(matrix, &tmp);
} else if (state == MatrixState::Translate) {
if (ptCount == 1) {
Matrix tmp = {1, 0, points[0], 0, 1, 0, 0, 0, 1};
_matrixCompose(matrix, &tmp, matrix);
*matrix = mathMultiply(matrix, &tmp);
} else if (ptCount == 2) {
Matrix tmp = {1, 0, points[0], 0, 1, points[1], 0, 0, 1};
_matrixCompose(matrix, &tmp, matrix);
*matrix = mathMultiply(matrix, &tmp);
} else goto error;
} else if (state == MatrixState::Rotate) {
//Transform to signed.
Expand All @@ -768,14 +742,14 @@ static Matrix* _parseTransformationMatrix(const char* value)
auto s = sinf(points[0] * (M_PI / 180.0));
if (ptCount == 1) {
Matrix tmp = { c, -s, 0, s, c, 0, 0, 0, 1 };
_matrixCompose(matrix, &tmp, matrix);
*matrix = mathMultiply(matrix, &tmp);
} else if (ptCount == 3) {
Matrix tmp = { 1, 0, points[1], 0, 1, points[2], 0, 0, 1 };
_matrixCompose(matrix, &tmp, matrix);
*matrix = mathMultiply(matrix, &tmp);
tmp = { c, -s, 0, s, c, 0, 0, 0, 1 };
_matrixCompose(matrix, &tmp, matrix);
*matrix = mathMultiply(matrix, &tmp);
tmp = { 1, 0, -points[1], 0, 1, -points[2], 0, 0, 1 };
_matrixCompose(matrix, &tmp, matrix);
*matrix = mathMultiply(matrix, &tmp);
} else {
goto error;
}
Expand All @@ -785,7 +759,17 @@ static Matrix* _parseTransformationMatrix(const char* value)
auto sy = sx;
if (ptCount == 2) sy = points[1];
Matrix tmp = { sx, 0, 0, 0, sy, 0, 0, 0, 1 };
_matrixCompose(matrix, &tmp, matrix);
*matrix = mathMultiply(matrix, &tmp);
} else if (state == MatrixState::SkewX) {
if (ptCount != 1) goto error;
auto deg = tanf(points[0] * (M_PI / 180.0));
Matrix tmp = { 1, deg, 0, 0, 1, 0, 0, 0, 1 };
*matrix = mathMultiply(matrix, &tmp);
} else if (state == MatrixState::SkewY) {
if (ptCount != 1) goto error;
auto deg = tanf(points[0] * (M_PI / 180.0));
Matrix tmp = { 1, 0, 0, deg, 1, 0, 0, 0, 1 };
*matrix = mathMultiply(matrix, &tmp);
}
}
return matrix;
Expand Down Expand Up @@ -3676,7 +3660,7 @@ bool SvgLoader::header()
}


bool SvgLoader::open(const char* data, uint32_t size, bool copy)
bool SvgLoader::open(const char* data, uint32_t size, TVG_UNUSED const string& rpath, bool copy)
{
clear();

Expand Down
2 changes: 1 addition & 1 deletion thirdparty/thorvg/src/loaders/svg/tvgSvgLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SvgLoader : public ImageLoader, public Task
~SvgLoader();

bool open(const string& path) override;
bool open(const char* data, uint32_t size, bool copy) override;
bool open(const char* data, uint32_t size, const string& rpath, bool copy) override;
bool resize(Paint* paint, float w, float h) override;
bool read() override;
bool close() override;
Expand Down
24 changes: 12 additions & 12 deletions thirdparty/thorvg/src/loaders/svg/tvgSvgSceneBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,36 +347,36 @@ static void _applyProperty(SvgLoaderData& loaderData, SvgNode* node, Shape* vg,
if (node->type == SvgNodeType::G || node->type == SvgNodeType::Use) return;

//Apply the stroke style property
vg->stroke(style->stroke.width);
vg->stroke(style->stroke.cap);
vg->stroke(style->stroke.join);
vg->strokeWidth(style->stroke.width);
vg->strokeCap(style->stroke.cap);
vg->strokeJoin(style->stroke.join);
vg->strokeMiterlimit(style->stroke.miterlimit);
if (style->stroke.dash.array.count > 0) {
P(vg)->strokeDash(style->stroke.dash.array.data, style->stroke.dash.array.count, style->stroke.dash.offset);
vg->strokeDash(style->stroke.dash.array.data, style->stroke.dash.array.count, style->stroke.dash.offset);
}

//If stroke property is nullptr then do nothing
if (style->stroke.paint.none) {
vg->stroke(0.0f);
vg->strokeWidth(0.0f);
} else if (style->stroke.paint.gradient) {
Box bBox = vBox;
if (!style->stroke.paint.gradient->userSpace) bBox = _boundingBox(vg);

if (style->stroke.paint.gradient->type == SvgGradientType::Linear) {
auto linear = _applyLinearGradientProperty(style->stroke.paint.gradient, vg, bBox, style->stroke.opacity);
vg->stroke(std::move(linear));
vg->strokeFill(std::move(linear));
} else if (style->stroke.paint.gradient->type == SvgGradientType::Radial) {
auto radial = _applyRadialGradientProperty(style->stroke.paint.gradient, vg, bBox, style->stroke.opacity);
vg->stroke(std::move(radial));
vg->strokeFill(std::move(radial));
}
} else if (style->stroke.paint.url) {
//TODO: Apply the color pointed by url
} else if (style->stroke.paint.curColor) {
//Apply the current style color
vg->stroke(style->color.r, style->color.g, style->color.b, style->stroke.opacity);
vg->strokeFill(style->color.r, style->color.g, style->color.b, style->stroke.opacity);
} else {
//Apply the stroke color
vg->stroke(style->stroke.paint.color.r, style->stroke.paint.color.g, style->stroke.paint.color.b, style->stroke.opacity);
vg->strokeFill(style->stroke.paint.color.r, style->stroke.paint.color.g, style->stroke.paint.color.b, style->stroke.opacity);
}

_applyComposition(loaderData, vg, node, vBox, svgPath);
Expand Down Expand Up @@ -571,14 +571,14 @@ static unique_ptr<Picture> _imageBuildHelper(SvgLoaderData& loaderData, SvgNode*
char *decoded = nullptr;
if (encoding == imageMimeTypeEncoding::base64) {
auto size = b64Decode(href, strlen(href), &decoded);
if (picture->load(decoded, size, mimetype, false) != Result::Success) {
if (picture->load(decoded, size, mimetype) != Result::Success) {
free(decoded);
TaskScheduler::async(true);
return nullptr;
}
} else {
auto size = svgUtilURLDecode(href, &decoded);
if (picture->load(decoded, size, mimetype, false) != Result::Success) {
if (picture->load(decoded, size, mimetype) != Result::Success) {
free(decoded);
TaskScheduler::async(true);
return nullptr;
Expand Down Expand Up @@ -803,7 +803,7 @@ static unique_ptr<Scene> _sceneBuildHelper(SvgLoaderData& loaderData, const SvgN
uint8_t r, g, b;
shape->fillColor(&r, &g, &b);
if (shape->fill() || r < 255 || g < 255 || b < 255 || shape->strokeFill() ||
(shape->strokeColor(&r, &g, &b) == Result::Success && (r < 255 || g < 255 || b < 255))) {
(shape->strokeFill(&r, &g, &b) == Result::Success && (r < 255 || g < 255 || b < 255))) {
*isMaskWhite = false;
}
}
Expand Down
Loading

0 comments on commit d400a42

Please sign in to comment.