HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ImfInputFile.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2004, Industrial Light & Magic, a division of Lucas
4 // Digital Ltd. LLC
5 //
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
10 // met:
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
16 // distribution.
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.
20 //
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.
32 //
33 ///////////////////////////////////////////////////////////////////////////
34 
35 
36 #ifndef INCLUDED_IMF_INPUT_FILE_H
37 #define INCLUDED_IMF_INPUT_FILE_H
38 
39 //-----------------------------------------------------------------------------
40 //
41 // class InputFile -- a scanline-based interface that can be used
42 // to read both scanline-based and tiled OpenEXR image files.
43 //
44 //-----------------------------------------------------------------------------
45 
46 #include "ImfHeader.h"
47 #include "ImfFrameBuffer.h"
48 #include "ImfTiledOutputFile.h"
49 #include "ImfThreading.h"
50 #include "ImfGenericInputFile.h"
51 #include "ImfNamespace.h"
52 #include "ImfForward.h"
53 #include "ImfExport.h"
54 
55 #include <fstream>
56 
57 
59 
60 
62 {
63  public:
64 
65  //-----------------------------------------------------------
66  // A constructor that opens the file with the specified name.
67  // Destroying the InputFile object will close the file.
68  //
69  // numThreads determines the number of threads that will be
70  // used to read the file (see ImfThreading.h).
71  //-----------------------------------------------------------
72 
73  InputFile (const char fileName[], int numThreads = globalThreadCount());
74 
75 
76  //-------------------------------------------------------------
77  // A constructor that attaches the new InputFile object to a
78  // file that has already been opened. Destroying the InputFile
79  // object will not close the file.
80  //
81  // numThreads determines the number of threads that will be
82  // used to read the file (see ImfThreading.h).
83  //-------------------------------------------------------------
84 
85  InputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, int numThreads = globalThreadCount());
86 
87 
88  //-----------
89  // Destructor
90  //-----------
91 
92  virtual ~InputFile ();
93 
94 
95  //------------------------
96  // Access to the file name
97  //------------------------
98 
99  const char * fileName () const;
100 
101 
102  //--------------------------
103  // Access to the file header
104  //--------------------------
105 
106  const Header & header () const;
107 
108 
109  //----------------------------------
110  // Access to the file format version
111  //----------------------------------
112 
113  int version () const;
114 
115 
116  //-----------------------------------------------------------
117  // Set the current frame buffer -- copies the FrameBuffer
118  // object into the InputFile object.
119  //
120  // The current frame buffer is the destination for the pixel
121  // data read from the file. The current frame buffer must be
122  // set at least once before readPixels() is called.
123  // The current frame buffer can be changed after each call
124  // to readPixels().
125  //-----------------------------------------------------------
126 
127  void setFrameBuffer (const FrameBuffer &frameBuffer);
128 
129 
130  //-----------------------------------
131  // Access to the current frame buffer
132  //-----------------------------------
133 
134  const FrameBuffer & frameBuffer () const;
135 
136 
137  //---------------------------------------------------------------
138  // Check if the file is complete:
139  //
140  // isComplete() returns true if all pixels in the data window are
141  // present in the input file, or false if any pixels are missing.
142  // (Another program may still be busy writing the file, or file
143  // writing may have been aborted prematurely.)
144  //---------------------------------------------------------------
145 
146  bool isComplete () const;
147 
148 
149  //---------------------------------------------------------------
150  // Check if SSE optimization is enabled
151  //
152  // Call after setFrameBuffer() to query whether optimized file decoding
153  // is available - decode times will be faster if returns true
154  //
155  // Optimization depends on:
156  // the file type (only scanline data is supported),
157  // the framebuffer channels (RGB/RGBA mono or stereo)
158  // the framebuffer channel types (all channels half-float format only)
159  // the file channels (RGB/RGBA mono or stereo)
160  // the file channel types (all channel half-float format only)
161  // whether SSE2 instruction support was detected at compile time
162  //
163  // Calling isOptimizationEnabled before setFrameBuffer will throw an exception
164  //
165  //---------------------------------------------------------------
166 
167  bool isOptimizationEnabled () const;
168 
169 
170 
171 
172  //---------------------------------------------------------------
173  // Read pixel data:
174  //
175  // readPixels(s1,s2) reads all scan lines with y coordinates
176  // in the interval [min (s1, s2), max (s1, s2)] from the file,
177  // and stores them in the current frame buffer.
178  //
179  // Both s1 and s2 must be within the interval
180  // [header().dataWindow().min.y, header().dataWindow().max.y]
181  //
182  // The scan lines can be read from the file in random order, and
183  // individual scan lines may be skipped or read multiple times.
184  // For maximum efficiency, the scan lines should be read in the
185  // order in which they were written to the file.
186  //
187  // readPixels(s) calls readPixels(s,s).
188  //
189  //---------------------------------------------------------------
190 
191  void readPixels (int scanLine1, int scanLine2);
192  void readPixels (int scanLine);
193 
194 
195  //----------------------------------------------
196  // Read a block of raw pixel data from the file,
197  // without uncompressing it (this function is
198  // used to implement OutputFile::copyPixels()).
199  //----------------------------------------------
200 
201  void rawPixelData (int firstScanLine,
202  const char *&pixelData,
203  int &pixelDataSize);
204 
205  //--------------------------------------------------
206  // Read a tile of raw pixel data from the file,
207  // without uncompressing it (this function is
208  // used to implement TiledOutputFile::copyPixels()).
209  //--------------------------------------------------
210 
211  void rawTileData (int &dx, int &dy,
212  int &lx, int &ly,
213  const char *&pixelData,
214  int &pixelDataSize);
215 
216  struct Data;
217 
218  private:
219 
220  InputFile (InputPartData* part);
221  InputFile (const InputFile &); // not implemented
222  InputFile & operator = (const InputFile &); // not implemented
223 
224  void initialize ();
225  void multiPartInitialize(InputPartData* part);
226  void compatibilityInitialize(OPENEXR_IMF_INTERNAL_NAMESPACE::IStream& is);
227  TiledInputFile * tFile ();
228 
229  friend void TiledOutputFile::copyPixels (InputFile &);
230 
231  Data * _data;
232 
233 
234  friend class MultiPartInputFile;
235 };
236 
237 
239 
240 #endif
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:109
#define IMF_EXPORT
Definition: ImfExport.h:59
OPENVDB_API void initialize()
Global registration of basic types.
Definition: logging.h:316
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER IMF_EXPORT int globalThreadCount()
void copyPixels(TiledInputFile &in)
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:108