HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImfRgbaFile.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2004, 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_RGBA_FILE_H
38 #define INCLUDED_IMF_RGBA_FILE_H
39 
40 
41 //-----------------------------------------------------------------------------
42 //
43 // Simplified RGBA image I/O
44 //
45 // class RgbaOutputFile
46 // class RgbaInputFile
47 //
48 //-----------------------------------------------------------------------------
49 
50 #include "ImfHeader.h"
51 #include "ImfFrameBuffer.h"
52 #include "ImfRgba.h"
53 #include "ImathVec.h"
54 #include "ImathBox.h"
55 #include "half.h"
56 #include "ImfThreading.h"
57 #include <string>
58 #include "ImfNamespace.h"
59 #include "ImfForward.h"
60 
62 
63 
64 //
65 // RGBA output file.
66 //
67 
69 {
70  public:
71 
72  //---------------------------------------------------
73  // Constructor -- header is constructed by the caller
74  //---------------------------------------------------
75 
76  RgbaOutputFile (const char name[],
77  const Header &header,
78  RgbaChannels rgbaChannels = WRITE_RGBA,
79  int numThreads = globalThreadCount());
80 
81 
82  //----------------------------------------------------
83  // Constructor -- header is constructed by the caller,
84  // file is opened by the caller, destructor will not
85  // automatically close the file.
86  //----------------------------------------------------
87 
88  RgbaOutputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &os,
89  const Header &header,
90  RgbaChannels rgbaChannels = WRITE_RGBA,
91  int numThreads = globalThreadCount());
92 
93 
94  //----------------------------------------------------------------
95  // Constructor -- header data are explicitly specified as function
96  // call arguments (empty dataWindow means "same as displayWindow")
97  //----------------------------------------------------------------
98 
99  RgbaOutputFile (const char name[],
100  const IMATH_NAMESPACE::Box2i &displayWindow,
101  const IMATH_NAMESPACE::Box2i &dataWindow = IMATH_NAMESPACE::Box2i(),
102  RgbaChannels rgbaChannels = WRITE_RGBA,
103  float pixelAspectRatio = 1,
104  const IMATH_NAMESPACE::V2f screenWindowCenter = IMATH_NAMESPACE::V2f (0, 0),
105  float screenWindowWidth = 1,
106  LineOrder lineOrder = INCREASING_Y,
107  Compression compression = PIZ_COMPRESSION,
108  int numThreads = globalThreadCount());
109 
110 
111  //-----------------------------------------------
112  // Constructor -- like the previous one, but both
113  // the display window and the data window are
114  // Box2i (V2i (0, 0), V2i (width - 1, height -1))
115  //-----------------------------------------------
116 
117  RgbaOutputFile (const char name[],
118  int width,
119  int height,
120  RgbaChannels rgbaChannels = WRITE_RGBA,
121  float pixelAspectRatio = 1,
122  const IMATH_NAMESPACE::V2f screenWindowCenter = IMATH_NAMESPACE::V2f (0, 0),
123  float screenWindowWidth = 1,
124  LineOrder lineOrder = INCREASING_Y,
125  Compression compression = PIZ_COMPRESSION,
126  int numThreads = globalThreadCount());
127 
128 
129  //-----------
130  // Destructor
131  //-----------
132 
133  virtual ~RgbaOutputFile ();
134 
135 
136  //------------------------------------------------
137  // Define a frame buffer as the pixel data source:
138  // Pixel (x, y) is at address
139  //
140  // base + x * xStride + y * yStride
141  //
142  //------------------------------------------------
143 
144  void setFrameBuffer (const Rgba *base,
145  size_t xStride,
146  size_t yStride);
147 
148 
149  //---------------------------------------------
150  // Write pixel data (see class Imf::OutputFile)
151  //---------------------------------------------
152 
153  void writePixels (int numScanLines = 1);
154  int currentScanLine () const;
155 
156 
157  //--------------------------
158  // Access to the file header
159  //--------------------------
160 
161  const Header & header () const;
162  const FrameBuffer & frameBuffer () const;
163  const IMATH_NAMESPACE::Box2i & displayWindow () const;
164  const IMATH_NAMESPACE::Box2i & dataWindow () const;
165  float pixelAspectRatio () const;
166  const IMATH_NAMESPACE::V2f screenWindowCenter () const;
167  float screenWindowWidth () const;
168  LineOrder lineOrder () const;
169  Compression compression () const;
170  RgbaChannels channels () const;
171 
172 
173  // --------------------------------------------------------------------
174  // Update the preview image (see Imf::OutputFile::updatePreviewImage())
175  // --------------------------------------------------------------------
176 
177  void updatePreviewImage (const PreviewRgba[]);
178 
179 
180  //-----------------------------------------------------------------------
181  // Rounding control for luminance/chroma images:
182  //
183  // If the output file contains luminance and chroma channels (WRITE_YC
184  // or WRITE_YCA), then the the significands of the luminance and
185  // chroma values are rounded to roundY and roundC bits respectively (see
186  // function half::round()). Rounding improves compression with minimal
187  // image degradation, usually much less than the degradation caused by
188  // chroma subsampling. By default, roundY is 7, and roundC is 5.
189  //
190  // If the output file contains RGB channels or a luminance channel,
191  // without chroma, then no rounding is performed.
192  //-----------------------------------------------------------------------
193 
194  void setYCRounding (unsigned int roundY,
195  unsigned int roundC);
196 
197 
198  //----------------------------------------------------
199  // Break a scan line -- for testing and debugging only
200  // (see Imf::OutputFile::updatePreviewImage()
201  //
202  // Warning: Calling this function usually results in a
203  // broken image file. The file or parts of it may not
204  // be readable, or the file may contain bad data.
205  //
206  //----------------------------------------------------
207 
208  void breakScanLine (int y,
209  int offset,
210  int length,
211  char c);
212  private:
213 
214  RgbaOutputFile (const RgbaOutputFile &); // not implemented
215  RgbaOutputFile & operator = (const RgbaOutputFile &); // not implemented
216 
217  class ToYca;
218 
219  OutputFile * _outputFile;
220  ToYca * _toYca;
221 };
222 
223 
224 //
225 // RGBA input file
226 //
227 
229 {
230  public:
231 
232  //-------------------------------------------------------
233  // Constructor -- opens the file with the specified name,
234  // destructor will automatically close the file.
235  //-------------------------------------------------------
236 
237  RgbaInputFile (const char name[], int numThreads = globalThreadCount());
238 
239 
240  //-----------------------------------------------------------
241  // Constructor -- attaches the new RgbaInputFile object to a
242  // file that has already been opened by the caller.
243  // Destroying the RgbaInputFile object will not automatically
244  // close the file.
245  //-----------------------------------------------------------
246 
247  RgbaInputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, int numThreads = globalThreadCount());
248 
249 
250  //--------------------------------------------------------------
251  // Constructors -- the same as the previous two, but the names
252  // of the red, green, blue, alpha, luminance and chroma channels
253  // are expected to be layerName.R, layerName.G, etc.
254  //--------------------------------------------------------------
255 
256  RgbaInputFile (const char name[],
257  const std::string &layerName,
258  int numThreads = globalThreadCount());
259 
260  RgbaInputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is,
261  const std::string &layerName,
262  int numThreads = globalThreadCount());
263 
264 
265  //-----------
266  // Destructor
267  //-----------
268 
269  virtual ~RgbaInputFile ();
270 
271 
272  //-----------------------------------------------------
273  // Define a frame buffer as the pixel data destination:
274  // Pixel (x, y) is at address
275  //
276  // base + x * xStride + y * yStride
277  //
278  //-----------------------------------------------------
279 
280  void setFrameBuffer (Rgba *base,
281  size_t xStride,
282  size_t yStride);
283 
284 
285  //----------------------------------------------------------------
286  // Switch to a different layer -- subsequent calls to readPixels()
287  // will read channels layerName.R, layerName.G, etc.
288  // After each call to setLayerName(), setFrameBuffer() must be
289  // called at least once before the next call to readPixels().
290  //----------------------------------------------------------------
291 
292  void setLayerName (const std::string &layerName);
293 
294 
295  //-------------------------------------------
296  // Read pixel data (see class Imf::InputFile)
297  //-------------------------------------------
298 
299  void readPixels (int scanLine1, int scanLine2);
300  void readPixels (int scanLine);
301 
302 
303  //--------------------------
304  // Access to the file header
305  //--------------------------
306 
307  const Header & header () const;
308  const FrameBuffer & frameBuffer () const;
309  const IMATH_NAMESPACE::Box2i & displayWindow () const;
310  const IMATH_NAMESPACE::Box2i & dataWindow () const;
311  float pixelAspectRatio () const;
312  const IMATH_NAMESPACE::V2f screenWindowCenter () const;
313  float screenWindowWidth () const;
314  LineOrder lineOrder () const;
315  Compression compression () const;
316  RgbaChannels channels () const;
317  const char * fileName () const;
318  bool isComplete () const;
319 
320 
321  //----------------------------------
322  // Access to the file format version
323  //----------------------------------
324 
325  int version () const;
326 
327  private:
328 
329  RgbaInputFile (const RgbaInputFile &); // not implemented
330  RgbaInputFile & operator = (const RgbaInputFile &); // not implemented
331 
332  class FromYca;
333 
334  InputFile * _inputFile;
335  FromYca * _fromYca;
336  std::string _channelNamePrefix;
337 };
338 
339 
341 
342 
343 
344 
345 
346 #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
GLint y
Definition: glcorearb.h:102
RgbaChannels
Definition: ImfRgba.h:81
GLint GLsizei width
Definition: glcorearb.h:102
Box< V2i > Box2i
Definition: ImathBox.h:133
GLintptr offset
Definition: glcorearb.h:664
#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
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:794