From 7ccc608d3415395ece36e7c1fa0e322497635861 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Mon, 17 Nov 2014 23:36:54 +0000 Subject: [PATCH] Generalise adjustSelectedAreaDims using PlaYUVerFramePelFormat --- app/PropertiesSidebar.cpp | 4 ++- app/SubWindowHandle.cpp | 3 +- lib/PlaYUVerFrame.cpp | 68 ++++++++++----------------------------- lib/PlaYUVerFrame.h | 4 ++- 4 files changed, 25 insertions(+), 54 deletions(-) diff --git a/app/PropertiesSidebar.cpp b/app/PropertiesSidebar.cpp index 2c39f99..50b0479 100644 --- a/app/PropertiesSidebar.cpp +++ b/app/PropertiesSidebar.cpp @@ -496,7 +496,9 @@ Void FramePropertiesSideBar::setSelection( const QRect &selectionArea ) if( selectionArea.isValid() ) { histogramWidget->stopHistogramComputation(); - histogramWidget->updateSelectionData( new PlaYUVerFrame(m_pcFrame, selectionArea)); + histogramWidget->updateSelectionData( new PlaYUVerFrame(m_pcFrame, + selectionArea.x(), selectionArea.y(), + selectionArea.width(), selectionArea.height() ) ); fullImageButton->show(); selectionImageButton->show(); selectionImageButton->click(); diff --git a/app/SubWindowHandle.cpp b/app/SubWindowHandle.cpp index 50c8523..74e8b1c 100644 --- a/app/SubWindowHandle.cpp +++ b/app/SubWindowHandle.cpp @@ -230,7 +230,8 @@ Bool SubWindowHandle::save( QString filename ) PlaYUVerFrame* saveFrame = m_pcCurrFrame; if( m_cSelectedArea.isValid() ) { - saveFrame = new PlaYUVerFrame( m_pcCurrFrame, m_cSelectedArea ); + saveFrame = new PlaYUVerFrame( m_pcCurrFrame, m_cSelectedArea.x(), m_cSelectedArea.y(), + m_cSelectedArea.width(), m_cSelectedArea.height() ); } if( !saveFrame ) { diff --git a/lib/PlaYUVerFrame.cpp b/lib/PlaYUVerFrame.cpp index 42ccf4f..8825fa0 100644 --- a/lib/PlaYUVerFrame.cpp +++ b/lib/PlaYUVerFrame.cpp @@ -82,11 +82,11 @@ PlaYUVerFrame::PlaYUVerFrame( PlaYUVerFrame *other ) copyFrom( other ); } -PlaYUVerFrame::PlaYUVerFrame( PlaYUVerFrame *other, QRect area ) +PlaYUVerFrame::PlaYUVerFrame( PlaYUVerFrame *other, UInt posX, UInt posY, UInt areaWidth, UInt areaHeight ) { - adjustSelectedAreaDims( area, other->getPelFormat() ); - init( area.width(), area.height(), other->getPelFormat() ); - copyFrom( other, area.x(), area.y() ); + adjustSelectedAreaDims( posX, posY, areaWidth, areaHeight, other->getPelFormat() ); + init( areaWidth, areaHeight, other->getPelFormat() ); + copyFrom( other, posX, posY ); } PlaYUVerFrame::~PlaYUVerFrame() @@ -100,53 +100,6 @@ PlaYUVerFrame::~PlaYUVerFrame() closePixfc(); } -Void PlaYUVerFrame::adjustSelectedAreaDims( QRect &area, Int pel_format ) -{ - Int posX = area.x(); - Int posY = area.y(); - Int width = area.width(); - Int height = area.height(); - - switch( pel_format ) - { - case YUV420p: - if( posX % 2 ) - area.setX( posX - 1 ); - if( posY % 2 ) - area.setY( posY - 1 ); - - if( ( posX + width ) % 2 ) - area.setWidth( ( posX + width ) - area.x() + 1 ); - else - area.setWidth( ( posX + width ) - area.x() ); - - if( ( posY + height ) % 2 ) - area.setHeight( ( posY + height ) - area.y() + 1 ); - else - area.setHeight( ( posY + height ) - area.y() ); - - break; - case YUV444p: - break; - case YUV422p: - case YUYV422: - if( posX % 2 ) - area.setX( posX - 1 ); - - if( ( posX + width ) % 2 ) - area.setWidth( ( posX + width ) - area.x() + 1 ); - else - area.setWidth( ( posX + width ) - area.x() ); - - break; - case GRAY: - break; - case RGB8: - break; - default: - break; - } -} Void PlaYUVerFrame::init( UInt width, UInt height, Int pel_format ) { @@ -252,6 +205,19 @@ Void PlaYUVerFrame::copyFrom( PlaYUVerFrame* input_frame ) memcpy( *m_pppcInputPel[LUMA], input_frame->getPelBufferYUV()[LUMA][0], getBytesPerFrame() * sizeof(Pel) ); } +Void PlaYUVerFrame::adjustSelectedAreaDims( UInt& posX, UInt& posY, UInt& areaWidth, UInt& areaHeight, Int pelFormat ) +{ + PlaYUVerFramePelFormat* pcPelFormat = &( g_PlaYUVerFramePelFormatsList[pelFormat] ); + if( posX % pcPelFormat->ratioChromaWidth ) + posX--; + if( posY % pcPelFormat->ratioChromaHeight ) + posY--; + if( ( posX + areaWidth ) % 2 ) + areaWidth++; + if( ( posY + areaHeight ) % 2 ) + areaHeight++; +} + Void PlaYUVerFrame::copyFrom( PlaYUVerFrame* input_frame, UInt xPos, UInt yPos ) { if( m_iPixelFormat != input_frame->getPelFormat() ) diff --git a/lib/PlaYUVerFrame.h b/lib/PlaYUVerFrame.h index b87eaa7..48fdb8b 100644 --- a/lib/PlaYUVerFrame.h +++ b/lib/PlaYUVerFrame.h @@ -95,7 +95,7 @@ public: PlaYUVerFrame( UInt width = 0, UInt height = 0, Int pel_format = 0 ); PlaYUVerFrame( PlaYUVerFrame * ); - PlaYUVerFrame( PlaYUVerFrame *, QRect area ); + PlaYUVerFrame( PlaYUVerFrame *other, UInt posX, UInt posY, UInt areaWidth, UInt areaHeight ); ~PlaYUVerFrame(); UInt64 getBytesPerFrame(); @@ -113,6 +113,8 @@ public: Void fillRGBBuffer(); Void copyFrom( PlaYUVerFrame* ); + + static Void adjustSelectedAreaDims( UInt& posX, UInt& posY, UInt& areaWidth, UInt& areaHeight, Int pelFormat ); Void copyFrom( PlaYUVerFrame*, UInt, UInt ); PlaYUVerFrame::Pixel getPixelValue( Int, Int, Int );