Image format size pickle

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
BrotSagtMist
Party member
Posts: 659
Joined: Fri Aug 06, 2021 10:30 pm

Image format size pickle

Post by BrotSagtMist »

So i am currently working on something that needs a shitton of photos.
I will also require transparency.
Now the problem is if i save my files in png format the project easily hits a few gb in size.
If i save in jpg it cuts the size by about 70% without quality drop, but it doesnt have transparency.
So, how can i solve this dilema? Are there file formats that work in Löve that combine booth qualities? Am i missing something on the png compression options?
I am even considering using a shader that blocks a specific colour, but would that be a performance hit?
obey
RNavega
Party member
Posts: 385
Joined: Sun Aug 16, 2020 1:28 pm

Re: Image format size pickle

Post by RNavega »

There are compressed image formats that support transparency, scroll down to the Compressed Formats table:
https://love2d.org/wiki/PixelFormat

The DXT5 format (Microsoft DirectDraw Surface DXT5) seems the best match. ImageMagick seems to read and write those.

Also, if you don't need one of the color channels then you could save space by omitting them, like storing alpha values in the blue or green channel, then having an image file with just RG or RGB data inside, and doing the remapping in a shader (restoring the alpha by plugging that channel into it, with vec4(texel.xy, 0.0, texel.z) ).
User avatar
BrotSagtMist
Party member
Posts: 659
Joined: Fri Aug 06, 2021 10:30 pm

Re: Image format size pickle

Post by BrotSagtMist »

Hm i used the command given in the link but the result is only margnially smaller as png.
Plus, the wiki says this is for desktops, my target is an rpi device, this maybe wont work.
Ill try getting better numbers when i have some time, but so far this doesnt look like the way.
obey
RNavega
Party member
Posts: 385
Joined: Sun Aug 16, 2020 1:28 pm

Re: Image format size pickle

Post by RNavega »

You'd need to consult the (embedded) GPU of your RasPi if it supports the compressed formats, using this: https://love2d.org/wiki/love.graphics.getImageFormats

Something else to try is making an FFI binding to libavif (preferably), or libwebp. They're both modern compressed image formats that support transparency. AVIF seems to have better compression-to-quality ratio than WebP.
https://github.com/AOMediaCodec/libavif

There are pre-built command line tools (avifenc and avifdec) for Windows on their Releases page, so you could try to encode-decode an image and see if the compression & quality is worth the effort.

Edit: Note that AVIF has a lossless mode. In AVIF you do that by setting the color quantizer and alpha quantizer both to zero (https://linuxcommandlibrary.com/man/avifenc).

You can find pre-built webp encoding and decoding tools in here: https://developers.google.com/speed/web ... recompiled
WebP also has a lossless mode.
User avatar
knorke
Party member
Posts: 274
Joined: Wed Jul 14, 2010 7:06 pm
Contact:

Re: Image format size pickle

Post by knorke »

How about using two files per image?
1) the photo as jpg file
2) the transparent areas, as a black&white png file

Basically this: https://en.wikipedia.org/wiki/Mask_(com ... mage_masks
User avatar
darkfrei
Party member
Posts: 1204
Joined: Sat Feb 08, 2020 11:09 pm

Re: Image format size pickle

Post by darkfrei »

Making images with transparent key value - it looks like chroma key.
https://en.m.wikipedia.org/wiki/Chroma_key
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
RNavega
Party member
Posts: 385
Joined: Sun Aug 16, 2020 1:28 pm

Re: Image format size pickle

Post by RNavega »

Yet another approach is to reduce the fidelity of the images.
I'm sure we've seen GIFs around the web that look "decent", and the fidelity of those is very reduced, with 256 colors total.
So instead of having a 32 bit image (RGBA8888), having it as a 16 bit image (RGB565) with the alpha as 5, 6 or 8 bits, should yield a very similar image and at a greatly reduced size (at least 25%, on a RGB565 A8 custom format).

Edit: probably has a similar result to Knorke's suggestion of using JPEG for RGB + uncompressed alpha.
User avatar
BrotSagtMist
Party member
Posts: 659
Joined: Fri Aug 06, 2021 10:30 pm

Re: Image format size pickle

Post by BrotSagtMist »

Okey first of, none of these ideas is a simple drop in.
It means i have not oeverlooked something stupid easy.
That is good to know, thanks.

Okey number wise i just realized the problem is bigger than a thought.
The same file that as a jpg only takes 620kb is 10.8mb as a png.
Even when removing colours to a hefty quality drop png still stays in the several mb range.
I tried some of the compressed file formats and they dont do much either, dxt5 results in 8.3mb.

Soooo it looks like having two jpg files mixed is the best option after all.
But seeing that i am just helping my nephew with an art project for school and not making something to release ill probably just put a bigger sd card in there and call it a day, he can look at this thread himself if he wants it to perform better.
My bigger beef with that is not even the space taken but loading these files causes stuttering, but ohwell that just imitates professional software these days.
The project is a virtual museum btw.
Students hold their art pieces at a camera and can then place it on the photo of a shelf and visitors can zoom around.
obey
RNavega
Party member
Posts: 385
Joined: Sun Aug 16, 2020 1:28 pm

Re: Image format size pickle

Post by RNavega »

BrotSagtMist wrote: Tue Apr 30, 2024 4:11 pm
My bigger beef with that is not even the space taken but loading these files causes stuttering, but ohwell that just imitates professional software these days.
Hm, I think the only solution to that is to move the loading to a child thread, similar to the code in this: viewtopic.php?p=258395#p258395
The project is a virtual museum btw.
Students hold their art pieces at a camera and can then place it on the photo of a shelf and visitors can zoom around.
What you mention doesn't seem to need transparency though, can you double-check? If it doesn't need it, a single JPEG would do it. Edit: and good luck to your nephew
User avatar
BrotSagtMist
Party member
Posts: 659
Joined: Fri Aug 06, 2021 10:30 pm

Re: Image format size pickle

Post by BrotSagtMist »

Linking a thread where myself posted "i am doing the same" :D
Yea i can drop in a thread loading lib, but i dont think this fits how this tool is working.
The end result is kinda supposed to look like a loot room in doom.
Students will upload a picture of their paintings or sculptures and place it in there, for savekeeping as the artroom has only so much space, its just a flat picture but detailed.
And if we imagine a whole class result of paintings, thats 30 students, and we try to flip "rooms" it has to reload 300mb from the sd card everytime as opposed to 30. Thats not a lot by modern standarts but still a loading time.

And yea if we have photos of sculptures it should look like n64 mario graphics of a tree and not like a photo, this is what transparency is for.

I honestly dont think this is going to be finished anyway, it doesnt have to, the task was to design something with the broad topic of usability and he went meta by wanting to design a digital display that incorperates everyones elses work.
He will get a good grade if he can prove it can be used in practice, that means giving a tech demonstration and the teacher being able to use it without hassle, but i doubt the school will allow to set it up in their display.
obey
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests