[libcamera-devel,v4,3/3] libcamera: stream_option: use format name to set cam/qcam format

Message ID 20200727162143.31317-4-kgupta@es.iitr.ac.in
State Accepted
Headers show
Series
  • Enable formats lookup based on name
Related show

Commit Message

Kaaira Gupta July 27, 2020, 4:21 p.m. UTC
Replace hex input for pixel formats with their format names, for input in
cam and qcam.
Hence, remove the todo.

Signed-off-by: Kaaira Gupta <kgupta@es.iitr.ac.in>
---
 src/cam/stream_options.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Kieran Bingham July 28, 2020, 10:47 a.m. UTC | #1
Hi Kaaira,

On 27/07/2020 17:21, Kaaira Gupta wrote:
> Replace hex input for pixel formats with their format names, for input in
> cam and qcam.
> Hence, remove the todo.
> 
> Signed-off-by: Kaaira Gupta <kgupta@es.iitr.ac.in>
> ---
>  src/cam/stream_options.cpp | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/src/cam/stream_options.cpp b/src/cam/stream_options.cpp
> index bd12c8f..4168e5d 100644
> --- a/src/cam/stream_options.cpp
> +++ b/src/cam/stream_options.cpp
> @@ -19,7 +19,7 @@ StreamKeyValueParser::StreamKeyValueParser()
>  		  ArgumentRequired);
>  	addOption("height", OptionInteger, "Height in pixels",
>  		  ArgumentRequired);
> -	addOption("pixelformat", OptionInteger, "Pixel format",
> +	addOption("pixelformat", OptionString, "Pixel format name",
>  		  ArgumentRequired);
>  }
>  
> @@ -95,9 +95,8 @@ int StreamKeyValueParser::updateConfiguration(CameraConfiguration *config,
>  			cfg.size.height = opts["height"];
>  		}
>  
> -		/* \todo Translate 4CC string to pixelformat with modifier. */
>  		if (opts.isSet("pixelformat"))
> -			cfg.pixelFormat = PixelFormat(opts["pixelformat"]);
> +			cfg.pixelFormat = PixelFormat::fromString(opts["pixelformat"].toString());

I'm looking forward to this:

  -s pixelformat=NV12

is so much nicer than:
  -s pixelformat=0x3231564e

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>


>  	}
>  
>  	return 0;
>
Laurent Pinchart July 28, 2020, 12:06 p.m. UTC | #2
On Tue, Jul 28, 2020 at 11:47:19AM +0100, Kieran Bingham wrote:
> On 27/07/2020 17:21, Kaaira Gupta wrote:
> > Replace hex input for pixel formats with their format names, for input in
> > cam and qcam.
> > Hence, remove the todo.
> > 
> > Signed-off-by: Kaaira Gupta <kgupta@es.iitr.ac.in>
> > ---
> >  src/cam/stream_options.cpp | 5 ++---
> >  1 file changed, 2 insertions(+), 3 deletions(-)
> > 
> > diff --git a/src/cam/stream_options.cpp b/src/cam/stream_options.cpp
> > index bd12c8f..4168e5d 100644
> > --- a/src/cam/stream_options.cpp
> > +++ b/src/cam/stream_options.cpp
> > @@ -19,7 +19,7 @@ StreamKeyValueParser::StreamKeyValueParser()
> >  		  ArgumentRequired);
> >  	addOption("height", OptionInteger, "Height in pixels",
> >  		  ArgumentRequired);
> > -	addOption("pixelformat", OptionInteger, "Pixel format",
> > +	addOption("pixelformat", OptionString, "Pixel format name",
> >  		  ArgumentRequired);
> >  }
> >  
> > @@ -95,9 +95,8 @@ int StreamKeyValueParser::updateConfiguration(CameraConfiguration *config,
> >  			cfg.size.height = opts["height"];
> >  		}
> >  
> > -		/* \todo Translate 4CC string to pixelformat with modifier. */
> >  		if (opts.isSet("pixelformat"))
> > -			cfg.pixelFormat = PixelFormat(opts["pixelformat"]);
> > +			cfg.pixelFormat = PixelFormat::fromString(opts["pixelformat"].toString());
> 
> I'm looking forward to this:
> 
>   -s pixelformat=NV12
> 
> is so much nicer than:
>   -s pixelformat=0x3231564e

I wonder if there's a need to support both, but that's something we can
easily add later if needed.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> 
> >  	}
> >  
> >  	return 0;

Patch

diff --git a/src/cam/stream_options.cpp b/src/cam/stream_options.cpp
index bd12c8f..4168e5d 100644
--- a/src/cam/stream_options.cpp
+++ b/src/cam/stream_options.cpp
@@ -19,7 +19,7 @@  StreamKeyValueParser::StreamKeyValueParser()
 		  ArgumentRequired);
 	addOption("height", OptionInteger, "Height in pixels",
 		  ArgumentRequired);
-	addOption("pixelformat", OptionInteger, "Pixel format",
+	addOption("pixelformat", OptionString, "Pixel format name",
 		  ArgumentRequired);
 }
 
@@ -95,9 +95,8 @@  int StreamKeyValueParser::updateConfiguration(CameraConfiguration *config,
 			cfg.size.height = opts["height"];
 		}
 
-		/* \todo Translate 4CC string to pixelformat with modifier. */
 		if (opts.isSet("pixelformat"))
-			cfg.pixelFormat = PixelFormat(opts["pixelformat"]);
+			cfg.pixelFormat = PixelFormat::fromString(opts["pixelformat"].toString());
 	}
 
 	return 0;