HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImfDeepImageChannel.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_CHANNEL_H
7 #define INCLUDED_IMF_DEEP_IMAGE_CHANNEL_H
8 
9 //----------------------------------------------------------------------------
10 //
11 // class DeepImageChannel,
12 // template class TypedDeepImageChannel<T>
13 //
14 // For an explanation of images, levels and channels,
15 // see the comments in header file Image.h.
16 //
17 //----------------------------------------------------------------------------
18 
19 #include "ImfNamespace.h"
20 #include "ImfUtilExport.h"
21 
22 #include "ImfImageChannel.h"
23 #include "ImfImageLevel.h"
24 #include "ImfSampleCountChannel.h"
25 
26 #include "ImfDeepFrameBuffer.h"
27 
29 
30 class DeepImageLevel;
31 class SampleCountChannel;
32 
33 //
34 // Image channels:
35 //
36 // A TypedDeepImageChannel<T> holds the pixel data for a single channel
37 // of one level of a deep image. Each pixel in the channel contains an
38 // array of n samples of type T, where T is either half, float or
39 // unsigned int, and n is stored in a separate sample count channel.
40 // Sample storage is allocated only for pixels within the data window
41 // of the level.
42 //
43 
45 {
46 public:
47  //
48  // Construct an OpenEXR frame buffer slice for this channel.
49  // This function is needed reading an image from an OpenEXR
50  // file and for saving an image in an OpenEXR file.
51  //
52 
53  virtual DeepSlice slice () const = 0;
54 
55  //
56  // Access to the image level to which this channel belongs.
57  //
58 
59  DeepImageLevel& deepLevel ();
60  const DeepImageLevel& deepLevel () const;
61 
62  //
63  // Access to the sample count channel for this deep channel.
64  //
65 
66  SampleCountChannel& sampleCounts ();
67  const SampleCountChannel& sampleCounts () const;
68 
69 protected:
70  friend class DeepImageLevel;
71 
72  DeepImageChannel (DeepImageLevel& level, bool pLinear);
73  virtual ~DeepImageChannel ();
74 
75  DeepImageChannel (const DeepImageChannel& other) = delete;
76  DeepImageChannel& operator= (const DeepImageChannel& other) = delete;
77  DeepImageChannel (DeepImageChannel&& other) = delete;
78  DeepImageChannel& operator= (DeepImageChannel&& other) = delete;
79 
80  virtual void setSamplesToZero (
81  size_t i, unsigned int oldNumSamples, unsigned int newNumSamples) = 0;
82 
83  virtual void moveSampleList (
84  size_t i,
85  unsigned int oldNumSamples,
86  unsigned int newNumSamples,
87  size_t newSampleListPosition) = 0;
88 
89  virtual void moveSamplesToNewBuffer (
90  const unsigned int* oldNumSamples,
91  const unsigned int* newNumSamples,
92  const size_t* newSampleListPositions) = 0;
93 
94  virtual void initializeSampleLists () = 0;
95 
96  virtual void resize ();
97 
98  virtual void resetBasePointer () = 0;
99 };
100 
101 template <class T>
103  : public DeepImageChannel
104 {
105 public:
106  //
107  // The OpenEXR pixel type of this channel (HALF, FLOAT or UINT).
108  //
109 
110  virtual PixelType pixelType () const;
111 
112  //
113  // Construct an OpenEXR frame buffer slice for this channel.
114  // This function is needed reading an image from an OpenEXR
115  // file and for saving an image in an OpenEXR file.
116  //
117 
118  virtual DeepSlice slice () const;
119 
120  //
121  // Access to the pixel at pixel space location (x, y), without bounds
122  // checking. Accessing a location outside the data window of the image
123  // level results in undefined behavior.
124  //
125  // The pixel contains a pointer to an array of samples to type T. The
126  // number of samples in this array is sampleCounts().at(x,y).
127  //
128 
129  T* operator() (int x, int y);
130  const T* operator() (int x, int y) const;
131 
132  //
133  // Access to the pixel at pixel space location (x, y), with bounds
134  // checking. Accessing a location outside the data window of the
135  // image level throws an Iex::ArgExc exception.
136  //
137 
138  T* at (int x, int y);
139  const T* at (int x, int y) const;
140 
141  //
142  // Faster access to all pixels in a single horizontal row of the
143  // channel. Access is not bounds checked; accessing out of bounds
144  // rows or pixels results in undefined behavior.
145  //
146  // Rows are numbered from 0 to pixelsPerColumn()-1, and each row
147  // contains pixelsPerRow() values. The number of samples in
148  // row(r)[i] is sampleCounts().row(r)[i].
149  //
150 
151  T* const* row (int r);
152  const T* const* row (int r) const;
153 
154 private:
155  friend class DeepImageLevel;
156 
158  TypedDeepImageChannel (DeepImageLevel& level, bool pLinear);
160  virtual ~TypedDeepImageChannel ();
161 
162  TypedDeepImageChannel (const TypedDeepImageChannel& other) = delete;
164  operator= (const TypedDeepImageChannel& other) = delete;
165  TypedDeepImageChannel (TypedDeepImageChannel&& other) = delete;
167 
169  virtual void setSamplesToZero (
170  size_t i, unsigned int oldNumSamples, unsigned int newNumSamples);
171 
173  virtual void moveSampleList (
174  size_t i,
175  unsigned int oldNumSamples,
176  unsigned int newNumSamples,
177  size_t newSampleListPosition);
178 
180  virtual void moveSamplesToNewBuffer (
181  const unsigned int* oldNumSamples,
182  const unsigned int* newNumSamples,
183  const size_t* newSampleListPositions);
184 
186  virtual void initializeSampleLists ();
187 
189  virtual void resize ();
190 
192  virtual void resetBasePointer ();
193 
194  T** _sampleListPointers; // Array of pointers to per-pixel
195  //sample lists
196 
197  T** _base; // Base pointer for faster access
198  // to entries in _sampleListPointers
199 
200  T* _sampleBuffer; // Contiguous memory block that
201  // contains all sample lists for
202  // this channel
203 };
204 
205 //
206 // Channel typedefs for the pixel data types supported by OpenEXR.
207 //
208 
212 
213 //-----------------------------------------------------------------------------
214 // Implementation of templates and inline functions
215 //-----------------------------------------------------------------------------
216 
217 template <class T>
218 inline T*
220 {
221  return _base[y * pixelsPerRow () + x];
222 }
223 
224 template <class T>
225 inline const T*
227 {
228  return _base[y * pixelsPerRow () + x];
229 }
230 
231 template <class T>
232 inline T*
234 {
235  boundsCheck (x, y);
236  return _base[y * pixelsPerRow () + x];
237 }
238 
239 template <class T>
240 inline const T*
242 {
243  boundsCheck (x, y);
244  return _base[y * pixelsPerRow () + x];
245 }
246 
247 template <class T>
248 inline T* const*
250 {
251  return _base + r * pixelsPerRow ();
252 }
253 
254 template <class T>
255 inline const T* const*
257 {
258  return _base + r * pixelsPerRow ();
259 }
260 
261 #ifndef COMPILING_IMF_DEEP_IMAGE_CHANNEL
262 extern template class IMFUTIL_EXPORT_EXTERN_TEMPLATE
264 extern template class IMFUTIL_EXPORT_EXTERN_TEMPLATE
266 extern template class IMFUTIL_EXPORT_EXTERN_TEMPLATE
268 #endif
269 
271 
272 #endif
#define IMFUTIL_EXPORT_EXTERN_TEMPLATE
Definition: ImfUtilExport.h:56
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:83
T * operator()(int x, int y)
#define IMFUTIL_EXPORT_TEMPLATE_TYPE
Definition: ImfUtilExport.h:55
virtual PixelType pixelType() const =0
GLint level
Definition: glcorearb.h:108
virtual void resetBasePointer()=0
GLint y
Definition: glcorearb.h:103
virtual void resize()
TypedDeepImageChannel< half > DeepHalfChannel
virtual void moveSampleList(size_t i, unsigned int oldNumSamples, unsigned int newNumSamples, size_t newSampleListPosition)=0
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER enum IMF_EXPORT_ENUM PixelType
Definition: ImfPixelType.h:20
virtual void initializeSampleLists()=0
#define IMFUTIL_EXPORT
Definition: ImfUtilExport.h:51
virtual DeepSlice slice() const =0
GLint GLenum GLint x
Definition: glcorearb.h:409
DeepImageChannel & operator=(const DeepImageChannel &other)=delete
virtual void moveSamplesToNewBuffer(const unsigned int *oldNumSamples, const unsigned int *newNumSamples, const size_t *newSampleListPositions)=0
virtual IMFUTIL_EXPORT void resize()
TypedDeepImageChannel< unsigned int > DeepUIntChannel
LeafData & operator=(const LeafData &)=delete
#define IMFUTIL_HIDDEN
Definition: ImfUtilExport.h:52
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:80
TypedDeepImageChannel< float > DeepFloatChannel
GLenum GLenum GLsizei void * row
Definition: glad.h:5135
GLboolean r
Definition: glcorearb.h:1222
virtual void setSamplesToZero(size_t i, unsigned int oldNumSamples, unsigned int newNumSamples)=0