Question

I'm using turbojpeg for reading images.

I'm doing something along these lines:

m_data = tjAlloc(MAX_RAW_SIZE);
c_jpeg_buffer = tjAlloc(MAX_RAW_SIZE);
tjDecompressHeader2(jpegDecompressor, c_jpeg_buffer, _jpegSize, &tj_width, &tj_height, &jpegSubsamp);
tjDecompress2(c_jpegDecompressor, m_data, _jpegSize, c_jpeg_buffer, tj_width, 0/*pitch*/, tj_height, TJPF_GRAY, TJFLAG_FASTDCT);
tjFree(c_jpeg_buffer);
tjFree(m_data);

I want to realloc m_data and c_jpeg_buffer in case the _jpegSize or (tj_width*tj_height) are too large. The turbojpeg documentation suggests that this would happen automatically if I'm using tjCompress2(...) or tjTransform(...). It says nothing about what happens in this case. Suppose I realloc the buffers - would it still be safe to use tjFree()?

Was it helpful?

Solution

For future users of turboJpeg... RTFM...

If you send a pre-allocated buffer, you need to pass it's size. Both buffer the itself and the size might be changed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top