libspng icon indicating copy to clipboard operation
libspng copied to clipboard

Streaming API improvements

Open randy408 opened this issue 6 years ago • 3 comments

The streaming API is similar to libpng's which is great when it comes porting code but it has some drawbacks, this issue is for listing potential improvements.

randy408 avatar Oct 24 '19 13:10 randy408

The current streaming API expects the read callback to copy data to a library-controlled buffer, this introduces unnecessary copying if the user is also storing the PNG in memory.

Add a new function spng_set_png_stream2() that takes a different type of callback:

typedef int spng_read_fn2(spng_ctx *ctx, void *user, void **dest, size_t length);

This callback function assigns the pointer dest to the requested amount of bytes.

randy408 avatar Oct 24 '19 13:10 randy408

It also might be nice to allow a push-style or asynchronous decoding interface. For example, in netsurf's png handler, it receives image data in chunks, and pushes it into libpng with png_process_data:

http://git.netsurf-browser.org/netsurf.git/tree/content/handlers/image/png.c#n315

I'm don't believe there is a way to do this with the current libspng API.

michaelforney avatar Nov 22 '19 18:11 michaelforney

I created a new issue for that: https://github.com/randy408/libspng/issues/39

randy408 avatar Nov 24 '19 15:11 randy408