From 6841e571358ca007e50927acc89bb07f89102153 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Wed, 9 Mar 2016 01:15:40 +0000 Subject: [PATCH] Add FrameMask module Fix module to work with mismatch pixel formats (this is usefull for gray masks) --- modules/CMakeLists.txt | 1 + modules/FrameMask.cpp | 103 ++++++++++++++++++++++++++++++ modules/FrameMask.h | 60 +++++++++++++++++ modules/FrameShift.cpp | 2 +- modules/PlaYUVerModuleFactory.cpp | 1 + 5 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 modules/FrameMask.cpp create mode 100644 modules/FrameMask.h diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index e4d0c58..db5a07e 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -35,6 +35,7 @@ ADD_MODULE( FilterComponentLuma "FilterComponent" ) ADD_MODULE( FilterComponentChromaU "FilterComponent" ) ADD_MODULE( FilterComponentChromaV "FilterComponent" ) ADD_MODULE( FrameDifference "FrameDifference" ) +ADD_MODULE( FrameMask "FrameMask" ) ADD_MODULE( AbsoluteFrameDifference "AbsoluteFrameDifference" ) ADD_MODULE( FrameBinarization "FrameBinarization" ) ADD_MODULE( FrameShift "FrameShift" ) diff --git a/modules/FrameMask.cpp b/modules/FrameMask.cpp new file mode 100644 index 0000000..89c6d96 --- /dev/null +++ b/modules/FrameMask.cpp @@ -0,0 +1,103 @@ +/* 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 FrameMask.cpp + * \brief Frame Difference module + */ + +#include "FrameMask.h" +#include + +namespace plaYUVer +{ + +FrameMask::FrameMask() +{ + /* Module Definition */ + m_iModuleAPI = MODULE_API_2; + m_iModuleType = FRAME_PROCESSING_MODULE; + m_pchModuleCategory = "Utilities"; + m_pchModuleName = "FrameMask"; + m_pchModuleTooltip = "Applies a mask to the selected image (first image)"; + m_uiModuleRequirements = MODULE_REQUIRES_NEW_WINDOW; + m_uiNumberOfFrames = MODULE_REQUIRES_TWO_FRAMES; + + m_dWeigth = 0.3; + + m_pcFrameMask = NULL; +} + +Bool FrameMask::create( std::vector apcFrameList ) +{ + _BASIC_MODULE_API_2_CHECK_ + + for( UInt i = 0; i < apcFrameList.size(); i++ ) + { + if( !apcFrameList[i]->haveSameFmt( apcFrameList[i], PlaYUVerFrame::MATCH_COLOR_SPACE | + PlaYUVerFrame::MATCH_RESOLUTION | PlaYUVerFrame::MATCH_BITS ) ) + { + return false; + } + } + + m_pcFrameMask = new PlaYUVerFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), apcFrameList[0]->getPelFormat(), apcFrameList[0]->getBitsPel() ); + return true; +} + +PlaYUVerFrame* FrameMask::process( std::vector apcFrameList ) +{ + Pel* pInput1PelYUV = apcFrameList[0]->getPelBufferYUV()[0][0]; + Pel* pInput2PelYUV = apcFrameList[1]->getPelBufferYUV()[0][0]; + Pel* pOutputPelYUV = m_pcFrameMask->getPelBufferYUV()[0][0]; + Double aux_pel_1, aux_pel_2, aux_pel_mask; + + for( UInt y = 0; y < m_pcFrameMask->getHeight(); y++ ) + for( UInt x = 0; x < m_pcFrameMask->getWidth(); x++ ) + { + aux_pel_1 = *pInput1PelYUV++; + aux_pel_2 = *pInput2PelYUV++; + aux_pel_mask = aux_pel_1 * ( 1 - m_dWeigth ) + aux_pel_2 * m_dWeigth; + *pOutputPelYUV++ = aux_pel_mask; + } + + for( UInt c = 1; c < m_pcFrameMask->getNumberChannels(); c++ ) + for( UInt y = 0; y < m_pcFrameMask->getChromaHeight(); y++ ) + for( UInt x = 0; x < m_pcFrameMask->getChromaWidth(); x++ ) + { + aux_pel_1 = *pInput1PelYUV++; + aux_pel_2 = *pInput2PelYUV++; + aux_pel_mask = aux_pel_1 * ( 1 - m_dWeigth ) + aux_pel_2 * m_dWeigth; + *pOutputPelYUV++ = aux_pel_mask; + } + + return m_pcFrameMask; +} + +Void FrameMask::destroy() +{ + if( m_pcFrameMask ) + { + delete m_pcFrameMask; + } + m_pcFrameMask = NULL; +} + +} // NAMESPACE + diff --git a/modules/FrameMask.h b/modules/FrameMask.h new file mode 100644 index 0000000..bf5f3b7 --- /dev/null +++ b/modules/FrameMask.h @@ -0,0 +1,60 @@ +/* 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 FrameMask.h + * \brief Module to aapply a mask to an image + */ + +#ifndef __FRAMEMASK_H__ +#define __FRAMEMASK_H__ + +#include "lib/PlaYUVerModuleIf.h" + +#include + +namespace plaYUVer +{ + +class FrameMask: public PlaYUVerModuleIf +{ + REGISTER_CLASS_FACTORY( FrameMask ) + +private: + Double m_dWeigth; + PlaYUVerFrame* m_pcFrameMask; + +public: + FrameMask(); + virtual ~FrameMask() + { + } + Bool create( std::vector apcFrameList ); + PlaYUVerFrame* process( std::vector apcFrameList ); + Void destroy(); + +}; + +} // NAMESPACE + +#endif // __FRAMEMASK_H__ + + + + diff --git a/modules/FrameShift.cpp b/modules/FrameShift.cpp index 13f9b54..bf686c6 100644 --- a/modules/FrameShift.cpp +++ b/modules/FrameShift.cpp @@ -85,7 +85,7 @@ PlaYUVerFrame* FrameShift::process( std::vector apcFrameList ) } Int iShiftHorChroma = CHROMASHIFT( m_iShiftHor, m_pcProcessedFrame->getChromaWidthRatio() ); - Int iShiftVerChroma = CHROMASHIFT( m_iShiftVer, m_pcProcessedFrame->getChromaWidthRatio() ); + Int iShiftVerChroma = CHROMASHIFT( m_iShiftVer, m_pcProcessedFrame->getChromaHeightRatio() ); xStartOut = iShiftHorChroma >= 0 ? iShiftHorChroma : 0; xStartIn = iShiftHorChroma >= 0 ? 0 : -iShiftHorChroma; diff --git a/modules/PlaYUVerModuleFactory.cpp b/modules/PlaYUVerModuleFactory.cpp index 6b0e01c..961295b 100644 --- a/modules/PlaYUVerModuleFactory.cpp +++ b/modules/PlaYUVerModuleFactory.cpp @@ -41,6 +41,7 @@ PlaYUVerModuleFactory::PlaYUVerModuleFactory() Register( "FilterComponentChromaV", &FilterComponentChromaV::Create ); Register( "AbsoluteFrameDifference", &AbsoluteFrameDifference::Create ); Register( "FrameDifference", &FrameDifference::Create ); + Register( "FrameMask", &FrameMask::Create ); Register( "SetChromaHalfScale", &SetChromaHalfScale::Create ); Register( "FrameCrop", &FrameCrop::Create ); Register( "FrameBinarization", &FrameBinarization::Create );