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

vetFilter.cpp

Go to the documentation of this file.
00001 
00018 #include "vetFilter.h"
00019 
00020 
00027 vetFilter::vetFilter(float fps) : vetInput(fps), vetObject()
00028  {
00029         bufferYUV = NULL;
00030         bufferRGB = NULL;
00031         bufferTuC = NULL;
00032 
00033         setName("Abstract Filter");
00034         setDescription("Abstract Class");
00035         setVersion(0.0);
00036  };
00037 
00038 
00042 vetFilter::~vetFilter()
00043  {
00044         if (bufferYUV != NULL)
00045                 delete bufferYUV;
00046 
00047         if (bufferRGB != NULL)
00048                 delete bufferRGB;
00049 
00050         if (bufferTuC != NULL)
00051                 delete bufferTuC;
00052 
00053         bufferYUV = NULL;
00054         bufferRGB = NULL;
00055         bufferTuC = NULL;
00056  };
00057 
00058 
00059 
00066 void vetFilter::allocateBuffer(vetFilterParameters::BUFFER_TYPE bType)
00067  {
00068         switch (bType)
00069          {
00070                  case vetFilterParameters::YUV:
00071                         useBufferYUV(0,0);
00072                         break;
00073                  case vetFilterParameters::RGB:
00074                         useBufferRGB(0,0);
00075                         break;
00076                  case vetFilterParameters::TuC:
00077                          useBufferTuC(0,0,vetFrame::VETFRAME_NONE);
00078                         break;
00079                  case vetFilterParameters::NONE:
00080                  default:
00081                         releaseBuffers();
00082          }
00083  };
00084 
00085 
00089 void vetFilter::releaseBuffers()
00090  {
00091         if (bufferYUV != NULL)
00092                 delete bufferYUV;
00093 
00094         if (bufferRGB != NULL)
00095                 delete bufferRGB;
00096 
00097         if (bufferTuC != NULL)
00098                 delete bufferTuC;
00099 
00100         bufferYUV = NULL;
00101         bufferRGB = NULL;
00102         bufferTuC = NULL;
00103 
00104         printf("getFilterParameters()->currentBuffer");
00105 
00106         if ( getFilterParameters() != NULL )
00107                 getFilterParameters()->currentBuffer = vetFilterParameters::NONE;
00108  };
00109 
00110 
00116 void vetFilter::useBufferYUV(unsigned int width, unsigned int height)
00117  {
00118         if ( bufferYUV == NULL )
00119                 bufferYUV = new vetFrameYUV420(width, height);
00120         else if ( bufferYUV->width != width || bufferYUV->height != height )
00121                 bufferYUV->reAllocCanvas(width, height);
00122 
00123         if ( getFilterParameters() != NULL )
00124                 getFilterParameters()->currentBuffer = vetFilterParameters::YUV;
00125 
00126         if ( bufferRGB != NULL )
00127          {
00128                 delete bufferRGB;
00129                 bufferRGB = NULL;
00130          }
00131         if ( bufferTuC != NULL )
00132          {
00133                 delete bufferTuC;
00134                 bufferTuC = NULL;
00135          }
00136  };
00137 
00143 void vetFilter::useBufferRGB(unsigned int width, unsigned int height)
00144  {
00145         if ( bufferRGB == NULL )
00146                 bufferRGB = new vetFrameRGB24(width, height);
00147         else if ( bufferRGB->width != width || bufferRGB->height != height )
00148                 bufferRGB->reAllocCanvas(width, height);
00149 
00150         if ( getFilterParameters() != NULL )
00151                 getFilterParameters()->currentBuffer = vetFilterParameters::RGB;
00152 
00153         if ( bufferYUV != NULL )
00154          {
00155                 delete bufferYUV;
00156                 bufferYUV = NULL;
00157          }
00158         if ( bufferTuC != NULL )
00159          {
00160                 delete bufferTuC;
00161                 bufferTuC = NULL;
00162          }
00163  };
00164 
00170 void vetFilter::useBufferTuC(unsigned int width, unsigned int height, vetFrame::VETFRAME_PROFILE profile)
00171  {
00172         if ( bufferTuC == NULL )
00173                 bufferTuC = new vetFrameT<unsigned char>(width, height, profile);
00174         else if ( bufferTuC->width != width || bufferTuC->height != height )
00175                 bufferTuC->reAllocCanvas(width, height);
00176 
00177         if ( getFilterParameters() != NULL )
00178                 getFilterParameters()->currentBuffer = vetFilterParameters::TuC;
00179 
00180         if ( bufferYUV != NULL )
00181          {
00182                 delete bufferYUV;
00183                 bufferYUV = NULL;
00184          }
00185         if ( bufferRGB != NULL )
00186          {
00187                 delete bufferRGB;
00188                 bufferRGB = NULL;
00189          }
00190  };
00191 
00192 
00198 VETRESULT vetFilter::setHeight(unsigned int value)
00199  {
00200         if (bufferYUV != NULL)
00201          {
00202                 bufferYUV->reAllocCanvas(bufferYUV->width, value);
00203                 return VETRET_OK;
00204          }
00205         else if (bufferRGB != NULL)
00206          {
00207                 bufferRGB->reAllocCanvas(bufferRGB->width, value);
00208                 return VETRET_OK;
00209          }
00210         else if (bufferTuC != NULL)
00211          {
00212                 bufferTuC->reAllocCanvas(bufferTuC->width, value);
00213                 return VETRET_OK;
00214          }
00215 
00216         return VETRET_NOT_IMPLEMENTED;
00217  };
00218 
00224 VETRESULT vetFilter::setWidth(unsigned int value)
00225  {
00226         if (bufferYUV != NULL)
00227          {
00228                 bufferYUV->reAllocCanvas(value, bufferYUV->height);
00229                 return VETRET_OK;
00230          }
00231         else if (bufferRGB != NULL)
00232          {
00233                 bufferRGB->reAllocCanvas(value, bufferRGB->height);
00234                 return VETRET_OK;
00235          }
00236         else if (bufferTuC != NULL)
00237          {
00238                 bufferTuC->reAllocCanvas(value, bufferTuC->height);
00239                 return VETRET_OK;
00240          }
00241 
00242         return VETRET_NOT_IMPLEMENTED;
00243  };
00244 
00250 unsigned int vetFilter::getWidth() const
00251  {
00252         if (bufferYUV != NULL)
00253                 return bufferYUV->width;
00254 
00255         else if (bufferRGB != NULL)
00256                 return bufferRGB->width;
00257 
00258         else if (bufferTuC != NULL)
00259                 return bufferTuC->width;
00260 
00261         return 0;
00262  };
00263 
00269 unsigned int vetFilter::getHeight() const
00270  {
00271         if (bufferYUV != NULL)
00272                 return bufferYUV->height;
00273 
00274         else if (bufferRGB != NULL)
00275                 return bufferRGB->height;
00276 
00277         else if (bufferTuC != NULL)
00278                 return bufferTuC->height;
00279 
00280         return 0;
00281  };
00282 
00283 
00290 bool vetFilter::EoF()
00291  {
00292         if (bufferYUV != NULL || bufferRGB != NULL || bufferTuC != NULL)
00293                 return false;
00294 
00295         return true;
00296  };
00297 
00298 
00299 
00300 
00301 
00302 VETRESULT vetFilter::extractTo(vetFrameYUV420& img)
00303  {
00304         INFO("VETRESULT vetFilter::extractTo(vetFrameYUV420& img) [pushing data]")
00305 
00306         if ( !isBufferYUV() )
00307                 return VETRET_ILLEGAL_USE;
00308 
00309         img = *bufferYUV;
00310 
00311         return VETRET_OK;
00312  };
00313 
00314 VETRESULT vetFilter::extractTo(vetFrameRGB24& img)
00315  {
00316         INFO("VETRESULT vetFilter::extractTo(vetFrameRGB24& img) [pushing data]")
00317 
00318         if ( !isBufferRGB() )
00319                 return VETRET_ILLEGAL_USE;
00320 
00321         img = *bufferRGB;
00322 
00323         return VETRET_OK;
00324  };
00325 
00326 VETRESULT vetFilter::extractTo(vetFrameT<unsigned char>& img)
00327  {
00328         INFO("VETRESULT vetFilter::extractTo(vetFrameT<unsigned char>& img) [pushing data]")
00329 
00330         if ( !isBufferTuC() )
00331                 return VETRET_ILLEGAL_USE;
00332 
00333         img = *bufferTuC;
00334 
00335         return VETRET_OK;
00336  };
00337 
00338 
00339 
00340 
00344 
00345 
00346 
00347 
00348 
00358 int vetFilterParameters::saveToXML(const char* filename)
00359  {
00360         FILE *fp;
00361         int ret = VETRET_OK;
00362 
00363         if ( (fp = fopen(filename, "w")) == NULL )
00364                 return VETRET_PARAM_ERR;
00365 
00366         if( fprintf(fp, "<?xml version=\"1.0\" ?>\n\n") == EOF )
00367          {
00368                 fclose(fp);
00369                 return VETRET_INTERNAL_ERR;
00370          }
00371 
00372         ret = saveToStreamXML(fp);
00373 
00374         fclose(fp);
00375 
00376         return ret;
00377  };
00378 
00379 
00389 int vetFilterParameters::loadFromXML(const char* filename)
00390  {
00391     FILE *fp;
00392         int ret = VETRET_OK;
00393 
00394     if ( (fp=fopen(filename,"r")) == NULL )
00395         return VETRET_PARAM_ERR;
00396 
00397     float xmlversion = 1.0;
00398 
00399     fscanf(fp, "<?xml version=\"%f\" ?>\n\n", &xmlversion);
00400 
00401     if (xmlversion == 0)
00402         throw "Incompatible XML file format";
00403 
00404         ret = loadFromStreamXML(fp);
00405 
00406         // closing tags reading is omitted
00407 
00408     fclose(fp);
00409 
00410     return ret;
00411  };
00412 
00413 

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