{"id":10821,"url":"https://patchwork.libcamera.org/api/patches/10821/?format=json","web_url":"https://patchwork.libcamera.org/patch/10821/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210105190522.682324-8-jacopo@jmondi.org>","date":"2021-01-05T19:05:17","name":"[libcamera-devel,07/12] libcamera: ipu3: Register ScalerCrop control","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"e889ece5eb9f178b5e6a8ff693b35ba955c068cf","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":{"id":15,"url":"https://patchwork.libcamera.org/api/users/15/?format=json","username":"jmondi","first_name":"Jacopo","last_name":"Mondi","email":"jacopo@jmondi.org"},"mbox":"https://patchwork.libcamera.org/patch/10821/mbox/","series":[{"id":1568,"url":"https://patchwork.libcamera.org/api/series/1568/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1568","date":"2021-01-05T19:05:10","name":"android: Exposure times + scaler crop + android metadata","version":1,"mbox":"https://patchwork.libcamera.org/series/1568/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/10821/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/10821/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 02379C0F1A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  5 Jan 2021 19:05:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C0C6F630BA;\n\tTue,  5 Jan 2021 20:05:19 +0100 (CET)","from relay11.mail.gandi.net (relay11.mail.gandi.net\n\t[217.70.178.231])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AC9316308C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  5 Jan 2021 20:05:16 +0100 (CET)","from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay11.mail.gandi.net (Postfix) with ESMTPSA id 49730100003\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  5 Jan 2021 19:05:16 +0000 (UTC)"],"From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue,  5 Jan 2021 20:05:17 +0100","Message-Id":"<20210105190522.682324-8-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.29.2","In-Reply-To":"<20210105190522.682324-1-jacopo@jmondi.org>","References":"<20210105190522.682324-1-jacopo@jmondi.org>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH 07/12] libcamera: ipu3: Register\n\tScalerCrop control","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":"Register the ScalerCrop control in the ImgU pipeline handler computed\nby using the Viewfinder [1280x720] pipeline output configuration and\nthe sensor resolution as parameters.\n\nThe ScalerCrop control limits should be updated everytime a new\nconfiguration is applied to the sensor.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/pipeline/ipu3/ipu3.cpp | 53 ++++++++++++++++++++++++++--\n 1 file changed, 51 insertions(+), 2 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex 418301b33a5e..f1329ffb0463 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -41,6 +41,7 @@ static constexpr unsigned int IMGU_OUTPUT_WIDTH_ALIGN = 64;\n static constexpr unsigned int IMGU_OUTPUT_HEIGHT_ALIGN = 4;\n static constexpr unsigned int IMGU_OUTPUT_WIDTH_MARGIN = 64;\n static constexpr unsigned int IMGU_OUTPUT_HEIGHT_MARGIN = 32;\n+static constexpr Size IPU3ViewfinderSize(1280, 720);\n \n static const ControlInfoMap::Map IPU3Controls = {\n \t{ &controls::draft::PipelineDepth, ControlInfo(2, 3) },\n@@ -378,7 +379,7 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera,\n \t\t\t * capped to the maximum sensor resolution and aligned\n \t\t\t * to the ImgU output constraints.\n \t\t\t */\n-\t\t\tsize = sensorResolution.boundedTo({ 1280, 720 })\n+\t\t\tsize = sensorResolution.boundedTo(IPU3ViewfinderSize)\n \t\t\t\t\t       .alignedDownTo(IMGU_OUTPUT_WIDTH_ALIGN,\n \t\t\t\t\t\t\t      IMGU_OUTPUT_HEIGHT_ALIGN);\n \t\t\tpixelFormat = formats::NV12;\n@@ -785,7 +786,7 @@ int PipelineHandlerIPU3::initProperties(IPU3CameraData *data)\n  */\n int PipelineHandlerIPU3::initControls(IPU3CameraData *data)\n {\n-\tconst CameraSensor *sensor = data->cio2_.sensor();\n+\tCameraSensor *sensor = data->cio2_.sensor();\n \tCameraSensorInfo sensorInfo{};\n \n \tint ret = sensor->sensorInfo(&sensorInfo);\n@@ -822,6 +823,54 @@ int PipelineHandlerIPU3::initControls(IPU3CameraData *data)\n \tcontrols[&controls::ExposureTime] = ControlInfo(minExposure, maxExposure,\n \t\t\t\t\t\t\tdefExposure);\n \n+\t/*\n+\t * Compute the scaler crop limits.\n+\t *\n+\t * \\todo The scaler crop limits depend on the sensor configuration.  It\n+\t * should be updated when a new configuration is applied.  To initialize\n+\t * the control use the 'Viewfinder' configuration (1280x720) as the\n+\t * pipeline output resolution and the full sensor size as input frame\n+\t * (see the todo note in the validation function).\n+\t */\n+\n+\t/*\n+\t * The maximum scaler crop rectangle is the analogue crop used to\n+\t * produce the maximum frame size.\n+\t */\n+\tV4L2SubdeviceFormat sensorFormat;\n+\tsensorFormat.size = sensor->resolution();\n+\tret = sensor->setFormat(&sensorFormat);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\t/* Re-fetch the sensor info updated to use the largest resolution. */\n+\tret = sensor->sensorInfo(&sensorInfo);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tconst Rectangle &analogueCrop = sensorInfo.analogCrop;\n+\tRectangle maxCrop = analogueCrop;\n+\n+\t/*\n+\t * The minimum crop rectangle is the default viewfinder configuration\n+\t * (or the sensor resolution, if smaller) re-scaled in the sensor's pixel\n+\t * array coordinates. As the ImgU cannot up-scale, the minimum selection\n+\t * rectangle has to be as large as the desired pipeline output size.\n+\t *\n+\t * The top-left corner position is not relevant as the minimum crop\n+\t * rectangle can be placed anywhere inside the analogue crop region.\n+\t */\n+\tconst Size &sensorOutput = sensorInfo.outputSize;\n+\tSize minCropSize = sensorOutput.boundedTo(IPU3ViewfinderSize)\n+\t\t\t\t       .alignedDownTo(IMGU_OUTPUT_WIDTH_ALIGN,\n+\t\t\t\t\t\t      IMGU_OUTPUT_HEIGHT_ALIGN);\n+\tRectangle minCrop(minCropSize);\n+\tminCrop.scaledBy(analogueCrop.size(), sensorOutput);\n+\tminCrop.x = analogueCrop.x;\n+\tminCrop.y = analogueCrop.y;\n+\n+\tcontrols[&controls::ScalerCrop] = ControlInfo(minCrop, maxCrop, maxCrop);\n+\n \tdata->controlInfo_ = std::move(controls);\n \n \treturn 0;\n","prefixes":["libcamera-devel","07/12"]}