From 8353c7bddd0e302335cf80ccf23835c18614077e Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Thu, 26 Mar 2015 01:13:27 +0000 Subject: [PATCH] Add FrameCrop code --- modules/FrameCrop.cpp | 81 +++++++++++++++++++++++++++++++++++++++++++ modules/FrameCrop.h | 57 ++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 modules/FrameCrop.cpp create mode 100644 modules/FrameCrop.h diff --git a/modules/FrameCrop.cpp b/modules/FrameCrop.cpp new file mode 100644 index 0000000..d4718cd --- /dev/null +++ b/modules/FrameCrop.cpp @@ -0,0 +1,81 @@ +/* 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 FrameCrop.cpp + * \brief Crop a region of an image + */ + +#include "FrameCrop.h" + +namespace plaYUVer +{ + +FrameCrop::FrameCrop() +{ + /* Module Definition */ + m_iModuleType = FRAME_PROCESSING_MODULE; + m_pchModuleCategory = "Utilities"; + m_pchModuleName = "FrameCrop"; + m_pchModuleTooltip = "Crop a region of a frame"; + m_uiNumberOfFrames = MODULE_REQUIRES_ONE_FRAME; + m_uiModuleRequirements = MODULE_REQUIRES_OPTIONS; + + m_cModuleOptions.addOptions()/**/ + ( "xPosition", m_uiXPosition, "X cordinate of the left-top corner of the crop region [0]" )/**/ + ( "yPosition", m_uiYPosition, "Y cordinate of the left-top corner of the crop region [0]" )/**/ + ( "width", m_iXSize, "Width of the crop region [-1]" )/**/ + ( "height", m_iYSize, "Height of the crop region [-1]" ); + + m_pcCropedFrame = NULL; + m_uiXPosition = 0; + m_uiYPosition = 0; + m_iXSize = -1; + m_iYSize = -1; +} + +Void FrameCrop::create( PlaYUVerFrame* frame ) +{ + m_pcCropedFrame = NULL; + if( m_iXSize == -1 ) + { + m_iXSize = frame->getWidth() - m_uiXPosition; + } + if( m_iYSize == -1 ) + { + m_iYSize = frame->getHeight() - m_uiYPosition; + } + m_pcCropedFrame = new PlaYUVerFrame( m_iXSize, m_iYSize, frame->getPelFormat() ); +} + +PlaYUVerFrame* FrameCrop::process( PlaYUVerFrame* frame ) +{ + m_pcCropedFrame->copyFrom( frame, m_uiXPosition, m_uiYPosition ); + return m_pcCropedFrame; +} + +Void FrameCrop::destroy() +{ + if( m_pcCropedFrame ) + delete m_pcCropedFrame; + m_pcCropedFrame = NULL; +} + +} // NAMESPACE + diff --git a/modules/FrameCrop.h b/modules/FrameCrop.h new file mode 100644 index 0000000..eee1f60 --- /dev/null +++ b/modules/FrameCrop.h @@ -0,0 +1,57 @@ +/* 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 FrameCrop.h + * \brief Crop a region of an image + */ + +#ifndef __FRAMECROP_H__ +#define __FRAMECROP_H__ + +#include "PlaYUVerModuleIf.h" + +namespace plaYUVer +{ + +class FrameCrop: public PlaYUVerModuleIf +{ +REGISTER_CLASS_FACTORY( FrameCrop ) + +private: + PlaYUVerFrame* m_pcCropedFrame; + UInt m_uiXPosition; + UInt m_uiYPosition; + Int m_iXSize; + Int m_iYSize; +public: + FrameCrop(); + virtual ~FrameCrop() + { + } + Void create( PlaYUVerFrame* ); + PlaYUVerFrame* process( PlaYUVerFrame* ); + Void destroy(); + +}; + +} // NAMESPACE + +#endif // __FRAMECROP_H__ +