phoboslab / qoi

The “Quite OK Image Format” for fast, lossless image compression
MIT License
6.94k stars 330 forks source link

No option to provide pre-allocated memory to encode and decode #285

Open abhaychirania2411 opened 1 year ago

abhaychirania2411 commented 1 year ago

Hi,

I have been working on a project that needs qoi encoding and decoding, but the final results should be put in a pre allocated memory. Although we can provide our own allocator, but i want to provide a pre allocated memory to the encoded function.

Something like this: void qoi_encode(const void data, const qoi_desc desc, int out_len, void *dest);

This dest adress can be optional, i.e if NULL then go ahead and allocate the memory using QOI_MALLOC

N-R-K commented 5 months ago

For decoding, I have a small header only decoder that accepts caller allocated memory: qoi-dec.c.

It also does a couple small optimization around redundant table insertion and bounds checking so it's a bit faster (especially with clang) than the official decoder:

          decode ms   decode mpps
qoi:            2.1        148.65
qoi-dec:        1.6        199.59

Maybe that interests you. The code is public domain so you can do whatever you want with it.

I don't have any encoder though. But @skeeto has one here: qoi.c. It's a streaming encoder and the caller is in control of the buffer where the encoder writes into.