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 //
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_DEEP_IMAGE_LEVEL_H
36 #define INCLUDED_IMF_DEEP_IMAGE_LEVEL_H
37 
38 //----------------------------------------------------------------------------
39 //
40 // class DeepImageLevel
41 // class DeepImageLevel::Iterator
42 // class DeepImageLevel::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 "ImfDeepImageChannel.h"
50 #include "ImfSampleCountChannel.h"
51 #include "ImfImageLevel.h"
52 #include "ImfUtilExport.h"
53 
54 #include <string>
55 #include <map>
56 
58 
59 class DeepImage;
60 
61 class DeepImageLevel : public ImageLevel
62 {
63  public:
64 
65  //
66  // Access to the image to which the level belongs.
67  //
68 
70  DeepImage & deepImage ();
72  const DeepImage & deepImage () const;
73 
74 
75  //
76  // Access to deep 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 
94 
98  const DeepImageChannel * findChannel (const std::string& name) const;
99 
101  DeepImageChannel & channel (const std::string& name);
103  const DeepImageChannel & channel (const std::string& name) const;
104 
105  template <class T>
107  (const std::string& name);
108 
109  template <class T>
111  (const std::string& name) const;
112 
113  template <class T>
115  (const std::string& name);
116 
117  template <class T>
119  (const std::string& name) const;
120 
121  //
122  // Iterator-style access to deep channels
123  //
124 
125  typedef std::map <std::string, DeepImageChannel *> ChannelMap;
126 
127  class Iterator;
128  class ConstIterator;
129 
131  Iterator begin();
133  ConstIterator begin() const;
134 
136  Iterator end();
138  ConstIterator end() const;
139 
140  //
141  // Access to the sample count channel
142  //
143 
147  const SampleCountChannel & sampleCounts() const;
148 
149  private:
150 
151  friend class DeepImage;
152  friend class SampleCountChannel;
153 
154  //
155  // The constructor and destructor are private.
156  // Deep image levels exist only as part of a deep image.
157  //
158 
160  int xLevelNumber,
161  int yLevelNumber,
163 
164  ~DeepImageLevel ();
165 
166  void setSamplesToZero (size_t i,
167  unsigned int oldNumSamples,
168  unsigned int newNumSamples);
169 
170  void moveSampleList (size_t i,
171  unsigned int oldNumSamples,
172  unsigned int newNumSamples,
173  size_t newSampleListPosition);
174 
175  void moveSamplesToNewBuffer (const unsigned int * oldNumSamples,
176  const unsigned int * newNumSamples,
177  const size_t * newSampleListPositions);
178 
179  void initializeSampleLists ();
180 
181  virtual void resize (const IMATH_NAMESPACE::Box2i& dataWindow);
182 
183  virtual void shiftPixels (int dx, int dy);
184 
185  virtual void insertChannel (const std::string& name,
186  PixelType type,
187  int xSampling,
188  int ySampling,
189  bool pLinear);
190 
191  virtual void eraseChannel (const std::string& name);
192 
193  virtual void clearChannels ();
194 
195  virtual void renameChannel (const std::string &oldName,
196  const std::string &newName);
197 
198  virtual void renameChannels (const RenamingMap &oldToNewNames);
199 
200  ChannelMap _channels;
201  SampleCountChannel _sampleCounts;
202 };
203 
204 
206 {
207  public:
208 
210  Iterator ();
212  Iterator (const DeepImageLevel::ChannelMap::iterator& i);
213 
214 
215  //
216  // Advance the iterator
217  //
218 
220  Iterator & operator ++ ();
222  Iterator operator ++ (int);
223 
224 
225  //
226  // Access to the channel to which the iterator points,
227  // and to the name of that channel.
228  //
229 
231  const std::string & name () const;
233  DeepImageChannel & channel () const;
234 
235  private:
236 
238 
239  DeepImageLevel::ChannelMap::iterator _i;
240 };
241 
242 
244 {
245  public:
246 
248  ConstIterator ();
250  ConstIterator (const DeepImageLevel::ChannelMap::const_iterator& i);
253 
254 
255  //
256  // Advance the iterator
257  //
258 
260  ConstIterator & operator ++ ();
262  ConstIterator operator ++ (int);
263 
264 
265  //
266  // Access to the channel to which the iterator points,
267  // and to the name of that channel.
268  //
269 
271  const std::string & name () const;
273  const DeepImageChannel & channel () const;
274 
275  private:
276 
277  friend bool operator ==
278  (const ConstIterator &, const ConstIterator &);
279 
280  friend bool operator !=
281  (const ConstIterator &, const ConstIterator &);
282 
283  DeepImageLevel::ChannelMap::const_iterator _i;
284 };
285 
286 
287 //-----------------------------------------------------------------------------
288 // Implementation of inline functions
289 //-----------------------------------------------------------------------------
290 
291 template <class T>
294 {
295  return dynamic_cast <TypedDeepImageChannel<T>*> (findChannel (name));
296 }
297 
298 
299 template <class T>
302 {
303  return dynamic_cast <const TypedDeepImageChannel<T>*> (findChannel (name));
304 }
305 
306 
307 template <class T>
310 {
311  TypedDeepImageChannel<T> * ptr = findTypedChannel<T> (name);
312 
313  if (ptr == 0)
315 
316  return *ptr;
317 }
318 
319 
320 template <class T>
323 {
324  const TypedDeepImageChannel<T> * ptr = findTypedChannel<T> (name);
325 
326  if (ptr == 0)
328 
329  return *ptr;
330 }
331 
332 
333 inline SampleCountChannel &
335 {
336  return _sampleCounts;
337 }
338 
339 
340 inline const SampleCountChannel &
342 {
343  return _sampleCounts;
344 }
345 
346 
347 inline
349 {
350  // empty
351 }
352 
353 
354 inline
356  (const DeepImageLevel::ChannelMap::iterator& i)
357 :
358  _i (i)
359 {
360  // empty
361 }
362 
363 
364 inline DeepImageLevel::Iterator &
366 {
367  ++_i;
368  return *this;
369 }
370 
371 
374 {
375  Iterator tmp = *this;
376  ++_i;
377  return tmp;
378 }
379 
380 
381 inline const std::string &
383 {
384  return _i->first;
385 }
386 
387 
388 inline DeepImageChannel &
390 {
391  return *_i->second;
392 }
393 
394 
395 inline
397 {
398  // empty
399 }
400 
401 inline
403  (const DeepImageLevel::ChannelMap::const_iterator& i): _i (i)
404 {
405  // empty
406 }
407 
408 
409 inline
411  (const DeepImageLevel::Iterator& other): _i (other._i)
412 {
413  // empty
414 }
415 
418 {
419  ++_i;
420  return *this;
421 }
422 
423 
426 {
427  ConstIterator tmp = *this;
428  ++_i;
429  return tmp;
430 }
431 
432 
433 inline const std::string &
435 {
436  return _i->first;
437 }
438 
439 inline const DeepImageChannel &
441 {
442  return *_i->second;
443 }
444 
445 
446 inline bool
449 {
450  return x._i == y._i;
451 }
452 
453 
454 inline bool
457 {
458  return !(x == y);
459 }
460 
462 
463 #endif
IMFUTIL_EXPORT DeepImageChannel & channel() const
GLuint const GLchar * name
Definition: glew.h:1814
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:109
IMFUTIL_EXPORT DeepImageChannel & channel(const std::string &name)
int ySampling() const
int yLevelNumber() const
Definition: ImfImageLevel.h:76
IMFUTIL_EXPORT ConstIterator & operator++()
IMFUTIL_EXPORT const DeepImageChannel & channel() const
int xLevelNumber() const
Definition: ImfImageLevel.h:75
GLenum GLsizei GLenum GLenum const void * image
Definition: glew.h:4943
#define IMFUTIL_EXPORT
Definition: ImfUtilExport.h:44
IMFUTIL_EXPORT Iterator & operator++()
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 DeepImage & deepImage()
IMFUTIL_EXPORT Iterator begin()
PixelType
Definition: ImfPixelType.h:51
bool pLinear() const
TypedDeepImageChannel< T > & typedChannel(const std::string &name)
int xSampling() const
IMFUTIL_EXPORT void throwBadChannelNameOrType(const std::string &name) const
IMFUTIL_EXPORT DeepImageChannel * findChannel(const std::string &name)
bool operator==(const DeepImageLevel::ConstIterator &x, const DeepImageLevel::ConstIterator &y)
std::map< std::string, DeepImageChannel * > ChannelMap
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
GLsizei const GLchar *const * string
Definition: glew.h:1844
IMFUTIL_EXPORT const std::string & name() const
const void * ptr(const T *p)
Definition: format.h:3292
IMFUTIL_EXPORT Iterator end()
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:108
IMFUTIL_EXPORT SampleCountChannel & sampleCounts()
const IMATH_NAMESPACE::Box2i & dataWindow() const
Definition: ImfImageLevel.h:78
TypedDeepImageChannel< T > * findTypedChannel(const std::string &name)
IMFUTIL_EXPORT const std::string & name() const
bool operator!=(const DeepImageLevel::ConstIterator &x, const DeepImageLevel::ConstIterator &y)