00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef IMAGE_VIEW_HPP
00026 #define IMAGE_VIEW_HPP
00027
00028
00029 namespace mapnik {
00030
00031 template <typename T>
00032 class image_view
00033 {
00034 typedef typename T::pixel_type pixel_type;
00035 public:
00036 image_view(unsigned x, unsigned y, unsigned width, unsigned height, T const& data)
00037 : x_(x),
00038 y_(y),
00039 width_(width),
00040 height_(height),
00041 data_(data)
00042 {
00043 if (x_ >= data_.width()) x_=data_.width()-1;
00044 if (y_ >= data_.height()) x_=data_.height()-1;
00045 if (x_ + width_ > data_.width()) width_= data_.width() - x_;
00046 if (y_ + height_ > data_.height()) height_= data_.height() - y_;
00047 }
00048
00049 ~image_view() {}
00050
00051 image_view(image_view<T> const& rhs)
00052 : x_(rhs.x_),
00053 y_(rhs.y_),
00054 width_(rhs.width_),
00055 height_(rhs.height_),
00056 data_(rhs.data_) {}
00057
00058 image_view<T> & operator=(image_view<T> const& rhs)
00059 {
00060 if (&rhs==this) return *this;
00061 x_ = rhs.x_;
00062 y_ = rhs.y_;
00063 width_ = rhs.width_;
00064 height_ = rhs.height_;
00065 data_ = rhs.data_;
00066 }
00067
00068 inline unsigned x() const
00069 {
00070 return x_;
00071 }
00072
00073 inline unsigned y() const
00074 {
00075 return y_;
00076 }
00077
00078 inline unsigned width() const
00079 {
00080 return width_;
00081 }
00082 inline unsigned height() const
00083 {
00084 return height_;
00085 }
00086
00087 inline const pixel_type* getRow(unsigned row) const
00088 {
00089 return data_.getRow(row + y_) + x_;
00090 }
00091
00092 private:
00093 unsigned x_;
00094 unsigned y_;
00095 unsigned width_;
00096 unsigned height_;
00097 T const& data_;
00098 };
00099 }
00100
00101 #endif // IMAGE_VIEW_HPP
00102