diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index b297cdd..20d0b75 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -38,6 +38,7 @@ ADD_MODULE( FilterComponentChromaV "FilterComponent" ) ADD_MODULE( FrameDifference "FrameDifference" ) ADD_MODULE( AbsoluteFrameDifference "AbsoluteFrameDifference" ) ADD_MODULE( FrameBinarization "FrameBinarization" ) +ADD_MODULE( EightBitsSampling "EightBitsSampling" ) ADD_MODULE( FrameCrop "FrameCrop" ) ADD_MODULE( LumaAverage "LumaAverage" ) IF( USE_OPENCV ) diff --git a/modules/EightBitsSampling.cpp b/modules/EightBitsSampling.cpp new file mode 100644 index 0000000..4ed2f20 --- /dev/null +++ b/modules/EightBitsSampling.cpp @@ -0,0 +1,86 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file EightBitsSampling.cpp + * \brief Binarize frame module + */ + +#include "EightBitsSampling.h" + +namespace plaYUVer +{ + +EightBitsSampling::EightBitsSampling() +{ + /* Module Definition */ + m_iModuleAPI = MODULE_API_2; + m_iModuleType = FRAME_PROCESSING_MODULE; + m_pchModuleCategory = "Conversions"; + m_pchModuleName = "EightBitsSampling"; + m_pchModuleTooltip = "Sub-sampling frame to 8bpp"; + m_uiNumberOfFrames = MODULE_REQUIRES_ONE_FRAME; + m_uiModuleRequirements = MODULE_REQUIRES_NOTHING; + + m_pcSubSampledFrame = NULL; +} + +Bool EightBitsSampling::create( std::vector apcFrameList ) +{ + if( apcFrameList[0]->getBitsPel() > 8 ) + { + m_pcSubSampledFrame = NULL; + m_pcSubSampledFrame = new PlaYUVerFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), apcFrameList[0]->getPelFormat(), 8 ); + return true; + } + return false; +} + +PlaYUVerFrame* EightBitsSampling::process( std::vector apcFrameList ) +{ + PlaYUVerFrame* pcFrame = apcFrameList[0]; + UInt uiShiftBits = pcFrame->getBitsPel() - 8; + Pel* pPelInput = pcFrame->getPelBufferYUV()[0][0]; + Pel* pPelSubSampled = m_pcSubSampledFrame->getPelBufferYUV()[0][0]; + Pel pelValue; + + for( UInt i = 0; i < pcFrame->getHeight() * pcFrame->getWidth(); i++ ) + { + pelValue = *pPelInput++; + pelValue = pelValue >> uiShiftBits; + *pPelSubSampled++ = pelValue; + } + for( UInt i = 0; i < pcFrame->getChromaLength() * 2; i++ ) + { + pelValue = *pPelInput++; + pelValue = pelValue >> uiShiftBits; + *pPelSubSampled++ = pelValue; + } + return m_pcSubSampledFrame; +} + +Void EightBitsSampling::destroy() +{ + if( m_pcSubSampledFrame ) + delete m_pcSubSampledFrame; + m_pcSubSampledFrame = NULL; +} + +} // NAMESPACE + diff --git a/modules/EightBitsSampling.h b/modules/EightBitsSampling.h new file mode 100644 index 0000000..98045b6 --- /dev/null +++ b/modules/EightBitsSampling.h @@ -0,0 +1,53 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file EightBitsSampling.h + * \brief Binarize frame module + */ + +#ifndef __EIGHTBITSSAMPLING_H__ +#define __EIGHTBITSSAMPLING_H__ + +#include "PlaYUVerModuleIf.h" + +namespace plaYUVer +{ + +class EightBitsSampling: public PlaYUVerModuleIf +{ +REGISTER_CLASS_FACTORY( EightBitsSampling ) + +private: + PlaYUVerFrame* m_pcSubSampledFrame; +public: + EightBitsSampling(); + virtual ~EightBitsSampling() + { + } + Bool create( std::vector apcFrameList ); + PlaYUVerFrame* process( std::vector apcFrameList ); + Void destroy(); + +}; + +} // NAMESPACE + +#endif // __EIGHTBITSSAMPLING_H__ + diff --git a/modules/PlaYUVerModuleFactory.cpp b/modules/PlaYUVerModuleFactory.cpp index 3716716..eb63928 100644 --- a/modules/PlaYUVerModuleFactory.cpp +++ b/modules/PlaYUVerModuleFactory.cpp @@ -40,6 +40,7 @@ PlaYUVerModuleFactory::PlaYUVerModuleFactory() Register( "AbsoluteFrameDifference", &AbsoluteFrameDifference::Create ); Register( "FrameCrop", &FrameCrop::Create ); Register( "FrameBinarization", &FrameBinarization::Create ); + Register( "EightBitsSampling", &EightBitsSampling::Create ); Register( "LumaAverage", &LumaAverage::Create ); #ifdef USE_OPENCV Register( "DisparityStereoVar", &DisparityStereoVar::Create );