Skip to content

Commit

Permalink
exrcheck: make readDeepTile allocate memory for just one tile (Academ…
Browse files Browse the repository at this point in the history
…ySoftwareFoundation#991)

Signed-off-by: Peter Hillman <peterh@wetafx.co.nz>
  • Loading branch information
peterhillman authored and cary-ilm committed May 12, 2021
1 parent 4a84390 commit 5865996
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/lib/OpenEXRUtil/ImfCheckFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ readDeepTile(T& in,bool reduceMemory , bool reduceTime)
int numXLevels = in.numXLevels();


localSampleCount.resizeErase(height, width);
localSampleCount.resizeErase( tileHeight , tileWidth );

int channelCount=0;
for(ChannelList::ConstIterator i=fileHeader.channels().begin();i!=fileHeader.channels().end();++i, channelCount++);
Expand All @@ -546,25 +546,19 @@ readDeepTile(T& in,bool reduceMemory , bool reduceTime)

for (int i = 0; i < channelCount; i++)
{
data[i].resizeErase(height, width);
data[i].resizeErase( tileHeight , tileWidth );
}

DeepFrameBuffer frameBuffer;

//
// memOffset is difference in bytes between theoretical address of pixel (0,0) and the origin of the data window
//
uint64_t memOffset = sizeof(unsigned int) * (static_cast<uint64_t>(dataWindow.min.x) + static_cast<uint64_t>(dataWindow.min.y) * width);

//
// Use integer arithmetic instead of pointer arithmetic to compute offset into array.
// if memOffset is larger than base, then the computed pointer is negative, which is reported as undefined behavior
// Instead, integers are used for computation which behaves as expected an all known architectures
//

intptr_t base = reinterpret_cast<intptr_t>(&localSampleCount[0][0] );
frameBuffer.insertSampleCountSlice (Slice (UINT,
reinterpret_cast<char*> (base - memOffset),
reinterpret_cast<char*>(&localSampleCount[0][0]),
sizeof (unsigned int) * 1,
sizeof (unsigned int) * width,
0.0, // fill
Expand All @@ -580,11 +574,10 @@ readDeepTile(T& in,bool reduceMemory , bool reduceTime)
int sampleSize = sizeof (float);

int pointerSize = sizeof (char *);
intptr_t base = reinterpret_cast<intptr_t>(&data[channel][0][0]);

frameBuffer.insert (i.name(),
DeepSlice (FLOAT,
reinterpret_cast<char*> (base- memOffset),
reinterpret_cast<char*>(&data[channel][0][0]),
pointerSize * 1,
pointerSize * width,
sampleSize,
Expand Down

0 comments on commit 5865996

Please sign in to comment.