qvidcap: Add stride option to command line
PATCH 1/1 qvidcap: Add stride option to command line
From: Bård Eirik Winther <[email protected]>
Add new hotkeys Shift+Left and Shift+Right to decrase or increase stride.
--- utils/qvidcap/capture.cpp | 38 ++++++++++++++++++++++++++++++++++---- utils/qvidcap/capture.h | 2 ++ utils/qvidcap/qvidcap.cpp | 6 ++++++ 3 files changed, 42 insertions(+), 4 deletions(-)
utils/qvidcap/capture.cpp +34 -4
@@ -571,6 +571,7 @@ void CaptureWin::keyPressEvent(QKeyEvent *event) { unsigned w = m_v4l_fmt.g_width(); unsigned h = m_v4l_fmt.g_frame_height(); + unsigned p = m_overrideHorPadding; bool hasShift = event->modifiers() & Qt::ShiftModifier; bool hasCtrl = event->modifiers() & Qt::ControlModifier; bool scalingEnabled = m_canOverrideResolution &&
@@ -587,12 +588,22 @@ void CaptureWin::keyPressEvent(QKeyEvent *event) if (!m_scrollArea->isFullScreen()) return; case Qt::Key_Left: - if (scalingEnabled && w > 16) - w -= 2; + if (hasShift) { + if (scalingEnabled && p >= 2) + p -= 2; + } else { + if (scalingEnabled && w > 16) + w -= 2; + } break; case Qt::Key_Right: - if (scalingEnabled && w < 10240) - w += 2; + if (hasShift) { + if (scalingEnabled && p < 10240) + p += 2; + } else { + if (scalingEnabled && w < 10240) + w += 2; + } break; case Qt::Key_Up: if (scalingEnabled && h > 16)
@@ -675,6 +686,12 @@ void CaptureWin::keyPressEvent(QKeyEvent *event) m_scrollArea->resize(w, h); else resize(w, h); + + if (p != m_v4l_fmt.g_bytesperline()) { + printf("New horizontal resolution: %u + %u (%u)\n", w, p, w + p); + setOverrideHorPadding(p); + updateShader(); + } } }
@@ -747,6 +764,14 @@ void CaptureWin::setOverrideHeight(__u32 h) m_resolutionOverride->setChecked(true); } +void CaptureWin::setOverrideHorPadding(__u32 p) +{ + m_overrideHorPadding = p; + + if (!m_overrideHorPadding && m_canOverrideResolution) + m_resolutionOverride->setChecked(true); +} + void CaptureWin::setModeV4L2(cv4l_fd *fd) { m_mode = AppModeV4L2;
@@ -953,6 +978,8 @@ bool CaptureWin::setV4LFormat(cv4l_fmt &fmt) } if (m_mode == AppModeFile && m_overrideWidth) fmt.s_width(m_overrideWidth); + if (m_mode == AppModeFile && m_overrideHorPadding) + fmt.s_bytesperline(fmt.g_bytesperline() + m_overrideHorPadding); if (m_mode == AppModeFile && m_overrideField != 0xffffffff) fmt.s_field(m_overrideField); if (m_mode == AppModeFile && m_overrideHeight)
@@ -1350,6 +1377,9 @@ void CaptureWin::initImageFormat() tpg_s_quantization(&m_tpg, m_v4l_fmt.g_quantization()); m_v4l_fmt.s_num_planes(tpg_g_buffers(&m_tpg)); for (unsigned p = 0; p < m_v4l_fmt.g_num_planes(); p++) { + if (m_mode == AppModeFile && m_overrideHorPadding) + tpg_s_bytesperline(&m_tpg, p, tpg_g_bytesperline(&m_tpg, p) + m_overrideHorPadding); + m_v4l_fmt.s_bytesperline(tpg_g_bytesperline(&m_tpg, p), p); m_v4l_fmt.s_sizeimage(tpg_calc_plane_size(&m_tpg, p), p); }
utils/qvidcap/capture.h +2 -0
@@ -82,6 +82,7 @@ public: bool updateV4LFormat(const cv4l_fmt &fmt);void setOverrideWidth (__u32 w);void setOverrideHeight (__u32 h); +void setOverrideHorPadding (__u32 p);void setCount (unsigned cnt) { m_cnt = cnt; }void setReportTimings (bool report) { m_reportTimings = report; }void setVerbose (bool verbose) { m_verbose = verbose; }
@@ -192,6 +193,7 @@ private:__u32 m_overridePixelFormat;__u32 m_overrideWidth;__u32 m_overrideHeight; +__u32 m_overrideHorPadding;__u32 m_overrideField;__u32 m_overrideColorspace;__u32 m_overrideYCbCrEnc;
utils/qvidcap/qvidcap.cpp +6 -0
@@ -72,6 +72,7 @@ static void usage() "\n" " -W, --width=<width> set width\n" " -H, --height=<height> set frame (not field!) height\n" + " -A, --padding=<bytes> set additional horizontal padding (after width)\n" " --fps=<fps> set frames-per-second (default is 30)\n" "\n" " The following option is only valid when reading from a file:\n"
@@ -446,6 +447,7 @@ int main(int argc, char **argv) __u32 overridePixelFormat = 0; __u32 overrideWidth = 0; __u32 overrideHeight = 0; + __u32 overrideHorPadding = 0; __u32 overrideField = 0xffffffff; __u32 overrideColorspace = 0xffffffff; __u32 overrideYCbCrEnc = 0xffffffff;
@@ -516,6 +518,9 @@ int main(int argc, char **argv) } else if (isOptArg(args[i], "--height", "-H")) { if (!processOption(args, i, overrideHeight)) return 0; + } else if (isOptArg(args[i], "--padding", "-A")) { + if (!processOption(args, i, overrideHorPadding)) + return 0; } else if (isOptArg(args[i], "--field", "-F")) { if (!processOption(args, i, s)) return 0;
@@ -749,6 +754,7 @@ int main(int argc, char **argv) } win.setOverrideWidth(overrideWidth); win.setOverrideHeight(overrideHeight); + win.setOverrideHorPadding(overrideHorPadding); win.setFps(fps); win.setFormat(format); win.setReportTimings(report_timings);
Signature · 1 line
2.20.1
Hi Bård,
Can you document the new option in qvidcap.1.in as well?
I also have one comment:
Quoted 51 lines · On 12/6/19 11:26 AM, [email protected] wrote:
From: Bård Eirik Winther <[email protected]>
Add new hotkeys Shift+Left and Shift+Right to decrase or increase stride.
Signed-off-by Bård Eirik Winther <[email protected]>--- utils/qvidcap/capture.cpp | 38 ++++++++++++++++++++++++++++++++++---- utils/qvidcap/capture.h | 2 ++ utils/qvidcap/qvidcap.cpp | 6 ++++++ 3 files changed, 42 insertions(+), 4 deletions(-)utils/qvidcap/capture.cpp +15
-4@@ -571,6 +571,7 @@ void CaptureWin::keyPressEvent(QKeyEvent *event) { unsigned w = m_v4l_fmt.g_width(); unsigned h = m_v4l_fmt.g_frame_height(); + unsigned p = m_overrideHorPadding; bool hasShift = event->modifiers() & Qt::ShiftModifier; bool hasCtrl = event->modifiers() & Qt::ControlModifier; bool scalingEnabled = m_canOverrideResolution &&@@ -587,12 +588,22 @@ void CaptureWin::keyPressEvent(QKeyEvent *event) if (!m_scrollArea->isFullScreen()) return; case Qt::Key_Left: - if (scalingEnabled && w > 16) - w -= 2; + if (hasShift) { + if (scalingEnabled && p >= 2) + p -= 2; + } else { + if (scalingEnabled && w > 16) + w -= 2; + } break; case Qt::Key_Right: - if (scalingEnabled && w < 10240) - w += 2; + if (hasShift) { + if (scalingEnabled && p < 10240) + p += 2; + } else { + if (scalingEnabled && w < 10240) + w += 2; + } break; case Qt::Key_Up: if (scalingEnabled && h > 16)
utils/qvidcap/capture.cpp void CaptureWin::keyPressEvent(QKeyEvent *event) · line 691
Quoted 6 lines
utils/qvidcap/capture.cpp +3
-0@@ -675,6 +686,12 @@ void CaptureWin::keyPressEvent(QKeyEvent *event) m_scrollArea->resize(w, h); else resize(w, h); + + if (p != m_v4l_fmt.g_bytesperline()) { + printf("New horizontal resolution: %u + %u (%u)\n", w, p, w + p);
I think this message should only be shown if the padding changed. Otherwise I keep seeing two messages when I just resize the image:
New horizontal resolution: 640 + 0 (640)
New resolution: 642x480
New horizontal resolution: 642 + 0 (642)
New resolution: 644x480
New horizontal resolution: 644 + 0 (644)
New resolution: 646x480
New horizontal resolution: 646 + 0 (646)
New resolution: 644x480
New horizontal resolution: 644 + 0 (644)
It's a bit too noisy.
Otherwise this looks great!
Regards,
Hans