image.hpp

Go to the documentation of this file.
00001 /*
00002 **    TP 4ETI CPE Lyon
00003 **    Copyright (C) 2011 Damien Rohmer
00004 **
00005 **    This program is free software: you can redistribute it and/or modify
00006 **    it under the terms of the GNU General Public License as published by
00007 **    the Free Software Foundation, either version 3 of the License, or
00008 **    (at your option) any later version.
00009 **
00010 **   This program is distributed in the hope that it will be useful,
00011 **    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 **    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 **    GNU General Public License for more details.
00014 **
00015 **    You should have received a copy of the GNU General Public License
00016 **    along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 */
00018 
00019 
00020 #ifndef _IMAGE_HPP_
00021 #define _IMAGE_HPP_
00022 
00023 #include <iostream>
00024 #include <vector>
00025 #include <exception_cpe.hpp>
00026 #include <p2d.hpp>
00027 
00028 
00029 
00030 namespace cpe
00031 {
00032 
00033     class color;
00034 
00036     class image
00037     {
00038     public:
00039 
00040         // ********************************************* //
00041         // ********************************************* //
00042         //  CONSTRUCTORS
00043         // ********************************************* //
00044         // ********************************************* //
00045 
00047         image();
00051         image(const unsigned int& N);
00056         image(const unsigned int& Nx,const unsigned int& Ny);
00060         image(const std::string& filename);
00061 
00062 
00063         // ********************************************* //
00064         // ********************************************* //
00065         //  Picture Size
00066         // ********************************************* //
00067         // ********************************************* //
00068 
00070         const unsigned int& get_Nx() const;
00072         const unsigned int& get_Ny() const;
00073 
00077         void resize(const unsigned int& N);
00082         void resize(const unsigned int& Nx,const unsigned int& Ny);
00083 
00088         void reshape(const unsigned int& Nx2);
00089 
00094         bool check_position(const p2d& u) const
00095         { return (u.x()<0 || u.x()>=static_cast<int>(internal_Nx) || u.y()<0 || u.y()>=static_cast<int>(internal_Ny))?false:true; }
00096 
00097 
00098         // ********************************************* //
00099         // ********************************************* //
00100         //  Pixel access
00101         // ********************************************* //
00102         // ********************************************* //
00103 
00108         void set_pixel(const p2d& u,const color& c);
00113         void get_pixel(const p2d& u,color *c) const;
00114 
00118         const unsigned char& get_r(const p2d& u) const;
00122         const unsigned char& get_g(const p2d& u) const;
00126         const unsigned char& get_b(const p2d& u) const;
00127 
00129         const std::vector<unsigned char>& get_data() const;
00131         std::vector<unsigned char>& get_data();
00132 
00133 
00134         // ********************************************* //
00135         // ********************************************* //
00136         //  Special pixel filling
00137         // ********************************************* //
00138         // ********************************************* //
00139 
00143         void fill(const color& c);
00149         void fill_rectangle(const p2d& u1,const p2d& u2,const color& c);
00150 
00151 
00152         // ********************************************* //
00153         // ********************************************* //
00154         //  I/O
00155         // ********************************************* //
00156         // ********************************************* //
00157 
00161         void export_ppm(const std::string& filename);
00162 
00163 
00164     protected:
00165 
00167         int coordinate_to_index(const p2d& u) const;
00168 
00169     private:
00170 
00171 
00172         // ********************************************* //
00173         // ********************************************* //
00174         //  Internal data
00175         // ********************************************* //
00176         // ********************************************* //
00177 
00182         std::vector<unsigned char> internal_data;
00184         unsigned int internal_Nx;
00186         unsigned int internal_Ny;
00187 
00188         // ********************************************* //
00189         // ********************************************* //
00190         //  Internal I/O
00191         // ********************************************* //
00192         // ********************************************* //
00193 
00197         static image read_ppm(const std::string& filename);
00198     };
00199 
00200 
00202     class exception_image : public exception_cpe
00203     {
00204     public:
00205 
00207         exception_image():exception_cpe(){}
00209         exception_image(const std::string& msg,const std::string& file,const std::string& caller,const int& line):exception_cpe(msg,file,caller,line){}
00210     };
00211 }
00212 
00213 #endif
Generated on Mon Apr 18 20:43:30 2011 by  doxygen 1.6.3