From 9ca10be1486a81a40faca83e7192b0d6eafb61b0 Mon Sep 17 00:00:00 2001 From: Luis Lucas Date: Sat, 29 Mar 2014 20:11:15 +0000 Subject: [PATCH 1/3] Show luma value when zoom is superior to 25. Debug prints are still active. There is a problem matching pixel grid with pixmap pixels for resolutions which are not powers of 2. --- source/app/ViewArea.cpp | 66 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/source/app/ViewArea.cpp b/source/app/ViewArea.cpp index 3976621..6d258bd 100755 --- a/source/app/ViewArea.cpp +++ b/source/app/ViewArea.cpp @@ -37,6 +37,8 @@ #include "ViewArea.h" #include "GridManager.h" +#include "PlaYUVerFrame.h" +#include "InputStream.h" namespace plaYUVer { @@ -108,7 +110,7 @@ Double ViewArea::getZoomFactor() Void ViewArea::zoomChangeEvent(Double factor) { Double zoomFactor; - Double maxZoom = 10.0; + Double maxZoom = 100.0; Double minZoom = ( 32.0 / m_pixmap.width() ); if( ( m_zoomFactor == minZoom ) && (factor < 1 ) ) @@ -324,6 +326,68 @@ void ViewArea::paintEvent( QPaintEvent *event ) painter.restore(); + + if(m_zoomFactor>=25.0) + { + Int imageWidth = m_pixmap.width(); + Int imageHeight = m_pixmap.height(); + PlaYUVerFrame *curFrame = getInputStream()->getCurrFrame(); + Pixel sPixelValue; + + QFont font("Helvetica"); + font.setPixelSize(m_zoomFactor/4); + painter.setFont(font); + + QRect vr = windowToView( winRect ); + qDebug() << "Info"; + qDebug() << winRect; + qDebug() << vr << vr.right(); + qDebug() << painter.window(); + qDebug() << painter.viewport(); + qDebug(); + + vr &= QRect( 0, 0, imageWidth, imageHeight ); + + for(Int i=vr.x() ; i<=vr.right() ; i++) + { + for(Int j=vr.y() ; j<=vr.bottom() ; j++) + { + QPoint pixelTopLeft(i,j); + sPixelValue = curFrame->getPixelValue( pixelTopLeft, COLOR_YUV ); + + QRect pixelRect(viewToWindow(pixelTopLeft), QSize(m_zoomFactor,m_zoomFactor)); + if( sPixelValue.Luma < 128 ) + painter.setPen(QColor(Qt::white)); + else + painter.setPen(QColor(Qt::black)); + painter.drawText(pixelRect, Qt::AlignCenter, QString::number(sPixelValue.Luma)); + qDebug() << pixelTopLeft << viewToWindow(pixelTopLeft); + } + } + + QColor color( Qt::white ); + QPen mainPen = QPen( color, 1, Qt::SolidLine ); + painter.setPen(mainPen); + + // Draw vertical line + for( Int x = vr.x(); x <= vr.right(); x ++ ) + { + // Always draw the full line otherwise the line stippling + // varies with the location of view area and we get glitchy + // patterns. + painter.drawLine( viewToWindow(QPoint(x,0)), viewToWindow(QPoint(x,imageHeight)) ); + qDebug() << "Line " << viewToWindow(QPoint(x,0)) << viewToWindow(QPoint(x,imageHeight)) << m_zoomFactor; + } + // Draw horizontal line + for( Int y = vr.y(); y <= vr.bottom(); y ++ ) + { + painter.drawLine( viewToWindow(QPoint(0,y)), viewToWindow(QPoint(imageWidth,y)) ); + } + } + + + + // Draw a border around the image. if( m_xOffset || m_yOffset ) { From 4d380e69304bb404d6643c6f4e4e36ad2f4c6d5d Mon Sep 17 00:00:00 2001 From: Luis Lucas Date: Sat, 29 Mar 2014 21:25:30 +0000 Subject: [PATCH 2/3] Fix bug in ZoomtoFit. --- source/app/SubWindowHandle.cpp | 8 +++++++- source/app/SubWindowHandle.h | 4 +++- source/app/plaYUVerApp.cpp | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/source/app/SubWindowHandle.cpp b/source/app/SubWindowHandle.cpp index 6c0a1d2..8052aca 100644 --- a/source/app/SubWindowHandle.cpp +++ b/source/app/SubWindowHandle.cpp @@ -250,12 +250,18 @@ Void SubWindowHandle::zoomToFit() scaleView( niceFit ); } -Void SubWindowHandle::scaleView( Double factor ) +Void SubWindowHandle::scaleViewFactor( Double factor ) { Q_ASSERT( m_cViewArea->image() ); m_cViewArea->zoomChangeEvent( factor ); } +Void SubWindowHandle::scaleView( Double scale ) +{ + Q_ASSERT( m_cViewArea->image() ); + m_cViewArea->setZoomFactor( scale ); +} + Void SubWindowHandle::scaleView( Int width, Int height ) { scaleView( QSize( width, height ) ); diff --git a/source/app/SubWindowHandle.h b/source/app/SubWindowHandle.h index 48fb532..0d58adf 100644 --- a/source/app/SubWindowHandle.h +++ b/source/app/SubWindowHandle.h @@ -106,7 +106,7 @@ public: * @param factor factor of scale. Ex: 1.2 scale the image up by 20% and * 0.8 scale the image down by 25% */ - Void scaleView( Double factor ); + Void scaleView( Double scale ); /** * The current image size is scaled to a rectangle as large as possible @@ -121,6 +121,8 @@ public: */ Void scaleView( const QSize & size ); + Void scaleViewFactor( Double factor ); + Double getScaleFactor() { return m_cViewArea->getZoomFactor(); diff --git a/source/app/plaYUVerApp.cpp b/source/app/plaYUVerApp.cpp index 501548b..4285a68 100644 --- a/source/app/plaYUVerApp.cpp +++ b/source/app/plaYUVerApp.cpp @@ -282,7 +282,7 @@ void plaYUVerApp::scaleFrame( int ratio ) { if( activeSubWindow() ) { - activeSubWindow()->scaleView( ( Double )( ratio ) / 100.0 ); + activeSubWindow()->scaleViewFactor( ( Double )( ratio ) / 100.0 ); // actionZoomIn->setEnabled( activeSubWindow()->getScaleFactor() < 3.0 ); // actionZoomOut->setEnabled( activeSubWindow()->getScaleFactor() > 0.333 ); From a0acc870854aa410e5a2384991bf7c800fb80dc8 Mon Sep 17 00:00:00 2001 From: Luis Lucas Date: Sat, 29 Mar 2014 22:32:18 +0000 Subject: [PATCH 3/3] Remove debug prints --- source/app/ViewArea.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/source/app/ViewArea.cpp b/source/app/ViewArea.cpp index 6d258bd..bd544c7 100755 --- a/source/app/ViewArea.cpp +++ b/source/app/ViewArea.cpp @@ -339,13 +339,6 @@ void ViewArea::paintEvent( QPaintEvent *event ) painter.setFont(font); QRect vr = windowToView( winRect ); - qDebug() << "Info"; - qDebug() << winRect; - qDebug() << vr << vr.right(); - qDebug() << painter.window(); - qDebug() << painter.viewport(); - qDebug(); - vr &= QRect( 0, 0, imageWidth, imageHeight ); for(Int i=vr.x() ; i<=vr.right() ; i++) @@ -361,7 +354,6 @@ void ViewArea::paintEvent( QPaintEvent *event ) else painter.setPen(QColor(Qt::black)); painter.drawText(pixelRect, Qt::AlignCenter, QString::number(sPixelValue.Luma)); - qDebug() << pixelTopLeft << viewToWindow(pixelTopLeft); } }