QOI in Luau
The Quite OK Image Format (QOI), an image de-/encoder for fast and lossless compression. Ported to Luau, for Roblox.
NOTE: This program utilizes Roblox’s beta feature EditableImage
, meaning that this cannot be used by published games for the meantime.
Why?
- This de-/encoder is stupidly simple yet elegant, despite being less than 300 lines of code, it can compress images down to 50~20% of it’s original size and decompress losslessly.
- Encodes and decodes in less that a second (depending on image complexity).
- Useful for saving the data of large
EditableImages
in DataStores.
Although, it is still important to note that these advantages may not work or be as effective on some images.
More info at https://qoiformat.org.
Benchmark
Here is a basic benchmark of how well it performs with sample population of 5 arbitrary images. I can’t actually make comparisons of any kind to stb_image or the like just like QOI, as there are those algorithms are not available in Roblox.
Upon analyzing the table and viewing each images, we can say that the codec is somewhat O(n). Meaning that the time taken during de-/encoding increases linearly with the (spatial) complexity of the image.
Usage
You can download the RBXM file on the latest release and import it to Studio on the GitHub page. After that, you can re-parent it wherever you want (but preferably ReplicatedStorage), then require
!
The module is simple and pretty self-explanatory, so I think this little code snippet is enough to do the job.
local Asset = game:GetService('AssetService')
local Image = workspace.Part.Decal
local QOI = require(game.ReplicatedStorage.QOI)
local EditableImage = Asset:CreateEditableImageAsync(Image.Texture)
EditableImage.Parent = Image
local QOIFile = QOI.encode( EditableImage )
-- // Then store at the DataStore or whateves...
-- // Retrieve it later, then decode.
local PXBFile = QOI.decode( QOIFile )
-- // Read the file back into an image.
QOI.read( PXBFile , EditableImage )
Hey everyone, this is my very first post here at the resource category, and my very first post ever! I really hope this codec can be of use to a lot of people. Also, if anything ever went wrong or didn’t work as intended, please inform me about it immediately! Thank you for noticing my work, God bless and much love! <3