Patch Detail
Show a patch.
GET /api/patches/13951/?format=api
{ "id": 13951, "url": "https://patchwork.libcamera.org/api/patches/13951/?format=api", "web_url": "https://patchwork.libcamera.org/patch/13951/", "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": "<20210927123327.14554-2-david.plowman@raspberrypi.com>", "date": "2021-09-27T12:33:25", "name": "[libcamera-devel,v2,1/3] libcamera: Add ColorSpace class", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "ed1fe6c2f35d42c193ab9e8be202addbf174df97", "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/13951/mbox/", "series": [ { "id": 2574, "url": "https://patchwork.libcamera.org/api/series/2574/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2574", "date": "2021-09-27T12:33:24", "name": "Colour spaces", "version": 2, "mbox": "https://patchwork.libcamera.org/series/2574/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/13951/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/13951/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 32AACBDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 27 Sep 2021 12:33:36 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EA85769197;\n\tMon, 27 Sep 2021 14:33:35 +0200 (CEST)", "from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com\n\t[IPv6:2a00:1450:4864:20::42e])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E2B0E6918A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Sep 2021 14:33:32 +0200 (CEST)", "by mail-wr1-x42e.google.com with SMTP id v17so8250924wrv.9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Sep 2021 05:33:32 -0700 (PDT)", "from pi4-davidp.pitowers.org\n\t([2a00:1098:3142:14:1ce1:9965:4328:89c4])\n\tby smtp.gmail.com with ESMTPSA id\n\tr9sm16285110wru.2.2021.09.27.05.33.31\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 27 Sep 2021 05:33:31 -0700 (PDT)" ], "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=\"fKGmSx2w\"; 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=tmZBQE4orKD4XTYhvhaHMaOkQ+/79Rt9g3dMNGENyY0=;\n\tb=fKGmSx2wTs5HnfNGvUGfksD7LUrjfqFF7n13SX4FHIZP7N+uwQ39Kfr4MlUXPnA0cS\n\t4//eUUgv4hHteuioVa+fjkkVbYbAfdhRm250kOnT/WTpTnB39V6ZuNlwFkVQh9+KvcBm\n\tod1guBgtRphBt6Gny/pZjZrUnvuEUyqFSAmA/RyihbDt4uzyYamD9yf3zE16e/ciB6ya\n\teYdlWfGEIX8J/f1j7gSa2QwVUC7dfaLyCERUlL9b98JwHAFyAOeBmnbsiVktjU5tYI2t\n\t6ECWMi+TddG3z4J627avV0tiLuWQGjBlEfAQprWsy+KwMOpf7aZ1P4wx+F6Ote7YkUHO\n\tv3fw==", "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=tmZBQE4orKD4XTYhvhaHMaOkQ+/79Rt9g3dMNGENyY0=;\n\tb=F3WJVjNT9M5wB0aQky6ntqiFtesBz6zetQhuqG3xBrjWhnj4ZOpbeq3S5eoa9hR7XA\n\tNaNMsNNeku4PIZoN6omRhc/Q0lJz3pv8asmCuMok7IyGkCj8subO4gCvxqbRJjDm5SGc\n\tu2fDQ/dM7hQNHkl/Lehsss3dm484GmxtqQ3dUztfx4ONtApfiQhG5pM40ZBt5fYxuHlS\n\troysmy3FxWWsE/zYrgQXyNPvS3syHyf6PpyFZtbxZlcVUOLrBPHEHmCxEviyEqi5dmV1\n\teTH3M1aNh1IR7kUblGm8bSd4DiFqV56QaoM5r5903BE5aiWr/2/XE4UmfkHReE/z1wXw\n\tNuzw==", "X-Gm-Message-State": "AOAM531xGXflvtNvOH+uZCiyGm/jTKCSVlF3ZkPMEnkVi08xB0I6eltu\n\tIFYpdrGfp5V8tfo60X9Zz7G39Fgm3R/7HkXM", "X-Google-Smtp-Source": "ABdhPJymWdPSaGlm+hqlWL30GVRgnDqYwovZlEBSjFU6/UcDrmbDbvt7wkknGXsFz7fG8gwtZbqcuQ==", "X-Received": "by 2002:a05:6000:124f:: with SMTP id\n\tj15mr4444113wrx.366.1632746012205; \n\tMon, 27 Sep 2021 05:33:32 -0700 (PDT)", "From": "David Plowman <david.plowman@raspberrypi.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 27 Sep 2021 13:33:25 +0100", "Message-Id": "<20210927123327.14554-2-david.plowman@raspberrypi.com>", "X-Mailer": "git-send-email 2.20.1", "In-Reply-To": "<20210927123327.14554-1-david.plowman@raspberrypi.com>", "References": "<20210927123327.14554-1-david.plowman@raspberrypi.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 1/3] libcamera: Add ColorSpace 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 class represents a colour space by defining its YCbCr encoding,\nthe transfer (gamma) function is uses, and whether the output is full\nor limited range.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\n---\n include/libcamera/color_space.h | 83 +++++++++++++\n include/libcamera/meson.build | 1 +\n src/libcamera/color_space.cpp | 207 ++++++++++++++++++++++++++++++++\n src/libcamera/meson.build | 1 +\n 4 files changed, 292 insertions(+)\n create mode 100644 include/libcamera/color_space.h\n create mode 100644 src/libcamera/color_space.cpp", "diff": "diff --git a/include/libcamera/color_space.h b/include/libcamera/color_space.h\nnew file mode 100644\nindex 00000000..9cd10503\n--- /dev/null\n+++ b/include/libcamera/color_space.h\n@@ -0,0 +1,83 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Raspberry Pi (Trading) Limited\n+ *\n+ * color_space.h - color space definitions\n+ */\n+\n+#ifndef __LIBCAMERA_COLOR_SPACE_H__\n+#define __LIBCAMERA_COLOR_SPACE_H__\n+\n+#include <string>\n+\n+namespace libcamera {\n+\n+class ColorSpace\n+{\n+public:\n+\tenum class Encoding : int {\n+\t\tUNDEFINED,\n+\t\tRAW,\n+\t\tREC601,\n+\t\tREC709,\n+\t\tREC2020,\n+\t\tVIDEO,\n+\t};\n+\n+\tenum class TransferFunction : int {\n+\t\tUNDEFINED,\n+\t\tIDENTITY,\n+\t\tSRGB,\n+\t\tREC709,\n+\t};\n+\n+\tenum class Range : int {\n+\t\tUNDEFINED,\n+\t\tFULL,\n+\t\tLIMITED,\n+\t};\n+\n+\tconstexpr ColorSpace(Encoding e, TransferFunction t, Range r)\n+\t\t: encoding(e), transferFunction(t), range(r)\n+\t{\n+\t}\n+\n+\tconstexpr ColorSpace()\n+\t\t: ColorSpace(Encoding::UNDEFINED, TransferFunction::UNDEFINED, Range::UNDEFINED)\n+\t{\n+\t}\n+\n+\tstatic const ColorSpace UNDEFINED;\n+\tstatic const ColorSpace RAW;\n+\tstatic const ColorSpace JFIF;\n+\tstatic const ColorSpace SMPTE170M;\n+\tstatic const ColorSpace REC709;\n+\tstatic const ColorSpace REC2020;\n+\tstatic const ColorSpace VIDEO;\n+\n+\tEncoding encoding;\n+\tTransferFunction transferFunction;\n+\tRange range;\n+\n+\tbool isFullyDefined() const;\n+\n+\tconst std::string toString() const;\n+};\n+\n+constexpr ColorSpace ColorSpace::UNDEFINED = { Encoding::UNDEFINED, TransferFunction::UNDEFINED, Range::UNDEFINED };\n+constexpr ColorSpace ColorSpace::RAW = { Encoding::RAW, TransferFunction::IDENTITY, Range::FULL };\n+constexpr ColorSpace ColorSpace::JFIF = { Encoding::REC601, TransferFunction::SRGB, Range::FULL };\n+constexpr ColorSpace ColorSpace::SMPTE170M = { Encoding::REC601, TransferFunction::REC709, Range::LIMITED };\n+constexpr ColorSpace ColorSpace::REC709 = { Encoding::REC709, TransferFunction::REC709, Range::LIMITED };\n+constexpr ColorSpace ColorSpace::REC2020 = { Encoding::REC2020, TransferFunction::REC709, Range::LIMITED };\n+constexpr ColorSpace ColorSpace::VIDEO = { Encoding::VIDEO, TransferFunction::REC709, Range::LIMITED };\n+\n+bool operator==(const ColorSpace &lhs, const ColorSpace &rhs);\n+static inline bool operator!=(const ColorSpace &lhs, const ColorSpace &rhs)\n+{\n+\treturn !(lhs == rhs);\n+}\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_COLOR_SPACE_H__ */\ndiff --git a/include/libcamera/meson.build b/include/libcamera/meson.build\nindex 5b25ef84..7a8a04e5 100644\n--- a/include/libcamera/meson.build\n+++ b/include/libcamera/meson.build\n@@ -3,6 +3,7 @@\n libcamera_public_headers = files([\n 'camera.h',\n 'camera_manager.h',\n+ 'color_space.h',\n 'compiler.h',\n 'controls.h',\n 'file_descriptor.h',\ndiff --git a/src/libcamera/color_space.cpp b/src/libcamera/color_space.cpp\nnew file mode 100644\nindex 00000000..d1ccb4cc\n--- /dev/null\n+++ b/src/libcamera/color_space.cpp\n@@ -0,0 +1,207 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Raspberry Pi (Trading) Limited\n+ *\n+ * color_space.cpp - color spaces.\n+ */\n+\n+#include <sstream>\n+\n+#include <libcamera/color_space.h>\n+\n+/**\n+ * \\file color_space.h\n+ * \\brief Class and enums to represent colour spaces.\n+ */\n+\n+namespace libcamera {\n+\n+/**\n+ * \\class ColorSpace\n+ * \\brief Class to describe a color space.\n+ *\n+ * The color space class defines the encodings of the color primaries, the\n+ * transfer function associated with the color space, and the range (sometimes\n+ * also referred to as the quantisation) of the color space.\n+ *\n+ * Certain combinations of these fields form well-known standard color spaces,\n+ * such as \"JFIF\" or \"REC709\", though there is flexibility to leave some or all\n+ * of them undefined too.\n+ */\n+\n+/**\n+ * \\enum ColorSpace::Encoding\n+ * \\brief The encoding used for the color primaries.\n+ *\n+ * \\var ColorSpace::Encoding::UNDEFINED\n+ * \\brief The encoding for the colour primaries is not specified.\n+ * \\var ColorSpace::Encoding::RAW\n+ * \\brief These are raw colours from the sensor.\n+ * \\var ColorSpace::Encoding::REC601\n+ * \\brief REC601 colour primaries.\n+ * \\var ColorSpace::Encoding::REC709\n+ * \\brief Rec709 colour primaries.\n+ * \\var ColorSpace::Encoding::REC2020\n+ * \\brief REC2020 colour primaries.\n+ * \\var ColorSpace::Encoding::VIDEO\n+ * \\brief A place-holder for video streams which will be resolved to one\n+ * of REC601, REC709 or REC2020 once the video resolution is known.\n+ */\n+\n+/**\n+ * \\enum ColorSpace::TransferFunction\n+ * \\brief The transfer function used for this colour space.\n+ *\n+ * \\var ColorSpace::TransferFunction::UNDEFINED\n+ * \\brief The transfer function is not specified.\n+ * \\var ColorSpace::TransferFunction::IDENTITY\n+ * \\brief This color space uses an identity transfer function.\n+ * \\var ColorSpace::TransferFunction::SRGB\n+ * \\brief sRGB transfer function.\n+ * \\var ColorSpace::TransferFunction::REC709\n+ * \\brief Rec709 transfer function.\n+ */\n+\n+/**\n+ * \\enum ColorSpace::Range\n+ * \\brief The range (sometimes \"quantisation\") for this color space.\n+ *\n+ * \\var ColorSpace::Range::UNDEFINED\n+ * \\brief The range is not specified.\n+ * \\var ColorSpace::Range::FULL\n+ * \\brief This color space uses full range pixel values.\n+ * \\var ColorSpace::Range::LIMITED\n+ * \\brief This color space uses limited range pixel values.\n+ */\n+\n+/**\n+ * \\fn ColorSpace::ColorSpace(Encoding e, TransferFunction t, Range r)\n+ * \\brief Construct a ColorSpace from explicit values\n+ * \\param[in] e The encoding for the color primaries\n+ * \\param[in] t The transfer function for the color space\n+ * \\param[in] r The range of the pixel values in this color space\n+ */\n+\n+/**\n+ * \\fn ColorSpace::ColorSpace()\n+ * \\brief Construct a color space with undefined encoding, transfer function\n+ * and range\n+ */\n+\n+/**\n+ * \\brief Return true if all the fields of the color space are defined, otherwise false.\n+ */\n+bool ColorSpace::isFullyDefined() const\n+{\n+\treturn encoding != Encoding::UNDEFINED &&\n+\t transferFunction != TransferFunction::UNDEFINED &&\n+\t range != Range::UNDEFINED;\n+}\n+\n+/**\n+ * \\brief Assemble and return a readable string representation of the\n+ * ColorSpace\n+ * \\return A string describing the ColorSpace\n+ */\n+const std::string ColorSpace::toString() const\n+{\n+\tstatic const char *encodings[] = {\n+\t\t\"UNDEFINED\",\n+\t\t\"RAW\",\n+\t\t\"REC601\",\n+\t\t\"REC709\",\n+\t\t\"REC2020\",\n+\t};\n+\tstatic const char *transferFunctions[] = {\n+\t\t\"UNDEFINED\",\n+\t\t\"IDENTITY\",\n+\t\t\"SRGB\",\n+\t\t\"REC709\",\n+\t};\n+\tstatic const char *ranges[] = {\n+\t\t\"UNDEFINED\",\n+\t\t\"FULL\",\n+\t\t\"LIMITED\",\n+\t};\n+\n+\tstd::stringstream ss;\n+\tss << std::string(encodings[static_cast<int>(encoding)]) << \"+\"\n+\t << std::string(transferFunctions[static_cast<int>(transferFunction)]) << \"+\"\n+\t << std::string(ranges[static_cast<int>(range)]);\n+\n+\treturn ss.str();\n+}\n+\n+/**\n+ * \\var ColorSpace::encoding\n+ * \\brief The encoding of the color primaries\n+ */\n+\n+/**\n+ * \\var ColorSpace::transferFunction\n+ * \\brief The transfer function for this color space.\n+ */\n+\n+/**\n+ * \\var ColorSpace::range\n+ * \\brief The pixel range used by this color space.\n+ */\n+\n+/**\n+ * \\var ColorSpace::UNDEFINED\n+ * \\brief A constant representing a fully undefined color space.\n+ */\n+\n+/**\n+ * \\var ColorSpace::RAW\n+ * \\brief A constant representing a raw color space (from a sensor).\n+ */\n+\n+/**\n+ * \\var ColorSpace::JFIF\n+ * \\brief A constant representing the JFIF color space usually used for\n+ * encoding JPEG images.\n+ */\n+\n+/**\n+ * \\var ColorSpace::SMPTE170M\n+ * \\brief A constant representing the SMPTE170M color space (sometimes also\n+ * referred to as \"full range BT601\").\n+ */\n+\n+/**\n+ * \\var ColorSpace::REC709\n+ * \\brief A constant representing the REC709 color space.\n+ */\n+\n+/**\n+ * \\var ColorSpace::REC2020\n+ * \\brief A constant representing the REC2020 color space.\n+ */\n+\n+/**\n+ * \\var ColorSpace::VIDEO\n+ * \\brief A constant that video streams can use to indicate the \"default\"\n+ * color space for a video of this resolution, once that is is known. For\n+ * exmample, SD streams would interpret this as SMPTE170M, HD streams as\n+ * REC709 and ultra HD as REC2020.\n+ */\n+\n+/**\n+ * \\brief Compare color spaces for equality\n+ * \\return True if the two color spaces are identical, false otherwise\n+ */\n+bool operator==(const ColorSpace &lhs, const ColorSpace &rhs)\n+{\n+\treturn lhs.encoding == rhs.encoding &&\n+\t lhs.transferFunction == rhs.transferFunction &&\n+\t lhs.range == rhs.range;\n+}\n+\n+/**\n+ * \\fn bool operator!=(const ColorSpace &lhs, const ColorSpace &rhs)\n+ * \\brief Compare color spaces for inequality\n+ * \\return True if the two color spaces are not identical, false otherwise\n+ */\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex bf82d38b..88dfbf24 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -8,6 +8,7 @@ libcamera_sources = files([\n 'camera_manager.cpp',\n 'camera_sensor.cpp',\n 'camera_sensor_properties.cpp',\n+ 'color_space.cpp',\n 'controls.cpp',\n 'control_serializer.cpp',\n 'control_validator.cpp',\n", "prefixes": [ "libcamera-devel", "v2", "1/3" ] }