HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ImfFlatImageLevel.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2014, 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 #ifndef INCLUDED_IMF_FLAT_IMAGE_LEVEL_H
36 #define INCLUDED_IMF_FLAT_IMAGE_LEVEL_H
37 
38 //----------------------------------------------------------------------------
39 //
40 // class FlatImageLevel
41 // class FlatImageLevel::Iterator
42 // class FlatImageLevel::ConstIterator
43 //
44 // For an explanation of images, levels and channels,
45 // see the comments in header file Image.h.
46 //
47 //----------------------------------------------------------------------------
48 
49 #include <ImfFlatImageChannel.h>
50 #include <ImfImageLevel.h>
51 #include <ImathBox.h>
52 #include <string>
53 #include <map>
54 #include "ImfExport.h"
55 
57 
58 class FlatImage;
59 
61 {
62  public:
63 
64  //
65  // Access to the flat image to which the level belongs.
66  //
67 
68  FlatImage & flatImage();
69  const FlatImage & flatImage() const;
70 
71 
72 
73  //
74  // Accessing channels by name:
75  //
76  // findChannel(n) returns a pointer to the image channel with
77  // name n, or 0 if no such channel exists.
78  //
79  // channel(n) returns a reference to the image channel with
80  // name n, or throws an Iex::ArgExc exception if
81  // no such channel exists.
82  //
83  // findTypedChannel<T>(n) returns a pointer to the image channel with
84  // name n and type T, or 0 if no such channel
85  // exists.
86  //
87  // typedChannel(n) returns a reference to the image channel with
88  // name n and type T, or throws an Iex::ArgExc
89  // exception if no such channel exists.
90  //
91 
92  FlatImageChannel * findChannel (const std::string& name);
93  const FlatImageChannel * findChannel (const std::string& name) const;
94 
95  FlatImageChannel & channel (const std::string& name);
96  const FlatImageChannel & channel (const std::string& name) const;
97 
98  template <class T>
99  TypedFlatImageChannel<T> * findTypedChannel
100  (const std::string& name);
101 
102  template <class T>
103  const TypedFlatImageChannel<T> * findTypedChannel
104  (const std::string& name) const;
105 
106  template <class T>
107  TypedFlatImageChannel<T> & typedChannel
108  (const std::string& name);
109 
110  template <class T>
111  const TypedFlatImageChannel<T> & typedChannel
112  (const std::string& name) const;
113 
114  //
115  // Iterator-style access to channels
116  //
117 
118  typedef std::map <std::string, FlatImageChannel *> ChannelMap;
119 
120  class Iterator;
121  class ConstIterator;
122 
123  Iterator begin();
124  ConstIterator begin() const;
125 
126  Iterator end();
127  ConstIterator end() const;
128 
129  private:
130 
131  friend class FlatImage;
132 
133  //
134  // The constructor and destructor are private.
135  // Image levels exist only as part of an image.
136  //
137 
139  int xLevelNumber,
140  int yLevelNumber,
142 
143  virtual ~FlatImageLevel ();
144 
145  virtual void resize (const IMATH_NAMESPACE::Box2i& dataWindow);
146 
147  virtual void shiftPixels (int dx, int dy);
148 
149  virtual void insertChannel (const std::string& name,
150  PixelType type,
151  int xSampling,
152  int ySampling,
153  bool pLinear);
154 
155  virtual void eraseChannel (const std::string& name);
156 
157  virtual void clearChannels ();
158 
159  virtual void renameChannel (const std::string &oldName,
160  const std::string &newName);
161 
162  virtual void renameChannels (const RenamingMap &oldToNewNames);
163 
164  ChannelMap _channels;
165 };
166 
167 
169 {
170  public:
171 
172  Iterator ();
173  Iterator (const FlatImageLevel::ChannelMap::iterator& i);
174 
175 
176  //
177  // Advance the iterator
178  //
179 
181  Iterator operator ++ (int);
182 
183 
184  //
185  // Access to the channel to which the iterator points,
186  // and to the name of that channel.
187  //
188 
189  const std::string & name () const;
190  FlatImageChannel & channel () const;
191 
192  private:
193 
195 
196  FlatImageLevel::ChannelMap::iterator _i;
197 };
198 
199 
201 {
202  public:
203 
204  ConstIterator ();
205  ConstIterator (const FlatImageLevel::ChannelMap::const_iterator& i);
207 
208 
209  //
210  // Advance the iterator
211  //
212 
215 
216 
217  //
218  // Access to the channel to which the iterator points,
219  // and to the name of that channel.
220  //
221 
222  const std::string & name () const;
223  const FlatImageChannel & channel () const;
224 
225  private:
226 
227  friend bool operator ==
228  (const ConstIterator &, const ConstIterator &);
229 
230  friend bool operator !=
231  (const ConstIterator &, const ConstIterator &);
232 
233  FlatImageLevel::ChannelMap::const_iterator _i;
234 };
235 
236 
237 //-----------------------------------------------------------------------------
238 // Implementation of templates and inline functions
239 //-----------------------------------------------------------------------------
240 
241 
242 template <class T>
245 {
246  return dynamic_cast <TypedFlatImageChannel<T>*> (findChannel (name));
247 }
248 
249 
250 template <class T>
253 {
254  return dynamic_cast <const TypedFlatImageChannel<T>*> (findChannel (name));
255 }
256 
257 
258 template <class T>
261 {
262  TypedFlatImageChannel<T> * ptr = findTypedChannel<T> (name);
263 
264  if (ptr == 0)
266 
267  return *ptr;
268 }
269 
270 
271 template <class T>
274 {
275  const TypedFlatImageChannel<T> * ptr = findTypedChannel<T> (name);
276 
277  if (ptr == 0)
279 
280  return *ptr;
281 }
282 
283 
284 inline
286 {
287  // empty
288 }
289 
290 
291 inline
292 FlatImageLevel::Iterator::Iterator (const FlatImageLevel::ChannelMap::iterator& i):
293  _i (i)
294 {
295  // empty
296 }
297 
298 
299 inline FlatImageLevel::Iterator &
301 {
302  ++_i;
303  return *this;
304 }
305 
306 
309 {
310  Iterator tmp = *this;
311  ++_i;
312  return tmp;
313 }
314 
315 
316 inline const std::string &
318 {
319  return _i->first;
320 }
321 
322 
323 inline FlatImageChannel &
325 {
326  return *_i->second;
327 }
328 
329 
330 inline
332 {
333  // empty
334 }
335 
336 inline
338  (const FlatImageLevel::ChannelMap::const_iterator& i): _i (i)
339 {
340  // empty
341 }
342 
343 
344 inline
346  (const FlatImageLevel::Iterator& other): _i (other._i)
347 {
348  // empty
349 }
350 
353 {
354  ++_i;
355  return *this;
356 }
357 
358 
361 {
362  ConstIterator tmp = *this;
363  ++_i;
364  return tmp;
365 }
366 
367 
368 inline const std::string &
370 {
371  return _i->first;
372 }
373 
374 inline const FlatImageChannel &
376 {
377  return *_i->second;
378 }
379 
380 
381 inline bool
384 {
385  return x._i == y._i;
386 }
387 
388 
389 inline bool
392 {
393  return !(x == y);
394 }
395 
397 
398 #endif
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:109
const FlatImageChannel & channel() const
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
png_voidp ptr
Definition: png.h:2145
GLint y
Definition: glcorearb.h:102
png_uint_32 i
Definition: png.h:2877
virtual void clearChannels()=0
png_bytepp image
Definition: png.h:1849
FlatImageChannel & channel() const
virtual void shiftPixels(int dx, int dy)
std::map< std::string, FlatImageChannel * > ChannelMap
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER typedef std::map< std::string, std::string > RenamingMap
IMF_EXPORT void throwBadChannelNameOrType(const std::string &name) const
Box< V2i > Box2i
Definition: ImathBox.h:133
virtual void renameChannel(const std::string &oldName, const std::string &newName)=0
bool operator==(const FlatImageLevel::ConstIterator &x, const FlatImageLevel::ConstIterator &y)
PixelType
Definition: ImfPixelType.h:51
GLuint GLuint end
Definition: glcorearb.h:474
FlatImageChannel * findChannel(const std::string &name)
TypedFlatImageChannel< T > * findTypedChannel(const std::string &name)
#define IMF_EXPORT
Definition: ImfExport.h:59
virtual void renameChannels(const RenamingMap &oldToNewNames)=0
GLuint const GLchar * name
Definition: glcorearb.h:785
const IMATH_NAMESPACE::Box2i & dataWindow() const
virtual void insertChannel(const std::string &name, PixelType type, int xSampling, int ySampling, bool pLinear)=0
virtual void resize(const IMATH_NAMESPACE::Box2i &dataWindow)
bool operator!=(const FlatImageLevel::ConstIterator &x, const FlatImageLevel::ConstIterator &y)
virtual void eraseChannel(const std::string &name)=0
GLint GLenum GLint x
Definition: glcorearb.h:408
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:108
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
const std::string & name() const
TypedFlatImageChannel< T > & typedChannel(const std::string &name)
const std::string & name() const