Show a patch.

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

{
    "id": 10218,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/10218/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/10218/",
    "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": "<20201023102159.26274-6-david.plowman@raspberrypi.com>",
    "date": "2020-10-23T10:21:59",
    "name": "[libcamera-devel,v5,5/5] libcamera: pipeline: raspberrypi: Implementation of digital zoom",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "ca5924ae686dbfc52e424c0e8070aa7389f5dd1f",
    "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/10218/mbox/",
    "series": [
        {
            "id": 1409,
            "url": "https://patchwork.libcamera.org/api/1.1/series/1409/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1409",
            "date": "2020-10-23T10:21:54",
            "name": "Digital zoom",
            "version": 5,
            "mbox": "https://patchwork.libcamera.org/series/1409/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/10218/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/10218/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 29D58C3D3C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 23 Oct 2020 10:22:12 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D5EFF61795;\n\tFri, 23 Oct 2020 12:22:11 +0200 (CEST)",
            "from mail-wm1-x330.google.com (mail-wm1-x330.google.com\n\t[IPv6:2a00:1450:4864:20::330])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4961D619AB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 23 Oct 2020 12:22:08 +0200 (CEST)",
            "by mail-wm1-x330.google.com with SMTP id k18so919988wmj.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 23 Oct 2020 03:22:08 -0700 (PDT)",
            "from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72])\n\tby smtp.gmail.com with ESMTPSA id\n\tr128sm2477831wma.20.2020.10.23.03.22.06\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 23 Oct 2020 03:22:06 -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=\"c3haEIYM\"; 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=Mj39ccQTSMuGU/dKsqpOkarhfi/ZGEAhU1hwhonA6KU=;\n\tb=c3haEIYMNQiW31aRlTcyRs4m5ikyOx476rc3L3QcQ7ObV2JlQlZ3zB+XMoqFR2dS30\n\tWfUNp17nc4mfvdNnos3JUgMCMNFtZh30YsOnq2vSVMzkNVVJTrxlMWinITa9Zr6GT3oz\n\tMOtGdvq+++44q7dbrcxSFFKvFqx55xShhGl0+v0xpp2Mi57LyKq5L6+ftNgxU5mFCYgy\n\t0vJRSwWSnVW4Z5Dl4TLuZj06d9U8GecZpqVV3PAJCl+it5sp1sr9gVaQkmaqV37+3WUK\n\tFa+ISIarN55kSK9cifmUER+Av/jR/c/jodz4cUGkJ3DQRef08YsPR9Pk8koWj9OuUQCH\n\tJygQ==",
        "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=Mj39ccQTSMuGU/dKsqpOkarhfi/ZGEAhU1hwhonA6KU=;\n\tb=F0Bkmrt+iUYkwD1B7XfD3Sfi2E05pmmG7vRF+x16SqglkdrOXX/pvEvOvWh7GZ3gUA\n\taHLk5T4GadGAp4F0QupCpK5tP8LQTdrsrTA+P33wxcssGVYTnBUw340vTTH2zRAzF3E+\n\tXb/+xXHsg/P+nloZE44Hf73Iy0N9qYkeTPMfGjaQwjkcOZduQ8piLaaI1GuRlpKSJXJQ\n\tMTVw/3YRSx354E1MXF5kKxxUUWxRxtf+hY8lKkO8Fd5qkynaBjR1kmLGTKT/tXXgDvJz\n\tJpYTLQ2F9hyevEr1P3sRVwO6lo8j/V4fQvnqE6dD2pEMYansBHnQFuMnYZ5yvB0ImQ0m\n\tnc7A==",
        "X-Gm-Message-State": "AOAM533Lm2jIsXtcV9IyhoBciL/DGKisLFBb78ilq4brKUfB+PkgrZAE\n\tOjWjPJs18nUUzZ2cVW0dsEjmrqV0pDRVlA==",
        "X-Google-Smtp-Source": "ABdhPJyUVOF7LAg8vAxYUYMmEkvuQ9v4ADc0JkuSzd0LY+LFYDaQBuGbLR+qSbOOSAEzCIxc0KzPuA==",
        "X-Received": "by 2002:a1c:ab0b:: with SMTP id\n\tu11mr1610697wme.165.1603448527567; \n\tFri, 23 Oct 2020 03:22:07 -0700 (PDT)",
        "From": "David Plowman <david.plowman@raspberrypi.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri, 23 Oct 2020 11:21:59 +0100",
        "Message-Id": "<20201023102159.26274-6-david.plowman@raspberrypi.com>",
        "X-Mailer": "git-send-email 2.20.1",
        "In-Reply-To": "<20201023102159.26274-1-david.plowman@raspberrypi.com>",
        "References": "<20201023102159.26274-1-david.plowman@raspberrypi.com>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH v5 5/5] libcamera: pipeline: raspberrypi:\n\tImplementation of digital 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": "During configure() we update the ScalerCropMaximum to the correct\nvalue for this camera mode and work out the minimum crop size allowed\nby the ISP.\n\nWhenever a new ScalerCrop request is received we check it's valid and\napply it to the ISP V4L2 device. When the IPA returns its metadata to\nus we add the ScalerCrop information, rescaled to sensor native\npixels.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\n---\n include/libcamera/ipa/raspberrypi.h           |  1 +\n src/ipa/raspberrypi/raspberrypi.cpp           |  5 ++\n .../pipeline/raspberrypi/raspberrypi.cpp      | 82 +++++++++++++++----\n 3 files changed, 72 insertions(+), 16 deletions(-)",
    "diff": "diff --git a/include/libcamera/ipa/raspberrypi.h b/include/libcamera/ipa/raspberrypi.h\nindex b23baf2f..ff2faf86 100644\n--- a/include/libcamera/ipa/raspberrypi.h\n+++ b/include/libcamera/ipa/raspberrypi.h\n@@ -62,6 +62,7 @@ static const ControlInfoMap Controls = {\n \t{ &controls::Saturation, ControlInfo(0.0f, 32.0f) },\n \t{ &controls::Sharpness, ControlInfo(0.0f, 16.0f, 1.0f) },\n \t{ &controls::ColourCorrectionMatrix, ControlInfo(-16.0f, 16.0f) },\n+\t{ &controls::ScalerCrop, ControlInfo(Rectangle{}, Rectangle(65535, 65535, 65535, 65535), Rectangle{}) },\n };\n \n } /* namespace RPi */\ndiff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex 1c255aa2..f338ff8b 100644\n--- a/src/ipa/raspberrypi/raspberrypi.cpp\n+++ b/src/ipa/raspberrypi/raspberrypi.cpp\n@@ -699,6 +699,11 @@ void IPARPi::queueRequest(const ControlList &controls)\n \t\t\tbreak;\n \t\t}\n \n+\t\tcase controls::SCALER_CROP: {\n+\t\t\t/* We do nothing with this, but should avoid the warning below. */\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 763451a8..83e91576 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -193,6 +193,11 @@ public:\n \tbool flipsAlterBayerOrder_;\n \tBayerFormat::Order nativeBayerOrder_;\n \n+\t/* For handling digital zoom. */\n+\tCameraSensorInfo sensorInfo_;\n+\tRectangle lastIspCrop_;\n+\tSize ispMinSize_;\n+\n \tunsigned int dropFrameCount_;\n \n private:\n@@ -677,26 +682,31 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n \t\treturn ret;\n \t}\n \n-\t/* Adjust aspect ratio by providing crops on the input image. */\n-\tRectangle crop{ 0, 0, sensorFormat.size };\n-\n-\tint ar = maxSize.height * sensorFormat.size.width - maxSize.width * sensorFormat.size.height;\n-\tif (ar > 0)\n-\t\tcrop.width = maxSize.width * sensorFormat.size.height / maxSize.height;\n-\telse if (ar < 0)\n-\t\tcrop.height = maxSize.height * sensorFormat.size.width / maxSize.width;\n+\t/* Figure out the smallest selection the ISP will allow. */\n+\tRectangle testCrop(0, 0, 1, 1);\n+\tdata->isp_[Isp::Input].dev()->setSelection(V4L2_SEL_TGT_CROP, &testCrop);\n+\tdata->ispMinSize_ = testCrop.size();\n \n-\tcrop.width &= ~1;\n-\tcrop.height &= ~1;\n+\t/* Adjust aspect ratio by providing crops on the input image. */\n+\tSize size = sensorFormat.size.boundedToAspectRatio(maxSize);\n+\tRectangle crop = size.centeredTo(sensorFormat.size.center());\n+\tdata->lastIspCrop_ = crop;\n \n-\tcrop.x = (sensorFormat.size.width - crop.width) >> 1;\n-\tcrop.y = (sensorFormat.size.height - crop.height) >> 1;\n \tdata->isp_[Isp::Input].dev()->setSelection(V4L2_SEL_TGT_CROP, &crop);\n \n \tret = data->configureIPA(config);\n \tif (ret)\n \t\tLOG(RPI, Error) << \"Failed to configure the IPA: \" << ret;\n \n+\t/*\n+\t * Update the ScalerCropMaximum to the correct value for this camera mode.\n+\t * For us, it's the same as the \"analogue crop\".\n+\t *\n+\t * \\todo Make this property the ScalerCrop maximum value when dynamic\n+\t * controls are available and set it at validate() time\n+\t */\n+\tdata->properties_.set(properties::ScalerCropMaximum, data->sensorInfo_.analogCrop);\n+\n \treturn ret;\n }\n \n@@ -1154,8 +1164,8 @@ int RPiCameraData::configureIPA(const CameraConfiguration *config)\n \t\tipaConfig.data.push_back(static_cast<unsigned int>(lsTable_.fd()));\n \t}\n \n-\tCameraSensorInfo sensorInfo = {};\n-\tint ret = sensor_->sensorInfo(&sensorInfo);\n+\t/* We store the CameraSensorInfo for digital zoom calculations. */\n+\tint ret = sensor_->sensorInfo(&sensorInfo_);\n \tif (ret) {\n \t\tLOG(RPI, Error) << \"Failed to retrieve camera sensor info\";\n \t\treturn ret;\n@@ -1164,7 +1174,7 @@ int RPiCameraData::configureIPA(const CameraConfiguration *config)\n \t/* Ready the IPA - it must know about the sensor resolution. */\n \tIPAOperationData result;\n \n-\tipa_->configure(sensorInfo, streamConfig, entityControls, ipaConfig,\n+\tipa_->configure(sensorInfo_, streamConfig, entityControls, ipaConfig,\n \t\t\t&result);\n \n \tunsigned int resultIdx = 0;\n@@ -1243,8 +1253,23 @@ void RPiCameraData::queueFrameAction([[maybe_unused]] unsigned int frame,\n \t\tFrameBuffer *buffer = isp_[Isp::Stats].getBuffers().at(bufferId);\n \n \t\thandleStreamBuffer(buffer, &isp_[Isp::Stats]);\n+\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\tRequest *request = requestQueue_.front();\n+\t\trequest->metadata() = std::move(action.controls[0]);\n+\n+\t\t/*\n+\t\t * Also update the ScalerCrop in the metadata with what we actually\n+\t\t * used. But we must first rescale that from ISP (camera mode) pixels\n+\t\t * back into sensor native pixels.\n+\t\t *\n+\t\t * Sending this information on every frame may be helpful.\n+\t\t */\n+\t\tRectangle crop = lastIspCrop_.scaledBy(sensorInfo_.analogCrop.size(),\n+\t\t\t\t\t\t       sensorInfo_.outputSize);\n+\t\tcrop.translateBy(sensorInfo_.analogCrop.topLeft());\n+\t\trequest->metadata().set(controls::ScalerCrop, crop);\n+\n \t\tstate_ = State::IpaComplete;\n \t\tbreak;\n \t}\n@@ -1595,6 +1620,31 @@ void RPiCameraData::tryRunPipeline()\n \t/* Take the first request from the queue and action the IPA. */\n \tRequest *request = requestQueue_.front();\n \n+\tif (request->controls().contains(controls::ScalerCrop)) {\n+\t\tRectangle crop = request->controls().get<Rectangle>(controls::ScalerCrop);\n+\n+\t\tif (crop.width && crop.height) {\n+\t\t\t/* First scale the crop from sensor native to camera mode pixels. */\n+\t\t\tcrop.translateBy(-sensorInfo_.analogCrop.topLeft());\n+\t\t\tcrop.scaleBy(sensorInfo_.outputSize, sensorInfo_.analogCrop.size());\n+\n+\t\t\t/*\n+\t\t\t * The crop that we set must be:\n+\t\t\t * 1. At least as big as ispMinSize_, once that's been\n+\t\t\t *    enlarged to the same aspect ratio.\n+\t\t\t * 2. With the same mid-point, if possible.\n+\t\t\t * 3. But it can't go outside the sensor area.\n+\t\t\t */\n+\t\t\tSize minSize = ispMinSize_.expandedToAspectRatio(crop.size());\n+\t\t\tSize size = crop.size().expandedTo(minSize);\n+\t\t\tcrop = size.centeredTo(crop.center()).enclosedIn(Rectangle(sensorInfo_.outputSize));\n+\n+\t\t\tif (crop != lastIspCrop_)\n+\t\t\t\tisp_[Isp::Input].dev()->setSelection(V4L2_SEL_TGT_CROP, &crop);\n+\t\t\tlastIspCrop_ = crop;\n+\t\t}\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",
        "v5",
        "5/5"
    ]
}