Show a patch.

GET /api/1.1/patches/18037/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 18037,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/18037/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/18037/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/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": "<20221216143344.8177-4-david.plowman@raspberrypi.com>",
    "date": "2022-12-16T14:33:44",
    "name": "[libcamera-devel,3/3] pipeline: raspberrypi: Fix colour spaces by handling missing YCbCr information",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "7efd9e53a23e34f1cafdd39357f7e7e170459f13",
    "submitter": {
        "id": 42,
        "url": "https://patchwork.libcamera.org/api/1.1/people/42/?format=api",
        "name": "David Plowman",
        "email": "david.plowman@raspberrypi.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/18037/mbox/",
    "series": [
        {
            "id": 3677,
            "url": "https://patchwork.libcamera.org/api/1.1/series/3677/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3677",
            "date": "2022-12-16T14:33:41",
            "name": "Fix colour spaces on Raspberry Pi",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/3677/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/18037/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/18037/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 7E57BC3200\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 16 Dec 2022 14:33:54 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 39A656339A;\n\tFri, 16 Dec 2022 15:33:54 +0100 (CET)",
            "from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com\n\t[IPv6:2a00:1450:4864:20::62f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1BFE96339E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 16 Dec 2022 15:33:50 +0100 (CET)",
            "by mail-ej1-x62f.google.com with SMTP id ud5so6616293ejc.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 16 Dec 2022 06:33:50 -0800 (PST)",
            "from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72])\n\tby smtp.gmail.com with ESMTPSA id\n\tmb4-20020a170906eb0400b0073dd8e5a39fsm907903ejb.156.2022.12.16.06.33.48\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 16 Dec 2022 06:33:49 -0800 (PST)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1671201234;\n\tbh=eV5HFJXm9Z1pBsbWQBHCKYlzvJ3p+++ZrVJAkvfDmMM=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=bwDHj70P89Zm21XseWXsIkxsCOF8M0cpsI5CaZ6I1Jgpsdun4bYF2u8QmFPPYZLjN\n\tlP19lyuFcSYCQA/J9NzYuKqZfVyN08WLgQ5/d+7VcuLoO99UKKCyKTmq35694jh5dR\n\tljrd2/XZrely19FL66yw++fc5ogZBlwPk4Yd8scA9lQ2Hj1kXh7xdvcxePlDvnYUqS\n\tx55Qk5VFj2EqP/A0Atxd8w7tEx4Xu7lITZM8IMwtrRdqRFtUv8eu5R9lx4OL35o1Pl\n\t9qKUBDIC4S3R++Aw4Oxd2g2TvBlmy8g3hY7LC+aTZTPlQ1TZh27ogOkfouU4u9QPat\n\tbaHje6mwFLZtw==",
            "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=r9aZV0AFWGsOMolbu6TRUsUyPIXMvru1Qfz14ROxvqE=;\n\tb=pY90ILlOIsGu9SXLESXbX2ysfwfTV3+WAlVwAMUlyPzhEz8QGlU8yIpvbTVyvhKSSj\n\tvIWMspRtVxCfc+st1UZCkwbFWmZXqXfPnprOLdE6fBvQdO0FLfRpzR6UfeDw5Mr5+Hw/\n\tbrqJeNRS3qCYpeAB8CYngCE9ZGZsd3x6fGJwo2RirjGCCu60DYLiKSrEaMVL4ui02DG6\n\t+P4CWuCwT5cZHSC4IcY/SxidNqKB7NqLfd1MtUba/XvNrjgYZ4rFTkVvxKARw4kbHKce\n\t06I602GwXqDpsU7p0LW3r3tuLDBYqsUU5eRkY7+Yded3IGYzDwJPm3f66uK+sb3CFwdO\n\tw0BA=="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"pY90ILlO\"; dkim-atps=neutral",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=r9aZV0AFWGsOMolbu6TRUsUyPIXMvru1Qfz14ROxvqE=;\n\tb=DHUDVJCah1O1K4JvbjqftvEg9/FWTwBLqD7sxVOEdStpgMufAM41zheTpkABRk+vlC\n\tDMrGucyhGBlY/oCOnX8UGPdii2Z87T/Qos+r7tEA9t80IByjJ18IxgL+ESDgo2QfMC3C\n\tIoWsUt7dWq3EDAubNQsW5hg6SNKn6fhYVCQThQlIx4tbcYakWYAiPykwSm4kIU2SvY2A\n\tKoa+SKzWp5h5p1rnjYueGZoe1GG38r00kWaY4gWDGDyh9YU3jPoeRy5oigzQIvvKpUFL\n\t6a9Ig4grn1goqstvOemq/1/x1VmpKrYZa0ljO5mnX0uBO0+SlkxqPgO9ZhzhrE5B9V9h\n\tAevw==",
        "X-Gm-Message-State": "ANoB5plcVXOuMGABer0cBKvskcYSw1yuqppdaKFXrAbQGGPZE4y2RmsL\n\tzLuk5jOcm7opu3tjIqn4b47HdNWc0CWEpmE5",
        "X-Google-Smtp-Source": "AA0mqf731Uq25b8P7xlNj4NDIiWE32/ANCnqC2xJVLchA9+6HYv6jmG6jl4tlQFNm/ABo6ErGk/pHg==",
        "X-Received": "by 2002:a17:906:4a9a:b0:7c1:2529:2760 with SMTP id\n\tx26-20020a1709064a9a00b007c125292760mr26778538eju.27.1671201229354; \n\tFri, 16 Dec 2022 06:33:49 -0800 (PST)",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri, 16 Dec 2022 14:33:44 +0000",
        "Message-Id": "<20221216143344.8177-4-david.plowman@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.30.2",
        "In-Reply-To": "<20221216143344.8177-1-david.plowman@raspberrypi.com>",
        "References": "<20221216143344.8177-1-david.plowman@raspberrypi.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 3/3] pipeline: raspberrypi: Fix colour\n\tspaces by handling missing YCbCr information",
        "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>",
        "From": "David Plowman via libcamera-devel <libcamera-devel@lists.libcamera.org>",
        "Reply-To": "David Plowman <david.plowman@raspberrypi.com>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "In this patch we fix up colour spaces by adding the YCbCr information\nthat is now not present for streams with an RGB output format. We need\nthis information so that colour spaces are translated into the V4L2\nones that the Raspberry Pi hardware drivers will interpret correctly.\n\nRelated to this, the YCbCr information is once again removed before\nthe actual colour space is returned to us, so we have to be more\ncareful about how we check that we got what we expected.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\n---\n .../pipeline/raspberrypi/raspberrypi.cpp      | 56 ++++++++++++++++++-\n 1 file changed, 54 insertions(+), 2 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex 8569df17..f2d10d2a 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -357,6 +357,39 @@ RPiCameraConfiguration::RPiCameraConfiguration(const RPiCameraData *data)\n {\n }\n \n+static const std::vector<ColorSpace> validColorSpaces = {\n+\tColorSpace::Sycc,\n+\tColorSpace::Smpte170m,\n+\tColorSpace::Rec709\n+};\n+\n+static std::optional<ColorSpace> fixColorSpace(const std::optional<ColorSpace> &colorSpace,\n+\t\t\t\t\t       CameraConfiguration::Status &status)\n+{\n+\tif (!colorSpace)\n+\t\treturn std::nullopt;\n+\n+\t/*\n+\t * We prefer to restore any YCbCr encoding and range information that may have been\n+\t * removed from RGB streams. This ensures the colour spaces will be converted correctly\n+\t * into the colour spaces that the drivers handle, namely V4L2_COLORSPACE_JPEG,\n+\t * V4L2_COLORSPACE_SMPTE170M and V4L2_COLORSPACE_REC709.\n+\t *\n+\t * Luckily, the primaries and transfer function are enough for us to deduce exactly which\n+\t * ColorSpace was originally intended.\n+\t */\n+\tfor (const auto &cs : validColorSpaces) {\n+\t\tif (colorSpace->primaries == cs.primaries &&\n+\t\t    colorSpace->transferFunction == cs.transferFunction)\n+\t\t\treturn cs;\n+\t}\n+\n+\t/* If nothing was matched, ask for sYCC. */\n+\tLOG(RPI, Debug) << \"No match for colour space \" << colorSpace->toString();\n+\tstatus = CameraConfiguration::Adjusted;\n+\treturn ColorSpace::Sycc;\n+}\n+\n CameraConfiguration::Status RPiCameraConfiguration::validate()\n {\n \tStatus status = Valid;\n@@ -533,7 +566,26 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \t\tV4L2DeviceFormat format;\n \t\tformat.fourcc = dev->toV4L2PixelFormat(cfg.pixelFormat);\n \t\tformat.size = cfg.size;\n-\t\tformat.colorSpace = cfg.colorSpace;\n+\t\t/*\n+\t\t * Make sure the colour space is the one we want converted for our drivers, with\n+\t\t * the YCbCr information restored. status will be set to Adjusted if we didn't\n+\t\t * like the input colour space.\n+\t\t */\n+\t\tformat.colorSpace = fixColorSpace(cfg.colorSpace, status);\n+\n+\t\t/*\n+\t\t * When it comes back, RGB streams will have had the YCbCr information\n+\t\t * overwritten again, so let's figure out what we really expect to be\n+\t\t * returned.\n+\t\t */\n+\t\tauto checkColorSpace = format.colorSpace;\n+\t\tif (checkColorSpace) {\n+\t\t\tconst PixelFormatInfo &info = PixelFormatInfo::info(cfg.pixelFormat);\n+\t\t\tif (info.colourEncoding == PixelFormatInfo::ColourEncodingRGB) {\n+\t\t\t\tcheckColorSpace->ycbcrEncoding = ColorSpace::YcbcrEncoding::None;\n+\t\t\t\tcheckColorSpace->range = ColorSpace::Range::Full;\n+\t\t\t}\n+\t\t}\n \n \t\tLOG(RPI, Debug)\n \t\t\t<< \"Try color space \" << ColorSpace::toString(cfg.colorSpace);\n@@ -542,7 +594,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \t\tif (ret)\n \t\t\treturn Invalid;\n \n-\t\tif (cfg.colorSpace != format.colorSpace) {\n+\t\tif (checkColorSpace != format.colorSpace) {\n \t\t\tstatus = Adjusted;\n \t\t\tLOG(RPI, Debug)\n \t\t\t\t<< \"Color space changed from \"\n",
    "prefixes": [
        "libcamera-devel",
        "3/3"
    ]
}