{"id":14631,"url":"https://patchwork.libcamera.org/api/patches/14631/?format=json","web_url":"https://patchwork.libcamera.org/patch/14631/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20211118151933.15627-7-david.plowman@raspberrypi.com>","date":"2021-11-18T15:19:32","name":"[libcamera-devel,v6,6/7] libcamera: Add validateColorSpaces to CameraConfiguration class","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"157531099b648e3c53d6df8ca6a5c23c7c14b577","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/?format=json","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/14631/mbox/","series":[{"id":2726,"url":"https://patchwork.libcamera.org/api/series/2726/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2726","date":"2021-11-18T15:19:26","name":"Colour spaces","version":6,"mbox":"https://patchwork.libcamera.org/series/2726/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/14631/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14631/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 3CBB5BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 18 Nov 2021 15:20:37 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E2E35603C9;\n\tThu, 18 Nov 2021 16:20:36 +0100 (CET)","from mail-wm1-x336.google.com (mail-wm1-x336.google.com\n\t[IPv6:2a00:1450:4864:20::336])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6C2DC6038A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 18 Nov 2021 16:20:30 +0100 (CET)","by mail-wm1-x336.google.com with SMTP id\n\tb184-20020a1c1bc1000000b0033140bf8dd5so5073952wmb.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 18 Nov 2021 07:20:30 -0800 (PST)","from pi4-davidp.pitowers.org\n\t([2a00:1098:3142:14:1ce1:9965:4328:89c4])\n\tby smtp.gmail.com with ESMTPSA id\n\tp12sm147367wro.33.2021.11.18.07.20.29\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 18 Nov 2021 07:20:29 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"PmhMNfpp\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=e9vLi2M3N7esEcpYN4gESMpiB1Tm8dGAXoq3VzNR2x4=;\n\tb=PmhMNfppy2HSu2E5gW+vG7BLArB4EdsouHEIIjqw3/3uhAYnQBHhsCHNTzfO19VFQM\n\t6auh3Zt93yIh+6xHIM3cOgKRvDhB64s1p3fTF/N8+0wKjKjQvk7JvO5S4b0pJ96V7iJS\n\tK00v5RNjnn2ao2sQhi4TS0Oyzu+YbnC9R/YGJEiVz+PpQOOX4PNtM7+cKvKpqqCSsYcH\n\tGY+2ayBhvqhY7Dc6Pl3aS9QMvYHC3hU6l30M8GpNWBXsJnM8KmaTqgTzMWkil8BzpE+u\n\tJun9d+vVc6k++6zIiyTrGCLcFGlCJS0NpqRiXveEnIeaHpYJ9URDCCv2wnH6F5dkgKLG\n\tf9Mg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=e9vLi2M3N7esEcpYN4gESMpiB1Tm8dGAXoq3VzNR2x4=;\n\tb=rMSPljn639hlGD2OKMWEf63qANki2OnRh0KdCJ73LtrQMetbSX3is7KPTxAzJhSUv0\n\thECU8WXmjOpL3ZsV3OiGYOj3DLVpEY6UOpGf+zEYZab1YvP9K+PZWzt9hOY42xpGAEJC\n\tA4KFGcjmdxFbqX1f09WuejUkH00a/tPGo1VWB2wQMW9y3Ql70OPlCF2p7ejnLu7SfsKm\n\tJ2Vn6fL/25T8tuoeskFNxGg3eajm0pDzJmrO1N6p+ExuJ+SAywgZTokTQ7cxBO8lUN6O\n\tx4eIlWGVJGPd6to1Bx63ZfQ9WCi95cxfpd6YXgBACUmasTXKc1PvEDwejMsLfok7h9aJ\n\tzjoA==","X-Gm-Message-State":"AOAM530OTKQqpHsG0ru9Cq7N2VGkUeJNgthn2SR1iCCJ7NEy511cltmL\n\tTTtrFVpHgZbPb9lva76b0X228g==","X-Google-Smtp-Source":"ABdhPJzRbAaHY/mJvm64joUeBIgYmzNLtHqd1my/s8wJO/SBKh0wG/CU0oaHySU7C8LET8LHShAZ4g==","X-Received":"by 2002:a1c:8015:: with SMTP id\n\tb21mr10641552wmd.161.1637248830116; \n\tThu, 18 Nov 2021 07:20:30 -0800 (PST)","From":"David Plowman <david.plowman@raspberrypi.com>","To":"laurent.pinchart@ideasonboard.com, kieran.bingham@ideasonboard.com,\n\thverkuil-cisco@xs4all.nl, tfiga@google.com, jacopo@jmondi.org,\n\tnaush@raspberrypi.com, libcamera-devel@lists.libcamera.org","Date":"Thu, 18 Nov 2021 15:19:32 +0000","Message-Id":"<20211118151933.15627-7-david.plowman@raspberrypi.com>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20211118151933.15627-1-david.plowman@raspberrypi.com>","References":"<20211118151933.15627-1-david.plowman@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v6 6/7] libcamera: Add validateColorSpaces\n\tto CameraConfiguration class","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"This method forces raw streams to have the \"raw\" color space, and also\noptionally makes all output streams to share the same color space as\nsome platforms may require this.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\n---\n include/libcamera/camera.h |  2 ++\n src/libcamera/camera.cpp   | 51 ++++++++++++++++++++++++++++++++++++++\n 2 files changed, 53 insertions(+)","diff":"diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h\nindex 601ee46e..fdab4410 100644\n--- a/include/libcamera/camera.h\n+++ b/include/libcamera/camera.h\n@@ -69,6 +69,8 @@ public:\n protected:\n \tCameraConfiguration();\n \n+\tStatus validateColorSpaces(bool sharedColorSpace);\n+\n \tstd::vector<StreamConfiguration> config_;\n };\n \ndiff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\nindex 400a7cf0..c1541685 100644\n--- a/src/libcamera/camera.cpp\n+++ b/src/libcamera/camera.cpp\n@@ -20,6 +20,7 @@\n \n #include \"libcamera/internal/camera.h\"\n #include \"libcamera/internal/camera_controls.h\"\n+#include \"libcamera/internal/formats.h\"\n #include \"libcamera/internal/pipeline_handler.h\"\n \n /**\n@@ -314,6 +315,56 @@ std::size_t CameraConfiguration::size() const\n \treturn config_.size();\n }\n \n+static bool isRaw(const PixelFormat &pixFmt)\n+{\n+\tconst PixelFormatInfo &info = PixelFormatInfo::info(pixFmt);\n+\treturn info.isValid() &&\n+\t       info.colourEncoding == PixelFormatInfo::ColourEncodingRAW;\n+}\n+\n+CameraConfiguration::Status CameraConfiguration::validateColorSpaces(bool sharedColorSpace)\n+{\n+\tStatus status = Valid;\n+\n+\t/* Find the largest non-raw stream (if any). */\n+\tint index = -1;\n+\tfor (unsigned int i = 0; i < config_.size(); i++) {\n+\t\tconst StreamConfiguration &cfg = config_[i];\n+\t\tif (!isRaw(cfg.pixelFormat) && (index < 0 || cfg.size > config_[i].size))\n+\t\t\tindex = i;\n+\t}\n+\n+\t/*\n+\t * Here we force raw streams to the correct color space. We handle\n+\t * the case where all output streams are to share a color space,\n+\t * which will match the color space of the largest (non-raw) stream.\n+\t */\n+\tfor (auto &cfg : config_) {\n+\t\tstd::optional<ColorSpace> initialColorSpace = cfg.colorSpace;\n+\n+\t\tif (isRaw(cfg.pixelFormat))\n+\t\t\tcfg.colorSpace = ColorSpace::Raw;\n+\t\telse if (sharedColorSpace) {\n+\t\t\t/*\n+\t\t\t * When all outputs share a color space, use the biggest\n+\t\t\t * output if that was set. If that was blank, but this\n+\t\t\t * stream's is not, then use this stream's color space for\n+\t\t\t * largest stream.\n+\t\t\t * (index must be != -1 if there are any non-raw streams.)\n+\t\t\t */\n+\t\t\tif (config_[index].colorSpace)\n+\t\t\t\tcfg.colorSpace = config_[index].colorSpace;\n+\t\t\telse if (cfg.colorSpace)\n+\t\t\t\tconfig_[index].colorSpace = cfg.colorSpace;\n+\t\t}\n+\n+\t\tif (cfg.colorSpace != initialColorSpace)\n+\t\t\tstatus = Adjusted;\n+\t}\n+\n+\treturn status;\n+}\n+\n /**\n  * \\var CameraConfiguration::transform\n  * \\brief User-specified transform to be applied to the image\n","prefixes":["libcamera-devel","v6","6/7"]}