Commit graph

313 commits

Author SHA1 Message Date
Hermet Park
a3ecff9504 svg_loader util: fix the floating constant truncated to zero issue.
fyi, the minimum value of the float is 1.175494351 E-38

@Issue: https://github.com/Samsung/thorvg/issues/899
2021-10-15 15:20:01 +09:00
Mira Grudzinska
1abee9f8d5 svg_loader: fixing viewBox clipping
For vw=width and vh=height, vx or vy > 0 had no effect. Fixed
2021-10-15 12:33:26 +09:00
Michal Maciola
e186bb4a82 svg_loader util: fix missing quot
There was checking for 0 ('\0') that should be checking for '0'
2021-10-15 02:04:17 +09:00
Hermet Park
d9f421ff4a svg_loader util: just fix a typo
exponet -> exponent
2021-10-13 20:12:51 +09:00
Hermet Park
5a6240bdf3 svg_loader util: code refactoring
fix for thorvg coding convention.

no logical changes.
2021-10-13 20:07:08 +09:00
Mira Grudzinska
0497ac894e svg_loader: removed unused variable
The gradient values passed to the scene builder are always given as percentages,
so there is no need to mark/check that.
2021-10-13 18:40:05 +09:00
Mira Grudzinska
c2bbdccac1 svg_loader: removed unnecessary casting
The used scaling factor should be a float - casting it to an int caused
misevaluation of the radial gradient radius
2021-10-11 18:59:23 +09:00
projectitis
dad6c71b6c
all: fix warnings on MSVC
* Explicit casts to suppress warnings
* Fixed compiler warnings
2021-10-09 11:33:45 +09:00
JunsuChoi
5e7981106b infra : add window build (with loaders) 2021-10-07 15:00:48 +09:00
Mira Grudzinska
a16e91b441 all: fix compiler warnings
pow->powf and sqrt->sqrtf
2021-10-07 14:49:00 +09:00
Hermet Park
a2ac28d0c5
infra: add all option to enable all loader formats.
just for developer convenience (including me)

ex) $meson . build -Dloaders="all" ...
2021-10-06 11:13:49 +09:00
Hermet Park
ff20974632 loaders: prepare for static jpg/png loaders.
This patch has 2 purposes,

1. revise the loaders infrastructure to support both static/external linking loaders.
2. add a template for static jpg/png loaders after external jpg/png.

Our default loaders prefer static linking, external loaders are only available
when dependent libraries on the build system are found.

You might wonder why we have the external loaders together,
they might be faster than static loaders since the popular libraries are likely to be well maintained,
fine-grained optimized.

Thus in this patch, meson tries to apply the external loaders first
then see if the dependencies were found or not,
if it's failed, it turns to the default static loaders.

Next this patch, we need the contribution for actual static jpg/png loaders implementation.

@Issue: https://github.com/Samsung/thorvg/issues/594
2021-10-05 19:22:51 +09:00
Mira Grudzinska
875e5bd058
svg_loader: proper handling width/height units (#851)
Units of the svg width and height tags were incorrectly assigned.
Percentage values will be handled separately.
2021-10-05 12:04:40 +02:00
Projectitis
591ea1d61c Changes to support MSVC 2021-09-29 22:56:52 +09:00
Mira Grudzinska
79f7c744c5 svg_loader: fixing minor warnings 2021-09-28 12:07:52 +02:00
Hermet Park
c8cc973888 tvg_loader: resolve sanitizer report.
"runtime error: load of misaligned address 0x7fb67895c815 for type 'unsigned int', which requires 4 byte alignment"

This is actually not an issue but we can resolve it with an easy workaround,
since we don't need to see this report repeatedly.
2021-09-24 11:53:46 +09: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
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
Michal Maciola
702f452c6c svg: fix url property
If 'fill="url(#image)"' and defs with id 'image' was not found, the paint was
improperly filled with color.
2021-09-21 20:20:59 +02:00
Mira Grudzinska
4589196689
common: preventing msvc compiler warnings (#817) 2021-09-20 13:54:06 +02:00
Hermet Park
75e1310c7a prepare to release tvg format feature. 2021-09-16 17:46:10 +09:00
Mira Grudzinska
c9c3776207 svg_loader: proper svg resizing
Solves the problem of 'vx' and 'vy' < 0 and cases with 'width'
and 'height' values different than widht and height from the 'viewBox'
attribute.
2021-09-15 19:12:43 +09:00
Hermet Park
e381edacb7 tvg_loader: code refactoring.
no logical changes in the succesful cases,

change the code for better readibility.
and add log messages in the error scenario.
2021-09-07 18:18:09 +09:00
Mira Grudzinska
b421660676 svg_loader: parsing flags in the elliptical arc curve
Since the arc flags can have values 0 or 1, we reported as
an error cases, when a float value was given.
Since the EBNF grammar can be used, we misread some paths.
Removing the condition that prevents giving a float as a flag solves
this problem and is in agreement with the w3 specs.
2021-09-07 13:15:50 +09:00
Hermet Park
d21089ddfd
tvg_saver: save the missing scene reserve count. (#771)
This reserved count was just missed,
Aside from it, tvg_loader logic is not well organized (hard to expect)
We can refine it by recovering the data tree structure in the reverse order.

@Issues: https://github.com/Samsung/thorvg/issues/768
2021-09-06 08:38:18 +02:00
Hermet Park
eddd253c55
tvg_loader: code refactoring & optimization loading. (#772)
Skip the reassigning values by the flags,
We assume those property values are reserved,
leave to apis that handle the invalids if the exceptions.
2021-09-06 08:35:11 +02:00
Hermet Park
c6becf4ec6 tvg_loader: guarantee the buffer ends with the null character
the issue is detected by asan.
2021-08-30 21:36:09 +09:00
Hermet Park
37e8011325 tvg_loader: fixed a wrong delete call.
delete is not expected here, malloc-free must be paired.
2021-08-30 15:36:31 +09:00
Michal Maciola
fe474856b9 tvg_loader: make sure the pointer does not exceed the size 2021-08-27 11:45:37 +09:00
Hermet Park
d599f744c8 tvg format: fix broken encoding/decoding.
a regression bug was introduced by 52a7a257b2
in size calculation of data in case of uncompressed version.

@Issue: https://github.com/Samsung/thorvg/issues/739
2021-08-25 21:48:30 +09:00
Michal Maciola
ae3141d65c svg: fix opacity percentage value parsing
Percentage values wasn't handled by _toOpacity() function. Other incorrect values
was handled wrongly. Now fixed.
2021-08-25 14:57:30 +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
Michal Maciola
e6ebb5379b common: RenderRegion x, y protect against negative value in unsigned int
This change protects against negative value in unsigned int of
RenderRegion.x/y. This fixes a problem of invisible paint if ClipPath
bounds was negative.

@issue: #704
2021-08-11 21:46:59 +09:00
Hermet Park
41ad6e16e9 --annoying compiler warnings. 2021-08-09 21:24:27 +09:00
Hermet Park
ae8120bb29 infra: fix missing tvg -> tvg_beta tag.
breakage was introduced by 6ad1b1bf73
2021-08-09 12:57:00 +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
b6590314f6 tvg_saver: add 4 bytes reserved area for future extensions.
This memory can be used for storing feature flags.
2021-08-09 12:10:11 +09:00
Michal Maciola
3d88d7eefc
JPG loader: print error string on failure
Added error string printing on jpg image loading failure.
The error message help developer find the corrupted jpg file.
Error message is not printed for open from char* data as there the
loaders are tried on by one.
2021-08-07 12:00:04 +09:00
Hermet Park
78f6f9d896 tvg_loader: introduce tvg interpreter base class for future extension.
tvg binary format might break the compatibility if any major features have been changed.
It's allowed to do it when the major version is upgraded.

In that case, still we need to support the backward compatibility,
we can provide multiple binary interpreters and choose the proper one
based on the current loading tvg binary format version.

Thus, you can add further interpreters if it's necessary in the future.
Our policy is to derive the TvgBinInterpreterBase class to make it running on
the interface.

for example, if the major version is upgraded 1.x, you can implement TvgBinInterpreter1.
2021-08-05 19:26:04 +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
a042e771e4
tvg_format: force to check for compatibility by version comparision.
tvg file stores the version info of thorvg when it's generated,
in order to compare it with the runtime thorvg version when it's loaded.

For this, thorvg builds up the current version of symbol on the initilaization step,
that can be referred by the tvg loader.
2021-08-04 15:31:06 +09:00
Hermet Park
b3aed50a2e common loader: lookup in the numberic order. 2021-07-30 12:36:19 +09:00
JunsuChoi
b72ff371ee svg_loader SvgLoader: Add 'href' attribute for parser
"xlink:href" will be deprecated.
https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/xlink:href
2021-07-30 12:26:27 +09:00
Hermet Park
e59ba67b7c tvg_format: optimize data format
This reduces tvg binary format size by converting PathCommand to more compact size.

This optimization increase +12% compress rate with our example:

195,668 => 174,071 (sum of all converted tvgs from svgs)

@Issues: https://github.com/Samsung/thorvg/issues/639
2021-07-30 10:35:30 +09:00
Hermet Park
2db5d24c9f tvg_loader: code refactoring.
keep the macro naming convention
2021-07-29 17:26:36 +09:00
Hermet Park
4bdf346dbb tvg format: code refactoring
use SIZE() macro for consistency.
2021-07-29 16:45:14 +09:00
Hermet Park
87c6ce1f7c tvg_format: save/restore default view size in the data.
current bounding box of the paint is the default view size...

Do we have any better information of that?
2021-07-29 15:51:00 +09:00
Michal Maciola
eb810a92f2
svg_loader: allow multiple defs tags
If svg contained multiple defs tags only the first one was handled correctly.
Every next 'defs' tag was skipped and its inner elements parsed as it was
outside the defs.
2021-07-29 11:47:33 +09:00
Hermet Park
d213a67180 common loader: code refactoring
Bitmap based pictures doesn't need the viewbox,
LoaderModule should delegate the viewbox to the derived classes which
having vector-based image loaders such as svg, tvg.

In that case, paint resizing can be performed by the loaders by own
policy.
2021-07-28 14:16:18 +09:00
Hermet Park
3cb0caf2c4 common loader: code refactoring.
replace from Scene to Paint at the internal interface.

Picture doesn't need to know the returned Node type.
base class, Paint is enough to in the data passing.
2021-07-28 13:45:34 +09:00