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