Open 190n opened 1 year ago
The way this is implemented at the moment, is quite naive: it just starts writing until it runs out of output buffer or until it is done. If it is done, it says it is done, otherwise it says it has written nothing, and it will restart from scratch when you give it a larger buffer.
Ideally, we should make a more streaming/stateful version of this, that can actually write partial output and then resume writing.
It's not super critical imo though, since it's not that hard to guess how large the jpeg will be: typical recompression saves around 20%, so if you take a buffer that is 25% larger than the input jxl file (or say 50% larger just to be sure), it will very likely be large enough.
Yes, I do already estimate an initial buffer size which usually ends up big enough. That said, it would still be helpful to decode in chunks because then I don't have to wait to decode the entire JXL file before returning it to the application; I can give it pieces of the JPEG incrementally (this is for a FUSE filesystem which converts JXL to JPEG on-the-fly).
Describe the bug
JxlDecoderReleaseJPEGBuffer
is supposed to return the number of bytes of the output buffer that have not yet been written to. In my use, it actually always returns the full size of the buffer, indicating that none of the buffer was written to, even though the buffer does actually contain a partial JPEG file (I verified with hashes that the full buffer I had allocated thus far matched that many bytes of the original JPEG).To Reproduce
JxlDecoder
and provide it the bytes of a recompressed JPEG file as inputJxlDecoderProcessInput
and thenJxlDecoderReleaseJPEGBuffer
Expected behavior Either the buffer contains garbage and
JxlDecoderReleaseJPEGBuffer
returns the size of the buffer as it does currently (if it needs more room before it can do any work, or something like that), or some of the buffer has been written to (in practice it seems that all of it is) andJxlDecoderReleaseJPEGBuffer
accurately reports how much.Screenshots
I attached the C++ code I've been using to test this (GitHub wouldn't let me upload it with the right extension). It's heavily modified from the
decode_oneshot
example. You can see that libjxl reports it has not written anything (line 84 is the printf)......but what is actually in the buffer corresponds to the JPEG file (and I verified this as far as 131072 bytes on this particular file, as the next time it resizes the buffer it actually fits the whole output):
decode_oneshot.txt
Environment
Additional context