[libcamera-devel,RFC,3/4] tests: stream: Add a colorspace adjustment test
diff mbox series

Message ID 20220802185719.380855-4-umang.jain@ideasonboard.com
State Superseded
Headers show
Series
  • Colorspace adjustments and gstreamer mapping
Related show

Commit Message

Umang Jain Aug. 2, 2022, 6:57 p.m. UTC
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@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

Comments

Laurent Pinchart Aug. 16, 2022, 2:35 a.m. UTC | #1
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@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)

Patch
diff mbox series

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 */
+		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;
+
+		/*
+		 * 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)