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