HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImfDeepImageLevel.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_DEEP_IMAGE_LEVEL_H
7 #define INCLUDED_IMF_DEEP_IMAGE_LEVEL_H
8 
9 //----------------------------------------------------------------------------
10 //
11 // class DeepImageLevel
12 // class DeepImageLevel::Iterator
13 // class DeepImageLevel::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 "ImfNamespace.h"
21 #include "ImfUtilExport.h"
22 
23 #include "ImfDeepImageChannel.h"
24 #include "ImfImageLevel.h"
25 #include "ImfSampleCountChannel.h"
26 
27 #include <map>
28 #include <string>
29 
31 
32 class DeepImage;
33 
35 {
36 public:
37  //
38  // Access to the image to which the level belongs.
39  //
40 
42  DeepImage& deepImage ();
44  const DeepImage& deepImage () const;
45 
46  //
47  // Access to deep 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  DeepImageChannel* findChannel (const std::string& name);
68  const DeepImageChannel* findChannel (const std::string& name) const;
69 
71  DeepImageChannel& channel (const std::string& name);
73  const DeepImageChannel& channel (const std::string& name) const;
74 
75  template <class T>
76  TypedDeepImageChannel<T>* findTypedChannel (const std::string& name);
77 
78  template <class T>
80  findTypedChannel (const std::string& name) const;
81 
82  template <class T>
83  TypedDeepImageChannel<T>& typedChannel (const std::string& name);
84 
85  template <class T>
87  typedChannel (const std::string& name) const;
88 
89  //
90  // Iterator-style access to deep channels
91  //
92 
93  typedef std::map<std::string, DeepImageChannel*> ChannelMap;
94 
95  class Iterator;
96  class ConstIterator;
97 
99  Iterator begin ();
101  ConstIterator begin () const;
102 
104  Iterator end ();
106  ConstIterator end () const;
107 
108  //
109  // Access to the sample count channel
110  //
111 
113  SampleCountChannel& sampleCounts ();
115  const SampleCountChannel& sampleCounts () const;
116 
117 private:
118  friend class DeepImage;
119  friend class SampleCountChannel;
120 
121  //
122  // The constructor and destructor are private.
123  // Deep image levels exist only as part of a deep image.
124  //
125  IMF_HIDDEN
127  DeepImage& image,
128  int xLevelNumber,
129  int yLevelNumber,
130  const IMATH_NAMESPACE::Box2i& dataWindow);
131 
132  IMF_HIDDEN
133  ~DeepImageLevel ();
134 
135  IMF_HIDDEN
136  void setSamplesToZero (
137  size_t i, unsigned int oldNumSamples, unsigned int newNumSamples);
138 
139  IMF_HIDDEN
140  void moveSampleList (
141  size_t i,
142  unsigned int oldNumSamples,
143  unsigned int newNumSamples,
144  size_t newSampleListPosition);
145 
146  IMF_HIDDEN
147  void moveSamplesToNewBuffer (
148  const unsigned int* oldNumSamples,
149  const unsigned int* newNumSamples,
150  const size_t* newSampleListPositions);
151 
152  IMF_HIDDEN
153  void initializeSampleLists ();
154 
155  IMF_HIDDEN
156  virtual void resize (const IMATH_NAMESPACE::Box2i& dataWindow);
157 
158  IMF_HIDDEN
159  virtual void shiftPixels (int dx, int dy);
160 
161  IMF_HIDDEN
162  virtual void insertChannel (
163  const std::string& name,
164  PixelType type,
165  int xSampling,
166  int ySampling,
167  bool pLinear);
168 
169  IMF_HIDDEN
170  virtual void eraseChannel (const std::string& name);
171 
172  IMF_HIDDEN
173  virtual void clearChannels ();
174 
175  IMF_HIDDEN
176  virtual void
177  renameChannel (const std::string& oldName, const std::string& newName);
178 
179  IMF_HIDDEN
180  virtual void renameChannels (const RenamingMap& oldToNewNames);
181 
182  ChannelMap _channels;
183  SampleCountChannel _sampleCounts;
184 };
185 
186 class IMFUTIL_EXPORT_TYPE DeepImageLevel::Iterator
187 {
188 public:
190  Iterator ();
192  Iterator (const DeepImageLevel::ChannelMap::iterator& i);
193 
194  //
195  // Advance the iterator
196  //
197 
199  Iterator& operator++ ();
201  Iterator operator++ (int);
202 
203  //
204  // Access to the channel to which the iterator points,
205  // and to the name of that channel.
206  //
207 
209  const std::string& name () const;
211  DeepImageChannel& channel () const;
212 
213 private:
215 
216  DeepImageLevel::ChannelMap::iterator _i;
217 };
218 
219 class IMFUTIL_EXPORT_TYPE DeepImageLevel::ConstIterator
220 {
221 public:
223  ConstIterator ();
225  ConstIterator (const DeepImageLevel::ChannelMap::const_iterator& i);
227  ConstIterator (const DeepImageLevel::Iterator& other);
228 
229  //
230  // Advance the iterator
231  //
232 
234  ConstIterator& operator++ ();
236  ConstIterator operator++ (int);
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 DeepImageChannel& channel () const;
247 
248 private:
249  friend bool operator== (const ConstIterator&, const ConstIterator&);
250 
251  friend bool operator!= (const ConstIterator&, const ConstIterator&);
252 
253  DeepImageLevel::ChannelMap::const_iterator _i;
254 };
255 
256 //-----------------------------------------------------------------------------
257 // Implementation of inline functions
258 //-----------------------------------------------------------------------------
259 
260 template <class T>
263 {
264  return dynamic_cast<TypedDeepImageChannel<T>*> (findChannel (name));
265 }
266 
267 template <class T>
270 {
271  return dynamic_cast<const TypedDeepImageChannel<T>*> (findChannel (name));
272 }
273 
274 template <class T>
277 {
278  TypedDeepImageChannel<T>* ptr = findTypedChannel<T> (name);
279 
280  if (ptr == 0) throwBadChannelNameOrType (name);
281 
282  return *ptr;
283 }
284 
285 template <class T>
288 {
289  const TypedDeepImageChannel<T>* ptr = findTypedChannel<T> (name);
290 
291  if (ptr == 0) throwBadChannelNameOrType (name);
292 
293  return *ptr;
294 }
295 
296 inline SampleCountChannel&
298 {
299  return _sampleCounts;
300 }
301 
302 inline const SampleCountChannel&
304 {
305  return _sampleCounts;
306 }
307 
308 inline DeepImageLevel::Iterator::Iterator () : _i ()
309 {
310  // empty
311 }
312 
313 inline DeepImageLevel::Iterator::Iterator (
314  const DeepImageLevel::ChannelMap::iterator& i)
315  : _i (i)
316 {
317  // empty
318 }
319 
321 DeepImageLevel::Iterator::operator++ ()
322 {
323  ++_i;
324  return *this;
325 }
326 
328 DeepImageLevel::Iterator::operator++ (int)
329 {
330  Iterator tmp = *this;
331  ++_i;
332  return tmp;
333 }
334 
335 inline const std::string&
337 {
338  return _i->first;
339 }
340 
341 inline DeepImageChannel&
342 DeepImageLevel::Iterator::channel () const
343 {
344  return *_i->second;
345 }
346 
347 inline DeepImageLevel::ConstIterator::ConstIterator () : _i ()
348 {
349  // empty
350 }
351 
352 inline DeepImageLevel::ConstIterator::ConstIterator (
353  const DeepImageLevel::ChannelMap::const_iterator& i)
354  : _i (i)
355 {
356  // empty
357 }
358 
359 inline DeepImageLevel::ConstIterator::ConstIterator (
360  const DeepImageLevel::Iterator& other)
361  : _i (other._i)
362 {
363  // empty
364 }
365 
367 DeepImageLevel::ConstIterator::operator++ ()
368 {
369  ++_i;
370  return *this;
371 }
372 
374 DeepImageLevel::ConstIterator::operator++ (int)
375 {
376  ConstIterator tmp = *this;
377  ++_i;
378  return tmp;
379 }
380 
381 inline const std::string&
383 {
384  return _i->first;
385 }
386 
387 inline const DeepImageChannel&
388 DeepImageLevel::ConstIterator::channel () const
389 {
390  return *_i->second;
391 }
392 
393 inline bool
397 {
398  return x._i == y._i;
399 }
400 
401 inline bool
405 {
406  return !(x == y);
407 }
408 
410 
411 #endif
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:83
int ySampling() const
IMFUTIL_EXPORT ConstIterator()
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
GLenum GLenum GLsizei void * image
Definition: glad.h:5132
GLint y
Definition: glcorearb.h:103
#define IMF_HIDDEN
Definition: ImfExport.h:55
virtual void clearChannels()=0
virtual IMFUTIL_EXPORT void resize(const IMATH_NAMESPACE::Box2i &dataWindow)
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 pLinear() const
std::map< std::string, DeepImageChannel * > ChannelMap
GLuint GLuint end
Definition: glcorearb.h:475
TypedDeepImageChannel< T > & typedChannel(const std::string &name)
#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
int xSampling() const
IMFUTIL_EXPORT void throwBadChannelNameOrType(const std::string &name) const
IMFUTIL_EXPORT DeepImageChannel * findChannel(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
bool operator==(const DeepImageLevel::ConstIterator &x, const DeepImageLevel::ConstIterator &y)
virtual IMFUTIL_EXPORT void shiftPixels(int dx, int dy)
GLint GLenum GLint x
Definition: glcorearb.h:409
IMFUTIL_EXPORT const std::string & name() const
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 OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:80
IMFUTIL_EXPORT SampleCountChannel & sampleCounts()
type
Definition: core.h:1059
TypedDeepImageChannel< T > * findTypedChannel(const std::string &name)
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat3.h:542
IMFUTIL_EXPORT Iterator()
bool operator!=(const DeepImageLevel::ConstIterator &x, const DeepImageLevel::ConstIterator &y)
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.
Definition: node.h:558