1 ///////////////////////////////////////////////////////////////////////////
3 // Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
6 // All rights reserved.
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
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
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.
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.
33 ///////////////////////////////////////////////////////////////////////////
37 #ifndef INCLUDED_IMF_FRAME_BUFFER_H
38 #define INCLUDED_IMF_FRAME_BUFFER_H
40 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
48 #include <ImfPixelType.h>
55 //-------------------------------------------------------
56 // Description of a single slice of the frame buffer:
58 // Note -- terminology: as part of a file, a component of
59 // an image (e.g. red, green, blue, depth etc.) is called
60 // a "channel". As part of a frame buffer, an image
61 // component is called a "slice".
62 //-------------------------------------------------------
66 //------------------------------
67 // Data type; see ImfPixelType.h
68 //------------------------------
73 //---------------------------------------------------------------------
74 // Memory layout: The address of pixel (x, y) is
76 // base + (xp / xSampling) * xStride + (yp / ySampling) * yStride
78 // where xp and yp are computed as follows:
80 // * If we are reading or writing a scanline-based file:
85 // * If we are reading a tile whose upper left coorner is at (xt, yt):
87 // if xTileCoords is true then xp = x - xt, else xp = x
88 // if yTileCoords is true then yp = y - yt, else yp = y
90 //---------------------------------------------------------------------
97 //--------------------------------------------
98 // Subsampling: pixel (x, y) is present in the
101 // x % xSampling == 0 && y % ySampling == 0
103 //--------------------------------------------
109 //----------------------------------------------------------
110 // Default value, used to fill the slice when a file without
111 // a channel that corresponds to this slice is read.
112 //----------------------------------------------------------
117 //-------------------------------------------------------
118 // For tiled files, the xTileCoords and yTileCoords flags
119 // determine whether pixel addressing is performed using
120 // absolute coordinates or coordinates relative to a
121 // tile's upper left corner. (See the comment on base,
122 // xStride and yStride, above.)
124 // For scanline-based files these flags have no effect;
125 // pixel addressing is always done using absolute
127 //-------------------------------------------------------
137 Slice (PixelType type = HALF,
143 double fillValue = 0.0,
144 bool xTileCoords = false,
145 bool yTileCoords = false);
157 void insert (const char name[],
160 //----------------------------------------------------------------
161 // Access to existing slices:
163 // [n] Returns a reference to the slice with name n.
164 // If no slice with name n exists, an Iex::ArgExc
167 // findSlice(n) Returns a pointer to the slice with name n,
168 // or 0 if no slice with name n exists.
170 //----------------------------------------------------------------
172 Slice & operator [] (const char name[]);
173 const Slice & operator [] (const char name[]) const;
175 Slice * findSlice (const char name[]);
176 const Slice * findSlice (const char name[]) const;
179 //-----------------------------------------
180 // Iterator-style access to existing slices
181 //-----------------------------------------
183 typedef std::map <Name, Slice> SliceMap;
189 ConstIterator begin () const;
191 ConstIterator end () const;
192 Iterator find (const char name[]);
193 ConstIterator find (const char name[]) const;
205 class FrameBuffer::Iterator
210 Iterator (const FrameBuffer::SliceMap::iterator &i);
212 Iterator & operator ++ ();
213 Iterator operator ++ (int);
215 const char * name () const;
216 Slice & slice () const;
220 friend class FrameBuffer::ConstIterator;
222 FrameBuffer::SliceMap::iterator _i;
226 class FrameBuffer::ConstIterator
231 ConstIterator (const FrameBuffer::SliceMap::const_iterator &i);
232 ConstIterator (const FrameBuffer::Iterator &other);
234 ConstIterator & operator ++ ();
235 ConstIterator operator ++ (int);
237 const char * name () const;
238 const Slice & slice () const;
242 friend bool operator == (const ConstIterator &, const ConstIterator &);
243 friend bool operator != (const ConstIterator &, const ConstIterator &);
245 FrameBuffer::SliceMap::const_iterator _i;
254 FrameBuffer::Iterator::Iterator (): _i()
261 FrameBuffer::Iterator::Iterator (const FrameBuffer::SliceMap::iterator &i):
268 inline FrameBuffer::Iterator &
269 FrameBuffer::Iterator::operator ++ ()
276 inline FrameBuffer::Iterator
277 FrameBuffer::Iterator::operator ++ (int)
279 Iterator tmp = *this;
286 FrameBuffer::Iterator::name () const
293 FrameBuffer::Iterator::slice () const
300 FrameBuffer::ConstIterator::ConstIterator (): _i()
306 FrameBuffer::ConstIterator::ConstIterator
307 (const FrameBuffer::SliceMap::const_iterator &i): _i (i)
314 FrameBuffer::ConstIterator::ConstIterator (const FrameBuffer::Iterator &other):
320 inline FrameBuffer::ConstIterator &
321 FrameBuffer::ConstIterator::operator ++ ()
328 inline FrameBuffer::ConstIterator
329 FrameBuffer::ConstIterator::operator ++ (int)
331 ConstIterator tmp = *this;
338 FrameBuffer::ConstIterator::name () const
344 FrameBuffer::ConstIterator::slice () const
351 operator == (const FrameBuffer::ConstIterator &x,
352 const FrameBuffer::ConstIterator &y)
359 operator != (const FrameBuffer::ConstIterator &x,
360 const FrameBuffer::ConstIterator &y)