Show a patch.

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

{
    "id": 14959,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/14959/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/14959/",
    "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": "<20211201134048.6363-1-david.plowman@raspberrypi.com>",
    "date": "2021-12-01T13:40:48",
    "name": "[libcamera-devel,v3] pipeline: raspberrypi: Choose bit depth and packing according to raw stream",
    "commit_ref": "b7b72027a07521bd6e1104a32cb50169aa29a58e",
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "11bdaaca8c7d1d8ea2003ca5ec10d20a71905f07",
    "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/14959/mbox/",
    "series": [
        {
            "id": 2794,
            "url": "https://patchwork.libcamera.org/api/1.1/series/2794/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2794",
            "date": "2021-12-01T13:40:48",
            "name": "[libcamera-devel,v3] pipeline: raspberrypi: Choose bit depth and packing according to raw stream",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/2794/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/14959/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/14959/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 46CEABF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  1 Dec 2021 13:41:07 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A489C60724;\n\tWed,  1 Dec 2021 14:41:06 +0100 (CET)",
            "from mail-wr1-x429.google.com (mail-wr1-x429.google.com\n\t[IPv6:2a00:1450:4864:20::429])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B56046011A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  1 Dec 2021 14:41:05 +0100 (CET)",
            "by mail-wr1-x429.google.com with SMTP id j3so52381641wrp.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 01 Dec 2021 05:41:05 -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\ta10sm1101384wmq.27.2021.12.01.05.41.04\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 01 Dec 2021 05:41:04 -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=\"ZPg/9Muh\"; 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=+J0tALPcVr3JUOjWtvfRYLeV/hJN8luGThVPxsycQRU=;\n\tb=ZPg/9MuhDEesGSD4+0SmuiAxwywxZI79gzQrD1XBIWlqUx7ZHQjM2pOZ0lesX0kLWQ\n\tahfPRC5KpFKZzJuSiIhJWgSX0GOcZHgVcPN5GMpLbUQnWAjfWsV0MY5Ho9BW5NR2IPUv\n\t8OHr44PtwPdEU0CwKQbG8olKsyjxHz9mvpahKlQjvgTAOlmzzHRU2LY7xloHgcp9+mvM\n\tvPWxx7UrtGdQnDein0jTjzl9aV28TnzPBN5ZLEki3UVoiFJZagLawrunvNaFTppZa8F4\n\tAkGqou3oAElaJNR5QQh4YdlACaXihvT9O3K1XcV6VkBT/3wUvzCY5b44YO4s3YGhOteN\n\tamGQ==",
        "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=+J0tALPcVr3JUOjWtvfRYLeV/hJN8luGThVPxsycQRU=;\n\tb=H6uCYsw+DDaDcn5Pea9Bbm01TnY6df6/P4ocyENJcjFYj6v4k6jzfYNDRoBRZaBypG\n\thxMItxttOaN4xIEcRgBhPobycWhHL5VcTEc0k+wJTPNxVuTS19QecNzhgYI7id1NaniH\n\tz5I/wvFjKViyOH4ljlB/n2NocDbLIilepGDygX42j/CqcMz0pgGbewKqgMaMDsr54Av8\n\tdine/JunUhTfScOwPkCUe7SJdrzcFahsg6K+93tU49gzJIPhnsXkBCHvxhp1DgDbuqnN\n\tyGIXQLxIV82n04enPPmhzDtmRcTHfERyZtXv7LPKabRqOFFg3prD01Cx3EK0sYElu7d8\n\t8TZA==",
        "X-Gm-Message-State": "AOAM532SCkkZVxaaL5NPp6U35BLTeTra9IYFakoUZRTdx9rpx+ZLAeEa\n\tiIsqeH/T6xcjuumRiUCqSTbeLX/QwgRypiB5",
        "X-Google-Smtp-Source": "ABdhPJx+HRc6tGiM/8MF7VPSZY3T2cRQhSFBqh/N7iEACul4eJ+RaMTiGw8BwVJvGt8pa+GfkJk/Sw==",
        "X-Received": "by 2002:adf:fb0c:: with SMTP id\n\tc12mr7323368wrr.614.1638366065138; \n\tWed, 01 Dec 2021 05:41:05 -0800 (PST)",
        "From": "David Plowman <david.plowman@raspberrypi.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Wed,  1 Dec 2021 13:40:48 +0000",
        "Message-Id": "<20211201134048.6363-1-david.plowman@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.30.2",
        "In-Reply-To": "<20211201101508.10619-3-david.plowman@raspberrypi.com>",
        "References": "<20211201101508.10619-3-david.plowman@raspberrypi.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v3] pipeline: raspberrypi: Choose bit\n\tdepth and packing according to raw stream",
        "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": "When a raw stream is specified, the bit depth and packing requested\nshould influence our choice of camera mode to match (if possible).\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n---\n .../pipeline/raspberrypi/raspberrypi.cpp      | 38 ++++++++++---------\n 1 file changed, 21 insertions(+), 17 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex 045725dd..7f387626 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -6,6 +6,7 @@\n  */\n #include <algorithm>\n #include <assert.h>\n+#include <cmath>\n #include <fcntl.h>\n #include <memory>\n #include <mutex>\n@@ -49,6 +50,8 @@ LOG_DEFINE_CATEGORY(RPI)\n \n namespace {\n \n+constexpr unsigned int defaultRawBitDepth = 12;\n+\n /* Map of mbus codes to supported sizes reported by the sensor. */\n using SensorFormats = std::map<unsigned int, std::vector<Size>>;\n \n@@ -125,15 +128,13 @@ double scoreFormat(double desired, double actual)\n \treturn score;\n }\n \n-V4L2SubdeviceFormat findBestFormat(const SensorFormats &formatsMap, const Size &req)\n+V4L2SubdeviceFormat findBestFormat(const SensorFormats &formatsMap, const Size &req, unsigned int bitDepth)\n {\n \tdouble bestScore = std::numeric_limits<double>::max(), score;\n \tV4L2SubdeviceFormat bestFormat;\n \n-#define PENALTY_AR\t\t1500.0\n-#define PENALTY_8BIT\t\t2000.0\n-#define PENALTY_10BIT\t\t1000.0\n-#define PENALTY_12BIT\t\t   0.0\n+\tconstexpr float penaltyAr = 1500.0;\n+\tconstexpr float penaltyBitDepth = 500.0;\n \n \t/* Calculate the closest/best mode from the user requested size. */\n \tfor (const auto &iter : formatsMap) {\n@@ -149,15 +150,10 @@ V4L2SubdeviceFormat findBestFormat(const SensorFormats &formatsMap, const Size &\n \t\t\t/* Score the dimensions for closeness. */\n \t\t\tscore = scoreFormat(req.width, size.width);\n \t\t\tscore += scoreFormat(req.height, size.height);\n-\t\t\tscore += PENALTY_AR * scoreFormat(reqAr, fmtAr);\n+\t\t\tscore += penaltyAr * scoreFormat(reqAr, fmtAr);\n \n \t\t\t/* Add any penalties... this is not an exact science! */\n-\t\t\tif (info.bitsPerPixel == 12)\n-\t\t\t\tscore += PENALTY_12BIT;\n-\t\t\telse if (info.bitsPerPixel == 10)\n-\t\t\t\tscore += PENALTY_10BIT;\n-\t\t\telse if (info.bitsPerPixel == 8)\n-\t\t\t\tscore += PENALTY_8BIT;\n+\t\t\tscore += std::abs(static_cast<int>(info.bitsPerPixel - bitDepth)) * penaltyBitDepth;\n \n \t\t\tif (score <= bestScore) {\n \t\t\t\tbestScore = score;\n@@ -397,9 +393,14 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \t\t\t * Calculate the best sensor mode we can use based on\n \t\t\t * the user request.\n \t\t\t */\n-\t\t\tV4L2SubdeviceFormat sensorFormat = findBestFormat(data_->sensorFormats_, cfg.size);\n+\t\t\tconst PixelFormatInfo &info = PixelFormatInfo::info(cfg.pixelFormat);\n+\t\t\tunsigned int bitDepth = info.isValid() ? info.bitsPerPixel : defaultRawBitDepth;\n+\t\t\tV4L2SubdeviceFormat sensorFormat = findBestFormat(data_->sensorFormats_, cfg.size, bitDepth);\n+\t\t\tBayerFormat::Packing packing = BayerFormat::Packing::CSI2;\n+\t\t\tif (info.isValid() && !info.packed)\n+\t\t\t\tpacking = BayerFormat::Packing::None;\n \t\t\tV4L2DeviceFormat unicamFormat = toV4L2DeviceFormat(sensorFormat,\n-\t\t\t\t\t\t\t\t\t   BayerFormat::Packing::CSI2);\n+\t\t\t\t\t\t\t\t\t   packing);\n \t\t\tint ret = data_->unicam_[Unicam::Image].dev()->tryFormat(&unicamFormat);\n \t\t\tif (ret)\n \t\t\t\treturn Invalid;\n@@ -533,7 +534,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n \t\tswitch (role) {\n \t\tcase StreamRole::Raw:\n \t\t\tsize = data->sensor_->resolution();\n-\t\t\tsensorFormat = findBestFormat(data->sensorFormats_, size);\n+\t\t\tsensorFormat = findBestFormat(data->sensorFormats_, size, defaultRawBitDepth);\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@@ -622,6 +623,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n \tSize maxSize, sensorSize;\n \tunsigned int maxIndex = 0;\n \tbool rawStream = false;\n+\tunsigned int bitDepth = defaultRawBitDepth;\n \n \t/*\n \t * Look for the RAW stream (if given) size as well as the largest\n@@ -638,7 +640,9 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n \t\t\tsensorSize = cfg.size;\n \t\t\trawStream = true;\n \t\t\t/* Check if the user has explicitly set an unpacked format. */\n-\t\t\tpacking = BayerFormat::fromPixelFormat(cfg.pixelFormat).packing;\n+\t\t\tBayerFormat bayerFormat = BayerFormat::fromPixelFormat(cfg.pixelFormat);\n+\t\t\tpacking = bayerFormat.packing;\n+\t\t\tbitDepth = bayerFormat.bitDepth;\n \t\t} else {\n \t\t\tif (cfg.size > maxSize) {\n \t\t\t\tmaxSize = config->at(i).size;\n@@ -664,7 +668,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n \t}\n \n \t/* First calculate the best sensor mode we can use based on the user request. */\n-\tV4L2SubdeviceFormat sensorFormat = findBestFormat(data->sensorFormats_, rawStream ? sensorSize : maxSize);\n+\tV4L2SubdeviceFormat sensorFormat = findBestFormat(data->sensorFormats_, rawStream ? sensorSize : maxSize, bitDepth);\n \tret = data->sensor_->setFormat(&sensorFormat);\n \tif (ret)\n \t\treturn ret;\n",
    "prefixes": [
        "libcamera-devel",
        "v3"
    ]
}