Commit graph

177 commits

Author SHA1 Message Date
JunsuChoi
fe35f69530 common: Fix typo 2021-10-19 16:28:28 +09:00
Mira Grudzinska
39af185de8 docs: ++ 2021-10-12 14:04:18 +02:00
Mira Grudzinska
6a63a5feac docs: saver module description ++ 2021-10-12 14:52:20 +09:00
Mira Grudzinska
dc55070ba7 docs: c and c++ apis docs improved 2021-10-06 22:11:17 +09:00
Mira Grudzinska
e7c3a91aa1 all: fixing clang warnings
fopen->fopen_s, strdup -> _strdup, strncpy -> strncpy_s
__declspec(dllexport) -> __attribute__ ((visibility ("default")))
2021-10-06 11:13:12 +09:00
Mira Grudzinska
fc29d888f1 docs: ++ docs of the load apis 2021-10-05 14:16:41 +02:00
Mira Grudzinska
5b7f94a527 capi: picture size apis added 2021-10-05 16:03:10 +09:00
Mira Grudzinska
aeda0e0ad3
docs: minor changes (#868) 2021-10-04 10:03:48 +02:00
Mira Grudzinska
9ad9c3e3f4
docs: improving c++ and c apis docs 2021-10-01 15:10:40 +09:00
Mira Grudzinska
79f7c744c5 svg_loader: fixing minor warnings 2021-09-28 12:07:52 +02:00
Hermet Park
74954db56d common paint: refine the bounds() api to return the values after applying transformation.
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
2021-09-24 11:25:49 +09:00
Hermet Park
000d3ec2f0 apis: release official apis.
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;
2021-09-24 11:25:27 +09:00
Hermet Park
e784143ff8 api: remove the redundant api, Picture::paint().
tvg::Picture is replaced to tvg::Scene if the picture has the vector tree,
Thus it's useless since it won't be reached logically.
2021-09-23 20:15:23 +09:00
Hermet Park
4e9452c4b8 api: removed unused 2021-09-09 14:18:46 +09:00
Michal Maciola
2a2ccb30bd
Wasm: allow iterator and add functions for layers revising (#730)
* 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
2021-09-09 13:06:13 +09:00
Hermet Park
79933d9efa api: set default value nullptr for user convenience. 2021-09-09 12:40:43 +09:00
Mira Grudzinska
d7cb87971b
docs: minor linguistic changes (#759) 2021-08-31 15:15:03 +02:00
JunsuChoi
700abffd38 doc: Enhance appendPath docs
Added description according to api behavior change
2021-08-30 11:07:47 +09:00
Hermet Park
52a7a257b2 tvg_format: newly introduced for tvg data compression.
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.
2021-08-24 14:24:17 +09:00
Hermet Park
a4ccf4d812 common picture: recover viewbox() api.
though picture has size() api, we have a regression issue in tizen,
we can't remove this api until we resolve any regression conditions.
2021-08-09 12:39:21 +09:00
Hermet Park
d0efdb9854 api: add deprecated syntax for deprecated apis. 2021-08-05 19:23:39 +09:00
Michal Maciola
cff8815404
loaders: Pass mimetype to picture::load
* loaders: Pass mimetype to picture::load

Added mimetype attribute to enfaster loading using a proper loader.

@Changed api: Picture::load(const char* data, uint32_t size, const std::string& mimeType, bool copy = false)
@issue: #571
2021-08-05 11:02:26 +09:00
Hermet Park
02081d8cdc common picture: correct non-working size() behavior.
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
2021-07-29 11:44:18 +09:00
Hermet Park
f7f241cff5 common picture: remove viewbox() api.
picture provides size() interface to return the image size,
viewbox() is conceptually not correct with the Picture.

Remove it under the beta api.
2021-07-28 13:07:43 +09:00
Hermet Park
589a1d871b picture: paint() method shall not be public. 2021-07-26 20:45:02 +09:00
Mira Grudzinska
82c7a96628 doc: ++ MemPool docs 2021-07-26 15:07:35 +09:00
Hermet Park
02b0f6cfc9 doc: improved Saver documentation. 2021-07-23 14:19:17 +09:00
Hermet Park
05737f979f apis: promote beta apis to the official ones.
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;
2021-07-23 14:09:37 +09:00
Hermet Park
fe00e54257 tvg_saver: introduce a new module tvg saver
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>
2021-07-21 19:30:15 +09:00
Hermet Park
e0667ca7f1 tvg format: code refactoring #8
Hide iterator APIs, simplify it as much as it's necessary.
2021-07-20 20:06:55 +09:00
Hermet Park
8059a23f7c tvg format: code refactoring #2
code clean up, removed reserved data sector
2021-07-20 12:53:16 +09:00
Hermet Park
60e3129ce2 common saver: change to instance based for future sync/async behavior.
reserve sync() method TODO
2021-07-19 20:32:31 +09:00
Mira Grudzinska
0150391f03
tvg_saver: implementation of the Saver class
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.
2021-07-19 17:31:36 +09:00
Mira Grudzinska
f23cba89f3
common: introducing basic iterators functionality
The introduced Iterator class enables to access the children nodes
of a given Paint.
2021-07-19 17:28:14 +09:00
Hermet Park
8aa941c4ab common picture: ++exception case.
Fixed load() to return InvalidArgument if the file path is invalid.
2021-07-02 14:01:52 +09:00
Hermet Park
2fd830c940 common shape: allow to reset stroke dash.
user may need to reset stroke dash to off,
now stroke api allows it.
2021-07-02 10:35:46 +09:00
Mira Grudzinska
6eea979dae common: introducing the composite API (getter)
The new API gets the composite method and the pointer to the composite
target of the given paint object.
2021-06-25 22:16:06 +09:00
Mira Grudzinska
96d6b47a64 common: PaintType enum changed to identifier in Paint class
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.
2021-06-25 22:13:20 +09:00
Hermet Park
ea668eae1d fix a build break in MSVC
add missing string header, string is used for a Picture::load() parameter
2021-06-22 14:35:46 +09:00
Hermet Park
0df8c00519 loaders: revise code from cce4b443b3
use copy variable instead of additional buffer pointer.
2021-06-22 10:42:34 +09:00
Michal Maciola
cce4b443b3 loaders: added copy param for Picture::load
@API Changed:
Result Picture::load(const char* data, uint32_t size, bool copy /*=false*/) noexcept
TVG_EXPORT Tvg_Result tvg_picture_load_data(Tvg_Paint* paint, const char *data, uint32_t size, bool copy);
2021-06-21 19:52:38 +09:00
mmaciola
16e39ee81b
TVG Loader/Saver: tvg loader introduced
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.
2021-06-11 12:49:37 +09:00
Hermet Park
13009657cd common canvas: supplement corner cases.
filled up corner cases to return the result properly.

Canvas newly has a drawing condition to prevent usage-violation.
2021-06-09 20:11:57 +09:00
Hermet Park
efa0035fe6 common initializer: correct the result value.
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.
2021-06-03 20:48:02 +09:00
Hermet Park
c2b2aa92c3 infra: install capi header file only its binding option is enabled.
decouple the capi header from the default headers by replacing it in capi folder.
now it's also installed optionally.
2021-06-03 20:43:39 +09:00
Mira Grudzinska
ed7d8b73b9 common: added API to get the transformation matrix of the object 2021-06-02 19:03:20 +09:00
Hermet Park
2c37191584 api: --inproper const syntax.
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
2021-06-02 16:42:08 +09:00
Hermet Park
54fa59e7c3 docs: -- beta tag.
Scene::clear() is ready to public.
2021-05-28 16:24:48 +09:00
Hermet Park
0394fa5ef5 common: fix a potential memory leak after clear()
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;
2021-05-28 16:19:01 +09:00
Hermet Park
af01f5b899 api doc: replace beta api desc to beta tag 2021-05-14 19:49:28 +09:00