PBRT
|
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 #ifndef INCLUDED_IMF_INPUT_FILE_H 00037 #define INCLUDED_IMF_INPUT_FILE_H 00038 00039 //----------------------------------------------------------------------------- 00040 // 00041 // class InputFile -- a scanline-based interface that can be used 00042 // to read both scanline-based and tiled OpenEXR image files. 00043 // 00044 //----------------------------------------------------------------------------- 00045 00046 #include <ImfHeader.h> 00047 #include <ImfFrameBuffer.h> 00048 #include <ImfTiledOutputFile.h> 00049 #include <string> 00050 #include <fstream> 00051 #include <ImfThreading.h> 00052 00053 namespace Imf { 00054 00055 class TiledInputFile; 00056 class ScanLineInputFile; 00057 00058 00059 class InputFile 00060 { 00061 public: 00062 00063 //----------------------------------------------------------- 00064 // A constructor that opens the file with the specified name. 00065 // Destroying the InputFile object will close the file. 00066 // 00067 // numThreads determines the number of threads that will be 00068 // used to read the file (see ImfThreading.h). 00069 //----------------------------------------------------------- 00070 00071 InputFile (const char fileName[], int numThreads = globalThreadCount()); 00072 00073 00074 //------------------------------------------------------------- 00075 // A constructor that attaches the new InputFile object to a 00076 // file that has already been opened. Destroying the InputFile 00077 // object will not close the file. 00078 // 00079 // numThreads determines the number of threads that will be 00080 // used to read the file (see ImfThreading.h). 00081 //------------------------------------------------------------- 00082 00083 InputFile (IStream &is, int numThreads = globalThreadCount()); 00084 00085 00086 //----------- 00087 // Destructor 00088 //----------- 00089 00090 virtual ~InputFile (); 00091 00092 00093 //------------------------ 00094 // Access to the file name 00095 //------------------------ 00096 00097 const char * fileName () const; 00098 00099 00100 //-------------------------- 00101 // Access to the file header 00102 //-------------------------- 00103 00104 const Header & header () const; 00105 00106 00107 //---------------------------------- 00108 // Access to the file format version 00109 //---------------------------------- 00110 00111 int version () const; 00112 00113 00114 //----------------------------------------------------------- 00115 // Set the current frame buffer -- copies the FrameBuffer 00116 // object into the InputFile object. 00117 // 00118 // The current frame buffer is the destination for the pixel 00119 // data read from the file. The current frame buffer must be 00120 // set at least once before readPixels() is called. 00121 // The current frame buffer can be changed after each call 00122 // to readPixels(). 00123 //----------------------------------------------------------- 00124 00125 void setFrameBuffer (const FrameBuffer &frameBuffer); 00126 00127 00128 //----------------------------------- 00129 // Access to the current frame buffer 00130 //----------------------------------- 00131 00132 const FrameBuffer & frameBuffer () const; 00133 00134 00135 //--------------------------------------------------------------- 00136 // Check if the file is complete: 00137 // 00138 // isComplete() returns true if all pixels in the data window are 00139 // present in the input file, or false if any pixels are missing. 00140 // (Another program may still be busy writing the file, or file 00141 // writing may have been aborted prematurely.) 00142 //--------------------------------------------------------------- 00143 00144 bool isComplete () const; 00145 00146 00147 //--------------------------------------------------------------- 00148 // Read pixel data: 00149 // 00150 // readPixels(s1,s2) reads all scan lines with y coordinates 00151 // in the interval [min (s1, s2), max (s1, s2)] from the file, 00152 // and stores them in the current frame buffer. 00153 // 00154 // Both s1 and s2 must be within the interval 00155 // [header().dataWindow().min.y, header().dataWindow().max.y] 00156 // 00157 // The scan lines can be read from the file in random order, and 00158 // individual scan lines may be skipped or read multiple times. 00159 // For maximum efficiency, the scan lines should be read in the 00160 // order in which they were written to the file. 00161 // 00162 // readPixels(s) calls readPixels(s,s). 00163 // 00164 //--------------------------------------------------------------- 00165 00166 void readPixels (int scanLine1, int scanLine2); 00167 void readPixels (int scanLine); 00168 00169 00170 //---------------------------------------------- 00171 // Read a block of raw pixel data from the file, 00172 // without uncompressing it (this function is 00173 // used to implement OutputFile::copyPixels()). 00174 //---------------------------------------------- 00175 00176 void rawPixelData (int firstScanLine, 00177 const char *&pixelData, 00178 int &pixelDataSize); 00179 00180 //-------------------------------------------------- 00181 // Read a tile of raw pixel data from the file, 00182 // without uncompressing it (this function is 00183 // used to implement TiledOutputFile::copyPixels()). 00184 //-------------------------------------------------- 00185 00186 void rawTileData (int &dx, int &dy, 00187 int &lx, int &ly, 00188 const char *&pixelData, 00189 int &pixelDataSize); 00190 00191 struct Data; 00192 00193 private: 00194 00195 InputFile (const InputFile &); // not implemented 00196 InputFile & operator = (const InputFile &); // not implemented 00197 00198 void initialize (); 00199 TiledInputFile * tFile (); 00200 00201 friend void TiledOutputFile::copyPixels (InputFile &); 00202 00203 Data * _data; 00204 }; 00205 00206 00207 } // namespace Imf 00208 00209 #endif