Skip to content

Commit

Permalink
always ignore chunkCount attribute unless it cannot be computed (Acad…
Browse files Browse the repository at this point in the history
…emySoftwareFoundation#738)

Signed-off-by: Peter Hillman <peterh@wetafx.co.nz>
Signed-off-by: smartin-13 <61707536+smartin-13@users.noreply.github.com>
  • Loading branch information
peterhillman authored and smartin-13 committed Jul 23, 2020
1 parent 2b2da38 commit d8077e7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 18 deletions.
2 changes: 1 addition & 1 deletion OpenEXR/IlmImf/ImfDeepTiledOutputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ DeepTiledOutputFile::initialize (const Header &header)
_data->numYTiles);

//ignore the existing value of chunkCount - correct it if it's wrong
_data->header.setChunkCount(getChunkOffsetTableSize(_data->header,true));
_data->header.setChunkCount(getChunkOffsetTableSize(_data->header));

_data->maxSampleCountTableSize = _data->tileDesc.ySize *
_data->tileDesc.xSize *
Expand Down
28 changes: 20 additions & 8 deletions OpenEXR/IlmImf/ImfMisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1900,18 +1900,30 @@ int
getTiledChunkOffsetTableSize(const Header& header);

int
getChunkOffsetTableSize(const Header& header,bool ignore_attribute)
getChunkOffsetTableSize(const Header& header,bool)
{
if(!ignore_attribute && header.hasChunkCount())
{
return header.chunkCount();
}

//
// if there is a type in the header which indicates the part is not a currently supported type,
// use the chunkCount attribute
//


if(header.hasType() && !isSupportedType(header.type()))
{
throw IEX_NAMESPACE::ArgExc ("unsupported header type to "
"get chunk offset table size");
if(header.hasChunkCount())
{
return header.chunkCount();
}
else
{
throw IEX_NAMESPACE::ArgExc ("unsupported header type to "
"get chunk offset table size");
}
}

//
// part is a known type - ignore the header attribute and compute the chunk size from the header
//
if (isTiled(header.type()) == false)
return getScanlineChunkOffsetTableSize(header);
else
Expand Down
11 changes: 7 additions & 4 deletions OpenEXR/IlmImf/ImfMisc.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,13 +464,16 @@ bool usesLongNames (const Header &header);


//
// compute size of chunk offset table - if ignore_attribute set to true
// will compute from the image size and layout, rather than the attribute
// The default behaviour is to read the attribute
// compute size of chunk offset table - for existing types, computes
// the chunk size from the image size, compression type, and tile description
// (for tiled types). If the type is not supported, uses the chunkCount attribute
// if present, or throws an exception otherwise
// deprecated_attribute is no longer used by this function
//
//

IMF_EXPORT
int getChunkOffsetTableSize(const Header& header,bool ignore_attribute=false);
int getChunkOffsetTableSize(const Header& header,bool deprecated_attribute=false);

OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT

Expand Down
2 changes: 1 addition & 1 deletion OpenEXR/IlmImf/ImfMultiPartInputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ MultiPartInputFile::Data::readChunkOffsetTables(bool reconstructChunkOffsetTable

for (size_t i = 0; i < parts.size(); i++)
{
int chunkOffsetTableSize = getChunkOffsetTableSize(parts[i]->header,false);
int chunkOffsetTableSize = getChunkOffsetTableSize(parts[i]->header);
parts[i]->chunkOffsets.resize(chunkOffsetTableSize);

for (int j = 0; j < chunkOffsetTableSize; j++)
Expand Down
8 changes: 4 additions & 4 deletions OpenEXR/IlmImf/ImfMultiPartOutputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ MultiPartOutputFile::Data::do_header_sanity_checks(bool overrideSharedAttributes
if (isMultiPart)
{
// multipart files must contain a chunkCount attribute
_headers[0].setChunkCount(getChunkOffsetTableSize(_headers[0],true));
_headers[0].setChunkCount(getChunkOffsetTableSize(_headers[0]));

for (size_t i = 1; i < parts; i++)
{
if (_headers[i].hasType() == false)
throw IEX_NAMESPACE::ArgExc ("Every header in a multipart file should have a type");


_headers[i].setChunkCount(getChunkOffsetTableSize(_headers[i],true));
_headers[i].setChunkCount(getChunkOffsetTableSize(_headers[i]));
_headers[i].sanityCheck (_headers[i].hasTileDescription(), isMultiPart);


Expand Down Expand Up @@ -191,7 +191,7 @@ MultiPartOutputFile::Data::do_header_sanity_checks(bool overrideSharedAttributes

if (_headers[0].hasType() && isImage(_headers[0].type()) == false)
{
_headers[0].setChunkCount(getChunkOffsetTableSize(_headers[0],true));
_headers[0].setChunkCount(getChunkOffsetTableSize(_headers[0]));
}

}
Expand Down Expand Up @@ -500,7 +500,7 @@ MultiPartOutputFile::Data::writeChunkTableOffsets (vector<OutputPartData*> &part
{
for (size_t i = 0; i < parts.size(); i++)
{
int chunkTableSize = getChunkOffsetTableSize(parts[i]->header,false);
int chunkTableSize = getChunkOffsetTableSize(parts[i]->header);

Int64 pos = os->tellp();

Expand Down

0 comments on commit d8077e7

Please sign in to comment.