memononen / nanosvg

Simple stupid SVG parser
zlib License
1.69k stars 357 forks source link

using embedded NSVG structs instead of embedded SVG data? #191

Closed darealshinji closed 3 years ago

darealshinji commented 3 years ago

I was wondering, in cases where someone might use embedded SVG data, would it be more efficient to parse that data with NanoSVG, dump the data as an array of bytes and then compile the actual program with that dumped data to copy into allocated NSVG structs? Or is the rendering part the most computation-intensive part, in which case someone could simply optimize the SVG before embedding (see scour)?

Anyway, I was trying to do that, but somethings not working right and the rendered picture is broken. https://gist.github.com/darealshinji/e30847aa20ac428b68a1f5ad3e0dd7f8 (those are 2 files)

oehhar commented 3 years ago

Am 23.01.2021 um 15:24 schrieb darealshinji:

I was wondering, in cases where someone might use embedded SVG data, would it be more efficient to parse that data with NanoSVG, dump the data as an array of bytes and then compile the actual program with that dumped data to copy into allocated NSVG structs? Or is the rendering part the most computation-intensive part, in which case someone could simply optimize the SVG before embedding (see scour)?

Anyway, I was trying to do that, but somethings not working right and the rendered picture is broken. https://gist.github.com/darealshinji/e30847aa20ac428b68a1f5ad3e0dd7f8 https://gist.github.com/darealshinji/e30847aa20ac428b68a1f5ad3e0dd7f8 (those are 2 files)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/memononen/nanosvg/issues/191, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC6WYLMD2Z7YEPBQGLCYHD3S3LL3HANCNFSM4WPXADJA.

Dear darealshinji,

I have implemented a serialization of the preparsed data to a memory blob:

https://core.tcl-lang.org/tk/vinfo/5b7e8328145b33e1?diff=1

My aim was, to reused the preparsed blog to raster images of different resolutions faster, as the parsing step is not required any more.

The results were disappointing:

But I am happy, that others have the same idea.

Harald

darealshinji commented 3 years ago

@oehhar Thanks for that info. I kinda thought it might be like that. Well, I can only recommend using scour in that case to minimize the SVG data before embedding it into the source code. By the way, if you dump the data into source code that will initialize all struct members like this=> shape->foo=1; shape->bar=9.99; compiling will takes ages on large SVG data, such as "23.svg".