Skip to content

Commit

Permalink
add test for skipped and filled channels in DeepTiles
Browse files Browse the repository at this point in the history
  • Loading branch information
peterhillman authored and kdt3rd committed Jul 25, 2019
1 parent 3c9d0b2 commit b1a5c8c
Showing 1 changed file with 163 additions and 75 deletions.
238 changes: 163 additions & 75 deletions OpenEXR/IlmImfTest/testDeepTiledBasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ void checkValue (void* sampleRawData,
void readFile (int channelCount,
bool bulkRead,
bool relativeCoords,
bool randomChannels,
const std::string & filename)
{
if (relativeCoords)
Expand All @@ -434,8 +435,12 @@ void readFile (int channelCount,

Array2D<unsigned int> localSampleCount;
localSampleCount.resizeErase(height, width);
Array<Array2D< void* > > data(channelCount);
for (int i = 0; i < channelCount; i++)

// also test filling channels. Generate up to 2 extra channels
int fillChannels=rand()%3;

Array<Array2D< void* > > data(channelCount+fillChannels);
for (int i = 0; i < channelCount+fillChannels; i++)
data[i].resizeErase(height, width);

DeepFrameBuffer frameBuffer;
Expand All @@ -454,30 +459,67 @@ void readFile (int channelCount,
relativeCoords,
relativeCoords));


vector<int> read_channel(channelCount);
int channels_added=0;
for (int i = 0; i < channelCount; i++)
{
PixelType type = NUM_PIXELTYPES;
if (channelTypes[i] == 0)
type = IMF::UINT;
if (channelTypes[i] == 1)
type = IMF::HALF;
if (channelTypes[i] == 2)
type = IMF::FLOAT;

if(randomChannels)
{
read_channel[i] = rand() % 2;

}
if(!randomChannels || read_channel[i]==1)
{
PixelType type = IMF::NUM_PIXELTYPES;
if (channelTypes[i] == 0)
type = IMF::UINT;
if (channelTypes[i] == 1)
type = IMF::HALF;
if (channelTypes[i] == 2)
type = IMF::FLOAT;

stringstream ss;
ss << i;
string str = ss.str();

int sampleSize = 0;
if (channelTypes[i] == 0) sampleSize = sizeof (unsigned int);
if (channelTypes[i] == 1) sampleSize = sizeof (half);
if (channelTypes[i] == 2) sampleSize = sizeof (float);

int pointerSize = sizeof (char *);

frameBuffer.insert (str,
DeepSlice (type,
(char *) (&data[i][0][0] - memOffset),
pointerSize * 1,
pointerSize * width,
sampleSize,
1, 1,
0,
relativeCoords,
relativeCoords));
channels_added++;
}
}
if(channels_added==0)
{
cout << "skipping " <<flush;
return;
}
for(int i = 0 ; i < fillChannels ; ++i )
{
PixelType type = IMF::FLOAT;
int sampleSize = sizeof(float);
int pointerSize = sizeof (char *);
stringstream ss;
ss << i;
// generate channel names that aren't in file but (might) interleave with existing file
ss << i << "fill";
string str = ss.str();

int sampleSize = 0;
if (channelTypes[i] == 0) sampleSize = sizeof (unsigned int);
if (channelTypes[i] == 1) sampleSize = sizeof (half);
if (channelTypes[i] == 2) sampleSize = sizeof (float);

int pointerSize = sizeof (char *);

frameBuffer.insert (str,
DeepSlice (type,
(char *) (&data[i][0][0] - memOffset),
(char *) (&data[i+channelCount][0][0] - memOffset),
pointerSize * 1,
pointerSize * width,
sampleSize,
Expand Down Expand Up @@ -533,7 +575,14 @@ void readFile (int channelCount,
if (channelTypes[k] == 2)
data[k][dwy][dwx] = new float[localSampleCount[dwy][dwx]];
}

for( int f = 0 ; f < fillChannels ; ++f )
{
data[f + channelTypes.size()][dwy][dwx] = new float[localSampleCount[dwy][dwx]];
}

}

}
}

Expand Down Expand Up @@ -570,6 +619,10 @@ void readFile (int channelCount,
if (channelTypes[k] == 2)
data[k][dwy][dwx] = new float[localSampleCount[dwy][dwx]];
}
for( int f = 0 ; f < fillChannels ; ++f )
{
data[f + channelTypes.size()][dwy][dwx] = new float[localSampleCount[dwy][dwx]];
}
}

file.readTile(j, i, lx, ly);
Expand Down Expand Up @@ -600,12 +653,21 @@ void readFile (int channelCount,

for (size_t k = 0; k < channelTypes.size(); k++)
{
if (channelTypes[k] == 0)
data[k][ty][tx] = new unsigned int[localSampleCount[ty][tx]];
if (channelTypes[k] == 1)
data[k][ty][tx] = new half[localSampleCount[ty][tx]];
if (channelTypes[k] == 2)
data[k][ty][tx] = new float[localSampleCount[ty][tx]];
if( !randomChannels || read_channel[k]==1)
{
if (channelTypes[k] == 0)
data[k][ty][tx] = new unsigned int[localSampleCount[ty][tx]];
if (channelTypes[k] == 1)
data[k][ty][tx] = new half[localSampleCount[ty][tx]];
if (channelTypes[k] == 2)
data[k][ty][tx] = new float[localSampleCount[ty][tx]];
}


}
for( int f = 0 ; f < fillChannels ; ++f )
{
data[f + channelTypes.size()][ty][tx] = new float[localSampleCount[ty][tx]];
}
}

Expand All @@ -621,16 +683,23 @@ void readFile (int channelCount,

for (size_t k = 0; k < channelTypes.size(); k++)
{
checkValue(data[k][ty][tx],
localSampleCount[ty][tx],
channelTypes[k],
dwx, dwy);
if (channelTypes[k] == 0)
delete[] (unsigned int*) data[k][ty][tx];
if (channelTypes[k] == 1)
delete[] (half*) data[k][ty][tx];
if (channelTypes[k] == 2)
delete[] (float*) data[k][ty][tx];
if( !randomChannels || read_channel[k]==1)
{
checkValue(data[k][ty][tx],
localSampleCount[ty][tx],
channelTypes[k],
dwx, dwy);
if (channelTypes[k] == 0)
delete[] (unsigned int*) data[k][ty][tx];
if (channelTypes[k] == 1)
delete[] (half*) data[k][ty][tx];
if (channelTypes[k] == 2)
delete[] (float*) data[k][ty][tx];
}
}
for( int f = 0 ; f < fillChannels ; ++f )
{
delete[] (float*) data[f+channelTypes.size()][ty][tx];
}
}
}
Expand All @@ -644,49 +713,61 @@ void readFile (int channelCount,
for (int j = 0; j < file.levelWidth(lx); j++)
for (int k = 0; k < channelCount; k++)
{
for (unsigned int l = 0; l < localSampleCount[i][j]; l++)
if( !randomChannels || read_channel[k]==1)
{
if (channelTypes[k] == 0)
{
unsigned int* value = (unsigned int*)(data[k][i][j]);
if (value[l] != static_cast<unsigned int>((i * width + j) % 2049))
cout << j << ", " << i << " error, should be "
<< (i * width + j) % 2049 << ", is " << value[l]
<< endl << flush;
assert (value[l] == static_cast<unsigned int>((i * width + j) % 2049));
}
if (channelTypes[k] == 1)
{
half* value = (half*)(data[k][i][j]);
if (value[l] != (i * width + j) % 2049)
cout << j << ", " << i << " error, should be "
<< (i * width + j) % 2049 << ", is " << value[l]
<< endl << flush;
assert (((half*)(data[k][i][j]))[l] == (i * width + j) % 2049);
}
if (channelTypes[k] == 2)
for (unsigned int l = 0; l < localSampleCount[i][j]; l++)
{
float* value = (float*)(data[k][i][j]);
if (value[l] != (i * width + j) % 2049)
cout << j << ", " << i << " error, should be "
<< (i * width + j) % 2049 << ", is " << value[l]
<< endl << flush;
assert (((float*)(data[k][i][j]))[l] == (i * width + j) % 2049);
if (channelTypes[k] == 0)
{
unsigned int* value = (unsigned int*)(data[k][i][j]);
if (value[l] != static_cast<unsigned int>(i * width + j) % 2049)
cout << j << ", " << i << " error, should be "
<< (i * width + j) % 2049 << ", is " << value[l]
<< endl << flush;
assert (value[l] == static_cast<unsigned int>(i * width + j) % 2049);
}
if (channelTypes[k] == 1)
{
half* value = (half*)(data[k][i][j]);
if (value[l] != (i * width + j) % 2049)
cout << j << ", " << i << " error, should be "
<< (i * width + j) % 2049 << ", is " << value[l]
<< endl << flush;
assert (((half*)(data[k][i][j]))[l] == (i * width + j) % 2049);
}
if (channelTypes[k] == 2)
{
float* value = (float*)(data[k][i][j]);
if (value[l] != (i * width + j) % 2049)
cout << j << ", " << i << " error, should be "
<< (i * width + j) % 2049 << ", is " << value[l]
<< endl << flush;
assert (((float*)(data[k][i][j]))[l] == (i * width + j) % 2049);
}
}
}
}

for (int i = 0; i < file.levelHeight(ly); i++)
for (int j = 0; j < file.levelWidth(lx); j++)
{
for (int k = 0; k < channelCount; k++)
{
if (channelTypes[k] == 0)
delete[] (unsigned int*) data[k][i][j];
if (channelTypes[k] == 1)
delete[] (half*) data[k][i][j];
if (channelTypes[k] == 2)
delete[] (float*) data[k][i][j];
if( !randomChannels || read_channel[k]==1)
{
if (channelTypes[k] == 0)
delete[] (unsigned int*) data[k][i][j];
if (channelTypes[k] == 1)
delete[] (half*) data[k][i][j];
if (channelTypes[k] == 2)
delete[] (float*) data[k][i][j];
}
}
for( int f = 0 ; f < fillChannels ; ++f )
{
delete[] (float*) data[f+channelTypes.size()][i][j];
}
}
}
}
}
Expand Down Expand Up @@ -720,17 +801,22 @@ void readWriteTestWithAbsoluateCoordinates (int channelCount,
}

generateRandomFile (channelCount, compression, false, false, fn);
readFile (channelCount, false, false, fn);
readFile (channelCount, false, false, false , fn);
readFile (channelCount, false, false, true , fn);
remove (fn.c_str());
cout << endl << flush;

generateRandomFile (channelCount, compression, true, false, fn);
readFile (channelCount, true, false, fn);
readFile (channelCount, true, false, false, fn);
readFile (channelCount, true, false, true, fn);

remove (fn.c_str());
cout << endl << flush;

generateRandomFile (channelCount, compression, false, true, fn);
readFile (channelCount, false, true, fn);
readFile (channelCount, false, true, false , fn);
readFile (channelCount, false, true, true , fn);

remove (fn.c_str());
cout << endl << flush;
}
Expand All @@ -749,10 +835,12 @@ void testDeepTiledBasic (const std::string & tempDir)
int numThreads = ThreadPool::globalThreadPool().numThreads();
ThreadPool::globalThreadPool().setNumThreads(2);

readWriteTestWithAbsoluateCoordinates ( 1, 2, tempDir);
readWriteTestWithAbsoluateCoordinates ( 3, 2, tempDir);
readWriteTestWithAbsoluateCoordinates (10, 2, tempDir);

for(int pass = 0 ; pass < 4 ; pass++)
{
readWriteTestWithAbsoluateCoordinates ( 1, 2, tempDir);
readWriteTestWithAbsoluateCoordinates ( 3, 2, tempDir);
readWriteTestWithAbsoluateCoordinates (10, 2, tempDir);
}
ThreadPool::globalThreadPool().setNumThreads(numThreads);

cout << "ok\n" << endl;
Expand Down

0 comments on commit b1a5c8c

Please sign in to comment.