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 "ImfImageLevel.h"
21 #include "ImfUtilExport.h"
22 
23 #include "ImfFrameBuffer.h"
24 #include "ImfPixelType.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  // Construct an OpenEXR frame buffer slice for this channel.
46  // This function is needed reading an image from an OpenEXR
47  // file and for saving an image in an OpenEXR file.
48  //
49 
50  virtual Slice slice () const = 0;
51 
52  //
53  // Access to the flat image level to which this channel belongs.
54  //
55 
56  FlatImageLevel& flatLevel ();
57  const FlatImageLevel& flatLevel () const;
58 
59 protected:
60  friend class FlatImageLevel;
61 
63  FlatImageLevel& level, int xSampling, int ySampling, bool pLinear);
64 
65  virtual ~FlatImageChannel ();
66 
67  FlatImageChannel (const FlatImageChannel& other) = delete;
68  FlatImageChannel& operator= (const FlatImageChannel& other) = delete;
69  FlatImageChannel (FlatImageChannel&& other) = delete;
70  FlatImageChannel& operator= (FlatImageChannel&& other) = delete;
71 
72  virtual void resize ();
73 
74  virtual void resetBasePointer () = 0;
75 };
76 
77 template <class T>
79  : public FlatImageChannel
80 {
81 public:
82  //
83  // The OpenEXR pixel type of this channel (HALF, FLOAT or UINT).
84  //
85 
86  virtual PixelType pixelType () const;
87 
88  //
89  // Construct an OpenEXR frame buffer slice for this channel.
90  //
91 
92  virtual Slice slice () const;
93 
94  //
95  // Access to the pixel at pixel space location (x, y), without
96  // bounds checking. Accessing a location outside the data window
97  // of the image level results in undefined behavior.
98  //
99 
100  T& operator() (int x, int y);
101  const T& operator() (int x, int y) const;
102 
103  //
104  // Access to the pixel at pixel space location (x, y), with bounds
105  // checking. Accessing a location outside the data window of the
106  // image level throws an Iex::ArgExc exception.
107  //
108 
109  T& at (int x, int y);
110  const T& at (int x, int y) const;
111 
112  //
113  // Faster access to all pixels in a single horizontal row of the
114  // channel. Rows are numbered from 0 to pixelsPerColumn()-1, and
115  // each row contains pixelsPerRow() values.
116  // Access is not bounds checked; accessing out of bounds rows or
117  // pixels results in undefined behavior.
118  //
119 
120  T* row (int r);
121  const T* row (int r) const;
122 
123 private:
124  friend class FlatImageLevel;
125 
126  //
127  // The constructor and destructor are not public because flat
128  // image channels exist only as parts of a flat image level.
129  //
130 
133  FlatImageLevel& level, int xSampling, int ySampling, bool pLinear);
134 
136  virtual ~TypedFlatImageChannel ();
137 
138  TypedFlatImageChannel (const TypedFlatImageChannel& other) = delete;
140  operator= (const TypedFlatImageChannel& other) = delete;
141  TypedFlatImageChannel (TypedFlatImageChannel&& other) = delete;
143 
145  virtual void resize ();
146 
148  virtual void resetBasePointer ();
149 
150  T* _pixels; // Pointer to allocated storage
151  T* _base; // Base pointer for faster pixel access
152 };
153 
154 //
155 // Channel typedefs for the pixel data types supported by OpenEXR.
156 //
157 
161 
162 //-----------------------------------------------------------------------------
163 // Implementation of templates and inline functions
164 //-----------------------------------------------------------------------------
165 
166 template <class T>
167 inline T&
169 {
170  return _base[(y / ySampling ()) * pixelsPerRow () + (x / xSampling ())];
171 }
172 
173 template <class T>
174 inline const T&
176 {
177  return _base[(y / ySampling ()) * pixelsPerRow () + (x / xSampling ())];
178 }
179 
180 template <class T>
181 inline T&
183 {
184  boundsCheck (x, y);
185  return _base[(y / ySampling ()) * pixelsPerRow () + (x / xSampling ())];
186 }
187 
188 template <class T>
189 inline const T&
191 {
192  boundsCheck (x, y);
193  return _base[(y / ySampling ()) * pixelsPerRow () + (x / xSampling ())];
194 }
195 
196 template <class T>
197 inline T*
199 {
200  return _base + r * pixelsPerRow ();
201 }
202 
203 template <class T>
204 inline const T*
206 {
207  return _base + n * pixelsPerRow ();
208 }
209 
210 #ifndef COMPILING_IMF_FLAT_IMAGE_CHANNEL
211 extern template class IMFUTIL_EXPORT_EXTERN_TEMPLATE
213 extern template class IMFUTIL_EXPORT_EXTERN_TEMPLATE
215 extern template class IMFUTIL_EXPORT_EXTERN_TEMPLATE
217 #endif
218 
220 
221 #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:83
#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:20
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()
LeafData & operator=(const LeafData &)=delete
#define IMFUTIL_HIDDEN
Definition: ImfUtilExport.h:52
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:80
GLenum GLenum GLsizei void * row
Definition: glad.h:5135
GLboolean r
Definition: glcorearb.h:1222
TypedFlatImageChannel< unsigned int > FlatUIntChannel
virtual Slice slice() const =0