This is an automatic generated email to let you know that the following patch were queued at the http://git.linuxtv.org/v4l-utils.git tree:
Subject: qv4l2: Add cropping option to remove pillarbox Author: Baard Eirik Winther <baard.e.wint...@wintherstormer.no> Date: Mon Sep 16 11:06:52 2013 +0200 Signed-off-by: Baard Eirik Winther <baard.e.wint...@wintherstormer.no> Signed-off-by: Hans Verkuil <hans.verk...@cisco.com> utils/qv4l2/capture-win-gl.cpp | 11 ++++++----- utils/qv4l2/capture-win-qt.cpp | 32 +++++++++++++++++--------------- utils/qv4l2/capture-win-qt.h | 4 +++- utils/qv4l2/capture-win.cpp | 23 ++++++++++++++++------- utils/qv4l2/capture-win.h | 7 ++++++- utils/qv4l2/general-tab.cpp | 3 +++ 6 files changed, 51 insertions(+), 29 deletions(-) --- http://git.linuxtv.org/v4l-utils.git?a=commitdiff;h=3ee63e4f90fb459addcae994ab2fbb3e4830a7ac diff --git a/utils/qv4l2/capture-win-gl.cpp b/utils/qv4l2/capture-win-gl.cpp index d1828cf..8038257 100644 --- a/utils/qv4l2/capture-win-gl.cpp +++ b/utils/qv4l2/capture-win-gl.cpp @@ -263,13 +263,14 @@ void CaptureWinGLEngine::changeShader() void CaptureWinGLEngine::paintFrame() { - float crop = (float)CaptureWin::cropHeight(m_frameWidth, m_frameHeight) / m_frameHeight; + float cropH = (float)CaptureWin::cropHeight(m_frameWidth, m_frameHeight) / m_frameHeight; + float cropW = (float)CaptureWin::cropWidth(m_frameWidth, m_frameHeight) / m_frameWidth; glBegin(GL_QUADS); - glTexCoord2f(0.0f, crop); glVertex2f(0.0, 0); - glTexCoord2f(1.0f, crop); glVertex2f(m_frameWidth, 0); - glTexCoord2f(1.0f, 1.0f - crop); glVertex2f(m_frameWidth, m_frameHeight); - glTexCoord2f(0.0f, 1.0f - crop); glVertex2f(0, m_frameHeight); + glTexCoord2f(cropW, cropH); glVertex2f(0, 0); + glTexCoord2f(1.0f - cropW, cropH); glVertex2f(m_frameWidth, 0); + glTexCoord2f(1.0f - cropW, 1.0f - cropH); glVertex2f(m_frameWidth, m_frameHeight); + glTexCoord2f(cropW, 1.0f - cropH); glVertex2f(0, m_frameHeight); glEnd(); } diff --git a/utils/qv4l2/capture-win-qt.cpp b/utils/qv4l2/capture-win-qt.cpp index d70f317..62a7be5 100644 --- a/utils/qv4l2/capture-win-qt.cpp +++ b/utils/qv4l2/capture-win-qt.cpp @@ -29,10 +29,12 @@ CaptureWinQt::CaptureWinQt() : CaptureWin::buildWindow(&m_videoSurface); m_scaledSize.setWidth(0); m_scaledSize.setHeight(0); - m_crop.crop = 0; + m_crop.cropH = 0; + m_crop.cropW = 0; m_crop.height = 0; + m_crop.width = 0; m_crop.offset = 0; - m_crop.bytes = 0; + m_crop.bytes = 0; } CaptureWinQt::~CaptureWinQt() @@ -45,14 +47,19 @@ void CaptureWinQt::resizeScaleCrop() m_scaledSize = scaleFrameSize(QSize(m_videoSurface.width(), m_videoSurface.height()), QSize(m_frame->width(), m_frame->height())); - if (!m_crop.bytes || m_crop.crop != cropHeight(m_frame->width(), m_frame->height())) { - m_crop.crop = cropHeight(m_frame->width(), m_frame->height()); - m_crop.height = m_frame->height() - (m_crop.crop * 2); - m_crop.offset = m_crop.crop * (m_frame->depth() / 8) * m_frame->width(); + if (!m_crop.bytes || m_crop.cropH != cropHeight(m_frame->width(), m_frame->height()) + || m_crop.cropW != cropWidth(m_frame->width(), m_frame->height())) { + + m_crop.cropH = cropHeight(m_frame->width(), m_frame->height()); + m_crop.cropW = cropWidth(m_frame->width(), m_frame->height()); + m_crop.height = m_frame->height() - (m_crop.cropH * 2); + m_crop.width = m_frame->width() - (m_crop.cropW * 2); + m_crop.offset = m_crop.cropH * (m_frame->depth() / 8) * m_frame->width() + + m_crop.cropW * (m_frame->depth() / 8); // Even though the values above can be valid, it might be that there is no // data at all. This makes sure that it is. - m_crop.bytes = m_crop.height * m_frame->width() * (m_frame->depth() / 8); + m_crop.bytes = m_crop.height * m_crop.width * (m_frame->depth() / 8); } } @@ -97,15 +104,10 @@ void CaptureWinQt::paintFrame() } m_filled = false; - unsigned char *data; - - if (m_data == NULL) - data = m_frame->bits(); - else - data = m_data; + unsigned char *data = (m_data == NULL) ? m_frame->bits() : m_data; - QImage displayFrame(&data[m_crop.offset], m_frame->width(), m_crop.height, - m_frame->numBytes()/m_frame->height(), m_frame->format()); + QImage displayFrame(&data[m_crop.offset], m_crop.width, m_crop.height, + m_frame->width() * (m_frame->depth() / 8), m_frame->format()); QPixmap img = QPixmap::fromImage(displayFrame); diff --git a/utils/qv4l2/capture-win-qt.h b/utils/qv4l2/capture-win-qt.h index cfc2a9d..b5de499 100644 --- a/utils/qv4l2/capture-win-qt.h +++ b/utils/qv4l2/capture-win-qt.h @@ -28,8 +28,10 @@ #include <QResizeEvent> struct CropInfo { - int crop; + int cropH; + int cropW; int height; + int width; int offset; int bytes; }; diff --git a/utils/qv4l2/capture-win.cpp b/utils/qv4l2/capture-win.cpp index a7daaab..49cb3be 100644 --- a/utils/qv4l2/capture-win.cpp +++ b/utils/qv4l2/capture-win.cpp @@ -108,6 +108,18 @@ int CaptureWin::cropHeight(int width, int height) return (height - validHeight) / 2; } +int CaptureWin::cropWidth(int width, int height) +{ + if (m_cropMethod != QV4L2_CROP_P43) + return 0; + + int validWidth = (int)(height / 1.33); + + if (validWidth < MIN_WIN_SIZE_WIDTH || validWidth >= width) + return 0; + + return (width - validWidth) / 2; +} void CaptureWin::setCropMethod(CropMethod crop) { @@ -156,7 +168,7 @@ void CaptureWin::resize(int width, int height) QSize margins = getMargins(); height = height + margins.height() - cropHeight(width, height) * 2; - width = margins.width() + actualFrameWidth(width); + width = margins.width() - cropWidth(width, height) * 2 + actualFrameWidth(width); QDesktopWidget *screen = QApplication::desktop(); QRect resolution = screen->screenGeometry(); @@ -177,15 +189,12 @@ void CaptureWin::resize(int width, int height) QSize CaptureWin::scaleFrameSize(QSize window, QSize frame) { - int actualWidth; + int actualWidth = actualFrameWidth(frame.width() - cropWidth(frame.width(), frame.height()) * 2); int actualHeight = frame.height() - cropHeight(frame.width(), frame.height()) * 2; if (!m_enableScaling) { - window.setWidth(frame.width()); - window.setHeight(frame.height()); - actualWidth = frame.width(); - } else { - actualWidth = CaptureWin::actualFrameWidth(frame.width()); + window.setWidth(actualWidth); + window.setHeight(actualHeight); } double newW, newH; diff --git a/utils/qv4l2/capture-win.h b/utils/qv4l2/capture-win.h index 596da13..bc71c26 100644 --- a/utils/qv4l2/capture-win.h +++ b/utils/qv4l2/capture-win.h @@ -27,12 +27,16 @@ #include <QLabel> enum CropMethod { + // Crop Height QV4L2_CROP_NONE, QV4L2_CROP_W149, QV4L2_CROP_W169, QV4L2_CROP_C185, QV4L2_CROP_C239, - QV4L2_CROP_TB + QV4L2_CROP_TB, + + // Crop Width + QV4L2_CROP_P43, }; class CaptureWin : public QWidget @@ -113,6 +117,7 @@ public: * to ensure that the cropping is done correctly. */ static int cropHeight(int width, int height); + static int cropWidth(int width, int height); /** * @brief Get the frame width when aspect ratio is applied. diff --git a/utils/qv4l2/general-tab.cpp b/utils/qv4l2/general-tab.cpp index 0bb328f..be33463 100644 --- a/utils/qv4l2/general-tab.cpp +++ b/utils/qv4l2/general-tab.cpp @@ -156,6 +156,7 @@ GeneralTab::GeneralTab(const QString &device, v4l2 &fd, int n, QWidget *parent) m_crop->addItem("Widescreen 16:9"); m_crop->addItem("Cinema 1.85:1"); m_crop->addItem("Cinema 2.39:1"); + m_crop->addItem("Traditional 4:3"); addLabel("Cropping"); addWidget(m_crop); @@ -1156,6 +1157,8 @@ CropMethod GeneralTab::getCropMethod() return QV4L2_CROP_C185; case 5: return QV4L2_CROP_C239; + case 6: + return QV4L2_CROP_P43; default: return QV4L2_CROP_NONE; } _______________________________________________ linuxtv-commits mailing list linuxtv-commits@linuxtv.org http://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits