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 // SPDX-License-Identifier: BSD-3-Clause
3 // Copyright (c) Contributors to the OpenEXR Project.
4 //
5 
6 #ifndef INCLUDED_IMF_FLAT_IMAGE_LEVEL_H
7 #define INCLUDED_IMF_FLAT_IMAGE_LEVEL_H
8 
9 //----------------------------------------------------------------------------
10 //
11 // class FlatImageLevel
12 // class FlatImageLevel::Iterator
13 // class FlatImageLevel::ConstIterator
14 //
15 // For an explanation of images, levels and channels,
16 // see the comments in header file Image.h.
17 //
18 //----------------------------------------------------------------------------
19 
20 #include "ImfFlatImageChannel.h"
21 #include "ImfImageLevel.h"
22 #include "ImfUtilExport.h"
23 #include <ImathBox.h>
24 #include <map>
25 #include <string>
26 
28 
29 class FlatImage;
30 
32 {
33 public:
34  //
35  // Access to the flat image to which the level belongs.
36  //
37 
39  FlatImage& flatImage ();
41  const FlatImage& flatImage () const;
42 
43  //
44  // Accessing channels by name:
45  //
46  // findChannel(n) returns a pointer to the image channel with
47  // name n, or 0 if no such channel exists.
48  //
49  // channel(n) returns a reference to the image channel with
50  // name n, or throws an Iex::ArgExc exception if
51  // no such channel exists.
52  //
53  // findTypedChannel<T>(n) returns a pointer to the image channel with
54  // name n and type T, or 0 if no such channel
55  // exists.
56  //
57  // typedChannel(n) returns a reference to the image channel with
58  // name n and type T, or throws an Iex::ArgExc
59  // exception if no such channel exists.
60  //
61 
63  FlatImageChannel* findChannel (const std::string& name);
65  const FlatImageChannel* findChannel (const std::string& name) const;
66 
68  FlatImageChannel& channel (const std::string& name);
70  const FlatImageChannel& channel (const std::string& name) const;
71 
72  template <class T>
73  TypedFlatImageChannel<T>* findTypedChannel (const std::string& name);
74 
75  template <class T>
77  findTypedChannel (const std::string& name) const;
78 
79  template <class T>
80  TypedFlatImageChannel<T>& typedChannel (const std::string& name);
81 
82  template <class T>
84  typedChannel (const std::string& name) const;
85 
86  //
87  // Iterator-style access to channels
88  //
89 
90  typedef std::map<std::string, FlatImageChannel*> ChannelMap;
91 
92  class Iterator;
93  class ConstIterator;
94 
96  Iterator begin ();
98  ConstIterator begin () const;
99 
101  Iterator end ();
103  ConstIterator end () const;
104 
105 private:
106  friend class FlatImage;
107 
108  //
109  // The constructor and destructor are private.
110  // Image levels exist only as part of an image.
111  //
114  FlatImage& image,
115  int xLevelNumber,
116  int yLevelNumber,
118 
120  virtual ~FlatImageLevel ();
121 
123  virtual void resize (const IMATH_NAMESPACE::Box2i& dataWindow);
124 
126  virtual void shiftPixels (int dx, int dy);
127 
129  virtual void insertChannel (
130  const std::string& name,
131  PixelType type,
132  int xSampling,
133  int ySampling,
134  bool pLinear);
135 
137  virtual void eraseChannel (const std::string& name);
138 
140  virtual void clearChannels ();
141 
143  virtual void
144  renameChannel (const std::string& oldName, const std::string& newName);
145 
147  virtual void renameChannels (const RenamingMap& oldToNewNames);
148 
149  ChannelMap _channels;
150 };
151 
152 class IMFUTIL_EXPORT_TYPE FlatImageLevel::Iterator
153 {
154 public:
156  Iterator ();
158  Iterator (const FlatImageLevel::ChannelMap::iterator& i);
159 
160  //
161  // Advance the iterator
162  //
163 
165  Iterator& operator++ ();
167  Iterator operator++ (int);
168 
169  //
170  // Access to the channel to which the iterator points,
171  // and to the name of that channel.
172  //
173 
175  const std::string& name () const;
177  FlatImageChannel& channel () const;
178 
179 private:
181 
182  FlatImageLevel::ChannelMap::iterator _i;
183 };
184 
185 class IMFUTIL_EXPORT_TYPE FlatImageLevel::ConstIterator
186 {
187 public:
189  ConstIterator ();
191  ConstIterator (const FlatImageLevel::ChannelMap::const_iterator& i);
193  ConstIterator (const FlatImageLevel::Iterator& other);
194 
195  //
196  // Advance the iterator
197  //
198 
200  ConstIterator& operator++ ();
202  ConstIterator operator++ (int);
203 
204  //
205  // Access to the channel to which the iterator points,
206  // and to the name of that channel.
207  //
208 
210  const std::string& name () const;
212  const FlatImageChannel& channel () const;
213 
214 private:
215  friend bool operator== (const ConstIterator&, const ConstIterator&);
216 
217  friend bool operator!= (const ConstIterator&, const ConstIterator&);
218 
219  FlatImageLevel::ChannelMap::const_iterator _i;
220 };
221 
222 //-----------------------------------------------------------------------------
223 // Implementation of templates and inline functions
224 //-----------------------------------------------------------------------------
225 
226 template <class T>
229 {
230  return dynamic_cast<TypedFlatImageChannel<T>*> (findChannel (name));
231 }
232 
233 template <class T>
236 {
237  return dynamic_cast<const TypedFlatImageChannel<T>*> (findChannel (name));
238 }
239 
240 template <class T>
243 {
244  TypedFlatImageChannel<T>* ptr = findTypedChannel<T> (name);
245 
246  if (ptr == 0) throwBadChannelNameOrType (name);
247 
248  return *ptr;
249 }
250 
251 template <class T>
254 {
255  const TypedFlatImageChannel<T>* ptr = findTypedChannel<T> (name);
256 
257  if (ptr == 0) throwBadChannelNameOrType (name);
258 
259  return *ptr;
260 }
261 
262 inline FlatImageLevel::Iterator::Iterator () : _i ()
263 {
264  // empty
265 }
266 
267 inline FlatImageLevel::Iterator::Iterator (
268  const FlatImageLevel::ChannelMap::iterator& i)
269  : _i (i)
270 {
271  // empty
272 }
273 
275 FlatImageLevel::Iterator::operator++ ()
276 {
277  ++_i;
278  return *this;
279 }
280 
282 FlatImageLevel::Iterator::operator++ (int)
283 {
284  Iterator tmp = *this;
285  ++_i;
286  return tmp;
287 }
288 
289 inline const std::string&
291 {
292  return _i->first;
293 }
294 
295 inline FlatImageChannel&
296 FlatImageLevel::Iterator::channel () const
297 {
298  return *_i->second;
299 }
300 
301 inline FlatImageLevel::ConstIterator::ConstIterator () : _i ()
302 {
303  // empty
304 }
305 
306 inline FlatImageLevel::ConstIterator::ConstIterator (
307  const FlatImageLevel::ChannelMap::const_iterator& i)
308  : _i (i)
309 {
310  // empty
311 }
312 
313 inline FlatImageLevel::ConstIterator::ConstIterator (
314  const FlatImageLevel::Iterator& other)
315  : _i (other._i)
316 {
317  // empty
318 }
319 
321 FlatImageLevel::ConstIterator::operator++ ()
322 {
323  ++_i;
324  return *this;
325 }
326 
328 FlatImageLevel::ConstIterator::operator++ (int)
329 {
330  ConstIterator tmp = *this;
331  ++_i;
332  return tmp;
333 }
334 
335 inline const std::string&
337 {
338  return _i->first;
339 }
340 
341 inline const FlatImageChannel&
342 FlatImageLevel::ConstIterator::channel () const
343 {
344  return *_i->second;
345 }
346 
347 inline bool
351 {
352  return x._i == y._i;
353 }
354 
355 inline bool
359 {
360  return !(x == y);
361 }
362 
364 
365 #endif
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:83
IMFUTIL_EXPORT ConstIterator()
IMFUTIL_EXPORT const IMATH_NAMESPACE::Box2i & dataWindow() const
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
IMFUTIL_EXPORT FlatImageChannel * findChannel(const std::string &name)
IMFUTIL_EXPORT Iterator()
GLenum GLenum GLsizei void * image
Definition: glad.h:5132
GLint y
Definition: glcorearb.h:103
virtual void clearChannels()=0
virtual IMFUTIL_EXPORT void resize(const IMATH_NAMESPACE::Box2i &dataWindow)
IMFUTIL_EXPORT const std::string & name() const
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER typedef std::map< std::string, std::string > RenamingMap
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER enum IMF_EXPORT_ENUM PixelType
Definition: ImfPixelType.h:20
Box< V2i > Box2i
2D box of base type int.
Definition: ImathBox.h:143
virtual void renameChannel(const std::string &oldName, const std::string &newName)=0
bool operator==(const FlatImageLevel::ConstIterator &x, const FlatImageLevel::ConstIterator &y)
GLuint GLuint end
Definition: glcorearb.h:475
#define IMFUTIL_EXPORT_TYPE
Definition: ImfUtilExport.h:54
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
Definition: Mat3.h:556
IMFUTIL_EXPORT void throwBadChannelNameOrType(const std::string &name) const
TypedFlatImageChannel< T > * findTypedChannel(const std::string &name)
virtual void renameChannels(const RenamingMap &oldToNewNames)=0
GLuint const GLchar * name
Definition: glcorearb.h:786
#define IMFUTIL_EXPORT
Definition: ImfUtilExport.h:51
virtual IMFUTIL_EXPORT void shiftPixels(int dx, int dy)
GLint GLenum GLint x
Definition: glcorearb.h:409
virtual void insertChannel(const std::string &name, PixelType type, int xSampling, int ySampling, bool pLinear)=0
bool operator!=(const FlatImageLevel::ConstIterator &x, const FlatImageLevel::ConstIterator &y)
virtual void eraseChannel(const std::string &name)=0
auto ptr(T p) -> const void *
Definition: format.h:2448
std::map< std::string, FlatImageChannel * > ChannelMap
#define IMFUTIL_HIDDEN
Definition: ImfUtilExport.h:52
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:80
type
Definition: core.h:1059
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat3.h:542
TypedFlatImageChannel< T > & typedChannel(const std::string &name)
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.
Definition: node.h:558