Commit graph

313 commits

Author SHA1 Message Date
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
e949883049 common log: use the log macro to replace the print method easier.
We can replace the system logger method by changing single line print source in common,
This also helps to remove the THORVG_LOG_ENABLED macro from each use-cases.

TVGLOG(): To print the hint & tip messages for users.
TVGERR(): To print the error message for debugging.

@Issues: https://github.com/Samsung/thorvg/issues/36
2021-07-23 21:17:01 +09:00
Hermet Park
5024e7f952 svg_loader: code refactoring.
clean up about logging before replacing it with TVGLOG()
2021-07-23 15:24:59 +09:00
Michal Maciola
934a95777c
common: style fixes (#644) 2021-07-22 13:35:26 +02:00
Hermet Park
e56476b7bd common: code refactoring.
renamed loader classes same to Saver classes

tvgLoaderMgr -> tvgLoader (tvgSaver)
tvgLoader -> tvgLoadModule (tvgSaveModule)
2021-07-22 17:30:02 +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
Michal Maciola
c2ec997db5
svg_loader: allow both clipPath and mask together (#622)
* svg_loader: allow both clipPath and mask together

* svg_loader: allow both clipPath and mask together fix #1

Changed seperate functions _applyClipPathComposition and _applyMaskComposition into single function _applyComposition
2021-07-21 12:12:09 +09:00
Hermet Park
02b3d7dd20 tvg format: code refactoring #9
revise format of the macro names, no logical changes.
++ comments for maintenence.
2021-07-21 11:26:21 +09:00
Hermet Park
ace58d5afd tvg format: code refactoring #7
remove return type values.
2021-07-20 15:55:51 +09:00
Hermet Park
21f8828890 tvg format: code refactoring #6
++ neat & clean code
2021-07-20 15:39:29 +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
0ca69c49ff jpg_loader: code refactoring
remove unnecessary member variables.
2021-07-19 16:02:35 +09:00
Michal Maciola
8826394b56
jpg_loader: decompress header on opening 2021-07-19 14:55:23 +09:00
Michal Maciola
b89abde7cb
svg_loader: image tag: force size equal to the viewbox (#603)
* svg_loader: image tag: force size equal to the viewbox

For some svg files it is needed to force size equal the viewbox
for proper scaling

* svg_loader: image tag: force size equal to the viewbox fix #1
2021-07-15 17:48:35 -07:00
Michal Maciola
30a3d442b9 svg_loader: image tag: fixed utf8 decode
Fixed svgUtilURLDecode function.
Deleted snippet was not needed and it broken decoding when space.
2021-07-14 10:08:15 +09:00
Michal Maciola
8e1d8b0cb2 svg_loader: race condition on arc processing
Unneeded static keyword in _pathAppendArcTo function led to race
conditioning
@issue: #604
2021-07-13 22:23:02 +09:00
JunsuChoi
233045f796 svg_loader SvgPath: Skip invalid path
If the d attribute of SVG path is not parsed through _nextCommand(),
it is regarded as an invalid data.
2021-07-12 16:43:44 +09:00
JunsuChoi
bbc0fbb130 svg_loader SvgUtil: Move nullcheck to before use
prevent invalid access
2021-07-12 13:37:42 +09:00
JunsuChoi
333cac8d9d svg_loader SvgLoader: Initialize to flag value of SvgParser
This patch fixes valgrind detection

$valgrind --leak-check=yes ./Svg

==21410== Conditional jump or move depends on uninitialised value(s)
==21410== at 0x505DB66: _attrParseStops(void*, char const*, char const*) (tvgSvgLoader.cpp:2099)
==21410== by 0x5064F6D: simpleXmlParseAttributes(char const*, unsigned int, bool ()(void, char const*, char const*), void const*) (tvgXmlParser.cpp:319)
==21410== by 0x5061774: _svgLoaderParserXmlOpen(SvgLoaderData*, char const*, unsigned int, bool) (tvgSvgLoader.cpp:2387)
==21410== by 0x5061857: _svgLoaderParser(void*, SimpleXMLType, char const*, unsigned int) (tvgSvgLoader.cpp:2408)
==21410== by 0x5065052: simpleXmlParse(char const*, unsigned int, bool, bool ()(void, SimpleXMLType, char const*, unsigned int), void const*) (tvgXmlParser.cpp:425)
==21410== by 0x5061993: SvgLoader::run(unsigned int) (tvgSvgLoader.cpp:2757)
==21410== by 0x5052F5E: operator() (tvgTaskScheduler.h:68)
==21410== by 0x5052F5E: tvg::TaskSchedulerImpl::run(unsigned int) (tvgTaskScheduler.cpp:138)
==21410== by 0x62C36DE: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.25)
==21410== by 0x6DA36DA: start_thread (pthread_create.c:463)
==21410== by 0x68C871E: clone (clone.S:95)
2021-07-12 12:35:42 +09:00
JunsuChoi
f9d82c2c28 svg_loader SvgLoader: Fix memory leak of duplicate declared id
Duplicate declaration of id attribute is invaild.
We do not have a separate policy for invalid svg files.
Therefore, it is a priority to prevent crashes or memory leaks.
If an id is declared as duplicate, the last declared id is used.
2021-07-12 11:21:05 +09:00
Hermet Park
aa1a43e3a2 jpg_loader: code refactoring
keep it clean and neat code add some TODO comments for the future tasks.

This also fixes potential data memory leak.
2021-07-09 21:15:59 +09:00
Hermet Park
0d71a74de5 jpg_loader: change source file mode 664 2021-07-09 16:53:08 +09:00
JunsuChoi
91cf75ff04 jpg_loader JpgLoader: Prevent memory leak
If the copied data in JpgLoader's data open is invalid,
it is processed without being cleared.
Therefore, data memory free is handled in the destructor.
2021-07-09 16:50:45 +09:00
Michal Maciola
31f45fbd5f svg_loader: <image> tag introduced fix #9
Fixed Base64 and utf8 for new line and whitespace
Changed tvgSvgLoaderCommon.h to single line convention
2021-07-09 12:04:29 +09:00
Michal Maciola
28342c5c1f svg_loader: <image> tag introduced fix #8
Disable embedded svg files to protect against recursive svg image loading
2021-07-09 12:04:29 +09:00
Michal Maciola
48bc30e70a svg_loader: <image> tag introduced fix #7
fixed auto and new lines in tvgSvgUtil.cpp
2021-07-09 12:04:29 +09:00
Michal Maciola
1f67c1d689 svg_loader: <image> tag introduced fix #6
Moved file:// removing into _imageBuildHelper
2021-07-09 12:04:29 +09:00
Michal Maciola
3e4512a9a6 svg_loader: <image> tag introduced fix #5
Added copyAttr for image
2021-07-09 12:04:29 +09:00
Michal Maciola
e01f29270a svg_loader: <image> tag introduced fix #4
fixed mistyped vw to w and vh to h
2021-07-09 12:04:29 +09:00
Michal Maciola
d69805c668 svg_loader: <image> tag introduced fix #3
Added working composition
2021-07-09 12:04:29 +09:00
Michal Maciola
c35f7e1f64 svg_loader: <image> tag introduced fix #2
Removed #ifdef from tvgSvgSceneBuilder.cpp
2021-07-09 12:04:29 +09:00
Michal Maciola
9c1af3dde5 svg_loader: <image> tag introduced fix #1
Fixed href string deleting
2021-07-09 12:04:29 +09:00
Michal Maciola
80fa97d366 svg_loader: <image> tag introduced
This patch introduces embeded <image> tag for svg files.
Images can be now loaded from local path or using data URI Scheme (RFC2397).
Base64 and utf8/uri are welcome.

@issue: #518
2021-07-09 12:04:29 +09:00
Hermet Park
af140a1fe5 svg_loader: fix gradient memory leak.
@Issue: https://github.com/Samsung/thorvg/issues/548
2021-07-09 11:58:44 +09:00
Hermet Park
3997aedcd5 svg_loader: optimize memory usage.
-- unnecessary memory fragmentation.
2021-07-09 11:58:44 +09:00
Michal Maciola
bb19bcf64f
svg_loader: postpone cloneNode()
Some svg export software puts <defs> element at the end of the file.
If so, the <defs> element won't be found, when parsing <use>.
In such scenario, this patch postpone node cloning until the whole file
is parsed.

@issue: #568
2021-07-07 15:34:15 +09:00
Michal Maciola
eddbb4d71d jpg_loader: introduced jpg decode using libjpeg-turbo fix #1
Added bool open(const char* data, uint32_t size, bool copy);
2021-07-07 13:44:16 +09:00
Michal Maciola
0435f29f11 jpg_loader: introduced jpg decode using libjpeg-turbo
This patch introduces a jpg loader.
For decoding the image, libjpeg-turbo library is used. Library was found to be
fast (SIMD instructions accelerated) and portable.

@issue: #517
2021-07-07 13:44:16 +09:00
JunsuChoi
ea3d79f5f3 svg_loader: Support percentage unit of dash-array
Refers to the diagonal length of the viewport.
https://www.w3.org/TR/SVG2/coords.html#Units
2021-07-07 09:48:46 +09:00
Michal Maciola
1e1f232016 png_loader: added open from memory
Added PngLoader::open(const char* data, uint32_t size, bool copy)
Changed variables visibility to private
2021-07-06 18:32:08 +09:00
Mira Grudzinska
1507438ecc svg_loader: set the priority for the style attribute for stop properties
Stop properies stop-color and stop-opacity set using a style attribute should
have higher priority than properties set in a different way.
2021-07-06 10:13:58 +02:00
Mira Grudzinska
fff5bfee83 svg_loader: set the higher priority of style attributes
issue #515
2021-07-06 10:13:58 +02:00
Michal Maciola
7a8d7ceac6 svg_loader: fix dead loop on none digit char in stroke-dasharray fix #3
Added zero and negative value protection
2021-07-06 10:39:34 +09:00
Michal Maciola
bf8c633d38 svg_loader: fix dead loop on none digit char in stroke-dasharray fix #2
Moved _skipComma at the begining of the loop
2021-07-06 10:39:34 +09:00
Michal Maciola
2f8c00580d svg_loader: fix dead loop on none digit char in stroke-dasharray 2021-07-06 10:39:34 +09:00
Hermet Park
8e2765be39 common picture: fix invalid size returns from raw image.
picture/raw should update the size if the raw image
with size values are entered.
2021-07-03 16:15:57 +09:00
Hermet Park
8d31496648 infra: print enabled features in the meson summary list.
instead removed individual messages.
2021-07-03 14:58:17 +09:00
Michal Maciola
99263d54d1 svg_loader: multiple composition memory leak
Multiple composition are still not supported, but this patch fixes a
memory leak if it is tried to be applied.
2021-07-03 14:14:01 +09:00
Michal Maciola
6a09a8f015 svg_loader: memory leak after improper stop tag fix #1
Updated printf message
2021-07-03 13:50:03 +09:00
Michal Maciola
b005f97bcd svg_loader: memory leak after improper stop tag
<stop> tag should be always a child of a <linearGradient> or
<radialGradient> element, but there were files with <stop> tag inside <rect>.
This patch fixes a memory leak if no gradient is defined before <stop> tag.
2021-07-03 13:50:03 +09:00