00001
00019 #include "vetFrameGreyETI.h"
00020
00026 vetFrameGreyETI::vetFrameGreyETI(vetFrameCache& img) : image(img.width, img.height, 32)
00027 {
00028 *this << img;
00029 }
00030
00031
00032
00033
00034 int vetFrameGreyETI::setPixel(unsigned int x, unsigned int y, PixelGrey p)
00042 {
00043 if ( put_GL( x, y, (int)p) )
00044 return VETRET_PARAM_ERR;
00045
00046 return VETRET_OK;
00047 }
00048
00049 int vetFrameGreyETI::getPixel(unsigned int x, unsigned int y, PixelGrey& p)
00057 {
00058 if ( x>(unsigned int)(get_dimx()-1) || y>(unsigned int)(get_dimy()-1) )
00059 return VETRET_PARAM_ERR;
00060
00061 p = (PixelGrey)get_GL(x, y);
00062
00063 return VETRET_OK;
00064 }
00065
00066
00067
00068 vetFrameGreyETI& vetFrameGreyETI::operator >> (vetFrameCache& img)
00069 {
00070 INFO("vetFrameGreyETI& vetFrameGreyETI::operator >> (vetFrameCache& img) [pushing data]")
00071
00072 if ( get_dimx() == 0 || get_dimy() == 0 )
00073 throw "Cannot do that with empty image (no size)";
00074
00075 if ( (unsigned int)get_dimx() != img.width || (unsigned int)get_dimy() != img.height)
00076 {
00077 img.width = (unsigned int)get_dimx();
00078 img.height = (unsigned int)get_dimy();
00079 if ( img.data != NULL )
00080 delete [] img.data;
00081 img.data = new PixelRGB[img.width*img.height];
00082 }
00083
00084 for (unsigned int y = 0; y < img.height; y++)
00085 for (unsigned int x = 0; x < img.width; x++)
00086 {
00087 img.data[y * img.width + x][0] = (int)get_GL(x, y);
00088 img.data[y * img.width + x][1] = (int)get_GL(x, y);
00089 img.data[y * img.width + x][2] = (int)get_GL(x, y);
00090 }
00091
00092 return *this;
00093 }
00094
00095 vetFrameGreyETI& vetFrameGreyETI::operator >> (vetFrameCache24& img)
00096 {
00097 INFO("vetFrameGreyETI& vetFrameGreyETI::operator >> (vetFrameCache& img) [pushing data]")
00098
00099 if ( get_dimx() == 0 || get_dimy() == 0 )
00100 throw "Cannot do that with empty image (no size)";
00101
00102 if ( (unsigned int)get_dimx() != img.width || (unsigned int)get_dimy() != img.height)
00103 {
00104 img.width = (unsigned int)get_dimx();
00105 img.height = (unsigned int)get_dimy();
00106 if ( img.data != NULL )
00107 delete [] img.data;
00108 img.data = new PixelRGB24[img.width*img.height];
00109 }
00110
00111 for (unsigned int y = 0; y < img.height; y++)
00112 for (unsigned int x = 0; x < img.width; x++)
00113 {
00114 img.data[y * img.width + x][0] = (unsigned char)get_GL(x, y);
00115 img.data[y * img.width + x][1] = (unsigned char)get_GL(x, y);
00116 img.data[y * img.width + x][2] = (unsigned char)get_GL(x, y);
00117 }
00118
00119 return *this;
00120 }
00121
00122
00123 vetFrameGreyETI& vetFrameGreyETI::operator >> (vetFrameRGB& img)
00124 {
00125
00126 vetFrameCache tmp;
00127 *this >> tmp;
00128 img << tmp;
00129
00130 return *this;
00131 }
00132
00133 vetFrameGreyETI& vetFrameGreyETI::operator >> (vetFrameGrey& img)
00134 {
00135
00136 if ( get_dimx() == 0 || get_dimy() == 0 )
00137 throw "Cannot do that with empty image (no size)";
00138
00139 if ( (unsigned int)get_dimx() != img.getWidth() || (unsigned int)get_dimy() != img.getHeight() )
00140 throw "Difference in vetFramegrey Dimensions";
00141
00142 for (unsigned int y = 0; y < img.getHeight(); y++)
00143 for (unsigned int x = 0; x < img.getWidth(); x++)
00144 img.setPixel(x, y, (int)get_GL(x, y));
00145
00146 return *this;
00147 }
00148
00149
00150
00151 void vetFrameGreyETI::operator << (vetFrameCache& img)
00152 {
00153
00154 if ( (unsigned int)get_dimx() != img.width || (unsigned int)get_dimy() != img.height)
00155 inflatesize(img.width, img.height, 32);
00156
00157 if ( get_dimy() == 0 || get_dimx() == 0 )
00158 throw "Cannot do that with empty image (no size)";
00159
00160
00161 for (unsigned int y = 0; y < img.height; y++)
00162 for (unsigned int x = 0; x < img.width; x++)
00163 {
00164 put_GL(x, y, (int) ( (float)img.data[y*img.width+x][0] * RED_COEF
00165 +(float)img.data[y*img.width+x][1] * GREEN_COEF
00166 +(float)img.data[y*img.width+x][2] * BLUE_COEF ) );
00167 }
00168 }
00169
00170
00171 void vetFrameGreyETI::operator << (vetFrameCache24& img)
00172 {
00173
00174 if ( (unsigned int)get_dimx() != img.width || (unsigned int)get_dimy() != img.height)
00175 inflatesize(img.width, img.height, 32);
00176
00177 if ( get_dimy() == 0 || get_dimx() == 0 )
00178 throw "Cannot do that with empty image (no size)";
00179
00180
00181 for (unsigned int y = 0; y < img.height; y++)
00182 for (unsigned int x = 0; x < img.width; x++)
00183 {
00184 put_GL(x, y, (int) ( img.data[y*img.width+x][0] * RED_COEF
00185 +img.data[y*img.width+x][1] * GREEN_COEF
00186 +img.data[y*img.width+x][2] * BLUE_COEF ) );
00187 }
00188 }
00189
00190 void vetFrameGreyETI::operator << (vetFrameRGB& img)
00191 {
00192
00193 if ( (unsigned int)get_dimx() != img.getWidth() || (unsigned int)get_dimy() != img.getHeight())
00194 inflatesize(img.getWidth(), img.getHeight(), 32);
00195
00196 if ( get_dimy() == 0 || get_dimx() == 0 )
00197 throw "Cannot do that with empty image (no size)";
00198
00199 PixelRGB p;
00200 for (unsigned int y = 0; y < img.getHeight(); y++)
00201 for (unsigned int x = 0; x < img.getWidth(); x++)
00202 {
00203 img.getPixel(x, y, p);
00204 put_GL(x, y, (int) ( (float)p[0] * RED_COEF
00205 +(float)p[1] * GREEN_COEF
00206 +(float)p[2] * BLUE_COEF ) );
00207 }
00208 }
00209
00210 void vetFrameGreyETI::operator << (vetFrameGrey& img)
00211 {
00212
00213 if ( (unsigned int)get_dimx() != img.getWidth() || (unsigned int)get_dimy() != img.getHeight())
00214 inflatesize(img.getWidth(), img.getHeight(), 32);
00215
00216 if ( get_dimy() == 0 || get_dimx() == 0 )
00217 throw "Cannot do that with empty image (no size)";
00218
00219
00220 for (unsigned int y = 0; y < img.getHeight(); y++)
00221 for (unsigned int x = 0; x < img.getWidth(); x++)
00222 put_GL(x, y, (int)img.getPixel(x, y));
00223
00224 }
00225