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

exrcheck: make readDeepTile allocate memory for just one tile #991

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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