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 public:
00035 typedef typename T::pixel_type pixel_type;
00036
00037 image_view(unsigned x, unsigned y, unsigned width, unsigned height, T const& data)
00038 : x_(x),
00039 y_(y),
00040 width_(width),
00041 height_(height),
00042 data_(data)
00043 {
00044 if (x_ >= data_.width()) x_=data_.width()-1;
00045 if (y_ >= data_.height()) x_=data_.height()-1;
00046 if (x_ + width_ > data_.width()) width_= data_.width() - x_;
00047 if (y_ + height_ > data_.height()) height_= data_.height() - y_;
00048 }
00049
00050 ~image_view() {}
00051
00052 image_view(image_view<T> const& rhs)
00053 : x_(rhs.x_),
00054 y_(rhs.y_),
00055 width_(rhs.width_),
00056 height_(rhs.height_),
00057 data_(rhs.data_) {}
00058
00059 image_view<T> & operator=(image_view<T> const& rhs)
00060 {
00061 if (&rhs==this) return *this;
00062 x_ = rhs.x_;
00063 y_ = rhs.y_;
00064 width_ = rhs.width_;
00065 height_ = rhs.height_;
00066 data_ = rhs.data_;
00067 }
00068
00069 inline unsigned x() const
00070 {
00071 return x_;
00072 }
00073
00074 inline unsigned y() const
00075 {
00076 return y_;
00077 }
00078
00079 inline unsigned width() const
00080 {
00081 return width_;
00082 }
00083 inline unsigned height() const
00084 {
00085 return height_;
00086 }
00087
00088 inline const pixel_type* getRow(unsigned row) const
00089 {
00090 return data_.getRow(row + y_) + x_;
00091 }
00092 inline T& data()
00093 {
00094 return data_;
00095 }
00096 inline T const& data() const
00097 {
00098 return data_;
00099 }
00100
00101 private:
00102 unsigned x_;
00103 unsigned y_;
00104 unsigned width_;
00105 unsigned height_;
00106 T const& data_;
00107 };
00108 }
00109
00110 #endif // IMAGE_VIEW_HPP
00111