image: add pixel offset query
This commit is contained in:
parent
0899c16557
commit
d5f1506afd
13
image.cpp
13
image.cpp
@ -255,13 +255,22 @@ util::image::buffer<T>::downsample (float factor) const
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
size_t
|
||||||
|
buffer<T>::offset (point<2,size_t> p) const
|
||||||
|
{
|
||||||
|
return dot (stride (), p);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
template <typename T>
|
||||||
T
|
T
|
||||||
buffer<T>::operator[] (point<2,size_t> p) const
|
buffer<T>::operator[] (point<2,size_t> p) const
|
||||||
{
|
{
|
||||||
CHECK_LT (p.x, w);
|
CHECK_LT (p.x, w);
|
||||||
CHECK_LT (p.y, h);
|
CHECK_LT (p.y, h);
|
||||||
|
|
||||||
return begin ()[p.y * s + p.x];
|
return begin ()[offset (p)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -273,7 +282,7 @@ buffer<T>::operator[] (point<2,size_t> p)
|
|||||||
CHECK_LT (p.x, w);
|
CHECK_LT (p.x, w);
|
||||||
CHECK_LT (p.y, h);
|
CHECK_LT (p.y, h);
|
||||||
|
|
||||||
return begin ()[p.y * s + p.x];
|
return begin ()[offset (p)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,6 +61,8 @@ namespace util { namespace image {
|
|||||||
size_t s;
|
size_t s;
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
size_t offset (point<2,size_t>) const;
|
||||||
|
|
||||||
T operator[] (point<2,size_t>) const;
|
T operator[] (point<2,size_t>) const;
|
||||||
T& operator[] (point<2,size_t>);
|
T& operator[] (point<2,size_t>);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user