Show a patch.

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

{
    "id": 12756,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/12756/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/12756/",
    "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": "<20210701113442.111718-2-naush@raspberrypi.com>",
    "date": "2021-07-01T11:34:39",
    "name": "[libcamera-devel,v2,1/4] ipa: raspberrypi: Allow long exposure modes for imx477.",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "6ace0cfd032094c2e735ccd237e491544b552605",
    "submitter": {
        "id": 34,
        "url": "https://patchwork.libcamera.org/api/1.1/people/34/?format=api",
        "name": "Naushir Patuck",
        "email": "naush@raspberrypi.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/12756/mbox/",
    "series": [
        {
            "id": 2196,
            "url": "https://patchwork.libcamera.org/api/1.1/series/2196/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2196",
            "date": "2021-07-01T11:34:38",
            "name": "Raspberry Pi: Enable imx477 long exposure modes",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/2196/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/12756/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/12756/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 A8230C3222\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  1 Jul 2021 11:34:50 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 65A7B684F7;\n\tThu,  1 Jul 2021 13:34:49 +0200 (CEST)",
            "from mail-wr1-x433.google.com (mail-wr1-x433.google.com\n\t[IPv6:2a00:1450:4864:20::433])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B2A4D60289\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  1 Jul 2021 13:34:47 +0200 (CEST)",
            "by mail-wr1-x433.google.com with SMTP id u8so7755231wrq.8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 01 Jul 2021 04:34:47 -0700 (PDT)",
            "from naush-laptop.patuck.local ([88.97.76.4])\n\tby smtp.gmail.com with ESMTPSA id\n\tf6sm8076495wrs.13.2021.07.01.04.34.46\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 01 Jul 2021 04:34:46 -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=\"ZYgoJ0P6\"; 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=d/qzJ12HXMrt3litZ/q3bNli735+KJm88bJeUyFLX2k=;\n\tb=ZYgoJ0P6QDiBTL+SLgyePiJnuGTJJk8dTLLQcOHksuLuy3d063m1r8CazDfC0UMyhx\n\tv4kgElNcoih1dPFV/fYRtwUvTl/oeV4di0C8Ystp3+AH1/f2VrMRy/M6lCnALaGACq9c\n\tXYzNSWysJHimGulNYnhCFqTJnE4jqJCvMLibRJ7pXXJm84+rPsG+odTisJ81h3K1+VPp\n\trjKK8xO2WS9LgoYSHjkFoZpvv/jKIQnEnn52oC3+cg76i1W+QTjRCytW+lKOwDWuDduu\n\t7I6IIWKBrt8fbK4CVSGdOcUyKSWAz48XSFrOqQjM02drxVOqbtiBdNYDKeS3P+DxzfT5\n\t/FMg==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\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=d/qzJ12HXMrt3litZ/q3bNli735+KJm88bJeUyFLX2k=;\n\tb=KG0wd7HCnH5kVTbcNEOSAGKxQiTUUjKueq2lQoUgAsh3P64iUbbUPzelqX2vTjC1pB\n\tbf/kEz6+e4ROt5/DulsiBjtfGk991ARYbsOOwjLbAeDZqFg2cXwBd1OwuV6Wp8GY1ul7\n\tqW86RF6hj4/1kaB8CYskt0I64C7Z4RMndxOSK8i0pkZYC9DHHk8cl9qG1/UMjJp/Eqc5\n\tiucJDHSUoWxpHvR6jjzZHNuNuZHzPfjaVIdH5vJtNcKVN3i2JGQz28Wp9A13nYZdvFbo\n\tMxRoHrnftCpNwyBbBpU2rydH5yILl20XNGkHsqYwvY+vQCWaIM4Uk2/Y9kWC4eXTfA5a\n\t8X/g==",
        "X-Gm-Message-State": "AOAM532dpXKBK2rxXqHejsIPxNOe+g5lnvX+PRB+aIQ9smLu36qECUV8\n\tYZAVChsq3JQjjLtfHMN6o2Af+LnamBZJVg==",
        "X-Google-Smtp-Source": "ABdhPJydDGlEqPPNmFAt6WgPWEWSVAa4vW1YJXe+cOHBOZ+3erw6GPkPN6u1818vDOL7LLpP53+hpQ==",
        "X-Received": "by 2002:adf:f74c:: with SMTP id\n\tz12mr46159338wrp.18.1625139287314; \n\tThu, 01 Jul 2021 04:34:47 -0700 (PDT)",
        "From": "Naushir Patuck <naush@raspberrypi.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu,  1 Jul 2021 12:34:39 +0100",
        "Message-Id": "<20210701113442.111718-2-naush@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "<20210701113442.111718-1-naush@raspberrypi.com>",
        "References": "<20210701113442.111718-1-naush@raspberrypi.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 1/4] ipa: raspberrypi: Allow long\n\texposure modes for imx477.",
        "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": "Update the imx477 CamHelper to use long exposure modes if needed.\nThis is done by overloading the CamHelper::GetVBlanking function to return a\nframe length (and vblank value) computed using a scaling factor when the value\nwould be larger than what the sensor register could otherwise hold.\n\nCamHelperImx477::Prepare is also overloaded to ensure that the \"device.status\"\nmetadata returns the right value if the long exposure scaling factor is used.\nThe scaling factor is unfortunately not returned back in metadata.\n\nWith the current imx477 driver, we can achieve a maximum exposure time of approx\n127 seconds since the HBLANK control is read-only.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\n---\n src/ipa/raspberrypi/cam_helper_imx477.cpp | 69 +++++++++++++++++++++++\n 1 file changed, 69 insertions(+)",
    "diff": "diff --git a/src/ipa/raspberrypi/cam_helper_imx477.cpp b/src/ipa/raspberrypi/cam_helper_imx477.cpp\nindex 4098fde6f322..139cc7dbd39a 100644\n--- a/src/ipa/raspberrypi/cam_helper_imx477.cpp\n+++ b/src/ipa/raspberrypi/cam_helper_imx477.cpp\n@@ -6,6 +6,7 @@\n  */\n \n #include <assert.h>\n+#include <cmath>\n #include <stddef.h>\n #include <stdio.h>\n #include <stdlib.h>\n@@ -14,6 +15,7 @@\n #include \"md_parser.hpp\"\n \n using namespace RPiController;\n+using libcamera::utils::Duration;\n \n /*\n  * We care about two gain registers and a pair of exposure registers. Their\n@@ -31,6 +33,9 @@ public:\n \tCamHelperImx477();\n \tuint32_t GainCode(double gain) const override;\n \tdouble Gain(uint32_t gain_code) const override;\n+\tvoid Prepare(libcamera::Span<const uint8_t> buffer, Metadata &metadata) override;\n+\tuint32_t GetVBlanking(Duration &exposure, Duration minFrameDuration,\n+\t\t\t      Duration maxFrameDuration) const override;\n \tvoid GetDelays(int &exposure_delay, int &gain_delay,\n \t\t       int &vblank_delay) const override;\n \tbool SensorEmbeddedDataPresent() const override;\n@@ -41,6 +46,10 @@ private:\n \t * in units of lines.\n \t */\n \tstatic constexpr int frameIntegrationDiff = 22;\n+\t/* Maximum frame length allowable for long exposure calculations. */\n+\tstatic constexpr int frameLengthMax = 0xffdc;\n+\t/* Largest long exposure scale factor given as a left shift on the frame length. */\n+\tstatic constexpr int longExposureShiftMax = 7;\n \n \tvoid PopulateMetadata(const MdParser::RegisterMap &registers,\n \t\t\t      Metadata &metadata) const override;\n@@ -61,6 +70,66 @@ double CamHelperImx477::Gain(uint32_t gain_code) const\n \treturn 1024.0 / (1024 - gain_code);\n }\n \n+void CamHelperImx477::Prepare(libcamera::Span<const uint8_t> buffer, Metadata &metadata)\n+{\n+\tDeviceStatus deviceStatus, parsedStatus;\n+\n+\t/* Get the device status provided by DelayedControls */\n+\tif (metadata.Get(\"device.status\", deviceStatus) != 0)\n+\t\treturn;\n+\n+\t/* Get the device status provided by the embedded data buffer. */\n+\tCamHelper::parseEmbeddedData(buffer, metadata);\n+\tmetadata.Get(\"device.status\", parsedStatus);\n+\n+\t/*\n+\t * If the ratio of DelayedControls to embedded data shutter speed is > 1\n+\t * and is a factor of 2^N, then we can assume this is a long exposure mode\n+\t * frame. Since embedded data does not provide any hints of long exposure\n+\t * modes, make sure we use the DelayedControls values in the metadata.\n+\t * Otherwise, just go with the embedded data values.\n+\t */\n+\tunsigned long ratio = std::lround(deviceStatus.shutter_speed / parsedStatus.shutter_speed);\n+\tbool replace = (ratio > 1) && ((ratio & (~ratio + 1)) == ratio);\n+\n+\tif (replace)\n+\t\tmetadata.Set(\"device.status\", deviceStatus);\n+}\n+\n+uint32_t CamHelperImx477::GetVBlanking(Duration &exposure,\n+\t\t\t\t       Duration minFrameDuration,\n+\t\t\t\t       Duration maxFrameDuration) const\n+{\n+\tuint32_t frameLength, exposureLines;\n+\tunsigned int shift = 0;\n+\n+\tframeLength = mode_.height + CamHelper::GetVBlanking(exposure, minFrameDuration,\n+\t\t\t\t\t\t\t     maxFrameDuration);\n+\t/*\n+\t * Check if the frame length calculated needs to be setup for long\n+\t * exposure mode. This will require us to use a long exposure scale\n+\t * factor provided by a shift operation in the sensor.\n+\t */\n+\twhile (frameLength > frameLengthMax) {\n+\t\tif (++shift > longExposureShiftMax) {\n+\t\t\tshift = longExposureShiftMax;\n+\t\t\tframeLength = frameLengthMax;\n+\t\t\tbreak;\n+\t\t}\n+\t\tframeLength >>= 1;\n+\t}\n+\n+\tif (shift) {\n+\t\t/* Account for any rounding in the scaled frame length value. */\n+\t\tframeLength <<= shift;\n+\t\texposureLines = CamHelper::ExposureLines(exposure);\n+\t\texposureLines = std::min(exposureLines, frameLength - frameIntegrationDiff);\n+\t\texposure = CamHelper::Exposure(exposureLines);\n+\t}\n+\n+\treturn frameLength - mode_.height;\n+}\n+\n void CamHelperImx477::GetDelays(int &exposure_delay, int &gain_delay,\n \t\t\t\tint &vblank_delay) const\n {\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "1/4"
    ]
}