|| m_frame->format() != dstFmt) {
delete m_frame;
m_frame = new QImage(width, height, dstFmt);
+ // Force a recalculation by setting this to 0.
+ m_crop.bytes = 0;
resizeScaleCrop();
}
int CaptureWin::actualFrameWidth(int width)
{
- if (m_enableScaling)
+ if (m_enableScaling && m_pixelAspectRatio > 1)
return width * m_pixelAspectRatio;
return width;
}
+int CaptureWin::actualFrameHeight(int height)
+{
+ if (m_enableScaling && m_pixelAspectRatio < 1)
+ return height / m_pixelAspectRatio;
+
+ return height;
+}
+
QSize CaptureWin::getMargins()
{
int l, t, r, b;
void CaptureWin::resize(int width, int height)
{
+ int h, w;
+
// Dont resize window if the frame size is the same in
// the event the window has been paused when beeing resized.
if (width == m_curWidth && height == m_curHeight)
m_curHeight = height;
QSize margins = getMargins();
- height = height + margins.height() - cropHeight(width, height) * 2;
- width = margins.width() - cropWidth(width, height) * 2 + actualFrameWidth(width);
+ h = margins.height() - cropHeight(width, height) * 2 + actualFrameHeight(height);
+ w = margins.width() - cropWidth(width, height) * 2 + actualFrameWidth(width);
+ height = h;
+ width = w;
QDesktopWidget *screen = QApplication::desktop();
QRect resolution = screen->screenGeometry();
QSize CaptureWin::scaleFrameSize(QSize window, QSize frame)
{
int actualWidth = actualFrameWidth(frame.width() - cropWidth(frame.width(), frame.height()) * 2);
- int actualHeight = frame.height() - cropHeight(frame.width(), frame.height()) * 2;
+ int actualHeight = actualFrameHeight(frame.height() - cropHeight(frame.width(), frame.height()) * 2);
if (!m_enableScaling) {
window.setWidth(actualWidth);
/**
* @brief Return the scaled size.
*
- * Scales a frame to fit inside a given window. Preseves aspect ratio.
+ * Scales a frame to fit inside a given window. Preserves aspect ratio.
*
* @param window The window the frame shall scale into
* @param frame The frame to scale
static int cropWidth(int width, int height);
/**
- * @brief Get the frame width when aspect ratio is applied.
+ * @brief Get the frame width when aspect ratio is applied if ratio > 1.
*
* @param width The original frame width.
- * @return The width with aspect ratio correctio (scaling must be enabled).
+ * @return The width with aspect ratio correction (scaling must be enabled).
*/
static int actualFrameWidth(int width);
+ /**
+ * @brief Get the frame height when aspect ratio is applied if ratio < 1.
+ *
+ * @param width The original frame width.
+ * @return The width with aspect ratio correction (scaling must be enabled).
+ */
+ static int actualFrameHeight(int height);
+
public slots:
void resetSize();
void ApplicationWindow::updatePixelAspectRatio()
{
if (m_capture != NULL && m_genTab != NULL)
- m_capture->setPixelAspectRatio(m_genTab->getPixelAspectRatio());
+ m_capture->setPixelAspectRatio(m_genTab->getPixelAspectRatio() /
+ (m_fieldCapture ? 2 : 1));
}
void ApplicationWindow::updateCropping()
}
g_fmt_cap(m_capSrcFormat);
+ m_fieldCapture = m_capSrcFormat.fmt.pix.field == V4L2_FIELD_TOP ||
+ m_capSrcFormat.fmt.pix.field == V4L2_FIELD_BOTTOM ||
+ m_capSrcFormat.fmt.pix.field == V4L2_FIELD_ALTERNATE;
+ m_heightDiv = m_fieldCapture ? 2 : 1;
s_fmt(m_capSrcFormat);
if (m_genTab->get_interval(interval))
set_interval(interval);
// Ensure that the initial image is large enough for native 32 bit per pixel formats
if (dstPix.pixelformat == V4L2_PIX_FMT_RGB32 || dstPix.pixelformat == V4L2_PIX_FMT_BGR32)
dstFmt = QImage::Format_ARGB32;
- m_capImage = new QImage(dstPix.width, dstPix.height, dstFmt);
+ m_capImage = new QImage(dstPix.width, dstPix.height / m_heightDiv, dstFmt);
m_capImage->fill(0);
updatePixelAspectRatio();
m_capture->setFrame(m_capImage->width(), m_capImage->height(),
m_capDestFormat.fmt.pix.pixelformat, m_capImage->bits(), "No frame");
- m_capture->resize(dstPix.width, dstPix.height);
+ m_capture->resize(dstPix.width, dstPix.height / m_heightDiv);
if (showFrames())
m_capture->show();
struct buffer *m_buffers;
struct v4l2_format m_capSrcFormat;
struct v4l2_format m_capDestFormat;
+ bool m_fieldCapture;
+ unsigned m_heightDiv;
unsigned char *m_frameData;
unsigned m_nbuffers;
struct v4lconvert_data *m_convertData;