PBRT
/home/felix/UBC/projects/AdaptiveLightfieldSampling/pbrt_v2/src/3rdparty/openexr-1.7.0/ImfRgbaFile.h
00001 
00002 //
00003 // Copyright (c) 2004, Industrial Light & Magic, a division of Lucas
00004 // Digital Ltd. LLC
00005 // 
00006 // All rights reserved.
00007 // 
00008 // Redistribution and use in source and binary forms, with or without
00009 // modification, are permitted provided that the following conditions are
00010 // met:
00011 // *       Redistributions of source code must retain the above copyright
00012 // notice, this list of conditions and the following disclaimer.
00013 // *       Redistributions in binary form must reproduce the above
00014 // copyright notice, this list of conditions and the following disclaimer
00015 // in the documentation and/or other materials provided with the
00016 // distribution.
00017 // *       Neither the name of Industrial Light & Magic nor the names of
00018 // its contributors may be used to endorse or promote products derived
00019 // from this software without specific prior written permission. 
00020 // 
00021 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00024 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00025 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00026 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00027 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00028 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00029 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00030 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00031 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032 //
00034 
00035 
00036 
00037 #ifndef INCLUDED_IMF_RGBA_FILE_H
00038 #define INCLUDED_IMF_RGBA_FILE_H
00039 
00040 
00041 //-----------------------------------------------------------------------------
00042 //
00043 //      Simplified RGBA image I/O
00044 //
00045 //      class RgbaOutputFile
00046 //      class RgbaInputFile
00047 //
00048 //-----------------------------------------------------------------------------
00049 
00050 #include <ImfHeader.h>
00051 #include <ImfFrameBuffer.h>
00052 #include <ImfRgba.h>
00053 #include "ImathVec.h"
00054 #include "ImathBox.h"
00055 #include "half.h"
00056 #include <ImfThreading.h>
00057 #include <string>
00058 
00059 namespace Imf {
00060 
00061 
00062 class OutputFile;
00063 class InputFile;
00064 struct PreviewRgba;
00065 
00066 //
00067 // RGBA output file.
00068 //
00069 
00070 class RgbaOutputFile
00071 {
00072   public:
00073 
00074     //---------------------------------------------------
00075     // Constructor -- header is constructed by the caller
00076     //---------------------------------------------------
00077 
00078     RgbaOutputFile (const char name[],
00079                     const Header &header,
00080                     RgbaChannels rgbaChannels = WRITE_RGBA,
00081                     int numThreads = globalThreadCount());
00082 
00083 
00084     //----------------------------------------------------
00085     // Constructor -- header is constructed by the caller,
00086     // file is opened by the caller, destructor will not
00087     // automatically close the file.
00088     //----------------------------------------------------
00089 
00090     RgbaOutputFile (OStream &os,
00091                     const Header &header,
00092                     RgbaChannels rgbaChannels = WRITE_RGBA,
00093                     int numThreads = globalThreadCount());
00094 
00095 
00096     //----------------------------------------------------------------
00097     // Constructor -- header data are explicitly specified as function
00098     // call arguments (empty dataWindow means "same as displayWindow")
00099     //----------------------------------------------------------------
00100 
00101     RgbaOutputFile (const char name[],
00102                     const Imath::Box2i &displayWindow,
00103                     const Imath::Box2i &dataWindow = Imath::Box2i(),
00104                     RgbaChannels rgbaChannels = WRITE_RGBA,
00105                     float pixelAspectRatio = 1,
00106                     const Imath::V2f screenWindowCenter = Imath::V2f (0, 0),
00107                     float screenWindowWidth = 1,
00108                     LineOrder lineOrder = INCREASING_Y,
00109                     Compression compression = PIZ_COMPRESSION,
00110                     int numThreads = globalThreadCount());
00111 
00112 
00113     //-----------------------------------------------
00114     // Constructor -- like the previous one, but both
00115     // the display window and the data window are
00116     // Box2i (V2i (0, 0), V2i (width - 1, height -1))
00117     //-----------------------------------------------
00118 
00119     RgbaOutputFile (const char name[],
00120                     int width,
00121                     int height,
00122                     RgbaChannels rgbaChannels = WRITE_RGBA,
00123                     float pixelAspectRatio = 1,
00124                     const Imath::V2f screenWindowCenter = Imath::V2f (0, 0),
00125                     float screenWindowWidth = 1,
00126                     LineOrder lineOrder = INCREASING_Y,
00127                     Compression compression = PIZ_COMPRESSION,
00128                     int numThreads = globalThreadCount());
00129 
00130 
00131     //-----------
00132     // Destructor
00133     //-----------
00134 
00135     virtual ~RgbaOutputFile ();
00136 
00137 
00138     //------------------------------------------------
00139     // Define a frame buffer as the pixel data source:
00140     // Pixel (x, y) is at address
00141     //
00142     //  base + x * xStride + y * yStride
00143     //
00144     //------------------------------------------------
00145 
00146     void                        setFrameBuffer (const Rgba *base,
00147                                                 size_t xStride,
00148                                                 size_t yStride);
00149 
00150 
00151     //---------------------------------------------
00152     // Write pixel data (see class Imf::OutputFile)
00153     //---------------------------------------------
00154 
00155     void                        writePixels (int numScanLines = 1);
00156     int                         currentScanLine () const;
00157 
00158 
00159     //--------------------------
00160     // Access to the file header
00161     //--------------------------
00162 
00163     const Header &              header () const;
00164     const FrameBuffer &         frameBuffer () const;
00165     const Imath::Box2i &        displayWindow () const;
00166     const Imath::Box2i &        dataWindow () const;
00167     float                       pixelAspectRatio () const;
00168     const Imath::V2f            screenWindowCenter () const;
00169     float                       screenWindowWidth () const;
00170     LineOrder                   lineOrder () const;
00171     Compression                 compression () const;
00172     RgbaChannels                channels () const;
00173 
00174 
00175     // --------------------------------------------------------------------
00176     // Update the preview image (see Imf::OutputFile::updatePreviewImage())
00177     // --------------------------------------------------------------------
00178 
00179     void                        updatePreviewImage (const PreviewRgba[]);
00180 
00181 
00182     //-----------------------------------------------------------------------
00183     // Rounding control for luminance/chroma images:
00184     //
00185     // If the output file contains luminance and chroma channels (WRITE_YC
00186     // or WRITE_YCA), then the the significands of the luminance and
00187     // chroma values are rounded to roundY and roundC bits respectively (see
00188     // function half::round()).  Rounding improves compression with minimal
00189     // image degradation, usually much less than the degradation caused by
00190     // chroma subsampling.  By default, roundY is 7, and roundC is 5.
00191     //
00192     // If the output file contains RGB channels or a luminance channel,
00193     // without chroma, then no rounding is performed.
00194     //-----------------------------------------------------------------------
00195 
00196     void                        setYCRounding (unsigned int roundY,
00197                                                unsigned int roundC);
00198 
00199 
00200     //----------------------------------------------------
00201     // Break a scan line -- for testing and debugging only
00202     // (see Imf::OutputFile::updatePreviewImage()
00203     //
00204     // Warning: Calling this function usually results in a
00205     // broken image file.  The file or parts of it may not
00206     // be readable, or the file may contain bad data.
00207     //
00208     //----------------------------------------------------
00209 
00210     void                        breakScanLine  (int y,
00211                                                 int offset,
00212                                                 int length,
00213                                                 char c);
00214   private:
00215 
00216     RgbaOutputFile (const RgbaOutputFile &);              // not implemented
00217     RgbaOutputFile & operator = (const RgbaOutputFile &); // not implemented
00218 
00219     class ToYca;
00220 
00221     OutputFile *                _outputFile;
00222     ToYca *                     _toYca;
00223 };
00224 
00225 
00226 //
00227 // RGBA input file
00228 //
00229 
00230 class RgbaInputFile
00231 {
00232   public:
00233 
00234     //-------------------------------------------------------
00235     // Constructor -- opens the file with the specified name,
00236     // destructor will automatically close the file.
00237     //-------------------------------------------------------
00238 
00239     RgbaInputFile (const char name[], int numThreads = globalThreadCount());
00240 
00241 
00242     //-----------------------------------------------------------
00243     // Constructor -- attaches the new RgbaInputFile object to a
00244     // file that has already been opened by the caller.
00245     // Destroying the RgbaInputFile object will not automatically
00246     // close the file.
00247     //-----------------------------------------------------------
00248 
00249     RgbaInputFile (IStream &is, int numThreads = globalThreadCount());
00250 
00251 
00252     //--------------------------------------------------------------
00253     // Constructors -- the same as the previous two, but the names
00254     // of the red, green, blue, alpha, luminance and chroma channels
00255     // are expected to be layerName.R, layerName.G, etc.
00256     //--------------------------------------------------------------
00257 
00258     RgbaInputFile (const char name[],
00259                    const std::string &layerName,
00260                    int numThreads = globalThreadCount());
00261 
00262     RgbaInputFile (IStream &is,
00263                    const std::string &layerName,
00264                    int numThreads = globalThreadCount());
00265 
00266 
00267     //-----------
00268     // Destructor
00269     //-----------
00270 
00271     virtual ~RgbaInputFile ();
00272 
00273 
00274     //-----------------------------------------------------
00275     // Define a frame buffer as the pixel data destination:
00276     // Pixel (x, y) is at address
00277     //
00278     //  base + x * xStride + y * yStride
00279     //
00280     //-----------------------------------------------------
00281 
00282     void                        setFrameBuffer (Rgba *base,
00283                                                 size_t xStride,
00284                                                 size_t yStride);
00285 
00286 
00287     //----------------------------------------------------------------
00288     // Switch to a different layer -- subsequent calls to readPixels()
00289     // will read channels layerName.R, layerName.G, etc.
00290     // After each call to setLayerName(), setFrameBuffer() must be
00291     // called at least once before the next call to readPixels().
00292     //----------------------------------------------------------------
00293 
00294     void                        setLayerName (const std::string &layerName);
00295 
00296 
00297     //-------------------------------------------
00298     // Read pixel data (see class Imf::InputFile)
00299     //-------------------------------------------
00300 
00301     void                        readPixels (int scanLine1, int scanLine2);
00302     void                        readPixels (int scanLine);
00303 
00304 
00305     //--------------------------
00306     // Access to the file header
00307     //--------------------------
00308 
00309     const Header &              header () const;
00310     const FrameBuffer &         frameBuffer () const;
00311     const Imath::Box2i &        displayWindow () const;
00312     const Imath::Box2i &        dataWindow () const;
00313     float                       pixelAspectRatio () const;
00314     const Imath::V2f            screenWindowCenter () const;
00315     float                       screenWindowWidth () const;
00316     LineOrder                   lineOrder () const;
00317     Compression                 compression () const;
00318     RgbaChannels                channels () const;
00319     const char *                fileName () const;
00320     bool                        isComplete () const;
00321 
00322 
00323     //----------------------------------
00324     // Access to the file format version
00325     //----------------------------------
00326 
00327     int                         version () const;
00328 
00329   private:
00330 
00331     RgbaInputFile (const RgbaInputFile &);                // not implemented
00332     RgbaInputFile & operator = (const RgbaInputFile &);   // not implemented
00333 
00334     class FromYca;
00335 
00336     InputFile *                 _inputFile;
00337     FromYca *                   _fromYca;
00338     std::string                 _channelNamePrefix;
00339 };
00340 
00341 
00342 } // namespace Imf
00343 
00344 #endif