Main Page | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages | Examples

vetFrameRGB96.cpp

Go to the documentation of this file.
00001 
00017 #include "vetFrameRGB96.h"
00018 #include <math.h>
00019 
00020 vetFrameRGB96::vetFrameRGB96() : vetFrame()
00021  {
00022         INFO("vetFrameRGB96::vetFrameRGB96() : vetFrame() [CONTRUCTOR]")
00023         data = NULL;
00024         width = 0;
00025         height = 0;
00026  }
00027 
00028 vetFrameRGB96::vetFrameRGB96(unsigned int w, unsigned int h)
00037  {
00038         data = NULL;
00039         reAllocCanvas(w, h);
00040 
00041         INFO("vetFrameRGB96::vetFrameRGB96(unsigned int w, unsigned int h) [CONTRUCTOR]")
00042         DEBUG(width)
00043         DEBUG(height)
00044  }
00045 
00046 
00047 vetFrameRGB96::vetFrameRGB96(vetFrameRGB96& img)
00053  {
00054         data = NULL;
00055         reAllocCanvas(img.width, img.height);
00056 
00057         *this = img;
00058 
00059         INFO("vetFrameRGB96::vetFrameRGB96(vetFrameRGB96& img) [CONTRUCTOR]")
00060         DEBUG(width)
00061         DEBUG(height)
00062  }
00063 
00064 
00065 vetFrameRGB96::vetFrameRGB96(vetFrameRGB24& img)
00071  {
00072         data = NULL;
00073         reAllocCanvas(img.width, img.height);
00074 
00075         *this << img;
00076 
00077         INFO("vetFrameRGB96::vetFrameRGB96(vetFrameRGB96& img) [CONTRUCTOR]")
00078         DEBUG(width)
00079         DEBUG(height)
00080  }
00081 
00082 vetFrameRGB96::vetFrameRGB96(vetFrameRGBA32& img)
00088  {
00089         data = NULL;
00090         reAllocCanvas(img.width, img.height);
00091 
00092         *this << img;
00093 
00094         INFO("vetFrameRGB96::vetFrameRGB96(vetFrameRGB96& img) [CONTRUCTOR]")
00095         DEBUG(width)
00096         DEBUG(height)
00097  }
00098 
00099 
00103 vetFrameRGB96::~vetFrameRGB96()
00104 {
00105         INFO("vetFrameRGB96::~vetFrameRGB96() [DESTRUCTOR]")
00106 
00107         if ( autoFreeData && data != NULL )
00108                 delete [] data;
00109 }
00110 
00111 VETRESULT vetFrameRGB96::reAllocCanvas(unsigned int w, unsigned int h)
00112  {
00113         if (data != NULL)
00114                 delete [] data;
00115 
00116         height = h;
00117         width = w;
00118         data = NULL;
00119 
00120         if ( width == 0 || height == 0)
00121                 return VETRET_PARAM_ERR;
00122 
00123         data = new PixelRGB96[width * height];
00124 
00125         return VETRET_OK;
00126  }
00127 
00128 VETRESULT vetFrameRGB96::setBlack()
00129  {
00130         if (width == 0 || height == 0 || data == NULL)
00131                 return VETRET_ILLEGAL_USE;
00132 
00133         memset(data, '\0', width * height * sizeof(PixelRGB96) );
00134 
00135         return VETRET_OK;
00136  }
00137 
00138 VETRESULT vetFrameRGB96::setWhite()
00139  {
00140         if (width == 0 || height == 0 || data == NULL)
00141                 return VETRET_ILLEGAL_USE;
00142 
00143         memset(data, 255, width * height  * sizeof(PixelRGB96) );
00144 
00145         return VETRET_OK;
00146  }
00147 
00148 
00149 VETRESULT vetFrameRGB96::extractBrightness(unsigned char* buffer, unsigned int* size)
00150  {
00151         if (width == 0 || height == 0 || data == NULL)
00152                 return VETRET_ILLEGAL_USE;
00153 
00154         if (buffer == NULL)
00155          {
00156                  if ( size == NULL)
00157                         return VETRET_PARAM_ERR;
00158 
00159                  *size = width*height;
00160                  return VETRET_OK;
00161          }
00162 
00163         return VETRET_NOT_IMPLEMENTED;
00164  }
00165 
00166 VETRESULT vetFrameRGB96::setPixel(unsigned int x, unsigned int y, PixelRGB96 p)
00173 {
00174         // Check that co-ords are valid.
00175         if ( x >= width || y >= height )
00176                 throw "Invalid Coordinates in method vetFrameRGB96::setPixel(unsigned int x, unsigned int y, PixelRGB96 p)";
00177 
00178         data[y * width + x] = p;
00179 
00180         return VETRET_OK;
00181 }
00182 
00183 
00184 VETRESULT vetFrameRGB96::setRGB(unsigned int x, unsigned int y, int red, int green, int blue)
00194 {
00195         // Check that co-ords are valid.
00196         if ( x >= width || y >= height )
00197                 throw "Invalid Coordinates in method vetFrameRGB96::setRGB(unsigned int x, unsigned int y, int red, int green, int blue)";
00198 
00199         unsigned int offset = y * width + x;
00200 
00201         data[offset][RED]   = red;
00202         data[offset][GREEN] = green;
00203         data[offset][BLUE]  = blue;
00204 
00205         return VETRET_OK;
00206  }
00207 
00208 
00209 VETRESULT vetFrameRGB96::setChannel(unsigned int x, unsigned int y, ChannelRGB fs, int value)
00218 {
00219         // Check that co-ords are valid.
00220         if ( x >= width || y >= height )
00221                 throw "Invalid Coordinates in method vetFrameRGB96::setChannel(unsigned int x, unsigned int y, ChannelRGB fs, int value)";
00222 
00223         unsigned int offset = y * width + x;
00224         data[offset][fs] = value;
00225 
00226         return VETRET_OK;
00227  }
00228 
00229 
00230 
00231 VETRESULT vetFrameRGB96::getPixel(unsigned int x, unsigned int y, PixelRGB96& p) const
00240 {
00241         // Check that co-ords are valid.
00242         if ( x >= width || y >= height )
00243                 throw "Invalid Coordinates in method vetFrameRGB96::setChannel(unsigned int x, unsigned int y, ChannelRGB fs, int value)";
00244 
00245         unsigned int offset = y * width + x;
00246 
00247         p[ RED ] = data[offset][RED];
00248         p[GREEN] = data[offset][GREEN];
00249         p[ BLUE] = data[offset][BLUE];
00250 
00251         return VETRET_OK;
00252  }
00253 
00254 const PixelRGB96& vetFrameRGB96::getPixel(unsigned int x, unsigned int y) const
00255 {
00256         // Check that co-ords are valid.
00257         if ( x >= width || y >= height )
00258                 throw "Invalid Coordinates in method vetFrameRGB96::setChannel(unsigned int x, unsigned int y, ChannelRGB fs, int value)";
00259 
00260         return data[y * width + x];
00261 
00262 }
00263 
00264 
00265 
00266 VETRESULT vetFrameRGB96::getChannel(unsigned int x, unsigned int y, ChannelRGB fs) const
00275 {
00276         // Check that co-ords are valid.
00277         if ( x >= width || y >= height )
00278                 throw "Invalid Coordinates in method vetFrameRGB96::setChannel(unsigned int x, unsigned int y, ChannelRGB fs, int value)";
00279 
00280         unsigned int offset = y * width + x;
00281         return data[offset][fs];
00282 
00283         return VETRET_OK;
00284  }
00285 
00286 
00287 vetFrameRGB96& vetFrameRGB96::clear(int k)
00293 {
00294         DEBUGMSG("vetFrameRGB96& vetFrameRGB96::clear(int k)", k)
00295 
00296         int *start = data[0];
00297         int *end   = start + width * height * 3;
00298 
00299         for (int *d = start; d < end; d++)
00300                 *d = k;
00301 
00302         return *this;
00303 }
00304 
00305 
00306 vetFrameRGB96& vetFrameRGB96::clearWith(PixelRGB96& p)
00312 {
00313         DEBUGMSG("vetFrameRGB96& vetFrameRGB96::clearWith(PixelRGB96& p)", p)
00314 
00315         int *start = data[0];
00316         int *end   = start + width * height * 3;
00317 
00318         for (int *d = start; d < end; d += 3) {
00319                 d[ RED ] = p[ RED ];
00320                 d[GREEN] = p[GREEN];
00321                 d[ BLUE] = p[ BLUE];
00322         }
00323 
00324         return *this;
00325 }
00326 
00327 
00328 vetFrameRGB96& vetFrameRGB96::clearChannel(ChannelRGB channel, int color)
00335 {
00336         INFO("vetFrameRGB96& vetFrameRGB96::clearChannel(ChannelRGB channel, int color)")
00337         DEBUG(channel)
00338         DEBUG(color)
00339 
00340         int *start = data[0];
00341         int *end   = start + width * height * 3;
00342 
00343         for (int *d = start + channel; d < end; d += 3)
00344                 *d = color;
00345 
00346         return *this;
00347 }
00348 
00349 VETRESULT vetFrameRGB96::setWidth(unsigned int newWidth)
00350  {
00351         if ( width != 0)
00352                 return VETRET_ILLEGAL_USE;
00353 
00354         width = newWidth;
00355 
00356         return VETRET_OK;
00357  }
00358 
00359 VETRESULT vetFrameRGB96::setHeight(unsigned int newHeight)
00360  {
00361         if ( height != 0)
00362                 return VETRET_ILLEGAL_USE;
00363 
00364         height = newHeight;
00365 
00366         return VETRET_OK;
00367  }
00368 
00369 
00370 vetFrameRGB96& vetFrameRGB96::copy(vetFrameRGB96& img)
00377 {
00378         INFO("vetFrameRGB96& vetFrameRGB96::copy(vetFrameRGB96& img)")
00379 
00380         /* check we're not trying to copy ourself */
00381         if (this == &img)
00382                 throw "Source and Destination are same Image";
00383 
00384         /* First check images are the same size and valid */
00385         if (width != img.width || height != img.height)
00386                 throw "Difference in vetFrameRGB96 Dimensions";
00387 
00388         /* Perform copy */
00389         memcpy(data, img.data, width * height * sizeof(PixelRGB96));
00390 
00391         return *this;
00392 }
00393 
00394 
00395 vetFrameRGB96& vetFrameRGB96::operator += (vetFrameRGB96& img)
00396 {
00397         INFO("vetFrameRGB96& vetFrameRGB96::operator += (vetFrameRGB96& img)")
00398 
00399         if (width != img.width || height != img.height)
00400                 throw "Difference in vetFrameRGB96 Dimensions";
00401 
00402     for(unsigned int i=0; i < width * height; i++)
00403         data[i] += img.data[i];
00404 
00405     return *this;
00406 }
00407 
00408 
00409 vetFrameRGB96& vetFrameRGB96::operator -= (vetFrameRGB96& img)
00410 {
00411         INFO("vetFrameRGB96& vetFrameRGB96::operator -= (vetFrameRGB96& img)")
00412 
00413         if (width != img.width || height != img.height)
00414                 throw "Difference in vetFrameRGB96 Dimensions";
00415 
00416     for(unsigned int i=0; i < width * height; i++)
00417         data[i] -= img.data[i];
00418 
00419     return *this;
00420 }
00421 
00422 vetFrameRGB96& vetFrameRGB96::operator >> (vetFrameYUV420& img)
00429 {
00430         INFO("vetFrameRGB96& vetFrameRGB96::operator >> (vetFrameYUV420& img) [pushing data]")
00431 
00432         if ( width == 0 || height == 0 )
00433                 throw "Cannot do that with empty image (no size)";
00434 
00435         if (width != img.width || height != img.height)
00436                 img.reAllocCanvas(width, height);
00437 
00438 //BUG
00439 
00440         return *this;
00441 }
00442 
00449 vetFrameRGB96& vetFrameRGB96::operator >> (vetFrameRGB24& img)
00450 {
00451         INFO("vetFrameRGB96& vetFrameRGB96::operator >> (vetFrameYUV420& img) [pushing data]")
00452 
00453         if ( width == 0 || height == 0 )
00454                 throw "Cannot do that with empty image (no size)";
00455 
00456         if (width != img.width || height != img.height)
00457                 img.reAllocCanvas(width, height);
00458 
00459         for (unsigned int i = 0; i < width*height; i++)
00460          {
00461                 img.data[i][RED] = (unsigned char)data[i][RED];
00462                 img.data[i][GREEN] = (unsigned char)data[i][GREEN];
00463                 img.data[i][BLUE] = (unsigned char)data[i][BLUE];
00464          }
00465 
00466         return *this;
00467 }
00468 
00469 
00476 vetFrameRGB96& vetFrameRGB96::operator >> (vetFrameRGBA32& img)
00477 {
00478         INFO("vetFrameRGB96& vetFrameRGB96::operator >> (vetFrameRGB96& img) [pushing data]")
00479 
00480         if ( width == 0 || height == 0 )
00481                 throw "Cannot do that with empty image (no size)";
00482 
00483         if (width != img.width || height != img.height )
00484                 img.reAllocCanvas(width, height);
00485 
00486 //BUG
00487 
00488         return *this;
00489 }
00490 
00497 vetFrameRGB96& vetFrameRGB96::operator >> (vetFrameGrey& img)
00498 {
00499         INFO("vetFrameRGB96& vetFrameRGB96::operator >> (vetFrameGrey& img) [pushing data]")
00500 
00501         if ( width == 0 || height == 0 )
00502                 throw "Cannot do that with empty image (no size)";
00503 
00504         if (width != img.width || height != img.height)
00505                 img.reAllocCanvas(width, height);
00506 
00507 //BUG
00508 
00509         return *this;
00510 }
00511 
00512 
00519 void vetFrameRGB96::operator << (const vetFrameYUV420& img)
00520 {
00521         INFO("void vetFrameRGB96::operator << (const vetFrameYUV420& img) [importing data]")
00522 
00523         if ( img.width == 0 || img.height == 0 )
00524                 throw "Cannot do that with empty image (no size)";
00525 
00526         if (width != img.width || height != img.height)
00527                 reAllocCanvas(img.width, img.height);
00528 
00529 //BUG
00530 
00531 }
00532 
00533 
00540 void vetFrameRGB96::operator << (const vetFrameRGB24& img)
00541 {
00542         INFO("void vetFrameRGB96::operator << (const vetFrameRGB24& img) [importing data]")
00543 
00544         if ( img.width == 0 || img.height == 0 )
00545                 throw "Cannot do that with empty image (no size)";
00546 
00547         if (width != img.width || height != img.height)
00548                 reAllocCanvas(img.width, img.height);
00549 
00550         /* Perform copy */
00551         for (unsigned int i = 0; i < width*height; i++)
00552          {
00553                 data[i][RED] = (int)img.data[i][RED];
00554                 data[i][GREEN] = (int)img.data[i][GREEN];
00555                 data[i][BLUE] = (int)img.data[i][BLUE];
00556          }
00557 }
00558 
00565 void vetFrameRGB96::operator << (const vetFrameRGBA32& img)
00566 {
00567         INFO("void vetFrameRGB96::operator << (const vetFrameYUV420& img) [importing data]")
00568 
00569         if ( img.width == 0 || img.height == 0 )
00570                 throw "Cannot do that with empty image (no size)";
00571 
00572         if (width != img.width || height != img.height)
00573                 reAllocCanvas(img.width, img.height);
00574 
00575         unsigned char* R = img.data;
00576         unsigned char* G = img.data + width*height;
00577         unsigned char* B = img.data + width*height*2;
00578 
00579         for (unsigned int i=0; i< width*height; i++)
00580          {
00581                 data[i][0] = *(R++);
00582                 data[i][1] = *(G++);
00583                 data[i][2] = *(B++);
00584          }
00585 //CHECKBUG
00586 
00587 }
00588 
00595 void vetFrameRGB96::operator << (const vetFrameGrey& img)
00596 {
00597         INFO("void vetFrameRGB96::operator << (const vetFrameGrey& img) [importing data]")
00598 
00599         if ( width == 0 || height == 0 || width != img.width || height != img.height )
00600          {
00601                 reAllocCanvas(img.width, img.height);
00602          }
00603 
00604         float cp;
00605         for (unsigned int i=0; i< width*height; i++)
00606          {
00607                 cp = (float)img.data[i];
00608                 data[i][0] = (int)(cp / RED_COEF );
00609                 data[i][1] = (int)(cp / GREEN_COEF );
00610                 data[i][2] = (int)(cp / BLUE_COEF );
00611          }
00612 //CHECKBUG
00613 
00614  }
00615 
00616 
00617 
00618 
00619 /****************************************************************************\
00620  *       Extra doxygen comments and information relating to this file       *
00621 \****************************************************************************/
00622 

Generated on Tue Jan 24 11:59:03 2006 for VETLib by  doxygen 1.4.4