Skip to content

Commit

Permalink
Switch over to use compressBound() instead of manually computing
Browse files Browse the repository at this point in the history
headroom for compress()
  • Loading branch information
Karl Rasche committed Feb 18, 2015
1 parent f4a6d3b commit c9a2e19
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions OpenEXR/IlmImf/ImfDwaCompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2163,7 +2163,7 @@ DwaCompressor::compress
if (*unknownUncompressedSize > 0)
{
uLongf inSize = (uLongf)(*unknownUncompressedSize);
uLongf outSize = (uLongf)(ceil ((float)inSize * 1.01f) + 100);
uLongf outSize = compressBound (inSize);

if (Z_OK != ::compress2 ((Bytef *)outDataPtr,
&outSize,
Expand Down Expand Up @@ -2201,8 +2201,8 @@ DwaCompressor::compress
case DEFLATE:

{
uLongf destLen = (uLongf)
(2 * (*totalAcUncompressedCount) * sizeof (unsigned short));
uLongf destLen = compressBound (
(*totalAcUncompressedCount) * sizeof (unsigned short));

if (Z_OK != ::compress2
((Bytef *)outDataPtr,
Expand Down Expand Up @@ -2254,8 +2254,7 @@ DwaCompressor::compress
_planarUncBuffer[RLE],
(signed char *)_rleBuffer);

uLongf dstLen =
(uLongf)ceil (1.01f * (float) * rleUncompressedSize) + 24;
uLongf dstLen = compressBound ((uLongf)*rleUncompressedSize);

if (Z_OK != ::compress2
((Bytef *)outDataPtr,
Expand Down Expand Up @@ -2493,16 +2492,14 @@ DwaCompressor::uncompress

if (unknownCompressedSize > 0)
{
uLongf outSize = static_cast<uLongf>(
ceil( (float)unknownUncompressedSize * 1.01) + 100);

if (unknownUncompressedSize < 0 ||
outSize > _planarUncBufferSize[UNKNOWN])
if (unknownUncompressedSize > _planarUncBufferSize[UNKNOWN])
{
throw Iex::InputExc("Error uncompressing DWA data"
"(corrupt header).");
}

uLongf outSize = (uLongf)unknownUncompressedSize;

if (Z_OK != ::uncompress
((Bytef *)_planarUncBuffer[UNKNOWN],
&outSize,
Expand Down Expand Up @@ -2925,10 +2922,13 @@ DwaCompressor::initializeBuffers (size_t &outBufferSize)
//
// This is the size of the number of packed
// components, plus the requirements for
// maximum Huffman encoding size.
// maximum Huffman encoding size (for STATIC_HUFFMAN)
// or for zlib compression (for DEFLATE)
//

maxOutBufferSize += 2 * maxLossyDctAcSize + 65536;
maxOutBufferSize += std::max(
(int)(2 * maxLossyDctAcSize + 65536),
(int)compressBound (maxLossyDctAcSize) );
numLossyDctChans++;
break;

Expand Down Expand Up @@ -2967,13 +2967,13 @@ DwaCompressor::initializeBuffers (size_t &outBufferSize)
// which could take slightly more space
//

maxOutBufferSize += (int)(ceil (1.01f * (float)rleBufferSize) + 100);
maxOutBufferSize += (int)compressBound ((uLongf)rleBufferSize);

//
// And the same goes for the UNKNOWN data
//

maxOutBufferSize += (int)(ceil (1.01f * (float)unknownBufferSize) + 100);
maxOutBufferSize += (int)compressBound ((uLongf)unknownBufferSize);

//
// Allocate a zip/deflate compressor big enought to hold the DC data
Expand Down Expand Up @@ -3095,8 +3095,8 @@ DwaCompressor::initializeBuffers (size_t &outBufferSize)

if (planarUncBufferSize[UNKNOWN] > 0)
{
planarUncBufferSize[UNKNOWN] =
(int) ceil (1.01f * (float)planarUncBufferSize[UNKNOWN]) + 100;
planarUncBufferSize[UNKNOWN] =
compressBound ((uLongf)planarUncBufferSize[UNKNOWN]);
}

for (int i = 0; i < NUM_COMPRESSOR_SCHEMES; ++i)
Expand Down

0 comments on commit c9a2e19

Please sign in to comment.