Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

always ignore chunkCount attribute unless it cannot be computed #738

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion OpenEXR/IlmImf/ImfDeepTiledOutputFile.cpp
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
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
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
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
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