/home/neoflo/smb4k/SERVEUR/Millie/trunk/src/Image.cpp

Aller à la documentation de ce fichier.
00001 /******************************************************************************
00002  *       __    _    _   _       _       _   _____                             *
00003  *       | \  / |  | | | |     | |     | |  | ___|                            *
00004  *       |  \/  |  | | | |     | |     | |  | |_                              *
00005  *       |      |  | | | |     | |     | |  |  _|                             *
00006  *       | |\/| |  | | | |__   | |__   | |  | |__                             *
00007  *       |_|  |_|  |_| |____|  |____|  |_|  |____|                            *
00008  * __________________________________________________________________________ *
00009  *                 Multifunctional Library For Image Processing               *
00010  *                                                                            *
00011  *                                                                            *
00012  *                                                                            *
00013  *      (c) Copyright 2007 by Humbert Florent                                 *
00014  *                                                                            *
00015  *      This program is free software; you can redistribute it and/or modify  *
00016  *      it under the terms of the GNU General Public License as published by  *
00017  *      the Free Software Foundation; only version 2 of the License.          *
00018  *                                                                            *
00019  *      This program is distributed in the hope that it will be useful,       *
00020  *      but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00021  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00022  *      GNU General Public License for more details.                          *
00023  *                                                                            *
00024  *      You should have received a copy of the GNU General Public License     *
00025  *      along with this program; if not, write to the Free Software           *
00026  *      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA             *
00027  *      02111-1307, USA.                                                      *
00028  ******************************************************************************/
00029 
00032 #ifdef _IMAGE_HPP_
00033 #include "Image.hpp"
00034 #include <iostream>
00035 
00036 
00037 
00038 template <typename T>
00039 TImage<T>::TImage(int largeur, int hauteur, int nbcanaux)
00040 {
00041   if(largeur< 0 || hauteur < 0 || nbcanaux <=0)
00042   {
00043     throw IllegalArgument("Image::Image");
00044   }
00045 
00046   _nbcanaux = nbcanaux;
00047   _largeur = largeur;
00048   _hauteur = hauteur;
00049 
00050   TImageMono<T> * current;
00051 
00052   for(int i = 0; i<nbcanaux; i++)
00053   {
00054     current = new TImageMono<T>(largeur, hauteur);
00055     _canaux.push_back(current);
00056   }
00057 
00058 }
00059 
00060 template <typename T>
00061 TImage<T>::TImage(int nbcanaux)
00062 {
00063   if(nbcanaux <=0)
00064     throw IllegalArgument("Image::Image");
00065 
00066   _nbcanaux = nbcanaux;
00067   _largeur = 0;
00068   _hauteur = 0;
00069 
00070   TImageMono<T> * current;
00071 
00072   for(int i = 0; i<nbcanaux; i++)
00073   {
00074     current = new TImageMono<T>();
00075     _canaux.push_back(current);
00076   }
00077 
00078 }
00079 
00080 
00081 template <typename T>
00082 TImage<T>::~TImage()
00083 {
00084   TImageMono<T> * _current;
00085   while(!_canaux.empty())
00086   {
00087     _current = _canaux.back();
00088     delete _current;
00089     _canaux.pop_back();
00090   }
00091 }
00092 
00093 template <typename T>
00094 int TImage<T>::getNumComponents() const
00095 {
00096   return _nbcanaux;
00097 }
00098 
00099 template <typename T>
00100 T TImage<T>::getPixel(int x, int y, int numcanal) const
00101 {
00102 #ifndef _MILLIE_DANGEROUS_OPTIMIZATIONS_
00103   if(numcanal <0 | numcanal> getNumComponents())
00104     throw OutOfRange("dans Image::getPixel");
00105 #endif
00106   return _canaux[numcanal]->getPixel(x, y);
00107 }
00108 
00109 template <typename T>
00110 void TImage<T>::setPixel(int x, int y, int numcanal, T  value)
00111 {
00112 #ifndef _MILLIE_DANGEROUS_OPTIMIZATIONS_
00113   if(numcanal <0 | numcanal> getNumComponents())
00114     throw OutOfRange("dans Image::setPixel");
00115 #endif
00116 
00117   _canaux[numcanal]->setPixel(x, y, value);
00118 }
00119 
00120 template <typename T>
00121 void TImage<T>::addToPixel(int x, int y, int numcanal, T  value)
00122 {
00123 #ifndef _MILLIE_DANGEROUS_OPTIMIZATIONS_
00124   if(numcanal <0 | numcanal> getNumComponents())
00125     throw OutOfRange("dans Image::setPixel");
00126 #endif
00127   _canaux[numcanal]->addToPixel(x, y, value);
00128 }
00129 
00130 template <typename T>
00131 int TImage<T>::getWidth() const
00132 {
00133   return _largeur;
00134 }
00135 
00136 template <typename T>
00137 int TImage<T>::getHeight() const
00138 {
00139   return _hauteur;
00140 }
00141 
00142 template <typename T>
00143 void TImage<T>::resize(int taillex, int tailley)
00144 {
00145   _largeur = taillex;
00146   _hauteur = tailley;
00147   for(int i = 0; i< getNumComponents(); i++)
00148     _canaux[i]->resize(taillex, tailley);
00149 }
00150 
00151 template <typename T>
00152 TImage<T>& TImage<T>::operator=(const TImage<T>& origine)
00153 {
00154   if(origine.getNumComponents() != getNumComponents())
00155     throw IllegalArgument("Image : operator=");
00156 
00157   resize(origine.getWidth(), origine.getHeight());
00158 
00159   for(int i = 0; i< getNumComponents(); i++)
00160     *_canaux[i] = *(origine._canaux[i]);
00161 
00162   return *this;
00163 }
00164 
00165 template <typename T>
00166 TImage<T>::TImage(const TImage<T> & c)
00167 {
00168   _nbcanaux = c.getNumComponents();
00169   _largeur = c.getWidth();
00170   _hauteur = c.getHeight();
00171 
00172   TImageMono<T> * current;
00173 
00174   for(int i = 0; i<getNumComponents(); i++)
00175   {
00176     current = new TImageMono<T>(getWidth(), getHeight());
00177     _canaux.push_back(current);
00178   }
00179 
00180   for(int i = 0; i< getNumComponents(); i++)
00181     *_canaux[i] = *(c._canaux[i]);
00182 
00183 }
00184 
00185 #endif
00186 

Généré le Fri May 18 23:24:33 2007 pour Millie par  doxygen 1.5.1