Disabled external gits
This commit is contained in:
		
							
								
								
									
										20
									
								
								cs440-acg/ext/openexr/OpenEXR/IlmImfFuzzTest/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								cs440-acg/ext/openexr/OpenEXR/IlmImfFuzzTest/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
# yue.nicholas@gmail.com
 | 
			
		||||
 | 
			
		||||
ADD_EXECUTABLE ( IlmImfFuzzTest
 | 
			
		||||
  fuzzFile.cpp
 | 
			
		||||
  main.cpp
 | 
			
		||||
  testFuzzDeepTiles.cpp
 | 
			
		||||
  testFuzzDeepScanLines.cpp
 | 
			
		||||
  testFuzzScanLines.cpp
 | 
			
		||||
  testFuzzTiles.cpp
 | 
			
		||||
  )
 | 
			
		||||
 | 
			
		||||
TARGET_LINK_LIBRARIES ( IlmImfFuzzTest 
 | 
			
		||||
        IlmImf
 | 
			
		||||
        Half
 | 
			
		||||
        Iex${ILMBASE_LIBSUFFIX}
 | 
			
		||||
        Imath${ILMBASE_LIBSUFFIX}
 | 
			
		||||
        IlmThread${ILMBASE_LIBSUFFIX}
 | 
			
		||||
        ${PTHREAD_LIB} ${ZLIB_LIBRARIES})
 | 
			
		||||
 | 
			
		||||
ADD_TEST ( TestIlmImfFuzz IlmImfFuzzTest )
 | 
			
		||||
							
								
								
									
										27
									
								
								cs440-acg/ext/openexr/OpenEXR/IlmImfFuzzTest/Makefile.am
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								cs440-acg/ext/openexr/OpenEXR/IlmImfFuzzTest/Makefile.am
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
## Process this file with automake to produce Makefile.in
 | 
			
		||||
 | 
			
		||||
if BUILD_IMFFUZZTEST
 | 
			
		||||
check_PROGRAMS = IlmImfFuzzTest
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
IlmImfFuzzTest_SOURCES = fuzzFile.cpp fuzzFile.h main.cpp tmpDir.h \
 | 
			
		||||
			 testFuzzScanLines.cpp testFuzzScanLines.h \
 | 
			
		||||
			 testFuzzDeepScanLines.cpp testFuzzDeepScanLines.h \
 | 
			
		||||
			 testFuzzDeepTiles.cpp testFuzzDeepTiles.h \
 | 
			
		||||
			 testFuzzTiles.cpp testFuzzTiles.h 
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
INCLUDES = -I$(top_builddir)  \
 | 
			
		||||
	   -I$(top_srcdir)/IlmImf \
 | 
			
		||||
	   -I$(top_srcdir)/config \
 | 
			
		||||
	   @ILMBASE_CXXFLAGS@
 | 
			
		||||
 | 
			
		||||
LDADD = -L$(top_builddir)/IlmImf \
 | 
			
		||||
	@ILMBASE_LDFLAGS@ @ILMBASE_LIBS@ \
 | 
			
		||||
	-lIlmImf -lz
 | 
			
		||||
 | 
			
		||||
if BUILD_IMFFUZZTEST
 | 
			
		||||
TESTS = IlmImfFuzzTest
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
EXTRA_DIST = CMakeLists.txt
 | 
			
		||||
							
								
								
									
										198
									
								
								cs440-acg/ext/openexr/OpenEXR/IlmImfFuzzTest/fuzzFile.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										198
									
								
								cs440-acg/ext/openexr/OpenEXR/IlmImfFuzzTest/fuzzFile.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,198 @@
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2007, Industrial Light & Magic, a division of Lucas
 | 
			
		||||
// Digital Ltd. LLC
 | 
			
		||||
// 
 | 
			
		||||
// All rights reserved.
 | 
			
		||||
// 
 | 
			
		||||
// Redistribution and use in source and binary forms, with or without
 | 
			
		||||
// modification, are permitted provided that the following conditions are
 | 
			
		||||
// met:
 | 
			
		||||
// *       Redistributions of source code must retain the above copyright
 | 
			
		||||
// notice, this list of conditions and the following disclaimer.
 | 
			
		||||
// *       Redistributions in binary form must reproduce the above
 | 
			
		||||
// copyright notice, this list of conditions and the following disclaimer
 | 
			
		||||
// in the documentation and/or other materials provided with the
 | 
			
		||||
// distribution.
 | 
			
		||||
// *       Neither the name of Industrial Light & Magic nor the names of
 | 
			
		||||
// its contributors may be used to endorse or promote products derived
 | 
			
		||||
// from this software without specific prior written permission. 
 | 
			
		||||
// 
 | 
			
		||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 | 
			
		||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 | 
			
		||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 | 
			
		||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 | 
			
		||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 | 
			
		||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
			
		||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 | 
			
		||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
//
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include <fuzzFile.h>
 | 
			
		||||
 | 
			
		||||
#include <ImfRgbaFile.h>
 | 
			
		||||
#include <ImfArray.h>
 | 
			
		||||
#include <Iex.h>
 | 
			
		||||
#include <half.h>
 | 
			
		||||
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <fstream>
 | 
			
		||||
 | 
			
		||||
// Handle the case when the custom namespace is not exposed
 | 
			
		||||
#include <OpenEXRConfig.h>
 | 
			
		||||
using namespace OPENEXR_IMF_INTERNAL_NAMESPACE;
 | 
			
		||||
using namespace std;
 | 
			
		||||
using namespace IMATH_NAMESPACE;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
namespace {
 | 
			
		||||
 | 
			
		||||
Int64
 | 
			
		||||
lengthOfFile (const char fileName[])
 | 
			
		||||
{
 | 
			
		||||
    ifstream ifs (fileName, ios_base::binary);
 | 
			
		||||
 | 
			
		||||
    if (!ifs)
 | 
			
		||||
	return 0;
 | 
			
		||||
 | 
			
		||||
    ifs.seekg (0, ios_base::end);
 | 
			
		||||
    return ifs.tellg();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
fuzzFile (const char goodFile[],
 | 
			
		||||
          const char brokenFile[],
 | 
			
		||||
	  Int64 offset,
 | 
			
		||||
	  Int64 windowSize,
 | 
			
		||||
	  Rand48 &random,
 | 
			
		||||
	  double fuzzAmount)
 | 
			
		||||
{
 | 
			
		||||
    //
 | 
			
		||||
    // Read the input file.
 | 
			
		||||
    //
 | 
			
		||||
 | 
			
		||||
    ifstream ifs (goodFile, ios_base::binary);
 | 
			
		||||
 | 
			
		||||
    if (!ifs)
 | 
			
		||||
	THROW_ERRNO ("Cannot open file " << goodFile << " (%T).");
 | 
			
		||||
 | 
			
		||||
    ifs.seekg (0, ios_base::end);
 | 
			
		||||
    Int64 fileLength = ifs.tellg();
 | 
			
		||||
    ifs.seekg (0, ios_base::beg);
 | 
			
		||||
 | 
			
		||||
    Array<char> data (fileLength);
 | 
			
		||||
    ifs.read (data, fileLength);
 | 
			
		||||
 | 
			
		||||
    if (!ifs)
 | 
			
		||||
	THROW_ERRNO ("Cannot read file " << goodFile << " (%T)." << endl);
 | 
			
		||||
 | 
			
		||||
    //
 | 
			
		||||
    // Damage the contents of the file by overwriting some of the bytes
 | 
			
		||||
    // in a window of size windowSize, starting at the specified offset.
 | 
			
		||||
    // 
 | 
			
		||||
 | 
			
		||||
    for (Int64 i = offset; i < offset + windowSize; ++i)
 | 
			
		||||
    {
 | 
			
		||||
	if (random.nextf() < fuzzAmount)
 | 
			
		||||
	    data[i] = char (random.nexti());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //
 | 
			
		||||
    // Save the damaged file contents in the output file.
 | 
			
		||||
    //
 | 
			
		||||
 | 
			
		||||
    ofstream ofs (brokenFile, ios_base::binary);
 | 
			
		||||
 | 
			
		||||
    if (!ofs)
 | 
			
		||||
	THROW_ERRNO ("Cannot open file " << brokenFile << " (%T)." << endl);
 | 
			
		||||
 | 
			
		||||
    ofs.write (data, fileLength);
 | 
			
		||||
 | 
			
		||||
    if (!ofs)
 | 
			
		||||
	THROW_ERRNO ("Cannot write file " << brokenFile << " (%T)." << endl);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
} // namespace
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
fuzzFile (const char goodFile[],
 | 
			
		||||
          const char brokenFile[],
 | 
			
		||||
	  void (*readFile) (const char[]),
 | 
			
		||||
	  int nSlidingWindow,
 | 
			
		||||
	  int nFixedWindow,
 | 
			
		||||
	  Rand48 &random)
 | 
			
		||||
{
 | 
			
		||||
    //
 | 
			
		||||
    // We want to test how resilient the IlmImf library is with respect
 | 
			
		||||
    // to malformed OpenEXR input files.  In order to do this we damage
 | 
			
		||||
    // a good input file by overwriting parts of it with random data.
 | 
			
		||||
    // We then call function readFile() to try and read the damaged file.
 | 
			
		||||
    // Provided the IlmImf library works as advertised, a try/catch(...)
 | 
			
		||||
    // block in readFile() should be able to handle all errors that could
 | 
			
		||||
    // possibly result from reading a broken OpenEXR file.  We repeat
 | 
			
		||||
    // this damage/read cycle many times, overwriting different parts
 | 
			
		||||
    // of the file:
 | 
			
		||||
    //
 | 
			
		||||
    // First we slide a window along the file.  The size of the window
 | 
			
		||||
    // is fileSize*2/nSlidingWindow bytes.  In each damage/read cycle
 | 
			
		||||
    // we overwrite up to 10% of the bytes the window, try to read the
 | 
			
		||||
    // file, and advance the window by fileSize/nSlidingWindow bytes.
 | 
			
		||||
    //
 | 
			
		||||
    // Next we overwrite up to 10% of the file's first 2048 bytes and
 | 
			
		||||
    // try to read the file.  We repeat this nFixedWindow times.
 | 
			
		||||
    //
 | 
			
		||||
 | 
			
		||||
    {
 | 
			
		||||
	Int64 fileSize = lengthOfFile (goodFile);
 | 
			
		||||
	Int64 windowSize = fileSize * 2 / nSlidingWindow;
 | 
			
		||||
	Int64 lastWindowOffset = fileSize - windowSize;
 | 
			
		||||
 | 
			
		||||
	cout << "sliding " << windowSize << "-byte window" << endl;
 | 
			
		||||
 | 
			
		||||
	for (int i = 0; i < nSlidingWindow; ++i)
 | 
			
		||||
	{
 | 
			
		||||
	    if (i % 100 == 0)
 | 
			
		||||
		cout << i << "\r" << flush;
 | 
			
		||||
 | 
			
		||||
	    Int64 offset = lastWindowOffset * i / (nSlidingWindow - 1);
 | 
			
		||||
	    double fuzzAmount = random.nextf (0.0, 0.1);
 | 
			
		||||
 | 
			
		||||
	    fuzzFile (goodFile, brokenFile,
 | 
			
		||||
		      offset, windowSize,
 | 
			
		||||
		      random, fuzzAmount);
 | 
			
		||||
 | 
			
		||||
	    readFile (brokenFile);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	cout << nSlidingWindow << endl;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    {
 | 
			
		||||
	Int64 windowSize = 2048;
 | 
			
		||||
 | 
			
		||||
	cout << windowSize << "-byte window at start of file" << endl;
 | 
			
		||||
 | 
			
		||||
	for (int i = 0; i < nFixedWindow; ++i)
 | 
			
		||||
	{
 | 
			
		||||
	    if (i % 100 == 0)
 | 
			
		||||
		cout << i << "\r" << flush;
 | 
			
		||||
 | 
			
		||||
	    double fuzzAmount = random.nextf (0.0, 0.1);
 | 
			
		||||
 | 
			
		||||
	    fuzzFile (goodFile, brokenFile,
 | 
			
		||||
		      0, windowSize,
 | 
			
		||||
		      random, fuzzAmount);
 | 
			
		||||
 | 
			
		||||
	    readFile (brokenFile);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	cout << nFixedWindow << endl;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										51
									
								
								cs440-acg/ext/openexr/OpenEXR/IlmImfFuzzTest/fuzzFile.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								cs440-acg/ext/openexr/OpenEXR/IlmImfFuzzTest/fuzzFile.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,51 @@
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2007, Industrial Light & Magic, a division of Lucas
 | 
			
		||||
// Digital Ltd. LLC
 | 
			
		||||
// 
 | 
			
		||||
// All rights reserved.
 | 
			
		||||
// 
 | 
			
		||||
// Redistribution and use in source and binary forms, with or without
 | 
			
		||||
// modification, are permitted provided that the following conditions are
 | 
			
		||||
// met:
 | 
			
		||||
// *       Redistributions of source code must retain the above copyright
 | 
			
		||||
// notice, this list of conditions and the following disclaimer.
 | 
			
		||||
// *       Redistributions in binary form must reproduce the above
 | 
			
		||||
// copyright notice, this list of conditions and the following disclaimer
 | 
			
		||||
// in the documentation and/or other materials provided with the
 | 
			
		||||
// distribution.
 | 
			
		||||
// *       Neither the name of Industrial Light & Magic nor the names of
 | 
			
		||||
// its contributors may be used to endorse or promote products derived
 | 
			
		||||
// from this software without specific prior written permission. 
 | 
			
		||||
// 
 | 
			
		||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 | 
			
		||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 | 
			
		||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 | 
			
		||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 | 
			
		||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 | 
			
		||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
			
		||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 | 
			
		||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
//
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef INCLUDED_FUZZ_FILE_H
 | 
			
		||||
#define INCLUDED_FUZZ_FILE_H
 | 
			
		||||
 | 
			
		||||
#include <ImathRandom.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
fuzzFile (const char goodFile[],
 | 
			
		||||
          const char brokenFile[],
 | 
			
		||||
	  void (*readFile) (const char[]),
 | 
			
		||||
	  int nSlidingWindow,
 | 
			
		||||
	  int nFixedWindow,
 | 
			
		||||
	  IMATH_NAMESPACE::Rand48 &random);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										76
									
								
								cs440-acg/ext/openexr/OpenEXR/IlmImfFuzzTest/main.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								cs440-acg/ext/openexr/OpenEXR/IlmImfFuzzTest/main.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,76 @@
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2007, Industrial Light & Magic, a division of Lucas
 | 
			
		||||
// Digital Ltd. LLC
 | 
			
		||||
// 
 | 
			
		||||
// All rights reserved.
 | 
			
		||||
// 
 | 
			
		||||
// Redistribution and use in source and binary forms, with or without
 | 
			
		||||
// modification, are permitted provided that the following conditions are
 | 
			
		||||
// met:
 | 
			
		||||
// *       Redistributions of source code must retain the above copyright
 | 
			
		||||
// notice, this list of conditions and the following disclaimer.
 | 
			
		||||
// *       Redistributions in binary form must reproduce the above
 | 
			
		||||
// copyright notice, this list of conditions and the following disclaimer
 | 
			
		||||
// in the documentation and/or other materials provided with the
 | 
			
		||||
// distribution.
 | 
			
		||||
// *       Neither the name of Industrial Light & Magic nor the names of
 | 
			
		||||
// its contributors may be used to endorse or promote products derived
 | 
			
		||||
// from this software without specific prior written permission. 
 | 
			
		||||
// 
 | 
			
		||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 | 
			
		||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 | 
			
		||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 | 
			
		||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 | 
			
		||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 | 
			
		||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
			
		||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 | 
			
		||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
//
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "ImfNamespace.h"
 | 
			
		||||
#include "testFuzzDeepScanLines.h"
 | 
			
		||||
#include "testFuzzDeepTiles.h"
 | 
			
		||||
#include "testFuzzScanLines.h"
 | 
			
		||||
#include "testFuzzTiles.h"
 | 
			
		||||
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#ifdef OPENEXR_IMF_HAVE_LINUX_PROCFS
 | 
			
		||||
    #include <unistd.h>
 | 
			
		||||
    #include <sstream>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define TEST(x) if (argc < 2 || !strcmp (argv[1], #x)) x();
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
main (int argc, char *argv[])
 | 
			
		||||
{
 | 
			
		||||
    TEST (testFuzzScanLines);
 | 
			
		||||
    TEST (testFuzzTiles);
 | 
			
		||||
    TEST (testFuzzDeepScanLines);
 | 
			
		||||
    TEST (testFuzzDeepTiles);
 | 
			
		||||
    
 | 
			
		||||
#ifdef OPENEXR_IMF_HAVE_LINUX_PROCFS
 | 
			
		||||
 | 
			
		||||
    //
 | 
			
		||||
    // Allow the user to check for file descriptor leaks
 | 
			
		||||
    //
 | 
			
		||||
 | 
			
		||||
    std::cout << "open file descriptors:" << std::endl;
 | 
			
		||||
 | 
			
		||||
    std::stringstream ss;
 | 
			
		||||
    ss << "ls -lG /proc/" << getpid() << "/fd";
 | 
			
		||||
 | 
			
		||||
    system (ss.str().c_str());
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,431 @@
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2013, Industrial Light & Magic, a division of Lucas
 | 
			
		||||
// Digital Ltd. LLC and Weta Digital Ltd
 | 
			
		||||
// 
 | 
			
		||||
// All rights reserved.
 | 
			
		||||
// 
 | 
			
		||||
// Redistribution and use in source and binary forms, with or without
 | 
			
		||||
// modification, are permitted provided that the following conditions are
 | 
			
		||||
// met:
 | 
			
		||||
// *       Redistributions of source code must retain the above copyright
 | 
			
		||||
// notice, this list of conditions and the following disclaimer.
 | 
			
		||||
// *       Redistributions in binary form must reproduce the above
 | 
			
		||||
// copyright notice, this list of conditions and the following disclaimer
 | 
			
		||||
// in the documentation and/or other materials provided with the
 | 
			
		||||
// distribution.
 | 
			
		||||
// *       Neither the name of Industrial Light & Magic nor the names of
 | 
			
		||||
// its contributors may be used to endorse or promote products derived
 | 
			
		||||
// from this software without specific prior written permission. 
 | 
			
		||||
// 
 | 
			
		||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 | 
			
		||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 | 
			
		||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 | 
			
		||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 | 
			
		||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 | 
			
		||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
			
		||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 | 
			
		||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
//
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "fuzzFile.h"
 | 
			
		||||
 | 
			
		||||
#include <ImfDeepScanLineOutputFile.h>
 | 
			
		||||
#include <ImfDeepScanLineInputFile.h>
 | 
			
		||||
#include <ImfDeepFrameBuffer.h>
 | 
			
		||||
#include <ImfPartType.h>
 | 
			
		||||
#include <ImfArray.h>
 | 
			
		||||
#include <ImfThreading.h>
 | 
			
		||||
#include <IlmThread.h>
 | 
			
		||||
#include <Iex.h>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <cassert>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
#include "tmpDir.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Handle the case when the custom namespace is not exposed
 | 
			
		||||
#include <ImfNamespace.h>
 | 
			
		||||
#include <ImfChannelList.h>
 | 
			
		||||
#include <ImfMultiPartOutputFile.h>
 | 
			
		||||
#include <ImfDeepScanLineOutputPart.h>
 | 
			
		||||
#include <ImfMultiPartInputFile.h>
 | 
			
		||||
#include <ImfDeepScanLineInputPart.h>
 | 
			
		||||
 | 
			
		||||
namespace IMF = OPENEXR_IMF_NAMESPACE;
 | 
			
		||||
using namespace IMF;
 | 
			
		||||
using namespace std;
 | 
			
		||||
using namespace IMATH_NAMESPACE;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
namespace
 | 
			
		||||
{
 | 
			
		||||
    
 | 
			
		||||
const int width = 90;
 | 
			
		||||
const int height = 80;
 | 
			
		||||
const int minX = 10;
 | 
			
		||||
const int minY = 11;
 | 
			
		||||
const Box2i dataWindow(V2i(minX, minY), V2i(minX + width - 1, minY + height - 1));
 | 
			
		||||
const Box2i displayWindow(V2i(0, 0), V2i(minX + width * 2, minY + height * 2));
 | 
			
		||||
 | 
			
		||||
Array2D<unsigned int> sampleCount;
 | 
			
		||||
 | 
			
		||||
void generateRandomFile(const char filename[], int channelCount,int parts , Compression compression)
 | 
			
		||||
{
 | 
			
		||||
    cout << "generating file with " << parts << " parts and compression " << compression << flush;
 | 
			
		||||
    vector<Header> headers(parts);
 | 
			
		||||
    
 | 
			
		||||
    headers[0] = Header(displayWindow, dataWindow,
 | 
			
		||||
                    1,
 | 
			
		||||
                    IMATH_NAMESPACE::V2f (0, 0),
 | 
			
		||||
                    1,
 | 
			
		||||
                    INCREASING_Y,
 | 
			
		||||
                    compression);
 | 
			
		||||
                        
 | 
			
		||||
                    
 | 
			
		||||
                        
 | 
			
		||||
    for (int i = 0; i < channelCount; i++)
 | 
			
		||||
    {
 | 
			
		||||
        stringstream ss;
 | 
			
		||||
        ss << i;
 | 
			
		||||
        string str = ss.str();
 | 
			
		||||
        headers[0].channels().insert(str, Channel(IMF::FLOAT));
 | 
			
		||||
    }
 | 
			
		||||
                        
 | 
			
		||||
     headers[0].setType(DEEPSCANLINE);
 | 
			
		||||
            
 | 
			
		||||
     headers[0].setName("bob");
 | 
			
		||||
     
 | 
			
		||||
     for(int p=1;p<parts;p++)
 | 
			
		||||
     {
 | 
			
		||||
         headers[p]=headers[0];
 | 
			
		||||
         ostringstream s;
 | 
			
		||||
         s << p;
 | 
			
		||||
         headers[p].setName(s.str());
 | 
			
		||||
     }
 | 
			
		||||
     
 | 
			
		||||
     
 | 
			
		||||
     Array<Array2D< void* > > data(channelCount);
 | 
			
		||||
     for (int i = 0; i < channelCount; i++)
 | 
			
		||||
         data[i].resizeErase(height, width);
 | 
			
		||||
     
 | 
			
		||||
     sampleCount.resizeErase(height, width);
 | 
			
		||||
                        
 | 
			
		||||
     remove (filename);
 | 
			
		||||
     
 | 
			
		||||
 | 
			
		||||
     MultiPartOutputFile file(filename,&headers[0],parts);
 | 
			
		||||
 | 
			
		||||
     DeepFrameBuffer frameBuffer;
 | 
			
		||||
         
 | 
			
		||||
     frameBuffer.insertSampleCountSlice (Slice (IMF::UINT,        // type // 7
 | 
			
		||||
                                                (char *) (&sampleCount[0][0]
 | 
			
		||||
                                                - dataWindow.min.x
 | 
			
		||||
                                                - dataWindow.min.y * width),        // base // 8
 | 
			
		||||
                                                sizeof (unsigned int) * 1,          // xStride// 9
 | 
			
		||||
                                                sizeof (unsigned int) * width));    // yStride// 10
 | 
			
		||||
     
 | 
			
		||||
     for (int i = 0; i < channelCount; i++)
 | 
			
		||||
     {
 | 
			
		||||
         PixelType type = IMF::FLOAT;
 | 
			
		||||
         stringstream ss;
 | 
			
		||||
         ss << i;
 | 
			
		||||
         string str = ss.str();
 | 
			
		||||
         
 | 
			
		||||
         int sampleSize = sizeof (float);
 | 
			
		||||
                            
 | 
			
		||||
         int pointerSize = sizeof(char *);
 | 
			
		||||
         
 | 
			
		||||
         frameBuffer.insert (str,                                    // name // 6
 | 
			
		||||
                             DeepSlice (type,                        // type // 7
 | 
			
		||||
                                        (char *) (&data[i][0][0]
 | 
			
		||||
                                        - dataWindow.min.x
 | 
			
		||||
                                        - dataWindow.min.y * width), // base // 8
 | 
			
		||||
                                        pointerSize * 1,             // xStride// 9
 | 
			
		||||
                                        pointerSize * width,         // yStride// 10
 | 
			
		||||
                                        sampleSize));                // sampleStride
 | 
			
		||||
     }
 | 
			
		||||
 | 
			
		||||
    for(int p=0;p<parts;p++)
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        DeepScanLineOutputPart pt(file,p);
 | 
			
		||||
        pt.setFrameBuffer(frameBuffer);
 | 
			
		||||
                        
 | 
			
		||||
        cout << "writing " << p << flush;
 | 
			
		||||
        for (int i = 0; i < height; i++)
 | 
			
		||||
        {
 | 
			
		||||
            //
 | 
			
		||||
            // Fill in data at the last minute.
 | 
			
		||||
            //
 | 
			
		||||
            
 | 
			
		||||
            for (int j = 0; j < width; j++)
 | 
			
		||||
            {
 | 
			
		||||
                sampleCount[i][j] = rand() % 4 + 1;
 | 
			
		||||
                for (int k = 0; k < channelCount; k++)
 | 
			
		||||
                {
 | 
			
		||||
                    data[k][i][j] = new float[sampleCount[i][j]];
 | 
			
		||||
                    for (int l = 0; l < sampleCount[i][j]; l++)
 | 
			
		||||
                    {
 | 
			
		||||
                        ((float*)data[k][i][j])[l] = (i * width + j) % 2049;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        pt.writePixels(height);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
    
 | 
			
		||||
void readFile(const char filename[])
 | 
			
		||||
{
 | 
			
		||||
    //single part interface to read file
 | 
			
		||||
    try{
 | 
			
		||||
        
 | 
			
		||||
        DeepScanLineInputFile file(filename, 8);
 | 
			
		||||
        
 | 
			
		||||
        
 | 
			
		||||
        const Header& fileHeader = file.header();
 | 
			
		||||
        
 | 
			
		||||
        int channelCount=0;
 | 
			
		||||
        for(ChannelList::ConstIterator i=fileHeader.channels().begin();i!=fileHeader.channels().end();++i,++channelCount);
 | 
			
		||||
        
 | 
			
		||||
        Array2D<unsigned int> localSampleCount;
 | 
			
		||||
        localSampleCount.resizeErase(height, width);
 | 
			
		||||
        Array<Array2D< void* > > data(channelCount);
 | 
			
		||||
        
 | 
			
		||||
        
 | 
			
		||||
        for (int i = 0; i < channelCount; i++)
 | 
			
		||||
            data[i].resizeErase(height, width);
 | 
			
		||||
        
 | 
			
		||||
        DeepFrameBuffer frameBuffer;
 | 
			
		||||
        
 | 
			
		||||
        frameBuffer.insertSampleCountSlice (Slice (IMF::UINT,        // type // 7
 | 
			
		||||
                                                   (char *) (&localSampleCount[0][0]
 | 
			
		||||
                                                   - dataWindow.min.x
 | 
			
		||||
                                                   - dataWindow.min.y * width),        // base // 8)
 | 
			
		||||
                                                   sizeof (unsigned int) * 1,          // xStride// 9
 | 
			
		||||
                                                   sizeof (unsigned int) * width));    // yStride// 10
 | 
			
		||||
        
 | 
			
		||||
        vector<int> read_channel(channelCount);
 | 
			
		||||
        
 | 
			
		||||
        
 | 
			
		||||
        for (int i = 0; i < channelCount; i++)
 | 
			
		||||
        {
 | 
			
		||||
            PixelType type = IMF::FLOAT;
 | 
			
		||||
            
 | 
			
		||||
            stringstream ss;
 | 
			
		||||
            ss << i;
 | 
			
		||||
            string str = ss.str();
 | 
			
		||||
            
 | 
			
		||||
            int sampleSize = sizeof (float);
 | 
			
		||||
            
 | 
			
		||||
            int pointerSize = sizeof (char *);
 | 
			
		||||
            
 | 
			
		||||
            frameBuffer.insert (str,                    
 | 
			
		||||
                                DeepSlice (type,        
 | 
			
		||||
                                           (char *) (&data[i][0][0]
 | 
			
		||||
                                           - dataWindow.min.x
 | 
			
		||||
                                           - dataWindow.min.y * width), // base // 8)
 | 
			
		||||
                                           pointerSize * 1,             // xStride// 9
 | 
			
		||||
                                           pointerSize * width,         // yStride// 10
 | 
			
		||||
                                           sampleSize));                // sampleStride
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        
 | 
			
		||||
        
 | 
			
		||||
        file.setFrameBuffer(frameBuffer);
 | 
			
		||||
        file.readPixelSampleCounts(dataWindow.min.y, dataWindow.max.y);
 | 
			
		||||
        for (int i = 0; i < dataWindow.max.y - dataWindow.min.y + 1; i++)
 | 
			
		||||
        {
 | 
			
		||||
            int y = i + dataWindow.min.y;
 | 
			
		||||
            
 | 
			
		||||
            for (int j = 0; j < width; j++)
 | 
			
		||||
            {
 | 
			
		||||
                for (int k = 0; k < channelCount; k++)
 | 
			
		||||
                {
 | 
			
		||||
                    data[k][i][j] = new float[localSampleCount[i][j]];
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        try{
 | 
			
		||||
            file.readPixels(dataWindow.min.y, dataWindow.max.y);
 | 
			
		||||
        }catch(...)
 | 
			
		||||
        {
 | 
			
		||||
            // if readPixels excepts we must clean up
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        for (int i = 0; i < height; i++)
 | 
			
		||||
            for (int j = 0; j < width; j++)
 | 
			
		||||
                for (int k = 0; k < channelCount; k++)
 | 
			
		||||
                {
 | 
			
		||||
                    delete[] (float*) data[k][i][j];
 | 
			
		||||
                }
 | 
			
		||||
                
 | 
			
		||||
    }catch(std::exception & e)
 | 
			
		||||
    {
 | 
			
		||||
        /* ... yeah, that's likely to happen a lot ... */
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    try{
 | 
			
		||||
        
 | 
			
		||||
        MultiPartInputFile file(filename, 8);
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
        for(int p=0;p<file.parts();p++)
 | 
			
		||||
        {
 | 
			
		||||
            DeepScanLineInputPart inpart(file,p);
 | 
			
		||||
            const Header& fileHeader = inpart.header();
 | 
			
		||||
            
 | 
			
		||||
            int channelCount=0;
 | 
			
		||||
            for(ChannelList::ConstIterator i=fileHeader.channels().begin();i!=fileHeader.channels().end();++i,++channelCount);
 | 
			
		||||
            
 | 
			
		||||
            Array2D<unsigned int> localSampleCount;
 | 
			
		||||
            localSampleCount.resizeErase(height, width);
 | 
			
		||||
            Array<Array2D< void* > > data(channelCount);
 | 
			
		||||
            
 | 
			
		||||
            
 | 
			
		||||
            for (int i = 0; i < channelCount; i++)
 | 
			
		||||
                data[i].resizeErase(height, width);
 | 
			
		||||
            
 | 
			
		||||
            DeepFrameBuffer frameBuffer;
 | 
			
		||||
            
 | 
			
		||||
            frameBuffer.insertSampleCountSlice (Slice (IMF::UINT,        // type // 7
 | 
			
		||||
                                                       (char *) (&localSampleCount[0][0]
 | 
			
		||||
                                                       - dataWindow.min.x
 | 
			
		||||
                                                       - dataWindow.min.y * width),        // base // 8)
 | 
			
		||||
                                                       sizeof (unsigned int) * 1,          // xStride// 9
 | 
			
		||||
                                                       sizeof (unsigned int) * width));    // yStride// 10
 | 
			
		||||
            
 | 
			
		||||
            vector<int> read_channel(channelCount);
 | 
			
		||||
            
 | 
			
		||||
        
 | 
			
		||||
            for (int i = 0; i < channelCount; i++)
 | 
			
		||||
            {
 | 
			
		||||
                PixelType type = IMF::FLOAT;
 | 
			
		||||
                
 | 
			
		||||
                stringstream ss;
 | 
			
		||||
                ss << i;
 | 
			
		||||
                string str = ss.str();
 | 
			
		||||
                
 | 
			
		||||
                int sampleSize = sizeof (float);
 | 
			
		||||
                
 | 
			
		||||
                int pointerSize = sizeof (char *);
 | 
			
		||||
                
 | 
			
		||||
                frameBuffer.insert (str,                    
 | 
			
		||||
                                    DeepSlice (type,        
 | 
			
		||||
                                               (char *) (&data[i][0][0]
 | 
			
		||||
                                               - dataWindow.min.x
 | 
			
		||||
                                               - dataWindow.min.y * width), // base // 8)
 | 
			
		||||
                                               pointerSize * 1,             // xStride// 9
 | 
			
		||||
                                               pointerSize * width,         // yStride// 10
 | 
			
		||||
                                               sampleSize));                // sampleStride
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
            inpart.setFrameBuffer(frameBuffer);
 | 
			
		||||
            inpart.readPixelSampleCounts(dataWindow.min.y, dataWindow.max.y);
 | 
			
		||||
            for (int i = 0; i < dataWindow.max.y - dataWindow.min.y + 1; i++)
 | 
			
		||||
            {
 | 
			
		||||
                int y = i + dataWindow.min.y;
 | 
			
		||||
                
 | 
			
		||||
                for (int j = 0; j < width; j++)
 | 
			
		||||
                {
 | 
			
		||||
                    for (int k = 0; k < channelCount; k++)
 | 
			
		||||
                    {
 | 
			
		||||
                        data[k][i][j] = new float[localSampleCount[i][j]];
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            try{
 | 
			
		||||
                inpart.readPixels(dataWindow.min.y, dataWindow.max.y);
 | 
			
		||||
            }catch(...)
 | 
			
		||||
            {
 | 
			
		||||
                
 | 
			
		||||
            }
 | 
			
		||||
    
 | 
			
		||||
            for (int i = 0; i < height; i++)
 | 
			
		||||
            {
 | 
			
		||||
                for (int j = 0; j < width; j++)
 | 
			
		||||
                {
 | 
			
		||||
                    for (int k = 0; k < channelCount; k++)
 | 
			
		||||
                    {
 | 
			
		||||
                        delete[] (float*) data[k][i][j];
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }catch(...)
 | 
			
		||||
    {
 | 
			
		||||
        // nothing
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
fuzzDeepScanLines (int numThreads, Rand48 &random)
 | 
			
		||||
{
 | 
			
		||||
    if (ILMTHREAD_NAMESPACE::supportsThreads())
 | 
			
		||||
    {
 | 
			
		||||
	setGlobalThreadCount (numThreads);
 | 
			
		||||
	cout << "\nnumber of threads: " << globalThreadCount() << endl;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Header::setMaxImageSize (10000, 10000);
 | 
			
		||||
 | 
			
		||||
    const char *goodFile = IMF_TMP_DIR "imf_test_deep_scanline_file_fuzz_good.exr";
 | 
			
		||||
    const char *brokenFile = IMF_TMP_DIR "imf_test_deep_scanline_file_fuzz_broken.exr";
 | 
			
		||||
 | 
			
		||||
    // read file if it already exists: allows re-testing reading of broken file
 | 
			
		||||
    readFile(brokenFile);
 | 
			
		||||
    
 | 
			
		||||
    for(int parts=1 ; parts < 3 ; parts++)
 | 
			
		||||
    {
 | 
			
		||||
        for(int comp_method=0;comp_method<2;comp_method++)
 | 
			
		||||
        {
 | 
			
		||||
            generateRandomFile(goodFile,8,parts,comp_method==0 ? NO_COMPRESSION : ZIPS_COMPRESSION);
 | 
			
		||||
            fuzzFile (goodFile, brokenFile, readFile, 5000, 3000, random);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    remove (goodFile);
 | 
			
		||||
    remove (brokenFile);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
} // namespace
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
testFuzzDeepScanLines ()
 | 
			
		||||
{
 | 
			
		||||
    try
 | 
			
		||||
    {
 | 
			
		||||
	cout << "Testing deep scanline-based files "
 | 
			
		||||
		"with randomly inserted errors" << endl;
 | 
			
		||||
 | 
			
		||||
	Rand48 random (1);
 | 
			
		||||
 | 
			
		||||
	fuzzDeepScanLines (0, random);
 | 
			
		||||
 | 
			
		||||
	if (ILMTHREAD_NAMESPACE::supportsThreads())
 | 
			
		||||
	    fuzzDeepScanLines (2, random);
 | 
			
		||||
 | 
			
		||||
	cout << "ok\n" << endl;
 | 
			
		||||
    }
 | 
			
		||||
    catch (const std::exception &e)
 | 
			
		||||
    {
 | 
			
		||||
	cerr << "ERROR -- caught exception: " << e.what() << endl;
 | 
			
		||||
	assert (false);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,39 @@
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2013, Industrial Light & Magic, a division of Lucas
 | 
			
		||||
// Digital Ltd. LLC and Weta Digital Ltd
 | 
			
		||||
// 
 | 
			
		||||
// All rights reserved.
 | 
			
		||||
// 
 | 
			
		||||
// Redistribution and use in source and binary forms, with or without
 | 
			
		||||
// modification, are permitted provided that the following conditions are
 | 
			
		||||
// met:
 | 
			
		||||
// *       Redistributions of source code must retain the above copyright
 | 
			
		||||
// notice, this list of conditions and the following disclaimer.
 | 
			
		||||
// *       Redistributions in binary form must reproduce the above
 | 
			
		||||
// copyright notice, this list of conditions and the following disclaimer
 | 
			
		||||
// in the documentation and/or other materials provided with the
 | 
			
		||||
// distribution.
 | 
			
		||||
// *       Neither the name of Industrial Light & Magic nor the names of
 | 
			
		||||
// its contributors may be used to endorse or promote products derived
 | 
			
		||||
// from this software without specific prior written permission. 
 | 
			
		||||
// 
 | 
			
		||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 | 
			
		||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 | 
			
		||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 | 
			
		||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 | 
			
		||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 | 
			
		||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
			
		||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 | 
			
		||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
//
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void testFuzzDeepScanLines ();
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,524 @@
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2013, Industrial Light & Magic, a division of Lucas
 | 
			
		||||
// Digital Ltd. LLC and Weta Digital Ltd
 | 
			
		||||
// 
 | 
			
		||||
// All rights reserved.
 | 
			
		||||
// 
 | 
			
		||||
// Redistribution and use in source and binary forms, with or without
 | 
			
		||||
// modification, are permitted provided that the following conditions are
 | 
			
		||||
// met:
 | 
			
		||||
// *       Redistributions of source code must retain the above copyright
 | 
			
		||||
// notice, this list of conditions and the following disclaimer.
 | 
			
		||||
// *       Redistributions in binary form must reproduce the above
 | 
			
		||||
// copyright notice, this list of conditions and the following disclaimer
 | 
			
		||||
// in the documentation and/or other materials provided with the
 | 
			
		||||
// distribution.
 | 
			
		||||
// *       Neither the name of Industrial Light & Magic nor the names of
 | 
			
		||||
// its contributors may be used to endorse or promote products derived
 | 
			
		||||
// from this software without specific prior written permission. 
 | 
			
		||||
// 
 | 
			
		||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 | 
			
		||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 | 
			
		||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 | 
			
		||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 | 
			
		||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 | 
			
		||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
			
		||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 | 
			
		||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
//
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "fuzzFile.h"
 | 
			
		||||
 | 
			
		||||
#include <ImfDeepTiledOutputFile.h>
 | 
			
		||||
#include <ImfDeepTiledInputFile.h>
 | 
			
		||||
#include <ImfDeepFrameBuffer.h>
 | 
			
		||||
#include <ImfPartType.h>
 | 
			
		||||
#include <ImfArray.h>
 | 
			
		||||
#include <ImfThreading.h>
 | 
			
		||||
#include <IlmThread.h>
 | 
			
		||||
#include <Iex.h>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <cassert>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <vector>
 | 
			
		||||
#include <sstream>
 | 
			
		||||
 | 
			
		||||
#include "tmpDir.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Handle the case when the custom namespace is not exposed
 | 
			
		||||
#include <ImfNamespace.h>
 | 
			
		||||
#include <ImfChannelList.h>
 | 
			
		||||
#include <ImfMultiPartInputFile.h>
 | 
			
		||||
#include <ImfMultiPartOutputFile.h>
 | 
			
		||||
#include <ImfDeepTiledOutputPart.h>
 | 
			
		||||
#include <ImfDeepTiledInputPart.h>
 | 
			
		||||
 | 
			
		||||
namespace IMF = OPENEXR_IMF_NAMESPACE;
 | 
			
		||||
using namespace IMF;
 | 
			
		||||
using namespace std;
 | 
			
		||||
using namespace IMATH_NAMESPACE;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
namespace
 | 
			
		||||
{
 | 
			
		||||
    
 | 
			
		||||
const int width = 127;
 | 
			
		||||
const int height = 46;
 | 
			
		||||
const int minX = 10;
 | 
			
		||||
const int minY = 11;
 | 
			
		||||
const Box2i dataWindow(V2i(minX, minY), V2i(minX + width - 1, minY + height - 1));
 | 
			
		||||
const Box2i displayWindow(V2i(0, 0), V2i(minX + width * 2, minY + height * 2));
 | 
			
		||||
Array2D< Array2D<unsigned int> > sampleCountWhole;
 | 
			
		||||
Header header;
 | 
			
		||||
    
 | 
			
		||||
void generateRandomFile(const char filename[], int channelCount, int parts , Compression compression)                            
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    vector<Header> headers(parts);
 | 
			
		||||
    
 | 
			
		||||
    cout << "generating " << flush;
 | 
			
		||||
    headers[0] = Header(displayWindow, dataWindow,
 | 
			
		||||
                    1,
 | 
			
		||||
                    IMATH_NAMESPACE::V2f (0, 0),
 | 
			
		||||
                    1,
 | 
			
		||||
                    INCREASING_Y,
 | 
			
		||||
                    compression
 | 
			
		||||
                    ); 
 | 
			
		||||
    cout << "compression " << compression << " " << flush;
 | 
			
		||||
                    
 | 
			
		||||
    for (int i = 0; i < channelCount; i++)
 | 
			
		||||
    {
 | 
			
		||||
        ostringstream ss;
 | 
			
		||||
        ss << i;
 | 
			
		||||
        string str = ss.str();
 | 
			
		||||
        headers[0].channels().insert(str, Channel(IMF::FLOAT));
 | 
			
		||||
    }
 | 
			
		||||
       
 | 
			
		||||
    headers[0].setType(DEEPTILE);
 | 
			
		||||
    headers[0].setTileDescription( TileDescription(rand() % width + 1, rand() % height + 1, RIPMAP_LEVELS));
 | 
			
		||||
       
 | 
			
		||||
    headers[0].setName("bob");
 | 
			
		||||
    
 | 
			
		||||
    for(int p=1;p<parts;p++)
 | 
			
		||||
    {
 | 
			
		||||
        headers[p]=headers[0];
 | 
			
		||||
        ostringstream s;
 | 
			
		||||
        s << p;
 | 
			
		||||
        headers[p].setName(s.str());
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    Array<Array2D< void* > > data(channelCount);
 | 
			
		||||
    for (int i = 0; i < channelCount; i++)
 | 
			
		||||
    {
 | 
			
		||||
        data[i].resizeErase(height, width);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    Array2D<unsigned int> sampleCount;
 | 
			
		||||
    sampleCount.resizeErase(height, width);
 | 
			
		||||
       
 | 
			
		||||
    remove (filename);
 | 
			
		||||
    
 | 
			
		||||
    MultiPartOutputFile file(filename, &headers[0], parts);
 | 
			
		||||
    
 | 
			
		||||
    DeepTiledOutputPart part(file,0);
 | 
			
		||||
    
 | 
			
		||||
    cout << "tileSizeX " << part.tileXSize() << " tileSizeY " << part.tileYSize() << " ";
 | 
			
		||||
    
 | 
			
		||||
    sampleCountWhole.resizeErase(part.numYLevels(), part.numXLevels());
 | 
			
		||||
    for (int i = 0; i < sampleCountWhole.height(); i++)
 | 
			
		||||
    {
 | 
			
		||||
        for (int j = 0; j < sampleCountWhole.width(); j++)
 | 
			
		||||
        {
 | 
			
		||||
            sampleCountWhole[i][j].resizeErase(height, width);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    DeepFrameBuffer frameBuffer;
 | 
			
		||||
    
 | 
			
		||||
    int memOffset = dataWindow.min.x + dataWindow.min.y * width;
 | 
			
		||||
                                                
 | 
			
		||||
    frameBuffer.insertSampleCountSlice (Slice (IMF::UINT,
 | 
			
		||||
                                               (char *) (&sampleCount[0][0] - memOffset),
 | 
			
		||||
                                               sizeof (unsigned int) * 1,
 | 
			
		||||
                                               sizeof (unsigned int) * width) );
 | 
			
		||||
    for (int i = 0; i < channelCount; i++)
 | 
			
		||||
    {
 | 
			
		||||
        stringstream ss;
 | 
			
		||||
        ss << i;
 | 
			
		||||
        string str = ss.str();
 | 
			
		||||
        
 | 
			
		||||
        int sampleSize = sizeof (float);
 | 
			
		||||
        
 | 
			
		||||
        int pointerSize = sizeof (char *);
 | 
			
		||||
        
 | 
			
		||||
        frameBuffer.insert (str,
 | 
			
		||||
                            DeepSlice (IMF::FLOAT,
 | 
			
		||||
                                       (char *) (&data[i][0][0] - memOffset),
 | 
			
		||||
                                       pointerSize * 1,
 | 
			
		||||
                                       pointerSize * width,
 | 
			
		||||
                                       sampleSize));
 | 
			
		||||
    }
 | 
			
		||||
       
 | 
			
		||||
    for(int part=0;part<parts;part++)
 | 
			
		||||
    {
 | 
			
		||||
        DeepTiledOutputPart p(file,part);
 | 
			
		||||
        p.setFrameBuffer(frameBuffer);
 | 
			
		||||
                                                                                           
 | 
			
		||||
        cout << "writing " << flush;
 | 
			
		||||
                                                                                           
 | 
			
		||||
        for (int ly = 0; ly < p.numYLevels(); ly++)
 | 
			
		||||
        {
 | 
			
		||||
            for (int lx = 0; lx < p.numXLevels(); lx++)
 | 
			
		||||
            {
 | 
			
		||||
                Box2i dataWindowL = p.dataWindowForLevel(lx, ly);
 | 
			
		||||
                
 | 
			
		||||
                for (int j = 0; j < p.numYTiles(ly); j++)
 | 
			
		||||
                {
 | 
			
		||||
                    for (int i = 0; i < p.numXTiles(lx); i++)
 | 
			
		||||
                    {
 | 
			
		||||
                        Box2i box = p.dataWindowForTile(i, j, lx, ly);
 | 
			
		||||
                        for (int y = box.min.y; y <= box.max.y; y++)
 | 
			
		||||
                        {
 | 
			
		||||
                            for (int x = box.min.x; x <= box.max.x; x++)
 | 
			
		||||
                            {
 | 
			
		||||
                                int dwy = y - dataWindowL.min.y;
 | 
			
		||||
                                int dwx = x - dataWindowL.min.x;
 | 
			
		||||
                                sampleCount[dwy][dwx] = rand() % 5 + 1;
 | 
			
		||||
                                sampleCountWhole[ly][lx][dwy][dwx] = sampleCount[dwy][dwx];
 | 
			
		||||
                                for (int k = 0; k < channelCount; k++)
 | 
			
		||||
                                {
 | 
			
		||||
                                    data[k][dwy][dwx] = new float[sampleCount[dwy][dwx]];
 | 
			
		||||
                                    for (int l = 0; l < sampleCount[dwy][dwx]; l++)
 | 
			
		||||
                                    {
 | 
			
		||||
                                        ((float*)data[k][dwy][dwx])[l] = (dwy * width + dwx) % 2049;
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                
 | 
			
		||||
                p.writeTiles(0, p.numXTiles(lx) - 1, 0, p.numYTiles(ly) - 1, lx, ly);
 | 
			
		||||
                    
 | 
			
		||||
                
 | 
			
		||||
                for(int k=0;k<data.size();k++)
 | 
			
		||||
                {
 | 
			
		||||
                    for(int y=0;y<data[k].height();y++)
 | 
			
		||||
                    {
 | 
			
		||||
                        for(int x=0;x<data[k].width();x++)
 | 
			
		||||
                        {
 | 
			
		||||
                            delete data[k][y][x];
 | 
			
		||||
                            data[k][y][x]=0;
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                
 | 
			
		||||
                
 | 
			
		||||
                
 | 
			
		||||
            }// next level
 | 
			
		||||
        }//next level
 | 
			
		||||
    }//next part
 | 
			
		||||
}
 | 
			
		||||
                            
 | 
			
		||||
void readFile(const char filename[])
 | 
			
		||||
{
 | 
			
		||||
                       
 | 
			
		||||
    try
 | 
			
		||||
    {
 | 
			
		||||
        DeepTiledInputFile file(filename, 8);
 | 
			
		||||
    
 | 
			
		||||
        const Header& fileHeader = file.header();
 | 
			
		||||
        
 | 
			
		||||
        Array2D<unsigned int> localSampleCount;
 | 
			
		||||
        
 | 
			
		||||
        Box2i dataWindow = fileHeader.dataWindow();
 | 
			
		||||
        
 | 
			
		||||
        int height = dataWindow.size().y+1;
 | 
			
		||||
        int width = dataWindow.size().x+1;
 | 
			
		||||
        
 | 
			
		||||
        
 | 
			
		||||
        localSampleCount.resizeErase(height, width);
 | 
			
		||||
        
 | 
			
		||||
        int channelCount=0;
 | 
			
		||||
        for(ChannelList::ConstIterator i=fileHeader.channels().begin();i!=fileHeader.channels().end();++i, channelCount++);
 | 
			
		||||
        
 | 
			
		||||
        Array<Array2D< void* > > data(channelCount);
 | 
			
		||||
        
 | 
			
		||||
        for (int i = 0; i < channelCount; i++)
 | 
			
		||||
        {
 | 
			
		||||
            data[i].resizeErase(height, width);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        DeepFrameBuffer frameBuffer;
 | 
			
		||||
        
 | 
			
		||||
        int memOffset = dataWindow.min.x + dataWindow.min.y * width;
 | 
			
		||||
        frameBuffer.insertSampleCountSlice (Slice (IMF::UINT,
 | 
			
		||||
                                                   (char *) (&localSampleCount[0][0] - memOffset),
 | 
			
		||||
                                                   sizeof (unsigned int) * 1,
 | 
			
		||||
                                                   sizeof (unsigned int) * width)
 | 
			
		||||
                                                   );
 | 
			
		||||
                                                   
 | 
			
		||||
         for (int i = 0; i < channelCount; i++)
 | 
			
		||||
         {                              
 | 
			
		||||
             stringstream ss;
 | 
			
		||||
             ss << i;
 | 
			
		||||
             string str = ss.str();
 | 
			
		||||
             
 | 
			
		||||
             int sampleSize  = sizeof (float);
 | 
			
		||||
             
 | 
			
		||||
             int pointerSize = sizeof (char *);
 | 
			
		||||
             
 | 
			
		||||
             frameBuffer.insert (str,
 | 
			
		||||
                                 DeepSlice (IMF::FLOAT,
 | 
			
		||||
                                            (char *) (&data[i][0][0] - memOffset),
 | 
			
		||||
                                            pointerSize * 1,
 | 
			
		||||
                                            pointerSize * width,
 | 
			
		||||
                                            sampleSize) );
 | 
			
		||||
         }
 | 
			
		||||
         
 | 
			
		||||
         file.setFrameBuffer(frameBuffer);
 | 
			
		||||
         for (int ly = 0; ly < file.numYLevels(); ly++)
 | 
			
		||||
         {
 | 
			
		||||
             for (int lx = 0; lx < file.numXLevels(); lx++)
 | 
			
		||||
             {
 | 
			
		||||
                 Box2i dataWindowL = file.dataWindowForLevel(lx, ly);
 | 
			
		||||
                 
 | 
			
		||||
                 
 | 
			
		||||
                 file.readPixelSampleCounts(0, file.numXTiles(lx) - 1, 0, file.numYTiles(ly) - 1, lx, ly);
 | 
			
		||||
                 
 | 
			
		||||
                 for (int i = 0; i < file.numYTiles(ly); i++)
 | 
			
		||||
                 {
 | 
			
		||||
                     for (int j = 0; j < file.numXTiles(lx); j++)
 | 
			
		||||
                     {
 | 
			
		||||
                         Box2i box = file.dataWindowForTile(j, i, lx, ly);
 | 
			
		||||
                         for (int y = box.min.y; y <= box.max.y; y++)
 | 
			
		||||
                             for (int x = box.min.x; x <= box.max.x; x++)
 | 
			
		||||
                             {
 | 
			
		||||
                                 int dwy = y - dataWindowL.min.y;
 | 
			
		||||
                                 int dwx = x - dataWindowL.min.x;
 | 
			
		||||
                                 
 | 
			
		||||
                                 for (int k = 0; k < channelCount; k++)
 | 
			
		||||
                                 {
 | 
			
		||||
                                     data[k][dwy][dwx] = new float[localSampleCount[dwy][dwx]];
 | 
			
		||||
                                 }
 | 
			
		||||
                             }
 | 
			
		||||
                     }
 | 
			
		||||
                 }
 | 
			
		||||
                 
 | 
			
		||||
                 try{
 | 
			
		||||
                     
 | 
			
		||||
                     file.readTiles(0, file.numXTiles(lx) - 1, 0, file.numYTiles(ly) - 1, lx, ly);
 | 
			
		||||
                 }catch(...)
 | 
			
		||||
                 {
 | 
			
		||||
                     // catch exceptions thrown by readTiles, clean up anyway
 | 
			
		||||
                 }
 | 
			
		||||
                 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++)
 | 
			
		||||
                         {
 | 
			
		||||
                             delete[] (float*) data[k][i][j];
 | 
			
		||||
                         }
 | 
			
		||||
                     }
 | 
			
		||||
                 }
 | 
			
		||||
             }
 | 
			
		||||
         }
 | 
			
		||||
         
 | 
			
		||||
    }catch(std::exception & e)
 | 
			
		||||
    {
 | 
			
		||||
        /* expect to get exceptions*/
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    // test multipart inputfile interface
 | 
			
		||||
    
 | 
			
		||||
    try
 | 
			
		||||
    {
 | 
			
		||||
        MultiPartInputFile file(filename, 8);
 | 
			
		||||
        
 | 
			
		||||
        for(int p=0;p<file.parts();p++)
 | 
			
		||||
        {
 | 
			
		||||
            DeepTiledInputPart part(file,p);
 | 
			
		||||
            const Header& fileHeader = part.header();
 | 
			
		||||
        
 | 
			
		||||
            Array2D<unsigned int> localSampleCount;
 | 
			
		||||
        
 | 
			
		||||
            Box2i dataWindow = fileHeader.dataWindow();
 | 
			
		||||
            
 | 
			
		||||
            int height = dataWindow.size().y+1;
 | 
			
		||||
            int width = dataWindow.size().x+1;
 | 
			
		||||
        
 | 
			
		||||
        
 | 
			
		||||
            localSampleCount.resizeErase(height, width);
 | 
			
		||||
            
 | 
			
		||||
            int channelCount=0;
 | 
			
		||||
            for(ChannelList::ConstIterator i=fileHeader.channels().begin();i!=fileHeader.channels().end();++i, channelCount++);
 | 
			
		||||
            
 | 
			
		||||
            Array<Array2D< void* > > data(channelCount);
 | 
			
		||||
            
 | 
			
		||||
            for (int i = 0; i < channelCount; i++)
 | 
			
		||||
            {
 | 
			
		||||
                data[i].resizeErase(height, width);
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
            DeepFrameBuffer frameBuffer;
 | 
			
		||||
        
 | 
			
		||||
            int memOffset = dataWindow.min.x + dataWindow.min.y * width;
 | 
			
		||||
            frameBuffer.insertSampleCountSlice (Slice (IMF::UINT,
 | 
			
		||||
                                                       (char *) (&localSampleCount[0][0] - memOffset),
 | 
			
		||||
                                                       sizeof (unsigned int) * 1,
 | 
			
		||||
                                                       sizeof (unsigned int) * width)
 | 
			
		||||
                                                       );
 | 
			
		||||
                                                       
 | 
			
		||||
            for (int i = 0; i < channelCount; i++)
 | 
			
		||||
            {                              
 | 
			
		||||
                stringstream ss;
 | 
			
		||||
                ss << i;
 | 
			
		||||
                string str = ss.str();
 | 
			
		||||
                
 | 
			
		||||
                int sampleSize  = sizeof (float);
 | 
			
		||||
                
 | 
			
		||||
                int pointerSize = sizeof (char *);
 | 
			
		||||
                
 | 
			
		||||
                frameBuffer.insert (str,
 | 
			
		||||
                                    DeepSlice (IMF::FLOAT,
 | 
			
		||||
                                               (char *) (&data[i][0][0] - memOffset),
 | 
			
		||||
                                               pointerSize * 1,
 | 
			
		||||
                                               pointerSize * width,
 | 
			
		||||
                                               sampleSize) );
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
            part.setFrameBuffer(frameBuffer);
 | 
			
		||||
             
 | 
			
		||||
            for (int ly = 0; ly < part.numYLevels(); ly++)
 | 
			
		||||
            {
 | 
			
		||||
                for (int lx = 0; lx < part.numXLevels(); lx++)
 | 
			
		||||
                {
 | 
			
		||||
                    Box2i dataWindowL = part.dataWindowForLevel(lx, ly);
 | 
			
		||||
                    
 | 
			
		||||
                    
 | 
			
		||||
                    part.readPixelSampleCounts(0, part.numXTiles(lx) - 1, 0, part.numYTiles(ly) - 1, lx, ly);
 | 
			
		||||
                    
 | 
			
		||||
                    for (int i = 0; i <  part.numYTiles(ly); i++)
 | 
			
		||||
                    {
 | 
			
		||||
                        for (int j = 0; j < part.numXTiles(lx); j++)
 | 
			
		||||
                        {
 | 
			
		||||
                            Box2i box = part.dataWindowForTile(j, i, lx, ly);
 | 
			
		||||
                            for (int y = box.min.y; y <= box.max.y; y++)
 | 
			
		||||
                                for (int x = box.min.x; x <= box.max.x; x++)
 | 
			
		||||
                                {
 | 
			
		||||
                                    int dwy = y - dataWindowL.min.y;
 | 
			
		||||
                                    int dwx = x - dataWindowL.min.x;
 | 
			
		||||
                                    
 | 
			
		||||
                                    for (int k = 0; k < channelCount; k++)
 | 
			
		||||
                                    {
 | 
			
		||||
                                        data[k][dwy][dwx] = new float[localSampleCount[dwy][dwx]];
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    
 | 
			
		||||
                    try{
 | 
			
		||||
                        part.readTiles(0, part.numXTiles(lx) - 1, 0, part.numYTiles(ly) - 1, lx, ly);
 | 
			
		||||
                    }catch(...)
 | 
			
		||||
                    {
 | 
			
		||||
                        
 | 
			
		||||
                    }
 | 
			
		||||
                    
 | 
			
		||||
                    for (int i = 0; i < part.levelHeight(ly); i++)
 | 
			
		||||
                    {
 | 
			
		||||
                        for (int j = 0; j < part.levelWidth(lx); j++)
 | 
			
		||||
                        {
 | 
			
		||||
                            for (int k = 0; k < channelCount; k++)
 | 
			
		||||
                            {
 | 
			
		||||
                                delete[] (float*) data[k][i][j];
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }        
 | 
			
		||||
    }catch(std::exception & e)
 | 
			
		||||
    {
 | 
			
		||||
        /* expect to get exceptions*/
 | 
			
		||||
    }
 | 
			
		||||
        
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
fuzzDeepTiles (int numThreads, Rand48 &random)
 | 
			
		||||
{
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
 
 | 
			
		||||
    
 | 
			
		||||
    if (ILMTHREAD_NAMESPACE::supportsThreads())
 | 
			
		||||
    {
 | 
			
		||||
	setGlobalThreadCount (numThreads);
 | 
			
		||||
	cout << "\nnumber of threads: " << globalThreadCount() << endl;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Header::setMaxImageSize (10000, 10000);
 | 
			
		||||
 | 
			
		||||
    const char *goodFile = IMF_TMP_DIR "imf_test_deep_tile_file_fuzz_good.exr";
 | 
			
		||||
    const char *brokenFile = IMF_TMP_DIR "imf_test_deel_tile_file_fuzz_broken.exr";
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
    // read file if it already exists: allows re-testing reading of broken file
 | 
			
		||||
    readFile(brokenFile);
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    for(int parts=1;parts<3;parts++)
 | 
			
		||||
    {
 | 
			
		||||
    
 | 
			
		||||
        for(int comp_method=0;comp_method<2;comp_method++)
 | 
			
		||||
        {
 | 
			
		||||
            generateRandomFile(goodFile,8,parts , comp_method==0 ? NO_COMPRESSION : ZIPS_COMPRESSION);
 | 
			
		||||
            fuzzFile (goodFile, brokenFile, readFile, 5000, 3000, random);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    remove (goodFile);
 | 
			
		||||
    remove (brokenFile);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
} // namespace
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
testFuzzDeepTiles ()
 | 
			
		||||
{
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    try
 | 
			
		||||
    {
 | 
			
		||||
	cout << "Testing deep tile-based files "
 | 
			
		||||
		"with randomly inserted errors" << endl;
 | 
			
		||||
 | 
			
		||||
	Rand48 random (1);
 | 
			
		||||
 | 
			
		||||
	fuzzDeepTiles (0, random);
 | 
			
		||||
 | 
			
		||||
	if (ILMTHREAD_NAMESPACE::supportsThreads())
 | 
			
		||||
	    fuzzDeepTiles (2, random);
 | 
			
		||||
 | 
			
		||||
	cout << "ok\n" << endl;
 | 
			
		||||
    }
 | 
			
		||||
    catch (const std::exception &e)
 | 
			
		||||
    {
 | 
			
		||||
	cerr << "ERROR -- caught exception: " << e.what() << endl;
 | 
			
		||||
	assert (false);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,39 @@
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2013, Industrial Light & Magic, a division of Lucas
 | 
			
		||||
// Digital Ltd. LLC and Weta Digital Ltd
 | 
			
		||||
// 
 | 
			
		||||
// All rights reserved.
 | 
			
		||||
// 
 | 
			
		||||
// Redistribution and use in source and binary forms, with or without
 | 
			
		||||
// modification, are permitted provided that the following conditions are
 | 
			
		||||
// met:
 | 
			
		||||
// *       Redistributions of source code must retain the above copyright
 | 
			
		||||
// notice, this list of conditions and the following disclaimer.
 | 
			
		||||
// *       Redistributions in binary form must reproduce the above
 | 
			
		||||
// copyright notice, this list of conditions and the following disclaimer
 | 
			
		||||
// in the documentation and/or other materials provided with the
 | 
			
		||||
// distribution.
 | 
			
		||||
// *       Neither the name of Industrial Light & Magic nor the names of
 | 
			
		||||
// its contributors may be used to endorse or promote products derived
 | 
			
		||||
// from this software without specific prior written permission. 
 | 
			
		||||
// 
 | 
			
		||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 | 
			
		||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 | 
			
		||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 | 
			
		||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 | 
			
		||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 | 
			
		||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
			
		||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 | 
			
		||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
//
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void testFuzzDeepTiles ();
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,273 @@
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2007, Industrial Light & Magic, a division of Lucas
 | 
			
		||||
// Digital Ltd. LLC
 | 
			
		||||
// 
 | 
			
		||||
// All rights reserved.
 | 
			
		||||
// 
 | 
			
		||||
// Redistribution and use in source and binary forms, with or without
 | 
			
		||||
// modification, are permitted provided that the following conditions are
 | 
			
		||||
// met:
 | 
			
		||||
// *       Redistributions of source code must retain the above copyright
 | 
			
		||||
// notice, this list of conditions and the following disclaimer.
 | 
			
		||||
// *       Redistributions in binary form must reproduce the above
 | 
			
		||||
// copyright notice, this list of conditions and the following disclaimer
 | 
			
		||||
// in the documentation and/or other materials provided with the
 | 
			
		||||
// distribution.
 | 
			
		||||
// *       Neither the name of Industrial Light & Magic nor the names of
 | 
			
		||||
// its contributors may be used to endorse or promote products derived
 | 
			
		||||
// from this software without specific prior written permission. 
 | 
			
		||||
// 
 | 
			
		||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 | 
			
		||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 | 
			
		||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 | 
			
		||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 | 
			
		||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 | 
			
		||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
			
		||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 | 
			
		||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
//
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include <ImfMultiPartOutputFile.h>
 | 
			
		||||
#include <ImfMultiPartInputFile.h>
 | 
			
		||||
#include <ImfPartType.h>
 | 
			
		||||
#include <ImfOutputPart.h>
 | 
			
		||||
#include <ImfInputPart.h>
 | 
			
		||||
 | 
			
		||||
#include <ImfRgbaFile.h>
 | 
			
		||||
 | 
			
		||||
#include <ImfArray.h>
 | 
			
		||||
#include <ImfThreading.h>
 | 
			
		||||
#include <IlmThread.h>
 | 
			
		||||
#include <Iex.h>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <cassert>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
#include "tmpDir.h"
 | 
			
		||||
#include "fuzzFile.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Handle the case when the custom namespace is not exposed
 | 
			
		||||
#include <OpenEXRConfig.h>
 | 
			
		||||
#include <ImfChannelList.h>
 | 
			
		||||
using namespace OPENEXR_IMF_INTERNAL_NAMESPACE;
 | 
			
		||||
using namespace std;
 | 
			
		||||
using namespace IMATH_NAMESPACE;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
namespace {
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
fillPixels (Array2D<Rgba> &pixels, int w, int h)
 | 
			
		||||
{
 | 
			
		||||
    for (int y = 0; y < h; ++y)
 | 
			
		||||
    {
 | 
			
		||||
	for (int x = 0; x < w; ++x)
 | 
			
		||||
	{
 | 
			
		||||
	    Rgba &p = pixels[y][x];
 | 
			
		||||
 | 
			
		||||
	    p.r = 0.5 + 0.5 * sin (0.1 * x + 0.1 * y);
 | 
			
		||||
	    p.g = 0.5 + 0.5 * sin (0.1 * x + 0.2 * y);
 | 
			
		||||
	    p.b = 0.5 + 0.5 * sin (0.1 * x + 0.3 * y);
 | 
			
		||||
	    p.a = (p.r + p.b + p.g) / 3.0;
 | 
			
		||||
	}
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
writeImage (const char fileName[],
 | 
			
		||||
	    int width,
 | 
			
		||||
	    int height,
 | 
			
		||||
	    const Array2D<Rgba> &pixels,
 | 
			
		||||
            int parts,
 | 
			
		||||
	    Compression comp)
 | 
			
		||||
{
 | 
			
		||||
    //
 | 
			
		||||
    // Save the image with the specified compression.
 | 
			
		||||
    //
 | 
			
		||||
 | 
			
		||||
    cout << parts << " parts with compression: " << comp << endl;
 | 
			
		||||
 | 
			
		||||
    Header header (width, height);
 | 
			
		||||
    header.compression() = comp;
 | 
			
		||||
 | 
			
		||||
    if(parts==1)
 | 
			
		||||
    {
 | 
			
		||||
        RgbaOutputFile out (fileName, header, WRITE_RGBA);
 | 
			
		||||
        out.setFrameBuffer (&pixels[0][0], 1, width);
 | 
			
		||||
        out.writePixels (height);
 | 
			
		||||
    }else{
 | 
			
		||||
        
 | 
			
		||||
        header.setType(SCANLINEIMAGE);
 | 
			
		||||
        
 | 
			
		||||
        header.channels().insert("R",Channel(HALF));
 | 
			
		||||
        header.channels().insert("G",Channel(HALF));
 | 
			
		||||
        header.channels().insert("B",Channel(HALF));
 | 
			
		||||
        header.channels().insert("A",Channel(HALF));
 | 
			
		||||
        
 | 
			
		||||
        vector<Header> headers(parts);
 | 
			
		||||
        for(int i=0;i<parts;i++)
 | 
			
		||||
        {
 | 
			
		||||
            
 | 
			
		||||
            headers[i]=header;
 | 
			
		||||
            ostringstream s;
 | 
			
		||||
            s << i;
 | 
			
		||||
            headers[i].setName(s.str());
 | 
			
		||||
        }
 | 
			
		||||
        MultiPartOutputFile out(fileName,&headers[0],parts);
 | 
			
		||||
        FrameBuffer f;
 | 
			
		||||
        f.insert("R",Slice(HALF,(char *) &(pixels[0][0].r),sizeof(Rgba),width*sizeof(Rgba)));
 | 
			
		||||
        f.insert("G",Slice(HALF,(char *) &(pixels[0][0].g),sizeof(Rgba),width*sizeof(Rgba)));
 | 
			
		||||
        f.insert("B",Slice(HALF,(char *) &(pixels[0][0].b),sizeof(Rgba),width*sizeof(Rgba)));
 | 
			
		||||
        f.insert("A",Slice(HALF,(char *) &(pixels[0][0].a),sizeof(Rgba),width*sizeof(Rgba)));
 | 
			
		||||
        
 | 
			
		||||
        for(int i=0;i<parts;i++)
 | 
			
		||||
        {
 | 
			
		||||
            OutputPart(out,i).setFrameBuffer(f);
 | 
			
		||||
            OutputPart(out,i).writePixels(height);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
readImage (const char fileName[])
 | 
			
		||||
{
 | 
			
		||||
    //
 | 
			
		||||
    // Try to read the specified file.
 | 
			
		||||
    // Reading should either succeed or throw an exception,
 | 
			
		||||
    // but it should not crash for any reason.
 | 
			
		||||
    //
 | 
			
		||||
 | 
			
		||||
    try
 | 
			
		||||
    {
 | 
			
		||||
        // first , test Rgba interface
 | 
			
		||||
        RgbaInputFile in (fileName);
 | 
			
		||||
        const Box2i &dw = in.dataWindow();
 | 
			
		||||
        
 | 
			
		||||
        int w = dw.max.x - dw.min.x + 1;
 | 
			
		||||
        int dx = dw.min.x;
 | 
			
		||||
        
 | 
			
		||||
        if (w > (1 << 24))
 | 
			
		||||
            return;
 | 
			
		||||
        
 | 
			
		||||
        Array<Rgba> pixels (w);
 | 
			
		||||
        in.setFrameBuffer (&pixels[-dx], 1, 0);
 | 
			
		||||
        
 | 
			
		||||
        for (int y = dw.min.y; y <= dw.max.y; ++y)
 | 
			
		||||
            in.readPixels (y);
 | 
			
		||||
    }catch(...)
 | 
			
		||||
    {
 | 
			
		||||
        // expect exceptions
 | 
			
		||||
    }
 | 
			
		||||
    try{
 | 
			
		||||
        // now test Multipart interface (even for single part files)
 | 
			
		||||
        
 | 
			
		||||
        MultiPartInputFile file(fileName);
 | 
			
		||||
        
 | 
			
		||||
        for(int p=0;p<file.parts();p++)
 | 
			
		||||
        {
 | 
			
		||||
            InputPart in(file,p);
 | 
			
		||||
            const Box2i &dw = in.header().dataWindow();
 | 
			
		||||
            
 | 
			
		||||
            int w = dw.max.x - dw.min.x + 1;
 | 
			
		||||
            int dx = dw.min.x;
 | 
			
		||||
            
 | 
			
		||||
            if (w > (1 << 24))
 | 
			
		||||
                return;
 | 
			
		||||
            
 | 
			
		||||
            Array<Rgba> pixels (w);
 | 
			
		||||
            FrameBuffer i;
 | 
			
		||||
            i.insert("R",Slice(HALF,(char *)&(pixels[-dx].r),sizeof(Rgba),0));
 | 
			
		||||
            i.insert("G",Slice(HALF,(char *)&(pixels[-dx].g),sizeof(Rgba),0));
 | 
			
		||||
            i.insert("B",Slice(HALF,(char *)&(pixels[-dx].b),sizeof(Rgba),0));
 | 
			
		||||
            i.insert("A",Slice(HALF,(char *)&(pixels[-dx].a),sizeof(Rgba),0));
 | 
			
		||||
            
 | 
			
		||||
            in.setFrameBuffer (i);
 | 
			
		||||
            for (int y = dw.min.y; y <= dw.max.y; ++y)
 | 
			
		||||
                in.readPixels (y);
 | 
			
		||||
            
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    catch (...)
 | 
			
		||||
    {
 | 
			
		||||
        // empty
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
fuzzScanLines (int numThreads, Rand48 &random)
 | 
			
		||||
{
 | 
			
		||||
    if (ILMTHREAD_NAMESPACE::supportsThreads())
 | 
			
		||||
    {
 | 
			
		||||
	setGlobalThreadCount (numThreads);
 | 
			
		||||
	cout << "\nnumber of threads: " << globalThreadCount() << endl;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Header::setMaxImageSize (10000, 10000);
 | 
			
		||||
 | 
			
		||||
    const int W = 217;
 | 
			
		||||
    const int H = 197;
 | 
			
		||||
 | 
			
		||||
    Array2D<Rgba> pixels (H, W);
 | 
			
		||||
    fillPixels (pixels, W, H);
 | 
			
		||||
 | 
			
		||||
    const char *goodFile = IMF_TMP_DIR "imf_test_scanline_file_fuzz_good.exr";
 | 
			
		||||
    const char *brokenFile = IMF_TMP_DIR "imf_test_scanline_file_fuzz_broken.exr";
 | 
			
		||||
 | 
			
		||||
    // re-attempt to read broken file if it still remains on disk from previous aborted run
 | 
			
		||||
    readImage(brokenFile);
 | 
			
		||||
    
 | 
			
		||||
    for (int parts = 1 ; parts<4 ; ++parts)
 | 
			
		||||
    {
 | 
			
		||||
        for (int comp = 0; comp < NUM_COMPRESSION_METHODS; ++comp)
 | 
			
		||||
        {
 | 
			
		||||
            writeImage (goodFile, W, H, pixels, parts,Compression (comp));
 | 
			
		||||
            fuzzFile (goodFile, brokenFile, readImage, 5000, 3000, random);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    remove (goodFile);
 | 
			
		||||
    remove (brokenFile);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
} // namespace
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
testFuzzScanLines ()
 | 
			
		||||
{
 | 
			
		||||
    try
 | 
			
		||||
    {
 | 
			
		||||
	cout << "Testing scanline-based files "
 | 
			
		||||
		"with randomly inserted errors" << endl;
 | 
			
		||||
 | 
			
		||||
	Rand48 random (1);
 | 
			
		||||
 | 
			
		||||
	fuzzScanLines (0, random);
 | 
			
		||||
 | 
			
		||||
	if (ILMTHREAD_NAMESPACE::supportsThreads())
 | 
			
		||||
	    fuzzScanLines (2, random);
 | 
			
		||||
 | 
			
		||||
	cout << "ok\n" << endl;
 | 
			
		||||
    }
 | 
			
		||||
    catch (const std::exception &e)
 | 
			
		||||
    {
 | 
			
		||||
	cerr << "ERROR -- caught exception: " << e.what() << endl;
 | 
			
		||||
	assert (false);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,39 @@
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2007, Industrial Light & Magic, a division of Lucas
 | 
			
		||||
// Digital Ltd. LLC
 | 
			
		||||
// 
 | 
			
		||||
// All rights reserved.
 | 
			
		||||
// 
 | 
			
		||||
// Redistribution and use in source and binary forms, with or without
 | 
			
		||||
// modification, are permitted provided that the following conditions are
 | 
			
		||||
// met:
 | 
			
		||||
// *       Redistributions of source code must retain the above copyright
 | 
			
		||||
// notice, this list of conditions and the following disclaimer.
 | 
			
		||||
// *       Redistributions in binary form must reproduce the above
 | 
			
		||||
// copyright notice, this list of conditions and the following disclaimer
 | 
			
		||||
// in the documentation and/or other materials provided with the
 | 
			
		||||
// distribution.
 | 
			
		||||
// *       Neither the name of Industrial Light & Magic nor the names of
 | 
			
		||||
// its contributors may be used to endorse or promote products derived
 | 
			
		||||
// from this software without specific prior written permission. 
 | 
			
		||||
// 
 | 
			
		||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 | 
			
		||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 | 
			
		||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 | 
			
		||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 | 
			
		||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 | 
			
		||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
			
		||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 | 
			
		||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
//
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void testFuzzScanLines ();
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										423
									
								
								cs440-acg/ext/openexr/OpenEXR/IlmImfFuzzTest/testFuzzTiles.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										423
									
								
								cs440-acg/ext/openexr/OpenEXR/IlmImfFuzzTest/testFuzzTiles.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,423 @@
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2007, Industrial Light & Magic, a division of Lucas
 | 
			
		||||
// Digital Ltd. LLC
 | 
			
		||||
// 
 | 
			
		||||
// All rights reserved.
 | 
			
		||||
// 
 | 
			
		||||
// Redistribution and use in source and binary forms, with or without
 | 
			
		||||
// modification, are permitted provided that the following conditions are
 | 
			
		||||
// met:
 | 
			
		||||
// *       Redistributions of source code must retain the above copyright
 | 
			
		||||
// notice, this list of conditions and the following disclaimer.
 | 
			
		||||
// *       Redistributions in binary form must reproduce the above
 | 
			
		||||
// copyright notice, this list of conditions and the following disclaimer
 | 
			
		||||
// in the documentation and/or other materials provided with the
 | 
			
		||||
// distribution.
 | 
			
		||||
// *       Neither the name of Industrial Light & Magic nor the names of
 | 
			
		||||
// its contributors may be used to endorse or promote products derived
 | 
			
		||||
// from this software without specific prior written permission. 
 | 
			
		||||
// 
 | 
			
		||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 | 
			
		||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 | 
			
		||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 | 
			
		||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 | 
			
		||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 | 
			
		||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
			
		||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 | 
			
		||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
//
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include <tmpDir.h>
 | 
			
		||||
#include <fuzzFile.h>
 | 
			
		||||
 | 
			
		||||
#include <ImfTiledRgbaFile.h>
 | 
			
		||||
#include <ImfArray.h>
 | 
			
		||||
#include <ImfThreading.h>
 | 
			
		||||
#include <IlmThread.h>
 | 
			
		||||
#include <Iex.h>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <cassert>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
// Handle the case when the custom namespace is not exposed
 | 
			
		||||
#include <OpenEXRConfig.h>
 | 
			
		||||
#include <ImfPartType.h>
 | 
			
		||||
#include <ImfMultiPartOutputFile.h>
 | 
			
		||||
#include <ImfTiledOutputPart.h>
 | 
			
		||||
#include <ImfMultiPartInputFile.h>
 | 
			
		||||
#include <ImfTiledInputPart.h>
 | 
			
		||||
#include <ImfChannelList.h>
 | 
			
		||||
using namespace OPENEXR_IMF_INTERNAL_NAMESPACE;
 | 
			
		||||
using namespace std;
 | 
			
		||||
using namespace IMATH_NAMESPACE;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
namespace {
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
fillPixels (Array2D<Rgba> &pixels, int w, int h)
 | 
			
		||||
{
 | 
			
		||||
    for (int y = 0; y < h; ++y)
 | 
			
		||||
    {
 | 
			
		||||
	for (int x = 0; x < w; ++x)
 | 
			
		||||
	{
 | 
			
		||||
	    Rgba &p = pixels[y][x];
 | 
			
		||||
 | 
			
		||||
	    p.r = 0.5 + 0.5 * sin (0.1 * x + 0.1 * y);
 | 
			
		||||
	    p.g = 0.5 + 0.5 * sin (0.1 * x + 0.2 * y);
 | 
			
		||||
	    p.b = 0.5 + 0.5 * sin (0.1 * x + 0.3 * y);
 | 
			
		||||
	    p.a = (p.r + p.b + p.g) / 3.0;
 | 
			
		||||
	}
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
writeImageONE (const char fileName[],
 | 
			
		||||
	       int width, int height,
 | 
			
		||||
	       int xSize, int ySize,
 | 
			
		||||
               int parts,
 | 
			
		||||
	       Compression comp)
 | 
			
		||||
{
 | 
			
		||||
    cout << "levelMode 0" << ", compression " << comp << " parts " << parts << endl;
 | 
			
		||||
 | 
			
		||||
    Header header (width, height);
 | 
			
		||||
    header.lineOrder() = INCREASING_Y;
 | 
			
		||||
    header.compression() = comp;
 | 
			
		||||
    
 | 
			
		||||
    Array2D<Rgba> pixels (height, width);
 | 
			
		||||
    fillPixels (pixels, width, height);
 | 
			
		||||
 | 
			
		||||
    if(parts==1)
 | 
			
		||||
    {
 | 
			
		||||
        TiledRgbaOutputFile out (fileName, header, WRITE_RGBA,
 | 
			
		||||
                                 xSize, ySize, ONE_LEVEL);
 | 
			
		||||
                                 
 | 
			
		||||
        out.setFrameBuffer (&pixels[0][0], 1, width);
 | 
			
		||||
        out.writeTiles (0, out.numXTiles() - 1, 0, out.numYTiles() - 1);
 | 
			
		||||
    }else{
 | 
			
		||||
        
 | 
			
		||||
        header.setTileDescription(TileDescription(xSize,ySize,ONE_LEVEL));
 | 
			
		||||
        
 | 
			
		||||
        header.setType(TILEDIMAGE);
 | 
			
		||||
        
 | 
			
		||||
        header.channels().insert("R",Channel(HALF));
 | 
			
		||||
        header.channels().insert("G",Channel(HALF));
 | 
			
		||||
        header.channels().insert("B",Channel(HALF));
 | 
			
		||||
        header.channels().insert("A",Channel(HALF));
 | 
			
		||||
        
 | 
			
		||||
        
 | 
			
		||||
        FrameBuffer f;
 | 
			
		||||
        f.insert("R",Slice(HALF,(char *) &(pixels[0][0].r),sizeof(Rgba),width*sizeof(Rgba)));
 | 
			
		||||
        f.insert("G",Slice(HALF,(char *) &(pixels[0][0].g),sizeof(Rgba),width*sizeof(Rgba)));
 | 
			
		||||
        f.insert("B",Slice(HALF,(char *) &(pixels[0][0].b),sizeof(Rgba),width*sizeof(Rgba)));
 | 
			
		||||
        f.insert("A",Slice(HALF,(char *) &(pixels[0][0].a),sizeof(Rgba),width*sizeof(Rgba)));
 | 
			
		||||
        
 | 
			
		||||
        
 | 
			
		||||
        vector<Header> headers(parts);
 | 
			
		||||
        for(int p=0;p<parts;p++)
 | 
			
		||||
        {
 | 
			
		||||
            headers[p]=header;
 | 
			
		||||
            ostringstream o;
 | 
			
		||||
            o << p;
 | 
			
		||||
            headers[p].setName(o.str());
 | 
			
		||||
        }
 | 
			
		||||
        MultiPartOutputFile file(fileName,&headers[0],headers.size());
 | 
			
		||||
        for(int p=0;p<parts;p++)
 | 
			
		||||
        {
 | 
			
		||||
            TiledOutputPart out(file,p);
 | 
			
		||||
            
 | 
			
		||||
            out.setFrameBuffer(f);
 | 
			
		||||
            out.writeTiles (0, out.numXTiles() - 1, 0, out.numYTiles() - 1);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
readImageONE (const char fileName[])
 | 
			
		||||
{
 | 
			
		||||
    //
 | 
			
		||||
    // Try to read the specified one-level file, which may be damaged.
 | 
			
		||||
    // Reading should either succeed or throw an exception, but it
 | 
			
		||||
    // should not cause a crash.
 | 
			
		||||
    //
 | 
			
		||||
    // attempt TiledRgbaInputFile interface
 | 
			
		||||
    try
 | 
			
		||||
    {
 | 
			
		||||
        TiledRgbaInputFile in (fileName);
 | 
			
		||||
        const Box2i &dw = in.dataWindow();
 | 
			
		||||
        
 | 
			
		||||
        int w = dw.max.x - dw.min.x + 1;
 | 
			
		||||
        int h = dw.max.y - dw.min.y + 1;
 | 
			
		||||
        int dwx = dw.min.x;
 | 
			
		||||
        int dwy = dw.min.y;
 | 
			
		||||
        
 | 
			
		||||
        Array2D<Rgba> pixels (h, w);
 | 
			
		||||
        in.setFrameBuffer (&pixels[-dwy][-dwx], 1, w);
 | 
			
		||||
        in.readTiles (0, in.numXTiles() - 1, 0, in.numYTiles() - 1);
 | 
			
		||||
    }
 | 
			
		||||
    catch (...)
 | 
			
		||||
    {
 | 
			
		||||
        // empty
 | 
			
		||||
    }
 | 
			
		||||
    try
 | 
			
		||||
    {
 | 
			
		||||
        
 | 
			
		||||
        // attempt MultiPart interface
 | 
			
		||||
        MultiPartInputFile in(fileName);
 | 
			
		||||
        for(int p=0;p<in.parts();p++)
 | 
			
		||||
        {
 | 
			
		||||
            TiledInputPart inpart(in,p);
 | 
			
		||||
            const Box2i &dw = inpart.header().dataWindow();
 | 
			
		||||
            
 | 
			
		||||
            int w = dw.max.x - dw.min.x + 1;
 | 
			
		||||
            int h = dw.max.y - dw.min.y + 1;
 | 
			
		||||
            int dwx = dw.min.x;
 | 
			
		||||
            int dwy = dw.min.y;
 | 
			
		||||
            
 | 
			
		||||
            Array2D<Rgba> pixels (h, w);
 | 
			
		||||
            FrameBuffer i;
 | 
			
		||||
            i.insert("R",Slice(HALF,(char *)&(pixels[-dwy][-dwx].r),sizeof(Rgba),w*sizeof(Rgba)));
 | 
			
		||||
            i.insert("G",Slice(HALF,(char *)&(pixels[-dwy][-dwx].g),sizeof(Rgba),w*sizeof(Rgba)));
 | 
			
		||||
            i.insert("B",Slice(HALF,(char *)&(pixels[-dwy][-dwx].b),sizeof(Rgba),w*sizeof(Rgba)));
 | 
			
		||||
            i.insert("A",Slice(HALF,(char *)&(pixels[-dwy][-dwx].a),sizeof(Rgba),w*sizeof(Rgba)));
 | 
			
		||||
            
 | 
			
		||||
            inpart.setFrameBuffer (i);
 | 
			
		||||
            inpart.readTiles (0, inpart.numXTiles() - 1, 0, inpart.numYTiles() - 1);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    catch (...)
 | 
			
		||||
    {
 | 
			
		||||
                // empty
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
writeImageMIP (const char fileName[],
 | 
			
		||||
	       int width, int height,
 | 
			
		||||
	       int xSize, int ySize,
 | 
			
		||||
               int parts, ///\todo support multipart MIP files
 | 
			
		||||
	       Compression comp)
 | 
			
		||||
{
 | 
			
		||||
    cout << "levelMode 1" << ", compression " << comp << endl;
 | 
			
		||||
 | 
			
		||||
    Header header (width, height);
 | 
			
		||||
    header.lineOrder() = INCREASING_Y;
 | 
			
		||||
    header.compression() = comp;
 | 
			
		||||
    
 | 
			
		||||
    Array < Array2D<Rgba> > levels;
 | 
			
		||||
 | 
			
		||||
    TiledRgbaOutputFile out (fileName, header, WRITE_RGBA,
 | 
			
		||||
			     xSize, ySize, MIPMAP_LEVELS, ROUND_DOWN);
 | 
			
		||||
    
 | 
			
		||||
    int numLevels = out.numLevels();
 | 
			
		||||
    levels.resizeErase (numLevels);
 | 
			
		||||
 | 
			
		||||
    for (int level = 0; level < out.numLevels(); ++level)
 | 
			
		||||
    {
 | 
			
		||||
	int levelWidth  = out.levelWidth(level);
 | 
			
		||||
	int levelHeight = out.levelHeight(level);
 | 
			
		||||
	levels[level].resizeErase(levelHeight, levelWidth);
 | 
			
		||||
	fillPixels (levels[level], levelWidth, levelHeight);
 | 
			
		||||
    
 | 
			
		||||
	out.setFrameBuffer (&(levels[level])[0][0], 1, levelWidth);
 | 
			
		||||
	out.writeTiles (0, out.numXTiles(level) - 1,
 | 
			
		||||
			0, out.numYTiles(level) - 1, level);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
readImageMIP (const char fileName[])
 | 
			
		||||
{
 | 
			
		||||
    //
 | 
			
		||||
    // Try to read the specified mipmap file, which may be damaged.
 | 
			
		||||
    // Reading should either succeed or throw an exception, but it
 | 
			
		||||
    // should not cause a crash.
 | 
			
		||||
    //
 | 
			
		||||
 | 
			
		||||
    try
 | 
			
		||||
    {
 | 
			
		||||
        TiledRgbaInputFile in (fileName);
 | 
			
		||||
        const Box2i &dw = in.dataWindow();
 | 
			
		||||
        int dwx = dw.min.x;
 | 
			
		||||
        int dwy = dw.min.y;
 | 
			
		||||
 | 
			
		||||
        int numLevels = in.numLevels();
 | 
			
		||||
        Array < Array2D<Rgba> > levels2 (numLevels);
 | 
			
		||||
        
 | 
			
		||||
        for (int level = 0; level < numLevels; ++level)
 | 
			
		||||
        {
 | 
			
		||||
            int levelWidth = in.levelWidth(level);
 | 
			
		||||
            int levelHeight = in.levelHeight(level);
 | 
			
		||||
            levels2[level].resizeErase(levelHeight, levelWidth);
 | 
			
		||||
        
 | 
			
		||||
            in.setFrameBuffer (&(levels2[level])[-dwy][-dwx], 1, levelWidth);
 | 
			
		||||
            in.readTiles (0, in.numXTiles(level) - 1,
 | 
			
		||||
                          0, in.numYTiles(level) - 1, level);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    catch (...)
 | 
			
		||||
    {
 | 
			
		||||
	// empty
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
writeImageRIP (const char fileName[],
 | 
			
		||||
	       int width, int height,
 | 
			
		||||
	       int xSize, int ySize,
 | 
			
		||||
               int parts, ///\todo support multipart RIP files
 | 
			
		||||
	       Compression comp)
 | 
			
		||||
{
 | 
			
		||||
    cout << "levelMode 2" << ", compression " << comp << endl;
 | 
			
		||||
 | 
			
		||||
    Header header (width, height);
 | 
			
		||||
    header.lineOrder() = INCREASING_Y;
 | 
			
		||||
    header.compression() = comp;
 | 
			
		||||
    
 | 
			
		||||
    Array2D < Array2D<Rgba> > levels;
 | 
			
		||||
 | 
			
		||||
    TiledRgbaOutputFile out (fileName, header, WRITE_RGBA,
 | 
			
		||||
			     xSize, ySize, RIPMAP_LEVELS, ROUND_UP);
 | 
			
		||||
 | 
			
		||||
    levels.resizeErase (out.numYLevels(), out.numXLevels());
 | 
			
		||||
 | 
			
		||||
    for (int ylevel = 0; ylevel < out.numYLevels(); ++ylevel)
 | 
			
		||||
    {            
 | 
			
		||||
	for (int xlevel = 0; xlevel < out.numXLevels(); ++xlevel)
 | 
			
		||||
	{
 | 
			
		||||
	    int levelWidth = out.levelWidth(xlevel);
 | 
			
		||||
	    int levelHeight = out.levelHeight(ylevel);
 | 
			
		||||
	    levels[ylevel][xlevel].resizeErase(levelHeight, levelWidth);
 | 
			
		||||
	    fillPixels (levels[ylevel][xlevel], levelWidth, levelHeight);
 | 
			
		||||
 | 
			
		||||
	    out.setFrameBuffer (&(levels[ylevel][xlevel])[0][0], 1,
 | 
			
		||||
				levelWidth); 
 | 
			
		||||
	    out.writeTiles (0, out.numXTiles(xlevel) - 1,
 | 
			
		||||
			    0, out.numYTiles(ylevel) - 1, xlevel, ylevel);
 | 
			
		||||
	}
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
readImageRIP (const char fileName[])
 | 
			
		||||
{
 | 
			
		||||
    //
 | 
			
		||||
    // Try to read the specified ripmap file, which may be damaged.
 | 
			
		||||
    // Reading should either succeed or throw an exception, but it
 | 
			
		||||
    // should not cause a crash.
 | 
			
		||||
    //
 | 
			
		||||
 | 
			
		||||
    try
 | 
			
		||||
    {
 | 
			
		||||
        TiledRgbaInputFile in (fileName);
 | 
			
		||||
        const Box2i &dw = in.dataWindow();
 | 
			
		||||
        int dwx = dw.min.x;
 | 
			
		||||
        int dwy = dw.min.y;        
 | 
			
		||||
        
 | 
			
		||||
        int numXLevels = in.numXLevels();
 | 
			
		||||
        int numYLevels = in.numYLevels();
 | 
			
		||||
	Array2D < Array2D<Rgba> > levels2 (numYLevels, numXLevels);
 | 
			
		||||
        
 | 
			
		||||
        for (int ylevel = 0; ylevel < numYLevels; ++ylevel)
 | 
			
		||||
        {
 | 
			
		||||
            for (int xlevel = 0; xlevel < numXLevels; ++xlevel)
 | 
			
		||||
            {
 | 
			
		||||
                int levelWidth  = in.levelWidth(xlevel);
 | 
			
		||||
                int levelHeight = in.levelHeight(ylevel);
 | 
			
		||||
                levels2[ylevel][xlevel].resizeErase(levelHeight, levelWidth);
 | 
			
		||||
                in.setFrameBuffer (&(levels2[ylevel][xlevel])[-dwy][-dwx], 1,
 | 
			
		||||
                                   levelWidth);
 | 
			
		||||
                                   
 | 
			
		||||
                in.readTiles (0, in.numXTiles(xlevel) - 1,
 | 
			
		||||
                              0, in.numYTiles(ylevel) - 1, xlevel, ylevel);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    catch (...)
 | 
			
		||||
    {
 | 
			
		||||
	// empty
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
fuzzTiles (int numThreads, Rand48 &random)
 | 
			
		||||
{
 | 
			
		||||
    if (ILMTHREAD_NAMESPACE::supportsThreads())
 | 
			
		||||
    {
 | 
			
		||||
	setGlobalThreadCount (numThreads);
 | 
			
		||||
	cout << "\nnumber of threads: " << globalThreadCount() << endl;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Header::setMaxImageSize (10000, 10000);
 | 
			
		||||
    Header::setMaxTileSize (10000, 10000);
 | 
			
		||||
 | 
			
		||||
    const int W = 217;
 | 
			
		||||
    const int H = 197;
 | 
			
		||||
    const int TW = 64;
 | 
			
		||||
    const int TH = 64;
 | 
			
		||||
 | 
			
		||||
    const char *goodFile = IMF_TMP_DIR "imf_test_tile_file_fuzz_good.exr";
 | 
			
		||||
    const char *brokenFile = IMF_TMP_DIR "imf_test_tile_file_fuzz_broken.exr";
 | 
			
		||||
 | 
			
		||||
    for (int parts = 1 ; parts < 3 ; parts++)
 | 
			
		||||
    {
 | 
			
		||||
        for (int comp = 0; comp < NUM_COMPRESSION_METHODS; ++comp)
 | 
			
		||||
        {
 | 
			
		||||
            writeImageONE (goodFile, W, H, TW, TH, parts , Compression (comp));
 | 
			
		||||
            fuzzFile (goodFile, brokenFile, readImageONE, 5000, 3000, random);
 | 
			
		||||
            
 | 
			
		||||
            if(parts==1)
 | 
			
		||||
            {
 | 
			
		||||
                writeImageMIP (goodFile, W, H, TW, TH, parts , Compression (comp));
 | 
			
		||||
                fuzzFile (goodFile, brokenFile, readImageMIP, 5000, 3000, random);
 | 
			
		||||
                
 | 
			
		||||
                writeImageRIP (goodFile, W, H, TW, TH, parts , Compression (comp));
 | 
			
		||||
                fuzzFile (goodFile, brokenFile, readImageRIP, 5000, 3000, random);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    remove (goodFile);
 | 
			
		||||
    remove (brokenFile);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
} // namespace
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
testFuzzTiles ()
 | 
			
		||||
{
 | 
			
		||||
    try
 | 
			
		||||
    {
 | 
			
		||||
	cout << "Testing tile-based files "
 | 
			
		||||
		"with randomly inserted errors" << endl;
 | 
			
		||||
 | 
			
		||||
	Rand48 random (5);
 | 
			
		||||
 | 
			
		||||
	fuzzTiles (0, random);
 | 
			
		||||
 | 
			
		||||
	if (ILMTHREAD_NAMESPACE::supportsThreads())
 | 
			
		||||
	    fuzzTiles (2, random);
 | 
			
		||||
 | 
			
		||||
	cout << "ok\n" << endl;
 | 
			
		||||
    }
 | 
			
		||||
    catch (const std::exception &e)
 | 
			
		||||
    {
 | 
			
		||||
	cerr << "ERROR -- caught exception: " << e.what() << endl;
 | 
			
		||||
	assert (false);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										39
									
								
								cs440-acg/ext/openexr/OpenEXR/IlmImfFuzzTest/testFuzzTiles.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								cs440-acg/ext/openexr/OpenEXR/IlmImfFuzzTest/testFuzzTiles.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2007, Industrial Light & Magic, a division of Lucas
 | 
			
		||||
// Digital Ltd. LLC
 | 
			
		||||
// 
 | 
			
		||||
// All rights reserved.
 | 
			
		||||
// 
 | 
			
		||||
// Redistribution and use in source and binary forms, with or without
 | 
			
		||||
// modification, are permitted provided that the following conditions are
 | 
			
		||||
// met:
 | 
			
		||||
// *       Redistributions of source code must retain the above copyright
 | 
			
		||||
// notice, this list of conditions and the following disclaimer.
 | 
			
		||||
// *       Redistributions in binary form must reproduce the above
 | 
			
		||||
// copyright notice, this list of conditions and the following disclaimer
 | 
			
		||||
// in the documentation and/or other materials provided with the
 | 
			
		||||
// distribution.
 | 
			
		||||
// *       Neither the name of Industrial Light & Magic nor the names of
 | 
			
		||||
// its contributors may be used to endorse or promote products derived
 | 
			
		||||
// from this software without specific prior written permission. 
 | 
			
		||||
// 
 | 
			
		||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 | 
			
		||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 | 
			
		||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 | 
			
		||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 | 
			
		||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 | 
			
		||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
			
		||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 | 
			
		||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
//
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void testFuzzTiles ();
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										40
									
								
								cs440-acg/ext/openexr/OpenEXR/IlmImfFuzzTest/tmpDir.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								cs440-acg/ext/openexr/OpenEXR/IlmImfFuzzTest/tmpDir.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2007, Industrial Light & Magic, a division of Lucas
 | 
			
		||||
// Digital Ltd. LLC
 | 
			
		||||
// 
 | 
			
		||||
// All rights reserved.
 | 
			
		||||
// 
 | 
			
		||||
// Redistribution and use in source and binary forms, with or without
 | 
			
		||||
// modification, are permitted provided that the following conditions are
 | 
			
		||||
// met:
 | 
			
		||||
// *       Redistributions of source code must retain the above copyright
 | 
			
		||||
// notice, this list of conditions and the following disclaimer.
 | 
			
		||||
// *       Redistributions in binary form must reproduce the above
 | 
			
		||||
// copyright notice, this list of conditions and the following disclaimer
 | 
			
		||||
// in the documentation and/or other materials provided with the
 | 
			
		||||
// distribution.
 | 
			
		||||
// *       Neither the name of Industrial Light & Magic nor the names of
 | 
			
		||||
// its contributors may be used to endorse or promote products derived
 | 
			
		||||
// from this software without specific prior written permission. 
 | 
			
		||||
// 
 | 
			
		||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 | 
			
		||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 | 
			
		||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 | 
			
		||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 | 
			
		||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 | 
			
		||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 | 
			
		||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 | 
			
		||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
			
		||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 | 
			
		||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
//
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#if defined(_WIN32) || defined(_WIN64) || defined(__MWERKS__) || defined(__ANDROID__)
 | 
			
		||||
    #define IMF_TMP_DIR ""
 | 
			
		||||
#else
 | 
			
		||||
    #define IMF_TMP_DIR "/var/tmp/"
 | 
			
		||||
#endif
 | 
			
		||||
		Reference in New Issue
	
	Block a user