Commit b6267d7e authored by Davis King's avatar Davis King

Made the image view objects implement the generic image interface. Not sure

why I didn't do this a long time ago.
parent 771036ce
......@@ -293,6 +293,8 @@ namespace dlib
- sets the image to have 0 pixels in it.
!*/
long get_width_step() const { return _width_step; }
private:
char* _data;
......@@ -362,6 +364,8 @@ namespace dlib
}
#endif
long get_width_step() const { return _width_step; }
private:
const char* _data;
long _width_step;
......@@ -393,6 +397,14 @@ namespace dlib
- constructs a const_image_view from an image object
!*/
// Don't stack image views on image views since that's pointless and just slows the
// compilation.
template <typename T> image_view<T>& make_image_view ( image_view<T>& img) { return img; }
template <typename T> const image_view<T>& make_image_view ( const image_view<T>& img) { return img; }
template <typename T> const_image_view<T>& make_image_view ( const_image_view<T>& img) { return img; }
template <typename T> const const_image_view<T>& make_image_view ( const const_image_view<T>& img) { return img; }
// ----------------------------------------------------------------------------------------
template <typename image_type>
......@@ -431,6 +443,86 @@ namespace dlib
objects should provide their own overload of num_rows() if needed.
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// Make the image views implement the generic image interface
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template <typename T>
struct image_traits<image_view<T>>
{
typedef typename image_traits<T>::pixel_type pixel_type;
};
template <typename T>
struct image_traits<const image_view<T>>
{
typedef typename image_traits<T>::pixel_type pixel_type;
};
template <typename T>
inline long num_rows( const image_view<T>& img) { return img.nr(); }
template <typename T>
inline long num_columns( const image_view<T>& img) { return img.nc(); }
template <typename T>
inline void set_image_size( image_view<T>& img, long rows, long cols ) { img.set_size(rows,cols); }
template <typename T>
inline void* image_data( image_view<T>& img)
{
if (img.size() != 0)
return &img[0][0];
else
return 0;
}
template <typename T>
inline const void* image_data(
const image_view<T>& img
)
{
if (img.size() != 0)
return &img[0][0];
else
return 0;
}
template <typename T>
inline long width_step( const image_view<T>& img) { return img.get_width_step(); }
// ----------------------------------------------------------------------------------------
template <typename T>
struct image_traits<const_image_view<T>>
{
typedef typename image_traits<T>::pixel_type pixel_type;
};
template <typename T>
struct image_traits<const const_image_view<T>>
{
typedef typename image_traits<T>::pixel_type pixel_type;
};
template <typename T>
inline long num_rows( const const_image_view<T>& img) { return img.nr(); }
template <typename T>
inline long num_columns( const const_image_view<T>& img) { return img.nc(); }
template <typename T>
inline const void* image_data(
const const_image_view<T>& img
)
{
if (img.size() != 0)
return &img[0][0];
else
return 0;
}
template <typename T>
inline long width_step( const const_image_view<T>& img) { return img.get_width_step(); }
// ----------------------------------------------------------------------------------------
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment