[PATCH 2/2] qcam: introduce a command line argument to rotate the viewfinder output
Joel Selvaraj
joelselvaraj.oss at gmail.com
Thu Jun 20 23:36:07 CEST 2024
Sometimes devicetrees may not specify the rotation or incorrectly
specify it. Introduce a command line argument to quickly test different
rotations. This also helps in easily identifying the rotation at which
the camera is mounted if kernel developer doesn't already know it.
Signed-off-by: Joel Selvaraj <joelselvaraj.oss at gmail.com>
---
src/apps/qcam/main.cpp | 3 +++
src/apps/qcam/main_window.cpp | 19 +++++++++++++++++++
src/apps/qcam/main_window.h | 1 +
3 files changed, 23 insertions(+)
diff --git a/src/apps/qcam/main.cpp b/src/apps/qcam/main.cpp
index 9846fba5..9100c69d 100644
--- a/src/apps/qcam/main.cpp
+++ b/src/apps/qcam/main.cpp
@@ -37,6 +37,9 @@ OptionsParser::Options parseOptions(int argc, char *argv[])
ArgumentRequired, "camera");
parser.addOption(OptHelp, OptionNone, "Display this help message",
"help");
+ parser.addOption(OptOrientation, OptionString,
+ "Desired image orientation (rot0, rot90, rot180, rot270)",
+ "orientation", ArgumentRequired, "orientation");
parser.addOption(OptRenderer, OptionString,
"Choose the renderer type {qt,gles} (default: qt)",
"renderer", ArgumentRequired, "renderer");
diff --git a/src/apps/qcam/main_window.cpp b/src/apps/qcam/main_window.cpp
index 18c94cf3..aa4a0fa0 100644
--- a/src/apps/qcam/main_window.cpp
+++ b/src/apps/qcam/main_window.cpp
@@ -399,6 +399,25 @@ int MainWindow::startCapture()
if (rotation)
orientation = orientationFromRotation(*rotation);
+ /* Override if user specifies orientation in command line argument */
+ if (options_.isSet(OptOrientation)) {
+ std::string orientOpt = options_[OptOrientation].toString();
+ static const std::map<std::string, Orientation> possible_orientations{
+ { "rot0", Orientation::Rotate0 },
+ { "rot90", Orientation::Rotate90 },
+ { "rot180", Orientation::Rotate180 },
+ { "rot270", Orientation::Rotate270 },
+ };
+
+ auto requested_orientation = possible_orientations.find(orientOpt);
+ if (requested_orientation == possible_orientations.end()) {
+ std::cerr << "Unsupported orientation " << orientOpt << std::endl;
+ return -EINVAL;
+ }
+
+ orientation = requested_orientation->second;
+ }
+
StreamConfiguration &vfConfig = config_->at(0);
/* Use a format supported by the viewfinder if available. */
diff --git a/src/apps/qcam/main_window.h b/src/apps/qcam/main_window.h
index 4cead734..6dbcd88d 100644
--- a/src/apps/qcam/main_window.h
+++ b/src/apps/qcam/main_window.h
@@ -40,6 +40,7 @@ class HotplugEvent;
enum {
OptCamera = 'c',
OptHelp = 'h',
+ OptOrientation = 'o',
OptRenderer = 'r',
OptStream = 's',
OptVerbose = 'v',
--
2.45.2
More information about the libcamera-devel
mailing list