HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImfDeepTiledOutputPart.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 IMFDEEPTILEDOUTPUTPART_H_
7 #define IMFDEEPTILEDOUTPUTPART_H_
8 
9 #include "ImfForward.h"
10 
11 #include "ImfTileDescription.h"
12 
13 #include <ImathBox.h>
14 
16 
18 {
19 public:
21  DeepTiledOutputPart (MultiPartOutputFile& multiPartFile, int partNumber);
22 
23  //------------------------
24  // Access to the file name
25  //------------------------
26 
28  const char* fileName () const;
29 
30  //--------------------------
31  // Access to the file header
32  //--------------------------
33 
35  const Header& header () const;
36 
37  //-------------------------------------------------------
38  // Set the current frame buffer -- copies the FrameBuffer
39  // object into the TiledOutputFile object.
40  //
41  // The current frame buffer is the source of the pixel
42  // data written to the file. The current frame buffer
43  // must be set at least once before writeTile() is
44  // called. The current frame buffer can be changed
45  // after each call to writeTile().
46  //-------------------------------------------------------
47 
49  void setFrameBuffer (const DeepFrameBuffer& frameBuffer);
50 
51  //-----------------------------------
52  // Access to the current frame buffer
53  //-----------------------------------
54 
56  const DeepFrameBuffer& frameBuffer () const;
57 
58  //-------------------
59  // Utility functions:
60  //-------------------
61 
62  //---------------------------------------------------------
63  // Multiresolution mode and tile size:
64  // The following functions return the xSize, ySize and mode
65  // fields of the file header's TileDescriptionAttribute.
66  //---------------------------------------------------------
67 
69  unsigned int tileXSize () const;
71  unsigned int tileYSize () const;
73  LevelMode levelMode () const;
75  LevelRoundingMode levelRoundingMode () const;
76 
77  //--------------------------------------------------------------------
78  // Number of levels:
79  //
80  // numXLevels() returns the file's number of levels in x direction.
81  //
82  // if levelMode() == ONE_LEVEL:
83  // return value is: 1
84  //
85  // if levelMode() == MIPMAP_LEVELS:
86  // return value is: rfunc (log (max (w, h)) / log (2)) + 1
87  //
88  // if levelMode() == RIPMAP_LEVELS:
89  // return value is: rfunc (log (w) / log (2)) + 1
90  //
91  // where
92  // w is the width of the image's data window, max.x - min.x + 1,
93  // y is the height of the image's data window, max.y - min.y + 1,
94  // and rfunc(x) is either floor(x), or ceil(x), depending on
95  // whether levelRoundingMode() returns ROUND_DOWN or ROUND_UP.
96  //
97  // numYLevels() returns the file's number of levels in y direction.
98  //
99  // if levelMode() == ONE_LEVEL or levelMode() == MIPMAP_LEVELS:
100  // return value is the same as for numXLevels()
101  //
102  // if levelMode() == RIPMAP_LEVELS:
103  // return value is: rfunc (log (h) / log (2)) + 1
104  //
105  //
106  // numLevels() is a convenience function for use with MIPMAP_LEVELS
107  // files.
108  //
109  // if levelMode() == ONE_LEVEL or levelMode() == MIPMAP_LEVELS:
110  // return value is the same as for numXLevels()
111  //
112  // if levelMode() == RIPMAP_LEVELS:
113  // an IEX_NAMESPACE::LogicExc exception is thrown
114  //
115  // isValidLevel(lx, ly) returns true if the file contains
116  // a level with level number (lx, ly), false if not.
117  //
118  //--------------------------------------------------------------------
119 
120  IMF_EXPORT
121  int numLevels () const;
122  IMF_EXPORT
123  int numXLevels () const;
124  IMF_EXPORT
125  int numYLevels () const;
126  IMF_EXPORT
127  bool isValidLevel (int lx, int ly) const;
128 
129  //---------------------------------------------------------
130  // Dimensions of a level:
131  //
132  // levelWidth(lx) returns the width of a level with level
133  // number (lx, *), where * is any number.
134  //
135  // return value is:
136  // max (1, rfunc (w / pow (2, lx)))
137  //
138  //
139  // levelHeight(ly) returns the height of a level with level
140  // number (*, ly), where * is any number.
141  //
142  // return value is:
143  // max (1, rfunc (h / pow (2, ly)))
144  //
145  //---------------------------------------------------------
146 
147  IMF_EXPORT
148  int levelWidth (int lx) const;
149  IMF_EXPORT
150  int levelHeight (int ly) const;
151 
152  //----------------------------------------------------------
153  // Number of tiles:
154  //
155  // numXTiles(lx) returns the number of tiles in x direction
156  // that cover a level with level number (lx, *), where * is
157  // any number.
158  //
159  // return value is:
160  // (levelWidth(lx) + tileXSize() - 1) / tileXSize()
161  //
162  //
163  // numYTiles(ly) returns the number of tiles in y direction
164  // that cover a level with level number (*, ly), where * is
165  // any number.
166  //
167  // return value is:
168  // (levelHeight(ly) + tileXSize() - 1) / tileXSize()
169  //
170  //----------------------------------------------------------
171 
172  IMF_EXPORT
173  int numXTiles (int lx = 0) const;
174  IMF_EXPORT
175  int numYTiles (int ly = 0) const;
176 
177  //---------------------------------------------------------
178  // Level pixel ranges:
179  //
180  // dataWindowForLevel(lx, ly) returns a 2-dimensional
181  // region of valid pixel coordinates for a level with
182  // level number (lx, ly)
183  //
184  // return value is a Box2i with min value:
185  // (dataWindow.min.x, dataWindow.min.y)
186  //
187  // and max value:
188  // (dataWindow.min.x + levelWidth(lx) - 1,
189  // dataWindow.min.y + levelHeight(ly) - 1)
190  //
191  // dataWindowForLevel(level) is a convenience function used
192  // for ONE_LEVEL and MIPMAP_LEVELS files. It returns
193  // dataWindowForLevel(level, level).
194  //
195  //---------------------------------------------------------
196 
197  IMF_EXPORT
198  IMATH_NAMESPACE::Box2i dataWindowForLevel (int l = 0) const;
199  IMF_EXPORT
200  IMATH_NAMESPACE::Box2i dataWindowForLevel (int lx, int ly) const;
201 
202  //-------------------------------------------------------------------
203  // Tile pixel ranges:
204  //
205  // dataWindowForTile(dx, dy, lx, ly) returns a 2-dimensional
206  // region of valid pixel coordinates for a tile with tile coordinates
207  // (dx,dy) and level number (lx, ly).
208  //
209  // return value is a Box2i with min value:
210  // (dataWindow.min.x + dx * tileXSize(),
211  // dataWindow.min.y + dy * tileYSize())
212  //
213  // and max value:
214  // (dataWindow.min.x + (dx + 1) * tileXSize() - 1,
215  // dataWindow.min.y + (dy + 1) * tileYSize() - 1)
216  //
217  // dataWindowForTile(dx, dy, level) is a convenience function
218  // used for ONE_LEVEL and MIPMAP_LEVELS files. It returns
219  // dataWindowForTile(dx, dy, level, level).
220  //
221  //-------------------------------------------------------------------
222 
223  IMF_EXPORT
224  IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy, int l = 0) const;
225 
226  IMF_EXPORT
228  dataWindowForTile (int dx, int dy, int lx, int ly) const;
229 
230  //------------------------------------------------------------------
231  // Write pixel data:
232  //
233  // writeTile(dx, dy, lx, ly) writes the tile with tile
234  // coordinates (dx, dy), and level number (lx, ly) to
235  // the file.
236  //
237  // dx must lie in the interval [0, numXTiles(lx) - 1]
238  // dy must lie in the interval [0, numYTiles(ly) - 1]
239  //
240  // lx must lie in the interval [0, numXLevels() - 1]
241  // ly must lie in the interval [0, numYLevels() - 1]
242  //
243  // writeTile(dx, dy, level) is a convenience function
244  // used for ONE_LEVEL and MIPMAP_LEVEL files. It calls
245  // writeTile(dx, dy, level, level).
246  //
247  // The two writeTiles(dx1, dx2, dy1, dy2, ...) functions allow
248  // writing multiple tiles at once. If multi-threading is used
249  // multiple tiles are written concurrently. The tile coordinates,
250  // dx1, dx2 and dy1, dy2, specify inclusive ranges of tile
251  // coordinates. It is valid for dx1 < dx2 or dy1 < dy2; the
252  // tiles are always written in the order specified by the line
253  // order attribute. Hence, it is not possible to specify an
254  // "invalid" or empty tile range.
255  //
256  // Pixels that are outside the pixel coordinate range for the tile's
257  // level, are never accessed by writeTile().
258  //
259  // Each tile in the file must be written exactly once.
260  //
261  // The file's line order attribute determines the order of the tiles
262  // in the file:
263  //
264  // INCREASING_Y In the file, the tiles for each level are stored
265  // in a contiguous block. The levels are ordered
266  // like this:
267  //
268  // (0, 0) (1, 0) ... (nx-1, 0)
269  // (0, 1) (1, 1) ... (nx-1, 1)
270  // ...
271  // (0,ny-1) (1,ny-1) ... (nx-1,ny-1)
272  //
273  // where nx = numXLevels(), and ny = numYLevels().
274  // In an individual level, (lx, ly), the tiles
275  // are stored in the following order:
276  //
277  // (0, 0) (1, 0) ... (tx-1, 0)
278  // (0, 1) (1, 1) ... (tx-1, 1)
279  // ...
280  // (0,ty-1) (1,ty-1) ... (tx-1,ty-1)
281  //
282  // where tx = numXTiles(lx),
283  // and ty = numYTiles(ly).
284  //
285  // DECREASING_Y As for INCREASING_Y, the tiles for each level
286  // are stored in a contiguous block. The levels
287  // are ordered the same way as for INCREASING_Y,
288  // but within an individual level, the tiles
289  // are stored in this order:
290  //
291  // (0,ty-1) (1,ty-1) ... (tx-1,ty-1)
292  // ...
293  // (0, 1) (1, 1) ... (tx-1, 1)
294  // (0, 0) (1, 0) ... (tx-1, 0)
295  //
296  //
297  // RANDOM_Y The order of the calls to writeTile() determines
298  // the order of the tiles in the file.
299  //
300  //------------------------------------------------------------------
301 
302  IMF_EXPORT
303  void writeTile (int dx, int dy, int l = 0);
304  IMF_EXPORT
305  void writeTile (int dx, int dy, int lx, int ly);
306 
307  IMF_EXPORT
308  void writeTiles (int dx1, int dx2, int dy1, int dy2, int lx, int ly);
309 
310  IMF_EXPORT
311  void writeTiles (int dx1, int dx2, int dy1, int dy2, int l = 0);
312 
313  //------------------------------------------------------------------
314  // Shortcut to copy all pixels from a TiledInputFile into this file,
315  // without uncompressing and then recompressing the pixel data.
316  // This file's header must be compatible with the TiledInputFile's
317  // header: The two header's "dataWindow", "compression",
318  // "lineOrder", "channels", and "tiles" attributes must be the same.
319  //------------------------------------------------------------------
320 
321  IMF_EXPORT
322  void copyPixels (DeepTiledInputFile& in);
323  IMF_EXPORT
324  void copyPixels (DeepTiledInputPart& in);
325 
326  //--------------------------------------------------------------
327  // Updating the preview image:
328  //
329  // updatePreviewImage() supplies a new set of pixels for the
330  // preview image attribute in the file's header. If the header
331  // does not contain a preview image, updatePreviewImage() throws
332  // an IEX_NAMESPACE::LogicExc.
333  //
334  // Note: updatePreviewImage() is necessary because images are
335  // often stored in a file incrementally, a few tiles at a time,
336  // while the image is being generated. Since the preview image
337  // is an attribute in the file's header, it gets stored in the
338  // file as soon as the file is opened, but we may not know what
339  // the preview image should look like until we have written the
340  // last tile of the main image.
341  //
342  //--------------------------------------------------------------
343 
344  IMF_EXPORT
345  void updatePreviewImage (const PreviewRgba newPixels[]);
346 
347  //-------------------------------------------------------------
348  // Break a tile -- for testing and debugging only:
349  //
350  // breakTile(dx,dy,lx,ly,p,n,c) introduces an error into the
351  // output file by writing n copies of character c, starting
352  // p bytes from the beginning of the tile with tile coordinates
353  // (dx, dy) and level number (lx, ly).
354  //
355  // Warning: Calling this function usually results in a broken
356  // image file. The file or parts of it may not be readable,
357  // or the file may contain bad data.
358  //
359  //-------------------------------------------------------------
360 
361  IMF_EXPORT
362  void
363  breakTile (int dx, int dy, int lx, int ly, int offset, int length, char c);
364 
365 private:
366  DeepTiledOutputFile* file;
367 };
368 
370 
371 #endif /* IMFDEEPTILEDOUTPUTPART_H_ */
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:83
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
enum IMF_EXPORT_ENUM LevelRoundingMode
class IMF_EXPORT_TYPE DeepTiledOutputPart
Definition: ImfForward.h:63
GLintptr offset
Definition: glcorearb.h:665
Box< V2i > Box2i
2D box of base type int.
Definition: ImathBox.h:143
#define IMF_EXPORT
Definition: ImfExport.h:54
#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