[libcamera-devel,v5,07/13] libcamera: rpi: Make isRaw/isYuv/isRgb static functions
diff mbox series

Message ID 20230921165550.50956-8-jacopo.mondi@ideasonboard.com
State Accepted
Headers show
Series
  • libcamera: Introduce SensorConfiguration
Related show

Commit Message

Jacopo Mondi Sept. 21, 2023, 4:55 p.m. UTC
From: Naushir Patuck <naush@raspberrypi.com>

Move the existing isRaw()/isYuv()/isRgb()into a static function of
PipelineHandlerBase. This will allow then to be shared with the
pipeline handler derived class.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
 .../pipeline/rpi/common/pipeline_base.cpp     | 52 +++++++++----------
 .../pipeline/rpi/common/pipeline_base.h       |  4 ++
 2 files changed, 30 insertions(+), 26 deletions(-)

Comments

Laurent Pinchart Sept. 26, 2023, 10:33 p.m. UTC | #1
On Thu, Sep 21, 2023 at 06:55:44PM +0200, Jacopo Mondi via libcamera-devel wrote:
> From: Naushir Patuck <naush@raspberrypi.com>
> 
> Move the existing isRaw()/isYuv()/isRgb()into a static function of
> PipelineHandlerBase. This will allow then to be shared with the

s/then/them/

> pipeline handler derived class.
> 
> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>

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

> ---
>  .../pipeline/rpi/common/pipeline_base.cpp     | 52 +++++++++----------
>  .../pipeline/rpi/common/pipeline_base.h       |  4 ++
>  2 files changed, 30 insertions(+), 26 deletions(-)
> 
> diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
> index 502cdff0051b..f6f6185cbfef 100644
> --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
> +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
> @@ -37,12 +37,6 @@ namespace {
>  
>  constexpr unsigned int defaultRawBitDepth = 12;
>  
> -bool isRaw(const PixelFormat &pixFmt)
> -{
> -	/* This test works for both Bayer and raw mono formats. */
> -	return BayerFormat::fromPixelFormat(pixFmt).isValid();
> -}
> -
>  PixelFormat mbusCodeToPixelFormat(unsigned int mbus_code,
>  				  BayerFormat::Packing packingReq)
>  {
> @@ -91,22 +85,6 @@ std::optional<ColorSpace> findValidColorSpace(const ColorSpace &colourSpace)
>  	return std::nullopt;
>  }
>  
> -bool isRgb(const PixelFormat &pixFmt)
> -{
> -	const PixelFormatInfo &info = PixelFormatInfo::info(pixFmt);
> -	return info.colourEncoding == PixelFormatInfo::ColourEncodingRGB;
> -}
> -
> -bool isYuv(const PixelFormat &pixFmt)
> -{
> -	/* The code below would return true for raw mono streams, so weed those out first. */
> -	if (isRaw(pixFmt))
> -		return false;
> -
> -	const PixelFormatInfo &info = PixelFormatInfo::info(pixFmt);
> -	return info.colourEncoding == PixelFormatInfo::ColourEncodingYUV;
> -}
> -
>  } /* namespace */
>  
>  /*
> @@ -129,7 +107,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validateColorSpaces([[maybe_
>  
>  	for (auto cfg : config_) {
>  		/* First fix up raw streams to have the "raw" colour space. */
> -		if (isRaw(cfg.pixelFormat)) {
> +		if (PipelineHandlerBase::isRaw(cfg.pixelFormat)) {
>  			/* If there was no value here, that doesn't count as "adjusted". */
>  			if (cfg.colorSpace && cfg.colorSpace != ColorSpace::Raw)
>  				status = Adjusted;
> @@ -156,13 +134,13 @@ CameraConfiguration::Status RPiCameraConfiguration::validateColorSpaces([[maybe_
>  		if (cfg.colorSpace == ColorSpace::Raw)
>  			continue;
>  
> -		if (isYuv(cfg.pixelFormat) && cfg.colorSpace != yuvColorSpace_) {
> +		if (PipelineHandlerBase::isYuv(cfg.pixelFormat) && cfg.colorSpace != yuvColorSpace_) {
>  			/* Again, no value means "not adjusted". */
>  			if (cfg.colorSpace)
>  				status = Adjusted;
>  			cfg.colorSpace = yuvColorSpace_;
>  		}
> -		if (isRgb(cfg.pixelFormat) && cfg.colorSpace != rgbColorSpace_) {
> +		if (PipelineHandlerBase::isRgb(cfg.pixelFormat) && cfg.colorSpace != rgbColorSpace_) {
>  			/* Be nice, and let the YUV version count as non-adjusted too. */
>  			if (cfg.colorSpace && cfg.colorSpace != yuvColorSpace_)
>  				status = Adjusted;
> @@ -203,7 +181,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()
>  
>  	std::vector<CameraData::StreamParams> rawStreams, outStreams;
>  	for (const auto &[index, cfg] : utils::enumerate(config_)) {
> -		if (isRaw(cfg.pixelFormat))
> +		if (PipelineHandlerBase::isRaw(cfg.pixelFormat))
>  			rawStreams.emplace_back(index, &cfg);
>  		else
>  			outStreams.emplace_back(index, &cfg);
> @@ -351,6 +329,28 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()
>  	return status;
>  }
>  
> +bool PipelineHandlerBase::isRgb(const PixelFormat &pixFmt)
> +{
> +	const PixelFormatInfo &info = PixelFormatInfo::info(pixFmt);
> +	return info.colourEncoding == PixelFormatInfo::ColourEncodingRGB;
> +}
> +
> +bool PipelineHandlerBase::isYuv(const PixelFormat &pixFmt)
> +{
> +	/* The code below would return true for raw mono streams, so weed those out first. */
> +	if (PipelineHandlerBase::isRaw(pixFmt))
> +		return false;
> +
> +	const PixelFormatInfo &info = PixelFormatInfo::info(pixFmt);
> +	return info.colourEncoding == PixelFormatInfo::ColourEncodingYUV;
> +}
> +
> +bool PipelineHandlerBase::isRaw(const PixelFormat &pixFmt)
> +{
> +	/* This test works for both Bayer and raw mono formats. */
> +	return BayerFormat::fromPixelFormat(pixFmt).isValid();
> +}
> +
>  V4L2DeviceFormat PipelineHandlerBase::toV4L2DeviceFormat(const V4L2VideoDevice *dev,
>  							 const V4L2SubdeviceFormat &format,
>  							 BayerFormat::Packing packingReq)
> diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h
> index 3e7c487fb0bf..135b74392140 100644
> --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h
> +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h
> @@ -213,6 +213,10 @@ public:
>  	{
>  	}
>  
> +	static bool isRgb(const PixelFormat &pixFmt);
> +	static bool isYuv(const PixelFormat &pixFmt);
> +	static bool isRaw(const PixelFormat &pixFmt);
> +
>  	static V4L2DeviceFormat toV4L2DeviceFormat(const V4L2VideoDevice *dev,
>  						   const V4L2SubdeviceFormat &format,
>  						   BayerFormat::Packing packingReq);

Patch
diff mbox series

diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
index 502cdff0051b..f6f6185cbfef 100644
--- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp
@@ -37,12 +37,6 @@  namespace {
 
 constexpr unsigned int defaultRawBitDepth = 12;
 
-bool isRaw(const PixelFormat &pixFmt)
-{
-	/* This test works for both Bayer and raw mono formats. */
-	return BayerFormat::fromPixelFormat(pixFmt).isValid();
-}
-
 PixelFormat mbusCodeToPixelFormat(unsigned int mbus_code,
 				  BayerFormat::Packing packingReq)
 {
@@ -91,22 +85,6 @@  std::optional<ColorSpace> findValidColorSpace(const ColorSpace &colourSpace)
 	return std::nullopt;
 }
 
-bool isRgb(const PixelFormat &pixFmt)
-{
-	const PixelFormatInfo &info = PixelFormatInfo::info(pixFmt);
-	return info.colourEncoding == PixelFormatInfo::ColourEncodingRGB;
-}
-
-bool isYuv(const PixelFormat &pixFmt)
-{
-	/* The code below would return true for raw mono streams, so weed those out first. */
-	if (isRaw(pixFmt))
-		return false;
-
-	const PixelFormatInfo &info = PixelFormatInfo::info(pixFmt);
-	return info.colourEncoding == PixelFormatInfo::ColourEncodingYUV;
-}
-
 } /* namespace */
 
 /*
@@ -129,7 +107,7 @@  CameraConfiguration::Status RPiCameraConfiguration::validateColorSpaces([[maybe_
 
 	for (auto cfg : config_) {
 		/* First fix up raw streams to have the "raw" colour space. */
-		if (isRaw(cfg.pixelFormat)) {
+		if (PipelineHandlerBase::isRaw(cfg.pixelFormat)) {
 			/* If there was no value here, that doesn't count as "adjusted". */
 			if (cfg.colorSpace && cfg.colorSpace != ColorSpace::Raw)
 				status = Adjusted;
@@ -156,13 +134,13 @@  CameraConfiguration::Status RPiCameraConfiguration::validateColorSpaces([[maybe_
 		if (cfg.colorSpace == ColorSpace::Raw)
 			continue;
 
-		if (isYuv(cfg.pixelFormat) && cfg.colorSpace != yuvColorSpace_) {
+		if (PipelineHandlerBase::isYuv(cfg.pixelFormat) && cfg.colorSpace != yuvColorSpace_) {
 			/* Again, no value means "not adjusted". */
 			if (cfg.colorSpace)
 				status = Adjusted;
 			cfg.colorSpace = yuvColorSpace_;
 		}
-		if (isRgb(cfg.pixelFormat) && cfg.colorSpace != rgbColorSpace_) {
+		if (PipelineHandlerBase::isRgb(cfg.pixelFormat) && cfg.colorSpace != rgbColorSpace_) {
 			/* Be nice, and let the YUV version count as non-adjusted too. */
 			if (cfg.colorSpace && cfg.colorSpace != yuvColorSpace_)
 				status = Adjusted;
@@ -203,7 +181,7 @@  CameraConfiguration::Status RPiCameraConfiguration::validate()
 
 	std::vector<CameraData::StreamParams> rawStreams, outStreams;
 	for (const auto &[index, cfg] : utils::enumerate(config_)) {
-		if (isRaw(cfg.pixelFormat))
+		if (PipelineHandlerBase::isRaw(cfg.pixelFormat))
 			rawStreams.emplace_back(index, &cfg);
 		else
 			outStreams.emplace_back(index, &cfg);
@@ -351,6 +329,28 @@  CameraConfiguration::Status RPiCameraConfiguration::validate()
 	return status;
 }
 
+bool PipelineHandlerBase::isRgb(const PixelFormat &pixFmt)
+{
+	const PixelFormatInfo &info = PixelFormatInfo::info(pixFmt);
+	return info.colourEncoding == PixelFormatInfo::ColourEncodingRGB;
+}
+
+bool PipelineHandlerBase::isYuv(const PixelFormat &pixFmt)
+{
+	/* The code below would return true for raw mono streams, so weed those out first. */
+	if (PipelineHandlerBase::isRaw(pixFmt))
+		return false;
+
+	const PixelFormatInfo &info = PixelFormatInfo::info(pixFmt);
+	return info.colourEncoding == PixelFormatInfo::ColourEncodingYUV;
+}
+
+bool PipelineHandlerBase::isRaw(const PixelFormat &pixFmt)
+{
+	/* This test works for both Bayer and raw mono formats. */
+	return BayerFormat::fromPixelFormat(pixFmt).isValid();
+}
+
 V4L2DeviceFormat PipelineHandlerBase::toV4L2DeviceFormat(const V4L2VideoDevice *dev,
 							 const V4L2SubdeviceFormat &format,
 							 BayerFormat::Packing packingReq)
diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h
index 3e7c487fb0bf..135b74392140 100644
--- a/src/libcamera/pipeline/rpi/common/pipeline_base.h
+++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h
@@ -213,6 +213,10 @@  public:
 	{
 	}
 
+	static bool isRgb(const PixelFormat &pixFmt);
+	static bool isYuv(const PixelFormat &pixFmt);
+	static bool isRaw(const PixelFormat &pixFmt);
+
 	static V4L2DeviceFormat toV4L2DeviceFormat(const V4L2VideoDevice *dev,
 						   const V4L2SubdeviceFormat &format,
 						   BayerFormat::Packing packingReq);