HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 "ImfUtilExport.h"
55 
57 
58 class FlatImage;
59 
60 class FlatImageLevel : public ImageLevel
61 {
62  public:
63 
64  //
65  // Access to the flat image to which the level belongs.
66  //
67 
69  FlatImage & flatImage();
71  const FlatImage & flatImage() const;
72 
73 
74 
75  //
76  // Accessing channels by name:
77  //
78  // findChannel(n) returns a pointer to the image channel with
79  // name n, or 0 if no such channel exists.
80  //
81  // channel(n) returns a reference to the image channel with
82  // name n, or throws an Iex::ArgExc exception if
83  // no such channel exists.
84  //
85  // findTypedChannel<T>(n) returns a pointer to the image channel with
86  // name n and type T, or 0 if no such channel
87  // exists.
88  //
89  // typedChannel(n) returns a reference to the image channel with
90  // name n and type T, or throws an Iex::ArgExc
91  // exception if no such channel exists.
92  //
93 
97  const FlatImageChannel * findChannel (const std::string& name) const;
98 
100  FlatImageChannel & channel (const std::string& name);
102  const FlatImageChannel & channel (const std::string& name) const;
103 
104  template <class T>
106  (const std::string& name);
107 
108  template <class T>
110  (const std::string& name) const;
111 
112  template <class T>
114  (const std::string& name);
115 
116  template <class T>
118  (const std::string& name) const;
119 
120  //
121  // Iterator-style access to channels
122  //
123 
124  typedef std::map <std::string, FlatImageChannel *> ChannelMap;
125 
126  class Iterator;
127  class ConstIterator;
128 
130  Iterator begin();
132  ConstIterator begin() const;
133 
135  Iterator end();
137  ConstIterator end() const;
138 
139  private:
140 
141  friend class FlatImage;
142 
143  //
144  // The constructor and destructor are private.
145  // Image levels exist only as part of an image.
146  //
147 
149  int xLevelNumber,
150  int yLevelNumber,
152 
153  virtual ~FlatImageLevel ();
154 
155  virtual void resize (const IMATH_NAMESPACE::Box2i& dataWindow);
156 
157  virtual void shiftPixels (int dx, int dy);
158 
159  virtual void insertChannel (const std::string& name,
160  PixelType type,
161  int xSampling,
162  int ySampling,
163  bool pLinear);
164 
165  virtual void eraseChannel (const std::string& name);
166 
167  virtual void clearChannels ();
168 
169  virtual void renameChannel (const std::string &oldName,
170  const std::string &newName);
171 
172  virtual void renameChannels (const RenamingMap &oldToNewNames);
173 
174  ChannelMap _channels;
175 };
176 
177 
179 {
180  public:
181 
183  Iterator ();
185  Iterator (const FlatImageLevel::ChannelMap::iterator& i);
186 
187 
188  //
189  // Advance the iterator
190  //
191 
193  Iterator & operator ++ ();
195  Iterator operator ++ (int);
196 
197 
198  //
199  // Access to the channel to which the iterator points,
200  // and to the name of that channel.
201  //
202 
204  const std::string & name () const;
206  FlatImageChannel & channel () const;
207 
208  private:
209 
211 
212  FlatImageLevel::ChannelMap::iterator _i;
213 };
214 
215 
217 {
218  public:
219 
221  ConstIterator ();
223  ConstIterator (const FlatImageLevel::ChannelMap::const_iterator& i);
226 
227 
228  //
229  // Advance the iterator
230  //
231 
233  ConstIterator & operator ++ ();
235  ConstIterator operator ++ (int);
236 
237 
238  //
239  // Access to the channel to which the iterator points,
240  // and to the name of that channel.
241  //
242 
244  const std::string & name () const;
246  const FlatImageChannel & channel () const;
247 
248  private:
249 
250  friend bool operator ==
251  (const ConstIterator &, const ConstIterator &);
252 
253  friend bool operator !=
254  (const ConstIterator &, const ConstIterator &);
255 
256  FlatImageLevel::ChannelMap::const_iterator _i;
257 };
258 
259 
260 //-----------------------------------------------------------------------------
261 // Implementation of templates and inline functions
262 //-----------------------------------------------------------------------------
263 
264 
265 template <class T>
268 {
269  return dynamic_cast <TypedFlatImageChannel<T>*> (findChannel (name));
270 }
271 
272 
273 template <class T>
276 {
277  return dynamic_cast <const TypedFlatImageChannel<T>*> (findChannel (name));
278 }
279 
280 
281 template <class T>
284 {
285  TypedFlatImageChannel<T> * ptr = findTypedChannel<T> (name);
286 
287  if (ptr == 0)
289 
290  return *ptr;
291 }
292 
293 
294 template <class T>
297 {
298  const TypedFlatImageChannel<T> * ptr = findTypedChannel<T> (name);
299 
300  if (ptr == 0)
302 
303  return *ptr;
304 }
305 
306 
307 inline
309 {
310  // empty
311 }
312 
313 
314 inline
315 FlatImageLevel::Iterator::Iterator (const FlatImageLevel::ChannelMap::iterator& i):
316  _i (i)
317 {
318  // empty
319 }
320 
321 
322 inline FlatImageLevel::Iterator &
324 {
325  ++_i;
326  return *this;
327 }
328 
329 
332 {
333  Iterator tmp = *this;
334  ++_i;
335  return tmp;
336 }
337 
338 
339 inline const std::string &
341 {
342  return _i->first;
343 }
344 
345 
346 inline FlatImageChannel &
348 {
349  return *_i->second;
350 }
351 
352 
353 inline
355 {
356  // empty
357 }
358 
359 inline
361  (const FlatImageLevel::ChannelMap::const_iterator& i): _i (i)
362 {
363  // empty
364 }
365 
366 
367 inline
369  (const FlatImageLevel::Iterator& other): _i (other._i)
370 {
371  // empty
372 }
373 
376 {
377  ++_i;
378  return *this;
379 }
380 
381 
384 {
385  ConstIterator tmp = *this;
386  ++_i;
387  return tmp;
388 }
389 
390 
391 inline const std::string &
393 {
394  return _i->first;
395 }
396 
397 inline const FlatImageChannel &
399 {
400  return *_i->second;
401 }
402 
403 
404 inline bool
407 {
408  return x._i == y._i;
409 }
410 
411 
412 inline bool
415 {
416  return !(x == y);
417 }
418 
420 
421 #endif
IMFUTIL_EXPORT Iterator end()
IMFUTIL_EXPORT FlatImage & flatImage()
GLuint const GLchar * name
Definition: glew.h:1814
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:109
IMFUTIL_EXPORT const FlatImageChannel & channel() const
int yLevelNumber() const
Definition: ImfImageLevel.h:76
IMFUTIL_EXPORT FlatImageChannel * findChannel(const std::string &name)
int xLevelNumber() const
Definition: ImfImageLevel.h:75
GLenum GLsizei GLenum GLenum const void * image
Definition: glew.h:4943
IMFUTIL_EXPORT void clearChannels()
IMFUTIL_EXPORT void insertChannel(const std::string &name, PixelType type, int xSampling=1, int ySampling=1, bool pLinear=false)
IMFUTIL_EXPORT void renameChannels(const RenamingMap &oldToNewNames)
IMFUTIL_EXPORT void eraseChannel(const std::string &name)
IMFUTIL_EXPORT FlatImageChannel & channel() const
#define IMFUTIL_EXPORT
Definition: ImfUtilExport.h:44
std::map< std::string, FlatImageChannel * > ChannelMap
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER typedef std::map< std::string, std::string > RenamingMap
GLint GLint GLint GLint GLint x
Definition: glew.h:1252
Box< V2i > Box2i
Definition: ImathBox.h:133
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1252
IMFUTIL_EXPORT FlatImageChannel & channel(const std::string &name)
bool operator==(const FlatImageLevel::ConstIterator &x, const FlatImageLevel::ConstIterator &y)
PixelType
Definition: ImfPixelType.h:51
IMFUTIL_EXPORT void throwBadChannelNameOrType(const std::string &name) const
TypedFlatImageChannel< T > * findTypedChannel(const std::string &name)
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
IMFUTIL_EXPORT void renameChannel(const std::string &oldName, const std::string &newName)
IMFUTIL_EXPORT Iterator & operator++()
GLsizei const GLchar *const * string
Definition: glew.h:1844
const void * ptr(const T *p)
Definition: format.h:3292
bool operator!=(const FlatImageLevel::ConstIterator &x, const FlatImageLevel::ConstIterator &y)
IMFUTIL_EXPORT void shiftPixels(int dx, int dy)
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:108
IMFUTIL_EXPORT void resize(const IMATH_NAMESPACE::Box2i &dataWindow)
IMFUTIL_EXPORT const std::string & name() const
IMFUTIL_EXPORT ConstIterator & operator++()
const IMATH_NAMESPACE::Box2i & dataWindow() const
Definition: ImfImageLevel.h:78
IMFUTIL_EXPORT Iterator begin()
TypedFlatImageChannel< T > & typedChannel(const std::string &name)
IMFUTIL_EXPORT const std::string & name() const