Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce saved file size #489

Open
Alecaddd opened this issue Feb 21, 2021 · 2 comments
Open

Reduce saved file size #489

Alecaddd opened this issue Feb 21, 2021 · 2 comments

Comments

@Alecaddd
Copy link
Member

We currently save our files in a JSON format which lists all the items and their properties.
We also save the imported images in a dedicated folder to always have the original available even if the user resizes it or reduces the quality on the canvas.
Everything is packed together into a .akira file, which is actually a .zip file.

I'm looking for ways to reduce the file size without losing quality.

JSON content

@esodan suggested to convert the JSON file into a binary representation of GLib.Variant.
That sounds like a good idea, but I have no idea how to do it and, so I'm totally open to suggestions and contributions.

Image size

We want to keep the originally imported image inside the saved file, but I'd like to find a way to reduce the file size in case the user imports many large images into its project.
Is there some sort of conversion, or non destructive compression that can be reverted on loading?
The images are automatically deleted from the saved file if the user removes every instance of those from the canvas, so there's no problem from that point of view.

@esodan
Copy link

esodan commented Feb 22, 2021

From GVls support of Meson files, you can read a string an convert to GLib.Variant using this:

Json.Parser parser = new Json.Parser ();
parser.load_from_data (str);
Json.Node node = parser.get_root ();
GLib.Variant v = Json.gvariant_deserialize (node, null);
commands.parse_variant (v);

Above code takes a JSON formated code an convert to GLib.Variant using Json.gvariant_deserialize, the inverse process is using Json.gvariant_serialize.

GVls has GVls.VariantObject, a non invasive interface that when implemented add a parse_variant and to_variant methods, so any GLib.Object class is scanned for properties to serialize/deserialize; all its properties are converted to equivalente JSON data types. An example on how GVls use it to read a JSON file then automatically fills out a GLib.Object can be found at GVls.MesonCommands. If you need a list of GVls.VariantObject objects of the same type (like strings or other GVls.VariantObject derived types), GVls uses GVls.Container that implement GLib.ListModel so you can use to add objects to, then you can serialize to/from GLib.Variant objects.

GLib.Variant,store helps to store a serialized binary version of Variant, the contrary form is use get_data or GLib.Variant.get_normal_form

@brigazvi
Copy link

my knowledge in programming is very very very basic. but maybe it will help:
@Alecaddd for the pictures maybe you can use JPEG-XL. it can compress JPEG images without losing quality.
and maybe if we will use 7z technology instead of zip it can reduce file size too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants