1 ///////////////////////////////////////////////////////////////////////////
3 // Copyright (c) 2004, Industrial Light & Magic, a division of Lucas
6 // All rights reserved.
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of Industrial Light & Magic nor the names of
18 // its contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 ///////////////////////////////////////////////////////////////////////////
36 #ifndef INCLUDED_IMF_INPUT_FILE_H
37 #define INCLUDED_IMF_INPUT_FILE_H
39 //-----------------------------------------------------------------------------
41 // class InputFile -- a scanline-based interface that can be used
42 // to read both scanline-based and tiled OpenEXR image files.
44 //-----------------------------------------------------------------------------
46 #include <ImfHeader.h>
47 #include <ImfFrameBuffer.h>
48 #include <ImfTiledOutputFile.h>
51 #include <ImfThreading.h>
56 class ScanLineInputFile;
63 //-----------------------------------------------------------
64 // A constructor that opens the file with the specified name.
65 // Destroying the InputFile object will close the file.
67 // numThreads determines the number of threads that will be
68 // used to read the file (see ImfThreading.h).
69 //-----------------------------------------------------------
71 InputFile (const char fileName[], int numThreads = globalThreadCount());
74 //-------------------------------------------------------------
75 // A constructor that attaches the new InputFile object to a
76 // file that has already been opened. Destroying the InputFile
77 // object will not close the file.
79 // numThreads determines the number of threads that will be
80 // used to read the file (see ImfThreading.h).
81 //-------------------------------------------------------------
83 InputFile (IStream &is, int numThreads = globalThreadCount());
90 virtual ~InputFile ();
93 //------------------------
94 // Access to the file name
95 //------------------------
97 const char * fileName () const;
100 //--------------------------
101 // Access to the file header
102 //--------------------------
104 const Header & header () const;
107 //----------------------------------
108 // Access to the file format version
109 //----------------------------------
111 int version () const;
114 //-----------------------------------------------------------
115 // Set the current frame buffer -- copies the FrameBuffer
116 // object into the InputFile object.
118 // The current frame buffer is the destination for the pixel
119 // data read from the file. The current frame buffer must be
120 // set at least once before readPixels() is called.
121 // The current frame buffer can be changed after each call
123 //-----------------------------------------------------------
125 void setFrameBuffer (const FrameBuffer &frameBuffer);
128 //-----------------------------------
129 // Access to the current frame buffer
130 //-----------------------------------
132 const FrameBuffer & frameBuffer () const;
135 //---------------------------------------------------------------
136 // Check if the file is complete:
138 // isComplete() returns true if all pixels in the data window are
139 // present in the input file, or false if any pixels are missing.
140 // (Another program may still be busy writing the file, or file
141 // writing may have been aborted prematurely.)
142 //---------------------------------------------------------------
144 bool isComplete () const;
147 //---------------------------------------------------------------
150 // readPixels(s1,s2) reads all scan lines with y coordinates
151 // in the interval [min (s1, s2), max (s1, s2)] from the file,
152 // and stores them in the current frame buffer.
154 // Both s1 and s2 must be within the interval
155 // [header().dataWindow().min.y, header().dataWindow().max.y]
157 // The scan lines can be read from the file in random order, and
158 // individual scan lines may be skipped or read multiple times.
159 // For maximum efficiency, the scan lines should be read in the
160 // order in which they were written to the file.
162 // readPixels(s) calls readPixels(s,s).
164 //---------------------------------------------------------------
166 void readPixels (int scanLine1, int scanLine2);
167 void readPixels (int scanLine);
170 //----------------------------------------------
171 // Read a block of raw pixel data from the file,
172 // without uncompressing it (this function is
173 // used to implement OutputFile::copyPixels()).
174 //----------------------------------------------
176 void rawPixelData (int firstScanLine,
177 const char *&pixelData,
180 //--------------------------------------------------
181 // Read a tile of raw pixel data from the file,
182 // without uncompressing it (this function is
183 // used to implement TiledOutputFile::copyPixels()).
184 //--------------------------------------------------
186 void rawTileData (int &dx, int &dy,
188 const char *&pixelData,
195 InputFile (const InputFile &); // not implemented
196 InputFile & operator = (const InputFile &); // not implemented
199 TiledInputFile * tFile ();
201 friend void TiledOutputFile::copyPixels (InputFile &);