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

vetFilterColor.cpp

Go to the documentation of this file.
00001 
00018  #include "vetFilterColor.h"
00019 
00020 
00025 vetFilterColor::vetFilterColor(vetFilterColorParameters* initParams) : vetFilter()
00026  {
00027         INFO("vetFilterColor::vetFilterColor(..* initParams) : vetFilter() [CONTRUCTOR]")
00028 
00029         setParameters(initParams);
00030         reset();
00031 
00032         setName("Colors Editing Filter");
00033         setDescription("Posterize, Nagative....");
00034         setVersion(1.0);
00035 
00036  }
00037 
00041 vetFilterColor::~vetFilterColor()
00042  {
00043         INFO("vetFilterColor::~vetFilterColor() [DESTRUCTOR]")
00044 
00045         if (myParams != NULL)
00046                 delete myParams;//BUG
00047         myParams = NULL;
00048 
00049  }
00050 
00060 VETRESULT vetFilterColor::setParameters (vetFilterColorParameters* initParams)
00061  {
00062 
00063         if ( initParams == NULL )
00064                 myParams = new vetFilterColorParameters();
00065         else
00066                 myParams = initParams;
00067 
00068         allocateBuffer(myParams->currentBuffer);
00069 
00070         return VETRET_OK;
00071  }
00072 
00078 VETRESULT vetFilterColor::reset()
00079  {
00080         INFO("VETRESULT vetFilterColor::reset() [SET DEFAULT PARAMETERS]")
00081 
00082         releaseBuffers();
00083 
00084         if (myParams != NULL)
00085          {
00086                 myParams->reset();
00087                 allocateBuffer(myParams->currentBuffer);
00088          }
00089         else
00090                 setParameters(NULL);
00091 
00092         return VETRET_OK;
00093  }
00094 
00095 
00106 VETRESULT vetFilterColor::importFrom(vetFrameYUV420& img)
00107  {
00108         DEBUGMSG("VETRESULT vetFilterColor::importFrom(vetFrameYUV420& img) [reading data]", myParams->runMode)
00109 
00110         switch ( myParams->runMode )
00111          {
00112          case vetFilterColorParameters::DO_NOTHING:
00113                         if ( !isBufferYUV() )
00114                          {
00115                                 useBufferYUV(img.width, img.height);
00116                                 *bufferYUV = img;
00117                                 return VETRET_OK_DEPRECATED;
00118                          }
00119                         else
00120                          {
00121                                 *bufferYUV = img;
00122                                 return VETRET_OK;
00123                          }
00124 
00125          case vetFilterColorParameters::CLAMP:
00126                         return clamp(img, myParams->currBpp);
00127 
00128          case vetFilterColorParameters::INVERT:
00129                         return invert(img, myParams->currBpp);
00130 
00131          case vetFilterColorParameters::EXTRACTBITPLANE:
00132                         return extractBitPlane(img, myParams->currBits);
00133 
00134          default:
00135                   return VETRET_PARAM_ERR;
00136          }
00137  }
00138 
00139 
00150 VETRESULT vetFilterColor::importFrom(vetFrameRGB24& img)
00151  {
00152         DEBUGMSG("VETRESULT vetFilterColor::importFrom(vetFrameYUV420& img) [reading data]", myParams->runMode)
00153 
00154         switch ( myParams->runMode )
00155          {
00156          case vetFilterColorParameters::DO_NOTHING:
00157                         if ( !isBufferRGB() )
00158                          {
00159                                 useBufferRGB(img.width, img.height);
00160                                 *bufferRGB = img;
00161                                 return VETRET_OK_DEPRECATED;
00162                          }
00163                         else
00164                          {
00165                                 *bufferRGB = img;
00166 
00167                                 return VETRET_OK;
00168                          }
00169 
00170          case vetFilterColorParameters::CLAMP:
00171                         return clamp(img, myParams->currBpp);
00172 
00173          case vetFilterColorParameters::INVERT:
00174                         return invert(img, myParams->currBpp);
00175 
00176          case vetFilterColorParameters::EXTRACTBITPLANE:
00177                         return extractBitPlane(img, myParams->currBits);
00178 
00179          default:
00180                   return VETRET_PARAM_ERR;
00181          }
00182  }
00183 
00194 VETRESULT vetFilterColor::importFrom(vetFrameT<unsigned char>& img)
00195  {
00196         DEBUGMSG("VETRESULT vetFilterColor::importFrom(vetFrameT<unsigned char>& img) [reading data]", myParams->runMode)
00197 
00198         switch ( myParams->runMode )
00199          {
00200          case vetFilterColorParameters::DO_NOTHING:
00201                         if ( !isBufferTuC() )
00202                          {
00203                                 useBufferTuC(img.width, img.height, img.profile);
00204                                 *bufferTuC = img;
00205                                 return VETRET_OK_DEPRECATED;
00206                          }
00207                         else
00208                          {
00209                                 *bufferTuC = img;
00210                                 return VETRET_OK;
00211                          }
00212 
00213 
00214          case vetFilterColorParameters::CLAMP:
00215                         return clamp(img, myParams->currBpp);
00216 
00217          case vetFilterColorParameters::INVERT:
00218                         return invert(img, myParams->currBpp);
00219 
00220          case vetFilterColorParameters::EXTRACTBITPLANE:
00221                         return extractBitPlane(img, myParams->currBits);
00222 
00223          default:
00224                   return VETRET_PARAM_ERR;
00225          }
00226  }
00227 
00228 
00231 
00232 
00233 
00234 //taglia tutti i valori saturi e negativi
00235 VETRESULT vetFilterColor::clamp(vetFrameYUV420& img, unsigned int bpp)//=sizeof(int)*3
00236  {
00237 
00238         return VETRET_NOT_IMPLEMENTED;
00239  }
00240 
00241 //taglia tutti i valori saturi
00242 VETRESULT vetFilterColor::clamp(vetFrameRGB24& img, unsigned int bpp)
00243  {
00244 //CHECKBUGS
00245         if ( bpp >= sizeof(unsigned char)*3 )
00246                 return VETRET_PARAM_ERR;
00247 
00248         useBufferRGB(img.width, img.height);
00249 
00250         for (unsigned int i=0; i < img.width * img.height; i++ )
00251          {
00252                 if ( img.data[i][0] > (unsigned char)( (1<<bpp)/3) )
00253                         bufferRGB->data[i][0] = (unsigned char)( (1<<bpp)/3);
00254                 else
00255                         bufferRGB->data[i][0] = img.data[i][0];
00256 
00257                 if ( img.data[i][1] > (unsigned char)( (1<<bpp)/3) )
00258                         bufferRGB->data[i][1] = (unsigned char)( (1<<bpp)/3);
00259                 else
00260                         bufferRGB->data[i][1] = img.data[i][1];
00261 
00262                 if ( img.data[i][1] > (unsigned char)( (1<<bpp)/3) )
00263                         bufferRGB->data[i][1] = (unsigned char)( (1<<bpp)/3);
00264                 else
00265                         bufferRGB->data[i][2] = img.data[i][2];
00266 
00267          }
00268         return VETRET_OK;
00269  }
00270 
00271 //taglia tutti i valori saturi e negativi
00272 VETRESULT vetFilterColor::clamp(vetFrameT<unsigned char>& img, unsigned int bpp)//=sizeof(int)*3
00273  {
00274 
00275         return VETRET_NOT_IMPLEMENTED;
00276  }
00277 
00278 
00279 VETRESULT vetFilterColor::invert(vetFrameYUV420& img, unsigned int bpp)//=sizeof(int)*3
00280  {
00281 
00282         return VETRET_NOT_IMPLEMENTED;
00283  }
00284 
00285 VETRESULT vetFilterColor::invert(vetFrameRGB24& img, unsigned int bpp)//=sizeof(int)*3
00286  {
00287 //CHECKBUGS
00288 
00289         int maxVal = (1<<bpp)/3-1;
00290 
00291         useBufferRGB(img.width, img.height);
00292 
00293         for (unsigned int i=0; i < img.width * img.height; i++ )
00294          {
00295                 bufferRGB->data[i][0] = maxVal - img.data[i][0];
00296                 bufferRGB->data[i][1] = maxVal - img.data[i][1];
00297                 bufferRGB->data[i][2] = maxVal - img.data[i][2];
00298          }
00299 
00300         return VETRET_OK;
00301  }
00302 VETRESULT vetFilterColor::invert(vetFrameT<unsigned char>& img, unsigned int bpp)//=sizeof(int)*3
00303  {
00304 
00305         return VETRET_NOT_IMPLEMENTED;
00306  }
00307 
00308 
00309 VETRESULT vetFilterColor::extractBitPlane(vetFrameRGB24& img, unsigned int bits)//=1
00310  {
00311 //CHECKBUGS
00312 
00313         int mask = (1<<bits)/3-1;
00314 
00315         useBufferRGB(img.width, img.height);
00316 
00317         for (unsigned int i=0; i < img.width * img.height; i++ )
00318          {
00319                 bufferRGB->data[i][0] = (img.data[i][0] & mask) != 0;
00320                 bufferRGB->data[i][1] = (img.data[i][1] & mask) != 0;
00321                 bufferRGB->data[i][2] = (img.data[i][2] & mask) != 0;
00322          }
00323 
00324         return VETRET_OK;
00325  }
00326 
00327 
00328 VETRESULT vetFilterColor::extractBitPlane(vetFrameYUV420& img, unsigned int bits)//=1
00329  {
00330         return VETRET_NOT_IMPLEMENTED;
00331  }
00332 
00333 VETRESULT vetFilterColor::extractBitPlane(vetFrameT<unsigned char>& img, unsigned int bits)//=1
00334  {
00335         return VETRET_NOT_IMPLEMENTED;
00336  }
00337 
00338 
00339 
00340 
00341 
00342 
00343 
00344 
00345 
00346 
00347 
00348 
00349 
00350 
00351 
00352 
00353 
00354 
00355 
00356 
00357 
00358 
00359 
00360 vetFilterColorParameters::vetFilterColorParameters(RUNMODE mode)
00361  {
00362         runMode = mode;
00363         reset();
00364  }
00365 
00366 void vetFilterColorParameters::reset()
00367  {
00368         runMode = vetFilterColorParameters::DO_NOTHING;
00369         currBpp = sizeof(int);
00370         currBits = 1;
00371         currentBuffer = vetFilterParameters::NONE;
00372  }
00373 
00374 int vetFilterColorParameters::saveToStreamXML(FILE *fp)
00375  {
00376 
00377         if ( fp == NULL )
00378                 return VETRET_PARAM_ERR;
00379 
00380         if( fprintf(fp, "<vetFilterColorParameters>\n") == EOF )
00381                 return VETRET_INTERNAL_ERR;
00382 
00383         if ( fprintf(fp, "  <runmode value=\"%i\" />\n", (int)runMode) == EOF)
00384                 return VETRET_INTERNAL_ERR;
00385 
00386         if ( fprintf(fp, "  <currBpp value=\"%u\" />\n", currBpp) == EOF)
00387                 return VETRET_INTERNAL_ERR;
00388 
00389         if ( fprintf(fp, "  <currBits value=\"%u\" />\n", currBits) == EOF)
00390                 return VETRET_INTERNAL_ERR;
00391 
00392         if ( fprintf(fp, "  <internalBufferType value=\"%u\" />\n", (int)currentBuffer) == EOF)
00393                 return VETRET_INTERNAL_ERR;
00394 
00395         if( fprintf(fp, "</vetFilterColorParameters>\n") == EOF )
00396                 return VETRET_INTERNAL_ERR;
00397 
00398         return VETRET_OK;
00399  }
00400 
00401 
00402 int vetFilterColorParameters::loadFromStreamXML(FILE *fp)
00403  {
00404         if ( fscanf(fp, "<vetFilterColorParameters>\n") == EOF )
00405                 throw "error in XML file, unable to import data.";
00406 
00407         int runTmp = 0;
00408         if ( fscanf(fp, "  <runmode value=\"%i\" />\n", &runTmp) == EOF )
00409                 throw "error in XML file, unable to import data.";
00410         else
00411                 runMode = (RUNMODE)runTmp;
00412 
00413         if ( fscanf(fp, "  <currBpp value=\"%u\" />\n", &currBpp) == EOF )
00414                 throw "error in XML file, unable to import data.";
00415 
00416         if ( fscanf(fp, "  <currBits value=\"%u\" />\n", &currBits) == EOF )
00417                 throw "error in XML file, unable to import data.";
00418 
00419         int cB = (int)currentBuffer;
00420         if ( fscanf(fp, "  <internalBufferType value=\"%u\" />\n", &cB) == EOF )
00421                 throw "error in XML file, unable to import data.";
00422         currentBuffer = (BUFFER_TYPE)cB;
00423 
00424         return VETRET_OK;
00425  }
00426 
00427 
00428 
00429 

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