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