13 #ifndef OGLPLUS_IMAGES_IMAGE_1107121519_HPP
14 #define OGLPLUS_IMAGES_IMAGE_1107121519_HPP
23 #include <oglplus/detail/aligned_pod_array.hpp>
48 GLsizei _width, _height, _depth, _channels;
50 oglplus::aux::AlignedPODArray _storage;
51 double (*_convert)(
void*);
54 static double _do_convert(
void* ptr)
56 assert(ptr !=
nullptr);
57 const double v = double(*static_cast<T*>(ptr));
58 const double n = double(_one((
T*)
nullptr));
62 bool _is_initialized(
void)
const;
74 return std::numeric_limits<T>::max();
77 static float _one(
float*)
82 static double _one(
double*)
88 bool _type_ok(
void)
const
96 assert(_is_initialized());
97 assert(_type_ok<T>());
98 return static_cast<T*
>(_storage.begin());
101 unsigned char* _begin_ub(
void)
103 return _begin<unsigned char>();
106 template <
typename T>
109 assert(_is_initialized());
110 assert(_type_ok<T>());
111 return static_cast<T*
>(_storage.end());
114 unsigned char* _end_ub(
void)
116 return _end<unsigned char>();
119 template <
typename T>
120 T& _at(
unsigned x,
unsigned y=0,
unsigned z=0)
122 return *
static_cast<T*
>(_storage.at(PixelPos(x, y, z)));
140 : _width(that._width)
141 , _height(that._height)
142 , _depth(that._depth)
143 , _channels(that._channels)
145 , _storage(that._storage)
146 , _convert(that._convert)
147 , _format(that._format)
148 , _internal(that._internal)
153 , _height(tmp._height)
155 , _channels(tmp._channels)
157 , _storage(std::move(tmp._storage))
158 , _convert(tmp._convert)
159 , _format(tmp._format)
160 , _internal(tmp._internal)
163 template <
typename T>
173 , _channels(channels)
175 , _storage(oglplus::aux::AlignedPODArray(data, _width*_height*_depth*_channels))
176 , _convert(&_do_convert<T>)
177 , _format(_get_def_pdf(channels))
178 , _internal(_get_def_pdif(channels))
181 template <
typename T>
193 , _channels(channels)
195 , _storage(oglplus::aux::AlignedPODArray(data, _width*_height*_depth*_channels))
196 , _convert(&_do_convert<T>)
198 , _internal(
internal)
204 _height = tmp._height;
206 _channels = tmp._channels;
208 _storage = std::move(tmp._storage);
209 _convert = tmp._convert;
210 _format = tmp._format;
211 _internal = tmp._internal;
224 if(i == 0)
return Width();
225 if(i == 1)
return Height();
226 if(i == 2)
return Depth();
228 assert(!
"Invalid image dimension specified");
260 assert(_is_initialized());
267 assert(_is_initialized());
274 assert(_is_initialized());
279 template <
typename T>
282 assert(_is_initialized());
283 assert(_type_ok<T>());
284 return static_cast<T*
>(_storage.begin());
290 assert(_is_initialized());
291 return _storage.begin();
297 assert(_is_initialized());
298 return _storage.size();
301 std::size_t PixelPos(
307 assert(_is_initialized());
311 assert(width <
Width());
312 assert(height <
Height());
313 assert(depth <
Depth());
315 return std::size_t(ppos*
Channels());
327 std::size_t ppos = PixelPos(width, height, depth);
329 _channels>0?_convert(_storage.at(ppos+0)):0.0,
330 _channels>1?_convert(_storage.at(ppos+1)):0.0,
331 _channels>2?_convert(_storage.at(ppos+2)):0.0,
332 _channels>3?_convert(_storage.at(ppos+3)):0.0
336 std::size_t ComponentPos(
343 std::size_t ppos = PixelPos(width, height, depth);
344 return std::size_t(ppos+component);
355 if(component >=
Channels())
return 0.0;
357 return _convert(_storage.at(ComponentPos(
366 template <
typename T>
374 assert(_type_ok<T>());
376 return *
static_cast<T*
>(_storage.at(ComponentPos(
388 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
389 #include <oglplus/images/image.ipp>
392 #endif // include guard
const void * RawData(void) const
Returns an untyped pointer to the data.
Definition: image.hpp:288
double Component(GLsizei width, GLsizei height, GLsizei depth, GLsizei component) const
Returns the component of the pixel at the specified coordinates.
Definition: image.hpp:348
PixelDataInternalFormat
OpenGL pixel data internal format enumeration.
Definition: pixel_data.hpp:79
GLsizei Channels(void) const
Returns the number of channels.
Definition: image.hpp:252
GLsizei Depth(void) const
Returns the depth of the image.
Definition: image.hpp:246
PixelDataType
OpenGL pixel data type enumeration.
Definition: pixel_data.hpp:29
GLsizei Width(void) const
Returns the width of the image.
Definition: image.hpp:234
PixelDataFormat
OpenGL pixel data format enumeration.
Definition: pixel_data.hpp:50
GLsizei Dimension(std::size_t i) const
Returns the i-th dimension of the image.
Definition: image.hpp:222
Data type-related declarations.
Pixel data-related declarations.
PixelDataFormat Format(void) const
Return the pixel data format.
Definition: image.hpp:265
Vector< double, 4 > Pixel(GLsizei width, GLsizei height, GLsizei depth) const
Returns the pixel at the specified coordinates.
Definition: image.hpp:319
GLsizei Height(void) const
Returns the height of the image.
Definition: image.hpp:240
Wrapper for (texture) image data.
Definition: image.hpp:45
PixelDataType Type(void) const
Returns the pixel data type.
Definition: image.hpp:258
T ComponentAs(GLsizei width, GLsizei height, GLsizei depth, GLsizei component) const
Returns the component of the pixel at the specified coordinates.
Definition: image.hpp:367
PixelDataInternalFormat InternalFormat(void) const
Return a suitable pixel data internal format.
Definition: image.hpp:272
const T * Data(void) const
Returns a pointer to the data.
Definition: image.hpp:280
std::size_t DataSize(void) const
Returns the size of data in bytes.
Definition: image.hpp:295
Basic template for vector types.
Definition: fwd.hpp:43