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 "ImfUtilExport.h"
20 #include "ImfNamespace.h"
21 
22 #include "ImfImageChannel.h"
23 #include "ImfSampleCountChannel.h"
24 #include "ImfImageLevel.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  //
49  // Construct an OpenEXR frame buffer slice for this channel.
50  // This function is needed reading an image from an OpenEXR
51  // file and for saving an image in an OpenEXR file.
52  //
53 
54  virtual DeepSlice slice () const = 0;
55 
56  //
57  // Access to the image level to which this channel belongs.
58  //
59 
60  DeepImageLevel & deepLevel();
61  const DeepImageLevel & deepLevel() const;
62 
63 
64  //
65  // Access to the sample count channel for this deep channel.
66  //
67 
68  SampleCountChannel & sampleCounts();
69  const SampleCountChannel & sampleCounts() const;
70 
71 
72  protected:
73 
74  friend class DeepImageLevel;
75 
76  DeepImageChannel (DeepImageLevel &level, bool pLinear);
77  virtual ~DeepImageChannel();
78 
79  DeepImageChannel (const DeepImageChannel& other) = delete;
80  DeepImageChannel& operator = (const DeepImageChannel& other) = delete;
81  DeepImageChannel (DeepImageChannel&& other) = delete;
82  DeepImageChannel& operator = (DeepImageChannel&& other) = delete;
83 
84  virtual void setSamplesToZero
85  (size_t i,
86  unsigned int oldNumSamples,
87  unsigned int newNumSamples) = 0;
88 
89  virtual void moveSampleList
90  (size_t i,
91  unsigned int oldNumSamples,
92  unsigned int newNumSamples,
93  size_t newSampleListPosition) = 0;
94 
95  virtual void moveSamplesToNewBuffer
96  (const unsigned int * oldNumSamples,
97  const unsigned int * newNumSamples,
98  const size_t * newSampleListPositions) = 0;
99 
100  virtual void initializeSampleLists () = 0;
101 
102  virtual void resize ();
103 
104  virtual void resetBasePointer () = 0;
105 };
106 
107 
108 template <class T>
110 {
111  public:
112 
113  //
114  // The OpenEXR pixel type of this channel (HALF, FLOAT or UINT).
115  //
116 
117  virtual PixelType pixelType () const;
118 
119 
120  //
121  // Construct an OpenEXR frame buffer slice for this channel.
122  // This function is needed reading an image from an OpenEXR
123  // file and for saving an image in an OpenEXR file.
124  //
125 
126  virtual DeepSlice slice () const;
127 
128 
129  //
130  // Access to the pixel at pixel space location (x, y), without bounds
131  // checking. Accessing a location outside the data window of the image
132  // level results in undefined behavior.
133  //
134  // The pixel contains a pointer to an array of samples to type T. The
135  // number of samples in this array is sampleCounts().at(x,y).
136  //
137 
138  T * operator () (int x, int y);
139  const T * operator () (int x, int y) const;
140 
141 
142  //
143  // Access to the pixel at pixel space location (x, y), with bounds
144  // checking. Accessing a location outside the data window of the
145  // image level throws an Iex::ArgExc exception.
146  //
147 
148  T * at (int x, int y);
149  const T * at (int x, int y) const;
150 
151  //
152  // Faster access to all pixels in a single horizontal row of the
153  // channel. Access is not bounds checked; accessing out of bounds
154  // rows or pixels results in undefined behavior.
155  //
156  // Rows are numbered from 0 to pixelsPerColumn()-1, and each row
157  // contains pixelsPerRow() values. The number of samples in
158  // row(r)[i] is sampleCounts().row(r)[i].
159  //
160 
161  T * const * row (int r);
162  const T * const * row (int r) const;
163 
164  private:
165 
166  friend class DeepImageLevel;
167 
169  TypedDeepImageChannel (DeepImageLevel &level, bool pLinear);
171  virtual ~TypedDeepImageChannel ();
172 
173  TypedDeepImageChannel (const TypedDeepImageChannel& other) = delete;
175  TypedDeepImageChannel (TypedDeepImageChannel&& other) = delete;
177 
179  virtual void setSamplesToZero
180  (size_t i,
181  unsigned int oldNumSamples,
182  unsigned int newNumSamples);
183 
185  virtual void moveSampleList
186  (size_t i,
187  unsigned int oldNumSamples,
188  unsigned int newNumSamples,
189  size_t newSampleListPosition);
190 
192  virtual void moveSamplesToNewBuffer
193  (const unsigned int * oldNumSamples,
194  const unsigned int * newNumSamples,
195  const size_t * newSampleListPositions);
196 
198  virtual void initializeSampleLists ();
199 
201  virtual void resize ();
202 
204  virtual void resetBasePointer ();
205 
206  T ** _sampleListPointers; // Array of pointers to per-pixel
207  //sample lists
208 
209  T ** _base; // Base pointer for faster access
210  // to entries in _sampleListPointers
211 
212  T * _sampleBuffer; // Contiguous memory block that
213  // contains all sample lists for
214  // this channel
215 };
216 
217 
218 //
219 // Channel typedefs for the pixel data types supported by OpenEXR.
220 //
221 
225 
226 //-----------------------------------------------------------------------------
227 // Implementation of templates and inline functions
228 //-----------------------------------------------------------------------------
229 
230 template <class T>
231 inline T *
233 {
234  return _base[y * pixelsPerRow() + x];
235 }
236 
237 
238 template <class T>
239 inline const T *
241 {
242  return _base[y * pixelsPerRow() + x];
243 }
244 
245 
246 template <class T>
247 inline T *
249 {
250  boundsCheck (x, y);
251  return _base[y * pixelsPerRow() + x];
252 }
253 
254 
255 template <class T>
256 inline const T *
258 {
259  boundsCheck (x, y);
260  return _base[y * pixelsPerRow() + x];
261 }
262 
263 
264 template <class T>
265 inline T * const *
267 {
268  return _base + r * pixelsPerRow();
269 }
270 
271 
272 template <class T>
273 inline const T * const *
275 {
276  return _base + r * pixelsPerRow();
277 }
278 
279 #ifndef COMPILING_IMF_DEEP_IMAGE_CHANNEL
283 #endif
284 
286 
287 #endif
#define IMFUTIL_EXPORT_EXTERN_TEMPLATE
Definition: ImfUtilExport.h:56
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:80
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:22
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
#define IMFUTIL_HIDDEN
Definition: ImfUtilExport.h:52
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:79
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