From patchwork Tue Aug 30 07:47:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 17255 X-Patchwork-Delegate: umang.jain@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 28BB1C3272 for ; Tue, 30 Aug 2022 07:47:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DB13261FCC; Tue, 30 Aug 2022 09:47:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1661845672; bh=Jdj0XGz/2g2ed/6YUcDmE0nB72gTUKyrwSC/zUCODMs=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=le2NdP+qJJj5qwerUpbKLB/1x0gr3QoGujMduXn4X0l/eIJBOplRcQ5zlinU7xrmX aqCZKDXz8MFBECHOnrZxWW94OnTyi+dAiFqRFy5DSWwxyvCQcVoiqwmPrkGsUuJzVF GWTlgUbNBY675hPV0amCRYj3ZNGTJLdyopaLLqZoExkCMGLMt6p0XZ/MSXP247jTiH tmMF/zV6wBzwVcVGjqUdjbq3fdLGywuBSKtWh4p4f/Eyj/dfTC0fS0YeZgsRA+17ol GIJTmlyIsvILKbr8VMPY1PIngLYPJyScSFY0SJ5s16rFusbsOeIQZ24+TW3hSrcbvr X1MEzeDOOzIOQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F0F6061FB9 for ; Tue, 30 Aug 2022 09:47:50 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="C0s69qaS"; dkim-atps=neutral Received: from umang.jainideasonboard.com (unknown [IPv6:2401:4900:1f3f:1548:78ac:4a3:edc3:c28a]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7022C481; Tue, 30 Aug 2022 09:47:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1661845670; bh=Jdj0XGz/2g2ed/6YUcDmE0nB72gTUKyrwSC/zUCODMs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C0s69qaSv/0FBKn1oTL0iV0TCSNfQcdsIDGA3wpzgIVKQ7t2f4ZFfrMsNLbr8Sh8C sH84PLXGACR+KZzhf/ruKi7/ztKfozwQ7Gz+p0Dnhj4swfYWfciUTWTA+2HJuHySRE jdCGSDNsxVbNwTuihdYVaD32b/YKoMMCwCkYN7Mw= To: libcamera-devel@lists.libcamera.org Date: Tue, 30 Aug 2022 13:17:24 +0530 Message-Id: <20220830074725.1059643-7-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220830074725.1059643-1-umang.jain@ideasonboard.com> References: <20220830074725.1059643-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 6/7] tests: stream: Add a colorspace adjustment test X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Umang Jain via libcamera-devel From: Umang Jain Reply-To: Umang Jain Cc: rishikeshdonadkar@gmail.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" ColorSpace can be adjusted based on the stream's pixelFormat being requested. Add a test to check the adjustment logic defined in ColorSpace::adjust(). Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart Reviewed-by: Paul Elder --- test/stream/meson.build | 1 + test/stream/stream_colorspace.cpp | 96 +++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 test/stream/stream_colorspace.cpp diff --git a/test/stream/meson.build b/test/stream/meson.build index 73608ffd..89f51c18 100644 --- a/test/stream/meson.build +++ b/test/stream/meson.build @@ -1,6 +1,7 @@ # SPDX-License-Identifier: CC0-1.0 stream_tests = [ + ['stream_colorspace', 'stream_colorspace.cpp'], ['stream_formats', 'stream_formats.cpp'], ] diff --git a/test/stream/stream_colorspace.cpp b/test/stream/stream_colorspace.cpp new file mode 100644 index 00000000..1b7afe65 --- /dev/null +++ b/test/stream/stream_colorspace.cpp @@ -0,0 +1,96 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2022, Ideas on Board Oy. + * + * stream_colorspace.cpp - Stream colorspace adjustment test + */ + +#include + +#include +#include +#include + +#include "test.h" + +using namespace libcamera; +using namespace std; + +class TestCameraConfiguration : public CameraConfiguration +{ +public: + TestCameraConfiguration() + : CameraConfiguration() + { + } + + Status validate() override + { + return validateColorSpaces(); + } +}; + +class StreamColorSpaceTest : public Test +{ +protected: + int run() + { + TestCameraConfiguration config; + + StreamConfiguration cfg; + cfg.size = { 640, 320 }; + cfg.pixelFormat = formats::YUV422; + cfg.colorSpace = ColorSpace::Srgb; + config.addConfiguration(cfg); + + StreamConfiguration &streamCfg = config.at(0); + + /* + * YUV pixelformat with sRGB colorspace should have Y'CbCr encoding + * adjusted. + */ + config.validate(); + if (streamCfg.colorSpace->ycbcrEncoding == ColorSpace::YcbcrEncoding::None) { + cerr << "YUV format must have YCbCr encoding" << endl; + return TestFail; + } + + /* + * For YUV pixelFormat, encoding should be picked up according + * to primaries and transfer function, if 'None' is specified. + */ + streamCfg.pixelFormat = formats::YUV422; + streamCfg.colorSpace = ColorSpace(ColorSpace::Primaries::Rec2020, + ColorSpace::TransferFunction::Rec709, + ColorSpace::YcbcrEncoding::None, + ColorSpace::Range::Limited); + config.validate(); + if (streamCfg.colorSpace->ycbcrEncoding != ColorSpace::YcbcrEncoding::Rec2020) { + cerr << "Failed to adjust colorspace Y'CbCr encoding according" + << " to primaries and transfer function" << endl; + return TestFail; + } + + /* For RGB pixelFormat, Sycc colorspace should get adjusted to sRGB. */ + streamCfg.pixelFormat = formats::RGB888; + streamCfg.colorSpace = ColorSpace::Sycc; + config.validate(); + if (streamCfg.colorSpace != ColorSpace::Srgb) { + cerr << "RGB format's colorspace should be set to Srgb" << endl; + return TestFail; + } + + /* Raw formats should always set colorspace to ColorSpace::Raw. */ + streamCfg.pixelFormat = formats::SBGGR8; + streamCfg.colorSpace = ColorSpace::Rec709; + config.validate(); + if (streamCfg.colorSpace != ColorSpace::Raw) { + cerr << "Raw format must always have Raw colorspace" << endl; + return TestFail; + } + + return TestPass; + } +}; + +TEST_REGISTER(StreamColorSpaceTest)