[{"id":30952,"web_url":"https://patchwork.libcamera.org/comment/30952/","msgid":"<20240828163544.GI27131@pendragon.ideasonboard.com>","date":"2024-08-28T16:35:44","subject":"Re: [PATCH v1 4/7] pipeline: rpi: Introduce CameraData::CropParams","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Naush,\n\nThank you for the patch.\n\nOn Thu, Aug 08, 2024 at 11:23:43AM +0100, Naushir Patuck wrote:\n> In preparation for assigning separate crop windows for each stream, add\n> a new CropParams structure that stores the existing ispCrop_ and\n> ispMinCropSize_ as fields. Use a new std::map to store a CropParams\n> structure where the map key is the index of the stream configuration in\n> the CameraConfiguration vector.\n> \n> At preset, only a single CropParams structure will be set at key == 0 to\n> preserve the existing crop handling logic.\n> \n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> ---\n>  .../pipeline/rpi/common/pipeline_base.cpp     | 23 +++++++++++--------\n>  .../pipeline/rpi/common/pipeline_base.h       | 21 +++++++++++++++--\n>  src/libcamera/pipeline/rpi/vc4/vc4.cpp        | 13 ++++++++---\n>  3 files changed, 43 insertions(+), 14 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> index 2de6111bacfd..412e71648231 100644\n> --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp\n> @@ -561,10 +561,12 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config)\n>  \tfor (auto const &c : result.controlInfo)\n>  \t\tctrlMap.emplace(c.first, c.second);\n>  \n> -\t/* Add the ScalerCrop control limits based on the current mode. */\n> -\tRectangle ispMinCrop = data->scaleIspCrop(Rectangle(data->ispMinCropSize_));\n> -\tctrlMap[&controls::ScalerCrop] = ControlInfo(ispMinCrop, data->sensorInfo_.analogCrop,\n> -\t\t\t\t\t\t     data->scaleIspCrop(data->ispCrop_));\n> +\tif (data->cropParams_.count(0)) {\n\nYou can avoid the double lookup with\n\n\tconst auto cropParams = data->cropParams_.find(0);\n\tif (cropParams != data->cropParams_.end()) {\n\nand use cropParams below.\n\n> +\t\t/* Add the ScalerCrop control limits based on the current mode. */\n> +\t\tRectangle ispMinCrop = data->scaleIspCrop(Rectangle(data->cropParams_[0].ispMinCropSize));\n> +\t\tctrlMap[&controls::ScalerCrop] = ControlInfo(ispMinCrop, data->sensorInfo_.analogCrop,\n> +\t\t\t\t\t\t\t     data->scaleIspCrop(data->cropParams_[0].ispCrop));\n> +\t}\n>  \n>  \tdata->controlInfo_ = ControlInfoMap(std::move(ctrlMap), result.controlInfo.idmap());\n>  \n> @@ -1291,7 +1293,8 @@ Rectangle CameraData::scaleIspCrop(const Rectangle &ispCrop) const\n>  void CameraData::applyScalerCrop(const ControlList &controls)\n>  {\n>  \tconst auto &scalerCrop = controls.get<Rectangle>(controls::ScalerCrop);\n> -\tif (scalerCrop) {\n> +\tif (scalerCrop && cropParams_.count(0)) {\n> +\t\tCropParams &cropParams = cropParams_[0];\n\nSame here.\n\n>  \t\tRectangle nativeCrop = *scalerCrop;\n>  \n>  \t\tif (!nativeCrop.width || !nativeCrop.height)\n> @@ -1308,12 +1311,12 @@ void CameraData::applyScalerCrop(const ControlList &controls)\n>  \t\t * 2. With the same mid-point, if possible.\n>  \t\t * 3. But it can't go outside the sensor area.\n>  \t\t */\n> -\t\tSize minSize = ispMinCropSize_.expandedToAspectRatio(nativeCrop.size());\n> +\t\tSize minSize = cropParams.ispMinCropSize.expandedToAspectRatio(nativeCrop.size());\n>  \t\tSize size = ispCrop.size().expandedTo(minSize);\n>  \t\tispCrop = size.centeredTo(ispCrop.center()).enclosedIn(Rectangle(sensorInfo_.outputSize));\n>  \n> -\t\tif (ispCrop != ispCrop_) {\n> -\t\t\tispCrop_ = ispCrop;\n> +\t\tif (ispCrop != cropParams.ispCrop) {\n> +\t\t\tcropParams.ispCrop = ispCrop;\n>  \t\t\tplatformSetIspCrop(ispCrop);\n>  \t\t}\n>  \t}\n> @@ -1471,7 +1474,9 @@ void CameraData::fillRequestMetadata(const ControlList &bufferControls, Request\n>  \trequest->metadata().set(controls::SensorTimestamp,\n>  \t\t\t\tbufferControls.get(controls::SensorTimestamp).value_or(0));\n>  \n> -\trequest->metadata().set(controls::ScalerCrop, scaleIspCrop(ispCrop_));\n> +\tif (cropParams_.count(0))\n> +\t\trequest->metadata().set(controls::ScalerCrop,\n> +\t\t\t\t\tscaleIspCrop(cropParams_[0].ispCrop));\n>  }\n>  \n>  } /* namespace libcamera */\n> diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h\n> index d65b695c30b5..2bed905178bc 100644\n> --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h\n> +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h\n> @@ -133,8 +133,25 @@ public:\n>  \n>  \t/* For handling digital zoom. */\n>  \tIPACameraSensorInfo sensorInfo_;\n> -\tRectangle ispCrop_; /* crop in ISP (camera mode) pixels */\n> -\tSize ispMinCropSize_;\n> +\n> +\tstruct CropParams {\n> +\t\tCropParams(Rectangle ispCrop_, Size ispMinCropSize_)\n> +\t\t\t: ispCrop(ispCrop_), ispMinCropSize(ispMinCropSize_)\n> +\t\t{\n> +\t\t}\n> +\n> +\t\tCropParams()\n> +\t\t{\n> +\t\t}\n> +\n> +\t\t/* Crop in ISP (camera mode) pixels */\n> +\t\tRectangle ispCrop;\n> +\t\t/* Minimum crop size in ISP output pixels */\n> +\t\tSize ispMinCropSize;\n> +\t};\n> +\n> +\t/* Mapping of CropParams keyed by the stream index in CameraConfiguration */\n> +\tstd::map<unsigned int, CropParams> cropParams_;\n>  \n>  \tunsigned int dropFrameCount_;\n>  \n> diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> index 0ea032293bc9..d118252f02dd 100644\n> --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n> @@ -702,13 +702,20 @@ int Vc4CameraData::platformConfigure(const RPi::RPiCameraConfiguration *rpiConfi\n>  \t/* Figure out the smallest selection the ISP will allow. */\n>  \tRectangle testCrop(0, 0, 1, 1);\n>  \tisp_[Isp::Input].dev()->setSelection(V4L2_SEL_TGT_CROP, &testCrop);\n> -\tispMinCropSize_ = testCrop.size();\n>  \n>  \t/* Adjust aspect ratio by providing crops on the input image. */\n>  \tSize size = unicamFormat.size.boundedToAspectRatio(maxSize);\n> -\tispCrop_ = size.centeredTo(Rectangle(unicamFormat.size).center());\n> +\tRectangle ispCrop = size.centeredTo(Rectangle(unicamFormat.size).center());\n>  \n> -\tplatformSetIspCrop(ispCrop_);\n> +\tplatformSetIspCrop(ispCrop);\n> +\t/*\n> +\t * Set the scaler crop to the value we are using (scaled to native sensor\n> +\t * coordinates).\n> +\t */\n> +\tcropParams_.clear();\n\nThis line could possibly go to the common implementation of\nPipelineHandlerBase::configure(). Up to you.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\tcropParams_.emplace(std::piecewise_construct,\n> +\t\t\t    std::forward_as_tuple(0),\n> +\t\t\t    std::forward_as_tuple(scaleIspCrop(ispCrop), testCrop.size()));\n>  \n>  \treturn 0;\n>  }","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 0F851C323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 28 Aug 2024 16:35:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0A4CB633CD;\n\tWed, 28 Aug 2024 18:35:50 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D989061903\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 28 Aug 2024 18:35:48 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E39E0220;\n\tWed, 28 Aug 2024 18:34:40 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"sRtoGyZJ\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1724862881;\n\tbh=z9kr4wylCOdLBqhcQL9Hx61GXgE4BMnO8JpATDgQY8w=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=sRtoGyZJY7Cvj+8DcYL2/deC0WsFDxwT1JLqJ+I8XGqe3CPpNfc6YdgSOTA6WKPf6\n\tJYLxNUNIPEadXRthX/fKsd4Sj2uTArn14BrAU1uBStYhlfI1nGq4opUpjqe+gu0Z7s\n\t/hmLEEiCijh9JNeWeoVaAJBEyiew9tl0U4js5hj8=","Date":"Wed, 28 Aug 2024 19:35:44 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Naushir Patuck <naush@raspberrypi.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v1 4/7] pipeline: rpi: Introduce CameraData::CropParams","Message-ID":"<20240828163544.GI27131@pendragon.ideasonboard.com>","References":"<20240808102346.13065-1-naush@raspberrypi.com>\n\t<20240808102346.13065-5-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20240808102346.13065-5-naush@raspberrypi.com>","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>"}}]