From 0654f4260d1ecf4cdd4ee9eb478e495018908e09 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Mon, 7 May 2018 22:11:56 +0100 Subject: [PATCH] Add frame concatenation module --- modules/CMakeLists.txt | 1 + modules/FrameConcatenation.cpp | 101 +++++++++++++++++++++++++++++++++ modules/FrameConcatenation.h | 47 +++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 modules/FrameConcatenation.cpp create mode 100644 modules/FrameConcatenation.h diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 5f682b5..457810a 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -23,6 +23,7 @@ ADD_MODULE( AbsoluteFrameDifference "AbsoluteFrameDifference" ) ADD_MODULE( InterFrameVariance "InterFrameVariance" ) ADD_MODULE( FrameBinarization "FrameBinarization" ) ADD_MODULE( FrameShift "FrameShift" ) +ADD_MODULE( FrameConcatenation "FrameConcatenation" ) ADD_MODULE( SetChromaHalfScale "SetChromaHalfScale" ) ADD_MODULE( EightBitsSampling "EightBitsSampling" ) ADD_MODULE( FrameCrop "FrameCrop" ) diff --git a/modules/FrameConcatenation.cpp b/modules/FrameConcatenation.cpp new file mode 100644 index 0000000..a00fa86 --- /dev/null +++ b/modules/FrameConcatenation.cpp @@ -0,0 +1,101 @@ +/* This file is a part of Calyp 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 FrameConcatenation.cpp + * \brief Concatenate two frames side-by-side + */ + +#include "FrameConcatenation.h" + +FrameConcatenation::FrameConcatenation() +{ + /* Module Definition */ + m_iModuleAPI = CLP_MODULE_API_2; + m_iModuleType = CLP_FRAME_PROCESSING_MODULE; + m_pchModuleCategory = "Utilities"; + m_pchModuleLongName = "Frame Concatenation"; + m_pchModuleName = "FrameConc"; + m_pchModuleTooltip = "Concatenate frames side-by-side"; + m_uiNumberOfFrames = 2; + m_uiModuleRequirements = CLP_MODULE_REQUIRES_OPTIONS | CLP_MODULE_REQUIRES_NEW_WINDOW; + + m_cModuleOptions.addOptions() /**/ + ( "ShiftHorizontal", m_iShiftHor, "Amount of pixels to shift in horizontal direction" ); + + m_pcProcessedFrame = NULL; + m_iShiftHor = 64; +} + +bool FrameConcatenation::create( std::vector apcFrameList ) +{ + _BASIC_MODULE_API_2_CHECK_ + + for( unsigned int i = 1; i < apcFrameList.size(); i++ ) + { + if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], CalypFrame::MATCH_COLOR_SPACE | + CalypFrame::MATCH_RESOLUTION | + CalypFrame::MATCH_BITS ) ) + { + return false; + } + } + + unsigned int newWidth = apcFrameList[0]->getWidth() * 2 + m_iShiftHor; + m_pcProcessedFrame = new CalypFrame( newWidth, apcFrameList[0]->getHeight(), apcFrameList[0]->getPelFormat(), apcFrameList[0]->getBitsPel() ); + return true; +} + +CalypFrame* FrameConcatenation::process( std::vector apcFrameList ) +{ + ClpPel* pelLeft; + ClpPel* pelRight; + ClpPel* pelout; + + m_pcProcessedFrame->reset(); + + for( unsigned int ch = 0; ch < m_pcProcessedFrame->getNumberChannels(); ch++ ) + { + unsigned int uiHeight = apcFrameList[0]->getHeight( ch ); + unsigned int uiWidth = apcFrameList[0]->getWidth( ch ); + unsigned int shift = ch == 0 ? m_iShiftHor : m_iShiftHor >> m_pcProcessedFrame->getChromaWidthRatio(); + + for( unsigned int y = 0; y < uiHeight; y++ ) + { + pelLeft = apcFrameList[0]->getPelBufferYUV()[ch][y]; + pelRight = apcFrameList[1]->getPelBufferYUV()[ch][y]; + pelout = m_pcProcessedFrame->getPelBufferYUV()[ch][y]; + + for( unsigned int x = 0; x < uiWidth; x++ ) + { + *pelout = *pelLeft++; + *( pelout + uiWidth + shift ) = *pelRight++; + pelout++; + } + } + } + return m_pcProcessedFrame; +} + +void FrameConcatenation::destroy() +{ + if( m_pcProcessedFrame ) + delete m_pcProcessedFrame; + m_pcProcessedFrame = NULL; +} diff --git a/modules/FrameConcatenation.h b/modules/FrameConcatenation.h new file mode 100644 index 0000000..6813f6a --- /dev/null +++ b/modules/FrameConcatenation.h @@ -0,0 +1,47 @@ +/* This file is a part of Calyp 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 FrameConcatenation.h + * \brief Concatenate two frames side-by-side + */ + +#ifndef __FRAMECONCATENATION_H__ +#define __FRAMECONCATENATION_H__ + +// CalypLib +#include "lib/CalypModuleIf.h" + +class FrameConcatenation : public CalypModuleIf +{ + REGISTER_CLASS_FACTORY( FrameConcatenation ) + +private: + CalypFrame* m_pcProcessedFrame; + int m_iShiftHor; + +public: + FrameConcatenation(); + virtual ~FrameConcatenation() {} + bool create( std::vector apcFrameList ); + CalypFrame* process( std::vector apcFrameList ); + void destroy(); +}; + +#endif // __FrameShift_H__