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

vetFrameYUV420.cpp

Go to the documentation of this file.
00001 
00018 #include "vetFrameYUV420.h"
00019 
00020 #include "vetUtility.h"
00021 
00022 
00023 vetFrameYUV420::vetFrameYUV420()  : vetFrame()
00024  {
00025         height = 0;
00026         width = 0;
00027         data = NULL;
00028         Y = NULL; // = data[0]
00029         U = NULL; // = data[ width*height ]
00030         V = NULL; // = data[ width*height*2 ]
00031 
00032         autoFreeData = true;
00033  }
00034 
00035 
00039 vetFrameYUV420::vetFrameYUV420(vetFrameYUV420& img)
00040  {
00041         data = NULL;
00042         reAllocCanvas(img.width, img.height);
00043 
00044         if ( width != 0 && height != 0 )
00045          {
00046                 memcpy(data, img.data, (int)(width * height * 1.5 * sizeof(unsigned char)));
00047          }
00048         autoFreeData = true;
00049  }
00050 
00051 
00057 vetFrameYUV420::vetFrameYUV420(unsigned int w, unsigned int h)
00058  {
00059         data = NULL;
00060         reAllocCanvas(w, h);
00061         autoFreeData = true;
00062  }
00063 
00064 
00068 vetFrameYUV420::~vetFrameYUV420()
00069  {
00070         if ( autoFreeData && data != NULL )
00071             delete [] data;
00072  }
00073 
00074 
00075 VETRESULT vetFrameYUV420::reAllocCanvas(unsigned int w, unsigned int h)
00076  {
00077         if (data != NULL)
00078          {
00079                 delete [] data;
00080                 data = NULL;
00081          }
00082 
00083         Y = NULL; // = data[0]
00084         U = NULL; // = data[ width*height ]
00085         V = NULL; // = data[ width*height*2 ]
00086         width = w;
00087         height = h;
00088 
00089         if ( width == 0 || height == 0)
00090                 return VETRET_PARAM_ERR;
00091 
00092         data = new unsigned char[ (int)(width * height * 1.5) ];
00093         Y = data;
00094         U = data + width * height;
00095         V = data + (int)(width * height * 1.25);
00096 
00097         return VETRET_OK;
00098  }
00099 
00100 
00101 VETRESULT vetFrameYUV420::setBlack()
00102  {
00103         if (width == 0 || height == 0 || data == NULL)
00104                 return VETRET_ILLEGAL_USE;
00105 
00106         memset(data, '\0', (int)(width * height * 1.5) );
00107 
00108         return VETRET_OK;
00109  }
00110 
00111 VETRESULT vetFrameYUV420::setWhite()
00112  {
00113         if (width == 0 || height == 0 || data == NULL)
00114                 return VETRET_ILLEGAL_USE;
00115 
00116         memset(data, 255, width * height );
00117         memset(U, '\0', (int)(width * height * 0.5) );
00118 
00119         return VETRET_OK;
00120  }
00121 
00122 VETRESULT vetFrameYUV420::extractBrightness(unsigned char* buffer, unsigned int* size)
00123  {
00124         if (width == 0 || height == 0 || data == NULL)
00125                 return VETRET_ILLEGAL_USE;
00126 
00127         if (buffer == NULL)
00128          {
00129                  if ( size == NULL)
00130                         return VETRET_PARAM_ERR;
00131 
00132                  *size = width*height;
00133                  return VETRET_OK;
00134          }
00135 
00136         memcpy (data, buffer, width*height);
00137         return VETRET_OK;
00138  }
00139 
00140 
00141 
00151 VETRESULT vetFrameYUV420::getPixel(unsigned int x, unsigned int y, unsigned char& value, ChannelYUV channel)
00152  {
00153         #ifdef _VETFRAMECACHE24_SLOWMODE
00154                 if ( x >= width || y >= height )
00155                         throw "Invalid Coordinates in method vetFrameYUV420::getPixel(unsigned int x, unsigned int y, PixelRGB& p)";
00156         #endif //_VETFRAMECACHE24_SLOWMODE
00157 
00158         if ( channel == vetFrameYUV420::Lum)
00159                 value = data[y * width + x];
00160         else if ( channel == vetFrameYUV420::Cb )
00161          {
00162 
00163 //BUG
00164                 value = data[y * width + x];
00165 
00166          }
00167         else if ( channel == vetFrameYUV420::Cr )
00168          {
00169 
00170 //BUG
00171                 value = data[y * width + x];
00172 
00173          }
00174 
00175         return VETRET_OK;
00176  }
00177 
00187 VETRESULT vetFrameYUV420::setPixel(unsigned int x, unsigned int y, unsigned char& value, ChannelYUV channel)
00188  {
00189         #ifdef _VETFRAMECACHE24_SLOWMODE
00190                 if ( x >= width || y >= height )
00191                         throw "Invalid Coordinates in method vetFrameYUV420::setPixel(unsigned int x, unsigned int y, PixelRGB p)";
00192         #endif //_VETFRAMECACHE24_SLOWMODE
00193 
00194         if ( channel == vetFrameYUV420::Lum)
00195                 data[y * width + x] = value;
00196         else if ( channel == vetFrameYUV420::Cb )
00197          {
00198 
00199 //BUG
00200                 data[y * width + x] = value;
00201 
00202          }
00203         else if ( channel == vetFrameYUV420::Cr )
00204          {
00205 
00206 //BUG
00207                 data[y * width + x] = value;
00208 
00209          }
00210 
00211         return VETRET_OK;
00212  }
00213 
00214 
00222 vetFrameYUV420& vetFrameYUV420::clearWith(unsigned char* value, ChannelYUV channel)
00223  {
00224         if ( data == NULL )
00225                 throw "Image is empty.";
00226 
00227         unsigned int start = 0;
00228         unsigned int end = 0;
00229 
00230         if ( channel == vetFrameYUV420::Lum )
00231          {
00232                 start = 0;
00233                 end = width*height;
00234          }
00235         else if ( channel == vetFrameYUV420::Cb )
00236          {
00237                 start = width*height;
00238                 end = (int)(width*height*1.25);
00239          }
00240         else if ( channel == vetFrameYUV420::Cr )
00241          {
00242                 start = (int)(width*height*1.25);
00243                 end = (int)(width*height*1.5);
00244          }
00245 
00246 
00247         for (unsigned int i=start; i<end; i++)
00248          {
00249                 data[i] = *value;
00250          }
00251         return *this;
00252  }
00253 
00262 vetFrameYUV420& vetFrameYUV420::operator = (vetFrameYUV420& img)
00263  {
00264         /* check we're not trying to copy ourself */
00265         if (this == &img)
00266                 return *this;
00267 
00268         if ( img.width == 0 || img.height == 0 )
00269                 throw "Cannot do that with empty image (no size)";
00270 
00271         if ( width != img.width || height != img.height )
00272                 img.reAllocCanvas(img.width, img.height);
00273 
00274         memcpy(data, img.data, (int)(width * height * 1.5 * sizeof(unsigned char)) );
00275 
00276         return *this;
00277  }
00278 
00279 
00280 vetFrameYUV420& vetFrameYUV420::operator += (vetFrameYUV420& img)
00281 {
00282         INFO("vetFrameYUV420& vetFrameYUV420::operator += (vetFrameYUV420& img)")
00283 
00284         if (width != img.width || height != img.height)
00285                 throw "Difference in vetFrameYUV420 Dimensions";
00286 
00287     for(unsigned int i=0; i < (unsigned int)(width * height * 1.5); i++)
00288         data[i] += img.data[i];
00289 
00290     return *this;
00291 }
00292 
00293 vetFrameYUV420& vetFrameYUV420::operator *= (vetFrameYUV420& img)
00294 {
00295         INFO("vetFrameYUV420& vetFrameYUV420::operator += (vetFrameYUV420& img)")
00296 
00297         if (width != img.width || height != img.height)
00298                 throw "Difference in vetFrameYUV420 Dimensions";
00299 
00300     for(unsigned int i=0; i < width * height * 1.5; i++)
00301         data[i] *= img.data[i];
00302 
00303     return *this;
00304 }
00305 
00306 
00307 
00308 
00309 
00310 
00311 
00312 vetFrameYUV420& vetFrameYUV420::operator >> (vetFrameRGB24& img)
00313  {
00314         INFO("vetFrameYUV420& vetFrameYUV420::operator >> (vetFrameYUV420& img) [pushing data]")
00315 
00316         if ( img.width == 0 || img.height == 0 || width != img.width || height != img.height )
00317                 img.reAllocCanvas(width, height);
00318 
00319         vetUtility::conv_PlanarYUVtoPixelRGB(data, (unsigned char*)img.data[0], width, height);
00320 
00321         return *this;
00322  }
00323 
00324 
00325 void vetFrameYUV420::operator << (const vetFrameRGB24& img)
00326 {
00327         INFO("void vetFrameYUV420::operator << (const vetFrameYUV420& img) [importing data]")
00328 
00329         if ( width == 0 || height == 0 || width != img.width || height != img.height )
00330                 reAllocCanvas(img.width, img.height);
00331 
00332         vetUtility::conv_PlanarYUVtoPixelRGB(data, (unsigned char*)img.data[0], width, height);
00333  }
00334 
00335 
00336 
00337 
00338 
00339 
00340 

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