From patchwork Tue Jan 5 19:05:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10821 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 02379C0F1A for ; Tue, 5 Jan 2021 19:05:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C0C6F630BA; Tue, 5 Jan 2021 20:05:19 +0100 (CET) Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AC9316308C for ; Tue, 5 Jan 2021 20:05:16 +0100 (CET) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 49730100003 for ; Tue, 5 Jan 2021 19:05:16 +0000 (UTC) From: Jacopo Mondi 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 ScalerCrop control X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Register the ScalerCrop control in the ImgU pipeline handler computed by using the Viewfinder [1280x720] pipeline output configuration and the sensor resolution as parameters. The ScalerCrop control limits should be updated everytime a new configuration is applied to the sensor. Signed-off-by: Jacopo Mondi --- src/libcamera/pipeline/ipu3/ipu3.cpp | 53 ++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 418301b33a5e..f1329ffb0463 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -41,6 +41,7 @@ static constexpr unsigned int IMGU_OUTPUT_WIDTH_ALIGN = 64; static constexpr unsigned int IMGU_OUTPUT_HEIGHT_ALIGN = 4; static constexpr unsigned int IMGU_OUTPUT_WIDTH_MARGIN = 64; static constexpr unsigned int IMGU_OUTPUT_HEIGHT_MARGIN = 32; +static constexpr Size IPU3ViewfinderSize(1280, 720); static const ControlInfoMap::Map IPU3Controls = { { &controls::draft::PipelineDepth, ControlInfo(2, 3) }, @@ -378,7 +379,7 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera, * capped to the maximum sensor resolution and aligned * to the ImgU output constraints. */ - size = sensorResolution.boundedTo({ 1280, 720 }) + size = sensorResolution.boundedTo(IPU3ViewfinderSize) .alignedDownTo(IMGU_OUTPUT_WIDTH_ALIGN, IMGU_OUTPUT_HEIGHT_ALIGN); pixelFormat = formats::NV12; @@ -785,7 +786,7 @@ int PipelineHandlerIPU3::initProperties(IPU3CameraData *data) */ int PipelineHandlerIPU3::initControls(IPU3CameraData *data) { - const CameraSensor *sensor = data->cio2_.sensor(); + CameraSensor *sensor = data->cio2_.sensor(); CameraSensorInfo sensorInfo{}; int ret = sensor->sensorInfo(&sensorInfo); @@ -822,6 +823,54 @@ int PipelineHandlerIPU3::initControls(IPU3CameraData *data) controls[&controls::ExposureTime] = ControlInfo(minExposure, maxExposure, defExposure); + /* + * Compute the scaler crop limits. + * + * \todo The scaler crop limits depend on the sensor configuration. It + * should be updated when a new configuration is applied. To initialize + * the control use the 'Viewfinder' configuration (1280x720) as the + * pipeline output resolution and the full sensor size as input frame + * (see the todo note in the validation function). + */ + + /* + * The maximum scaler crop rectangle is the analogue crop used to + * produce the maximum frame size. + */ + V4L2SubdeviceFormat sensorFormat; + sensorFormat.size = sensor->resolution(); + ret = sensor->setFormat(&sensorFormat); + if (ret) + return ret; + + /* Re-fetch the sensor info updated to use the largest resolution. */ + ret = sensor->sensorInfo(&sensorInfo); + if (ret) + return ret; + + const Rectangle &analogueCrop = sensorInfo.analogCrop; + Rectangle maxCrop = analogueCrop; + + /* + * The minimum crop rectangle is the default viewfinder configuration + * (or the sensor resolution, if smaller) re-scaled in the sensor's pixel + * array coordinates. As the ImgU cannot up-scale, the minimum selection + * rectangle has to be as large as the desired pipeline output size. + * + * The top-left corner position is not relevant as the minimum crop + * rectangle can be placed anywhere inside the analogue crop region. + */ + const Size &sensorOutput = sensorInfo.outputSize; + Size minCropSize = sensorOutput.boundedTo(IPU3ViewfinderSize) + .alignedDownTo(IMGU_OUTPUT_WIDTH_ALIGN, + IMGU_OUTPUT_HEIGHT_ALIGN); + Rectangle minCrop(minCropSize); + minCrop.scaledBy(analogueCrop.size(), sensorOutput); + minCrop.x = analogueCrop.x; + minCrop.y = analogueCrop.y; + + controls[&controls::ScalerCrop] = ControlInfo(minCrop, maxCrop, maxCrop); + data->controlInfo_ = std::move(controls); return 0;