Skip to content

Commit

Permalink
avoid creating compression object just to compute numLinesInBuffer
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Hillman <[email protected]>
  • Loading branch information
peterhillman committed Feb 4, 2020
1 parent e7c26f6 commit a6408c9
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions OpenEXR/IlmImf/ImfMisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ defaultFormat (Compressor * compressor)
}


//obsolete
int
numLinesInBuffer (Compressor * compressor)
{
Expand Down Expand Up @@ -1842,6 +1843,39 @@ usesLongNames (const Header &header)
return false;
}

namespace
{
// for a given compression type, return the number of scanlines
// compressed into a single chunk
// TODO add to API and move to ImfCompressor.cpp
int
numLinesInBuffer(Compression comp)
{
switch(comp)
{
case NO_COMPRESSION :
case RLE_COMPRESSION:
case ZIPS_COMPRESSION:
return 1;
case ZIP_COMPRESSION:
return 16;
case PIZ_COMPRESSION:
return 32;
case PXR24_COMPRESSION:
return 16;
case B44_COMPRESSION:
case B44A_COMPRESSION:
case DWAA_COMPRESSION:
return 32;
case DWAB_COMPRESSION:
return 256;

default:
throw IEX_NAMESPACE::ArgExc ("Unknown compression type");
}
}
}

int
getScanlineChunkOffsetTableSize(const Header& header)
{
Expand All @@ -1851,17 +1885,11 @@ getScanlineChunkOffsetTableSize(const Header& header)
size_t maxBytesPerLine = bytesPerLineTable (header,
bytesPerLine);

Compressor* compressor = newCompressor(header.compression(),
maxBytesPerLine,
header);

int linesInBuffer = numLinesInBuffer (compressor);
int linesInBuffer = numLinesInBuffer ( header.compression() );

int lineOffsetSize = (dataWindow.max.y - dataWindow.min.y +
linesInBuffer) / linesInBuffer;

delete compressor;

return lineOffsetSize;
}

Expand Down

0 comments on commit a6408c9

Please sign in to comment.