image: remove access to w/h/s members
This commit is contained in:
parent
fdb12e57f6
commit
b5929b7b4a
58
image.cpp
58
image.cpp
@ -23,54 +23,20 @@ using util::image::buffer;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
util::image::buffer<T>::buffer (util::extent2u _size):
|
||||
buffer<T> (_size.w, _size.h)
|
||||
util::image::buffer<T>::buffer (util::extentu<2> _size):
|
||||
m_size (_size),
|
||||
m_stride (1, _size.w),
|
||||
m_data (std::make_unique<T[]> (_size.area ()))
|
||||
{ ; }
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
util::image::buffer<T>::buffer (size_t _w, size_t _h, size_t _s):
|
||||
w (_w),
|
||||
h (_h),
|
||||
s (_s),
|
||||
m_data (std::make_unique<T[]> (_h * _s))
|
||||
{
|
||||
CHECK_NEQ (w * h, 0);
|
||||
CHECK_GE (s, w);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
util::image::buffer<T>::buffer (size_t _w, size_t _h):
|
||||
buffer<T> (_w, _h, _w)
|
||||
{ ; }
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
util::image::buffer<T>::buffer (size_t _w,
|
||||
size_t _h,
|
||||
size_t _s,
|
||||
std::unique_ptr<T[]> &&_data):
|
||||
w (_w),
|
||||
h (_h),
|
||||
s (_s),
|
||||
m_data (std::move (_data))
|
||||
{
|
||||
CHECK_NEQ (w * h, 0);
|
||||
CHECK_GE (s, w);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
template <typename U>
|
||||
util::image::buffer<U>
|
||||
util::image::buffer<T>::alloc (void) const
|
||||
{
|
||||
return buffer<U> (w, h, s);
|
||||
return buffer<U> (m_size);
|
||||
}
|
||||
|
||||
|
||||
@ -102,8 +68,7 @@ template <typename T>
|
||||
const T&
|
||||
buffer<T>::operator[] (point<2,size_t> p) const
|
||||
{
|
||||
CHECK_LT (p.x, w);
|
||||
CHECK_LT (p.y, h);
|
||||
CHECK (util::all (p < size ()));
|
||||
|
||||
return begin ()[offset (p)];
|
||||
}
|
||||
@ -114,8 +79,7 @@ template <typename T>
|
||||
T&
|
||||
buffer<T>::operator[] (point<2,size_t> p)
|
||||
{
|
||||
CHECK_LT (p.x, w);
|
||||
CHECK_LT (p.y, h);
|
||||
CHECK (util::all (p < size ()));
|
||||
|
||||
return begin ()[offset (p)];
|
||||
}
|
||||
@ -126,7 +90,7 @@ template <typename T>
|
||||
const T&
|
||||
buffer<T>::operator[] (size_t idx) const
|
||||
{
|
||||
CHECK_LT (idx, h * s);
|
||||
CHECK_LT (idx, size ());
|
||||
|
||||
return begin ()[idx];
|
||||
}
|
||||
@ -137,7 +101,7 @@ template <typename T>
|
||||
T&
|
||||
buffer<T>::operator[] (size_t idx)
|
||||
{
|
||||
CHECK_LT (idx, h * s);
|
||||
CHECK_LT (idx, size ());
|
||||
|
||||
return begin ()[idx];
|
||||
}
|
||||
@ -166,7 +130,7 @@ template <typename T>
|
||||
T*
|
||||
buffer<T>::end (void)
|
||||
{
|
||||
return begin () + h * s;
|
||||
return begin () + m_size.back () * m_stride.back ();
|
||||
}
|
||||
|
||||
|
||||
@ -211,7 +175,7 @@ template <typename T>
|
||||
const T*
|
||||
buffer<T>::cend (void) const
|
||||
{
|
||||
return cbegin () + h * s;
|
||||
return cbegin () + m_size.back () * m_stride.back ();
|
||||
}
|
||||
|
||||
|
||||
|
14
image.hpp
14
image.hpp
@ -31,13 +31,13 @@ namespace util { namespace image {
|
||||
typedef T value_type;
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
buffer (util::extent2u);
|
||||
buffer (size_t w, size_t h);
|
||||
buffer (size_t w, size_t h, size_t s);
|
||||
buffer (size_t w, size_t h, size_t s, std::unique_ptr<T[]> &&data);
|
||||
buffer (util::extentu<2>);
|
||||
buffer (util::extentu<2>, std::unique_ptr<T[]> &&data);
|
||||
|
||||
buffer (const buffer<T>&) = delete;
|
||||
buffer (buffer<T> &&) = default;
|
||||
buffer& operator= (const buffer<T>&) = default;
|
||||
buffer& operator= (buffer<T>&&) = default;
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
/// allocate and return a buffer of the same dimensions. contents are undefined.
|
||||
@ -54,10 +54,6 @@ namespace util { namespace image {
|
||||
|
||||
constexpr bool is_packed (void) const;
|
||||
|
||||
size_t w;
|
||||
size_t h;
|
||||
size_t s;
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
constexpr size_t offset (point<2,size_t>) const;
|
||||
|
||||
@ -80,6 +76,8 @@ namespace util { namespace image {
|
||||
const T* cend (void) const;
|
||||
|
||||
private:
|
||||
util::extent2u m_size;
|
||||
util::vector2u m_stride;
|
||||
std::unique_ptr<T[]> m_data;
|
||||
};
|
||||
} }
|
||||
|
@ -25,7 +25,7 @@ namespace util { namespace image {
|
||||
constexpr extent2u
|
||||
buffer<T>::extent (void) const
|
||||
{
|
||||
return { w, h };
|
||||
return m_size;
|
||||
}
|
||||
|
||||
|
||||
@ -34,7 +34,7 @@ namespace util { namespace image {
|
||||
constexpr vector2u
|
||||
buffer<T>::stride (void) const
|
||||
{
|
||||
return { 1, s };
|
||||
return m_stride;
|
||||
}
|
||||
|
||||
|
||||
@ -52,7 +52,7 @@ namespace util { namespace image {
|
||||
constexpr size_t
|
||||
buffer<T>::size (void) const
|
||||
{
|
||||
return extent ()[1] * stride ()[1];
|
||||
return extent ().back () * stride ().back ();
|
||||
}
|
||||
|
||||
|
||||
@ -61,6 +61,6 @@ namespace util { namespace image {
|
||||
constexpr bool
|
||||
buffer<T>::is_packed (void) const
|
||||
{
|
||||
return stride ()[1] == extent ()[0];
|
||||
return stride ().back () == extent ().back ();
|
||||
}
|
||||
} }
|
||||
|
@ -10,7 +10,7 @@ main (void)
|
||||
|
||||
constexpr size_t W = 64;
|
||||
constexpr size_t H = 128;
|
||||
util::image::buffer<uint16_t> img (W, H);
|
||||
util::image::buffer<uint16_t> img ({W, H});
|
||||
|
||||
if (!img.is_packed ())
|
||||
tap.skip ("linear position probe requires packed image allocation");
|
||||
|
Loading…
Reference in New Issue
Block a user