Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a binary kind of SVG?

It just seems to me that when writing code for dynamic data visualization, I end up doing the same things over and over in different languages/platforms. Now if I had a cross platform language(which I do) and something like a binary version of SVG, I could make my code target that and use/create interpreters for whatever platform I currently need to use it on.

The reason I don't want SVG is because the plaintext part makes it too slow for my purposes. I could of course just create my own intermediary format but if there is something already out there that's implemented by various things then the less work for me!

like image 988
user81993 Avatar asked Jul 09 '15 21:07

user81993


People also ask

Are SVG files binary?

SVG can only bundle bitmaps and other binary data through base64 encoding, which has a fair amount of overhead. PDF can include “streams” of raw binary data, and is surprisingly efficient when programmatically generated.

Are there different types of SVG files?

SVG allows three types of graphic objects: vector graphic shapes (such as paths consisting of straight lines and curves), bitmap images, and text. Graphical objects can be grouped, styled, transformed and composited into previously rendered objects.

Is SVG just XML?

Scalable Vector Graphics (SVG) are an XML-based markup language for describing two-dimensional based vector graphics.

What is the difference between SVG and EPS?

SVG file formats are suited for graphics and iconic elements on a website, whereas EPS file format is better for high-quality document printing, logos, and marketing materials. An SVG file format is an uprising feature on a web platform, whereas an EPS format is dying off and is reserved for old vector graphics.


2 Answers

Depending on what you mean by “too slow”, the answer varies:

Filesize too large

Officially, the closest thing SVG has to a binary format is SVGZ, which is a gzipped SVG file with the .svgz extension. All conforming SVG viewers should be able to open it. Making one is simple on *nix systems:

gzip yourfile.svg && mv yourfile.svg.gz yourfile.svgz

You could also try Brotli compression, which tends to have smaller filesize at the cost of more compression time.

Including other assets is inefficient

SVG can only bundle bitmaps and other binary data through base64 encoding, which has a fair amount of overhead.

PDF can include “streams” of raw binary data, and is surprisingly efficient when programmatically generated.

Parsing the text data takes too long

This is tricky. PDF and its brother, Encapsulated PostScript, are also old, well-supported vector graphic formats. Unfortunately, they too are also text at their core, with optional compression.

You could try Computer Graphics Metafiles, which can be compiled ahead of time. But I’m unsure how well-supported they are across consumer devices.

like image 178
Tigt Avatar answered Oct 02 '22 10:10

Tigt


From a comment:

Almost nothing about the performance of SVG other than the transmission cost of sending it over a network is down to it being plaintext

No, that's completely wrong. I worked at CSIRO using XML for massive 3D models. GeoScience Australia did a formal study into the parsing speed - parsing floating point numbers from text is relatively expensive for big data sets, compared to reading a 4 or 8 byte binary representation.

I've spent a lot of time optimising my internal binary formats for Touchgram and am now looking at vector art.

One of the techniques you can use is a combination of

  1. variable-length integer coding and
  2. normalising your points to a scale represented by integers, then storing paths as sequences of deltas

That can yield paths where often only 1 or 2 bytes are used per step, as opposed to the typical 12.

Consider a basic line <polyline class="Connect" points="100,200 100,100" />

I could represent that with 4 bytes instead of 53.

So far, all I've been able to find in binary SVG is this post about a Go project linking to the project description and repo

like image 33
Andy Dent Avatar answered Oct 02 '22 11:10

Andy Dent