From 2adfd28e48bca55689936931cb998b395a1560d4 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Tue, 7 May 2019 22:12:44 +0100 Subject: [PATCH] Change module to enable frame re-sampling --- modules/EightBitsSampling.cpp | 60 ++++++++++++++++------------------- modules/EightBitsSampling.h | 4 ++- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/modules/EightBitsSampling.cpp b/modules/EightBitsSampling.cpp index b230366..cba6cad 100644 --- a/modules/EightBitsSampling.cpp +++ b/modules/EightBitsSampling.cpp @@ -30,53 +30,49 @@ EightBitsSampling::EightBitsSampling() m_iModuleAPI = CLP_MODULE_API_2; m_iModuleType = CLP_FRAME_PROCESSING_MODULE; m_pchModuleCategory = "Conversions"; - m_pchModuleName = "EightBitsSampling"; - m_pchModuleLongName = "8 bit sub-sampling"; - m_pchModuleTooltip = "Sub-sampling frame to 8bpp"; + m_pchModuleName = "BitsResampling"; + m_pchModuleLongName = "Re-sampling frame"; + m_pchModuleTooltip = "Re-sampling frame to a different value of bits per pixel"; m_uiNumberOfFrames = 1; - m_uiModuleRequirements = CLP_MODULE_REQUIRES_NOTHING; + m_uiModuleRequirements = CLP_MODULE_REQUIRES_OPTIONS; - m_pcSubSampledFrame = NULL; + m_cModuleOptions.addOptions() /**/ + ( "num_bits", m_iNumberOfBits, "Number of bits/pixel (8-16) [8]" ); + + m_iNumberOfBits = 8; + m_pcResampledFrame = NULL; } bool EightBitsSampling::create( std::vector apcFrameList ) { - if( apcFrameList[0]->getBitsPel() > 8 ) - { - m_pcSubSampledFrame = NULL; - m_pcSubSampledFrame = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), - apcFrameList[0]->getPelFormat(), 8 ); - return true; - } - return false; + m_iBitSifting = int( apcFrameList[0]->getBitsPel() ) - m_iNumberOfBits; + if( !m_iBitSifting ) + return false; + + m_pcResampledFrame = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), + apcFrameList[0]->getPelFormat(), m_iNumberOfBits ); + return true; } CalypFrame* EightBitsSampling::process( std::vector apcFrameList ) { CalypFrame* pcFrame = apcFrameList[0]; - unsigned int uiShiftBits = pcFrame->getBitsPel() - 8; ClpPel* pPelInput = pcFrame->getPelBufferYUV()[0][0]; - ClpPel* pPelSubSampled = m_pcSubSampledFrame->getPelBufferYUV()[0][0]; - ClpPel pelValue; + ClpPel* pPelResampled = m_pcResampledFrame->getPelBufferYUV()[0][0]; + int bitShifting = m_iBitSifting > 0 ? m_iBitSifting : -m_iBitSifting; - for( unsigned int i = 0; i < pcFrame->getHeight() * pcFrame->getWidth(); i++ ) - { - pelValue = *pPelInput++; - pelValue = pelValue >> uiShiftBits; - *pPelSubSampled++ = pelValue; - } - for( unsigned int i = 0; i < pcFrame->getChromaLength() * 2; i++ ) - { - pelValue = *pPelInput++; - pelValue = pelValue >> uiShiftBits; - *pPelSubSampled++ = pelValue; - } - return m_pcSubSampledFrame; + if( m_iBitSifting > 0 ) + for( unsigned i = 0; i < pcFrame->getTotalNumberOfPixels(); i++ ) + *pPelResampled++ = *pPelInput++ >> bitShifting; + else + for( unsigned i = 0; i < pcFrame->getTotalNumberOfPixels(); i++ ) + *pPelResampled++ = *pPelInput++ << bitShifting; + return m_pcResampledFrame; } void EightBitsSampling::destroy() { - if( m_pcSubSampledFrame ) - delete m_pcSubSampledFrame; - m_pcSubSampledFrame = NULL; + if( m_pcResampledFrame ) + delete m_pcResampledFrame; + m_pcResampledFrame = NULL; } diff --git a/modules/EightBitsSampling.h b/modules/EightBitsSampling.h index 786d3b2..6950a9c 100644 --- a/modules/EightBitsSampling.h +++ b/modules/EightBitsSampling.h @@ -33,7 +33,9 @@ class EightBitsSampling : public CalypModuleIf REGISTER_CLASS_FACTORY( EightBitsSampling ) private: - CalypFrame* m_pcSubSampledFrame; + int m_iNumberOfBits; + int m_iBitSifting; + CalypFrame* m_pcResampledFrame; public: EightBitsSampling();