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
00026
00027
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