PBRT
/home/felix/UBC/projects/AdaptiveLightfieldSampling/pbrt_v2/src/3rdparty/openexr-1.7.0/ImfAcesFile.h
00001 
00002 //
00003 // Copyright (c) 2007, 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_ACES_FILE_H
00038 #define INCLUDED_IMF_ACES_FILE_H
00039 
00040 
00041 //-----------------------------------------------------------------------------
00042 //
00043 //      ACES image file I/O.
00044 //      
00045 //      This header file declares two classes that directly support
00046 //      image file input and output according to the Academy Image
00047 //      Interchange Framework.
00048 //      
00049 //      The Academy Image Interchange file format is a subset of OpenEXR:
00050 //      
00051 //          - Images are stored as scanlines.  Tiles are not allowed.
00052 //      
00053 //          - Images contain three color channels, either
00054 //                  R, G, B (red, green, blue) or
00055 //                  Y, RY, BY (luminance, sub-sampled chroma)
00056 //      
00057 //          - Images may optionally contain an alpha channel.
00058 //      
00059 //          - Only three compression types are allowed:
00060 //                  - NO_COMPRESSION (file is not compressed)
00061 //                  - PIZ_COMPRESSION (lossless)
00062 //                  - B44A_COMPRESSION (lossy)
00063 //      
00064 //          - The "chromaticities" header attribute must specify
00065 //            the ACES RGB primaries and white point.
00066 //      
00067 //      class AcesOutputFile writes an OpenEXR file, enforcing the
00068 //      restrictions listed above.  Pixel data supplied by application
00069 //      software must already be in the ACES RGB space.
00070 //      
00071 //      class AcesInputFile reads an OpenEXR file.  Pixel data delivered
00072 //      to application software is guaranteed to be in the ACES RGB space.
00073 //      If the RGB space of the file is not the same as the ACES space,
00074 //      then the pixels are automatically converted: the pixels are
00075 //      converted to CIE XYZ, a color adaptation transform shifts the
00076 //      white point, and the result is converted to ACES RGB.
00077 //
00078 //-----------------------------------------------------------------------------
00079 
00080 #include <ImfHeader.h>
00081 #include <ImfRgba.h>
00082 #include "ImathVec.h"
00083 #include "ImathBox.h"
00084 #include <ImfThreading.h>
00085 #include <string>
00086 
00087 namespace Imf {
00088 
00089 
00090 class RgbaOutputFile;
00091 class RgbaInputFile;
00092 struct PreviewRgba;
00093 class Chromaticities;
00094 
00095 //
00096 // ACES red, green, blue and white-point chromaticities.
00097 //
00098 
00099 const Chromaticities &  acesChromaticities ();
00100 
00101 
00102 //
00103 // ACES output file.
00104 //
00105 
00106 class AcesOutputFile
00107 {
00108   public:
00109 
00110     //---------------------------------------------------
00111     // Constructor -- header is constructed by the caller
00112     //---------------------------------------------------
00113 
00114     AcesOutputFile (const std::string &name,
00115                     const Header &header,
00116                     RgbaChannels rgbaChannels = WRITE_RGBA,
00117                     int numThreads = globalThreadCount());
00118 
00119 
00120     //----------------------------------------------------
00121     // Constructor -- header is constructed by the caller,
00122     // file is opened by the caller, destructor will not
00123     // automatically close the file.
00124     //----------------------------------------------------
00125 
00126     AcesOutputFile (OStream &os,
00127                     const Header &header,
00128                     RgbaChannels rgbaChannels = WRITE_RGBA,
00129                     int numThreads = globalThreadCount());
00130 
00131 
00132     //----------------------------------------------------------------
00133     // Constructor -- header data are explicitly specified as function
00134     // call arguments (empty dataWindow means "same as displayWindow")
00135     //----------------------------------------------------------------
00136 
00137     AcesOutputFile (const std::string &name,
00138                     const Imath::Box2i &displayWindow,
00139                     const Imath::Box2i &dataWindow = Imath::Box2i(),
00140                     RgbaChannels rgbaChannels = WRITE_RGBA,
00141                     float pixelAspectRatio = 1,
00142                     const Imath::V2f screenWindowCenter = Imath::V2f (0, 0),
00143                     float screenWindowWidth = 1,
00144                     LineOrder lineOrder = INCREASING_Y,
00145                     Compression compression = PIZ_COMPRESSION,
00146                     int numThreads = globalThreadCount());
00147 
00148 
00149     //-----------------------------------------------
00150     // Constructor -- like the previous one, but both
00151     // the display window and the data window are
00152     // Box2i (V2i (0, 0), V2i (width - 1, height -1))
00153     //-----------------------------------------------
00154 
00155     AcesOutputFile (const std::string &name,
00156                     int width,
00157                     int height,
00158                     RgbaChannels rgbaChannels = WRITE_RGBA,
00159                     float pixelAspectRatio = 1,
00160                     const Imath::V2f screenWindowCenter = Imath::V2f (0, 0),
00161                     float screenWindowWidth = 1,
00162                     LineOrder lineOrder = INCREASING_Y,
00163                     Compression compression = PIZ_COMPRESSION,
00164                     int numThreads = globalThreadCount());
00165 
00166 
00167     //-----------
00168     // Destructor
00169     //-----------
00170 
00171     virtual ~AcesOutputFile ();
00172 
00173 
00174     //------------------------------------------------
00175     // Define a frame buffer as the pixel data source:
00176     // Pixel (x, y) is at address
00177     //
00178     //  base + x * xStride + y * yStride
00179     //
00180     //------------------------------------------------
00181 
00182     void                        setFrameBuffer (const Rgba *base,
00183                                                 size_t xStride,
00184                                                 size_t yStride);
00185 
00186 
00187     //-------------------------------------------------
00188     // Write pixel data (see class Imf::OutputFile)
00189     // The pixels are assumed to contain ACES RGB data.
00190     //-------------------------------------------------
00191 
00192     void                        writePixels (int numScanLines = 1);
00193     int                         currentScanLine () const;
00194 
00195 
00196     //--------------------------
00197     // Access to the file header
00198     //--------------------------
00199 
00200     const Header &              header () const;
00201     const Imath::Box2i &        displayWindow () const;
00202     const Imath::Box2i &        dataWindow () const;
00203     float                       pixelAspectRatio () const;
00204     const Imath::V2f            screenWindowCenter () const;
00205     float                       screenWindowWidth () const;
00206     LineOrder                   lineOrder () const;
00207     Compression                 compression () const;
00208     RgbaChannels                channels () const;
00209 
00210 
00211     // --------------------------------------------------------------------
00212     // Update the preview image (see Imf::OutputFile::updatePreviewImage())
00213     // --------------------------------------------------------------------
00214 
00215     void                        updatePreviewImage (const PreviewRgba[]);
00216 
00217 
00218   private:
00219 
00220     AcesOutputFile (const AcesOutputFile &);              // not implemented
00221     AcesOutputFile & operator = (const AcesOutputFile &); // not implemented
00222 
00223     class Data;
00224 
00225     Data *                      _data;
00226 };
00227 
00228 
00229 //
00230 // ACES input file
00231 //
00232 
00233 class AcesInputFile
00234 {
00235   public:
00236 
00237     //-------------------------------------------------------
00238     // Constructor -- opens the file with the specified name,
00239     // destructor will automatically close the file.
00240     //-------------------------------------------------------
00241 
00242     AcesInputFile (const std::string &name,
00243                    int numThreads = globalThreadCount());
00244 
00245 
00246     //-----------------------------------------------------------
00247     // Constructor -- attaches the new AcesInputFile object to a
00248     // file that has already been opened by the caller.
00249     // Destroying the AcesInputFile object will not automatically
00250     // close the file.
00251     //-----------------------------------------------------------
00252 
00253     AcesInputFile (IStream &is,
00254                    int numThreads = globalThreadCount());
00255 
00256 
00257     //-----------
00258     // Destructor
00259     //-----------
00260 
00261     virtual ~AcesInputFile ();
00262 
00263 
00264     //-----------------------------------------------------
00265     // Define a frame buffer as the pixel data destination:
00266     // Pixel (x, y) is at address
00267     //
00268     //  base + x * xStride + y * yStride
00269     //
00270     //-----------------------------------------------------
00271 
00272     void                        setFrameBuffer (Rgba *base,
00273                                                 size_t xStride,
00274                                                 size_t yStride);
00275 
00276 
00277     //--------------------------------------------
00278     // Read pixel data (see class Imf::InputFile)
00279     // Pixels returned will contain ACES RGB data.
00280     //--------------------------------------------
00281 
00282     void                        readPixels (int scanLine1, int scanLine2);
00283     void                        readPixels (int scanLine);
00284 
00285 
00286     //--------------------------
00287     // Access to the file header
00288     //--------------------------
00289 
00290     const Header &              header () const;
00291     const Imath::Box2i &        displayWindow () const;
00292     const Imath::Box2i &        dataWindow () const;
00293     float                       pixelAspectRatio () const;
00294     const Imath::V2f            screenWindowCenter () const;
00295     float                       screenWindowWidth () const;
00296     LineOrder                   lineOrder () const;
00297     Compression                 compression () const;
00298     RgbaChannels                channels () const;
00299     const char *                fileName () const;
00300     bool                        isComplete () const;
00301 
00302 
00303     //----------------------------------
00304     // Access to the file format version
00305     //----------------------------------
00306 
00307     int                         version () const;
00308 
00309   private:
00310 
00311     AcesInputFile (const AcesInputFile &);                // not implemented
00312     AcesInputFile & operator = (const AcesInputFile &);   // not implemented
00313 
00314     class Data;
00315 
00316     Data *                      _data;
00317 };
00318 
00319 
00320 } // namespace Imf
00321 
00322 #endif