HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImfTiledInputFile.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_TILED_INPUT_FILE_H
7 #define INCLUDED_IMF_TILED_INPUT_FILE_H
8 
9 //-----------------------------------------------------------------------------
10 //
11 // class TiledInputFile
12 //
13 //-----------------------------------------------------------------------------
14 
15 #include "ImfForward.h"
16 
17 #include "ImfContext.h"
18 
19 #include "ImfThreading.h"
20 
21 #include "ImfTileDescription.h"
22 #include <ImathBox.h>
23 
25 
27 {
28 public:
29  //--------------------------------------------------------------------
30  // A constructor that opens the file with the specified name, and
31  // reads the file header. The constructor throws an IEX_NAMESPACE::ArgExc
32  // exception if the file is not tiled.
33  // The numThreads parameter specifies how many worker threads this
34  // file will try to keep busy when decompressing individual tiles.
35  // Destroying TiledInputFile objects constructed with this constructor
36  // automatically closes the corresponding files.
37  //--------------------------------------------------------------------
38 
41  const char fileName[], int numThreads = globalThreadCount ());
42 
43  // ----------------------------------------------------------
44  // A constructor that attaches the new TiledInputFile object
45  // to a file that has already been opened.
46  // Destroying TiledInputFile objects constructed with this
47  // constructor does not automatically close the corresponding
48  // files.
49  // ----------------------------------------------------------
50 
54  int numThreads = globalThreadCount ());
55 
58  const char* filename,
59  const ContextInitializer& ctxtinit,
60  int numThreads = globalThreadCount ());
61 
62  //------------------------
63  // Access to the file name
64  //------------------------
65 
67  const char* fileName () const;
68 
69  //--------------------------
70  // Access to the file header
71  //--------------------------
72 
74  const Header& header () const;
75 
76  //----------------------------------
77  // Access to the file format version
78  //----------------------------------
79 
81  int version () const;
82 
83  //-----------------------------------------------------------
84  // Set the current frame buffer -- copies the FrameBuffer
85  // object into the TiledInputFile object.
86  //
87  // The current frame buffer is the destination for the pixel
88  // data read from the file. The current frame buffer must be
89  // set at least once before readTile() is called.
90  // The current frame buffer can be changed after each call
91  // to readTile().
92  //-----------------------------------------------------------
93 
95  void setFrameBuffer (const FrameBuffer& frameBuffer);
96 
97  //-----------------------------------
98  // Access to the current frame buffer
99  //-----------------------------------
100 
101  IMF_EXPORT
102  const FrameBuffer& frameBuffer () const;
103 
104  //------------------------------------------------------------
105  // Check if the file is complete:
106  //
107  // isComplete() returns true if all pixels in the data window
108  // (in all levels) are present in the input file, or false if
109  // any pixels are missing. (Another program may still be busy
110  // writing the file, or file writing may have been aborted
111  // prematurely.)
112  //------------------------------------------------------------
113 
114  IMF_EXPORT
115  bool isComplete () const;
116 
117  //--------------------------------------------------
118  // Utility functions:
119  //--------------------------------------------------
120 
121  //---------------------------------------------------------
122  // Multiresolution mode and tile size:
123  // The following functions return the xSize, ySize and mode
124  // fields of the file header's TileDescriptionAttribute.
125  //---------------------------------------------------------
126 
127  IMF_EXPORT
128  unsigned int tileXSize () const;
129  IMF_EXPORT
130  unsigned int tileYSize () const;
131  IMF_EXPORT
132  LevelMode levelMode () const;
133  IMF_EXPORT
134  LevelRoundingMode levelRoundingMode () const;
135 
136  //--------------------------------------------------------------------
137  // Number of levels:
138  //
139  // numXLevels() returns the file's number of levels in x direction.
140  //
141  // if levelMode() == ONE_LEVEL:
142  // return value is: 1
143  //
144  // if levelMode() == MIPMAP_LEVELS:
145  // return value is: rfunc (log (max (w, h)) / log (2)) + 1
146  //
147  // if levelMode() == RIPMAP_LEVELS:
148  // return value is: rfunc (log (w) / log (2)) + 1
149  //
150  // where
151  // w is the width of the image's data window, max.x - min.x + 1,
152  // y is the height of the image's data window, max.y - min.y + 1,
153  // and rfunc(x) is either floor(x), or ceil(x), depending on
154  // whether levelRoundingMode() returns ROUND_DOWN or ROUND_UP.
155  //
156  // numYLevels() returns the file's number of levels in y direction.
157  //
158  // if levelMode() == ONE_LEVEL or levelMode() == MIPMAP_LEVELS:
159  // return value is the same as for numXLevels()
160  //
161  // if levelMode() == RIPMAP_LEVELS:
162  // return value is: rfunc (log (h) / log (2)) + 1
163  //
164  //
165  // numLevels() is a convenience function for use with
166  // MIPMAP_LEVELS files.
167  //
168  // if levelMode() == ONE_LEVEL or levelMode() == MIPMAP_LEVELS:
169  // return value is the same as for numXLevels()
170  //
171  // if levelMode() == RIPMAP_LEVELS:
172  // an IEX_NAMESPACE::LogicExc exception is thrown
173  //
174  // isValidLevel(lx, ly) returns true if the file contains
175  // a level with level number (lx, ly), false if not.
176  //
177  //--------------------------------------------------------------------
178 
179  IMF_EXPORT
180  int numLevels () const;
181  IMF_EXPORT
182  int numXLevels () const;
183  IMF_EXPORT
184  int numYLevels () const;
185  IMF_EXPORT
186  bool isValidLevel (int lx, int ly) const;
187 
188  //----------------------------------------------------------
189  // Dimensions of a level:
190  //
191  // levelWidth(lx) returns the width of a level with level
192  // number (lx, *), where * is any number.
193  //
194  // return value is:
195  // max (1, rfunc (w / pow (2, lx)))
196  //
197  //
198  // levelHeight(ly) returns the height of a level with level
199  // number (*, ly), where * is any number.
200  //
201  // return value is:
202  // max (1, rfunc (h / pow (2, ly)))
203  //
204  //----------------------------------------------------------
205 
206  IMF_EXPORT
207  int levelWidth (int lx) const;
208  IMF_EXPORT
209  int levelHeight (int ly) const;
210 
211  //--------------------------------------------------------------
212  // Number of tiles:
213  //
214  // numXTiles(lx) returns the number of tiles in x direction
215  // that cover a level with level number (lx, *), where * is
216  // any number.
217  //
218  // return value is:
219  // (levelWidth(lx) + tileXSize() - 1) / tileXSize()
220  //
221  //
222  // numYTiles(ly) returns the number of tiles in y direction
223  // that cover a level with level number (*, ly), where * is
224  // any number.
225  //
226  // return value is:
227  // (levelHeight(ly) + tileXSize() - 1) / tileXSize()
228  //
229  //--------------------------------------------------------------
230 
231  IMF_EXPORT
232  int numXTiles (int lx = 0) const;
233  IMF_EXPORT
234  int numYTiles (int ly = 0) const;
235 
236  //---------------------------------------------------------------
237  // Level pixel ranges:
238  //
239  // dataWindowForLevel(lx, ly) returns a 2-dimensional region of
240  // valid pixel coordinates for a level with level number (lx, ly)
241  //
242  // return value is a Box2i with min value:
243  // (dataWindow.min.x, dataWindow.min.y)
244  //
245  // and max value:
246  // (dataWindow.min.x + levelWidth(lx) - 1,
247  // dataWindow.min.y + levelHeight(ly) - 1)
248  //
249  // dataWindowForLevel(level) is a convenience function used
250  // for ONE_LEVEL and MIPMAP_LEVELS files. It returns
251  // dataWindowForLevel(level, level).
252  //
253  //---------------------------------------------------------------
254 
255  IMF_EXPORT
256  IMATH_NAMESPACE::Box2i dataWindowForLevel (int l = 0) const;
257  IMF_EXPORT
258  IMATH_NAMESPACE::Box2i dataWindowForLevel (int lx, int ly) const;
259 
260  //-------------------------------------------------------------------
261  // Tile pixel ranges:
262  //
263  // dataWindowForTile(dx, dy, lx, ly) returns a 2-dimensional
264  // region of valid pixel coordinates for a tile with tile coordinates
265  // (dx,dy) and level number (lx, ly).
266  //
267  // return value is a Box2i with min value:
268  // (dataWindow.min.x + dx * tileXSize(),
269  // dataWindow.min.y + dy * tileYSize())
270  //
271  // and max value:
272  // (dataWindow.min.x + (dx + 1) * tileXSize() - 1,
273  // dataWindow.min.y + (dy + 1) * tileYSize() - 1)
274  //
275  // dataWindowForTile(dx, dy, level) is a convenience function
276  // used for ONE_LEVEL and MIPMAP_LEVELS files. It returns
277  // dataWindowForTile(dx, dy, level, level).
278  //
279  //-------------------------------------------------------------------
280 
281  IMF_EXPORT
282  IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy, int l = 0) const;
283 
284  IMF_EXPORT
286  dataWindowForTile (int dx, int dy, int lx, int ly) const;
287 
288  //------------------------------------------------------------
289  // Read pixel data:
290  //
291  // readTile(dx, dy, lx, ly) reads the tile with tile
292  // coordinates (dx, dy), and level number (lx, ly),
293  // and stores it in the current frame buffer.
294  //
295  // dx must lie in the interval [0, numXTiles(lx)-1]
296  // dy must lie in the interval [0, numYTiles(ly)-1]
297  //
298  // lx must lie in the interval [0, numXLevels()-1]
299  // ly must lie in the interval [0, numYLevels()-1]
300  //
301  // readTile(dx, dy, level) is a convenience function used
302  // for ONE_LEVEL and MIPMAP_LEVELS files. It calls
303  // readTile(dx, dy, level, level).
304  //
305  // The two readTiles(dx1, dx2, dy1, dy2, ...) functions allow
306  // reading multiple tiles at once. If multi-threading is used
307  // the multiple tiles are read concurrently.
308  //
309  // Pixels that are outside the pixel coordinate range for the
310  // tile's level, are never accessed by readTile().
311  //
312  // Attempting to access a tile that is not present in the file
313  // throws an InputExc exception.
314  //
315  //------------------------------------------------------------
316 
317  IMF_EXPORT
318  void readTile (int dx, int dy, int l = 0);
319  IMF_EXPORT
320  void readTile (int dx, int dy, int lx, int ly);
321 
322  IMF_EXPORT
323  void readTiles (int dx1, int dx2, int dy1, int dy2, int lx, int ly);
324 
325  IMF_EXPORT
326  void readTiles (int dx1, int dx2, int dy1, int dy2, int l = 0);
327 
328  //--------------------------------------------------
329  // Read a tile of raw pixel data from the file,
330  // without uncompressing it (this function is
331  // used to implement TiledOutputFile::copyPixels()).
332  //
333  // for single part files, reads the next tile in the file
334  // for multipart files, reads the tile specified by dx,dy,lx,ly
335  //
336  //--------------------------------------------------
337 
338  IMF_EXPORT
339  void rawTileData (
340  int& dx,
341  int& dy,
342  int& lx,
343  int& ly,
344  const char*& pixelData,
345  int& pixelDataSize);
346 
347 private:
348  Context _ctxt;
349  struct IMF_HIDDEN Data;
350  std::shared_ptr<Data> _data;
351 
352  friend class InputFile;
353  friend class MultiPartInputFile;
354 
355  IMF_HIDDEN
356  TiledInputFile (InputPartData* part);
357 
358  IMF_HIDDEN
359  bool isValidTile (int dx, int dy, int lx, int ly) const;
360 
361  IMF_HIDDEN
362  size_t bytesPerLineForTile (int dx, int dy, int lx, int ly) const;
363 
364  IMF_HIDDEN
365  void tileOrder (int dx[], int dy[], int lx[], int ly[]) const;
366 
367  friend class TiledOutputFile;
368 };
369 
371 
372 #endif
GT_API const UT_StringHolder filename
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:83
Provides generic access to read an image from an EXR file.
Definition: ImfInputFile.h:64
#define IMF_HIDDEN
Definition: ImfExport.h:55
ContextInitializer provides a basic type to initialize a Context with.
enum IMF_EXPORT_ENUM LevelRoundingMode
TODO: Document this.
Box< V2i > Box2i
2D box of base type int.
Definition: ImathBox.h:143
#define IMF_EXPORT
Definition: ImfExport.h:54
GT_API const UT_StringHolder version
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER IMF_EXPORT int globalThreadCount()
Context provides a wrapper around the Core library context object.
Definition: ImfContext.h:30
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:80
class IMF_EXPORT_TYPE TiledInputFile
Definition: ImfForward.h:34
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER enum IMF_EXPORT_ENUM LevelMode
#define IMF_EXPORT_TYPE
Definition: ImfExport.h:57
class IMF_EXPORT_TYPE IStream
Definition: ImfForward.h:87