PNG Decompressor Showcase

I wrote a PNG decompressor that reads the binary of a PNG file and uncompresses the raw pixel data in pure Lua and I imported it onto Roblox.

Showcase video: https://www.youtube.com/watch?v=TVPil3Lx8aM

It works by HTTP requesting a direct link to a PNG to get access to the file’s data. It’s still possible to optimize this decompressor slightly more, but because of Luau’s table element limit it wont be able to load images with more than 2^26 values (each RGB of a pixel counts as a value and an Alpha channel if there is one) without work arounds. This still allows it to decompress images over 4000 by 4000 pixels in RGB. After decoding the image is written onto editable images, which get split up into multiple images if the image is bigger than 1024x1024.

10 Likes

Does this use EditableImage in any way ?

Yes the image is rendered using editable images, it can also use parts but thats way too performance heavy for bigger images. Images over 1024x1024 get split into multiple editable images.

2 Likes

This PNG decompressor looks great! Good job on it! How long did it take for you to make it in total?

Coding the actual decoder took quite a long time. The compression algorithm PNG uses, which is Zlib and specifically Deflate, doesn’t have the best documentation in my opinion. So finding resources to understand how to undo the compression and understanding them took a while. Also after I got the decoder working I had a bunch of performance issues which I had to fix and I got it quite optimized at this point. Overall it did take over a month, but it was a pretty interesting project lol.

2 Likes

Didn’t MaximumADHD already make a module to do exactly this?

Please open source this :pray: It seems very cool

2 Likes

Idk, I wrote mine myself from scratch after reading and understanding the PNG documentation

1 Like

Btw on which os/roblox studio is that? The ui looks really neat!

Seems to be the Next Gen Studio Preview in beta settings

Anyway, cool project! A jpeg decoder has been something i’ve wanted to attempt for a while, how do you manage operations on raw bytes?
It’s a shame you can’t really release this in any way, for obvious reasons :grin:

you using buffers for this? seems like a good use case for them

I use string.unpack() to convert binary strings into decimal values, and then you can use the bit32 library in studio for the binary operators. If your working with raw Lua, the newer Lua versions have native binary operators.

1 Like

I would’ve, but when I noticed they got released I was already finished with most of the decoder and got too lazy to mess around with them lol

GitHub - MaximumADHD/Roblox-PNG-Library: An implementation of the PNG file format in Lua, natively designed for Roblox.

Try using buffers, it’s so much faster. You can send the binary data as unsigned 8 bit as the values go from 0-255. Then create buffer from string and readu8.