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 //
3 // Copyright (c) 2011, Industrial Light & Magic, a division of Lucas
4 // Digital Ltd. LLC
5 //
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
10 // met:
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
16 // distribution.
17 // * Neither the name of Industrial Light & Magic nor the names of
18 // its contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
33 ///////////////////////////////////////////////////////////////////////////
34 
35 
36 #ifndef IMFDEEPTILEDINPUTPART_H_
37 #define IMFDEEPTILEDINPUTPART_H_
38 
39 #include "ImfDeepTiledInputFile.h"
40 #include "ImfNamespace.h"
41 #include "ImfForward.h"
42 #include "ImfExport.h"
43 
45 
47 {
48  public:
49 
51  DeepTiledInputPart(MultiPartInputFile& multiPartFile, int partNumber);
52 
53  //------------------------
54  // Access to the file name
55  //------------------------
56 
58  const char * fileName () const;
59 
60 
61  //--------------------------
62  // Access to the file header
63  //--------------------------
64 
66  const Header & header () const;
67 
68 
69  //----------------------------------
70  // Access to the file format version
71  //----------------------------------
72 
74  int version () const;
75 
76 
77  //-----------------------------------------------------------
78  // Set the current frame buffer -- copies the FrameBuffer
79  // object into the TiledInputFile object.
80  //
81  // The current frame buffer is the destination for the pixel
82  // data read from the file. The current frame buffer must be
83  // set at least once before readTile() is called.
84  // The current frame buffer can be changed after each call
85  // to readTile().
86  //-----------------------------------------------------------
87 
90 
91 
92  //-----------------------------------
93  // Access to the current frame buffer
94  //-----------------------------------
95 
97  const DeepFrameBuffer & frameBuffer () const;
98 
99 
100  //------------------------------------------------------------
101  // Check if the file is complete:
102  //
103  // isComplete() returns true if all pixels in the data window
104  // (in all levels) are present in the input file, or false if
105  // any pixels are missing. (Another program may still be busy
106  // writing the file, or file writing may have been aborted
107  // prematurely.)
108  //------------------------------------------------------------
109 
110  IMF_EXPORT
111  bool isComplete () const;
112 
113 
114  //--------------------------------------------------
115  // Utility functions:
116  //--------------------------------------------------
117 
118  //---------------------------------------------------------
119  // Multiresolution mode and tile size:
120  // The following functions return the xSize, ySize and mode
121  // fields of the file header's TileDescriptionAttribute.
122  //---------------------------------------------------------
123 
124  IMF_EXPORT
125  unsigned int tileXSize () const;
126  IMF_EXPORT
127  unsigned int tileYSize () const;
128  IMF_EXPORT
129  LevelMode levelMode () const;
130  IMF_EXPORT
132 
133 
134  //--------------------------------------------------------------------
135  // Number of levels:
136  //
137  // numXLevels() returns the file's number of levels in x direction.
138  //
139  // if levelMode() == ONE_LEVEL:
140  // return value is: 1
141  //
142  // if levelMode() == MIPMAP_LEVELS:
143  // return value is: rfunc (log (max (w, h)) / log (2)) + 1
144  //
145  // if levelMode() == RIPMAP_LEVELS:
146  // return value is: rfunc (log (w) / log (2)) + 1
147  //
148  // where
149  // w is the width of the image's data window, max.x - min.x + 1,
150  // y is the height of the image's data window, max.y - min.y + 1,
151  // and rfunc(x) is either floor(x), or ceil(x), depending on
152  // whether levelRoundingMode() returns ROUND_DOWN or ROUND_UP.
153  //
154  // numYLevels() returns the file's number of levels in y direction.
155  //
156  // if levelMode() == ONE_LEVEL or levelMode() == MIPMAP_LEVELS:
157  // return value is the same as for numXLevels()
158  //
159  // if levelMode() == RIPMAP_LEVELS:
160  // return value is: rfunc (log (h) / log (2)) + 1
161  //
162  //
163  // numLevels() is a convenience function for use with
164  // MIPMAP_LEVELS files.
165  //
166  // if levelMode() == ONE_LEVEL or levelMode() == MIPMAP_LEVELS:
167  // return value is the same as for numXLevels()
168  //
169  // if levelMode() == RIPMAP_LEVELS:
170  // an IEX_NAMESPACE::LogicExc exception is thrown
171  //
172  // isValidLevel(lx, ly) returns true if the file contains
173  // a level with level number (lx, ly), false if not.
174  //
175  //--------------------------------------------------------------------
176 
177  IMF_EXPORT
178  int numLevels () const;
179  IMF_EXPORT
180  int numXLevels () const;
181  IMF_EXPORT
182  int numYLevels () const;
183  IMF_EXPORT
184  bool isValidLevel (int lx, int ly) const;
185 
186 
187  //----------------------------------------------------------
188  // Dimensions of a level:
189  //
190  // levelWidth(lx) returns the width of a level with level
191  // number (lx, *), where * is any number.
192  //
193  // return value is:
194  // max (1, rfunc (w / pow (2, lx)))
195  //
196  //
197  // levelHeight(ly) returns the height of a level with level
198  // number (*, ly), where * is any number.
199  //
200  // return value is:
201  // max (1, rfunc (h / pow (2, ly)))
202  //
203  //----------------------------------------------------------
204 
205  IMF_EXPORT
206  int levelWidth (int lx) const;
207  IMF_EXPORT
208  int levelHeight (int ly) const;
209 
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  //---------------------------------------------------------------
238  // Level pixel ranges:
239  //
240  // dataWindowForLevel(lx, ly) returns a 2-dimensional region of
241  // valid pixel coordinates for a level with level number (lx, ly)
242  //
243  // return value is a Box2i with min value:
244  // (dataWindow.min.x, dataWindow.min.y)
245  //
246  // and max value:
247  // (dataWindow.min.x + levelWidth(lx) - 1,
248  // dataWindow.min.y + levelHeight(ly) - 1)
249  //
250  // dataWindowForLevel(level) is a convenience function used
251  // for ONE_LEVEL and MIPMAP_LEVELS files. It returns
252  // dataWindowForLevel(level, level).
253  //
254  //---------------------------------------------------------------
255 
256  IMF_EXPORT
258  IMF_EXPORT
259  IMATH_NAMESPACE::Box2i dataWindowForLevel (int lx, int ly) const;
260 
261 
262  //-------------------------------------------------------------------
263  // Tile pixel ranges:
264  //
265  // dataWindowForTile(dx, dy, lx, ly) returns a 2-dimensional
266  // region of valid pixel coordinates for a tile with tile coordinates
267  // (dx,dy) and level number (lx, ly).
268  //
269  // return value is a Box2i with min value:
270  // (dataWindow.min.x + dx * tileXSize(),
271  // dataWindow.min.y + dy * tileYSize())
272  //
273  // and max value:
274  // (dataWindow.min.x + (dx + 1) * tileXSize() - 1,
275  // dataWindow.min.y + (dy + 1) * tileYSize() - 1)
276  //
277  // dataWindowForTile(dx, dy, level) is a convenience function
278  // used for ONE_LEVEL and MIPMAP_LEVELS files. It returns
279  // dataWindowForTile(dx, dy, level, level).
280  //
281  //-------------------------------------------------------------------
282 
283  IMF_EXPORT
284  IMATH_NAMESPACE::Box2i dataWindowForTile (int dx, int dy, int l = 0) const;
285 
286  IMF_EXPORT
288  int lx, int ly) const;
289 
290  //------------------------------------------------------------
291  // Read pixel data:
292  //
293  // readTile(dx, dy, lx, ly) reads the tile with tile
294  // coordinates (dx, dy), and level number (lx, ly),
295  // and stores it in the current frame buffer.
296  //
297  // dx must lie in the interval [0, numXTiles(lx)-1]
298  // dy must lie in the interval [0, numYTiles(ly)-1]
299  //
300  // lx must lie in the interval [0, numXLevels()-1]
301  // ly must lie in the inverval [0, numYLevels()-1]
302  //
303  // readTile(dx, dy, level) is a convenience function used
304  // for ONE_LEVEL and MIPMAP_LEVELS files. It calls
305  // readTile(dx, dy, level, level).
306  //
307  // The two readTiles(dx1, dx2, dy1, dy2, ...) functions allow
308  // reading multiple tiles at once. If multi-threading is used
309  // the multiple tiles are read concurrently.
310  //
311  // Pixels that are outside the pixel coordinate range for the
312  // tile's level, are never accessed by readTile().
313  //
314  // Attempting to access a tile that is not present in the file
315  // throws an InputExc exception.
316  //
317  //------------------------------------------------------------
318 
319  IMF_EXPORT
320  void readTile (int dx, int dy, int l = 0);
321  IMF_EXPORT
322  void readTile (int dx, int dy, int lx, int ly);
323 
324  IMF_EXPORT
325  void readTiles (int dx1, int dx2, int dy1, int dy2,
326  int lx, int ly);
327 
328  IMF_EXPORT
329  void readTiles (int dx1, int dx2, int dy1, int dy2,
330  int l = 0);
331 
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 (int &dx, int &dy,
341  int &lx, int &ly,
342  char *data,
343  Int64 &dataSize
344  ) const;
345 
346  //------------------------------------------------------------------
347  // Read pixel sample counts into a slice in the frame buffer.
348  //
349  // readPixelSampleCount(dx, dy, lx, ly) reads the sample counts
350  // for tile (dx, dy) in level (lx, ly).
351  //
352  // readPixelSampleCount(dx, dy, l) calls
353  // readPixelSampleCount(dx, dy, lx = l, ly = l)
354  //
355  // dx must lie in the interval [0, numXTiles(lx)-1]
356  // dy must lie in the interval [0, numYTiles(ly)-1]
357  //
358  // lx must lie in the interval [0, numXLevels()-1]
359  // ly must lie in the inverval [0, numYLevels()-1]
360  //
361  // readPixelSampleCounts(dx1, dx2, dy1, dy2, lx, ly) reads all
362  // the sample counts for tiles within range
363  // [(min(dx1, dx2), min(dy1, dy2))...(max(dx1, dx2), max(dy1, dy2)],
364  // and on level (lx, ly)
365  //
366  // readPixelSampleCounts(dx1, dx2, dy1, dy2, l) calls
367  // readPixelSampleCounts(dx1, dx2, dy1, dy2, lx = l, ly = l).
368  //------------------------------------------------------------------
369 
370  IMF_EXPORT
371  void readPixelSampleCount (int dx, int dy, int l = 0);
372  IMF_EXPORT
373  void readPixelSampleCount (int dx, int dy, int lx, int ly);
374 
375  IMF_EXPORT
376  void readPixelSampleCounts (int dx1, int dx2,
377  int dy1, int dy2,
378  int lx, int ly);
379 
380  IMF_EXPORT
381  void readPixelSampleCounts (int dx1, int dx2,
382  int dy1, int dy2,
383  int l = 0);
384 
385  private:
386  DeepTiledInputFile* file;
387 
388  friend void DeepTiledOutputFile::copyPixels(DeepTiledInputPart &);
389 };
390 
392 
393 
394 #endif /* IMFDEEPTILEDINPUTPART_H_ */
IMF_EXPORT void setFrameBuffer(const DeepFrameBuffer &frameBuffer)
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:109
GLdouble l
Definition: glew.h:9122
IMF_EXPORT void readPixelSampleCount(int dx, int dy, int l=0)
IMF_EXPORT LevelMode levelMode() const
IMF_EXPORT DeepTiledInputPart(MultiPartInputFile &multiPartFile, int partNumber)
IMF_EXPORT int numYTiles(int ly=0) const
IMF_EXPORT int numXLevels() const
IMF_EXPORT unsigned int tileXSize() const
Box< V2i > Box2i
Definition: ImathBox.h:133
IMF_EXPORT IMATH_NAMESPACE::Box2i dataWindowForLevel(int l=0) const
IMF_EXPORT int numLevels() const
IMF_EXPORT int levelHeight(int ly) const
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER typedef long long unsigned int Int64
Definition: ImathInt64.h:58
IMF_EXPORT const DeepFrameBuffer & frameBuffer() const
GLenum GLsizei dataSize
Definition: glew.h:2739
LevelRoundingMode
#define IMF_EXPORT
Definition: ImfExport.h:44
IMF_EXPORT const char * fileName() const
IMF_EXPORT int numYLevels() const
IMF_EXPORT int levelWidth(int lx) const
IMF_EXPORT int version() const
IMF_EXPORT void copyPixels(DeepTiledInputFile &in)
IMF_EXPORT void readTile(int dx, int dy, int l=0)
IMF_EXPORT void rawTileData(int &dx, int &dy, int &lx, int &ly, char *data, Int64 &dataSize) const
IMF_EXPORT void readPixelSampleCounts(int dx1, int dx2, int dy1, int dy2, int lx, int ly)
IMF_EXPORT int numXTiles(int lx=0) const
IMF_EXPORT const Header & header() const
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:108
IMF_EXPORT LevelRoundingMode levelRoundingMode() const
IMF_EXPORT unsigned int tileYSize() const
IMF_EXPORT IMATH_NAMESPACE::Box2i dataWindowForTile(int dx, int dy, int l=0) const
IMF_EXPORT bool isValidLevel(int lx, int ly) const
IMF_EXPORT bool isComplete() const
IMF_EXPORT void readTiles(int dx1, int dx2, int dy1, int dy2, int lx, int ly)