FLIF-hub / FLIF

Free Lossless Image Format
Other
3.72k stars 229 forks source link

API needs a stream interface #469

Open lixo6500 opened 7 years ago

lixo6500 commented 7 years ago

Both the encoder and decoder APIs need some sort of stream interface.

On the decoder side, things are almost ready. The decoding already using a stream interface internally (BlobReader). All that is remaining to do is to provide some sort of struct the user can fill with function pointers to read data and seek.

The encoder also needs the same. Allow the user to provide function pointers to write and seek.

It could be something as simple as

// reads at most "size" bytes into buffer. Return the number of read bytes uint32_t read_data(void userData, void buffer, uint32_t size);

// seeks the stream to the requested position. Return true if successfull bool seek_data(void* userData, uint32_t position);

// writes at most "size" bytes from buffer. Return the number of written bytes uint32_t write_data(void userData, const void buffer, uint32_t size);

lixo6500 commented 7 years ago

I would like to reinforce the urgency of the above mentioned APIs, now that I looked at the insides of "flif_encoder_encode_memory"

The function documentation does not tell much about the buffers it expects. Since there is no way to know the size of the encoded data, one would assume that the API expects just a pointer and it will take care of allocating memory. So far so good.

The problems:

All those problems would be solved by some sort of stream API.

Also, maybe this kind of undefined behavior regarding the (probable) use of free with memory allocated with new[] may be the cause of the problems mentioned by that other issue "Google" opened.

OronDF343 commented 5 years ago

This is critical for any application that needs to decode FLIF from any source which isn't on the local filesystem - such as files in network locations and files inside archives - without resorting to complex workarounds. The current API is simply inadequate for any application with such requirements.

IMHO the lack of a stream API is significantly holding back adoption of FLIF in applications as dynamic linking to official-version binaries would not be possible if these features are needed. This is especially problematic for managed languages such as C# and Java.