From 014fd2f28b09edefb4fc7cf63abe2570f2ed901f Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Tue, 6 Feb 2018 04:06:39 +0000 Subject: [PATCH] Improve PlaYUVerFrame and add comments --- lib/PlaYUVerFrame.cpp | 59 ++++++++++++++++++--------------- lib/PlaYUVerFrame.h | 65 ++++++++++++++++++++++++++++++++----- modules/FilterComponent.cpp | 4 +-- modules/FrameShift.cpp | 46 ++++++++------------------ 4 files changed, 106 insertions(+), 68 deletions(-) diff --git a/lib/PlaYUVerFrame.cpp b/lib/PlaYUVerFrame.cpp index 20532ac..0a63833 100644 --- a/lib/PlaYUVerFrame.cpp +++ b/lib/PlaYUVerFrame.cpp @@ -455,6 +455,13 @@ struct PlaYUVerFramePrivate { realChannel = channel; } + else if( m_pcPelFormat->colorSpace == PlaYUVerPixel::COLOR_GRAY ) + { + if( channel >= 10 && channel < 11 ) + { + realChannel = channel - 10; + } + } else if( m_pcPelFormat->colorSpace == PlaYUVerPixel::COLOR_YUV ) { if( channel >= 10 && channel < 13 ) @@ -473,6 +480,8 @@ struct PlaYUVerFramePrivate realChannel = channel - 20; } } + if( realChannel > (Int)m_uiHistoChannels ) + realChannel = -1; return realChannel; } @@ -647,23 +656,9 @@ UInt8 PlaYUVerFrame::getChromaHeightRatio() const return d->m_pcPelFormat->log2ChromaHeight; } -UInt PlaYUVerFrame::getChromaWidth() const -{ - if( d->m_pcPelFormat->colorSpace == GRAY ) - return 0; - return CHROMASHIFT( d->m_uiWidth, d->m_pcPelFormat->log2ChromaWidth ); -} - -UInt PlaYUVerFrame::getChromaHeight() const -{ - if( d->m_pcPelFormat->colorSpace == GRAY ) - return 0; - return CHROMASHIFT( d->m_uiHeight, d->m_pcPelFormat->log2ChromaHeight ); -} - UInt PlaYUVerFrame::getChromaLength() const { - return getChromaWidth() * getChromaHeight(); + return getWidth( 1 ) * getHeight( 1 ); } UInt PlaYUVerFrame::getBitsPel() const @@ -727,16 +722,28 @@ UChar* PlaYUVerFrame::getRGBBuffer() const } return NULL; } -UChar* PlaYUVerFrame::getRGBBuffer() +//UChar* PlaYUVerFrame::getRGBBuffer() +//{ +// if( !d->m_bHasRGBPel ) +// { +// fillRGBBuffer(); +// } +// return d->m_pcARGB32; +//} + +Pel PlaYUVerFrame::operator()( UInt ch, UInt xPos, UInt yPos ) { - if( !d->m_bHasRGBPel ) - { - fillRGBBuffer(); - } - return d->m_pcARGB32; + if( ch < d->m_pcPelFormat->numberChannels ) + return d->m_pppcInputPel[ch][yPos][xPos]; + return 0; } -PlaYUVerPixel PlaYUVerFrame::getPixel( Int xPos, Int yPos ) +PlaYUVerPixel PlaYUVerFrame::operator()( UInt xPos, UInt yPos ) +{ + return getPixel( xPos, yPos ); +} + +PlaYUVerPixel PlaYUVerFrame::getPixel( UInt xPos, UInt yPos ) { PlaYUVerPixel PixelValue( d->m_pcPelFormat->colorSpace ); for( UInt ch = 0; ch < d->m_pcPelFormat->numberChannels; ch++ ) @@ -748,7 +755,7 @@ PlaYUVerPixel PlaYUVerFrame::getPixel( Int xPos, Int yPos ) return PixelValue; } -PlaYUVerPixel PlaYUVerFrame::getPixel( Int xPos, Int yPos, PlaYUVerPixel::ColorSpace eColorSpace ) +PlaYUVerPixel PlaYUVerFrame::getPixel( UInt xPos, UInt yPos, PlaYUVerPixel::ColorSpace eColorSpace ) { PlaYUVerPixel PixelValue( d->m_pcPelFormat->colorSpace ); for( UInt ch = 0; ch < d->m_pcPelFormat->numberChannels; ch++ ) @@ -761,7 +768,7 @@ PlaYUVerPixel PlaYUVerFrame::getPixel( Int xPos, Int yPos, PlaYUVerPixel::ColorS return PixelValue; } -Void PlaYUVerFrame::setPixel( Int xPos, Int yPos, PlaYUVerPixel pixel ) +Void PlaYUVerFrame::setPixel( UInt xPos, UInt yPos, PlaYUVerPixel pixel ) { for( UInt ch = 0; ch < d->m_pcPelFormat->numberChannels; ch++ ) { @@ -1552,8 +1559,8 @@ Double PlaYUVerFrame::getSSIM( PlaYUVerFrame* Org, Int component ) } else { - dSSIM = compute_ssim( d->m_pppcInputPel[component], Org->getPelBufferYUV()[component], getChromaWidth(), - getChromaHeight(), 4, 4, 255, 4 ); + dSSIM = compute_ssim( d->m_pppcInputPel[component], Org->getPelBufferYUV()[component], getWidth( component ), + getHeight( component ), 4, 4, 255, 4 ); } return dSSIM; } diff --git a/lib/PlaYUVerFrame.h b/lib/PlaYUVerFrame.h index 2559577..9c1dfa4 100644 --- a/lib/PlaYUVerFrame.h +++ b/lib/PlaYUVerFrame.h @@ -253,12 +253,23 @@ public: */ UInt getPixels( Int channel = 0 ) const; + /** + * Get chroma width ratio + * @return ratio multiple of 2 + */ UInt8 getChromaWidthRatio() const; + + /** + * Get chroma height ratio + * @return ratio multiple of 2 + */ UInt8 getChromaHeightRatio() const; - UInt getChromaWidth() const; - UInt getChromaHeight() const; + + /** + * Get number of pixels in each chroma channel + * @return number of pixels + */ UInt getChromaLength() const; - UInt getChromaSize() const; /** * Get number of bits per pixel @@ -285,12 +296,50 @@ public: Pel*** getPelBufferYUV() const; Pel*** getPelBufferYUV(); - UChar* getRGBBuffer() const; - UChar* getRGBBuffer(); - PlaYUVerPixel getPixel( Int xPos, Int yPos ); - PlaYUVerPixel getPixel( Int xPos, Int yPos, PlaYUVerPixel::ColorSpace eColorSpace ); - Void setPixel( Int xPos, Int yPos, PlaYUVerPixel pixel ); + UChar* getRGBBuffer() const; + + /** + * Get pixel value at coordinates + * @param ch frame channel + * @param xPos position in X axis + * @param yPos position in Y axis + * @return pixel value + */ + Pel operator()( UInt ch, UInt xPos, UInt yPos ); + + /** + * Get pixel value at coordinates + * @param xPos position in X axis + * @param yPos position in Y axis + * @return pixel value + */ + PlaYUVerPixel operator()( UInt xPos, UInt yPos ); + + /** + * Get pixel value at coordinates + * @param xPos position in X axis + * @param yPos position in Y axis + * @return pixel value + */ + PlaYUVerPixel getPixel( UInt xPos, UInt yPos ); + + /** + * Get pixel value at coordinates + * in the desired color space + * @param xPos position in X axis + * @param yPos position in Y axis + * @param eColorSpace desired color space + * @return pixel value + */ + PlaYUVerPixel getPixel( UInt xPos, UInt yPos, PlaYUVerPixel::ColorSpace eColorSpace ); + + /** + * Set pixel value at coordinates to a given value + * @param xPos position in X axis + * @param yPos position in Y axis + */ + Void setPixel( UInt xPos, UInt yPos, PlaYUVerPixel pixel ); Void copyFrom( const PlaYUVerFrame& ); Void copyFrom( const PlaYUVerFrame* ); diff --git a/modules/FilterComponent.cpp b/modules/FilterComponent.cpp index 6f59019..90c5d3b 100644 --- a/modules/FilterComponent.cpp +++ b/modules/FilterComponent.cpp @@ -90,7 +90,7 @@ Bool FilterComponentChromaU::create( std::vector apcFrameList ) { if( apcFrameList[0]->getNumberChannels() > 1 ) { - return createFilter( apcFrameList[0]->getChromaWidth(), apcFrameList[0]->getChromaHeight(), + return createFilter( apcFrameList[0]->getWidth( CHROMA_U ), apcFrameList[0]->getHeight( CHROMA_U ), apcFrameList[0]->getBitsPel() ); } return false; @@ -113,7 +113,7 @@ Bool FilterComponentChromaV::create( std::vector apcFrameList ) { if( apcFrameList[0]->getNumberChannels() > 1 ) { - return createFilter( apcFrameList[0]->getChromaWidth(), apcFrameList[0]->getChromaHeight(), + return createFilter( apcFrameList[0]->getWidth( CHROMA_V ), apcFrameList[0]->getHeight( CHROMA_V ), apcFrameList[0]->getBitsPel() ); } return false; diff --git a/modules/FrameShift.cpp b/modules/FrameShift.cpp index fc97593..aea5559 100644 --- a/modules/FrameShift.cpp +++ b/modules/FrameShift.cpp @@ -57,47 +57,29 @@ PlaYUVerFrame* FrameShift::process( std::vector apcFrameList ) Pel* pPelInput; Pel* pPelOut; - UInt xStartOut = m_iShiftHor >= 0 ? m_iShiftHor : 0; - UInt xStartIn = m_iShiftHor >= 0 ? 0 : -m_iShiftHor; - UInt xEndOut = m_iShiftHor >= 0 ? m_pcProcessedFrame->getWidth() : m_pcProcessedFrame->getWidth() + m_iShiftHor; - - UInt yStartOut = m_iShiftVer >= 0 ? m_iShiftVer : 0; - UInt yStartIn = m_iShiftVer >= 0 ? 0 : -m_iShiftVer; - UInt yEndOut = m_iShiftVer >= 0 ? m_pcProcessedFrame->getHeight() : m_pcProcessedFrame->getHeight() + m_iShiftVer; - m_pcProcessedFrame->clear(); - for( UInt y = yStartOut, yIn = yStartIn; y < yEndOut; y++, yIn++ ) + for( UInt ch = 0; ch < m_pcProcessedFrame->getNumberChannels(); ch++ ) { - pPelInput = &( apcFrameList[0]->getPelBufferYUV()[LUMA][yIn][xStartIn] ); - pPelOut = &( m_pcProcessedFrame->getPelBufferYUV()[LUMA][y][xStartOut] ); - for( UInt x = xStartOut; x < xEndOut; x++ ) - { - *pPelOut = *pPelInput; - pPelInput++; - pPelOut++; - } - } + UInt uiWidth = m_pcProcessedFrame->getWidth( ch ); + UInt uiHeight = m_pcProcessedFrame->getHeight( ch ); - Int iShiftHorChroma = CHROMASHIFT( m_iShiftHor, m_pcProcessedFrame->getChromaWidthRatio() ); - Int iShiftVerChroma = CHROMASHIFT( m_iShiftVer, m_pcProcessedFrame->getChromaHeightRatio() ); + Int iShiftHor = m_iShiftHor >> ( ch > 0 ? m_pcProcessedFrame->getChromaWidthRatio() : 0 ); + Int iShiftVer = m_iShiftVer >> ( ch > 0 ? m_pcProcessedFrame->getChromaHeightRatio() : 0 ); - xStartOut = iShiftHorChroma >= 0 ? iShiftHorChroma : 0; - xStartIn = iShiftHorChroma >= 0 ? 0 : -iShiftHorChroma; - xEndOut = iShiftHorChroma >= 0 ? m_pcProcessedFrame->getChromaWidth() : - m_pcProcessedFrame->getChromaWidth() + iShiftHorChroma; + UInt xStartIn = iShiftHor >= 0 ? 0 : -iShiftHor; + UInt yStartIn = iShiftVer >= 0 ? 0 : -iShiftVer; - yStartOut = iShiftVerChroma >= 0 ? iShiftVerChroma : 0; - yStartIn = iShiftVerChroma >= 0 ? 0 : -iShiftVerChroma; - yEndOut = iShiftVerChroma >= 0 ? m_pcProcessedFrame->getChromaHeight() : - m_pcProcessedFrame->getChromaHeight() + iShiftVerChroma; + UInt xStartOut = std::max( iShiftHor, 0 ); + UInt xEndOut = std::min( uiWidth, uiWidth + iShiftHor ); + + UInt yStartOut = std::max( iShiftVer, 0 ); + UInt yEndOut = std::min( uiHeight, uiHeight + iShiftVer ); - for( UInt c = 1; c < m_pcProcessedFrame->getNumberChannels(); c++ ) - { for( UInt y = yStartOut, yIn = yStartIn; y < yEndOut; y++, yIn++ ) { - pPelInput = &( apcFrameList[0]->getPelBufferYUV()[c][yIn][xStartIn] ); - pPelOut = &( m_pcProcessedFrame->getPelBufferYUV()[c][y][xStartOut] ); + pPelInput = &( apcFrameList[0]->getPelBufferYUV()[ch][yIn][xStartIn] ); + pPelOut = &( m_pcProcessedFrame->getPelBufferYUV()[ch][y][xStartOut] ); for( UInt x = xStartOut; x < xEndOut; x++ ) { *pPelOut = *pPelInput;