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