Patch Detail
Show a patch.
GET /api/patches/15111/?format=api
{ "id": 15111, "url": "https://patchwork.libcamera.org/api/patches/15111/?format=api", "web_url": "https://patchwork.libcamera.org/patch/15111/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20211210112142.18441-8-david.plowman@raspberrypi.com>", "date": "2021-12-10T11:21:41", "name": "[libcamera-devel,v11,7/8] libcamera: Add validateColorSpaces to CameraConfiguration class", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "4e3816f5374f48bb4f6691d9a0a817ded21f5551", "submitter": { "id": 42, "url": "https://patchwork.libcamera.org/api/people/42/?format=api", "name": "David Plowman", "email": "david.plowman@raspberrypi.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/15111/mbox/", "series": [ { "id": 2834, "url": "https://patchwork.libcamera.org/api/series/2834/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2834", "date": "2021-12-10T11:21:34", "name": "Colour spaces", "version": 11, "mbox": "https://patchwork.libcamera.org/series/2834/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/15111/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/15111/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 0B933C3259\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 10 Dec 2021 11:22:13 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A71996089C;\n\tFri, 10 Dec 2021 12:22:12 +0100 (CET)", "from mail-wr1-x432.google.com (mail-wr1-x432.google.com\n\t[IPv6:2a00:1450:4864:20::432])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A32056089C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 10 Dec 2021 12:22:08 +0100 (CET)", "by mail-wr1-x432.google.com with SMTP id u1so14277893wru.13\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 10 Dec 2021 03:22:08 -0800 (PST)", "from pi4-davidp.pitowers.org\n\t([2a00:1098:3142:14:e4a2:3070:eea4:e434])\n\tby smtp.gmail.com with ESMTPSA id\n\tz18sm2198469wrq.11.2021.12.10.03.22.07\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 10 Dec 2021 03:22:07 -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=\"Oj6PUd0/\"; 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=2bNStc3f5yx0+9r6cEGZZIEuYgCV35H3PWXSv/otXK8=;\n\tb=Oj6PUd0/l6GDhYXP26/dGOCLjmf00nZqBRVB1jprHDW2gXSuh4KPBH5V4QUPHsNwsy\n\tT6AaW9OP74Hf2jpfdezD1fBEk3oaZ+O9mi3bt2t2lpsvjk4VtSq7oC4m/M1131UPM9Y3\n\tL3kzMLTAbPmsPYGcGVDWhse9aV5NjNXZA6wX1YtMb0Xn3owUROXLhhv3Rc8LRCdRSJ6V\n\tvAQbZK+gvp/TmnM2IZHJYymADx1r+mQfHOMxwLKtXWXCIjs2yWG0wVv9gHlbugkOTx04\n\tEd2Ci0Do5jVy/LRWHnsQnPMqimYkaoFK6Pi8XNCnkBoHY1QInkO4PXSihLPCmGT8WlOs\n\tUhTg==", "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=2bNStc3f5yx0+9r6cEGZZIEuYgCV35H3PWXSv/otXK8=;\n\tb=PKv/+XJy3cT6dbzUTRHgQGgJHu/NlOc4GtAKJ9146p0FnTriDr6BMp3IYa4MISduZF\n\tkWW8ZhKDxSJZOoDDPYevWZQqh6FlEIdvEySId47NCiG2xSuGlrPQGYRMGk20NVDMnKHt\n\th4x+1Pg1UwjODw+cfiTqn/zHuWDI3++lPfk9dbJiCRlziI37d6/eDM3oQ6He6TA/uBPG\n\tnJ+cQAFlWnn4KTRcAx3t46eO28BJ2NXCoOmwjEje6N26YSNeQjIgkuxQ5gt4vKvmIUxR\n\ts24KkqMOJIDInMySU6xXQtrYMvtoMroHcgLt8t2yEy2xYMYE7Kj4uafhBGWaHcWO4hw2\n\tz59Q==", "X-Gm-Message-State": "AOAM531fIiRoDTRJV7V3MXSUthDVarC2VPS+2bH22LeHDIxelzV/GqgD\n\tr8RrNLjB6vfPwNeS4p19sH9C4A==", "X-Google-Smtp-Source": "ABdhPJwiWVRpYlhWu5qtQXZi3is+jdND5+Sp9+8jyI78ekDj2M74WPrLZ4WOtc/EhTJNO5FLv0QFvg==", "X-Received": "by 2002:a5d:6886:: with SMTP id\n\th6mr13314127wru.287.1639135328314; \n\tFri, 10 Dec 2021 03:22:08 -0800 (PST)", "From": "David Plowman <david.plowman@raspberrypi.com>", "To": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tHans Verkuil <hverkuil-cisco@xs4all.nl>, Tomasz Figa <tfiga@google.com>, \n\tJacopo Mondi <jacopo@jmondi.org>,\n\tNaushir Patuck <naush@raspberrypi.com>, \n\tlibcamera-devel@lists.libcamera.org", "Date": "Fri, 10 Dec 2021 11:21:41 +0000", "Message-Id": "<20211210112142.18441-8-david.plowman@raspberrypi.com>", "X-Mailer": "git-send-email 2.30.2", "In-Reply-To": "<20211210112142.18441-1-david.plowman@raspberrypi.com>", "References": "<20211210112142.18441-1-david.plowman@raspberrypi.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v11 7/8] libcamera: Add\n\tvalidateColorSpaces to 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 function forces raw streams to have the \"raw\" color space, and\nalso optionally makes all non-raw output streams to share the same\ncolor space as some platforms may require this.\n\nWhen sharing color spaces we take the shared value to be the one from\nthe largest of these streams. This choice is ultimately arbitrary, but\ncan be appropriate if smaller output streams are used for image\nanalysis rather than human consumption, when the precise colours may\nbe less important.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\n---\n include/libcamera/camera.h | 10 +++++\n src/libcamera/camera.cpp | 80 ++++++++++++++++++++++++++++++++++++++\n 2 files changed, 90 insertions(+)", "diff": "diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h\nindex a7759ccb..5bb06584 100644\n--- a/include/libcamera/camera.h\n+++ b/include/libcamera/camera.h\n@@ -13,6 +13,7 @@\n #include <string>\n \n #include <libcamera/base/class.h>\n+#include <libcamera/base/flags.h>\n #include <libcamera/base/object.h>\n #include <libcamera/base/signal.h>\n \n@@ -69,6 +70,15 @@ public:\n protected:\n \tCameraConfiguration();\n \n+\tenum class ColorSpaceFlag {\n+\t\tNone,\n+\t\tStreamsShareColorSpace,\n+\t};\n+\n+\tusing ColorSpaceFlags = Flags<ColorSpaceFlag>;\n+\n+\tStatus validateColorSpaces(ColorSpaceFlags flags = ColorSpaceFlag::None);\n+\n \tstd::vector<StreamConfiguration> config_;\n };\n \ndiff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\nindex 400a7cf0..5f8533e8 100644\n--- a/src/libcamera/camera.cpp\n+++ b/src/libcamera/camera.cpp\n@@ -14,12 +14,14 @@\n #include <libcamera/base/log.h>\n #include <libcamera/base/thread.h>\n \n+#include <libcamera/color_space.h>\n #include <libcamera/framebuffer_allocator.h>\n #include <libcamera/request.h>\n #include <libcamera/stream.h>\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 +316,84 @@ std::size_t CameraConfiguration::size() const\n \treturn config_.size();\n }\n \n+namespace {\n+\n+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+} /* namespace */\n+\n+/**\n+ * \\enum CameraConfiguration::ColorSpaceFlag\n+ * \\brief Specify the behaviour of validateColorSpaces\n+ * \\var CameraConfiguration::ColorSpaceFlag::None\n+ * \\brief No extra validation of color spaces is required\n+ * \\var CameraConfiguration::ColorSpaceFlag::StreamsShareColorSpace\n+ * \\brief Non-raw output streams must share the same color space\n+ */\n+\n+/**\n+ * \\typedef CameraConfiguration::ColorSpaceFlags\n+ * \\brief A bitwise combination of ColorSpaceFlag values\n+ */\n+\n+/**\n+ * \\brief Check the color spaces requested for each stream\n+ * \\param[in] flags Flags to control the behaviour of this function\n+ *\n+ * This function performs certain consistency checks on the color spaces of\n+ * the streams and may adjust them so that:\n+ *\n+ * - Any raw streams have the Raw color space\n+ * - If the StreamsShareColorSpace flag is set, all output streams are forced\n+ * to share the same color space (this may be a constraint on some platforms).\n+ *\n+ * It is optional for a pipeline handler to use this function.\n+ *\n+ * \\return A CameraConfiguration::Status value that describes the validation\n+ * status.\n+ * \\retval CameraConfigutation::Adjusted The configuration has been adjusted\n+ * and is now valid. The color space of some or all of the streams may bave\n+ * benn changed. The caller shall check the color spaces carefully.\n+ * \\retval CameraConfiguration::Valid The configuration was already valid and\n+ * hasn't been adjusted.\n+ */\n+CameraConfiguration::Status CameraConfiguration::validateColorSpaces(ColorSpaceFlags flags)\n+{\n+\tStatus status = Valid;\n+\n+\t/*\n+\t * Set all raw streams to the Raw color space, and make a note of the largest\n+\t * non-raw stream with a defined color space (if there is one).\n+\t */\n+\tint index = -1;\n+\tfor (auto [i, cfg] : utils::enumerate(config_)) {\n+\t\tif (isRaw(cfg.pixelFormat) && cfg.colorSpace != ColorSpace::Raw) {\n+\t\t\tcfg.colorSpace = ColorSpace::Raw;\n+\t\t\tstatus = Adjusted;\n+\t\t} else if (cfg.colorSpace && (index == -1 || cfg.size > config_[i].size))\n+\t\t\tindex = i;\n+\t}\n+\n+\tif (index < 0 || !(flags & ColorSpaceFlag::StreamsShareColorSpace))\n+\t\treturn status;\n+\n+\t/* Make all output color spaces the same, if requested. */\n+\tfor (auto &cfg : config_) {\n+\t\tif (!isRaw(cfg.pixelFormat) &&\n+\t\t cfg.colorSpace != config_[index].colorSpace) {\n+\t\t\tcfg.colorSpace = config_[index].colorSpace;\n+\t\t\tstatus = Adjusted;\n+\t\t}\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", "v11", "7/8" ] }