Commit graph

213 commits

Author SHA1 Message Date
Hermet Park
e947fef9a4 common: introduce iterator
+++

auto picture = tvg::Picture::gen();

auto func = [](const tvg::Paint* paint, const tvg::Paint* parent, bool hasChildren) -> int
{
    if (paint->identifier() == Shape::identifier())
        //TODO: override properties.

    //return true to continue, return false to stop.
    return true;
};

picture = tvg::Iteratorv::iterate(move(picture), func);
2021-12-17 12:16:14 +09:00
Hermet Park
1d4db59a25 common: revise the identifier() implementation
Migrate the id property to the base class internals
so that pimpl classes could access the data easier.

This is a sort of prerequisite change for the coming texmap anti-aliasing.
2021-12-13 19:10:31 +09:00
Hermet Park
4cdf648e14 sw_engine image: support non-premultiplied alpha images.
Previously, translucent png images are not displayed properly
due to alpha channels premultiplication.

This patch implements that missing part to support it properly
by introducing the Surface data between canvas engine & rasterizer

@Issue: https://github.com/Samsung/thorvg/issues/655
2021-12-02 17:10:12 +09:00
Hermet Park
e2dd889e1a apis: promote beta apis to the official ones.
these apis are good to open in the next release.
2021-11-11 14:17:43 +09:00
Hermet Park
3b2e1f4291 Revert "loaders: Consider colorspaces (#838)"
This reverts commit cd5116b053.

Ah this breaks the Stress example due to Picture::duplicate() is not available...

Need to consider and come back again.
2021-11-01 16:53:25 +09:00
Michal Maciola
cd5116b053
loaders: Consider colorspaces (#838)
* common: added colorSpace() function

This patch introduces colorSpace() function for SW and GL engine.

* infra: change LoadModule:read() into LoadModule:read(uint32_t colorspace)

This patch changes LoadModule:read() into LoadModule:read(uint32_t colorspace)

* picture: implement passing colorspace into loader

This patch implements passing colorspace into loaders.
Loader->read is now called on the first update.

* external_jpg_loader: support colorspaces

* external_png_loader: support colorspaces
2021-11-01 16:10:22 +09:00
Michal Maciola
479cea74cc common: Unmultiplicated colorspace
This patch introduces _STRAIGHT colorspaces (ABGR8888_STRAIGHT and
ARGB8888_STRAIGHT) whose colors are un-alpha-premultiplied. Unmultiplicated
colors are especially needed for wasm thorvg loader and svg2png / tvg2png.
Only C version now.

@issue: #791
2021-11-01 15:57:13 +09:00
Hermet Park
f24409a76d doc: updated api doc.
use @retval for the multiple return values.
2021-10-23 11:52:10 +09:00
Hermet Park
47334800c6 common: code refactoring
renamed internal module name IteratorModule -> IteratorAccessor
2021-10-22 23:20:29 +09:00
Hermet Park
999c01ede8 api: not allow the inheritance of the Saver.
We missed the final keyword for the Saver,
This inheritance is out of our policy.

It might be break apis but Saver class is just opened,
and we're pretty sure that there is no any extension of this.

I know this is the bad decision, but we have a chance yet,
so we must correct it before further late.
2021-10-22 19:15:05 +09:00
Hermet Park
36270f588e common: replace the id() -> identifier() 2021-10-22 18:47:05 +09:00
Hermet Park
78d85d714a common: Introduce class type identifier apis.
This identifier is useful when user identify the instance type in runtime.

ThorVG basically don't prefer to dynamic_cast() nor typeid(),
it compiles with -fno-rtti option for the optimial size.

Here is an example for the simple usage.

if (paint->identifier() == Shape::identifier())
  auto shape = static_cast<Shape*>(paint);

@Issue: https://github.com/Samsung/thorvg/issues/693
2021-10-22 18:47:05 +09:00
Ji2z
fcb0258b3c common: Fix typo
Fix typo backeneds to backends
2021-10-22 15:10:02 +09:00
Mira Grudzinska
e0aa007659 common: new api for a grad transformation
The new apii allows to transform the gradient fill.
2021-10-19 17:43:24 +09:00
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