Current paint::bounds() returns the coordinates under the raw status,
the values are not quite useful if the paint object has the transformed children.
Thus, we extends the feature and give an additional parameter "transformed"
to return the coordinates values after transformation by user demands.
This is also necessary for tvg format, since we need the exact view size of the scene information.
The previous api is deprecated and we introduce a new api to replace it.
@APIs:
+ Result Paint::bounds(float* x, float* y, float* w, float* h, bool transformed) const noexcept;
- Result Paint::bounds(float* x, float* y, float* w, float* h) const noexcept;
@Issues: https://github.com/Samsung/thorvg/issues/746
tvg picture is going to be released, we need the Saver as well.
Also, two stable periperal apis are released in v0.5
@APIs:
Result Picture::load(const char* data, uint32_t size, const std::string& mimeType, bool copy = false) noexcept;
CompositeMethod Paint::composite(const Paint** target) const noexcept;
Result Saver::save(std::unique_ptr<Paint> paint, const std::string& path, bool compress = true) noexcept;
Result Saver::sync() noexcept;
static std::unique_ptr<Saver> Saver::gen() noexcept;
* common: move iterator functionality into separate IteratorModule
* wasm: allow internal lib dependencies and iterator
* wasm: added functions for layers revising
This patch adds functions to thorvgwasm.cpp:
layers() - that return a list of paints in a picture
bounds() - that returns a bounds of a given paint
setOpacity() - that sets the opacity of a given paint
By choosing compress option, tvg tries to compress the data to reduce the binary size.
Since the compression has the double-edges sword, we provides an option to users
to select it by their demand. Basically, compression is better than non-compression.
After profiling, we decided to use the encoder/decoder of Guilherme R. Lampert's.
Here is the profiling result:
test.tvg: 296037 -> 243411 (-17%)
tiger.tvg: 54568 -> 50622 (-7%)
image-embedded.tvg: 2282 -> 1231 (-46%)
@Issue: https://github.com/Samsung/thorvg/issues/639
About compression method:
Lempel–Ziv–Welch (LZW) encoder/decoder by Guilherme R. Lampert
This is the compression scheme used by the GIF image format and the Unix 'compress' tool.
Main differences from this implementation is that End Of Input (EOI) and Clear Codes (CC)
are not stored in the output and the max code length in bits is 12, vs 16 in compress.
EOI is simply detected by the end of the data stream, while CC happens if the
dictionary gets filled. Data is written/read from bit streams, which handle
byte-alignment for us in a transparent way.
The decoder relies on the hardcoded data layout produced by the encoder, since
no additional reconstruction data is added to the output, so they must match.
The nice thing about LZW is that we can reconstruct the dictionary directly from
the stream of codes generated by the encoder, so this avoids storing additional
headers in the bit stream.
The output code length is variable. It starts with the minimum number of bits
required to store the base byte-sized dictionary and automatically increases
as the dictionary gets larger (it starts at 9-bits and grows to 10-bits when
code 512 is added, then 11-bits when 1024 is added, and so on). If the dictionary
is filled (4096 items for a 12-bits dictionary), the whole thing is cleared and
the process starts over. This is the main reason why the encoder and the decoder
must match perfectly, since the lengths of the codes will not be specified with
the data itself.
Pixel-based image picture doesn't work at size() method.
Obvisouly, we missed to implement it properly.
This patch corrects it.
@Issue: https://github.com/Samsung/thorvg/issues/656
3 api candidates has been verified since it's tagged in beta,
we confirm that they are useful for tvg usages.
Here list shows the candidates apis:
@API Addition:
Matrix Paint::transform() noexcept;
CompositeMethod Paint::composite(const Paint** target) const noexcept;
Result SwCanvas::mempool(MempoolPolicy policy) noexcept;
tvg saver is a new module to export tvg files.
In this patch, it also contains the infrastructure of saver module
to expand other types of savers such as png, jpg, etc.
To save the tvg file from a paint, you can use the Saver feature, for example:
auto saver = tvg::Saver::gen();
saver->save(paint, "sample.tvg");
saver->sync();
Later, you can read the "sample.tvg" using Picture.
auto picture = tvg::Picture::gen();
picture->load("sample.tvg");
...
The behavior of the saver will work on sync/async based on the threading setting of the initializer.
Thus if you wish to have a benefit of it, you must call sync() after the save() in the proper delayed time.
Otherwise, you can call sync() immediately.
Note that, the asynchronous tasking is depent on the saver module implementation.
Also, you need to enable tvg saver/loader modules from meson option. (yet this feature is under the beta)
@API Addition:
Result Saver::save(std::unique_ptr<Paint> paint, const std::string& path) noexcept;
Result Saver::sync() noexcept;
@Examples: tvgSaver
@Co-author: Mira Grudzinska <m.grudzinska@samsung.com>
The Saver class enables to save any Paint object (Scene, Shape, Picture)
in a binary file. To read the file the tvg loader should be used.
To save a paint a new API was introduced - tvg::Saver::save.
The PaintType enum was used to set the paint type in the internal Paint
implementation. This solution is switched to an identifier with id() getter,
so that the information about the type can be reached from outside the Paint.
This patch introduces tvg loader module for loading .tvg binary files.
This allows to load and reuse pregenerated scene.
tvg file format:
.tvg is a binary file format designed for saving/restoring the scene content.
It allows to save scenes and reuse them in other apps or to restore state of
the application.
@Example:
auto picture = tvg::Picture::gen();
picture->load(EXAMPLE_DIR"/tvg_file.tvg");
canvas->push(move(picture));
@API Additions:
Result paint(std::unique_ptr<Paint> paint) noexcept;
@Issue: Issue ticket is #375.
When memory is not allocated successully, it must return the FailedAllocation as the return value.
Previous initializer wrongly returns the value that case, this corrects it.
compoiste() requires internal data change, its api syntax should not contain "const"
though this changes the api spec, but won't affect build break
since it allows wider usage.
@API Modification
from:
Result Paint::composite(std::unique_ptr<Paint> target, CompositeMethod method) const noexcept
to:
Result Paint::composite(std::unique_ptr<Paint> target, CompositeMethod method) noexcept
Paints must clear canvas engine data if they were dismissed from the canvas,
1. Canvas::clear(free = false) must retain all the paints from the paints hierarchy
so that user keeps the all dangled paints lifecycle.
In this scenario, it could leak the engine data of paints, this patch fixes it.
2. Previously, t just keeps the immediate paints lives of canvas, but not them of children of scene nor picture.
This patch changes a policy which was not considered seriously,
Now it keeps the all paints lives through the tree-hieararchy.
3. Also changed the Scene::clear() behavior identical to Canvas::clear() for consistency.
@API Modification:
From: Result Scene::clear() noexcept;
To: Result Scene::clear(bool free = true) noexcept;
We have encountered that multi-threading usage that user creates,
multiple canvases owned by multiple user threads.
Current sw_engine memory pool has been considered only for multi-threads,
spawned by tvg task scheduler.
In this case it's safe but when user threads introduced, it can occur race-condition.
Thus, Here is a renewal policy that non-threading tvg(initialized threads with zero),
takes care of multiple user threads bu changing its policy,
each of canvases should have individual memory pool to guarantee mutual-exclusion.
@API additions
enum MempoolPolicy
{
Default = 0, ///< Default behavior that ThorVG is designed to.
Shareable, ///< Memory Pool is shared among the SwCanvases.
Individual ///< Allocate designated memory pool that is only used by current instance.
};
Result SwCanvas::mempool(MempoolPolicy policy) noexcept;
All in all, if user calls multiple threads, set memory pool policy to Individual.
TVG_RESULT_INVALID_ARGUMENT returned in case a nullptr passed as an argument
(does not apply to color getters).
The change is addressed in the docs file.