From ed5876bbc3fe98d190ecbacf8d1aee3a9801efcb Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Wed, 31 Jan 2018 02:24:55 +0000 Subject: [PATCH] Add module to rotate frame --- modules/CMakeLists.txt | 1 + modules/FrameRotate.cpp | 118 ++++++++++++++++++++++++++++++++++++++++ modules/FrameRotate.h | 47 ++++++++++++++++ 3 files changed, 166 insertions(+) create mode 100644 modules/FrameRotate.cpp create mode 100644 modules/FrameRotate.h diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index cc25656..df6dcca 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -18,6 +18,7 @@ ADD_MODULE( FilterComponentChromaU "FilterComponent" ) ADD_MODULE( FilterComponentChromaV "FilterComponent" ) ADD_MODULE( FrameDifference "FrameDifference" ) ADD_MODULE( FrameMask "FrameMask" ) +ADD_MODULE( FrameRotate "FrameRotate" ) ADD_MODULE( AbsoluteFrameDifference "AbsoluteFrameDifference" ) ADD_MODULE( InterFrameVariance "InterFrameVariance" ) ADD_MODULE( FrameBinarization "FrameBinarization" ) diff --git a/modules/FrameRotate.cpp b/modules/FrameRotate.cpp new file mode 100644 index 0000000..cfef3cc --- /dev/null +++ b/modules/FrameRotate.cpp @@ -0,0 +1,118 @@ +/* This file is a part of PlaYUVer project + * Copyright (C) 2014-2018 by Joao Carreira (jfmcarreira@gmail.com) + * Luis Lucas (luisfrlucas@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 FrameRotate.cpp + * \brief Frame Difference module + */ + +#include "FrameRotate.h" + +FrameRotate::FrameRotate() +{ + /* Module Definition */ + m_iModuleAPI = MODULE_API_2; + m_iModuleType = FRAME_PROCESSING_MODULE; + m_pchModuleCategory = "Utilities"; + m_pchModuleName = "FrameRotate"; + m_pchModuleTooltip = "Rotates frame"; + m_uiNumberOfFrames = MODULE_REQUIRES_ONE_FRAME; + m_uiModuleRequirements = MODULE_REQUIRES_OPTIONS; + + m_cModuleOptions.addOptions() /**/ + ( "Angle", m_iAngle, "Angle to rotate (0, 90, 180, 270)" ); + + m_iAngle = 90; + + m_pcFrameProcessed = NULL; +} + +Bool FrameRotate::create( std::vector apcFrameList ) +{ + _BASIC_MODULE_API_2_CHECK_ + + UInt iWidth; + UInt iHeight; + + switch( m_iAngle ) + { + case 0: + case 180: + iWidth = apcFrameList[0]->getWidth(); + iHeight = apcFrameList[0]->getHeight(); + break; + case 90: + case 270: + iHeight = apcFrameList[0]->getWidth(); + iWidth = apcFrameList[0]->getHeight(); + break; + default: + return false; + } + + m_pcFrameProcessed = new PlaYUVerFrame( iWidth, iHeight, apcFrameList[0]->getPelFormat(), + apcFrameList[0]->getBitsPel() ); + return true; +} + +PlaYUVerFrame* FrameRotate::process( std::vector apcFrameList ) +{ + PlaYUVerFrame* InputFrame = apcFrameList[0]; + UInt inWidht = InputFrame->getWidth(); + UInt inHeight = InputFrame->getHeight(); + PlaYUVerPixel pixel; + UInt inX; + UInt inY; + + for( UInt y = 0; y < m_pcFrameProcessed->getHeight(); y++ ) + { + for( UInt x = 0; x < m_pcFrameProcessed->getWidth(); x++ ) + { + inX = x; + inY = y; + switch( m_iAngle ) + { + case 90: + inX = y; + inY = inHeight - x - 1; + break; + case 180: + inX = inWidht - x - 1; + inY = inHeight - y - 1; + break; + case 270: + inX = inWidht - y; + inY = x; + break; + } + pixel = InputFrame->getPixelValue( inX, inY ); + m_pcFrameProcessed->setPixelValue( x, y, pixel ); + } + } + return m_pcFrameProcessed; +} + +Void FrameRotate::destroy() +{ + if( m_pcFrameProcessed ) + { + delete m_pcFrameProcessed; + } + m_pcFrameProcessed = NULL; +} diff --git a/modules/FrameRotate.h b/modules/FrameRotate.h new file mode 100644 index 0000000..c40d7f4 --- /dev/null +++ b/modules/FrameRotate.h @@ -0,0 +1,47 @@ +/* This file is a part of PlaYUVer project + * Copyright (C) 2014-2018 by Joao Carreira (jfmcarreira@gmail.com) + * Luis Lucas (luisfrlucas@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 FrameRotate.h + * \brief Module to aapply a mask to an image + */ + +#ifndef __FRAMEROTATE_H__ +#define __FRAMEROTATE_H__ + +// PlaYUVerLib +#include "lib/PlaYUVerModuleIf.h" + +class FrameRotate : public PlaYUVerModuleIf +{ + REGISTER_CLASS_FACTORY( FrameRotate ) + +private: + Int m_iAngle; + PlaYUVerFrame* m_pcFrameProcessed; + +public: + FrameRotate(); + virtual ~FrameRotate() {} + Bool create( std::vector apcFrameList ); + PlaYUVerFrame* process( std::vector apcFrameList ); + Void destroy(); +}; + +#endif // __FRAMEROTATE_H__