[v5,1/2] pipeline: virtual: Provide and validate colorspace
diff mbox series

Message ID 20251103221315.73350-2-uajain@igalia.com
State Accepted
Commit 5d2d005306ad1b64c7ad857c48a2edf8e56629f5
Headers show
Series
  • lc-compliance: Ensure stream's colorspace is set after validate()
Related show

Commit Message

Umang Jain Nov. 3, 2025, 10:13 p.m. UTC
Virtual pipeline handler should provide colorSpace in
generateConfiguration() and validate the colorspace in validate().
It is mandatory for a pipeline handler to set the colorspace if it
is unset in the stream configuration, during validate().

For choosing the colorspace for the generated NV12 frames, following
points have been taken into account:
- The transfer function should be Rec.709 for NV12
- The YCbCr encoding has been chosen Rec.709 as it is the most common
  than Rec.601/Rec.2020
- Range should be 'Limited' as with the NV12 pixel format.

Hence, the closest colorspace match is ColorSpace::Rec709 which is
set for the virtual pipeline handler.

Signed-off-by: Umang Jain <uajain@igalia.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Tested-by: Robert Mader <robert.mader@collabora.com>
---
 src/libcamera/pipeline/virtual/virtual.cpp | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Laurent Pinchart Dec. 1, 2025, 2:05 a.m. UTC | #1
On Mon, Nov 03, 2025 at 10:13:14PM +0000, Umang Jain wrote:
> Virtual pipeline handler should provide colorSpace in
> generateConfiguration() and validate the colorspace in validate().
> It is mandatory for a pipeline handler to set the colorspace if it
> is unset in the stream configuration, during validate().
> 
> For choosing the colorspace for the generated NV12 frames, following
> points have been taken into account:
> - The transfer function should be Rec.709 for NV12
> - The YCbCr encoding has been chosen Rec.709 as it is the most common
>   than Rec.601/Rec.2020
> - Range should be 'Limited' as with the NV12 pixel format.

This doesn't look right. Have you looked at home frames are generated ?
Color spaces are not values we set randomly to please compliance checks.
They need to reflect the contents of the image.

The virtual pipeline handler can read images from files, or generate
test patterns. In both cases they're converted to NV12 with libyuv.
Please check what colorspace is generated in both cases, and set the
colorspace accordingly. As this patch has been merged, we need a fix on
top.

> Hence, the closest colorspace match is ColorSpace::Rec709 which is
> set for the virtual pipeline handler.
> 
> Signed-off-by: Umang Jain <uajain@igalia.com>
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> Tested-by: Robert Mader <robert.mader@collabora.com>
> ---
>  src/libcamera/pipeline/virtual/virtual.cpp | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/src/libcamera/pipeline/virtual/virtual.cpp b/src/libcamera/pipeline/virtual/virtual.cpp
> index 23eae852..34def19b 100644
> --- a/src/libcamera/pipeline/virtual/virtual.cpp
> +++ b/src/libcamera/pipeline/virtual/virtual.cpp
> @@ -214,6 +214,17 @@ CameraConfiguration::Status VirtualCameraConfiguration::validate()
>  			adjusted = true;
>  		}
>  
> +		if (cfg.colorSpace != ColorSpace::Rec709) {
> +			cfg.colorSpace = ColorSpace::Rec709;
> +			status = Adjusted;
> +			adjusted = true;
> +		}
> +
> +		if (validateColorSpaces() == Adjusted) {
> +			status = Adjusted;
> +			adjusted = true;
> +		}
> +
>  		if (adjusted)
>  			LOG(Virtual, Info)
>  				<< "Stream configuration adjusted to " << cfg.toString();
> @@ -278,6 +289,7 @@ PipelineHandlerVirtual::generateConfiguration(Camera *camera,
>  		cfg.pixelFormat = pixelFormat;
>  		cfg.size = data->config_.maxResolutionSize;
>  		cfg.bufferCount = VirtualCameraConfiguration::kBufferCount;
> +		cfg.colorSpace = ColorSpace::Rec709;
>  
>  		config->addConfiguration(cfg);
>  	}

Patch
diff mbox series

diff --git a/src/libcamera/pipeline/virtual/virtual.cpp b/src/libcamera/pipeline/virtual/virtual.cpp
index 23eae852..34def19b 100644
--- a/src/libcamera/pipeline/virtual/virtual.cpp
+++ b/src/libcamera/pipeline/virtual/virtual.cpp
@@ -214,6 +214,17 @@  CameraConfiguration::Status VirtualCameraConfiguration::validate()
 			adjusted = true;
 		}
 
+		if (cfg.colorSpace != ColorSpace::Rec709) {
+			cfg.colorSpace = ColorSpace::Rec709;
+			status = Adjusted;
+			adjusted = true;
+		}
+
+		if (validateColorSpaces() == Adjusted) {
+			status = Adjusted;
+			adjusted = true;
+		}
+
 		if (adjusted)
 			LOG(Virtual, Info)
 				<< "Stream configuration adjusted to " << cfg.toString();
@@ -278,6 +289,7 @@  PipelineHandlerVirtual::generateConfiguration(Camera *camera,
 		cfg.pixelFormat = pixelFormat;
 		cfg.size = data->config_.maxResolutionSize;
 		cfg.bufferCount = VirtualCameraConfiguration::kBufferCount;
+		cfg.colorSpace = ColorSpace::Rec709;
 
 		config->addConfiguration(cfg);
 	}