Show a patch.

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

{
    "id": 14464,
    "url": "https://patchwork.libcamera.org/api/patches/14464/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/14464/",
    "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": "<20211104135805.5269-8-david.plowman@raspberrypi.com>",
    "date": "2021-11-04T13:58:05",
    "name": "[libcamera-devel,v5,7/7] libcamera: pipeline: raspberrypi: Support color spaces",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "8175190bc270caab83300662d1d3148d4cdab013",
    "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/14464/mbox/",
    "series": [
        {
            "id": 2691,
            "url": "https://patchwork.libcamera.org/api/series/2691/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2691",
            "date": "2021-11-04T13:57:58",
            "name": "Colour spaces",
            "version": 5,
            "mbox": "https://patchwork.libcamera.org/series/2691/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/14464/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/14464/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 A9C6FC324E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  4 Nov 2021 13:58:35 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6292660352;\n\tThu,  4 Nov 2021 14:58:35 +0100 (CET)",
            "from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com\n\t[IPv6:2a00:1450:4864:20::32f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4AFC36034F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Nov 2021 14:58:27 +0100 (CET)",
            "by mail-wm1-x32f.google.com with SMTP id\n\t67-20020a1c1946000000b0030d4c90fa87so4355036wmz.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 04 Nov 2021 06:58:27 -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\ti20sm2264736wmq.41.2021.11.04.06.58.26\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 04 Nov 2021 06:58:26 -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=\"NRF75VlA\"; 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=MWi8mj5S4W6cGhtr7B2BNpqXeeXBc2vqiVreCzJ+MGg=;\n\tb=NRF75VlAaoeHCI5komFAHp4swHbQny90tLbCh4pl+GDMbwQS1rc3MMrTVWypiul4VN\n\tfHD2+x53Jk4CaqoelioERZYNcakJpk1hOjJsK4TIxtOlH6wz0kE4hdlWnQqNs9hZip3U\n\tt7bKZf2WvZGVHAoKi0EO9xxzMdvADCNal2iKg0CCiCsbrXG4oaEmrUkseMX3evCi0/6V\n\tp0BIacveiIRCMr7BDmwBQ9h8AyeiNO40R/EbO+zB4Gk+caHGg/YlcyAbGg1vT7Wl/LBR\n\tbSs6pv72L3/6DE3qV2E0ODDiwM1y+LSVLFyKLLuB2ik8r3RzSNQ/wFb1vO/cfvf34z48\n\tNiKw==",
        "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=MWi8mj5S4W6cGhtr7B2BNpqXeeXBc2vqiVreCzJ+MGg=;\n\tb=AfOKoM0Xxd+V/f1b2rIZJMchzZhwndB4h9JLTpiGJs5vcgcgsOX8yeCkFGHFqJiQ0a\n\tddpn7RdUca2z559jSQz4bvOKXlFw2UL6CTIt4AF+JD+IgdtDn0dP3f8ZJ4fPBXs+PvSa\n\tB6xPctzzleIw6h08sE4dMfkvpFBfK1oH9HIvXIVUsJMxSZyXPc/YIMXnVef/XAYwGb9R\n\tEbRuSyF8qPK+Tz8N16shR2MCLiTiHXmfjLhd74bMTZ4/BAl7LpqrEb1GegzK7zNFYO+a\n\tKa6Wxc4V6vn1bzPhCyztg5ChHmm/nJX6y5PjHBCdks6KCrCLZRhlXuMxPKKQjZu+Z77m\n\tItXA==",
        "X-Gm-Message-State": "AOAM532N5Vb+ciXssYBPWOKHC99i1H/owzZhlJw9hDiIc+K/Q1oZBtZ8\n\tFCktBPXOFbXCNUVHyL+90U3fz16kNz+2Ug==",
        "X-Google-Smtp-Source": "ABdhPJy+rQao/v+ex3rNuP/WSTLIB7o4Q+Ann03LkpPS8XGYLgdYEkZRhW+znZP6UR5m8h8y70KQ1A==",
        "X-Received": "by 2002:a05:600c:210d:: with SMTP id\n\tu13mr23082571wml.82.1636034306844; \n\tThu, 04 Nov 2021 06:58:26 -0700 (PDT)",
        "From": "David Plowman <david.plowman@raspberrypi.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu,  4 Nov 2021 13:58:05 +0000",
        "Message-Id": "<20211104135805.5269-8-david.plowman@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.20.1",
        "In-Reply-To": "<20211104135805.5269-1-david.plowman@raspberrypi.com>",
        "References": "<20211104135805.5269-1-david.plowman@raspberrypi.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v5 7/7] libcamera: pipeline: raspberrypi:\n\tSupport color spaces",
        "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": "The Raspberry Pi pipeline handler now sets color spaces correctly.\n\nIn generateConfiguration() it sets them to reasonable default values\nbased on the stream role.\n\nvalidate() now calls validateColorSpaces() to ensure that the\nrequested color spaces are sensible, before proceeding to check what\nthe hardware can deliver.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n---\n .../pipeline/raspberrypi/raspberrypi.cpp      | 42 +++++++++++++++++++\n 1 file changed, 42 insertions(+)",
    "diff": "diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex 5e1f2273..bbb21e9b 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -93,6 +93,7 @@ V4L2DeviceFormat toV4L2DeviceFormat(const V4L2SubdeviceFormat &format,\n \n \tdeviceFormat.fourcc = V4L2PixelFormat::fromPixelFormat(pix);\n \tdeviceFormat.size = format.size;\n+\tdeviceFormat.colorSpace = format.colorSpace;\n \treturn deviceFormat;\n }\n \n@@ -126,6 +127,7 @@ V4L2SubdeviceFormat findBestFormat(const SensorFormats &formatsMap, const Size &\n {\n \tdouble bestScore = std::numeric_limits<double>::max(), score;\n \tV4L2SubdeviceFormat bestFormat;\n+\tbestFormat.colorSpace = ColorSpace::Raw;\n \n #define PENALTY_AR\t\t1500.0\n #define PENALTY_8BIT\t\t2000.0\n@@ -332,6 +334,8 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \tif (config_.empty())\n \t\treturn Invalid;\n \n+\tstatus = validateColorSpaces(true);\n+\n \t/*\n \t * What if the platform has a non-90 degree rotation? We can't even\n \t * \"adjust\" the configuration and carry on. Alternatively, raising an\n@@ -494,10 +498,21 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \t\tV4L2DeviceFormat format;\n \t\tformat.fourcc = V4L2PixelFormat::fromPixelFormat(cfg.pixelFormat);\n \t\tformat.size = cfg.size;\n+\t\tformat.colorSpace = cfg.requestedColorSpace;\n+\t\tLOG(RPI, Debug)\n+\t\t\t<< \"Try color space \" << cfg.requestedColorSpace.toString();\n \n \t\tint ret = dev->tryFormat(&format);\n \t\tif (ret)\n \t\t\treturn Invalid;\n+\t\tcfg.actualColorSpace = format.colorSpace;\n+\t\tif (cfg.actualColorSpace != cfg.requestedColorSpace) {\n+\t\t\tstatus = Adjusted;\n+\t\t\tLOG(RPI, Warning)\n+\t\t\t\t<< \"Color space changed from \"\n+\t\t\t\t<< cfg.requestedColorSpace.toString() << \" to \"\n+\t\t\t\t<< cfg.actualColorSpace.toString();\n+\t\t}\n \n \t\tcfg.stride = format.planes[0].bpl;\n \t\tcfg.frameSize = format.planes[0].size;\n@@ -522,6 +537,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n \tPixelFormat pixelFormat;\n \tV4L2VideoDevice::Formats fmts;\n \tSize size;\n+\tColorSpace colorSpace;\n \n \tif (roles.empty())\n \t\treturn config;\n@@ -536,6 +552,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n \t\t\tpixelFormat = mbusCodeToPixelFormat(sensorFormat.mbus_code,\n \t\t\t\t\t\t\t    BayerFormat::Packing::CSI2);\n \t\t\tASSERT(pixelFormat.isValid());\n+\t\t\tcolorSpace = ColorSpace::Raw;\n \t\t\tbufferCount = 2;\n \t\t\trawCount++;\n \t\t\tbreak;\n@@ -543,6 +560,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n \t\tcase StreamRole::StillCapture:\n \t\t\tfmts = data->isp_[Isp::Output0].dev()->formats();\n \t\t\tpixelFormat = formats::NV12;\n+\t\t\tcolorSpace = ColorSpace::Jpeg;\n \t\t\t/* Return the largest sensor resolution. */\n \t\t\tsize = data->sensor_->resolution();\n \t\t\tbufferCount = 1;\n@@ -560,6 +578,8 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n \t\t\t */\n \t\t\tfmts = data->isp_[Isp::Output0].dev()->formats();\n \t\t\tpixelFormat = formats::YUV420;\n+\t\t\t/* This will be reasonable for many applications. */\n+\t\t\tcolorSpace = ColorSpace::Rec709;\n \t\t\tsize = { 1920, 1080 };\n \t\t\tbufferCount = 4;\n \t\t\toutCount++;\n@@ -568,6 +588,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n \t\tcase StreamRole::Viewfinder:\n \t\t\tfmts = data->isp_[Isp::Output0].dev()->formats();\n \t\t\tpixelFormat = formats::ARGB8888;\n+\t\t\tcolorSpace = ColorSpace::Jpeg;\n \t\t\tsize = { 800, 600 };\n \t\t\tbufferCount = 4;\n \t\t\toutCount++;\n@@ -599,6 +620,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n \t\tStreamConfiguration cfg(formats);\n \t\tcfg.size = size;\n \t\tcfg.pixelFormat = pixelFormat;\n+\t\tcfg.requestedColorSpace = colorSpace;\n \t\tcfg.bufferCount = bufferCount;\n \t\tconfig->addConfiguration(cfg);\n \t}\n@@ -703,6 +725,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n \t\tV4L2PixelFormat fourcc = V4L2PixelFormat::fromPixelFormat(cfg.pixelFormat);\n \t\tformat.size = cfg.size;\n \t\tformat.fourcc = fourcc;\n+\t\tformat.colorSpace = cfg.requestedColorSpace;\n \n \t\tLOG(RPI, Debug) << \"Setting \" << stream->name() << \" to \"\n \t\t\t\t<< format.toString();\n@@ -718,6 +741,23 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n \t\t\treturn -EINVAL;\n \t\t}\n \n+\t\tif (cfg.actualColorSpace != format.colorSpace) {\n+\t\t\t/*\n+\t\t\t * We should have been through validate() before so this\n+\t\t\t * shouldn't be possible, but we mustn't sweep color space\n+\t\t\t * problems under the carpet.\n+\t\t\t */\n+\t\t\tLOG(RPI, Warning)\n+\t\t\t\t<< \"Unexpected color space change (\"\n+\t\t\t\t<< cfg.actualColorSpace.toString() << \" to \"\n+\t\t\t\t<< format.colorSpace.toString() << \") in stream \"\n+\t\t\t\t<< stream->name();\n+\t\t\tcfg.actualColorSpace = format.colorSpace;\n+\t\t}\n+\t\tLOG(RPI, Debug)\n+\t\t\t<< \"Stream \" << stream->name() << \" has color space \"\n+\t\t\t<< cfg.actualColorSpace.toString();\n+\n \t\tcfg.setStream(stream);\n \t\tstream->setExternal(true);\n \n@@ -742,6 +782,8 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n \t\tformat = {};\n \t\tformat.size = maxSize;\n \t\tformat.fourcc = V4L2PixelFormat::fromPixelFormat(formats::YUV420);\n+\t\t/* No one asked for output, so the color space doesn't matter. */\n+\t\tformat.colorSpace = ColorSpace::Jpeg;\n \t\tret = data->isp_[Isp::Output0].dev()->setFormat(&format);\n \t\tif (ret) {\n \t\t\tLOG(RPI, Error)\n",
    "prefixes": [
        "libcamera-devel",
        "v5",
        "7/7"
    ]
}