Conversation
* src/lib/openjp2/openjpeg.c (opj_seek_from_buffer): changed signature to match opj_stream_seek_fn typedef. The incorrect signature resulted in a sliced pointer.
|
Unfortunately, a bug slipped in the pull request. The second commit addresses the bug. The bug only shows up in 32-bit builds, when the size of off_t does not match the size of size_t, so it might have gone unnoticed. |
|
Any chance we can get this integrated into master? |
|
Curious what is the state of this. Seems noone replied at all? |
|
It would be great to have this in master. Just wrote the same functionality myself and I do think more people will need this. |
|
Is there anything I might help with? |
|
Hi, I believe I've found two bugs in this pull request.
PS: I'm not able to create a proper pull request with this fix at the moment. Memory leakWhen encoding, this pull request will resize memory as it needs. But after the encoding is finished, void
opj_stream_destroy_buffer_stream(opj_buffer_info_t* buffer)
{
if (buffer == 00)
return;
if (buffer->buf == 00)
return;
/* Free buffer */
opj_free(buffer->buf);
/* Zero out buffer */
buffer->buf = 00;
buffer->cur = 00;
buffer->len = 0;
}Usage: /* Output stream */
opj_buffer_info_t buffer;
buffer.buf = nullptr;
buffer.cur = nullptr;
buffer.len = 0;
stream_wrapper_t stream = opj_stream_create_buffer_stream(&buffer, /* input */false);
/* Compression, encoding, error handling */
opj_stream_destroy_buffer_stream(&buffer);32-bit encoding errorThe user function The complete method should be: static OPJ_OFF_T
opj_skip_from_buffer(OPJ_OFF_T len, opj_buffer_info_t* psrc)
{
OPJ_OFF_T n = psrc->buf + psrc->len - psrc->cur;
if (n) {
if (n > len)
n = len;
psrc->cur += len;
}
else
n = (OPJ_OFF_T)-1;
return n;
}I hope this helps. |
|
It surely helps. There is a commit in that branch that addresses the off_t argument. I could spend some time creating a different patch and create a pull request but it will be from a different fork since I no longer have access to that repository. |
|
Alright, I think I am going to close this pull request. I am currently putting together a different enhancement and, perhaps, we'll get that in. |
|
@thinkoid , is it possible you could show me(us) how to use this ? How to add data to the buffer from memory ? |
|
@thinkoid , sorry found it, we could use the existing code in the repo to do memory based decoding via |
That is correct for decompression. For compression you pass in an empty opj_buffer_info_t; the buffer will be initialized and resized as needed by the library. At the end of compression you will be left with the buffer containing the compressed stream data. It is your responsibility to dispose of it. The buffer is allocated with malloc, you free it after you are done. |
FWIW, we're using this patch to implement buffer-based encoding and decoding to and from JPEG-2000 in our imaging software. As for attributions this is based on work done by Aron Boxer in another fork.