Show a patch.

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

{
    "id": 8554,
    "url": "https://patchwork.libcamera.org/api/patches/8554/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/8554/",
    "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": "<20200702105337.31161-3-david.plowman@raspberrypi.com>",
    "date": "2020-07-02T10:53:37",
    "name": "[libcamera-devel,2/2] libcamera: raspberrypi: Implement digital zoom",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "6336f3e6588383c5241df09818841097c2e91f48",
    "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/8554/mbox/",
    "series": [
        {
            "id": 1072,
            "url": "https://patchwork.libcamera.org/api/series/1072/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1072",
            "date": "2020-07-02T10:53:35",
            "name": "Digital zoom implementation",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/1072/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/8554/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/8554/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 BEE69BE905\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  2 Jul 2020 10:53:45 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 88FA160C55;\n\tThu,  2 Jul 2020 12:53:45 +0200 (CEST)",
            "from mail-wr1-x443.google.com (mail-wr1-x443.google.com\n\t[IPv6:2a00:1450:4864:20::443])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7D4AF60C58\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  2 Jul 2020 12:53:43 +0200 (CEST)",
            "by mail-wr1-x443.google.com with SMTP id h5so27594730wrc.7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 02 Jul 2020 03:53:43 -0700 (PDT)",
            "from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72])\n\tby smtp.gmail.com with ESMTPSA id\n\tp25sm9768444wmg.39.2020.07.02.03.53.42\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 02 Jul 2020 03:53:42 -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=\"DBh2mNrc\"; 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=gkLgitQJ/2bvHDpVFnNbn5whUaq3pqiy9fByQxOHyHI=;\n\tb=DBh2mNrc9goErsH8FPd6zRbhI/wGQGAfjfR1x3ZPASaZirpon1OJ2PgdknqSRPY2a1\n\tQkUyzq5K0R4iy9XAfTEJ39lnPAWYFQi7wMkHpsmX2+Xp2JfeTAWhRoVGU6eWQJo8JJOB\n\tHWr1aMM1yc0EZz81ZGYl5s2iNDOylibMeSnn3r7Vl1Ww+pHC5qcOVEXUX0KsVA2uMOhh\n\tTHh5kfoXkeE20sof3gvEth0RkHX0W9/O2pV6e+Kra97rjjAhh1zZ5h/sKjfbPj3F6QnW\n\tGNdJumD4tjliJeR5vqVvl5SOX6i67UnRzhU0h0nllG4FsUhfJ8PtKKQrzB8GLACSmws6\n\tQezw==",
        "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=gkLgitQJ/2bvHDpVFnNbn5whUaq3pqiy9fByQxOHyHI=;\n\tb=igB4MScdSPBykrgqX6g0X1+jAZYguITcBty4JqIOG2vONZLofhT/SBKBkvZc/DrfIm\n\tvJ9HS+69m1gCKUo3o0G8DrkwXvguNJhlhiLZdTSZiyCqWcSPrMe8M85oLPhWJ8uu1+FU\n\t2zux8b+CyMtY6jApig+x18q1T1HGYjS9tfCAJUmxzF3Yvmd8/KuQyBjA+F8ahib2F9Qo\n\tfL/hBwaiSm891ig+wXdTBlWZk5BN7OetVcm7CR/tdH8xngMSmKaOrVzP009yVzOdaruF\n\t5H9yYMJbQv0qsjsxhuyGM4a1bwgJRiisM0e51SYEPUyPJJvF9oJ3lAYRgTY7yIgylfaA\n\tYl1w==",
        "X-Gm-Message-State": "AOAM530ma5Pfw1sGaSFT7P9sUQ0pZNLzUlL5QvyDAoIRv+LtTbvPRFHg\n\tLsbCIRnLwW65icr5nACIkcyNT39Ci84=",
        "X-Google-Smtp-Source": "ABdhPJzB0S8MwvFc44jm57Zbn4Itz4bWBvPecTjpSyAJJe6YqfPxu3+GfHWtfRwqjF8gF/TLZ0UVFw==",
        "X-Received": "by 2002:adf:f10a:: with SMTP id r10mr649815wro.406.1593687222845;\n\tThu, 02 Jul 2020 03:53:42 -0700 (PDT)",
        "From": "David Plowman <david.plowman@raspberrypi.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu,  2 Jul 2020 11:53:37 +0100",
        "Message-Id": "<20200702105337.31161-3-david.plowman@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.20.1",
        "In-Reply-To": "<20200702105337.31161-1-david.plowman@raspberrypi.com>",
        "References": "<20200702105337.31161-1-david.plowman@raspberrypi.com>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH 2/2] libcamera: raspberrypi: Implement\n\tdigital zoom",
        "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>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "These changes implement digital zoom for the Raspberry Pi. We detect\nthe digital zoom control and update the V4L2 \"selection\" before\nstarting the ISP.\n\nLibcamera metadata is always filled in by the IPAs, so we intercept it\nwhen it comes back to the pipeline handler and update the digital zoom\nregion with the rectangle that we actually used.\n---\n include/libcamera/ipa/raspberrypi.h           |  1 +\n src/ipa/raspberrypi/raspberrypi.cpp           | 10 ++++\n .../pipeline/raspberrypi/raspberrypi.cpp      | 59 +++++++++++++++++++\n 3 files changed, 70 insertions(+)",
    "diff": "diff --git a/include/libcamera/ipa/raspberrypi.h b/include/libcamera/ipa/raspberrypi.h\nindex a18ce9a..e66402e 100644\n--- a/include/libcamera/ipa/raspberrypi.h\n+++ b/include/libcamera/ipa/raspberrypi.h\n@@ -52,6 +52,7 @@ static const ControlInfoMap RPiControls = {\n \t{ &controls::Contrast, ControlInfo(0.0f, 32.0f) },\n \t{ &controls::Saturation, ControlInfo(0.0f, 32.0f) },\n \t{ &controls::Sharpness, ControlInfo(0.0f, 16.0f, 1.0f) },\n+\t{ &controls::DigitalZoom, ControlInfo(Rectangle{ 0, 0, 0, 0 }, Rectangle{ 65535, 65535, 65535, 65535 }, Rectangle{ 0, 0, 0, 0 }) },\n };\n \n } /* namespace libcamera */\ndiff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex bc89ab5..b4e42c1 100644\n--- a/src/ipa/raspberrypi/raspberrypi.cpp\n+++ b/src/ipa/raspberrypi/raspberrypi.cpp\n@@ -645,6 +645,16 @@ void IPARPi::queueRequest(const ControlList &controls)\n \t\t\tbreak;\n \t\t}\n \n+\t\tcase controls::DIGITAL_ZOOM: {\n+\t\t\t/*\n+\t\t\t * We send the zoom info back in the metadata where the pipeline\n+\t\t\t * handler will update it to the values actually used.\n+\t\t\t */\n+\t\t\tRectangle crop = ctrl.second.get<Rectangle>();\n+\t\t\tlibcameraMetadata_.set(controls::DigitalZoom, crop);\n+\t\t\tbreak;\n+\t\t}\n+\n \t\tdefault:\n \t\t\tLOG(IPARPI, Warning)\n \t\t\t\t<< \"Ctrl \" << controls::controls.at(ctrl.first)->name()\ndiff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex 9d887b7..25cbe13 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -37,6 +37,8 @@ namespace libcamera {\n \n LOG_DEFINE_CATEGORY(RPI)\n \n+static constexpr int ISP_MIN_SIZE = 64;\n+\n using V4L2PixFmtMap = std::map<V4L2PixelFormat, std::vector<SizeRange>>;\n \n namespace {\n@@ -322,6 +324,13 @@ public:\n \tvoid handleStreamBuffer(FrameBuffer *buffer, const RPiStream *stream);\n \tvoid handleState();\n \n+\tvoid initSensorCrop(Rectangle const &crop)\n+\t{\n+\t\t/* The initial zoom region is the whole of the sensorCrop_. */\n+\t\tsensorCrop_ = crop;\n+\t\tzoomRect_ = Rectangle{ 0, 0, crop.width, crop.height };\n+\t}\n+\n \tCameraSensor *sensor_;\n \t/* Array of Unicam and ISP device streams and associated buffers/streams. */\n \tRPiDevice<Unicam, 2> unicam_;\n@@ -358,6 +367,14 @@ private:\n \n \tbool dropFrame_;\n \tint ispOutputCount_;\n+\t/*\n+\t * sensorCrop_ is the largest region of the full sensor output that matches\n+\t * the desired aspect ratio, and therefore represents the area within\n+\t * which we can pan and zoom. zoomRect_ is the portion from within the\n+\t * sensorCrop_ that pan/zoom is currently using.\n+\t */\n+\tRectangle sensorCrop_;\n+\tRectangle zoomRect_;\n };\n \n class RPiCameraConfiguration : public CameraConfiguration\n@@ -763,6 +780,14 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n \n \tcrop.x = (sensorFormat.size.width - crop.width) >> 1;\n \tcrop.y = (sensorFormat.size.height - crop.height) >> 1;\n+\n+\tif (crop.width < ISP_MIN_SIZE || crop.height < ISP_MIN_SIZE) {\n+\t\tLOG(RPI, Error) << \"Crop from sensor \" << crop.width << \"x\" << crop.height << \" is too small\";\n+\t\treturn -1;\n+\t}\n+\tsensorCrop_ = Size(crop.width, crop.height);\n+\tdata->initSensorCrop(crop);\n+\n \tdata->isp_[Isp::Input].dev()->setSelection(V4L2_SEL_TGT_CROP, &crop);\n \n \tret = configureIPA(camera);\n@@ -1226,6 +1251,13 @@ void RPiCameraData::queueFrameAction(unsigned int frame, const IPAOperationData\n \t\thandleStreamBuffer(buffer, &isp_[Isp::Stats]);\n \t\t/* Fill the Request metadata buffer with what the IPA has provided */\n \t\trequestQueue_.front()->metadata() = std::move(action.controls[0]);\n+\t\tControlList &metadata = requestQueue_.front()->metadata();\n+\t\t/*\n+\t\t * The IPA sends the zoom metadata back to us, but we're the ones who\n+\t\t * actually know what we used, so must fill it in correctly.\n+\t\t */\n+\t\tif (metadata.contains(controls::DigitalZoom))\n+\t\t\tmetadata.set(controls::DigitalZoom, zoomRect_);\n \t\tstate_ = State::IpaComplete;\n \t\tbreak;\n \t}\n@@ -1548,6 +1580,33 @@ void RPiCameraData::tryRunPipeline()\n \t */\n \tRequest *request = requestQueue_.front();\n \n+\tif (request->controls().contains(controls::DigitalZoom)) {\n+\t\tRectangle rect = request->controls().get<Rectangle>(controls::DigitalZoom);\n+\t\t/*\n+\t\t * If a new digital zoom value was given, check that it lies within the\n+\t\t * available sensorCrop_, coercing it if necessary.\n+\t\t */\n+\t\tif (rect.width && rect.height) {\n+\t\t\tzoomRect_ = rect;\n+\t\t\tif (zoomRect_.width < ISP_MIN_SIZE)\n+\t\t\t\tzoomRect_.width = ISP_MIN_SIZE;\n+\t\t\telse if (zoomRect_.width > sensorCrop_.width)\n+\t\t\t\tzoomRect_.width = sensorCrop_.width;\n+\t\t\tif (zoomRect_.height < ISP_MIN_SIZE)\n+\t\t\t\tzoomRect_.height = ISP_MIN_SIZE;\n+\t\t\telse if (zoomRect_.height > sensorCrop_.height)\n+\t\t\t\tzoomRect_.height = sensorCrop_.height;\n+\t\t\tif (zoomRect_.x + zoomRect_.width > sensorCrop_.width)\n+\t\t\t\tzoomRect_.x = sensorCrop_.width - zoomRect_.width;\n+\t\t\tif (zoomRect_.y + zoomRect_.height > sensorCrop_.height)\n+\t\t\t\tzoomRect_.y = sensorCrop_.height - zoomRect_.height;\n+\t\t}\n+\t\tRectangle sensorRect = zoomRect_;\n+\t\tsensorRect.x += sensorCrop_.x;\n+\t\tsensorRect.y += sensorCrop_.y;\n+\t\tisp_[Isp::Input].dev()->setSelection(V4L2_SEL_TGT_CROP, &sensorRect);\n+\t}\n+\n \t/*\n \t * Process all the user controls by the IPA. Once this is complete, we\n \t * queue the ISP output buffer listed in the request to start the HW\n",
    "prefixes": [
        "libcamera-devel",
        "2/2"
    ]
}