HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImfAcesFile.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 
7 #ifndef INCLUDED_IMF_ACES_FILE_H
8 #define INCLUDED_IMF_ACES_FILE_H
9 
10 
11 //-----------------------------------------------------------------------------
12 //
13 // ACES image file I/O.
14 //
15 // This header file declares two classes that directly support
16 // image file input and output according to the Academy Image
17 // Interchange Framework.
18 //
19 // The Academy Image Interchange file format is a subset of OpenEXR:
20 //
21 // - Images are stored as scanlines. Tiles are not allowed.
22 //
23 // - Images contain three color channels, either
24 // R, G, B (red, green, blue) or
25 // Y, RY, BY (luminance, sub-sampled chroma)
26 //
27 // - Images may optionally contain an alpha channel.
28 //
29 // - Only three compression types are allowed:
30 // - NO_COMPRESSION (file is not compressed)
31 // - PIZ_COMPRESSION (lossless)
32 // - B44A_COMPRESSION (lossy)
33 //
34 // - The "chromaticities" header attribute must specify
35 // the ACES RGB primaries and white point.
36 //
37 // class AcesOutputFile writes an OpenEXR file, enforcing the
38 // restrictions listed above. Pixel data supplied by application
39 // software must already be in the ACES RGB space.
40 //
41 // class AcesInputFile reads an OpenEXR file. Pixel data delivered
42 // to application software is guaranteed to be in the ACES RGB space.
43 // If the RGB space of the file is not the same as the ACES space,
44 // then the pixels are automatically converted: the pixels are
45 // converted to CIE XYZ, a color adaptation transform shifts the
46 // white point, and the result is converted to ACES RGB.
47 //
48 //-----------------------------------------------------------------------------
49 
50 #include "ImfHeader.h"
51 #include "ImfRgba.h"
52 #include "ImathVec.h"
53 #include "ImathBox.h"
54 #include "ImfThreading.h"
55 #include "ImfNamespace.h"
56 #include "ImfExport.h"
57 #include "ImfForward.h"
58 
59 #include <string>
60 
62 
63 
64 //
65 // ACES red, green, blue and white-point chromaticities.
66 //
67 
69 
70 
71 //
72 // ACES output file.
73 //
74 
76 {
77  public:
78 
79  //---------------------------------------------------
80  // Constructor -- header is constructed by the caller
81  //---------------------------------------------------
82 
85  const Header &header,
86  RgbaChannels rgbaChannels = WRITE_RGBA,
87  int numThreads = globalThreadCount());
88 
89 
90  //----------------------------------------------------
91  // Constructor -- header is constructed by the caller,
92  // file is opened by the caller, destructor will not
93  // automatically close the file.
94  //----------------------------------------------------
95 
98  const Header &header,
99  RgbaChannels rgbaChannels = WRITE_RGBA,
100  int numThreads = globalThreadCount());
101 
102 
103  //----------------------------------------------------------------
104  // Constructor -- header data are explicitly specified as function
105  // call arguments (empty dataWindow means "same as displayWindow")
106  //----------------------------------------------------------------
107 
108  IMF_EXPORT
109  AcesOutputFile (const std::string &name,
110  const IMATH_NAMESPACE::Box2i &displayWindow,
111  const IMATH_NAMESPACE::Box2i &dataWindow = IMATH_NAMESPACE::Box2i(),
112  RgbaChannels rgbaChannels = WRITE_RGBA,
113  float pixelAspectRatio = 1,
114  const IMATH_NAMESPACE::V2f screenWindowCenter = IMATH_NAMESPACE::V2f (0, 0),
115  float screenWindowWidth = 1,
116  LineOrder lineOrder = INCREASING_Y,
117  Compression compression = PIZ_COMPRESSION,
118  int numThreads = globalThreadCount());
119 
120 
121  //-----------------------------------------------
122  // Constructor -- like the previous one, but both
123  // the display window and the data window are
124  // Box2i (V2i (0, 0), V2i (width - 1, height -1))
125  //-----------------------------------------------
126 
127  IMF_EXPORT
128  AcesOutputFile (const std::string &name,
129  int width,
130  int height,
131  RgbaChannels rgbaChannels = WRITE_RGBA,
132  float pixelAspectRatio = 1,
133  const IMATH_NAMESPACE::V2f screenWindowCenter = IMATH_NAMESPACE::V2f (0, 0),
134  float screenWindowWidth = 1,
135  LineOrder lineOrder = INCREASING_Y,
136  Compression compression = PIZ_COMPRESSION,
137  int numThreads = globalThreadCount());
138 
139 
140  //-----------
141  // Destructor
142  //-----------
143 
144  IMF_EXPORT
145  virtual ~AcesOutputFile ();
146 
147 
148  //------------------------------------------------
149  // Define a frame buffer as the pixel data source:
150  // Pixel (x, y) is at address
151  //
152  // base + x * xStride + y * yStride
153  //
154  //------------------------------------------------
155 
156  IMF_EXPORT
157  void setFrameBuffer (const Rgba *base,
158  size_t xStride,
159  size_t yStride);
160 
161 
162  //-------------------------------------------------
163  // Write pixel data (see class Imf::OutputFile)
164  // The pixels are assumed to contain ACES RGB data.
165  //-------------------------------------------------
166 
167  IMF_EXPORT
168  void writePixels (int numScanLines = 1);
169  IMF_EXPORT
170  int currentScanLine () const;
171 
172 
173  //--------------------------
174  // Access to the file header
175  //--------------------------
176 
177  IMF_EXPORT
178  const Header & header () const;
179  IMF_EXPORT
180  const IMATH_NAMESPACE::Box2i & displayWindow () const;
181  IMF_EXPORT
182  const IMATH_NAMESPACE::Box2i & dataWindow () const;
183  IMF_EXPORT
184  float pixelAspectRatio () const;
185  IMF_EXPORT
186  const IMATH_NAMESPACE::V2f screenWindowCenter () const;
187  IMF_EXPORT
188  float screenWindowWidth () const;
189  IMF_EXPORT
190  LineOrder lineOrder () const;
191  IMF_EXPORT
192  Compression compression () const;
193  IMF_EXPORT
194  RgbaChannels channels () const;
195 
196 
197  // --------------------------------------------------------------------
198  // Update the preview image (see Imf::OutputFile::updatePreviewImage())
199  // --------------------------------------------------------------------
200 
201  IMF_EXPORT
202  void updatePreviewImage (const PreviewRgba[]);
203 
204 
205  private:
206 
207  AcesOutputFile (const AcesOutputFile &) = delete;
208  AcesOutputFile & operator = (const AcesOutputFile &) = delete;
209  AcesOutputFile (AcesOutputFile &&) = delete;
210  AcesOutputFile & operator = (AcesOutputFile &&) = delete;
211 
212  class IMF_HIDDEN Data;
213 
214  Data * _data;
215 };
216 
217 
218 //
219 // ACES input file
220 //
221 
223 {
224  public:
225 
226  //-------------------------------------------------------
227  // Constructor -- opens the file with the specified name,
228  // destructor will automatically close the file.
229  //-------------------------------------------------------
230 
231  IMF_EXPORT
233  int numThreads = globalThreadCount());
234 
235 
236  //-----------------------------------------------------------
237  // Constructor -- attaches the new AcesInputFile object to a
238  // file that has already been opened by the caller.
239  // Destroying the AcesInputFile object will not automatically
240  // close the file.
241  //-----------------------------------------------------------
242 
243  IMF_EXPORT
245  int numThreads = globalThreadCount());
246 
247 
248  //-----------
249  // Destructor
250  //-----------
251 
252  IMF_EXPORT
253  virtual ~AcesInputFile ();
254 
255 
256  //-----------------------------------------------------
257  // Define a frame buffer as the pixel data destination:
258  // Pixel (x, y) is at address
259  //
260  // base + x * xStride + y * yStride
261  //
262  //-----------------------------------------------------
263 
264  IMF_EXPORT
265  void setFrameBuffer (Rgba *base,
266  size_t xStride,
267  size_t yStride);
268 
269 
270  //--------------------------------------------
271  // Read pixel data (see class Imf::InputFile)
272  // Pixels returned will contain ACES RGB data.
273  //--------------------------------------------
274 
275  IMF_EXPORT
276  void readPixels (int scanLine1, int scanLine2);
277  IMF_EXPORT
278  void readPixels (int scanLine);
279 
280 
281  //--------------------------
282  // Access to the file header
283  //--------------------------
284 
285  IMF_EXPORT
286  const Header & header () const;
287  IMF_EXPORT
288  const IMATH_NAMESPACE::Box2i & displayWindow () const;
289  IMF_EXPORT
290  const IMATH_NAMESPACE::Box2i & dataWindow () const;
291  IMF_EXPORT
292  float pixelAspectRatio () const;
293  IMF_EXPORT
294  const IMATH_NAMESPACE::V2f screenWindowCenter () const;
295  IMF_EXPORT
296  float screenWindowWidth () const;
297  IMF_EXPORT
298  LineOrder lineOrder () const;
299  IMF_EXPORT
300  Compression compression () const;
301  IMF_EXPORT
302  RgbaChannels channels () const;
303  IMF_EXPORT
304  const char * fileName () const;
305  IMF_EXPORT
306  bool isComplete () const;
307 
308 
309  //----------------------------------
310  // Access to the file format version
311  //----------------------------------
312 
313  IMF_EXPORT
314  int version () const;
315 
316  private:
317 
318  AcesInputFile (const AcesInputFile &) = delete;
319  AcesInputFile & operator = (const AcesInputFile &) = delete;
320  AcesInputFile (AcesInputFile &&) = delete;
321  AcesInputFile & operator = (AcesInputFile &&) = delete;
322 
323  class IMF_HIDDEN Data;
324 
325  Data * _data;
326 };
327 
328 
330 
331 
332 
333 
334 #endif
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:80
class IMF_EXPORT_TYPE AcesOutputFile
Definition: ImfForward.h:44
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
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER const Chromaticities & acesChromaticities()
#define IMF_HIDDEN
Definition: ImfExport.h:55
GLint GLsizei GLsizei height
Definition: glcorearb.h:103
PIZ_COMPRESSION
Box< V2i > Box2i
2D box of base type int.
Definition: ImathBox.h:143
class IMF_EXPORT_TYPE AcesInputFile
Definition: ImfForward.h:43
#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
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
INCREASING_Y
Definition: ImfLineOrder.h:23
#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