Skip to content

Commit 6390862

Browse files
committed
Merge pull request #253 from goddardl/EXR2
EXR2 Deep Image Reader and Writer
2 parents 51f38b8 + 63c6c14 commit 6390862

19 files changed

+1515
-4
lines changed

SConstruct

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,15 @@ if doConfigure :
14591459
corePythonSources.remove( "src/IECorePython/EnvMapSHProjectorBinding.cpp" )
14601460
corePythonSources.remove( "src/IECorePython/ImageConvolveOpBinding.cpp" )
14611461

1462+
if c.CheckHeader( "OpenEXR/ImfDeepFrameBuffer.h", "\"\"", "C++" ) :
1463+
for e in allCoreEnvs :
1464+
e.Append( CPPFLAGS = '-DIECORE_WITH_DEEPEXR' )
1465+
else :
1466+
coreSources.remove( "src/IECore/EXRDeepImageReader.cpp" )
1467+
corePythonSources.remove( "src/IECorePython/EXRDeepImageReaderBinding.cpp" )
1468+
coreSources.remove( "src/IECore/EXRDeepImageWriter.cpp" )
1469+
corePythonSources.remove( "src/IECorePython/EXRDeepImageWriterBinding.cpp" )
1470+
14621471
if c.CheckLibWithHeader( "tiff", "tiff.h", "CXX" ) :
14631472
for e in allCoreEnvs :
14641473
e.Append( CPPFLAGS = '-DIECORE_WITH_TIFF' )
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
//////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright (c) 2014, Image Engine Design Inc. All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are
7+
// met:
8+
//
9+
// * Redistributions of source code must retain the above copyright
10+
// notice, this list of conditions and the following disclaimer.
11+
//
12+
// * Redistributions in binary form must reproduce the above copyright
13+
// notice, this list of conditions and the following disclaimer in the
14+
// documentation and/or other materials provided with the distribution.
15+
//
16+
// * Neither the name of Image Engine Design nor the names of any
17+
// other contributors to this software may be used to endorse or
18+
// promote products derived from this software without specific prior
19+
// written permission.
20+
//
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22+
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23+
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
//
33+
//////////////////////////////////////////////////////////////////////////
34+
#ifndef IECORE_EXRDEEPIMAGEREADER_H
35+
#define IECORE_EXRDEEPIMAGEREADER_H
36+
37+
#include "OpenEXR/ImfDeepScanLineInputFile.h"
38+
39+
#include "IECore/DeepImageReader.h"
40+
#include "IECore/LRUCache.h"
41+
#include "IECore/TypeIds.h"
42+
43+
namespace IECore
44+
{
45+
46+
/// The EXRDeepImageReader class reads EXR 2.0 deep image files.
47+
/// \ingroup deepCompositingGroup
48+
/// \ingroup ioGroup
49+
class EXRDeepImageReader : public DeepImageReader
50+
{
51+
public :
52+
53+
IE_CORE_DECLARERUNTIMETYPEDEXTENSION( EXRDeepImageReader, EXRDeepImageReaderTypeId, DeepImageReader );
54+
55+
EXRDeepImageReader();
56+
EXRDeepImageReader( const std::string &filename );
57+
58+
virtual ~EXRDeepImageReader();
59+
60+
static bool canRead( const std::string &filename );
61+
62+
virtual void channelNames( std::vector<std::string> &names );
63+
virtual bool isComplete();
64+
virtual Imath::Box2i dataWindow();
65+
virtual Imath::Box2i displayWindow();
66+
virtual Imath::M44f worldToNDCMatrix();
67+
virtual Imath::M44f worldToCameraMatrix();
68+
69+
protected :
70+
71+
virtual DeepPixelPtr doReadPixel( int x, int y );
72+
73+
private :
74+
75+
static const ReaderDescription<EXRDeepImageReader> g_readerDescription;
76+
77+
/// Tries to open the file, returning true on success and false on failure. On success,
78+
/// all of the private members will be valid. If throwOnFailure is true then a descriptive
79+
/// Exception is thrown rather than false being returned.
80+
bool open( bool throwOnFailure = false );
81+
82+
class Scanline : public RefCounted
83+
{
84+
public :
85+
86+
IE_CORE_DECLAREMEMBERPTR( Scanline );
87+
88+
Scanline( size_t width, size_t numChannels );
89+
90+
std::vector<unsigned> sampleCount;
91+
std::vector<void *> pointers;
92+
std::vector<char> data;
93+
94+
};
95+
96+
struct Getter;
97+
typedef LRUCache<int, Scanline::Ptr> Cache;
98+
99+
Cache *m_cache;
100+
Imf::DeepScanLineInputFile *m_inputFile;
101+
102+
int m_depthChannel;
103+
std::vector<std::string> m_channelNames;
104+
std::vector<Imf::PixelType> m_channelTypes;
105+
106+
};
107+
108+
IE_CORE_DECLAREPTR( EXRDeepImageReader );
109+
110+
} // namespace IECore
111+
112+
#endif // IECORE_EXRDEEPIMAGEREADER_H
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
//////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright (c) 2014, Image Engine Design Inc. All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are
7+
// met:
8+
//
9+
// * Redistributions of source code must retain the above copyright
10+
// notice, this list of conditions and the following disclaimer.
11+
//
12+
// * Redistributions in binary form must reproduce the above copyright
13+
// notice, this list of conditions and the following disclaimer in the
14+
// documentation and/or other materials provided with the distribution.
15+
//
16+
// * Neither the name of Image Engine Design nor the names of any
17+
// other contributors to this software may be used to endorse or
18+
// promote products derived from this software without specific prior
19+
// written permission.
20+
//
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22+
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23+
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
//
33+
//////////////////////////////////////////////////////////////////////////
34+
#ifndef IECORE_EXRDEEPIMAGEWRITER_H
35+
#define IECORE_EXRDEEPIMAGEWRITER_H
36+
37+
#include "OpenEXR/ImfDeepScanLineOutputFile.h"
38+
#include "OpenEXR/ImfCompression.h"
39+
#include "OpenEXR/half.h"
40+
41+
#include "IECore/DeepImageWriter.h"
42+
#include "IECore/NumericParameter.h"
43+
#include "IECore/TypeIds.h"
44+
45+
namespace IECore
46+
{
47+
48+
/// The EXRDeepImageWriter class writes EXR 2.0 deep image files.
49+
/// \todo Currently we only support the writing of pixels by scanline in ascending order. Add random access.
50+
/// \ingroup deepCompositingGroup
51+
/// \ingroup ioGroup
52+
class EXRDeepImageWriter : public DeepImageWriter
53+
{
54+
public :
55+
56+
IE_CORE_DECLARERUNTIMETYPEDEXTENSION( EXRDeepImageWriter, EXRDeepImageWriterTypeId, DeepImageWriter );
57+
58+
EXRDeepImageWriter();
59+
EXRDeepImageWriter( const std::string &filename );
60+
61+
virtual ~EXRDeepImageWriter();
62+
63+
static bool canWrite( const std::string &filename );
64+
65+
/// The different modes of compression that are available.
66+
enum Compression
67+
{
68+
None = Imf::NO_COMPRESSION,
69+
RLE = Imf::RLE_COMPRESSION,
70+
ZIPS = Imf::ZIPS_COMPRESSION
71+
};
72+
73+
protected :
74+
75+
virtual void doWritePixel( int x, int y, const DeepPixel *pixel );
76+
77+
Imf::Compression compression() const;
78+
79+
private :
80+
81+
void clearScanlineBuffer();
82+
void appendParameters();
83+
void writeScanline();
84+
unsigned int numberOfChannels() const;
85+
const std::string &channelName( unsigned int index ) const;
86+
87+
static const DeepImageWriterDescription<EXRDeepImageWriter> g_writerDescription;
88+
89+
/// Tries to open the file for writing, throwing on failure. On success,
90+
/// all of the private members will be valid.
91+
void open();
92+
93+
Imf::DeepScanLineOutputFile *m_outputFile;
94+
IntParameterPtr m_compressionParameter;
95+
StringVectorParameterPtr m_halfChannelsParameter;
96+
97+
unsigned int m_numberOfFloatChannels;
98+
unsigned int m_numberOfHalfChannels;
99+
100+
std::vector< unsigned > m_sampleCount;
101+
std::vector< const void * > m_samplePointers;
102+
103+
std::vector< std::vector< float > > m_floatSamples;
104+
std::vector< std::vector< half > > m_halfSamples;
105+
106+
std::vector< std::vector< float > > m_depthSamples;
107+
std::vector< const float * > m_depthPointers;
108+
109+
std::vector<Imf::PixelType> m_channelTypes;
110+
111+
int m_width, m_height;
112+
int m_currentSlice, m_lastSlice;
113+
};
114+
115+
IE_CORE_DECLAREPTR( EXRDeepImageWriter );
116+
117+
} // namespace IECore
118+
119+
#endif // IECORE_EXRDEEPIMAGEWRITER_H

include/IECore/IECore.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//////////////////////////////////////////////////////////////////////////
22
//
3-
// Copyright (c) 2007-2011, Image Engine Design Inc. All rights reserved.
3+
// Copyright (c) 2007-2014, Image Engine Design Inc. All rights reserved.
44
// Copyright (c) 2012, John Haddon. All rights reserved.
55
//
66
// Redistribution and use in source and binary forms, with or without
@@ -65,6 +65,8 @@ bool withJPEG();
6565
bool withFreeType();
6666
/// Returns true if IECore was built with PNG suppport
6767
bool withPNG();
68+
/// Returns true if IECore was built with Deep EXR support
69+
bool withDeepEXR();
6870

6971
}
7072

include/IECore/TypeIds.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,8 @@ enum TypeId
436436
StandardRadialLensModelTypeId = 388,
437437
LensDistortOpTypeId = 389,
438438
TransferSmoothSkinningWeightsOpTypeId = 390,
439+
EXRDeepImageReaderTypeId = 391,
440+
EXRDeepImageWriterTypeId = 392,
439441

440442
// Remember to update TypeIdBinding.cpp !!!
441443

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright (c) 2014, Image Engine Design Inc. All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are
7+
// met:
8+
//
9+
// * Redistributions of source code must retain the above copyright
10+
// notice, this list of conditions and the following disclaimer.
11+
//
12+
// * Redistributions in binary form must reproduce the above copyright
13+
// notice, this list of conditions and the following disclaimer in the
14+
// documentation and/or other materials provided with the distribution.
15+
//
16+
// * Neither the name of Image Engine Design nor the names of any
17+
// other contributors to this software may be used to endorse or
18+
// promote products derived from this software without specific prior
19+
// written permission.
20+
//
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22+
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23+
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
//
33+
//////////////////////////////////////////////////////////////////////////
34+
35+
#ifndef IECOREPYTHON_EXRDEEPIMAGEREADER_BINDING
36+
#define IECOREPYTHON_EXRDEEPIMAGEREADER_BINDING
37+
38+
namespace IECorePython
39+
{
40+
#ifdef IECORE_WITH_DEEPEXR
41+
void bindEXRDeepImageReader();
42+
#endif
43+
}
44+
45+
#endif // IECOREPYTHON_EXRDEEPIMAGEREADER_BINDING
46+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright (c) 2014, Image Engine Design Inc. All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are
7+
// met:
8+
//
9+
// * Redistributions of source code must retain the above copyright
10+
// notice, this list of conditions and the following disclaimer.
11+
//
12+
// * Redistributions in binary form must reproduce the above copyright
13+
// notice, this list of conditions and the following disclaimer in the
14+
// documentation and/or other materials provided with the distribution.
15+
//
16+
// * Neither the name of Image Engine Design nor the names of any
17+
// other contributors to this software may be used to endorse or
18+
// promote products derived from this software without specific prior
19+
// written permission.
20+
//
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22+
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23+
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
//
33+
//////////////////////////////////////////////////////////////////////////
34+
35+
#ifndef IECOREPYTHON_EXRDEEPIMAGEWRITER_BINDING
36+
#define IECOREPYTHON_EXRDEEPIMAGEWRITER_BINDING
37+
38+
namespace IECorePython
39+
{
40+
#ifdef IECORE_WITH_DEEPEXR
41+
void bindEXRDeepImageWriter();
42+
#endif
43+
}
44+
45+
#endif // IECOREPYTHON_EXRDEEPIMAGEWRITER_BINDING
46+

0 commit comments

Comments
 (0)