From d6676b3eaf551ccc707a9e52485223d86f1de203 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Mon, 15 Apr 2019 16:37:44 +0100 Subject: [PATCH] Fix copyTo and copyFrom functions --- lib/CalypFrame.cpp | 25 +++++++++---------------- lib/CalypFrame.h | 31 +++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/lib/CalypFrame.cpp b/lib/CalypFrame.cpp index 73c447b..26431c7 100644 --- a/lib/CalypFrame.cpp +++ b/lib/CalypFrame.cpp @@ -546,61 +546,54 @@ void CalypFrame::copyFrom( const CalypFrame* other ) copyFrom( *other ); } -void CalypFrame::copyFrom( const CalypFrame& other, unsigned int xPos, unsigned int yPos ) +void CalypFrame::copyFrom( const CalypFrame& other, unsigned x, unsigned y ) { if( !haveSameFmt( other, MATCH_COLOR_SPACE | MATCH_BITS ) ) return; // TODO: Protect width and height ClpPel*** pInput = other.getPelBufferYUV(); - // ClpPel* pInput; - // ClpPel* pOutput; for( unsigned int ch = 0; ch < d->m_pcPelFormat->numberChannels; ch++ ) { int ratioH = ch > 0 ? d->m_pcPelFormat->log2ChromaWidth : 0; int ratioW = ch > 0 ? d->m_pcPelFormat->log2ChromaHeight : 0; for( unsigned int i = 0; i < CHROMASHIFT( d->m_uiHeight, ratioH ); i++ ) { - memcpy( &( d->m_pppcInputPel[ch][i][0] ), &( pInput[ch][( yPos >> ratioH ) + i][( xPos >> ratioW )] ), + memcpy( &( d->m_pppcInputPel[ch][i][0] ), &( pInput[ch][( y >> ratioH ) + i][( x >> ratioW )] ), ( d->m_uiWidth >> ratioW ) * sizeof( ClpPel ) ); - // pOutput = d->m_pppcInputPel[ch][i]; - // pInput = other.getPelBufferYUV()[ch][( yPos >> ratioH ) + i] + ( xPos >> ratioW ); - // for( unsigned int j = 0; j < CHROMASHIFT( d->m_uiWidth, ratioW ); j++ ) - // { - // *pOutput++ = *pInput++; - // } } } d->m_bHasRGBPel = false; d->m_bHasHistogram = false; } -void CalypFrame::copyFrom( const CalypFrame* other, unsigned int x, unsigned int y ) +void CalypFrame::copyFrom( const CalypFrame* other, unsigned x, unsigned y ) { if( other ) copyFrom( *other, x, y ); } -void CalypFrame::copyTo( const CalypFrame& other, unsigned int xPos, unsigned int yPos ) +void CalypFrame::copyTo( const CalypFrame& other, unsigned x, unsigned y ) { if( !haveSameFmt( other, MATCH_COLOR_SPACE | MATCH_PEL_FMT | MATCH_BITS ) ) return; ClpPel*** pInput = other.getPelBufferYUV(); + unsigned width = other.getWidth(); // TODO: Protect width and height for( unsigned int ch = 0; ch < d->m_pcPelFormat->numberChannels; ch++ ) { int ratioH = ch > 0 ? d->m_pcPelFormat->log2ChromaWidth : 0; int ratioW = ch > 0 ? d->m_pcPelFormat->log2ChromaHeight : 0; - for( unsigned int i = 0; i < CHROMASHIFT( other.getHeight(), ratioH ); i++ ) + for( unsigned int i = 0; i < other.getHeight( ch ); i++ ) { - memcpy( &( d->m_pppcInputPel[ch][( yPos >> ratioH ) + i][( xPos >> ratioW )] ), &( pInput[ch][i][0] ), - ( other.getWidth() >> ratioW ) * sizeof( ClpPel ) ); + memcpy( &( d->m_pppcInputPel[ch][( y >> ratioH ) + i][( x >> ratioW )] ), &( pInput[ch][i][0] ), + ( width >> ratioW ) * sizeof( ClpPel ) ); } } d->m_bHasRGBPel = false; d->m_bHasHistogram = false; } -void CalypFrame::copyTo( const CalypFrame* other, unsigned int x, unsigned int y ) +void CalypFrame::copyTo( const CalypFrame* other, unsigned x, unsigned y ) { if( other ) copyTo( *other, x, y ); diff --git a/lib/CalypFrame.h b/lib/CalypFrame.h index e7b4670..a155741 100644 --- a/lib/CalypFrame.h +++ b/lib/CalypFrame.h @@ -298,13 +298,32 @@ public: */ void setPixel( unsigned int xPos, unsigned int yPos, CalypPixel pixel ); - void copyFrom( const CalypFrame& ); - void copyFrom( const CalypFrame* ); - void copyFrom( const CalypFrame&, unsigned int, unsigned int ); - void copyFrom( const CalypFrame*, unsigned int, unsigned int ); + /** + * Copy a frame into the current buffer + * @param other frame to be copied + */ + void copyFrom( const CalypFrame& other ); + void copyFrom( const CalypFrame* other ); - void copyTo( const CalypFrame&, unsigned int, unsigned int ); - void copyTo( const CalypFrame*, unsigned int, unsigned int ); + /** + * Copy a region from a reference corresponding to the size + * of the size of the current frame + * @param other frame to be copied + * @param x x position on the reference frame + * @param y y position on the reference frame + */ + void copyFrom( const CalypFrame& other, unsigned x, unsigned y ); + void copyFrom( const CalypFrame* other, unsigned x, unsigned y ); + + /** + * Copy a reference frame to a specific location on the current frame + * The whole reference frame is copied + * @param other frame to be copied + * @param x x position on the current frame + * @param y y position on the current frame + */ + void copyTo( const CalypFrame& other, unsigned x, unsigned y ); + void copyTo( const CalypFrame* other, unsigned x, unsigned y ); void frameFromBuffer( ClpByte*, int, unsigned long ); void frameFromBuffer( ClpByte*, int );