[libcamera-devel] [RFC PATCH 3/4] tests: stream: Add a colorspace adjustment test

Laurent Pinchart laurent.pinchart at ideasonboard.com
Tue Aug 16 04:35:52 CEST 2022


Hi Umang,

Thank you for the patch.

On Wed, Aug 03, 2022 at 12:27:18AM +0530, Umang Jain via libcamera-devel wrote:
> ColorSpace can be adjusted based on the stream's pixelFormat being
> requested. Add a test to check the adjustment logic.
> 
> Signed-off-by: Umang Jain <umang.jain at ideasonboard.com>
> ---
>  test/stream/meson.build           |  1 +
>  test/stream/stream_colorspace.cpp | 57 +++++++++++++++++++++++++++++++
>  2 files changed, 58 insertions(+)
>  create mode 100644 test/stream/stream_colorspace.cpp
> 
> diff --git a/test/stream/meson.build b/test/stream/meson.build
> index 73608ffd..bf78ddfe 100644
> --- a/test/stream/meson.build
> +++ b/test/stream/meson.build
> @@ -2,6 +2,7 @@
>  
>  stream_tests = [
>      ['stream_formats',  'stream_formats.cpp'],
> +    ['stream_colorspace', 'stream_colorspace.cpp'],
>  ]
>  
>  foreach t : stream_tests
> diff --git a/test/stream/stream_colorspace.cpp b/test/stream/stream_colorspace.cpp
> new file mode 100644
> index 00000000..e8ac17d3
> --- /dev/null
> +++ b/test/stream/stream_colorspace.cpp
> @@ -0,0 +1,57 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Copyright (C) 2022, Ideas on Board Oy.
> + *
> + * stream_colorspace.cpp - Stream colorspace tests
> + */
> +
> +#include <iostream>
> +
> +#include <libcamera/formats.h>
> +#include <libcamera/stream.h>
> +
> +#include "test.h"
> +
> +using namespace libcamera;
> +
> +class StreamColorSpaceTest : public Test
> +{
> +protected:
> +	int run()
> +	{
> +		StreamConfiguration cfg;
> +		cfg.size = { 640, 320 };
> +		cfg.pixelFormat = formats::YUV422;
> +		cfg.colorSpace = ColorSpace::Srgb;
> +
> +		/* YUV stream with sRGB colorspace should have y'cbcr encoding adjusted */

s/y'cbcr/Y'CbCr/

> +		ColorSpace adjColorSpace = cfg.colorSpace->adjust(cfg);
> +		if (adjColorSpace.ycbcrEncoding == ColorSpace::YcbcrEncoding::None)
> +			return TestFail;
> +
> +		/* For RGB pixelFormat, sRGB colorspace shouldn't get adjusted */
> +		cfg.pixelFormat = formats::RGB888;
> +		adjColorSpace = cfg.colorSpace->adjust(cfg);
> +		if (adjColorSpace == ColorSpace::Srgb)
> +			;
> +		else
> +			return TestFail;

That's peculiar.

		if (adjColorSpace != ColorSpace::Srgb)
			return TestFail;

I expect this patch to change based on the comments on 2/4, so I'll
review it again then.

> +
> +		/*
> +		 * For YUV pixelFormat, encoding should picked up according to
> +		 * primaries.
> +		 */
> +		cfg.pixelFormat = formats::YUV422;
> +		cfg.colorSpace = ColorSpace(ColorSpace::Primaries::Rec2020,
> +					    ColorSpace::TransferFunction::Rec709,
> +					    ColorSpace::YcbcrEncoding::None,
> +					    ColorSpace::Range::Limited);
> +		adjColorSpace = cfg.colorSpace->adjust(cfg);
> +		if (adjColorSpace.ycbcrEncoding != ColorSpace::YcbcrEncoding::Rec2020)
> +			return TestFail;
> +
> +		return TestPass;
> +	}
> +};
> +
> +TEST_REGISTER(StreamColorSpaceTest)

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list