Commit graph

2408 commits

Author SHA1 Message Date
Hermet Park
08252990a6 wasm: Set a GIF background color.
Use a white background by default.
2023-11-14 10:47:52 +09:00
Hermet Park
1fddcd3af2 examples/GifSaver: updated with a background usage 2023-11-14 10:47:52 +09:00
Hermet Park
561a6d8935 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-11-14 10:47:52 +09:00
Hermet Park
0611e7088c lottie/parser: ++ blending options
thorvg blending is quite buggy,
the feature needs a verification.
2023-11-13 13:53:50 +09:00
Hermet Park
86bdf30479 examples: show users the best practice usage. 2023-11-10 13:56:11 +09:00
Hermet Park
33a2ef0b2d sw_engine: ++null safety 2023-11-10 12:12:39 +09:00
Hermet Park
b133b2a8ae lottie/builder: Fix a broken animation
The animation couldn't be triggered on a single thread.
Regression bug introduced by 29b5bc372d
2023-11-10 09:45:13 +09:00
Hermet Park
29b5bc372d 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-11-09 21:41:35 +09:00
Hermet Park
84f683d087 renderer/loader: code refactoring
Move the raw image loading interface to the RawImageLoader.
it is only valid for this component.
2023-11-09 14:46:32 +09:00
Hermet Park
2082343463 doc: make it up missing parameter information. 2023-11-09 14:46:14 +09:00
Hermet Park
d1bae0b44c capi: udpated the doc.
BETA_API -> Experimental API
2023-11-08 10:53:39 +09:00
Sergii
4da90b2847 picture: added ability to support premultiplied for picture raw loader
[issues 1479: picture raw loader to support premultiplied](https://github.com/thorvg/thorvg/issues/1764)

api changes:
    Result Picture::load(uint32_t* data, uint32_t w, uint32_t h, bool copy);
    Result Picture::load(uint32_t* data, uint32_t w, uint32_t h, bool premultiplied, bool copy);

capi changes
    TVG_API Tvg_Result tvg_picture_load_raw(Tvg_Paint* paint, uint32_t *data, uint32_t w, uint32_t h, bool copy);
    TVG_API Tvg_Result tvg_picture_load_raw(Tvg_Paint* paint, uint32_t *data, uint32_t w, uint32_t h, bool premultiplied, bool copy);
2023-11-08 10:46:23 +09:00
Hermet Park
9b3b4b1c63 example: renamed a sample, Svg2 -> DataLoad
The sample actually intends to test Picture::load() with a data.
2023-11-07 19:43:15 +09:00
Sergii Liebodkin
52eca9630c 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-11-06 20:35:26 +09:00
Sergii Liebodkin
a3adbef2c2 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-11-06 20:35:26 +09:00
Hermet Park
2f8c920654 gif: corrected the wrong aspect ratio scaling. 2023-11-06 20:18:13 +09:00
Hermet Park
ebe4672eff saver/gif: Fix a clipping issue.
The Lottie loader missed handling the base clipper resizing.
This patch addresses the issue.
2023-11-06 17:47:14 +09:00
Hermet Park
f71aa2e300 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-11-06 17:47:14 +09:00
Hermet Park
7bf958e913 binding/wasm: remove layer functionality.
We will revisit this function later with a proper design.
2023-11-06 16:54:01 +09:00
Hermet Park
12534e6934 binding/wasm: updated save features
- removed the compression option
- added an animation save function.
2023-11-06 16:54:01 +09:00
Hermet Park
07a6b9cbe4
Update README.md 2023-11-04 21:40:50 +09:00
Hermet Park
4208278bb1
Update README.md 2023-11-04 21:36:57 +09:00
Hermet Park
0687b09c72 doc: keep the style clean & neat 2023-11-03 23:54:58 +09:00
Hermet Park
0819fc9058 binding/wasm: updated save features
- removed the compression option
- added an animation save function.
2023-11-03 23:54:58 +09:00
Hermet Park
4bfdac7140
Update README.md 2023-11-03 17:29:17 +09:00
Hermet Park
024e879ee6 tools/lottie2gif: introduce a new converter tool.
Usage:
   lottie2gif [Lottie file] or [Lottie folder] [-r resolution] [-f fps]

Examples:
    $ lottie2gif input.json
    $ lottie2gif input.json -f 30
    $ lottie2gif input.json -r 600x600 -f 30
    $ lottie2gif lottiefolder
    $ lottie2gif lottiefolder -r 600x600
    $ lottie2gif lottiefolder -r 600x600 -f 30
2023-11-03 17:19:05 +09:00
Jinny You
a60c881b60 docs: Remove all warnings from doxygen 2023-11-03 12:05:21 +09:00
RuiwenTang
a1c3a4a5ad gl_engine: fix memory out of bounds error in GlGpuBuffer
If buffer data is larger than memory alignment, need to make sure there
is enough memory in current stage buffer
2023-11-03 11:21:31 +09:00
Hermet Park
83151933a9 renderer: maintain consistency in the logging domain. 2023-11-02 21:12:58 +09:00
Hermet Park
c3aa1bf8eb
Update AUTHORS 2023-11-02 17:54:28 +09:00
JunsuChoi
d03bf7a089 saver GifSaver: Introduce GifSaver for animation
Add save() API that takes tvg::Animation as a parameter.
This API uses gif.h to create each animation frame as a gif frame.
Gif creation do not support threads because they must be added sequentially.
Please see example/GifSaver.cpp

ex)
auto animation = tvg::Animation::gen();
auto picture = animation->picture();
picture->load(EXAMPLE_DIR"/walker.json");
auto saver = tvg::Saver::gen();
saver->save(std::move(animation), EXAMPLE_DIR"/test.gif");
saver->sync();

New API:
Result Saver::save(std::unique_ptr<Animation> animation, const std::string& path, uint32_t quality = 100, uint32_t fps = 0);

Issue: https://github.com/thorvg/thorvg/issues/1712
2023-11-02 17:50:27 +09:00
Hermet Park
a08b7f0c38 loaders/png: fixed data conversion warnings on Windows
../src/loaders/external_png/tvgPngLoader.cpp(110): warning C4244: '=': conversion from 'float' to 'uint32_t', possible loss of data
../src/loaders/external_png/tvgPngLoader.cpp(111): warning C4244: '=': conversion from 'float' to 'uint32_t', possible loss of data
../src/loaders/external_png/tvgPngLoader.cpp(112): warning C4244: '=': conversion from 'float' to 'uint32_t', possible loss of data
2023-11-02 17:49:41 +09:00
Hermet Park
226c468f72 example/capi: remove saver test.
This generated tvg often make us confused
when Tvg example doesn't show it properly.

It's too small circle.
2023-11-02 11:58:23 +09:00
Hermet Park
d3c60955fa tvg: revise the tvg binary format for 1.0 release
- The TVG binary format now consistently compresses the data.
- Removed redundant internal properties as part of this change.

Please note that this change will break compatibility with the TVG file format from version 1.0 onward.

Issue: https://github.com/thorvg/thorvg/issues/1372
2023-11-02 11:58:23 +09:00
Hermet Park
d879e56856 saver: Revised the API for the 1.0 release
replaced the 'compress' option with 'quality'

API changes:
Result Saver::save(std::unique_ptr<Paint> paint, const std::string& path, bool compress) ->
Result Saver::save(std::unique_ptr<Paint> paint, const std::string& path, uint32_t quality = 100)

TVG_API Tvg_Result tvg_saver_save(Tvg_Saver* saver, Tvg_Paint* paint, const char* path, bool compress) ->
Tvg_Result tvg_saver_save(Tvg_Saver* saver, Tvg_Paint* paint, const char* path, uint32_t quality)

Issue: #1372
2023-11-02 11:58:23 +09:00
Jinny You
82bd8a3f8b examples: Support mac os to execute all 2023-11-02 11:55:34 +09:00
Hermet Park
a607bf586b renderer: ++safety
these member values can be accesssed without update() call.
2023-10-31 15:39:31 +09:00
Hermet Park
2d2928652b wasm: fix a regression bug.
The Animation::frame() method has been modified.
It will now return InsufficientCondition,
if the frame value is the same as the previous one.

In addition to this change, we have also updated its usage accordingly.
2023-10-31 12:03:32 +09:00
Hermet Park
d6fffd13c2 api: revise the engine initializer for the 1.0 release.
This change introduces the CanvasEngine::All type to automatically
initialize the engines available on the current system.

These revisions improve the usability of these APIs.

Addtions:
- enum class CanvasEngine::All

Modifications:
- Result Initializer::init(CanvasEngine engine, uint32_t threads) ->
Result Initializer::init(uint32_t threads, CanvasEngine engine = tvg::CanvasEngine::All)
2023-10-30 11:48:02 +09:00
Mira Grudzinska
25a1321243 common: stroke dash offset support with new apis.
This change just allows users to use the offset of the stroke dash.
Actually feature enhacement has been introduced by
478e45f9f3.

@APIs:
uint32_t Shape::strokeDash(const float** dashPattern) ->
uint32_t Shape::strokeDash(const float** dashPattern, float* offset = nullptr)

Result Shape::strokeDash(const float* dashPattern, uint32_t cnt) ->
Result Shape::strokeDash(const float* dashPattern, uint32_t cnt, float offset = 0.0f)

Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* dashPattern, uint32_t cnt) ->
Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* dashPattern, uint32_t cnt, float offset)

Tvg_Result tvg_shape_get_stroke_dash(const Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt) ->
Tvg_Result tvg_shape_get_stroke_dash(const Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt, float* offset)

@Issue: https://github.com/thorvg/thorvg/issues/1372
2023-10-30 11:47:51 +09:00
Hermet Park
f3a2d2a5a6 portability: addressed all compilation warnings from MSVC 2023-10-27 14:20:50 +09:00
Hermet Park
bb30db429e lottie: fixed all memory access violations. 2023-10-27 13:50:13 +09:00
Hermet Park
baee5ec767 renderer/paint: added a blend update flag.
Keep track of the update changes accurately.
We can utilize this value change in the backend engine.
2023-10-27 12:13:00 +09:00
Hermet Park
c77ef98fef lottie/builder: enable layer blending
Issue: https://github.com/thorvg/thorvg/issues/1737
2023-10-27 12:13:00 +09:00
Hermet Park
db55481e97 renamed stroke apis family.
float Shape::stroke(float width) -> float Shape::strokeWidth(float width)
Result Shape::stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) -> Result Shape::strokeFill(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255)
Result Shape::stroke(std::unique_ptr<Fill> f) -> Result Shape::strokeFill(std::unique_ptr<Fill> f)
Result Shape::stroke(const float* dashPattern, uint32_t cnt, float offset = 0.0f) ->  Result Shape::strokeDash(const float* dashPattern, uint32_t cnt, float offset = 0.0f)
Result Shape::stroke(StrokeCap cap) -> Result Shape::strokeCap(StrokeCap cap)
Result Shape::stroke(StrokeJoin join) -> Result Shape::strokeJoin(StrokeJoin join)
Result Shape::strokeColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a = nullptr) const -> Result Shape::strokeFill(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a = nullptr) const

@Issue: https://github.com/thorvg/thorvg/issues/1372
2023-10-27 11:46:51 +09:00
Hermet Park
989b995189 renderer: revise the internal paints structure.
Get rid of the polymorphism function table,
use the switch directly instead.

We profiled, both binary & performance is better than before.

Tested on a local machine (single thread):
- Lottie: 2ms improved
- Binary: -0.5kb
2023-10-27 11:24:44 +09:00
Hermet Park
5a3bc31373 lottie: ++optimization with a caching effect.
reuse clippers if they are available.

Binary: +132
2023-10-26 15:24:36 +09:00
Hermet Park
d37c500262 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
2023-10-26 15:24:36 +09:00
Hermet Park
978f85c3ea apis: optimize for compact data size.
Still it needs to size down of the PathCommand.

@Issue: https://github.com/thorvg/thorvg/issues/1372
2023-10-26 15:11:31 +09:00
Hermet Park
21911fa1c8 apis: remove deprecated
- Result Picture::bounds(float* x, float* y, float* w, float* h) const
- Result Picture::load(const char* data, uint32_t size, bool copy = false)
- Result Canvas::reserve(uint32_t size)
- Result Scene::reserve(uint32_t size)

@Issue: https://github.com/thorvg/thorvg/issues/1372
2023-10-26 15:03:13 +09:00