[libcamera-devel] [PATCH] libcamera: stream_option: use fourcc values to set cam/qcam formats
Niklas Söderlund
niklas.soderlund at ragnatech.se
Tue Jun 2 17:20:14 CEST 2020
Hi Kaaira,
Thanks for your patch.
On 2020-05-29 19:34:33 +0530, Kaaira Gupta wrote:
> Replace hex input for pixelformats with their fourcc values,
> in cam and qcam.
>
> Signed-off-by: Kaaira Gupta <kgupta at es.iitr.ac.in>
> ---
> src/cam/stream_options.cpp | 13 ++++++++++---
> 1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/src/cam/stream_options.cpp b/src/cam/stream_options.cpp
> index bd12c8f..9f9536e 100644
> --- a/src/cam/stream_options.cpp
> +++ b/src/cam/stream_options.cpp
> @@ -6,6 +6,7 @@
> */
> #include "stream_options.h"
>
> +#include <bits/stdc++.h>
> #include <iostream>
>
> using namespace libcamera;
> @@ -19,7 +20,7 @@ StreamKeyValueParser::StreamKeyValueParser()
> ArgumentRequired);
> addOption("height", OptionInteger, "Height in pixels",
> ArgumentRequired);
> - addOption("pixelformat", OptionInteger, "Pixel format",
> + addOption("pixelformat", OptionString, "Pixel format fourcc",
> ArgumentRequired);
> }
>
> @@ -96,8 +97,14 @@ int StreamKeyValueParser::updateConfiguration(CameraConfiguration *config,
> }
>
> /* \todo Translate 4CC string to pixelformat with modifier. */
> - if (opts.isSet("pixelformat"))
> - cfg.pixelFormat = PixelFormat(opts["pixelformat"]);
> + if (opts.isSet("pixelformat")) {
> + std::string fourcc = opts["pixelformat"];
> + transform(fourcc.begin(), fourcc.end(), fourcc.begin(), ::toupper);
I fear we don't know all fourcc codes will be uppercase. It's currently
true all DRM defined ones are, but might change. As an example look at
V4L2 fourcc codes where lower/upper case is already mixed.
> + char char_array[5];
> + strcpy(char_array, fourcc.c_str());
I think you can simplify this, or something similar (not compile
tested).
const char *fourcc = opts["pixelformat"].toString().c_str();
> + cfg.pixelFormat = PixelFormat((__u32)(char_array[0]) | ((__u32)(char_array[1]) << 8) |
> + ((__u32)(char_array[2]) << 16) | ((__u32)(char_array[3]) << 24));
> + }
> }
>
> return 0;
> --
> 2.17.1
>
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel at lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
--
Regards,
Niklas Söderlund
More information about the libcamera-devel
mailing list