/home/andreas/src/svn/mapnik/include/mapnik/image_view.hpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * 
00003  * This file is part of Mapnik (c++ mapping toolkit)
00004  *
00005  * Copyright (C) 2006 Artem Pavlenko
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020  *
00021  *****************************************************************************/
00022 
00023 //$Id$
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 

Generated on Thu Jul 19 17:59:26 2007 for Mapnik by  doxygen 1.4.7