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