简体   繁体   English

在turbojpeg cpp中重新分配图像缓冲区

[英]realloc image buffer in turbojpeg cpp

I'm using turbojpeg for reading images. 我正在使用turbojpeg读取图像。

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. 我想重新分配m_data和c_jpeg_buffer,以防_jpegSize或(tj_width * tj_height)太大。 The turbojpeg documentation suggests that this would happen automatically if I'm using tjCompress2(...) or tjTransform(...). turbojpeg文档建议,如果我使用tjCompress2(...)或tjTransform(...),则会自动发生这种情况。 It says nothing about what happens in this case. 它没有说明在这种情况下会发生什么。 Suppose I realloc the buffers - would it still be safe to use tjFree()? 假设我重新分配了缓冲区-使用tjFree()仍然安全吗?

For future users of turboJpeg... RTFM... 对于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. 两者都会缓冲自身,并且大小可能会更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM