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

Umang Jain umang.jain at ideasonboard.com
Tue Aug 2 20:57:18 CEST 2022


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



More information about the libcamera-devel mailing list