[PATCH 2/2] qcam: introduce a command line argument to rotate the viewfinder output
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Fri Jun 21 15:52:11 CEST 2024
On Thu, Jun 20, 2024 at 04:36:07PM -0500, Joel Selvaraj wrote:
> 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;
There's similar code in src/apps/cam/camera_session.cpp. Is it worth
moving it to a helper in src/apps/common/ ? options.cpp could be a
suitable candidate.
And I think it would be nice if the argument behaved the same way as in
cam, so it should be used to set config->orientation, overriding the
default Orientation::Rotate0 value.
> + }
> +
> 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',
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list