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

Revision 855, 12.7 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#ifndef INCLUDED_IMF_TILED_RGBA_FILE_H
37#define INCLUDED_IMF_TILED_RGBA_FILE_H
38
39//-----------------------------------------------------------------------------
40//
41//      Simplified RGBA image I/O for tiled files
42//
43//      class TiledRgbaOutputFile
44//      class TiledRgbaInputFile
45//
46//-----------------------------------------------------------------------------
47
48#include <ImfHeader.h>
49#include <ImfFrameBuffer.h>
50#include <ImathVec.h>
51#include <ImathBox.h>
52#include <half.h>
53#include <ImfTileDescription.h>
54#include <ImfRgba.h>
55
56namespace Imf {
57
58class TiledOutputFile;
59class TiledInputFile;
60struct PreviewRgba;
61
62
63//
64// Tiled RGBA output file.
65//
66
67class TiledRgbaOutputFile
68{
69  public:
70
71    //---------------------------------------------------
72    // Constructor -- rgbaChannels, tileXSize, tileYSize,
73    // levelMode, and levelRoundingMode overwrite the
74    // channel list and tile description attribute in the
75    // header that is passed as an argument to the
76    // constructor.
77    //---------------------------------------------------
78
79    TiledRgbaOutputFile (const char name[],
80                         const Header &header,
81                         RgbaChannels rgbaChannels,
82                         int tileXSize,
83                         int tileYSize,
84                         LevelMode mode,
85                         LevelRoundingMode rmode = ROUND_DOWN);
86
87
88    //---------------------------------------------------
89    // Constructor -- like the previous one, but the new
90    // TiledRgbaOutputFile is attached to a file that has
91    // already been opened by the caller.  Destroying
92    // TiledRgbaOutputFileObjects constructed with this
93    // constructor does not automatically close the
94    // corresponding files.
95    //---------------------------------------------------
96
97    TiledRgbaOutputFile (OStream &os,
98                         const Header &header,
99                         RgbaChannels rgbaChannels,
100                         int tileXSize,
101                         int tileYSize,
102                         LevelMode mode,
103                         LevelRoundingMode rmode = ROUND_DOWN);
104
105
106    //------------------------------------------------------
107    // Constructor -- header data are explicitly specified
108    // as function call arguments (an empty dataWindow means
109    // "same as displayWindow")
110    //------------------------------------------------------
111
112    TiledRgbaOutputFile (const char name[],
113                         int tileXSize,
114                         int tileYSize,
115                         LevelMode mode,
116                         LevelRoundingMode rmode,
117                         const Imath::Box2i &displayWindow,
118                         const Imath::Box2i &dataWindow = Imath::Box2i(),
119                         RgbaChannels rgbaChannels = WRITE_RGBA,
120                         float pixelAspectRatio = 1,
121                         const Imath::V2f screenWindowCenter =
122                                                    Imath::V2f (0, 0),
123                         float screenWindowWidth = 1,
124                         LineOrder lineOrder = INCREASING_Y,
125                         Compression compression = ZIP_COMPRESSION);
126
127
128    //-----------------------------------------------
129    // Constructor -- like the previous one, but both
130    // the display window and the data window are
131    // Box2i (V2i (0, 0), V2i (width - 1, height -1))
132    //-----------------------------------------------
133
134    TiledRgbaOutputFile (const char name[],
135                         int width,
136                         int height,
137                         int tileXSize,
138                         int tileYSize,
139                         LevelMode mode,
140                         LevelRoundingMode rmode = ROUND_DOWN,
141                         RgbaChannels rgbaChannels = WRITE_RGBA,
142                         float pixelAspectRatio = 1,
143                         const Imath::V2f screenWindowCenter =
144                                                    Imath::V2f (0, 0),
145                         float screenWindowWidth = 1,
146                         LineOrder lineOrder = INCREASING_Y,
147                         Compression compression = ZIP_COMPRESSION);
148
149
150    virtual ~TiledRgbaOutputFile ();
151
152
153    //------------------------------------------------
154    // Define a frame buffer as the pixel data source:
155    // Pixel (x, y) is at address
156    //
157    //  base + x * xStride + y * yStride
158    //
159    //------------------------------------------------
160
161    void                setFrameBuffer (const Rgba *base,
162                                        size_t xStride,
163                                        size_t yStride);
164
165    //--------------------------
166    // Access to the file header
167    //--------------------------
168
169    const Header &              header () const;
170    const FrameBuffer &         frameBuffer () const;
171    const Imath::Box2i &        displayWindow () const;
172    const Imath::Box2i &        dataWindow () const;
173    float                       pixelAspectRatio () const;
174    const Imath::V2f            screenWindowCenter () const;
175    float                       screenWindowWidth () const;
176    LineOrder                   lineOrder () const;
177    Compression                 compression () const;
178    RgbaChannels                channels () const;
179
180
181    //----------------------------------------------------
182    // Utility functions (same as in Imf::TiledOutputFile)
183    //----------------------------------------------------
184
185    unsigned int        tileXSize () const;
186    unsigned int        tileYSize () const;
187    LevelMode           levelMode () const;
188    LevelRoundingMode   levelRoundingMode () const;
189
190    int                 numLevels () const;
191    int                 numXLevels () const;
192    int                 numYLevels () const;
193    bool                isValidLevel (int lx, int ly) const;
194
195    int                 levelWidth  (int lx) const;
196    int                 levelHeight (int ly) const;
197
198    int                 numXTiles (int lx = 0) const;
199    int                 numYTiles (int ly = 0) const;
200
201    Imath::Box2i        dataWindowForLevel (int l = 0) const;
202    Imath::Box2i        dataWindowForLevel (int lx, int ly) const;
203
204    Imath::Box2i        dataWindowForTile (int dx, int dy,
205                                           int l = 0) const;
206
207    Imath::Box2i        dataWindowForTile (int dx, int dy,
208                                           int lx, int ly) const;
209
210    //------------------------------------------------------------------
211    // Write pixel data:
212    //
213    // writeTile(dx, dy, lx, ly) writes the tile with tile
214    // coordinates (dx, dy), and level number (lx, ly) to
215    // the file.
216    //
217    //   dx must lie in the interval [0, numXTiles(lx)-1]
218    //   dy must lie in the interval [0, numYTiles(ly)-1]
219    //
220    //   lx must lie in the interval [0, numXLevels()-1]
221    //   ly must lie in the inverval [0, numYLevels()-1]
222    //
223    // writeTile(dx, dy, level) is a convenience function
224    // used for ONE_LEVEL and MIPMAP_LEVEL files.  It calls
225    // writeTile(dx, dy, level, level).
226    //
227    // Pixels that are outside the pixel coordinate range for the tile's
228    // level, are never accessed by writeTile().
229    //
230    // Each tile in the file must be written exactly once.
231    //
232    //------------------------------------------------------------------
233
234    void                        writeTile (int dx, int dy, int l = 0);
235    void                        writeTile (int dx, int dy, int lx, int ly);
236
237
238    // -------------------------------------------------------------------------
239    // Update the preview image (see Imf::TiledOutputFile::updatePreviewImage())
240    // -------------------------------------------------------------------------
241
242    void                        updatePreviewImage (const PreviewRgba[]);
243
244  private:
245
246    //
247    // Copy constructor and assignment are not implemented
248    //
249
250    TiledRgbaOutputFile (const TiledRgbaOutputFile &); 
251    TiledRgbaOutputFile & operator = (const TiledRgbaOutputFile &);
252
253    class ToYa;
254
255    TiledOutputFile *            _outputFile;
256    ToYa *                      _toYa;
257};
258
259
260
261//
262// Tiled RGBA input file
263//
264
265class TiledRgbaInputFile
266{
267  public:
268
269    //--------------------------------------------------------
270    // Constructor -- opens the file with the specified name.
271    // Destroying TiledRgbaInputFile objects constructed with
272    // this constructor automatically closes the corresponding
273    // files.
274    //--------------------------------------------------------
275
276    TiledRgbaInputFile (const char name[]);
277
278
279    //-------------------------------------------------------
280    // Constructor -- attaches the new TiledRgbaInputFile
281    // object to a file that has already been opened by the
282    // caller.
283    // Destroying TiledRgbaInputFile objects constructed with
284    // this constructor does not automatically close the
285    // corresponding files.
286    //-------------------------------------------------------
287
288    TiledRgbaInputFile (IStream &is);
289
290
291    //-----------
292    // Destructor
293    //-----------
294
295    virtual ~TiledRgbaInputFile ();
296
297
298    //-----------------------------------------------------
299    // Define a frame buffer as the pixel data destination:
300    // Pixel (x, y) is at address
301    //
302    //  base + x * xStride + y * yStride
303    //
304    //-----------------------------------------------------
305
306    void                        setFrameBuffer (Rgba *base,
307                                                size_t xStride,
308                                                size_t yStride);
309
310    //--------------------------
311    // Access to the file header
312    //--------------------------
313
314    const Header &              header () const;
315    const FrameBuffer &         frameBuffer () const;
316    const Imath::Box2i &        displayWindow () const;
317    const Imath::Box2i &        dataWindow () const;
318    float                       pixelAspectRatio () const;
319    const Imath::V2f            screenWindowCenter () const;
320    float                       screenWindowWidth () const;
321    LineOrder                   lineOrder () const;
322    Compression                 compression () const;
323    RgbaChannels                channels () const;
324    const char *                fileName () const;
325    bool                        isComplete () const;
326
327    //----------------------------------
328    // Access to the file format version
329    //----------------------------------
330
331    int                         version () const;
332
333
334    //---------------------------------------------------
335    // Utility functions (same as in Imf::TiledInputFile)
336    //---------------------------------------------------
337
338    unsigned int        tileXSize () const;
339    unsigned int        tileYSize () const;
340    LevelMode           levelMode () const;
341    LevelRoundingMode   levelRoundingMode () const;
342
343    int                 numLevels () const;
344    int                 numXLevels () const;
345    int                 numYLevels () const;
346    bool                isValidLevel (int lx, int ly) const;
347
348    int                 levelWidth  (int lx) const;
349    int                 levelHeight (int ly) const;
350
351    int                 numXTiles (int lx = 0) const;
352    int                 numYTiles (int ly = 0) const;
353
354    Imath::Box2i        dataWindowForLevel (int l = 0) const;
355    Imath::Box2i        dataWindowForLevel (int lx, int ly) const;
356
357    Imath::Box2i        dataWindowForTile (int dx, int dy,
358                                           int l = 0) const;
359
360    Imath::Box2i        dataWindowForTile (int dx, int dy,
361                                           int lx, int ly) const;
362                                           
363
364    //----------------------------------------------------------------
365    // Read pixel data:
366    //
367    // readTile(dx, dy, lx, ly) reads the tile with tile
368    // coordinates (dx, dy), and level number (lx, ly),
369    // and stores it in the current frame buffer.
370    //
371    //   dx must lie in the interval [0, numXTiles(lx)-1]
372    //   dy must lie in the interval [0, numYTiles(ly)-1]
373    //
374    //   lx must lie in the interval [0, numXLevels()-1]
375    //   ly must lie in the inverval [0, numYLevels()-1]
376    //
377    // readTile(dx, dy, level) is a convenience function used
378    // for ONE_LEVEL and MIPMAP_LEVELS files.  It calls
379    // readTile(dx, dy, level, level).
380    //
381    // Pixels that are outside the pixel coordinate range for the
382    // tile's level, are never accessed by readTile().
383    //
384    // Attempting to access a tile that is not present in the file
385    // throws an InputExc exception.
386    //
387    //----------------------------------------------------------------
388
389    void                 readTile (int dx, int dy, int l = 0);
390    void                 readTile (int dx, int dy, int lx, int ly);
391
392  private:
393
394    //
395    // Copy constructor and assignment are not implemented
396    //
397
398    TiledRgbaInputFile (const TiledRgbaInputFile &);
399    TiledRgbaInputFile & operator = (const TiledRgbaInputFile &);
400
401    class FromYa;
402
403    TiledInputFile *    _inputFile;
404    FromYa *            _fromYa;
405};
406
407
408} // namespace Imf
409
410#endif
Note: See TracBrowser for help on using the repository browser.