source: NonGTP/OpenEXR/include/IlmImf/ImfRgbaFile.h @ 855

Revision 855, 9.2 KB checked in by igarcia, 18 years ago (diff)
Line 
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
57namespace Imf {
58
59
60class OutputFile;
61class InputFile;
62struct PreviewRgba;
63
64//
65// RGBA output file.
66//
67
68class RgbaOutputFile
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
80
81    //----------------------------------------------------
82    // Constructor -- header is constructed by the caller,
83    // file is opened by the caller, destructor will not
84    // automatically close the file.
85    //----------------------------------------------------
86
87    RgbaOutputFile (OStream &os,
88                    const Header &header,
89                    RgbaChannels rgbaChannels = WRITE_RGBA);
90
91
92    //----------------------------------------------------------------
93    // Constructor -- header data are explicitly specified as function
94    // call arguments (empty dataWindow means "same as displayWindow")
95    //----------------------------------------------------------------
96
97    RgbaOutputFile (const char name[],
98                    const Imath::Box2i &displayWindow,
99                    const Imath::Box2i &dataWindow = Imath::Box2i(),
100                    RgbaChannels rgbaChannels = WRITE_RGBA,
101                    float pixelAspectRatio = 1,
102                    const Imath::V2f screenWindowCenter = Imath::V2f (0, 0),
103                    float screenWindowWidth = 1,
104                    LineOrder lineOrder = INCREASING_Y,
105                    Compression compression = PIZ_COMPRESSION);
106
107
108    //-----------------------------------------------
109    // Constructor -- like the previous one, but both
110    // the display window and the data window are
111    // Box2i (V2i (0, 0), V2i (width - 1, height -1))
112    //-----------------------------------------------
113
114    RgbaOutputFile (const char name[],
115                    int width,
116                    int height,
117                    RgbaChannels rgbaChannels = WRITE_RGBA,
118                    float pixelAspectRatio = 1,
119                    const Imath::V2f screenWindowCenter = Imath::V2f (0, 0),
120                    float screenWindowWidth = 1,
121                    LineOrder lineOrder = INCREASING_Y,
122                    Compression compression = PIZ_COMPRESSION);
123
124
125    //-----------
126    // Destructor
127    //-----------
128
129    virtual ~RgbaOutputFile ();
130
131
132    //------------------------------------------------
133    // Define a frame buffer as the pixel data source:
134    // Pixel (x, y) is at address
135    //
136    //  base + x * xStride + y * yStride
137    //
138    //------------------------------------------------
139
140    void                        setFrameBuffer (const Rgba *base,
141                                                size_t xStride,
142                                                size_t yStride);
143
144
145    //---------------------------------------------
146    // Write pixel data (see class Imf::OutputFile)
147    //---------------------------------------------
148
149    void                        writePixels (int numScanLines = 1);
150    int                         currentScanLine () const;
151
152
153    //--------------------------
154    // Access to the file header
155    //--------------------------
156
157    const Header &              header () const;
158    const FrameBuffer &         frameBuffer () const;
159    const Imath::Box2i &        displayWindow () const;
160    const Imath::Box2i &        dataWindow () const;
161    float                       pixelAspectRatio () const;
162    const Imath::V2f            screenWindowCenter () const;
163    float                       screenWindowWidth () const;
164    LineOrder                   lineOrder () const;
165    Compression                 compression () const;
166    RgbaChannels                channels () const;
167
168
169    // --------------------------------------------------------------------
170    // Update the preview image (see Imf::OutputFile::updatePreviewImage())
171    // --------------------------------------------------------------------
172
173    void                        updatePreviewImage (const PreviewRgba[]);
174
175
176    //-----------------------------------------------------------------------
177    // Rounding control for luminance/chroma images:
178    //
179    // If the output file contains luminance and chroma channels (WRITE_YC
180    // or WRITE_YCA), then the the significands of the luminance and
181    // chroma values are rounded to roundY and roundC bits respectively (see
182    // function half::round()).  Rounding improves compression, with minimal
183    // image degradation, usually much less than the degradation caused by
184    // chroma subsampling.  By default, roundY is 7, and roundC is 5.
185    //
186    // If the output file contains RGB channels or a luminance channel,
187    // without chroma, then no rounding is performed.
188    //-----------------------------------------------------------------------
189
190    void                        setYCRounding (unsigned int roundY,
191                                               unsigned int roundC);
192
193  private:
194
195    RgbaOutputFile (const RgbaOutputFile &);              // not implemented
196    RgbaOutputFile & operator = (const RgbaOutputFile &); // not implemented
197
198    class ToYca;
199
200    OutputFile *                _outputFile;
201    ToYca *                     _toYca;
202};
203
204
205//
206// RGBA input file
207//
208
209class RgbaInputFile
210{
211  public:
212
213    //-------------------------------------------------------
214    // Constructor -- opens the file with the specified name,
215    // destructor will automatically close the file.
216    //-------------------------------------------------------
217
218    RgbaInputFile (const char name[]);
219
220
221    //-----------------------------------------------------------
222    // Constructor -- attaches the new RgbaInputFile object to a
223    // file that has already been opened by the caller.
224    // Destroying the RgbaInputFile object will not automatically
225    // close the file.
226    //-----------------------------------------------------------
227
228    RgbaInputFile (IStream &is);
229
230
231    //-----------
232    // Destructor
233    //-----------
234
235    virtual ~RgbaInputFile ();
236
237    //-----------------------------------------------------
238    // Define a frame buffer as the pixel data destination:
239    // Pixel (x, y) is at address
240    //
241    //  base + x * xStride + y * yStride
242    //
243    //-----------------------------------------------------
244
245    void                        setFrameBuffer (Rgba *base,
246                                                size_t xStride,
247                                                size_t yStride);
248
249
250    //-------------------------------------------
251    // Read pixel data (see class Imf::InputFile)
252    //-------------------------------------------
253
254    void                        readPixels (int scanLine1, int scanLine2);
255    void                        readPixels (int scanLine);
256
257
258    //--------------------------
259    // Access to the file header
260    //--------------------------
261
262    const Header &              header () const;
263    const FrameBuffer &         frameBuffer () const;
264    const Imath::Box2i &        displayWindow () const;
265    const Imath::Box2i &        dataWindow () const;
266    float                       pixelAspectRatio () const;
267    const Imath::V2f            screenWindowCenter () const;
268    float                       screenWindowWidth () const;
269    LineOrder                   lineOrder () const;
270    Compression                 compression () const;
271    RgbaChannels                channels () const;
272    const char *                fileName () const;
273    bool                        isComplete () const;
274
275    //----------------------------------
276    // Access to the file format version
277    //----------------------------------
278
279    int                         version () const;
280
281  private:
282
283    RgbaInputFile (const RgbaInputFile &);                // not implemented
284    RgbaInputFile & operator = (const RgbaInputFile &);   // not implemented
285
286    class FromYca;
287
288    InputFile *                 _inputFile;
289    FromYca *                   _fromYca;
290};
291
292
293} // namespace Imf
294
295#endif
Note: See TracBrowser for help on using the repository browser.