Commit graph

2069 commits

Author SHA1 Message Date
Hermet Park
6f19c581e8 infra: renamed the folders, images -> resources.
these folders might have more than images.
2024-01-02 20:34:10 +09:00
Hermet Park
f594806dd3 renderer/shape: Apply the magic number kappa to achieve rounded corners.
The magic number kappa (0.552284), which is associated with the bezier curve,
has been introduced. This formula is supposed to be applied to the rounded corners
of the rectangle to ensure consistent drawing results.

Issue: https://github.com/thorvg/thorvg/issues/1824
2024-01-02 20:34:10 +09:00
Hermet Park
c0a1f82033 renderer/loader: optimization++
removed the internal unique_ptr usage to reduce the binary size(-553)
2024-01-02 20:34:10 +09:00
Jinny You
118516f015 lottie/builder: fix crash by null reference 2024-01-02 20:34:10 +09:00
Jinny You
d173e62530 loader/jpg: Fix warning 2024-01-02 20:34:10 +09:00
Sergii Liebodkin
cb737f174c [Issues 1811: Compiller shadowing warning](https://github.com/thorvg/thorvg/issues/1811)
Godot CI compilation issue fixed
2024-01-02 20:34:10 +09:00
RuiwenTang
269537a411 gl_engine: support advance compose method 2024-01-02 20:34:10 +09:00
Hermet Park
221005bb25 lottie/builder: revert the clipper cache.
This ia a buggy,
We will revisit this optimization with a perfect solution.
2024-01-02 20:34:10 +09:00
Hermet Park
f64ee28079 Loaders: Introduced a loader cache.
The loader cache is applied to conserve memory.

If the input data is already present in loaders,
the loader cache will promptly return the active loader.

This results in a lot of memory savings for the duplicated resources.

binary diff: -400 bytes
2024-01-02 20:34:10 +09:00
Hermet Park
8cc8cf3b02 common: Move the list to the gl_engine side.
Unfortunately, the usage of this list is not intuitive,
so can be confusing. Placed it only for gl.
2024-01-02 20:34:10 +09:00
Hermet Park
815eb23856 lottie/builder: ++size optimization
Replaced std::queue with inlist for optimizing binary size (-1.3kb).
2024-01-02 20:34:10 +09:00
Hermet Park
49137b3851 common/inlist: added a inline list data structure.
Inline lists mean that their nodes' pointers are part of the same memory as the data.
This has the benefit of fragmenting memory less and avoiding node->data indirection.
2024-01-02 20:34:10 +09:00
Hermet Park
52a90d54ee lottie/builder: corrected polystar rotation.
There was likely a mistake in the rotation value set;
there was no reason to multiply it by 2.

Issue: https://github.com/thorvg/thorvg/issues/1773
2024-01-02 20:34:10 +09:00
Hermet Park
1fbdf7bbb6 renderer, loader: minor code refactoring.
- sync with its file name
- remove unnecessary section comments
- compact binary size (-300)
- private Task::run() methods from the loaders
2024-01-02 20:34:10 +09:00
Hermet Park
92d7727c2a Lottie/builder: revert a static cache optimization.
There are some matting masking bugs observed,
Reverted the commit. We will revisit it later.

commit d37c500262
Author: Hermet Park <hermet@lottiefiles.com>
Date:   Wed Oct 25 18:55:05 2023 +0900

    lottie: introduced static layer cache.

    lottie builder doesn't need to rebuild the layer object
    if it has no any animation frame data.

    That case, we can cache the layer scene in order to reuse it.

    Tested on local machine (single thread):
    - Lottie: appx. 2ms enhanced.
    - Binary: +204
2024-01-02 20:34:10 +09:00
Hermet Park
5c2be47e57 lottie/builder: hotfix, invalid stroking scaling.
There is a buggy workaround code that rewinds the stroke scaling.

Issue: https://github.com/thorvg/thorvg/issues/1730
2024-01-02 20:34:10 +09:00
Sergii Liebodkin
51e98eebdb Add support for textures color space formats
[Issues 1479: pictures](https://github.com/thorvg/thorvg/issues/1479)

Formats supported:
    ABGR8888
    ARGB8888
    ABGR8888S
    ARGB8888S
2024-01-02 20:34:10 +09:00
Hermet Park
ec1510ee08 gif/saver: fix a invalid memory access 2024-01-02 20:34:10 +09:00
Hermet Park
b8b8188879 sw_engine: fixed a bug where strokes were not showing.
Basic shapes were trimmed entirely when they were outside of the canvas,
even if they had a big enough stroke to be partially on the canvas.

This fixes the issue.

Issue: https://github.com/thorvg/thorvg/issues/1785
2024-01-02 20:34:10 +09:00
Sergii Liebodkin
802fb3efc6 examples: fixed manual loading of binary data (jpg, png, raw ect)
To load binary data operations must be performed in binary mode rather than text.
The issue appears on windows platform, especially for PNG loading
2024-01-02 20:34:10 +09:00
Hermet Park
0665837899 gif/encoder: fixed memory violation.
There was an invalid palette data access
when no frame data had been changed, detected by memory sanitizer.
2024-01-02 20:34:10 +09:00
Sergii Liebodkin
c5b642e3e7 wg_engine: introduced images drawing support
[issues 1479: pictures](https://github.com/thorvg/thorvg/issues/1479)

    auto picture = tvg::Picture::gen();
    picture->load("images/test.png");
    picture->translate(0, 0);
    picture->size(100, 100);
    picture->opacity(255);
    canvas->push(std::move(picture));
2023-12-26 18:36:45 +09:00
Hermet Park
b87bb2b1a0 lottie/parser: Fix the shapes parsing logic.
Currently, it assumes "ty":"gr" for the related shapes children,
which can be skipped since the children will be in the "it" scope.

Some Lottie data is missing the "ty":"gr" field,
and ThorVG couldn't display the content properly.
It can ignore it with the context understanding.
2023-12-26 18:36:38 +09:00
Hermet Park
c44e09faae gif/encoder: adjusted alpha transparent threshold 255 -> 127
More than half-transparent(50%) pixels will be encoded as well.
2023-12-26 18:36:31 +09:00
Hermet Park
89a6a835dd saver/gif: memory usage optimization.
Use a cache to store the intermediate palette data.
2023-12-26 18:36:25 +09:00
Hermet Park
b3e2c7e6b0 saver/gif: code refactoring
Revised the code to keep the thorvg convention consistency.
2023-12-26 18:36:18 +09:00
Hermet Park
2053bbbc37 gif: fixed a regresion bug by clear() change
by 66305f3e6d
2023-12-26 18:34:49 +09:00
Hermet Park
34f47671b1 gif: support transparent gif animation
if no background is set, gif will generate transparent version.

Issue: https://github.com/thorvg/thorvg/issues/1769
2023-12-26 18:33:46 +09:00
Hermet Park
dfbb3893b0 saver/gif: code refactoring
Remove unused dithering logics for reducing binary size.
This is not quite effective for vector images.
2023-12-26 18:33:40 +09:00
Hermet Park
f58895a04a gl_engine/renderer: skip sync if nothing should be done.
update by 66305f3e6d
2023-12-26 18:33:33 +09:00
Hermet Park
6387615a90 tools/lottie2gif: support background color setting.
A white background will be set by default.

Usage:
$lottie2gif test.lottie -b ff0000 //red background color
2023-12-26 18:30:50 +09:00
Hermet Park
750e4d6261 wasm: Set a GIF background color.
Use a white background by default.
2023-12-26 18:30:42 +09:00
Hermet Park
b1c1958c99 examples/GifSaver: updated with a background usage 2023-12-26 18:30:27 +09:00
Hermet Park
27843d2557 savers: provides a background setting.
Allow users to set a custom background with a saver.

API:
- Result Saver::background(std::unique_ptr<Paint> paint);
2023-12-26 18:30:06 +09:00
Hermet Park
5129b05023 lottie/parser: ++ blending options
thorvg blending is quite buggy,
the feature needs a verification.
2023-12-26 18:24:21 +09:00
Hermet Park
5401b1ae2e examples: show users the best practice usage. 2023-12-26 18:24:04 +09:00
Hermet Park
39022851b7 sw_engine: ++null safety 2023-12-26 18:23:54 +09:00
Hermet Park
965e58806a lottie/builder: Fix a broken animation
The animation couldn't be triggered on a single thread.
Regression bug introduced by 29b5bc372d
2023-12-26 18:23:46 +09:00
Hermet Park
4ba8ff1e11 lottie/loader: Corrected an issue with the return value when loading fails.
Previously, Picture::load(const char* data, uint32_t size, const std::string& mimeType, bool copy = false)
would return 'Success' even when the data is invalid.

This issue only occurred when the number of threads is set to 0.
2023-12-26 18:23:40 +09:00
Hermet Park
042693ccfe renderer/loader: code refactoring
Move the raw image loading interface to the RawImageLoader.
it is only valid for this component.
2023-12-26 18:23:25 +09:00
Hermet Park
a37649cd1f doc: make it up missing parameter information. 2023-12-26 18:21:01 +09:00
Hermet Park
3efb659e48 capi: udpated the doc.
BETA_API -> Experimental API
2023-12-26 18:19:46 +09:00
Hermet Park
cd216a5235 example: renamed a sample, Svg2 -> DataLoad
The sample actually intends to test Picture::load() with a data.
2023-12-26 18:18:57 +09:00
Sergii Liebodkin
bad02c7de0 Added ability to draw solid strokes with dashes
[issues 1479: Shape](https://github.com/thorvg/thorvg/issues/1479)

In order to build you need third party libraries. Before you start please read this: [LearnWebGPU](https://eliemichel.github.io/LearnWebGPU/getting-started/hello-webgpu.html)

Usage example:

    // init glfw
    glfwInit();

    // create a windowed mode window and its opengl context
    glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
    GLFWwindow* window = glfwCreateWindow(800, 800, "WebGPU base app", nullptr, nullptr);

    // get window size
    int width{}, height{};
    glfwGetWindowSize(window, &width, &height);

    // init engine webgpu
    tvg::Initializer::init(tvg::CanvasEngine::Wg, 0);

    // create wg canvas
    auto canvasWg = tvg::WgCanvas::gen();
    canvas_wg->target(glfwGetWin32Window(window), width, height);

    //Test for Stroke Dash for Arc, Circle, Rect
    auto shape = tvg::Shape::gen();
    shape->appendArc(70, 600, 160, 10, 30, true);
    shape->appendCircle(70, 700, 20, 60);
    shape->appendRect(130, 710, 100, 40);
    shape->strokeFill(255, 0, 0);
    shape->strokeWidth(5);
    shape->strokeJoin(tvg::StrokeJoin::Round);
    shape->strokeCap(tvg::StrokeCap::Round);
    float dashPattern[2] = {20, 10};
    shape->strokeDash(dashPattern, 2);
    if (canvas_wg->push(std::move(shape)) != tvg::Result::Success) return;

    while (!glfwWindowShouldClose(window)) {
        // webgpu
        canvas_wg->draw();
        canvas_wg->sync();

        // pull events
        glfwPollEvents();
    }

    // terminate engine and window
    tvg::Initializer::term(tvg::CanvasEngine::Wg);
    glfwDestroyWindow(window);
    glfwTerminate();
2023-12-26 18:18:48 +09:00
Sergii Liebodkin
41ea198a5e Added ability to draw solid strokes
[issues 1479: Shape](https://github.com/thorvg/thorvg/issues/1479)

In order to build you need third party libraries. Before you start please read this: [LearnWebGPU](https://eliemichel.github.io/LearnWebGPU/getting-started/hello-webgpu.html)

Usage example:

    // init glfw
    glfwInit();

    // create a windowed mode window and its opengl context
    glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
    GLFWwindow* window = glfwCreateWindow(800, 800, "WebGPU base app", nullptr, nullptr);

    // get window size
    int width{}, height{};
    glfwGetWindowSize(window, &width, &height);

    // init engine webgpu
    tvg::Initializer::init(tvg::CanvasEngine::Wg, 0);

    // create wg canvas
    auto canvasWg = tvg::WgCanvas::gen();
    canvas_wg->target(glfwGetWin32Window(window), width, height);

    //Test for Stroke Dash for Arc, Circle, Rect
    auto shape = tvg::Shape::gen();
    shape->appendArc(70, 600, 160, 10, 30, true);
    shape->appendCircle(70, 700, 20, 60);
    shape->appendRect(130, 710, 100, 40);
    shape->strokeFill(255, 0, 0);
    shape->strokeWidth(5);
    shape->strokeJoin(tvg::StrokeJoin::Round);
    shape->strokeCap(tvg::StrokeCap::Round);
    if (canvas_wg->push(std::move(shape)) != tvg::Result::Success) return;

    while (!glfwWindowShouldClose(window)) {
        // webgpu
        canvas_wg->draw();
        canvas_wg->sync();

        // pull events
        glfwPollEvents();
    }

    // terminate engine and window
    tvg::Initializer::term(tvg::CanvasEngine::Wg);
    glfwDestroyWindow(window);
    glfwTerminate();
2023-12-26 18:18:42 +09:00
Hermet Park
f5e6fce5c1 gif: corrected the wrong aspect ratio scaling. 2023-12-26 18:18:33 +09:00
Hermet Park
58311ee5c3 saver/gif: Fix a clipping issue.
The Lottie loader missed handling the base clipper resizing.
This patch addresses the issue.
2023-12-26 18:18:27 +09:00
Hermet Park
acb67dad8c saver/gif: up to date the gif encoder.
this fixes the memory sanitizer report:

../src/savers/gif/gif.h:315:31: runtime error: index 255 out of bounds for type 'unsigned char [255]'
../src/savers/gif/gif.h:113:54: runtime error: index 255 out of bounds for type 'unsigned char [255]'

Issue: https://github.com/thorvg/thorvg/issues/1758
2023-12-26 18:18:21 +09:00
Hermet Park
875b623c95 binding/wasm: updated save features
- removed the compression option
- added an animation save function.
2023-12-26 18:17:41 +09:00
Hermet Park
2c382e3d9b doc: keep the style clean & neat 2023-12-26 18:17:41 +09:00