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 "ImfExport.h"
53 #include <string>
54 #include <map>
55 
57 
58 class DeepImage;
59 
61 {
62  public:
63 
64  //
65  // Access to the image to which the level belongs.
66  //
67 
68  DeepImage & deepImage ();
69  const DeepImage & deepImage () const;
70 
71 
72  //
73  // Access to deep channels by name:
74  //
75  // findChannel(n) returns a pointer to the image channel with
76  // name n, or 0 if no such channel exists.
77  //
78  // channel(n) returns a reference to the image channel with
79  // name n, or throws an Iex::ArgExc exception if
80  // no such channel exists.
81  //
82  // findTypedChannel<T>(n) returns a pointer to the image channel with
83  // name n and type T, or 0 if no such channel
84  // exists.
85  //
86  // typedChannel(n) returns a reference to the image channel with
87  // name n and type T, or throws an Iex::ArgExc
88  // exception if no such channel exists.
89  //
90 
91 
92  DeepImageChannel * findChannel (const std::string& name);
93  const DeepImageChannel * findChannel (const std::string& name) const;
94 
95  DeepImageChannel & channel (const std::string& name);
96  const DeepImageChannel & channel (const std::string& name) const;
97 
98  template <class T>
99  TypedDeepImageChannel<T> * findTypedChannel
100  (const std::string& name);
101 
102  template <class T>
103  const TypedDeepImageChannel<T> * findTypedChannel
104  (const std::string& name) const;
105 
106  template <class T>
107  TypedDeepImageChannel<T> & typedChannel
108  (const std::string& name);
109 
110  template <class T>
111  const TypedDeepImageChannel<T> & typedChannel
112  (const std::string& name) const;
113 
114  //
115  // Iterator-style access to deep channels
116  //
117 
118  typedef std::map <std::string, DeepImageChannel *> ChannelMap;
119 
120  class Iterator;
121  class ConstIterator;
122 
123  Iterator begin();
124  ConstIterator begin() const;
125 
126  Iterator end();
127  ConstIterator end() const;
128 
129  //
130  // Access to the sample count channel
131  //
132 
133  SampleCountChannel & sampleCounts();
134  const SampleCountChannel & sampleCounts() const;
135 
136  private:
137 
138  friend class DeepImage;
139  friend class SampleCountChannel;
140 
141  //
142  // The constructor and destructor are private.
143  // Deep image levels exist only as part of a deep image.
144  //
145 
147  int xLevelNumber,
148  int yLevelNumber,
149  const IMATH_NAMESPACE::Box2i& dataWindow);
150 
151  ~DeepImageLevel ();
152 
153  void setSamplesToZero (size_t i,
154  unsigned int oldNumSamples,
155  unsigned int newNumSamples);
156 
157  void moveSampleList (size_t i,
158  unsigned int oldNumSamples,
159  unsigned int newNumSamples,
160  size_t newSampleListPosition);
161 
162  void moveSamplesToNewBuffer (const unsigned int * oldNumSamples,
163  const unsigned int * newNumSamples,
164  const size_t * newSampleListPositions);
165 
166  void initializeSampleLists ();
167 
168  virtual void resize (const IMATH_NAMESPACE::Box2i& dataWindow);
169 
170  virtual void shiftPixels (int dx, int dy);
171 
172  virtual void insertChannel (const std::string& name,
173  PixelType type,
174  int xSampling,
175  int ySampling,
176  bool pLinear);
177 
178  virtual void eraseChannel (const std::string& name);
179 
180  virtual void clearChannels ();
181 
182  virtual void renameChannel (const std::string &oldName,
183  const std::string &newName);
184 
185  virtual void renameChannels (const RenamingMap &oldToNewNames);
186 
187  ChannelMap _channels;
188  SampleCountChannel _sampleCounts;
189 };
190 
191 
193 {
194  public:
195 
196  Iterator ();
197  Iterator (const DeepImageLevel::ChannelMap::iterator& i);
198 
199 
200  //
201  // Advance the iterator
202  //
203 
205  Iterator operator ++ (int);
206 
207 
208  //
209  // Access to the channel to which the iterator points,
210  // and to the name of that channel.
211  //
212 
213  const std::string & name () const;
214  DeepImageChannel & channel () const;
215 
216  private:
217 
219 
220  DeepImageLevel::ChannelMap::iterator _i;
221 };
222 
223 
225 {
226  public:
227 
228  ConstIterator ();
229  ConstIterator (const DeepImageLevel::ChannelMap::const_iterator& i);
231 
232 
233  //
234  // Advance the iterator
235  //
236 
239 
240 
241  //
242  // Access to the channel to which the iterator points,
243  // and to the name of that channel.
244  //
245 
246  const std::string & name () const;
247  const DeepImageChannel & channel () const;
248 
249  private:
250 
251  friend bool operator ==
252  (const ConstIterator &, const ConstIterator &);
253 
254  friend bool operator !=
255  (const ConstIterator &, const ConstIterator &);
256 
257  DeepImageLevel::ChannelMap::const_iterator _i;
258 };
259 
260 
261 //-----------------------------------------------------------------------------
262 // Implementation of inline functions
263 //-----------------------------------------------------------------------------
264 
265 template <class T>
268 {
269  return dynamic_cast <TypedDeepImageChannel<T>*> (findChannel (name));
270 }
271 
272 
273 template <class T>
276 {
277  return dynamic_cast <const TypedDeepImageChannel<T>*> (findChannel (name));
278 }
279 
280 
281 template <class T>
284 {
285  TypedDeepImageChannel<T> * ptr = findTypedChannel<T> (name);
286 
287  if (ptr == 0)
289 
290  return *ptr;
291 }
292 
293 
294 template <class T>
297 {
298  const TypedDeepImageChannel<T> * ptr = findTypedChannel<T> (name);
299 
300  if (ptr == 0)
302 
303  return *ptr;
304 }
305 
306 
307 inline SampleCountChannel &
309 {
310  return _sampleCounts;
311 }
312 
313 
314 inline const SampleCountChannel &
316 {
317  return _sampleCounts;
318 }
319 
320 
321 inline
323 {
324  // empty
325 }
326 
327 
328 inline
330  (const DeepImageLevel::ChannelMap::iterator& i)
331 :
332  _i (i)
333 {
334  // empty
335 }
336 
337 
338 inline DeepImageLevel::Iterator &
340 {
341  ++_i;
342  return *this;
343 }
344 
345 
348 {
349  Iterator tmp = *this;
350  ++_i;
351  return tmp;
352 }
353 
354 
355 inline const std::string &
357 {
358  return _i->first;
359 }
360 
361 
362 inline DeepImageChannel &
364 {
365  return *_i->second;
366 }
367 
368 
369 inline
371 {
372  // empty
373 }
374 
375 inline
377  (const DeepImageLevel::ChannelMap::const_iterator& i): _i (i)
378 {
379  // empty
380 }
381 
382 
383 inline
385  (const DeepImageLevel::Iterator& other): _i (other._i)
386 {
387  // empty
388 }
389 
392 {
393  ++_i;
394  return *this;
395 }
396 
397 
400 {
401  ConstIterator tmp = *this;
402  ++_i;
403  return tmp;
404 }
405 
406 
407 inline const std::string &
409 {
410  return _i->first;
411 }
412 
413 inline const DeepImageChannel &
415 {
416  return *_i->second;
417 }
418 
419 
420 inline bool
423 {
424  return x._i == y._i;
425 }
426 
427 
428 inline bool
431 {
432  return !(x == y);
433 }
434 
436 
437 #endif
DeepImageChannel & channel() const
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:109
int ySampling() const
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
png_voidp ptr
Definition: png.h:2145
const DeepImageChannel & channel() const
GLint y
Definition: glcorearb.h:102
png_uint_32 i
Definition: png.h:2877
virtual void clearChannels()=0
png_bytepp image
Definition: png.h:1849
virtual void shiftPixels(int dx, int dy)
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER typedef std::map< std::string, std::string > RenamingMap
IMF_EXPORT void throwBadChannelNameOrType(const std::string &name) const
Box< V2i > Box2i
Definition: ImathBox.h:133
virtual void renameChannel(const std::string &oldName, const std::string &newName)=0
PixelType
Definition: ImfPixelType.h:51
bool pLinear() const
GLuint GLuint end
Definition: glcorearb.h:474
TypedDeepImageChannel< T > & typedChannel(const std::string &name)
int xSampling() const
#define IMF_EXPORT
Definition: ImfExport.h:59
virtual void renameChannels(const RenamingMap &oldToNewNames)=0
bool operator==(const DeepImageLevel::ConstIterator &x, const DeepImageLevel::ConstIterator &y)
GLuint const GLchar * name
Definition: glcorearb.h:785
std::map< std::string, DeepImageChannel * > ChannelMap
const std::string & name() const
virtual void insertChannel(const std::string &name, PixelType type, int xSampling, int ySampling, bool pLinear)=0
virtual void resize(const IMATH_NAMESPACE::Box2i &dataWindow)
virtual void eraseChannel(const std::string &name)=0
GLint GLenum GLint x
Definition: glcorearb.h:408
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:108
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
SampleCountChannel & sampleCounts()
DeepImageChannel * findChannel(const std::string &name)
TypedDeepImageChannel< T > * findTypedChannel(const std::string &name)
const std::string & name() const
bool operator!=(const DeepImageLevel::ConstIterator &x, const DeepImageLevel::ConstIterator &y)