HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImfFlatImageChannel.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_FLAT_IMAGE_CHANNEL_H
7 #define INCLUDED_IMF_FLAT_IMAGE_CHANNEL_H
8 
9 //----------------------------------------------------------------------------
10 //
11 // class FlatImageChannel,
12 // template class TypedFlatImageChannel<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 "ImfImageChannel.h"
20 #include "ImfUtilExport.h"
21 #include "ImfImageLevel.h"
22 
23 #include "ImfPixelType.h"
24 #include "ImfFrameBuffer.h"
25 #include <ImathBox.h>
26 #include <half.h>
27 
29 
30 class FlatImageLevel;
31 
32 //
33 // Image channels:
34 //
35 // A TypedFlatImageChannel<T> holds the pixel data for a single channel
36 // of one level of a flat image. The pixels in the channel are of type T,
37 // where T is either half, float or unsigned int. Storage is allocated
38 // only for pixels within the data window of the level.
39 //
40 
42 {
43  public:
44 
45  //
46  // Construct an OpenEXR frame buffer slice for this channel.
47  // This function is needed reading an image from an OpenEXR
48  // file and for saving an image in an OpenEXR file.
49  //
50 
51  virtual Slice slice () const = 0;
52 
53 
54  //
55  // Access to the flat image level to which this channel belongs.
56  //
57 
58  FlatImageLevel & flatLevel ();
59  const FlatImageLevel & flatLevel () const;
60 
61  protected:
62 
63  friend class FlatImageLevel;
64 
66  int xSampling,
67  int ySampling,
68  bool pLinear);
69 
70  virtual ~FlatImageChannel();
71 
72  FlatImageChannel (const FlatImageChannel& other) = delete;
73  FlatImageChannel& operator = (const FlatImageChannel& other) = delete;
74  FlatImageChannel (FlatImageChannel&& other) = delete;
75  FlatImageChannel& operator = (FlatImageChannel&& other) = delete;
76 
77  virtual void resize ();
78 
79  virtual void resetBasePointer () = 0;
80 };
81 
82 template <class T>
84 {
85  public:
86 
87  //
88  // The OpenEXR pixel type of this channel (HALF, FLOAT or UINT).
89  //
90 
91  virtual PixelType pixelType () const;
92 
93 
94  //
95  // Construct an OpenEXR frame buffer slice for this channel.
96  //
97 
98  virtual Slice slice () const;
99 
100 
101  //
102  // Access to the pixel at pixel space location (x, y), without
103  // bounds checking. Accessing a location outside the data window
104  // of the image level results in undefined behavior.
105  //
106 
107  T & operator () (int x, int y);
108  const T & operator () (int x, int y) const;
109 
110 
111  //
112  // Access to the pixel at pixel space location (x, y), with bounds
113  // checking. Accessing a location outside the data window of the
114  // image level throws an Iex::ArgExc exception.
115  //
116 
117  T & at (int x, int y);
118  const T & at (int x, int y) const;
119 
120  //
121  // Faster access to all pixels in a single horizontal row of the
122  // channel. Rows are numbered from 0 to pixelsPerColumn()-1, and
123  // each row contains pixelsPerRow() values.
124  // Access is not bounds checked; accessing out of bounds rows or
125  // pixels results in undefined behavior.
126  //
127 
128  T * row (int r);
129  const T * row (int r) const;
130 
131  private:
132 
133  friend class FlatImageLevel;
134 
135  //
136  // The constructor and destructor are not public because flat
137  // image channels exist only as parts of a flat image level.
138  //
139 
142  int xSampling,
143  int ySampling,
144  bool pLinear);
145 
147  virtual ~TypedFlatImageChannel ();
148 
149  TypedFlatImageChannel (const TypedFlatImageChannel& other) = delete;
151  TypedFlatImageChannel (TypedFlatImageChannel&& other) = delete;
153 
155  virtual void resize ();
156 
158  virtual void resetBasePointer ();
159 
160  T * _pixels; // Pointer to allocated storage
161  T * _base; // Base pointer for faster pixel access
162 };
163 
164 
165 //
166 // Channel typedefs for the pixel data types supported by OpenEXR.
167 //
168 
172 
173 
174 //-----------------------------------------------------------------------------
175 // Implementation of templates and inline functions
176 //-----------------------------------------------------------------------------
177 
178 
179 
180 
181 template <class T>
182 inline T &
184 {
185  return _base[(y / ySampling()) * pixelsPerRow() + (x / xSampling())];
186 }
187 
188 
189 template <class T>
190 inline const T &
192 {
193  return _base[(y / ySampling()) * pixelsPerRow() + (x / xSampling())];
194 }
195 
196 
197 template <class T>
198 inline T &
200 {
201  boundsCheck (x, y);
202  return _base[(y / ySampling()) * pixelsPerRow() + (x / xSampling())];
203 }
204 
205 
206 template <class T>
207 inline const T &
209 {
210  boundsCheck (x, y);
211  return _base[(y / ySampling()) * pixelsPerRow() + (x / xSampling())];
212 }
213 
214 
215 template <class T>
216 inline T *
218 {
219  return _base + r * pixelsPerRow();
220 }
221 
222 
223 template <class T>
224 inline const T *
226 {
227  return _base + n * pixelsPerRow();
228 }
229 
230 #ifndef COMPILING_IMF_FLAT_IMAGE_CHANNEL
234 #endif
235 
237 
238 #endif
FlatImageChannel & operator=(const FlatImageChannel &other)=delete
#define IMFUTIL_EXPORT_EXTERN_TEMPLATE
Definition: ImfUtilExport.h:56
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:80
#define IMFUTIL_EXPORT_TEMPLATE_TYPE
Definition: ImfUtilExport.h:55
virtual void resize()
virtual PixelType pixelType() const =0
GLint level
Definition: glcorearb.h:108
GLint y
Definition: glcorearb.h:103
GLdouble n
Definition: glcorearb.h:2008
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER enum IMF_EXPORT_ENUM PixelType
Definition: ImfPixelType.h:22
TypedFlatImageChannel< float > FlatFloatChannel
TypedFlatImageChannel< half > FlatHalfChannel
#define IMFUTIL_EXPORT
Definition: ImfUtilExport.h:51
GLint GLenum GLint x
Definition: glcorearb.h:409
T & operator()(int x, int y)
virtual void resetBasePointer()=0
virtual IMFUTIL_EXPORT void resize()
#define IMFUTIL_HIDDEN
Definition: ImfUtilExport.h:52
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:79
GLenum GLenum GLsizei void * row
Definition: glad.h:5135
GLboolean r
Definition: glcorearb.h:1222
TypedFlatImageChannel< unsigned int > FlatUIntChannel
virtual Slice slice() const =0