Commit graph

998 commits

Author SHA1 Message Date
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
41b5d8eb4e tvg_saver: verify view size earlier before the job is started. 2021-08-06 10:30:42 +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
Hermet Park
8844bdd1e9 common picture: return bounding box size with the current image size.
if the picture has a bitmap-based image,
it can return the bounding box size with the current image size.
2021-08-05 16:10:45 +09:00
JunsuChoi
cc81f8ef99 common Shape: Fix check to invalid argument
add cmds null check
2021-08-05 14:59:24 +09:00
Hermet Park
e12161d04f tvg loader: code refactoring
revise the mimetype load method to keep it clean & neat.
2021-08-05 13:27:08 +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
0e98809f15 sw_engine raster: code refactoring.
Separate simd implementation by files to maintain them easier.

Now we have avx, c, neon version implementation base,
we can add implementations to them.
2021-08-05 10:58:48 +09:00
Michal Szczecinski
3ce0722ffd sw_engine common: Added neon alpha blending.
Changes:
- Prepare neon verison of ALPHA_BLEND API.
- Use ALPHA_BLEND_NEON in _translucentRle

Notes:
- _translucentRle with neon support reduces execution time of this
function ~ 300 % (measured on uint32_t 400 x 400 buffer).
- API was tested on ARMv7l device with GCC 9.2 based toolchain. Results
  on other devices could be different.
2021-08-04 18:49:55 +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
19b11277a0 common loader: use RawLoader class immediately.
no need to find it here.
2021-08-04 15:30:21 +09:00
Michal Maciola
a4a323929f loader: removed loader finding for LoaderMgr::loader(data, w, h, copy)
LoaderMgr::loader(data, w, h, copy) is dedicated for raw images only.
No need to try other loaders.
2021-08-04 15:25:17 +09:00
Hermet Park
dc7bb0deed tvg_saver: do not pass through if the view size is invalid. 2021-07-30 12:40:02 +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
5e52134e2a dexample Picture: improve the test coverage.
In this patch, it replaced the test images with Lenna.
and fix the wrong jpeg file size figuring.
2021-07-30 12:09:59 +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
JunsuChoi
37453a2dfd
sw_engine Raster: Apply bilinear interpolation to images
* Apply bilinear interpolation to images

Apply bilinear interpolation when drawing images with transformation
If the mapped coordinate value is a floating point value,
bilinear interpolation is performed using adjacent pixel values.
Interpolation is not performed in cases when the color values to beinterpolated
are the same or scale down case.
2021-07-30 10:31:59 +09:00
Hermet Park
ccc3c7d381 tvg_saver: code refactoring.
keep the macro naming convention.
2021-07-29 20:12:00 +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
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
750d170978 sw_engine raster: remove inlining.
Reduce the binary size,

Leave it to the best choice by the complier.
2021-07-28 19:56:37 +09:00
Michal Szczecinski
1acc25b5ac sw_engine common: Added neon version of rasterRGBA32 API.
Changes:
- Added 'neon' vector option in build system
- Introduced neon version of rasterRGBA32 API, which improves
speed of the funciton on ARM cpu's around ~35%
2021-07-28 19:17:23 +09:00
Hermet Park
386888bd11 sw_engine: flush memory pool after drawing.
if many canvas instances own private memory pool,
the memory usage can be increased linearly.

To prevent memory usage, flush out memory pool from the clear()
if the canvas uses private memory pool.
2021-07-28 17:22:35 +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
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
7e5311fb86 sw_engine: -- unused header 2021-07-27 23:36:54 +09:00
Hermet Park
749a0fbb54 example performance: improve to print average... 2021-07-27 23:32:49 +09:00
Hermet Park
db85313328 example: add a sample for checking rendering performance. 2021-07-27 13:30:06 +09:00
Hermet Park
f66af5c8f5 tools svg2tvg: introduce a new tool for exporting tvg.
This is an utility to convert a file from svg to tvg
To use this, enable the feature by toggling in the meson option.

$meson build -Dtools="svg2tvg" ...

See also the usage:

Usage:
   svg2tvg [SVG file]

Examples:
    $ svg2tvg input.svg
2021-07-27 10:56:31 +09:00
Hermet Park
57e086db64 sw_engine renderer: ++exception handling.
initialize a member with the default value.
2021-07-26 16:51:25 +09:00
Hermet Park
30ebf35c13 tvg_saver: fix the invalid data size.
sizeof(colors) indicates its pointer size, we actually intended to the structure size.
2021-07-26 16:18:37 +09:00
Hermet Park
5e3011f86e tvg_saver: +exception handling
close the file handle before returning the function.
2021-07-26 16:17:06 +09:00
Mira Grudzinska
18f4b96786 tvg_saver: removing saving the default values
The default values (stroke cap/join, fill rule/spread or color with alpha = 0)
were unnecessarily saved in the tvg format file.
2021-07-26 15:32:38 +09:00
Michal Maciola
330e258495
sw_engine: removed unused rleAlphaMask 2021-07-23 21:27:39 +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
3ae9e33c65 examples: replace sprintf() with snprintf()
snprintf() is more preferred to use in preventing buffer overflow.
2021-07-22 16:32:12 +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
87d00b4121 tvg format: code refactoring #10
keep neat & clean code,
revise to tvg style naming convention.
2021-07-21 13:59:57 +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
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
ace58d5afd tvg format: code refactoring #7
remove return type values.
2021-07-20 15:55:51 +09:00