HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImfTiledRgbaFile.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2004, 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 INCLUDED_IMF_TILED_RGBA_FILE_H
37 #define INCLUDED_IMF_TILED_RGBA_FILE_H
38 
39 //-----------------------------------------------------------------------------
40 //
41 // Simplified RGBA image I/O for tiled files
42 //
43 // class TiledRgbaOutputFile
44 // class TiledRgbaInputFile
45 //
46 //-----------------------------------------------------------------------------
47 
48 #include "ImfHeader.h"
49 #include "ImfFrameBuffer.h"
50 #include "ImathVec.h"
51 #include "ImathBox.h"
52 #include "half.h"
53 #include "ImfTileDescription.h"
54 #include "ImfRgba.h"
55 #include "ImfThreading.h"
56 #include <string>
57 #include "ImfNamespace.h"
58 #include "ImfForward.h"
59 
60 
62 
63 
64 //
65 // Tiled RGBA output file.
66 //
67 
69 {
70  public:
71 
72  //---------------------------------------------------
73  // Constructor -- rgbaChannels, tileXSize, tileYSize,
74  // levelMode, and levelRoundingMode overwrite the
75  // channel list and tile description attribute in the
76  // header that is passed as an argument to the
77  // constructor.
78  //---------------------------------------------------
79 
81  TiledRgbaOutputFile (const char name[],
82  const Header &header,
83  RgbaChannels rgbaChannels,
84  int tileXSize,
85  int tileYSize,
88  int numThreads = globalThreadCount ());
89 
90 
91  //---------------------------------------------------
92  // Constructor -- like the previous one, but the new
93  // TiledRgbaOutputFile is attached to a file that has
94  // already been opened by the caller. Destroying
95  // TiledRgbaOutputFileObjects constructed with this
96  // constructor does not automatically close the
97  // corresponding files.
98  //---------------------------------------------------
99 
100  IMF_EXPORT
101  TiledRgbaOutputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &os,
102  const Header &header,
103  RgbaChannels rgbaChannels,
104  int tileXSize,
105  int tileYSize,
106  LevelMode mode,
108  int numThreads = globalThreadCount ());
109 
110 
111  //------------------------------------------------------
112  // Constructor -- header data are explicitly specified
113  // as function call arguments (an empty dataWindow means
114  // "same as displayWindow")
115  //------------------------------------------------------
116 
117  IMF_EXPORT
118  TiledRgbaOutputFile (const char name[],
119  int tileXSize,
120  int tileYSize,
121  LevelMode mode,
122  LevelRoundingMode rmode,
125  RgbaChannels rgbaChannels = WRITE_RGBA,
126  float pixelAspectRatio = 1,
128  IMATH_NAMESPACE::V2f (0, 0),
129  float screenWindowWidth = 1,
132  int numThreads = globalThreadCount ());
133 
134 
135  //-----------------------------------------------
136  // Constructor -- like the previous one, but both
137  // the display window and the data window are
138  // Box2i (V2i (0, 0), V2i (width - 1, height -1))
139  //-----------------------------------------------
140 
141  IMF_EXPORT
142  TiledRgbaOutputFile (const char name[],
143  int width,
144  int height,
145  int tileXSize,
146  int tileYSize,
147  LevelMode mode,
149  RgbaChannels rgbaChannels = WRITE_RGBA,
150  float pixelAspectRatio = 1,
152  IMATH_NAMESPACE::V2f (0, 0),
153  float screenWindowWidth = 1,
156  int numThreads = globalThreadCount ());
157 
158  IMF_EXPORT
159  virtual ~TiledRgbaOutputFile ();
160 
161 
162  //------------------------------------------------
163  // Define a frame buffer as the pixel data source:
164  // Pixel (x, y) is at address
165  //
166  // base + x * xStride + y * yStride
167  //
168  //------------------------------------------------
169 
170  IMF_EXPORT
171  void setFrameBuffer (const Rgba *base,
172  size_t xStride,
173  size_t yStride);
174 
175  //--------------------------
176  // Access to the file header
177  //--------------------------
178 
179  IMF_EXPORT
180  const Header & header () const;
181  IMF_EXPORT
182  const FrameBuffer & frameBuffer () const;
183  IMF_EXPORT
184  const IMATH_NAMESPACE::Box2i & displayWindow () const;
185  IMF_EXPORT
186  const IMATH_NAMESPACE::Box2i & dataWindow () const;
187  IMF_EXPORT
188  float pixelAspectRatio () const;
189  IMF_EXPORT
191  IMF_EXPORT
192  float screenWindowWidth () const;
193  IMF_EXPORT
194  LineOrder lineOrder () const;
195  IMF_EXPORT
196  Compression compression () const;
197  IMF_EXPORT
198  RgbaChannels channels () const;
199 
200 
201  //----------------------------------------------------
202  // Utility functions (same as in Imf::TiledOutputFile)
203  //----------------------------------------------------
204 
205  IMF_EXPORT
206  unsigned int tileXSize () const;
207  IMF_EXPORT
208  unsigned int tileYSize () const;
209  IMF_EXPORT
210  LevelMode levelMode () const;
211  IMF_EXPORT
213 
214  IMF_EXPORT
215  int numLevels () const;
216  IMF_EXPORT
217  int numXLevels () const;
218  IMF_EXPORT
219  int numYLevels () const;
220  IMF_EXPORT
221  bool isValidLevel (int lx, int ly) const;
222 
223  IMF_EXPORT
224  int levelWidth (int lx) const;
225  IMF_EXPORT
226  int levelHeight (int ly) const;
227 
228  IMF_EXPORT
229  int numXTiles (int lx = 0) const;
230  IMF_EXPORT
231  int numYTiles (int ly = 0) const;
232 
233  IMF_EXPORT
235  IMF_EXPORT
236  IMATH_NAMESPACE::Box2i dataWindowForLevel (int lx, int ly) const;
237 
238  IMF_EXPORT
240  int l = 0) const;
241 
242  IMF_EXPORT
244  int lx, int ly) const;
245 
246  //------------------------------------------------------------------
247  // Write pixel data:
248  //
249  // writeTile(dx, dy, lx, ly) writes the tile with tile
250  // coordinates (dx, dy), and level number (lx, ly) to
251  // the file.
252  //
253  // dx must lie in the interval [0, numXTiles(lx)-1]
254  // dy must lie in the interval [0, numYTiles(ly)-1]
255  //
256  // lx must lie in the interval [0, numXLevels()-1]
257  // ly must lie in the inverval [0, numYLevels()-1]
258  //
259  // writeTile(dx, dy, level) is a convenience function
260  // used for ONE_LEVEL and MIPMAP_LEVEL files. It calls
261  // writeTile(dx, dy, level, level).
262  //
263  // The two writeTiles(dx1, dx2, dy1, dy2, ...) functions allow
264  // writing multiple tiles at once. If multi-threading is used
265  // multiple tiles are written concurrently.
266  //
267  // Pixels that are outside the pixel coordinate range for the tile's
268  // level, are never accessed by writeTile().
269  //
270  // Each tile in the file must be written exactly once.
271  //
272  //------------------------------------------------------------------
273 
274  IMF_EXPORT
275  void writeTile (int dx, int dy, int l = 0);
276  IMF_EXPORT
277  void writeTile (int dx, int dy, int lx, int ly);
278 
279  IMF_EXPORT
280  void writeTiles (int dxMin, int dxMax, int dyMin, int dyMax,
281  int lx, int ly);
282 
283  IMF_EXPORT
284  void writeTiles (int dxMin, int dxMax, int dyMin, int dyMax,
285  int l = 0);
286 
287 
288  // -------------------------------------------------------------------------
289  // Update the preview image (see Imf::TiledOutputFile::updatePreviewImage())
290  // -------------------------------------------------------------------------
291 
292  IMF_EXPORT
293  void updatePreviewImage (const PreviewRgba[]);
294 
295 
296  //------------------------------------------------
297  // Break a tile -- for testing and debugging only
298  // (see Imf::TiledOutputFile::breakTile())
299  //
300  // Warning: Calling this function usually results
301  // in a broken image file. The file or parts of
302  // it may not be readable, or the file may contain
303  // bad data.
304  //
305  //------------------------------------------------
306 
307  IMF_EXPORT
308  void breakTile (int dx, int dy,
309  int lx, int ly,
310  int offset,
311  int length,
312  char c);
313  private:
314 
315  //
316  // Copy constructor and assignment are not implemented
317  //
318 
319  TiledRgbaOutputFile (const TiledRgbaOutputFile &);
320  TiledRgbaOutputFile & operator = (const TiledRgbaOutputFile &);
321 
322  class ToYa;
323 
324  TiledOutputFile * _outputFile;
325  ToYa * _toYa;
326 };
327 
328 
329 
330 //
331 // Tiled RGBA input file
332 //
333 
335 {
336  public:
337 
338  //--------------------------------------------------------
339  // Constructor -- opens the file with the specified name.
340  // Destroying TiledRgbaInputFile objects constructed with
341  // this constructor automatically closes the corresponding
342  // files.
343  //--------------------------------------------------------
344 
345  IMF_EXPORT
346  TiledRgbaInputFile (const char name[],
347  int numThreads = globalThreadCount ());
348 
349 
350  //-------------------------------------------------------
351  // Constructor -- attaches the new TiledRgbaInputFile
352  // object to a file that has already been opened by the
353  // caller.
354  // Destroying TiledRgbaInputFile objects constructed with
355  // this constructor does not automatically close the
356  // corresponding files.
357  //-------------------------------------------------------
358 
359  IMF_EXPORT
360  TiledRgbaInputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, int numThreads = globalThreadCount ());
361 
362 
363  //------------------------------------------------------------
364  // Constructors -- the same as the previous two, but the names
365  // of the red, green, blue, alpha, and luminance channels are
366  // expected to be layerName.R, layerName.G, etc.
367  //------------------------------------------------------------
368 
369  IMF_EXPORT
370  TiledRgbaInputFile (const char name[],
371  const std::string &layerName,
372  int numThreads = globalThreadCount());
373 
374  IMF_EXPORT
375  TiledRgbaInputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is,
376  const std::string &layerName,
377  int numThreads = globalThreadCount());
378 
379  //-----------
380  // Destructor
381  //-----------
382 
383  IMF_EXPORT
384  virtual ~TiledRgbaInputFile ();
385 
386 
387  //-----------------------------------------------------
388  // Define a frame buffer as the pixel data destination:
389  // Pixel (x, y) is at address
390  //
391  // base + x * xStride + y * yStride
392  //
393  //-----------------------------------------------------
394 
395  IMF_EXPORT
396  void setFrameBuffer (Rgba *base,
397  size_t xStride,
398  size_t yStride);
399 
400  //-------------------------------------------------------------------
401  // Switch to a different layer -- subsequent calls to readTile()
402  // and readTiles() will read channels layerName.R, layerName.G, etc.
403  // After each call to setLayerName(), setFrameBuffer() must be called
404  // at least once before the next call to readTile() or readTiles().
405  //-------------------------------------------------------------------
406 
407  IMF_EXPORT
408  void setLayerName (const std::string &layerName);
409 
410 
411  //--------------------------
412  // Access to the file header
413  //--------------------------
414 
415  IMF_EXPORT
416  const Header & header () const;
417  IMF_EXPORT
418  const FrameBuffer & frameBuffer () const;
419  IMF_EXPORT
420  const IMATH_NAMESPACE::Box2i & displayWindow () const;
421  IMF_EXPORT
422  const IMATH_NAMESPACE::Box2i & dataWindow () const;
423  IMF_EXPORT
424  float pixelAspectRatio () const;
425  IMF_EXPORT
427  IMF_EXPORT
428  float screenWindowWidth () const;
429  IMF_EXPORT
430  LineOrder lineOrder () const;
431  IMF_EXPORT
432  Compression compression () const;
433  IMF_EXPORT
434  RgbaChannels channels () const;
435  IMF_EXPORT
436  const char * fileName () const;
437  IMF_EXPORT
438  bool isComplete () const;
439 
440  //----------------------------------
441  // Access to the file format version
442  //----------------------------------
443 
444  IMF_EXPORT
445  int version () const;
446 
447 
448  //---------------------------------------------------
449  // Utility functions (same as in Imf::TiledInputFile)
450  //---------------------------------------------------
451 
452  IMF_EXPORT
453  unsigned int tileXSize () const;
454  IMF_EXPORT
455  unsigned int tileYSize () const;
456  IMF_EXPORT
457  LevelMode levelMode () const;
458  IMF_EXPORT
460 
461  IMF_EXPORT
462  int numLevels () const;
463  IMF_EXPORT
464  int numXLevels () const;
465  IMF_EXPORT
466  int numYLevels () const;
467  IMF_EXPORT
468  bool isValidLevel (int lx, int ly) const;
469 
470  IMF_EXPORT
471  int levelWidth (int lx) const;
472  IMF_EXPORT
473  int levelHeight (int ly) const;
474 
475  IMF_EXPORT
476  int numXTiles (int lx = 0) const;
477  IMF_EXPORT
478  int numYTiles (int ly = 0) const;
479 
480  IMF_EXPORT
482  IMF_EXPORT
483  IMATH_NAMESPACE::Box2i dataWindowForLevel (int lx, int ly) const;
484 
485  IMF_EXPORT
487  int l = 0) const;
488 
489  IMF_EXPORT
491  int lx, int ly) const;
492 
493 
494  //----------------------------------------------------------------
495  // Read pixel data:
496  //
497  // readTile(dx, dy, lx, ly) reads the tile with tile
498  // coordinates (dx, dy), and level number (lx, ly),
499  // and stores it in the current frame buffer.
500  //
501  // dx must lie in the interval [0, numXTiles(lx)-1]
502  // dy must lie in the interval [0, numYTiles(ly)-1]
503  //
504  // lx must lie in the interval [0, numXLevels()-1]
505  // ly must lie in the inverval [0, numYLevels()-1]
506  //
507  // readTile(dx, dy, level) is a convenience function used
508  // for ONE_LEVEL and MIPMAP_LEVELS files. It calls
509  // readTile(dx, dy, level, level).
510  //
511  // The two readTiles(dx1, dx2, dy1, dy2, ...) functions allow
512  // reading multiple tiles at once. If multi-threading is used
513  // multiple tiles are read concurrently.
514  //
515  // Pixels that are outside the pixel coordinate range for the
516  // tile's level, are never accessed by readTile().
517  //
518  // Attempting to access a tile that is not present in the file
519  // throws an InputExc exception.
520  //
521  //----------------------------------------------------------------
522 
523  IMF_EXPORT
524  void readTile (int dx, int dy, int l = 0);
525  IMF_EXPORT
526  void readTile (int dx, int dy, int lx, int ly);
527 
528  IMF_EXPORT
529  void readTiles (int dxMin, int dxMax,
530  int dyMin, int dyMax, int lx, int ly);
531 
532  IMF_EXPORT
533  void readTiles (int dxMin, int dxMax,
534  int dyMin, int dyMax, int l = 0);
535 
536  private:
537 
538  //
539  // Copy constructor and assignment are not implemented
540  //
541 
542  TiledRgbaInputFile (const TiledRgbaInputFile &);
543  TiledRgbaInputFile & operator = (const TiledRgbaInputFile &);
544 
545  class FromYa;
546 
547  TiledInputFile * _inputFile;
548  FromYa * _fromYa;
549  std::string _channelNamePrefix;
550 };
551 
552 
554 
555 
556 
557 
558 
559 #endif
IMF_EXPORT const IMATH_NAMESPACE::V2f screenWindowCenter() const
IMF_EXPORT int numLevels() const
LineOrder
Definition: ImfLineOrder.h:50
IMF_EXPORT int levelHeight(int ly) const
IMF_EXPORT float pixelAspectRatio() const
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:109
IMF_EXPORT float pixelAspectRatio() const
IMF_EXPORT void writeTile(int dx, int dy, int l=0)
IMF_EXPORT const Header & header() const
IMF_EXPORT int version() const
IMF_EXPORT const IMATH_NAMESPACE::V2f screenWindowCenter() const
IMF_EXPORT int numYLevels() const
const GLfloat * c
Definition: glew.h:16631
IMF_EXPORT RgbaChannels channels() const
IMF_EXPORT int levelHeight(int ly) const
IMF_EXPORT int numXLevels() const
IMF_EXPORT RgbaChannels channels() const
GLuint const GLchar * name
Definition: glcorearb.h:785
IMF_EXPORT bool isComplete() const
RgbaChannels
Definition: ImfRgba.h:71
IMF_EXPORT int levelWidth(int lx) const
IMF_EXPORT int numYTiles(int ly=0) const
GLdouble l
Definition: glew.h:9164
IMF_EXPORT unsigned int tileXSize() const
IMF_EXPORT void updatePreviewImage(const PreviewRgba[])
IMF_EXPORT const IMATH_NAMESPACE::Box2i & displayWindow() const
IMF_EXPORT LevelMode levelMode() const
IMF_EXPORT TiledRgbaInputFile(const char name[], int numThreads=globalThreadCount())
IMF_EXPORT const FrameBuffer & frameBuffer() const
Box< V2i > Box2i
Definition: ImathBox.h:133
IMF_EXPORT int numYLevels() const
IMF_EXPORT TiledRgbaOutputFile(const char name[], const Header &header, RgbaChannels rgbaChannels, int tileXSize, int tileYSize, LevelMode mode, LevelRoundingMode rmode=ROUND_DOWN, int numThreads=globalThreadCount())
IMF_EXPORT IMATH_NAMESPACE::Box2i dataWindowForTile(int dx, int dy, int l=0) const
IMF_EXPORT int numLevels() const
IMF_EXPORT Compression compression() const
IMF_EXPORT const FrameBuffer & frameBuffer() const
IMF_EXPORT const IMATH_NAMESPACE::Box2i & dataWindow() const
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
IMF_EXPORT Compression compression() const
IMF_EXPORT float screenWindowWidth() const
IMF_EXPORT LevelRoundingMode levelRoundingMode() const
IMF_EXPORT int numXLevels() const
IMF_EXPORT void breakTile(int dx, int dy, int lx, int ly, int offset, int length, char c)
virtual IMF_EXPORT ~TiledRgbaOutputFile()
LevelRoundingMode
#define IMF_EXPORT
Definition: ImfExport.h:44
IMF_EXPORT int levelWidth(int lx) const
IMF_EXPORT void readTiles(int dxMin, int dxMax, int dyMin, int dyMax, int lx, int ly)
IMF_EXPORT const IMATH_NAMESPACE::Box2i & dataWindow() const
IMF_EXPORT float screenWindowWidth() const
GLint GLsizei width
Definition: glcorearb.h:102
GLint GLsizei GLsizei height
Definition: glcorearb.h:102
GLenum mode
Definition: glcorearb.h:98
Vec2< float > V2f
Definition: ImathVec.h:689
IMF_EXPORT unsigned int tileXSize() const
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:794
IMF_EXPORT IMATH_NAMESPACE::Box2i dataWindowForTile(int dx, int dy, int l=0) const
IMF_EXPORT LineOrder lineOrder() const
IMF_EXPORT LevelMode levelMode() const
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER IMF_EXPORT int globalThreadCount()
IMF_EXPORT const char * fileName() const
IMF_EXPORT int numXTiles(int lx=0) const
virtual IMF_EXPORT ~TiledRgbaInputFile()
IMF_EXPORT void setLayerName(const std::string &layerName)
IMF_EXPORT int numYTiles(int ly=0) const
IMF_EXPORT LevelRoundingMode levelRoundingMode() const
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:108
IMF_EXPORT bool isValidLevel(int lx, int ly) const
Definition: ImfRgba.h:55
IMF_EXPORT unsigned int tileYSize() const
IMF_EXPORT void setFrameBuffer(const Rgba *base, size_t xStride, size_t yStride)
IMF_EXPORT int numXTiles(int lx=0) const
IMF_EXPORT bool isValidLevel(int lx, int ly) const
GLintptr offset
Definition: glcorearb.h:664
IMF_EXPORT LineOrder lineOrder() const
IMF_EXPORT const IMATH_NAMESPACE::Box2i & displayWindow() const
IMF_EXPORT const Header & header() const
IMF_EXPORT unsigned int tileYSize() const
IMF_EXPORT void setFrameBuffer(Rgba *base, size_t xStride, size_t yStride)
IMF_EXPORT void writeTiles(int dxMin, int dxMax, int dyMin, int dyMax, int lx, int ly)
IMF_EXPORT IMATH_NAMESPACE::Box2i dataWindowForLevel(int l=0) const
Compression
IMF_EXPORT void readTile(int dx, int dy, int l=0)
IMF_EXPORT IMATH_NAMESPACE::Box2i dataWindowForLevel(int l=0) const