diff --git a/OpenEXR/IlmImfTest/testDeepTiledBasic.cpp b/OpenEXR/IlmImfTest/testDeepTiledBasic.cpp index bcded5792e..ffff825d5b 100644 --- a/OpenEXR/IlmImfTest/testDeepTiledBasic.cpp +++ b/OpenEXR/IlmImfTest/testDeepTiledBasic.cpp @@ -411,6 +411,7 @@ void checkValue (void* sampleRawData, void readFile (int channelCount, bool bulkRead, bool relativeCoords, + bool randomChannels, const std::string & filename) { if (relativeCoords) @@ -434,8 +435,12 @@ void readFile (int channelCount, Array2D localSampleCount; localSampleCount.resizeErase(height, width); - Array > data(channelCount); - for (int i = 0; i < channelCount; i++) + + // also test filling channels. Generate up to 2 extra channels + int fillChannels=rand()%3; + + Array > data(channelCount+fillChannels); + for (int i = 0; i < channelCount+fillChannels; i++) data[i].resizeErase(height, width); DeepFrameBuffer frameBuffer; @@ -454,30 +459,67 @@ void readFile (int channelCount, relativeCoords, relativeCoords)); + + vector 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 " <((i * width + j) % 2049)) - cout << j << ", " << i << " error, should be " - << (i * width + j) % 2049 << ", is " << value[l] - << endl << flush; - assert (value[l] == static_cast((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(i * width + j) % 2049) + cout << j << ", " << i << " error, should be " + << (i * width + j) % 2049 << ", is " << value[l] + << endl << flush; + assert (value[l] == static_cast(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]; } + } } } } @@ -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; } @@ -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;