qoi icon indicating copy to clipboard operation
qoi copied to clipboard

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

Open abhaychirania2411 opened this issue 1 year ago • 1 comments

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

abhaychirania2411 avatar Sep 14 '23 11:09 abhaychirania2411

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.

N-R-K avatar Apr 14 '24 07:04 N-R-K