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

Revision 855, 9.5 KB checked in by igarcia, 19 years ago (diff)
RevLine 
[855]1///////////////////////////////////////////////////////////////////////////
2//
3// Copyright (c) 2002, 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_CHANNEL_LIST_H
38#define INCLUDED_IMF_CHANNEL_LIST_H
39
40//-----------------------------------------------------------------------------
41//
42//      class Channel
43//      class ChannelList
44//
45//-----------------------------------------------------------------------------
46
47#include <ImfName.h>
48#include <ImfPixelType.h>
49#include <map>
50#include <set>
51
52
53namespace Imf {
54
55
56struct Channel
57{
58    //------------------------------
59    // Data type; see ImfPixelType.h
60    //------------------------------
61
62    PixelType           type;
63
64
65    //--------------------------------------------
66    // Subsampling: pixel (x, y) is present in the
67    // channel only if
68    //
69    //  x % xSampling == 0 && y % ySampling == 0
70    //
71    //--------------------------------------------
72
73    int                 xSampling;
74    int                 ySampling;
75
76
77    //------------
78    // Constructor
79    //------------
80   
81    Channel (PixelType type = HALF,
82             int xSampling = 1,
83             int ySampling = 1);
84
85
86    //------------
87    // Operator ==
88    //------------
89
90    bool                operator == (const Channel &other) const;
91};
92
93
94class ChannelList
95{
96  public:
97
98    //--------------
99    // Add a channel
100    //--------------
101
102    void                        insert (const char name[],
103                                        const Channel &channel);
104
105    //------------------------------------------------------------------
106    // Access to existing channels:
107    //
108    // [n]              Returns a reference to the channel with name n.
109    //                  If no channel with name n exists, an Iex::ArgExc
110    //                  is thrown.
111    //
112    // findChannel(n)   Returns a pointer to the channel with name n,
113    //                  or 0 if no channel with name n exists.
114    //
115    //------------------------------------------------------------------
116
117    Channel &                   operator [] (const char name[]);
118    const Channel &             operator [] (const char name[]) const;
119
120    Channel *                   findChannel (const char name[]);
121    const Channel *             findChannel (const char name[]) const;
122
123
124    //-------------------------------------------
125    // Iterator-style access to existing channels
126    //-------------------------------------------
127
128    typedef std::map <Name, Channel> ChannelMap;
129
130    class Iterator;
131    class ConstIterator;
132
133    Iterator                    begin ();
134    ConstIterator               begin () const;
135    Iterator                    end ();
136    ConstIterator               end () const;
137    Iterator                    find (const char name[]);
138    ConstIterator               find (const char name[]) const;
139
140   
141    //-----------------------------------------------------------------
142    // Support for image layers:
143    //
144    // In an image file with many channels it is sometimes useful to
145    // group the channels into "layers", that is, into sets of channels
146    // that logically belong together.  Grouping channels into layers
147    // is done using a naming convention:  channel C in layer L is
148    // called "L.C".
149    //
150    // For example, a computer graphic image may contain separate
151    // R, G and B channels for light that originated at each of
152    // several different virtual light sources.  The channels in
153    // this image might be called "light1.R", "light1.G", "light1.B",
154    // "light2.R", "light2.G", "light2.B", etc.
155    //
156    // Note that this naming convention allows layers to be nested;
157    // for example, "light1.specular.R" identifies the "R" channel
158    // in the "specular" sub-layer of layer "light1".
159    //
160    // Channel names that don't contain a "." or that contain a
161    // "." only at the beginning or at the end are not considered
162    // to be part of any layer.
163    //
164    // layers(lns)              sorts the channels in this ChannelList
165    //                          into layers and stores the names of
166    //                          all layers, sorted alphabetically,
167    //                          into string set lns.
168    //
169    // channelsInLayer(ln,f,l)  stores a pair of iterators in f and l
170    //                          such that the loop
171    //
172    //                          for (ConstIterator i = f; f != l; ++i)
173    //                             ...
174    //
175    //                          iterates over all channels in layer ln.
176    //                          channelsInLayer (ln, l, p) calls
177    //                          channelsWithPrefix (ln + ".", l, p).
178    //
179    //-----------------------------------------------------------------
180
181    void                layers (std::set <std::string> &layerNames) const;
182
183    void                channelsInLayer (const std::string &layerName,
184                                         Iterator &first,
185                                         Iterator &last);
186
187    void                channelsInLayer (const std::string &layerName,
188                                         ConstIterator &first,
189                                         ConstIterator &last) const;
190
191
192    //-------------------------------------------------------------------
193    // Find all channels whose name begins with a given prefix:
194    //
195    // channelsWithPrefix(p,f,l) stores a pair of iterators in f and l
196    // such that the following loop iterates over all channels whose name
197    // begins with string p:
198    //
199    //          for (ConstIterator i = f; f != l; ++i)
200    //              ...
201    //
202    //-------------------------------------------------------------------
203
204    void                        channelsWithPrefix (const char prefix[],
205                                                    Iterator &first,
206                                                    Iterator &last);
207
208    void                        channelsWithPrefix (const char prefix[],
209                                                    ConstIterator &first,
210                                                    ConstIterator &last) const;
211
212    //------------
213    // Operator ==
214    //------------
215
216    bool                        operator == (const ChannelList &other) const;
217
218  private:
219
220    ChannelMap                  _map;
221};
222
223
224//----------
225// Iterators
226//----------
227
228class ChannelList::Iterator
229{
230  public:
231
232    Iterator ();
233    Iterator (const ChannelList::ChannelMap::iterator &i);
234
235    Iterator &                  operator ++ ();
236    Iterator                    operator ++ (int);
237
238    const char *                name () const;
239    Channel &                   channel () const;
240
241  private:
242
243    friend class ChannelList::ConstIterator;
244
245    ChannelList::ChannelMap::iterator _i;
246};
247
248
249class ChannelList::ConstIterator
250{
251  public:
252
253    ConstIterator ();
254    ConstIterator (const ChannelList::ChannelMap::const_iterator &i);
255    ConstIterator (const ChannelList::Iterator &other);
256
257    ConstIterator &             operator ++ ();
258    ConstIterator               operator ++ (int);
259
260    const char *                name () const;
261    const Channel &             channel () const;
262
263  private:
264
265    friend bool operator == (const ConstIterator &, const ConstIterator &);
266    friend bool operator != (const ConstIterator &, const ConstIterator &);
267
268    ChannelList::ChannelMap::const_iterator _i;
269};
270
271
272//-----------------
273// Inline Functions
274//-----------------
275
276inline
277ChannelList::Iterator::Iterator (): _i()
278{
279    // empty
280}
281
282
283inline
284ChannelList::Iterator::Iterator (const ChannelList::ChannelMap::iterator &i):
285    _i (i)
286{
287    // empty
288}
289
290
291inline ChannelList::Iterator &         
292ChannelList::Iterator::operator ++ ()
293{
294    ++_i;
295    return *this;
296}
297
298
299inline ChannelList::Iterator   
300ChannelList::Iterator::operator ++ (int)
301{
302    Iterator tmp = *this;
303    ++_i;
304    return tmp;
305}
306
307
308inline const char *
309ChannelList::Iterator::name () const
310{
311    return *_i->first;
312}
313
314
315inline Channel &       
316ChannelList::Iterator::channel () const
317{
318    return _i->second;
319}
320
321
322inline
323ChannelList::ConstIterator::ConstIterator (): _i()
324{
325    // empty
326}
327
328inline
329ChannelList::ConstIterator::ConstIterator
330    (const ChannelList::ChannelMap::const_iterator &i): _i (i)
331{
332    // empty
333}
334
335
336inline
337ChannelList::ConstIterator::ConstIterator (const ChannelList::Iterator &other):
338    _i (other._i)
339{
340    // empty
341}
342
343inline ChannelList::ConstIterator &
344ChannelList::ConstIterator::operator ++ ()
345{
346    ++_i;
347    return *this;
348}
349
350
351inline ChannelList::ConstIterator               
352ChannelList::ConstIterator::operator ++ (int)
353{
354    ConstIterator tmp = *this;
355    ++_i;
356    return tmp;
357}
358
359
360inline const char *
361ChannelList::ConstIterator::name () const
362{
363    return *_i->first;
364}
365
366inline const Channel & 
367ChannelList::ConstIterator::channel () const
368{
369    return _i->second;
370}
371
372
373inline bool
374operator == (const ChannelList::ConstIterator &x,
375             const ChannelList::ConstIterator &y)
376{
377    return x._i == y._i;
378}
379
380
381inline bool
382operator != (const ChannelList::ConstIterator &x,
383             const ChannelList::ConstIterator &y)
384{
385    return !(x == y);
386}
387
388
389} // namespace Imf
390
391#endif
Note: See TracBrowser for help on using the repository browser.