HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImfInputFile.h
Go to the documentation of this file.
1 //
2 // SPDX-License-Identifier: BSD-3-Clause
3 // Copyright (c) Contributors to the OpenEXR Project.
4 //
5 
6 #ifndef INCLUDED_IMF_INPUT_FILE_H
7 #define INCLUDED_IMF_INPUT_FILE_H
8 
9 //-----------------------------------------------------------------------------
10 //
11 // class InputFile -- a scanline-based interface that can be used
12 // to read both scanline-based and tiled OpenEXR image files.
13 //
14 //-----------------------------------------------------------------------------
15 
16 #include "ImfForward.h"
17 
18 #include "ImfGenericInputFile.h"
19 #include "ImfThreading.h"
20 
22 
24 {
25 public:
26  //-----------------------------------------------------------
27  // A constructor that opens the file with the specified name.
28  // Destroying the InputFile object will close the file.
29  //
30  // numThreads determines the number of threads that will be
31  // used to read the file (see ImfThreading.h).
32  //-----------------------------------------------------------
33 
35  InputFile (const char fileName[], int numThreads = globalThreadCount ());
36 
37  //-------------------------------------------------------------
38  // A constructor that attaches the new InputFile object to a
39  // file that has already been opened. Destroying the InputFile
40  // object will not close the file.
41  //
42  // numThreads determines the number of threads that will be
43  // used to read the file (see ImfThreading.h).
44  //-------------------------------------------------------------
45 
47  InputFile (
49  int numThreads = globalThreadCount ());
50 
51  //-----------
52  // Destructor
53  //-----------
54 
56  virtual ~InputFile ();
57 
58  //------------------------
59  // Access to the file name
60  //------------------------
61 
63  const char* fileName () const;
64 
65  //--------------------------
66  // Access to the file header
67  //--------------------------
68 
70  const Header& header () const;
71 
72  //----------------------------------
73  // Access to the file format version
74  //----------------------------------
75 
77  int version () const;
78 
79  //-----------------------------------------------------------
80  // Set the current frame buffer -- copies the FrameBuffer
81  // object into the InputFile object.
82  //
83  // The current frame buffer is the destination for the pixel
84  // data read from the file. The current frame buffer must be
85  // set at least once before readPixels() is called.
86  // The current frame buffer can be changed after each call
87  // to readPixels().
88  //-----------------------------------------------------------
89 
91  void setFrameBuffer (const FrameBuffer& frameBuffer);
92 
93  //-----------------------------------
94  // Access to the current frame buffer
95  //-----------------------------------
96 
98  const FrameBuffer& frameBuffer () const;
99 
100  //---------------------------------------------------------------
101  // Check if the file is complete:
102  //
103  // isComplete() returns true if all pixels in the data window are
104  // present in the input file, or false if any pixels are missing.
105  // (Another program may still be busy writing the file, or file
106  // writing may have been aborted prematurely.)
107  //---------------------------------------------------------------
108 
109  IMF_EXPORT
110  bool isComplete () const;
111 
112  //---------------------------------------------------------------
113  // Check if SSE optimization is enabled
114  //
115  // Call after setFrameBuffer() to query whether optimized file decoding
116  // is available - decode times will be faster if returns true
117  //
118  // Optimization depends on:
119  // the file type (only scanline data is supported),
120  // the framebuffer channels (RGB/RGBA mono or stereo)
121  // the framebuffer channel types (all channels half-float format only)
122  // the file channels (RGB/RGBA mono or stereo)
123  // the file channel types (all channel half-float format only)
124  // whether SSE2 instruction support was detected at compile time
125  //
126  // Calling isOptimizationEnabled before setFrameBuffer will throw an exception
127  //
128  //---------------------------------------------------------------
129 
130  IMF_EXPORT
131  bool isOptimizationEnabled () const;
132 
133  //---------------------------------------------------------------
134  // Read pixel data:
135  //
136  // readPixels(s1,s2) reads all scan lines with y coordinates
137  // in the interval [min (s1, s2), max (s1, s2)] from the file,
138  // and stores them in the current frame buffer.
139  //
140  // Both s1 and s2 must be within the interval
141  // [header().dataWindow().min.y, header().dataWindow().max.y]
142  //
143  // The scan lines can be read from the file in random order, and
144  // individual scan lines may be skipped or read multiple times.
145  // For maximum efficiency, the scan lines should be read in the
146  // order in which they were written to the file.
147  //
148  // readPixels(s) calls readPixels(s,s).
149  //
150  //---------------------------------------------------------------
151 
152  IMF_EXPORT
153  void readPixels (int scanLine1, int scanLine2);
154  IMF_EXPORT
155  void readPixels (int scanLine);
156 
157  //----------------------------------------------
158  // Read a block of raw pixel data from the file,
159  // without uncompressing it (this function is
160  // used to implement OutputFile::copyPixels()).
161  //----------------------------------------------
162 
163  IMF_EXPORT
164  void rawPixelData (
165  int firstScanLine, const char*& pixelData, int& pixelDataSize);
166 
167  //----------------------------------------------
168  // Read a scanline's worth of raw pixel data
169  // from the file, without uncompressing it, and
170  // store in an external buffer, pixelData.
171  // pixelData should be pre-allocated with space
172  // for pixelDataSize chars.
173  //
174  // This function can be used to separate the
175  // reading of a raw scan line from the
176  // decompression of that scan line, for
177  // example to allow multiple scan lines to be
178  // decompressed in parallel by an application's
179  // own threads, where it is not convenient to
180  // use the threading within the library.
181  //----------------------------------------------
182 
183  IMF_EXPORT
184  void rawPixelDataToBuffer (
185  int scanLine, char* pixelData, int& pixelDataSize) const;
186 
187  //--------------------------------------------------
188  // Read a tile of raw pixel data from the file,
189  // without uncompressing it (this function is
190  // used to implement TiledOutputFile::copyPixels()).
191  //--------------------------------------------------
192 
193  IMF_EXPORT
194  void rawTileData (
195  int& dx,
196  int& dy,
197  int& lx,
198  int& ly,
199  const char*& pixelData,
200  int& pixelDataSize);
201 
202  struct IMF_HIDDEN Data;
203 
204 private:
205  IMF_HIDDEN InputFile (InputPartData* part);
206 
207  InputFile (const InputFile&) = delete;
208  InputFile& operator= (const InputFile&) = delete;
209  InputFile (InputFile&&) = delete;
210  InputFile& operator= (InputFile&&) = delete;
211 
212  IMF_HIDDEN void initialize ();
213  IMF_HIDDEN void multiPartInitialize (InputPartData* part);
214  IMF_HIDDEN void
215  compatibilityInitialize (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream& is);
216  IMF_HIDDEN TiledInputFile* tFile ();
217 
218  // for copyPixels
219  friend class TiledOutputFile;
220 
221  Data* _data;
222 
223  friend class MultiPartInputFile;
224 };
225 
227 
228 #endif
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:83
class IMF_EXPORT_TYPE InputFile
Definition: ImfForward.h:36
struct IMF_HIDDEN Data
#define IMF_HIDDEN
Definition: ImfExport.h:55
#define IMF_EXPORT
Definition: ImfExport.h:54
OPENVDB_API void initialize()
Global registration of native Grid, Transform, Metadata and Point attribute types. Also initializes blosc (if enabled).
Definition: logging.h:294
GT_API const UT_StringHolder version
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER IMF_EXPORT int globalThreadCount()
LeafData & operator=(const LeafData &)=delete
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:80
#define IMF_EXPORT_TYPE
Definition: ImfExport.h:57
class IMF_EXPORT_TYPE IStream
Definition: ImfForward.h:87