Commit graph

476 commits

Author SHA1 Message Date
Hermet Park
e9b12aa9f7 engine/loaders: Migrate alpha premultiplying to the engine side.
It's not efficient to handle alpha premultiplying in every loader.
The backend engine should be responsible for it.
Now, we can remove duplicate code.
2023-04-29 12:37:09 +09:00
Hermet Park
c710af2560 loaders: Remove the color space conversion on the loader side.
Now, the job is completely delegated to the backend engine.
2023-04-28 15:27:53 +09:00
Hermet Park
cf4484c1ad engine/loaders: develop the ColorSpace feature infrastructure
Replace the existing fragile usage of the colorspace data type
with a new and robust concrete ColorSpace type.
2023-04-28 15:27:53 +09:00
Hermet Park
1e370712e0 loader svg: ++code readability
Use own bit operation helpers.
2023-04-26 11:15:48 +09:00
Mira Grudzinska
bf2b348343 svg_loader: removed unused code
While css styling applied one of conditions was
always false. It is now removed and the function
that was called is refactored
2023-04-25 14:30:40 +09:00
Mira Grudzinska
83ffe9f612 svg_loader: fixing grad overwritting
Gradient was mistakenly overwritten in
files in which the <def> section existed,
but grad was defined outside it.
2023-04-25 14:30:23 +09:00
Mira Grudzinska
ef93a45d56 svg_loader: removing setting the locale
The locale was set while reading the path attr,
which could have caused race conditions between
threads and potentially led to crashes.
Now removed as unnecessary.

@Issue: https://github.com/thorvg/thorvg/issues/1389
2023-04-25 09:17:00 +09:00
Mira Grudzinska
74c9a5f795 svg_loader: changed update order
The gradient was updated before the style,
which resulted in only the URL tag being
inherited, but the gradient itself was not
applied to the node.
2023-04-25 09:01:19 +09:00
Mira Grudzinska
b0991b6ce7 svg_loader: fixing 'infinity' handling in svgUtilStrtof
The word 'infinity' was not read to the end due to
the pointer shifting.
2023-04-24 10:47:17 +09:00
Hermet Park
aa915ee1c4 Make it silent MSVC's trivial compilation warnings.
@Issue: https://github.com/thorvg/thorvg/issues/1381
2023-04-21 08:28:56 +09:00
Mira Grudzinska
46147dcec7 svg_loader: fixing clipper transformation
In a case where both the clipper and the clippee
are transformed, the final clipper transformation
matrix should be calculated as the multiplication
of both matrices.

@Issue: https://github.com/thorvg/thorvg/issues/1255
2023-04-19 11:43:16 +09:00
Mira Grudzinska
219e23855f svg_loader: paint-order attrib handled
@Issue: https://github.com/thorvg/thorvg/issues/1340
2023-04-18 22:21:55 +09:00
Mira Grudzinska
e61857f27d svg_loader: _applySvgViewFlag refactored 2023-04-17 21:43:36 +09:00
Mira Grudzinska
158e36f7c9 svg_loader: fix vx and vy
If no viewbox is given, vx and vy were set to values
corresponding to the svg's bounding box. This is now
applied only if no viewbox and no width/height information
is given. Otherwise, vx and vy are set to the default
values (0, 0).

@Issue: https://github.com/thorvg/thorvg/issues/1368
2023-04-17 21:43:36 +09:00
Mira Grudzinska
f089b77a45 svg_loader: fixing parsing empty elements
Self-closing tags (empty elements) were parsed until
the appearance of the '>' character, causing the '/'
char to be appended to the tag name. The final '/'
char should be omitted.
2023-04-17 09:57:52 +09:00
Mira Grudzinska
598c28a597 svg_loader: gradient inheritance implemented
Till now only the grad stops were inherited. Now all
grad attribs are.
Inheritance from different grad type is not supported.

@Issue: https://github.com/thorvg/thorvg/issues/1209
2023-04-15 17:43:42 +09:00
Mira Grudzinska
66ef84e7d7 svg_loader: code refactoring
Changed order of functions - needed in the grad
inheritance commit.
2023-04-15 17:43:42 +09:00
Mira Grudzinska
d60a7bec7e svg_loader: fixing svgs without viewbox attr
For svgs without any viewbox and width/height
whole image is drawn. Before it was forced
to set x=y=0.
2023-04-03 12:39:43 +02:00
Mira Grudzinska
c7137a8105 svg_loader: forcing file loading completion
Svgs without any viewbox and width/height information
have to be loaded before any other action is taken.
This is necessary to get the valid sive/viewbox info.
2023-03-31 09:48:01 +02:00
JunsuChoi
1e088a6a61 external_jpg_loader: Fix crash when loader is reloaded
When reload is called from tvgPicture,
clear() of external_jpg loader is called and 'data' is freed.
In the past, there was no case where reload was called until bitmap() was called after load.
Currently I have to consider reload() for a none-viewbox svg case
So change the color myself because loader can't call open() again.
2023-03-31 11:20:12 +09:00
Mira Grudzinska
d96b8f4385 svg_loader: invalid strokes' width set to zero
In case the "stroke" attrib is set to "none",
the width of the stroke is set to zero. Thanks
to that it isn't taken into account while
establishing the bounds of the shape.
2023-03-24 11:52:14 +09:00
Mira Grudzinska
be361221df svg_loader: handling zero width/height viewbox
For svgs with the width and/or height value set to zero
rendering was disabled - the load api return Result:Unknown
and draw - Result::InsufficientCondition.
Now an empty scene is added, so that both, load and draw,
return Result::Success.
2023-03-21 11:11:45 +09:00
Mira Grudzinska
9e8980a1f7 svg_loader: handling svgs without viewBox/viewPort
Additionally:
- cases of inforrect viewBox values are handled
- cases of zero width/height of a viewBox and/or viewPort

@Issue: https://github.com/Samsung/thorvg/issues/1239
2023-03-21 11:11:45 +09:00
JunsuChoi
50da80573d png_loader(static): Move the colortype check code to open() 2023-02-10 22:23:24 +09:00
JunsuChoi
02613feac3 png_loader(static): Fix the colorspace of an image with an alpha channel
Set colorspace to ABGR when colortype of lodepng is LCT_RGBA.
Since an image without an alpha channel becomes an ARGB colorspace with LCT_RGB,
it is the same as the default colorspace.
2023-02-10 22:23:24 +09:00
JunsuChoi
507b11829c loader: Support ABGR colorspace
Since the color space is set at the time of specifying the target buffer of the canvas,
there is no way to know the color space when the picture is loaded.
So, check the color space applied to SwCanvas at the time of reload()
and change the color space.

There is an issue of BGR color space support for each loader.
The external_jpg loader resets the TJPF color space and calls read() to get a new buffer.
In the case of external_png, we need to change the color value directly
because it have to start over from begin_read_*.

This solution can affect performance as much as it access again image buffer
that have already been `read()` done. However, this only happens once.
2023-02-08 17:54:33 -08:00
Hermet Park
cd68a783dd svg loader: correct clipper usage.
that has been changed by 0de3872be3
2023-01-26 21:37:03 +09:00
Mira Grudzinska
b58c20b881 svg_loader: overwrite the clip's opacity/alpha
According to the svg standard the clips opacity
doesn't affect the final rendering. In order to
avoid any confusion the opacity values are
overwritten by the max possible value.
2023-01-19 23:07:50 +01:00
Hermet Park
9b3c34c3b1 updated copyright. 2023-01-14 13:48:11 +09:00
Mira Grudzinska
ae07b480d0 svg_loader: fixing crash for to big buffer
Crash observed on macOS for the image-embeded-*.svg files.
Since the alloca function was used the stack allocation failure
could not be handled.
2023-01-08 11:28:42 +09:00
Mira Grudzinska
1980d9d0e3 all: Trailing spaces removed 2023-01-07 10:53:51 +09:00
Mira Grudzinska
df9a28bf0a svg_loader: fixing name
_parserColor -> _parseColor
2023-01-07 10:52:56 +09:00
JunsuChoi
1769e1c4af common Util: Move to before decimal part calculation 2022-12-14 10:42:27 +09:00
JunsuChoi
439c918553 common Util: Skip if there is a space after the dot
Some SVG parsers allow parsing of "0."
If there is a space after the dot, skip to the next step.
2022-12-14 10:42:27 +09:00
JunsuChoi
abb9df7c6b svg_loader: Change SVG viewbox variable type from int to float
The viewbox and size(width, height) defined in SVG can be of type float.
This prevents matrix calculation errors caused by this.
2022-12-12 23:48:52 +09:00
Hermet Park
d958fc7971 saver/loader tvg: support picture mesh properties.
this mesh properites newly introduced in v0.8
(see: 3dd65dfed0)

tvg saver/loader should implement mesh support to
properly capture/replay the scene snapshot.

@Issue: https://github.com/Samsung/thorvg/issues/1242
2022-12-08 22:29:29 +09:00
Hermet Park
93b88370ad svg loader: remove unused logic.
Please keep it simple and easy.

Don't leave a chance compiler warn it.
2022-09-02 12:02:39 +09:00
Mira Grudzinska
3939b61770
svg_loader: preserveAspectRatio attrib handled according to the svg standard (#1249)
* svg_loader: preserveAspectRatio attrib handled according to the svg standard

* svg_loader: symbol fixed

The correct width/height values used in the _useBuildHelper function.
Bug was propageted while the preserveAspectRatio attrib was handled,
now fixed.

* svg_loader: refactoring code regarding the preserveAspectRatio attrib

To avoid copy/paste a new function is introduced to handle the proper
scaling.

* svg_loader: initialize the svg loader members

The 'align' and 'meetOrSlice' svg loader members were not initialized.

* svg_loader: resize function forces any transformation

The resize function is called after the svg image is read and scaled
taking into account the proper preserveAspectRatio value. While resizing
the preserveAspectRatio isn't checked any more and the image can be
freely transformed.
2022-09-02 11:59:49 +09:00
Mira Grudzinska
c93c2d3100 svg_loader: deeper search for postponed nodes
Till now the proper node was searched only among children,
now all the nodes are checked.
2022-09-02 11:15:08 +09:00
Mira Grudzinska
313a4d1562 svg_loader: prevent stack-overflow for nested nodes 2022-09-02 11:13:45 +09:00
JunsuChoi
b7b8c2424c svg_loader: No skip luma mask when composition node is image
Improved to skip Luma Mask when conditions are the same
as AlphaMask for optimization in e409bb29.
If the composition node is an image, it is not skipped because
it is not known for sure whether to skip it.
2022-08-31 21:33:22 +02:00
Mira Grudzinska
be4f382d99 svg_loader: prevent mem leaks
A necessary check added before strdup function is called
2022-08-31 11:27:37 +09:00
JunsuChoi
b24e7c7402 svg_loader: Remove unnecessary code 2022-08-30 23:31:25 +02:00
JunsuChoi
eb936d1a81 svg_loader: If there is already set color url, it will be deleted.
When setting the url for color, if there is an already set url,
it will be overwritten after deletion. This prevents memory leaks.

asan result)

Direct leak of 2 byte(s) in 1 object(s) allocated from:
    #0 0x7ff1d547bc68 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10bc68)
    #1 0x7ff1d4e435b4 in _idFromUrl ../src/loaders/svg/tvgSvgLoader.cpp:327
    #2 0x7ff1d4e44a8e in _toColor ../src/loaders/svg/tvgSvgLoader.cpp:558
    #3 0x7ff1d4e42ee9 in _parseStyleAttr ../src/loaders/svg/tvgSvgLoader.cpp:1033
    #4 0x7ff1d4e7f092 in simpleXmlParseAttributes(char const*, unsigned int, bool (*)(void*, char const*, char const*), void const*) ../src/loaders/svg/tvgXmlParser.cpp:361
    #5 0x7ff1d4e597d3 in _createPathNode ../src/loaders/svg/tvgSvgLoader.cpp:1363
    #6 0x7ff1d4e61359 in _svgLoaderParserXmlOpen ../src/loaders/svg/tvgSvgLoader.cpp:2723
    #7 0x7ff1d4e61c49 in _svgLoaderParser ../src/loaders/svg/tvgSvgLoader.cpp:2801
    #8 0x7ff1d4e7f3f6 in simpleXmlParse(char const*, unsigned int, bool, bool (*)(void*, SimpleXMLType, char const*, unsigned int), void const*) ../src/loaders/svg/tvgXmlParser.cpp:429
    #9 0x7ff1d4e639a1 in SvgLoader::run(unsigned int) ../src/loaders/svg/tvgSvgLoader.cpp:3121
    #10 0x7ff1d4dc8b75 in tvg::Task::operator()(unsigned int) ../src/lib/tvgTaskScheduler.h:68
    #11 0x7ff1d4dc8b75 in tvg::TaskSchedulerImpl::run(unsigned int) ../src/lib/tvgTaskScheduler.cpp:138
    #12 0x7ff1d4dc98f7 in tvg::TaskSchedulerImpl::TaskSchedulerImpl(unsigned int)::{lambda()#1}::operator()() const ../src/lib/tvgTaskScheduler.cpp:113
    #13 0x7ff1d4dc98f7 in void std::__invoke_impl<void, tvg::TaskSchedulerImpl::TaskSchedulerImpl(unsigned int)::{lambda()#1}>(std::__invoke_other, tvg::TaskSchedulerImpl::TaskSchedulerImpl(unsigned int)::{lambda()#1}&&) /usr/include/c++/9/bits/invoke.h:60
    #14 0x7ff1d4dc98f7 in std::__invoke_result<tvg::TaskSchedulerImpl::TaskSchedulerImpl(unsigned int)::{lambda()#1}>::type std::__invoke<tvg::TaskSchedulerImpl::TaskSchedulerImpl(unsigned int)::{lambda()#1}>(std::__invoke_result&&, (tvg::TaskSchedulerImpl::TaskSchedulerImpl(unsigned int)::{lambda()#1}&&)...) /usr/include/c++/9/bits/invoke.h:95
    #15 0x7ff1d4dc98f7 in void std:🧵:_Invoker<std::tuple<tvg::TaskSchedulerImpl::TaskSchedulerImpl(unsigned int)::{lambda()#1}> >::_M_invoke<0ul>(std::_Index_tuple<0ul>) /usr/include/c++/9/thread:244
    #16 0x7ff1d4dc98f7 in std:🧵:_Invoker<std::tuple<tvg::TaskSchedulerImpl::TaskSchedulerImpl(unsigned int)::{lambda()#1}> >::operator()() /usr/include/c++/9/thread:251
    #17 0x7ff1d4dc98f7 in std:🧵:_State_impl<std:🧵:_Invoker<std::tuple<tvg::TaskSchedulerImpl::TaskSchedulerImpl(unsigned int)::{lambda()#1}> > >::_M_run() /usr/include/c++/9/thread:195
    #18 0x7ff1d3a344bf  (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0xd44bf)

example)
<svg height="400" width="600" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg">
   <defs>
      <radialGradient r="12" fy="10" fx="10" cy="10" cx="10" id="i" xlink:href="#d"/>
      <clipPath id="g" clipPathUnits="userSpaceOnUse">
         <path d="M0 10 10z" style="marker:none" fill="#fff" stroke-width="2"/>
      </clipPath>
   </defs>
         <path d="M0 10 Z" fill="url(#g)" style="fill:url(#i);fill-opacity:1"/>
</svg>
2022-08-30 23:31:25 +02:00
Mira Grudzinska
092a53b0aa svg_loader: fill and stroke paiint url were copied twice
The url were copied in the _copyAttr and in the _styleCopy
functions.
2022-08-29 12:00:35 +09:00
Mira Grudzinska
e36368c40c svg_loader: only the first css style node is interpreted
Since the css id selector is not supported in TVG, only the first
style node is taken into account.
2022-08-29 11:59:32 +09:00
Vincent Torri
b6ca58f655 Fix compilation error on Windows 2022-08-24 22:31:41 +09:00
projectitis
510ffa571a Fix compiler warnings on windows 2022-08-20 12:30:35 +09:00
Hermet Park
714470e618 loaders raw: fix a compiler warnings on Windows.
fix the invalid conversion from float to uint32_t.

@Issue: https://github.com/Samsung/thorvg/issues/1229
2022-08-04 17:02:56 +09:00
Omar Polo
53074d250f fix OpenBSD compile issue
Linux seems the only system AFAICS to have alloca.h.  All the BSDs have
the declaration in stdlib.h
2022-07-13 10:28:46 +09:00