|
| 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 |
0 commit comments