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 <ImathBox.h>
23 #include <string>
24 #include <map>
25 #include "ImfUtilExport.h"
26 
28 
29 class FlatImage;
30 
32 {
33  public:
34 
35  //
36  // Access to the flat image to which the level belongs.
37  //
38 
40  FlatImage & flatImage();
42  const FlatImage & flatImage() const;
43 
44 
45 
46  //
47  // Accessing channels by name:
48  //
49  // findChannel(n) returns a pointer to the image channel with
50  // name n, or 0 if no such channel exists.
51  //
52  // channel(n) returns a reference to the image channel with
53  // name n, or throws an Iex::ArgExc exception if
54  // no such channel exists.
55  //
56  // findTypedChannel<T>(n) returns a pointer to the image channel with
57  // name n and type T, or 0 if no such channel
58  // exists.
59  //
60  // typedChannel(n) returns a reference to the image channel with
61  // name n and type T, or throws an Iex::ArgExc
62  // exception if no such channel exists.
63  //
64 
66  FlatImageChannel * findChannel (const std::string& name);
68  const FlatImageChannel * findChannel (const std::string& name) const;
69 
71  FlatImageChannel & channel (const std::string& name);
73  const FlatImageChannel & channel (const std::string& name) const;
74 
75  template <class T>
76  TypedFlatImageChannel<T> * findTypedChannel
77  (const std::string& name);
78 
79  template <class T>
80  const TypedFlatImageChannel<T> * findTypedChannel
81  (const std::string& name) const;
82 
83  template <class T>
84  TypedFlatImageChannel<T> & typedChannel
85  (const std::string& name);
86 
87  template <class T>
88  const TypedFlatImageChannel<T> & typedChannel
89  (const std::string& name) const;
90 
91  //
92  // Iterator-style access to channels
93  //
94 
95  typedef std::map <std::string, FlatImageChannel *> ChannelMap;
96 
97  class Iterator;
98  class ConstIterator;
99 
101  Iterator begin();
103  ConstIterator begin() const;
104 
106  Iterator end();
108  ConstIterator end() const;
109 
110  private:
111 
112  friend class FlatImage;
113 
114  //
115  // The constructor and destructor are private.
116  // Image levels exist only as part of an image.
117  //
120  int xLevelNumber,
121  int yLevelNumber,
123 
125  virtual ~FlatImageLevel ();
126 
128  virtual void resize (const IMATH_NAMESPACE::Box2i& dataWindow);
129 
131  virtual void shiftPixels (int dx, int dy);
132 
134  virtual void insertChannel (const std::string& name,
135  PixelType type,
136  int xSampling,
137  int ySampling,
138  bool pLinear);
139 
141  virtual void eraseChannel (const std::string& name);
142 
144  virtual void clearChannels ();
145 
147  virtual void renameChannel (const std::string &oldName,
148  const std::string &newName);
149 
151  virtual void renameChannels (const RenamingMap &oldToNewNames);
152 
153  ChannelMap _channels;
154 };
155 
156 
157 class IMFUTIL_EXPORT_TYPE FlatImageLevel::Iterator
158 {
159  public:
160 
162  Iterator ();
164  Iterator (const FlatImageLevel::ChannelMap::iterator& i);
165 
166 
167  //
168  // Advance the iterator
169  //
170 
172  Iterator & operator ++ ();
174  Iterator operator ++ (int);
175 
176 
177  //
178  // Access to the channel to which the iterator points,
179  // and to the name of that channel.
180  //
181 
183  const std::string & name () const;
185  FlatImageChannel & channel () const;
186 
187  private:
188 
190 
191  FlatImageLevel::ChannelMap::iterator _i;
192 };
193 
194 
195 class IMFUTIL_EXPORT_TYPE FlatImageLevel::ConstIterator
196 {
197  public:
198 
200  ConstIterator ();
202  ConstIterator (const FlatImageLevel::ChannelMap::const_iterator& i);
204  ConstIterator (const FlatImageLevel::Iterator& other);
205 
206 
207  //
208  // Advance the iterator
209  //
210 
212  ConstIterator & operator ++ ();
214  ConstIterator operator ++ (int);
215 
216 
217  //
218  // Access to the channel to which the iterator points,
219  // and to the name of that channel.
220  //
221 
223  const std::string & name () const;
225  const FlatImageChannel & channel () const;
226 
227  private:
228 
229  friend bool operator ==
230  (const ConstIterator &, const ConstIterator &);
231 
232  friend bool operator !=
233  (const ConstIterator &, const ConstIterator &);
234 
235  FlatImageLevel::ChannelMap::const_iterator _i;
236 };
237 
238 
239 //-----------------------------------------------------------------------------
240 // Implementation of templates and inline functions
241 //-----------------------------------------------------------------------------
242 
243 
244 template <class T>
247 {
248  return dynamic_cast <TypedFlatImageChannel<T> *> (findChannel (name));
249 }
250 
251 
252 template <class T>
255 {
256  return dynamic_cast <const TypedFlatImageChannel<T> *> (findChannel (name));
257 }
258 
259 
260 template <class T>
263 {
264  TypedFlatImageChannel<T> * ptr = findTypedChannel<T> (name);
265 
266  if (ptr == 0)
268 
269  return *ptr;
270 }
271 
272 
273 template <class T>
276 {
277  const TypedFlatImageChannel<T> * ptr = findTypedChannel<T> (name);
278 
279  if (ptr == 0)
281 
282  return *ptr;
283 }
284 
285 
286 inline
287 FlatImageLevel::Iterator::Iterator (): _i()
288 {
289  // empty
290 }
291 
292 
293 inline
294 FlatImageLevel::Iterator::Iterator (const FlatImageLevel::ChannelMap::iterator& i):
295  _i (i)
296 {
297  // empty
298 }
299 
300 
301 inline FlatImageLevel::Iterator &
302 FlatImageLevel::Iterator::operator ++ ()
303 {
304  ++_i;
305  return *this;
306 }
307 
308 
310 FlatImageLevel::Iterator::operator ++ (int)
311 {
312  Iterator tmp = *this;
313  ++_i;
314  return tmp;
315 }
316 
317 
318 inline const std::string &
320 {
321  return _i->first;
322 }
323 
324 
325 inline FlatImageChannel &
326 FlatImageLevel::Iterator::channel () const
327 {
328  return *_i->second;
329 }
330 
331 
332 inline
333 FlatImageLevel::ConstIterator::ConstIterator (): _i()
334 {
335  // empty
336 }
337 
338 inline
339 FlatImageLevel::ConstIterator::ConstIterator
340  (const FlatImageLevel::ChannelMap::const_iterator& i): _i (i)
341 {
342  // empty
343 }
344 
345 
346 inline
347 FlatImageLevel::ConstIterator::ConstIterator
348  (const FlatImageLevel::Iterator& other): _i (other._i)
349 {
350  // empty
351 }
352 
354 FlatImageLevel::ConstIterator::operator ++ ()
355 {
356  ++_i;
357  return *this;
358 }
359 
360 
362 FlatImageLevel::ConstIterator::operator ++ (int)
363 {
364  ConstIterator tmp = *this;
365  ++_i;
366  return tmp;
367 }
368 
369 
370 inline const std::string &
372 {
373  return _i->first;
374 }
375 
376 inline const FlatImageChannel &
377 FlatImageLevel::ConstIterator::channel () const
378 {
379  return *_i->second;
380 }
381 
382 
383 inline bool
386 {
387  return x._i == y._i;
388 }
389 
390 
391 inline bool
394 {
395  return !(x == y);
396 }
397 
399 
400 #endif
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:80
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)
std::map< std::string, FlatImageChannel * > ChannelMap
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:22
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
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
virtual void eraseChannel(const std::string &name)=0
auto ptr(T p) -> const void *
Definition: format.h:2448
#define IMFUTIL_HIDDEN
Definition: ImfUtilExport.h:52
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:79
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:483