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