/** @file vetFilterSample.cpp * * File containing methods for the 'vetFilterSample' class. * The header for this class can be found in vetFilterSample.h, check that file * for class description. * * * **************************************************************************** * VETLib Framework 1.02 * Copyright (C) Alessandro Polo 2005 * http://www.ewgate.net/vetlib * ****************************************************************************/ #include "vetFilterSample.h" /** * @brief Default constructor, initialize parameters and superclasses. * @param[in] initParams parameters for this module or NULL for defaults. */ vetFilterSample::vetFilterSample(vetFilterSampleParameters* initParams) : vetFilter() { INFO("vetFilterSample::vetFilterSample(..* initParams) : vetFilter() [CONTRUCTOR]") myParams = NULL; setParameters(initParams); setName("Geometric Editing Filter"); setDescription("Resize, Crop, Rotation, Flip"); setVersion(1.0); reset(); } /** * @brief Default destructor, free buffer. */ vetFilterSample::~vetFilterSample() { INFO("vetFilterSample::~vetFilterSample() [DESTRUCTOR]") if (myParams != NULL) delete myParams; } /** * @brief Reset buffers and parameters. * * @return VETRET_OK */ VETRESULT vetFilterSample::reset() { INFO("int vetFilterSample::reset() [SET DEFAULT PARAMETERS]") releaseBuffers(); if (myParams != NULL) { myParams->reset(); allocateBuffer(myParams->currentBuffer); } else setParameters(NULL); return VETRET_OK; } /** * @brief Set parameters for this filter. * * @param[in] initParams Instance of vetFilterSampleParameters or NULL, * NULL argument make function to create a new * instance with default parameters. * * @return VETRET_OK */ VETRESULT vetFilterSample::setParameters (vetFilterSampleParameters* initParams) { if (initParams != NULL && myParams == initParams) return VETRET_PARAM_ERR; if ( initParams == NULL ) { if ( myParams != NULL ) reset(); else myParams = new vetFilterSampleParameters(); } else { if ( myParams != NULL ) delete myParams; myParams = initParams; } allocateBuffer(myParams->currentBuffer); return VETRET_OK; } /** * @brief Process the frame with current settings and store in buffer. * * @param[in] img VETLib Cache Frame to be processed. * * @return VETRET_OK if everything is fine, VETRET_INTERNAL_ERR else. * * @note Input operator (<<) call directly this function. * @see operator << (vetFrameYUV420&) */ VETRESULT vetFilterSample::importFrom(vetFrameYUV420& img) { DEBUGMSG("int vetFilterSample::importFrom(vetFrameYUV420& img) [reading data]", myParams->runMode) switch ( myParams->runMode ) { case vetFilterSampleParameters::DO_NOTHING: if ( !isBufferYUV() ) { useBufferYUV(img.width, img.height); *bufferYUV = img; return VETRET_OK_DEPRECATED; } else { *bufferYUV = img; return VETRET_OK; } case vetFilterSampleParameters::ROTATE90: return rotate90(*bufferYUV, img); default: return VETRET_PARAM_ERR; } return VETRET_NOT_IMPLEMENTED; } /** * @brief Process the frame with current settings and store in buffer. * * @param[in] img VETLib Cache24 Frame to be processed. * * @return VETRET_OK if everything is fine, VETRET_INTERNAL_ERR else. * * @note Input operator (<<) call directly this function. * @see operator << (vetFrameRGB24&) */ VETRESULT vetFilterSample::importFrom(vetFrameRGB24& img) { DEBUGMSG("int vetFilterSample::importFrom(vetFrameRGB24& img) [reading data]", myParams->runMode) switch ( myParams->runMode ) { case vetFilterSampleParameters::DO_NOTHING: if ( !isBufferRGB() ) { useBufferRGB(img.width, img.height); *bufferRGB = img; return VETRET_OK_DEPRECATED; } else { *bufferRGB = img; return VETRET_OK; } case vetFilterSampleParameters::ROTATE90: return rotate90(*bufferRGB, img); default: return VETRET_PARAM_ERR; } return VETRET_NOT_IMPLEMENTED; } /** * @brief Process the frame with current settings and store in buffer. * * @param[in] img VETLib Grayscale Frame to be processed. * * @return VETRET_OK if everything is fine, VETRET_INTERNAL_ERR else. * * @note Input operator (<<) call directly this function. * @see operator << (vetFrameT&) */ VETRESULT vetFilterSample::importFrom(vetFrameT& img) { DEBUGMSG("int vetFilterSample::importFrom(vetFrameT& img) [reading data]", myParams->runMode) switch ( myParams->runMode ) { case vetFilterSampleParameters::DO_NOTHING: if ( !isBufferTuC() ) { useBufferTuC(img.width, img.height, img.profile); *bufferTuC = img; return VETRET_OK_DEPRECATED; } else { *bufferTuC = img; return VETRET_OK; } case vetFilterSampleParameters::ROTATE90: return rotate90(*bufferTuC, img); default: return VETRET_PARAM_ERR; } return VETRET_NOT_IMPLEMENTED; } /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// VETRESULT vetFilterSample::rotate90(vetFrameYUV420& dest, vetFrameYUV420& source) { if (dest.width != source.height || dest.height != source.width) dest.reAllocCanvas(source.height, source.width); for ( unsigned int y=0; y < source.height; y++ ) // single pixel copy routine for ( unsigned int x=0; x < source.width; x++ ) dest.data[(dest.height-1-y)*dest.width+x] = source.data[x*source.width + y]; return VETRET_OK; } VETRESULT vetFilterSample::rotate90(vetFrameRGB24& dest, vetFrameRGB24& source) { if (dest.width != source.height || dest.height != source.width) dest.reAllocCanvas(source.height, source.width); for ( unsigned int y=0; y < source.height; y++ ) // single pixel copy routine for ( unsigned int x=0; x < source.width; x++ ) dest.data[(dest.height-1-y)*dest.width+x] = source.data[x*source.width + y]; return VETRET_OK; } VETRESULT vetFilterSample::rotate90(vetFrameT& dest, vetFrameT& source) { if (dest.width != source.height || dest.height != source.width) dest.reAllocCanvas(source.height, source.width); return VETRET_NOT_IMPLEMENTED; } /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// vetFilterSampleParameters::vetFilterSampleParameters() { reset(); } void vetFilterSampleParameters::reset() { runMode = vetFilterSampleParameters::DO_NOTHING; currentBuffer = vetFilterParameters::NONE; } int vetFilterSampleParameters::saveToStreamXML(FILE *fp) { if ( fp == NULL ) return VETRET_PARAM_ERR; if( fprintf(fp, "\n") == EOF ) return VETRET_INTERNAL_ERR; // add your variables here if ( fprintf(fp, " \n", (int)runMode) == EOF) return VETRET_INTERNAL_ERR; if ( fprintf(fp, " \n", (int)currentBuffer) == EOF) return VETRET_INTERNAL_ERR; if( fprintf(fp, "\n") == EOF ) return VETRET_INTERNAL_ERR; return VETRET_OK; } int vetFilterSampleParameters::loadFromStreamXML(FILE *fp) { if ( fscanf(fp, "\n") == EOF ) throw "error in XML file, unable to import data."; // add your variables here int runTmp = 0; if ( fscanf(fp, " \n", &runTmp) == EOF ) throw "error in XML file, unable to import data."; else runMode = (RUNMODE)runTmp; int cB = (int)currentBuffer; if ( fscanf(fp, " \n", &cB) == EOF ) throw "error in XML file, unable to import data."; currentBuffer = (BUFFER_TYPE)cB; return VETRET_OK; }