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
21OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
22
23
24class IMF_EXPORT_TYPE InputFile : public GenericInputFile
25{
26 public:
27
28 //-----------------------------------------------------------
29 // A constructor that opens the file with the specified name.
30 // Destroying the InputFile object will close the file.
31 //
32 // numThreads determines the number of threads that will be
33 // used to read the file (see ImfThreading.h).
34 //-----------------------------------------------------------
35
36 IMF_EXPORT
37 InputFile (const char fileName[], int numThreads = globalThreadCount());
38
39
40 //-------------------------------------------------------------
41 // A constructor that attaches the new InputFile object to a
42 // file that has already been opened. Destroying the InputFile
43 // object will not close the file.
44 //
45 // numThreads determines the number of threads that will be
46 // used to read the file (see ImfThreading.h).
47 //-------------------------------------------------------------
48
49 IMF_EXPORT
50 InputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, int numThreads = globalThreadCount());
51
52
53 //-----------
54 // Destructor
55 //-----------
56
57 IMF_EXPORT
58 virtual ~InputFile ();
59
60
61 //------------------------
62 // Access to the file name
63 //------------------------
64
65 IMF_EXPORT
66 const char * fileName () const;
67
68
69 //--------------------------
70 // Access to the file header
71 //--------------------------
72
73 IMF_EXPORT
74 const Header & header () const;
75
76
77 //----------------------------------
78 // Access to the file format version
79 //----------------------------------
80
81 IMF_EXPORT
82 int version () const;
83
84
85 //-----------------------------------------------------------
86 // Set the current frame buffer -- copies the FrameBuffer
87 // object into the InputFile object.
88 //
89 // The current frame buffer is the destination for the pixel
90 // data read from the file. The current frame buffer must be
91 // set at least once before readPixels() is called.
92 // The current frame buffer can be changed after each call
93 // to readPixels().
94 //-----------------------------------------------------------
95
96 IMF_EXPORT
97 void setFrameBuffer (const FrameBuffer &frameBuffer);
98
99
100 //-----------------------------------
101 // Access to the current frame buffer
102 //-----------------------------------
103
104 IMF_EXPORT
105 const FrameBuffer & frameBuffer () const;
106
107
108 //---------------------------------------------------------------
109 // Check if the file is complete:
110 //
111 // isComplete() returns true if all pixels in the data window are
112 // present in the input file, or false if any pixels are missing.
113 // (Another program may still be busy writing the file, or file
114 // writing may have been aborted prematurely.)
115 //---------------------------------------------------------------
116
117 IMF_EXPORT
118 bool isComplete () const;
119
120
121 //---------------------------------------------------------------
122 // Check if SSE optimization is enabled
123 //
124 // Call after setFrameBuffer() to query whether optimized file decoding
125 // is available - decode times will be faster if returns true
126 //
127 // Optimization depends on:
128 // the file type (only scanline data is supported),
129 // the framebuffer channels (RGB/RGBA mono or stereo)
130 // the framebuffer channel types (all channels half-float format only)
131 // the file channels (RGB/RGBA mono or stereo)
132 // the file channel types (all channel half-float format only)
133 // whether SSE2 instruction support was detected at compile time
134 //
135 // Calling isOptimizationEnabled before setFrameBuffer will throw an exception
136 //
137 //---------------------------------------------------------------
138
139 IMF_EXPORT
140 bool isOptimizationEnabled () const;
141
142
143
144
145 //---------------------------------------------------------------
146 // Read pixel data:
147 //
148 // readPixels(s1,s2) reads all scan lines with y coordinates
149 // in the interval [min (s1, s2), max (s1, s2)] from the file,
150 // and stores them in the current frame buffer.
151 //
152 // Both s1 and s2 must be within the interval
153 // [header().dataWindow().min.y, header().dataWindow().max.y]
154 //
155 // The scan lines can be read from the file in random order, and
156 // individual scan lines may be skipped or read multiple times.
157 // For maximum efficiency, the scan lines should be read in the
158 // order in which they were written to the file.
159 //
160 // readPixels(s) calls readPixels(s,s).
161 //
162 //---------------------------------------------------------------
163
164 IMF_EXPORT
165 void readPixels (int scanLine1, int scanLine2);
166 IMF_EXPORT
167 void readPixels (int scanLine);
168
169
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 //----------------------------------------------
175
176 IMF_EXPORT
177 void rawPixelData (int firstScanLine,
178 const char *&pixelData,
179 int &pixelDataSize);
180
181
182 //----------------------------------------------
183 // Read a scanline's worth of raw pixel data
184 // from the file, without uncompressing it, and
185 // store in an external buffer, pixelData.
186 // pixelData should be pre-allocated with space
187 // for pixelDataSize chars.
188 //
189 // This function can be used to separate the
190 // reading of a raw scan line from the
191 // decompression of that scan line, for
192 // example to allow multiple scan lines to be
193 // decompressed in parallel by an application's
194 // own threads, where it is not convenient to
195 // use the threading within the library.
196 //----------------------------------------------
197
198 IMF_EXPORT
199 void rawPixelDataToBuffer (int scanLine,
200 char *pixelData,
201 int &pixelDataSize) const;
202
203
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 IMF_EXPORT
212 void rawTileData (int &dx, int &dy,
213 int &lx, int &ly,
214 const char *&pixelData,
215 int &pixelDataSize);
216
217 struct IMF_HIDDEN Data;
218
219 private:
220
221 IMF_HIDDEN InputFile (InputPartData* part);
222
223 InputFile (const InputFile &) = delete;
224 InputFile & operator = (const InputFile &) = delete;
225 InputFile (InputFile &&) = delete;
226 InputFile & operator = (InputFile &&) = delete;
227
228 IMF_HIDDEN void initialize ();
229 IMF_HIDDEN void multiPartInitialize(InputPartData* part);
230 IMF_HIDDEN void compatibilityInitialize(OPENEXR_IMF_INTERNAL_NAMESPACE::IStream& is);
231 IMF_HIDDEN TiledInputFile * tFile ();
232
233 // for copyPixels
234 friend class TiledOutputFile;
235
236 Data * _data;
237
238
239 friend class MultiPartInputFile;
240};
241
242
243OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
244
245#endif
246

source code of include/OpenEXR/ImfInputFile.h