From patchwork Thu Oct 3 07:47:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21487 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 BC12ABD80A for ; Thu, 3 Oct 2024 07:53:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4C00263525; Thu, 3 Oct 2024 09:53:49 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="JNn33N0H"; dkim-atps=neutral Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3B6A76351F for ; Thu, 3 Oct 2024 09:53:45 +0200 (CEST) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-42cae563348so1105805e9.0 for ; Thu, 03 Oct 2024 00:53:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1727942024; x=1728546824; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZtSclxseLGwOqhwBSFiuoCXZTAi6XcvSaWhU/rWpZxA=; b=JNn33N0Hw2+F4dL2mARu3s1d9CguTuERusaVTTb3WXQcM9ELpQpEZsjPkvgHqb1QVy OmqQHfzIPH1pZivnuKjH2BZRgxaYA95+Zs2wpOTM3GkM2dNsXITspyVwlqmlmW4MKErM RnFaao19smnIqPhXQaeDX815Gm3xs1asoEKo5vrGcteDY6lQDamaRNGQmLWh2u+scUO2 w+i+5QqSDxa1RktKfvCYua/AJXab1xe+aSja4Nn6XRFRl3PiIG0xi2tkU6CiVoanRqH3 h4ay8qHTY+DM9yxfqQ+A5Ba0dzJC34nGlSBiqZ9FetfroqpqFxMewIlrblsb9I2pJrkN DinA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727942024; x=1728546824; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZtSclxseLGwOqhwBSFiuoCXZTAi6XcvSaWhU/rWpZxA=; b=kVBLWQIuasMZCdrKgXL4dkI2TgijWYxPbIJomgA7QzDJhtj71HEjl3xXmhKcZOeVnX rkn0oWCmcaRGrhP9KmSyrUnSM60sAVO4jiZ/IBIbXc4/1zyM+kkCTEXpMObi91LUWhmP QGLFe3iDerDiGs4MILYPuNeAZIAB35ZjgVqXVIJvCYRAzKM+kjuqxJZsk4Lvvf8Ql0Q0 OiN84eluNTCUhJQ35DB9Fo49UIydhU6uyTu0/B5f6jYyzRRzv5kn5GHKtem4DARAWbTb 1fqVaWRHW4mSX/yfOpjLzfWGh9akwICdL/RU+6aMR/OKpuHwXL88HKQibo/QeKy+85VH Qjuw== X-Gm-Message-State: AOJu0YxQn0cNc0Prb48nmMeWFsHi7V0QJDC2MUTLpNogZC9c67mqUbS9 734hu8/xAoN31IvI/LGRhb5Poh78Q+Gx7Bke8W4R6arMXuaGaIaOZFaJ75pNmm3MmPobFuFBG4D 4 X-Google-Smtp-Source: AGHT+IGHbhyeUhy2i0DU+Q55Izhudb6iapOCwvyBF6movKh6pu3HlLyKisSsCawNYUxqmX1TvB3Cmg== X-Received: by 2002:a05:600c:3c93:b0:42c:bb35:b6d0 with SMTP id 5b1f17b1804b1-42f777b0043mr19815525e9.1.1727942024294; Thu, 03 Oct 2024 00:53:44 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42f8025b583sm8740825e9.12.2024.10.03.00.53.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 00:53:43 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , Jacopo Mondi Subject: [PATCH v3 1/7] controls: rpi: Add a vendor rpi::ScalerCrops control Date: Thu, 3 Oct 2024 08:47:14 +0100 Message-Id: <20241003074720.18882-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241003074720.18882-1-naush@raspberrypi.com> References: <20241003074720.18882-1-naush@raspberrypi.com> MIME-Version: 1.0 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" Add a vendor control rpi::ScalerCrops that is analogous to the current core::ScalerCrop, but can apply a different crop to each configured stream. This control takes a span of Rectangle structures - the order of rectangles must match the order of streams configured by the application. Signed-off-by: Naushir Patuck Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/ipa/rpi/common/ipa_base.cpp | 14 ++++++++++++++ src/libcamera/control_ids_rpi.yaml | 25 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/ipa/rpi/common/ipa_base.cpp b/src/ipa/rpi/common/ipa_base.cpp index ee3848b54f21..d408cdb74255 100644 --- a/src/ipa/rpi/common/ipa_base.cpp +++ b/src/ipa/rpi/common/ipa_base.cpp @@ -96,6 +96,15 @@ const ControlInfoMap::Map ipaAfControls{ { &controls::LensPosition, ControlInfo(0.0f, 32.0f, 1.0f) } }; +/* Platform specific controls */ +const std::map platformControls { + { "pisp", + { + { &controls::rpi::ScalerCrops, ControlInfo(Rectangle{}, Rectangle(65535, 65535, 65535, 65535), Rectangle{}) } + } + }, +}; + } /* namespace */ LOG_DEFINE_CATEGORY(IPARPI) @@ -159,6 +168,10 @@ int32_t IpaBase::init(const IPASettings &settings, const InitParams ¶ms, Ini if (lensPresent_) ctrlMap.merge(ControlInfoMap::Map(ipaAfControls)); + auto platformCtrlsIt = platformControls.find(controller_.getTarget()); + if (platformCtrlsIt != platformControls.end()) + ctrlMap.merge(ControlInfoMap::Map(platformCtrlsIt->second)); + monoSensor_ = params.sensorInfo.cfaPattern == properties::draft::ColorFilterArrangementEnum::MONO; if (!monoSensor_) ctrlMap.merge(ControlInfoMap::Map(ipaColourControls)); @@ -1070,6 +1083,7 @@ void IpaBase::applyControls(const ControlList &controls) break; } + case controls::rpi::SCALER_CROPS: case controls::SCALER_CROP: { /* We do nothing with this, but should avoid the warning below. */ break; diff --git a/src/libcamera/control_ids_rpi.yaml b/src/libcamera/control_ids_rpi.yaml index 42c4bf5d408f..34bbdfc863c5 100644 --- a/src/libcamera/control_ids_rpi.yaml +++ b/src/libcamera/control_ids_rpi.yaml @@ -30,4 +30,29 @@ controls: \sa StatsOutputEnable + - ScalerCrops: + type: Rectangle + size: [n] + description: | + An array of rectangles, where each singular value has identical + functionality to the ScalerCrop control. This control allows the + Raspberry Pi pipeline handler to control individual scaler crops per + output stream. + + The order of rectangles passed into the control must match the order of + streams configured by the application. The pipeline handler will only + configure crop retangles up-to the number of output streams configured. + All subsequent rectangles passed into this control are ignored by the + pipeline handler. + + If both rpi::ScalerCrops and ScalerCrop controls are present in a + ControlList, the latter is discarded, and crops are obtained from this + control. + + Note that using different crop rectangles for each output stream with + this control is only applicable on the Pi5/PiSP platform. This control + should also be considered temporary/draft and will be replaced with + official libcamera API support for per-stream controls in the future. + + \sa ScalerCrop ... From patchwork Thu Oct 3 07:47:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21488 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 C2FBDBD80A for ; Thu, 3 Oct 2024 07:53:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 881586352E; Thu, 3 Oct 2024 09:53:50 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="LmNlU4tL"; dkim-atps=neutral Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A1D7162C93 for ; Thu, 3 Oct 2024 09:53:46 +0200 (CEST) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-42cb3c6c353so1082815e9.3 for ; Thu, 03 Oct 2024 00:53:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1727942026; x=1728546826; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gF1CRK5658pUZV0uzy7B6zhR0H6HtzA+lmLE8dz6KjA=; b=LmNlU4tLWVxh155owywBmgcxrXytkkQadbQ0LfMrvT4C7RwPU8Je6vPkJkzGAK8Vu9 Z08uSPDe0xb3b1iXUuRQSYJb/rMSsQR1Vk+A9AtZk7Is5iuodnE/9Jhhiia9ctL+aXU+ wcQSKAXy2zydRaPJUsp8+ypmLXcVDvdSeN1SCSQ0Agmo3cKxTHsQthSfzJkIV98n5JUy Nspa6n+CMkPotk69X6eUCdlIUGnIb40wh7D3UCp9eIU5gqDZjuf8pawf258BmRJolTwQ UvLkK+ua4EHkJ4h6CwJEL6h9OqPttDPdkLO2ZRHnspF5sDKEiTFCYIP2tSsh+woYEond A/dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727942026; x=1728546826; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gF1CRK5658pUZV0uzy7B6zhR0H6HtzA+lmLE8dz6KjA=; b=ZfRLQXFZbWybPj/pth8sIphX7Jylgeq9KKSNbvLWfU/U8z6Cj9YkLBfqMUAPrvsq5b JTzqVZr7YQCRGDwxSwKjlH80bgN8xusoRkgKttkjS+e/WhMjUJpNMCxxqTLw77Rv7b29 559NKny/vAkptJHkY/APIrqrNEbM0778la4uQtzx5rc/yHeafuJvJmeugGSycAOVJX0B JN4g8ZR5mCpzhPNexbV9Bj5OSdXpDYqzBQyFf92H6jVOwoOECL8zfHGpTNd74CGTFoOL YkNoBl94W/65EwsSolUOY1kd6bA80nL21bNykshD04lRdix5lb7NNBLNTFpuxOu/fZOf 52Qg== X-Gm-Message-State: AOJu0Yzyz9xDmrOFIpVBIVTTpvZ8rW7Eg8VP45AfRkVAhgqDq9gZLgW4 WLDxaJ1DoAYuRteVZd1PCIgknVne4nOmmc8AdgbL5qDd1u3sjesHYrvQ4lwWHrAWFZUbB6j57+v w X-Google-Smtp-Source: AGHT+IHFdsOFLVd/0HLDP7ZzeOprKcDizHXOc1ot80O1tRrLN7wThoA4VqIC31U0IeN4wodp8pLJuQ== X-Received: by 2002:a05:600c:3c93:b0:42c:bb35:b6d0 with SMTP id 5b1f17b1804b1-42f777b0043mr19815795e9.1.1727942025822; Thu, 03 Oct 2024 00:53:45 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42f8025b583sm8740825e9.12.2024.10.03.00.53.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 00:53:44 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , Laurent Pinchart , Jacopo Mondi Subject: [PATCH v3 2/7] pipeline: rpi: Remove CameraData::scalerCrop_ Date: Thu, 3 Oct 2024 08:47:15 +0100 Message-Id: <20241003074720.18882-3-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241003074720.18882-1-naush@raspberrypi.com> References: <20241003074720.18882-1-naush@raspberrypi.com> MIME-Version: 1.0 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" Do not cache the scalerCrop_ parameter. The cached value is used to update the request metadata, but since this is not an expensive operation (and can only occur once per frame), caching it is of limited value. This will simplify logic in a future commit where we can specify a crop per-output stream. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- .../pipeline/rpi/common/pipeline_base.cpp | 18 +++--------------- .../pipeline/rpi/common/pipeline_base.h | 1 - 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 3041fd1ed9fd..11f1bfd4a5da 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -544,12 +544,6 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config) return ret; } - /* - * Set the scaler crop to the value we are using (scaled to native sensor - * coordinates). - */ - data->scalerCrop_ = data->scaleIspCrop(data->ispCrop_); - /* * Update the ScalerCropMaximum to the correct value for this camera mode. * For us, it's the same as the "analogue crop". @@ -569,7 +563,8 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config) /* Add the ScalerCrop control limits based on the current mode. */ Rectangle ispMinCrop = data->scaleIspCrop(Rectangle(data->ispMinCropSize_)); - ctrlMap[&controls::ScalerCrop] = ControlInfo(ispMinCrop, data->sensorInfo_.analogCrop, data->scalerCrop_); + ctrlMap[&controls::ScalerCrop] = ControlInfo(ispMinCrop, data->sensorInfo_.analogCrop, + data->scaleIspCrop(data->ispCrop_)); data->controlInfo_ = ControlInfoMap(std::move(ctrlMap), result.controlInfo.idmap()); @@ -1320,13 +1315,6 @@ void CameraData::applyScalerCrop(const ControlList &controls) if (ispCrop != ispCrop_) { ispCrop_ = ispCrop; platformSetIspCrop(); - - /* - * Also update the ScalerCrop in the metadata with what we actually - * used. But we must first rescale that from ISP (camera mode) pixels - * back into sensor native pixels. - */ - scalerCrop_ = scaleIspCrop(ispCrop_); } } } @@ -1483,7 +1471,7 @@ void CameraData::fillRequestMetadata(const ControlList &bufferControls, Request request->metadata().set(controls::SensorTimestamp, bufferControls.get(controls::SensorTimestamp).value_or(0)); - request->metadata().set(controls::ScalerCrop, scalerCrop_); + request->metadata().set(controls::ScalerCrop, scaleIspCrop(ispCrop_)); } } /* namespace libcamera */ diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h index f9cecf70f179..5161c16e518f 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h @@ -134,7 +134,6 @@ public: /* For handling digital zoom. */ IPACameraSensorInfo sensorInfo_; Rectangle ispCrop_; /* crop in ISP (camera mode) pixels */ - Rectangle scalerCrop_; /* crop in sensor native pixels */ Size ispMinCropSize_; unsigned int dropFrameCount_; From patchwork Thu Oct 3 07:47:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21489 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 3E23EBD80A for ; Thu, 3 Oct 2024 07:53:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B3B2A63534; Thu, 3 Oct 2024 09:53:55 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="KWQ94QDK"; dkim-atps=neutral Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1E28B6352B for ; Thu, 3 Oct 2024 09:53:48 +0200 (CEST) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-42caeb4d671so1084995e9.2 for ; Thu, 03 Oct 2024 00:53:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1727942027; x=1728546827; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IUr6Lw+NnsqPBWYBrmq0WF1o8u+vmudIqx4yHm1X3FA=; b=KWQ94QDKcIZTV89oybsdmmfmSpTfAaHuLGD0qu8Jr5I/Xbuh0HJA5q1p8jK1RGeHPg 1kHV6+8T+Ne4p5fmJQ6bJXj/4Bq4vLLnaxBOqcKV3+nOQIIIYD47OUIfajjW/L74lKoO 0cPZYmqPzmIRZb5sS8FDBKMJKtdYnMK2pLi07ggsaSt7hw+JvW2qY3a+ocQKX4pcHY1l MzCP9ySJd6/iXUNRimO+BiCYABoOYlV8cP3j2v/Jhws5kpnmN5ktyYcyI0YfTmfoLXyq ak5SasclVtDsghvGVc4CxxeE8EHQie69P9R/hmQJ42eNDLKpn40FIu3ZeofPeLZzQQdh s42g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727942027; x=1728546827; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IUr6Lw+NnsqPBWYBrmq0WF1o8u+vmudIqx4yHm1X3FA=; b=nw4HPxRrGRKSqJ9CtqzorEwlIjom8Hno46LtySWfPCCc27NvMGPy49QKe6bG2zmM0q BghdMHLCTxg9dhdFBWFyZx60j0QAbmLkh9h1aiBarzyjiBzUHkSsuRiugcBjhoT7Hp8a R0o0YAH0hvfDDNg4SQtgJ8vsvQhYmDywU4BNbn68Eo05SPTGo8STf1wPFdeSpEEOyYvu vlmy1BUMgmTltRdj/lWQ5d+v/Q95hWgIsPAiFNH92KP8BOADFUzz014/ANyuxlXzBfks dio1UBxzfzzmtFwAsbHoCFbOtbZRNcYbpgp7cek+K/UcXtckPrArnAwm+eZlEIwOML/Q dHGw== X-Gm-Message-State: AOJu0Yy9OKcckwvJNZ61kMge3MJptojIKNtkStGfmnW3OiQv/v/108bo deQ0c7Hy/WCWSnc31m5CuBhxqMccYBErpRUeMLA0ob7x+WPUe3YqvMUn0L3W8yZws/D8Xjx9AFu v X-Google-Smtp-Source: AGHT+IHKYMawzHSvDTiXHCEYRS931DsSrZB2hpyUO9PuGkywAYDDy01hLq1hlxUYtkavZw8PURWWdw== X-Received: by 2002:a05:600c:1897:b0:42c:aeee:da86 with SMTP id 5b1f17b1804b1-42f77d30905mr19539405e9.8.1727942027286; Thu, 03 Oct 2024 00:53:47 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42f8025b583sm8740825e9.12.2024.10.03.00.53.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 00:53:46 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , Laurent Pinchart , Jacopo Mondi Subject: [PATCH v3 3/7] pipeline: rpi: Pass crop rectangle as a parameter to platformSetIspCrop() Date: Thu, 3 Oct 2024 08:47:16 +0100 Message-Id: <20241003074720.18882-4-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241003074720.18882-1-naush@raspberrypi.com> References: <20241003074720.18882-1-naush@raspberrypi.com> MIME-Version: 1.0 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" This will be required when we program separate crop values to each ISP output in a future commit. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/libcamera/pipeline/rpi/common/pipeline_base.cpp | 2 +- src/libcamera/pipeline/rpi/common/pipeline_base.h | 2 +- src/libcamera/pipeline/rpi/vc4/vc4.cpp | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 11f1bfd4a5da..2de6111bacfd 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -1314,7 +1314,7 @@ void CameraData::applyScalerCrop(const ControlList &controls) if (ispCrop != ispCrop_) { ispCrop_ = ispCrop; - platformSetIspCrop(); + platformSetIspCrop(ispCrop); } } } diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h index 5161c16e518f..d65b695c30b5 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h @@ -83,7 +83,7 @@ public: Rectangle scaleIspCrop(const Rectangle &ispCrop) const; void applyScalerCrop(const ControlList &controls); - virtual void platformSetIspCrop() = 0; + virtual void platformSetIspCrop(const Rectangle &ispCrop) = 0; void cameraTimeout(); void frameStarted(uint32_t sequence); diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp index e5b6ef2b37cd..0ea032293bc9 100644 --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp @@ -109,9 +109,10 @@ public: Config config_; private: - void platformSetIspCrop() override + void platformSetIspCrop(const Rectangle &ispCrop) override { - isp_[Isp::Input].dev()->setSelection(V4L2_SEL_TGT_CROP, &ispCrop_); + Rectangle crop = ispCrop; + isp_[Isp::Input].dev()->setSelection(V4L2_SEL_TGT_CROP, &crop); } int platformConfigure(const RPi::RPiCameraConfiguration *rpiConfig) override; @@ -707,7 +708,7 @@ int Vc4CameraData::platformConfigure(const RPi::RPiCameraConfiguration *rpiConfi Size size = unicamFormat.size.boundedToAspectRatio(maxSize); ispCrop_ = size.centeredTo(Rectangle(unicamFormat.size).center()); - platformSetIspCrop(); + platformSetIspCrop(ispCrop_); return 0; } From patchwork Thu Oct 3 07:47:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21490 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 CB747C3263 for ; Thu, 3 Oct 2024 07:53:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C972363533; Thu, 3 Oct 2024 09:53:57 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="mp4bmExt"; dkim-atps=neutral Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CDC3462C93 for ; Thu, 3 Oct 2024 09:53:48 +0200 (CEST) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-42ca5447142so790045e9.2 for ; Thu, 03 Oct 2024 00:53:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1727942028; x=1728546828; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=M8Bkl1NDdbyVnMd9SQ2t2KujXMGXSf+tPA84EVzMo8I=; b=mp4bmExtV3a8+o4Y2Aiqm0rpFvxzXjgIWzUJEa7DCuRZ60i0z7VteReYhS6d24UiGy pUINW/yyJ7Q2NxzMUK2fmztiN5PYnqzU5vWAcW3i3H80RT5fL7oNB6eWp6DCsGORqGF+ p/ZZbxc3FB/jv5NxaE/p3B3xL7rq9+y4RUWd6jEACWlZU4A8bnexLRrDCUngzDeiTQOP 6wT8nGV6dzq4fmN3AR5tpvlzte525xtHSoXbKiXxhoW/ZY2ZGte08XcQ5d3ZJJnM/L4/ H717BbOSVhMDkfM3q5UqlieD2EXm7LPXbpzpZBDaM1fZCuKcrbi40EyRuialB+4Uhsf+ 0ERQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727942028; x=1728546828; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M8Bkl1NDdbyVnMd9SQ2t2KujXMGXSf+tPA84EVzMo8I=; b=gZuRp6gLjdR6lzTGSEkFu8ymrxXIcCpFgysrhCMhoxpcHRIdLc5IwDY05/h1MVVGcQ Jtcf6XKkTGAEEm0BhOWueEAB4uyT55xTV2Z0p8BXA9dJEwqpVLlVHd2ezeJBAAHp6o0j oJn0gOfB0pYI9k7HTow258ENzZ61YDqdRsafkMcpAgjuUnDxf9dgei+Ic3LUAzr+yFO3 iYbVmlsaDqKPc7a1cHRgtC4kQq4jjftmYi1MZVpXi1n8XXzCcOvwkdyy+XKVugFDY0KH KIm5+4hjQl6KbuMRpPrvRpcbPUo5YvlN1sz7PrKyii+lXARM5ttO6RhAGGAUQ/qPnQcM k6sg== X-Gm-Message-State: AOJu0Yww+fOYn1nswvR+TZoePUqUyuMyNrhDbQR5SEfivr4u+acN+vpS 5t5iFRVTW56P2d9seK/z7WG1sD3d6iZoy0x9m2OfFtvY8VA0xIIGEf/zUlJ6VUgrnwwScpEnBEA U X-Google-Smtp-Source: AGHT+IHCWT24O2VccjlTcpMASylk5mPzvX4f07X2Q2kDuP4nfT1nY5fB+b9zaiFTDpg9CJ+Mm6AmWw== X-Received: by 2002:a05:600c:4455:b0:42c:c0d8:bf49 with SMTP id 5b1f17b1804b1-42f7775453amr21329185e9.0.1727942027949; Thu, 03 Oct 2024 00:53:47 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42f8025b583sm8740825e9.12.2024.10.03.00.53.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 00:53:47 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , Laurent Pinchart , Jacopo Mondi Subject: [PATCH v3 4/7] pipeline: rpi: Introduce CameraData::CropParams Date: Thu, 3 Oct 2024 08:47:17 +0100 Message-Id: <20241003074720.18882-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241003074720.18882-1-naush@raspberrypi.com> References: <20241003074720.18882-1-naush@raspberrypi.com> MIME-Version: 1.0 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" In preparation for assigning separate crop windows for each stream, add a new CropParams structure that stores the existing ispCrop_ and ispMinCropSize_ as fields. Use a new std::map to store a CropParams structure where the map key is the index of the stream configuration in the CameraConfiguration vector. At preset, only a single CropParams structure will be set at key == 0 to preserve the existing crop handling logic. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- .../pipeline/rpi/common/pipeline_base.cpp | 28 +++++++++++++------ .../pipeline/rpi/common/pipeline_base.h | 17 +++++++++-- src/libcamera/pipeline/rpi/vc4/vc4.cpp | 12 ++++++-- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 2de6111bacfd..220c7b962280 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -533,6 +533,7 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config) * Platform specific internal stream configuration. This also assigns * external streams which get configured below. */ + data->cropParams_.clear(); ret = data->platformConfigure(rpiConfig); if (ret) return ret; @@ -561,10 +562,14 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config) for (auto const &c : result.controlInfo) ctrlMap.emplace(c.first, c.second); - /* Add the ScalerCrop control limits based on the current mode. */ - Rectangle ispMinCrop = data->scaleIspCrop(Rectangle(data->ispMinCropSize_)); - ctrlMap[&controls::ScalerCrop] = ControlInfo(ispMinCrop, data->sensorInfo_.analogCrop, - data->scaleIspCrop(data->ispCrop_)); + const auto cropParamsIt = data->cropParams_.find(0); + if (cropParamsIt != data->cropParams_.end()) { + const CameraData::CropParams &cropParams = cropParamsIt->second; + /* Add the ScalerCrop control limits based on the current mode. */ + Rectangle ispMinCrop = data->scaleIspCrop(Rectangle(cropParams.ispMinCropSize)); + ctrlMap[&controls::ScalerCrop] = ControlInfo(ispMinCrop, data->sensorInfo_.analogCrop, + data->scaleIspCrop(cropParams.ispCrop)); + } data->controlInfo_ = ControlInfoMap(std::move(ctrlMap), result.controlInfo.idmap()); @@ -1291,8 +1296,10 @@ Rectangle CameraData::scaleIspCrop(const Rectangle &ispCrop) const void CameraData::applyScalerCrop(const ControlList &controls) { const auto &scalerCrop = controls.get(controls::ScalerCrop); - if (scalerCrop) { + const auto cropParamsIt = cropParams_.find(0); + if (scalerCrop && cropParamsIt != cropParams_.end()) { Rectangle nativeCrop = *scalerCrop; + CropParams &cropParams = cropParamsIt->second; if (!nativeCrop.width || !nativeCrop.height) nativeCrop = { 0, 0, 1, 1 }; @@ -1308,12 +1315,12 @@ void CameraData::applyScalerCrop(const ControlList &controls) * 2. With the same mid-point, if possible. * 3. But it can't go outside the sensor area. */ - Size minSize = ispMinCropSize_.expandedToAspectRatio(nativeCrop.size()); + Size minSize = cropParams.ispMinCropSize.expandedToAspectRatio(nativeCrop.size()); Size size = ispCrop.size().expandedTo(minSize); ispCrop = size.centeredTo(ispCrop.center()).enclosedIn(Rectangle(sensorInfo_.outputSize)); - if (ispCrop != ispCrop_) { - ispCrop_ = ispCrop; + if (ispCrop != cropParams.ispCrop) { + cropParams.ispCrop = ispCrop; platformSetIspCrop(ispCrop); } } @@ -1471,7 +1478,10 @@ void CameraData::fillRequestMetadata(const ControlList &bufferControls, Request request->metadata().set(controls::SensorTimestamp, bufferControls.get(controls::SensorTimestamp).value_or(0)); - request->metadata().set(controls::ScalerCrop, scaleIspCrop(ispCrop_)); + const auto cropParamsIt = cropParams_.find(0); + if (cropParamsIt != cropParams_.end()) + request->metadata().set(controls::ScalerCrop, + scaleIspCrop(cropParamsIt->second.ispCrop)); } } /* namespace libcamera */ diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h index d65b695c30b5..88bd603193f4 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h @@ -133,8 +133,21 @@ public: /* For handling digital zoom. */ IPACameraSensorInfo sensorInfo_; - Rectangle ispCrop_; /* crop in ISP (camera mode) pixels */ - Size ispMinCropSize_; + + struct CropParams { + CropParams(Rectangle ispCrop_, Size ispMinCropSize_) + : ispCrop(ispCrop_), ispMinCropSize(ispMinCropSize_) + { + } + + /* Crop in ISP (camera mode) pixels */ + Rectangle ispCrop; + /* Minimum crop size in ISP output pixels */ + Size ispMinCropSize; + }; + + /* Mapping of CropParams keyed by the output stream order in CameraConfiguration */ + std::map cropParams_; unsigned int dropFrameCount_; diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp index 0ea032293bc9..8080f55a1cf4 100644 --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp @@ -702,13 +702,19 @@ int Vc4CameraData::platformConfigure(const RPi::RPiCameraConfiguration *rpiConfi /* Figure out the smallest selection the ISP will allow. */ Rectangle testCrop(0, 0, 1, 1); isp_[Isp::Input].dev()->setSelection(V4L2_SEL_TGT_CROP, &testCrop); - ispMinCropSize_ = testCrop.size(); /* Adjust aspect ratio by providing crops on the input image. */ Size size = unicamFormat.size.boundedToAspectRatio(maxSize); - ispCrop_ = size.centeredTo(Rectangle(unicamFormat.size).center()); + Rectangle ispCrop = size.centeredTo(Rectangle(unicamFormat.size).center()); - platformSetIspCrop(ispCrop_); + platformSetIspCrop(ispCrop); + /* + * Set the scaler crop to the value we are using (scaled to native sensor + * coordinates). + */ + cropParams_.emplace(std::piecewise_construct, + std::forward_as_tuple(0), + std::forward_as_tuple(ispCrop, testCrop.size())); return 0; } From patchwork Thu Oct 3 07:47:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21491 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 9109DBD80A for ; Thu, 3 Oct 2024 07:54:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1868C63530; Thu, 3 Oct 2024 09:53:59 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="g56uDgdd"; dkim-atps=neutral Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 815EB6352C for ; Thu, 3 Oct 2024 09:53:49 +0200 (CEST) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-42cae563348so1105895e9.0 for ; Thu, 03 Oct 2024 00:53:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1727942029; x=1728546829; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=m+HMPpTvzYXkSdblmG4sRCzch1p6qCvF2EX9uYU6P/c=; b=g56uDgddQ2R6OTMKxECBBYkOpK01NkQWDPjjHpzUSsh3sbB8TiFNQAmNziT2W84Omf OI+LUtj+Li6l/9JvwGSdDo6rwwoNcnqSp1vXW3Ui339fotmgag/HHbtRcXeULYw0Ibm1 IbbKvnJKv5243i1rojk3AJ26ycnIOIP9QMiZe8CstWRvnWhrQ29IAx9WUtnYgJI3fABo Hrw5n2l36u5Q58InfeRHk/jijq/cu5K+ZhbSEdpVANT6pFOIBZAyc5DSFazZUp4o0xs6 XhWdkvaXEVJRMDSvSMpta7z6rf4orVN5YlJTPzaGP1B2Ycu7ClCR50kq8GYftGkATT3h VlFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727942029; x=1728546829; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=m+HMPpTvzYXkSdblmG4sRCzch1p6qCvF2EX9uYU6P/c=; b=bd9gzOvoscskOiQIhdVD41jqKGX6pEv/m6LC5qVP9ltJY6N/WreGX+YIglTs0wSGSP bbFyrMfxq4bonkFA2BWrKkywV/pOvPNV1uPyuTxQfUGJM8K4f4EglBpiN1m0a+ifGM3s +LnV1xUjbbrvXEdcxUHd0T5iG2u64UsdlJuWQcs4VVOQWI8qKZMc4fGXXOrNPRl9nuKY KQ0cfq5bEapYaGkvsG7nnbLNOKiFKye7SCbiHT2zrUjo5VT92j/+My0GR2iAbuflby7p g/vrqw36HYn9xRuEdqv+tUuRP7M58F9Rb4igZuoGJ6JPe1GkfFqQX5WaHw0TECDBDNvM 5BWg== X-Gm-Message-State: AOJu0Yy6qFnkAHO35M9ojBwRTBfNHy3cDcTwiXNK8paxLYzx+rarXnRl kCUHYihfEay/wWTA2NTlbM4EA00j+ziRkFtalu93JEMZcMPd1plX1HO6s73M1JCezlhio1z1+Bt u X-Google-Smtp-Source: AGHT+IHdf2DX5E19P4CGwDzfmAFfUi//erzlBIbG7DzSjnNiFNsWJywdXgVFwuP0dQqwWj69bwb2nw== X-Received: by 2002:a05:600c:3ba2:b0:42c:baba:13cb with SMTP id 5b1f17b1804b1-42f7d0a1371mr11327285e9.2.1727942028652; Thu, 03 Oct 2024 00:53:48 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42f8025b583sm8740825e9.12.2024.10.03.00.53.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 00:53:48 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , Laurent Pinchart , Jacopo Mondi Subject: [PATCH v3 5/7] pipeline: rpi: Track which ISP output is configured for a stream Date: Thu, 3 Oct 2024 08:47:18 +0100 Message-Id: <20241003074720.18882-6-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241003074720.18882-1-naush@raspberrypi.com> References: <20241003074720.18882-1-naush@raspberrypi.com> MIME-Version: 1.0 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" Add a ispIndex field to CropParams that is used to track which ISP output (0/1) will be used for a given stream during configuration. Tracking this information is required for an upcoming change where crop rectangles can be specified for each configured stream. Currently, the value is fixed to 0. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/libcamera/pipeline/rpi/common/pipeline_base.h | 6 ++++-- src/libcamera/pipeline/rpi/vc4/vc4.cpp | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h index 88bd603193f4..9912796ec472 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h @@ -135,8 +135,8 @@ public: IPACameraSensorInfo sensorInfo_; struct CropParams { - CropParams(Rectangle ispCrop_, Size ispMinCropSize_) - : ispCrop(ispCrop_), ispMinCropSize(ispMinCropSize_) + CropParams(Rectangle ispCrop_, Size ispMinCropSize_, unsigned int ispIndex_) + : ispCrop(ispCrop_), ispMinCropSize(ispMinCropSize_), ispIndex(ispIndex_) { } @@ -144,6 +144,8 @@ public: Rectangle ispCrop; /* Minimum crop size in ISP output pixels */ Size ispMinCropSize; + /* Index of the ISP output channel for this crop */ + unsigned int ispIndex; }; /* Mapping of CropParams keyed by the output stream order in CameraConfiguration */ diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp index 8080f55a1cf4..cfed214ddbd4 100644 --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp @@ -714,7 +714,7 @@ int Vc4CameraData::platformConfigure(const RPi::RPiCameraConfiguration *rpiConfi */ cropParams_.emplace(std::piecewise_construct, std::forward_as_tuple(0), - std::forward_as_tuple(ispCrop, testCrop.size())); + std::forward_as_tuple(ispCrop, testCrop.size(), 0)); return 0; } From patchwork Thu Oct 3 07:47:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21492 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 3A983C3263 for ; Thu, 3 Oct 2024 07:54:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 85B2163525; Thu, 3 Oct 2024 09:54:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="rjZa180l"; dkim-atps=neutral Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 24DD46352D for ; Thu, 3 Oct 2024 09:53:50 +0200 (CEST) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-42cb0d0311fso797625e9.1 for ; Thu, 03 Oct 2024 00:53:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1727942029; x=1728546829; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KemNgYMBW8186eLynbOGC1vQGWAH0T0PqLUvHvsVvSM=; b=rjZa180lsOn3j+16nwd8G4vKcPGkX+h+nSm47gKj1YWynRfp2BAKtjPPfaONr+ySLp 0Uk7gMljfAmBSGuThzt3iwCsSjgH5sCDRYlOqxbi5o3sZ8PJJCf3QRWg67VgiwvxJPxk DruJHPdyQx5K89ReaWDUXNss4EodiTNSnDsLRE8znATi94BHNr0SsnbqwwF8nugHFSdo MHGRUGwwOKtMs/cMY4qYL3wW7gCUcJby+/vpvwvmauUGO/iMPXlri++GEWBw1Y9SGarq m+VbpWl35E9mfNPVLhX9BEnhB4zOmV9779XmTGvl1tBD79s9z5rUoH8CdPImCtOo4ad7 MqLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727942029; x=1728546829; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KemNgYMBW8186eLynbOGC1vQGWAH0T0PqLUvHvsVvSM=; b=SmcTFbp4kXkxRNk5vpfZSYu/fRxL68DYESbXzB/QLagDDYOjlp9RrmNiP+q2a5eBY7 SerHb8VYkHtxdfwOgbGvnhLK+v1vWTwg7n/o3Cnnwc8kpJypz1FvdDmgjAAf+Bo7j3hH 0nh3F7AFYyyfMecYLBqN9bHEb2zFWoQZWKHYHc98IHZ+QH1rNM+bPbp46pDRNrhN36+B HP0e1UQ5MovyIIz0pyCSsT+zwn1zViTzLEzHfsiBcjOJK5aGXKUHCxexhHBVraiz5OQq 1mdYI+Sg2hoZp6nmERcLerLLM4DrDLFC11O2hvsX2Bofe2TbQre4FUthoXnar8CVScXw +sOw== X-Gm-Message-State: AOJu0Yx7pcK3fAnSDSdGG64xNp5byhTY+81eu18VBPqw3OWiaFWr2i+W XYdlFyvCwR0QqWhzZstVbNyUvqR+anpM3z4XbFva09yvfmTjQC/63fRwkNykpIq3Wi8qEz7Pssy Q X-Google-Smtp-Source: AGHT+IGtUUmUoxZajtIDfK46wOvyoL8JBuAtWUI6H7NYxYY4yTvraNd1kikvzohqJwXu9n6n+4ztQw== X-Received: by 2002:a05:600c:1d26:b0:42c:bfd6:9d1f with SMTP id 5b1f17b1804b1-42f777b010bmr21671845e9.1.1727942029335; Thu, 03 Oct 2024 00:53:49 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42f8025b583sm8740825e9.12.2024.10.03.00.53.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 00:53:48 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , Laurent Pinchart , Jacopo Mondi Subject: [PATCH v3 6/7] pipeline: rpi: Pass ISP output index into platformSetIspCrop() Date: Thu, 3 Oct 2024 08:47:19 +0100 Message-Id: <20241003074720.18882-7-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241003074720.18882-1-naush@raspberrypi.com> References: <20241003074720.18882-1-naush@raspberrypi.com> MIME-Version: 1.0 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" At this point, the index is unused, but will be in a future commit where we can set different crops on each ISP output. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/libcamera/pipeline/rpi/common/pipeline_base.cpp | 2 +- src/libcamera/pipeline/rpi/common/pipeline_base.h | 2 +- src/libcamera/pipeline/rpi/vc4/vc4.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 220c7b962280..267e6bd9cd70 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -1321,7 +1321,7 @@ void CameraData::applyScalerCrop(const ControlList &controls) if (ispCrop != cropParams.ispCrop) { cropParams.ispCrop = ispCrop; - platformSetIspCrop(ispCrop); + platformSetIspCrop(cropParams.ispIndex, ispCrop); } } } diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h index 9912796ec472..aae0c2f35888 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h @@ -83,7 +83,7 @@ public: Rectangle scaleIspCrop(const Rectangle &ispCrop) const; void applyScalerCrop(const ControlList &controls); - virtual void platformSetIspCrop(const Rectangle &ispCrop) = 0; + virtual void platformSetIspCrop(unsigned int index, const Rectangle &ispCrop) = 0; void cameraTimeout(); void frameStarted(uint32_t sequence); diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp index cfed214ddbd4..fd8d84b14f15 100644 --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp @@ -109,7 +109,7 @@ public: Config config_; private: - void platformSetIspCrop(const Rectangle &ispCrop) override + void platformSetIspCrop([[maybe_unused]] unsigned int index, const Rectangle &ispCrop) override { Rectangle crop = ispCrop; isp_[Isp::Input].dev()->setSelection(V4L2_SEL_TGT_CROP, &crop); @@ -707,7 +707,7 @@ int Vc4CameraData::platformConfigure(const RPi::RPiCameraConfiguration *rpiConfi Size size = unicamFormat.size.boundedToAspectRatio(maxSize); Rectangle ispCrop = size.centeredTo(Rectangle(unicamFormat.size).center()); - platformSetIspCrop(ispCrop); + platformSetIspCrop(0, ispCrop); /* * Set the scaler crop to the value we are using (scaled to native sensor * coordinates). From patchwork Thu Oct 3 07:47:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 21493 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 9509DC32DB for ; Thu, 3 Oct 2024 07:54:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 719A163530; Thu, 3 Oct 2024 09:54:03 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="TS5R9rXD"; dkim-atps=neutral Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D089563530 for ; Thu, 3 Oct 2024 09:53:50 +0200 (CEST) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-42ca4e0014dso949645e9.2 for ; Thu, 03 Oct 2024 00:53:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1727942030; x=1728546830; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LJAXZj7wiaO7Oa3XnUk7pfIlTYztCA94P+HfSdQLQC0=; b=TS5R9rXDgDsMMskVOO3InYtZrvI6b6ipUdWqKvW7giYvlx+mXBiu4PyCScP5/CKNwK 6I7ytxUem6/DrZaVfbIkBGIj7rpEG6g2lV0pWrXYpeLIPTxnkgM1ozZammmjcti2HDpI COetDdciwdjfHgzuBspMR0lamc18td8eVkmsKm6VrU8Tsgl0C8N7mX9cf6CxIeqZaX4q 8G4nWV3EgXv8wd7URwpttVUNtvZ8wvVlfyEpPI7KvaGhrsQwT5bFAYXEdAr9AysI/34B z3QXrMQR1oNqG2bw3XbnF2nfsGN6/aAyrCIt4JcKjSKN+IPIoQmScq7xP22uFX8xIm5Q CpGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727942030; x=1728546830; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LJAXZj7wiaO7Oa3XnUk7pfIlTYztCA94P+HfSdQLQC0=; b=pQc1VX2B0wsB0BhxA8oh+PWeYVOQxM+pk1AjFuIUOz7kjD8z69win+LwgUQCdBF2Oc 3vB5m5xNhS3PKYgr87Zk86RsFQdyITDIwGQrLXuv9sHTVs3ftU+xI6VPmGCEtTFAHZjn NUeHprVytQIZFmpwenFJFeEDDq8lzocqFMq0txDJnP8vMGU4fFw8XlUGQus7z+QmOu9E zWq7xTWgNHrrOzFddogTXSJp2RdPvWQ/j4C1p647D7asOtLBs/KHldnghY4dJr48hrLD 75PzaX1fqzIz4fIGA+NyycmynKcV1OFnWW2isIwIWyr4MP1GOp8xr3X+ZlSFqCEpRTA2 zeEg== X-Gm-Message-State: AOJu0YwyVz3st4JQ/kN8sDB9AdJm4Jx+qY6uOr343tzz5GbMTBKCfCvi a9GX2WpXzp7X6UM8IxzSXKptnRejOKTOzlb2gJhCliskWvIi2NLc8UNzV94huZmYsQMBQH8Qc2b Z X-Google-Smtp-Source: AGHT+IGqKnJO7cDNKvE+rq+2a48gxIUnBho1u9T434peERQGuKb20WclxJqVo8hhP0E8bFC45jVS4Q== X-Received: by 2002:a05:600c:4f50:b0:42c:c59a:ac21 with SMTP id 5b1f17b1804b1-42f777b0b7fmr21661395e9.2.1727942029973; Thu, 03 Oct 2024 00:53:49 -0700 (PDT) Received: from naush-laptop.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42f8025b583sm8740825e9.12.2024.10.03.00.53.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 00:53:49 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Naushir Patuck , Jacopo Mondi Subject: [PATCH v3 7/7] pipeline: rpi: Handler controls::rpi::ScalerCrops Date: Thu, 3 Oct 2024 08:47:20 +0100 Message-Id: <20241003074720.18882-8-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241003074720.18882-1-naush@raspberrypi.com> References: <20241003074720.18882-1-naush@raspberrypi.com> MIME-Version: 1.0 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" Handle multiple scaler crops being set through the rpi::ScalerCrops control. We now populate the cropParams_ map in the loop where we handle the output stream configuration items. The key of this map is the index of the stream configuration structure set by the application. This will also be the same index used to specify the crop rectangles through the ScalerCrops control. CameraData::applyScalerCrop() has been adapted to look at either controls::ScalerCrop or controls::rpi::ScalerCrops. The former takes priority over the latter, and if present, will apply the same scaler crop to all output streams. Finally return all crops through the same ScalerCrops control via request metadata. The first configure stream's crop rectangle is also returned via the ScalerCrop control in the request metadata. Signed-off-by: Naushir Patuck Reviewed-by: Jacopo Mondi --- .../pipeline/rpi/common/pipeline_base.cpp | 76 ++++++++++++++----- 1 file changed, 59 insertions(+), 17 deletions(-) diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 267e6bd9cd70..eba4dad6d212 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -181,12 +181,14 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() rawStreams_.clear(); outStreams_.clear(); + unsigned int rawStreamIndex = 0; + unsigned int outStreamIndex = 0; - for (const auto &[index, cfg] : utils::enumerate(config_)) { + for (auto &cfg : config_) { if (PipelineHandlerBase::isRaw(cfg.pixelFormat)) - rawStreams_.emplace_back(index, &cfg); + rawStreams_.emplace_back(rawStreamIndex++, &cfg); else - outStreams_.emplace_back(index, &cfg); + outStreams_.emplace_back(outStreamIndex++, &cfg); } /* Sort the streams so the highest resolution is first. */ @@ -565,10 +567,24 @@ int PipelineHandlerBase::configure(Camera *camera, CameraConfiguration *config) const auto cropParamsIt = data->cropParams_.find(0); if (cropParamsIt != data->cropParams_.end()) { const CameraData::CropParams &cropParams = cropParamsIt->second; - /* Add the ScalerCrop control limits based on the current mode. */ + /* + * Add the ScalerCrop control limits based on the current mode and + * the first configured stream. + */ Rectangle ispMinCrop = data->scaleIspCrop(Rectangle(cropParams.ispMinCropSize)); ctrlMap[&controls::ScalerCrop] = ControlInfo(ispMinCrop, data->sensorInfo_.analogCrop, data->scaleIspCrop(cropParams.ispCrop)); + if (data->cropParams_.size() == 2) { + /* + * The control map for rpi::ScalerCrops has the min value + * as the default crop for stream 0, max value as the default + * value for stream 1. + */ + ctrlMap[&controls::rpi::ScalerCrops] = + ControlInfo(data->scaleIspCrop(data->cropParams_.at(0).ispCrop), + data->scaleIspCrop(data->cropParams_.at(1).ispCrop), + ctrlMap[&controls::ScalerCrop].def()); + } } data->controlInfo_ = ControlInfoMap(std::move(ctrlMap), result.controlInfo.idmap()); @@ -1295,11 +1311,29 @@ Rectangle CameraData::scaleIspCrop(const Rectangle &ispCrop) const void CameraData::applyScalerCrop(const ControlList &controls) { - const auto &scalerCrop = controls.get(controls::ScalerCrop); - const auto cropParamsIt = cropParams_.find(0); - if (scalerCrop && cropParamsIt != cropParams_.end()) { - Rectangle nativeCrop = *scalerCrop; - CropParams &cropParams = cropParamsIt->second; + const auto &scalerCropRPi = controls.get>(controls::rpi::ScalerCrops); + const auto &scalerCropCore = controls.get(controls::ScalerCrop); + std::vector scalerCrops; + + /* + * First thing to do is create a vector of crops to apply to each ISP output + * based on either controls::ScalerCrop or controls::rpi::ScalerCrops if + * present. + * + * If controls::ScalerCrop is present, apply the same crop to all ISP output + * streams. Otherwise if controls::rpi::ScalerCrops, apply the given crops + * to the ISP output streams, indexed by the same order in which they had + * been configured. This is not the same as the ISP output index. + */ + for (unsigned int i = 0; i < cropParams_.size(); i++) { + if (scalerCropRPi && i < scalerCropRPi->size()) + scalerCrops.push_back(scalerCropRPi->data()[i]); + else if (scalerCropCore) + scalerCrops.push_back(*scalerCropCore); + } + + for (auto const &[i, scalerCrop] : utils::enumerate(scalerCrops)) { + Rectangle nativeCrop = scalerCrop; if (!nativeCrop.width || !nativeCrop.height) nativeCrop = { 0, 0, 1, 1 }; @@ -1315,13 +1349,13 @@ void CameraData::applyScalerCrop(const ControlList &controls) * 2. With the same mid-point, if possible. * 3. But it can't go outside the sensor area. */ - Size minSize = cropParams.ispMinCropSize.expandedToAspectRatio(nativeCrop.size()); + Size minSize = cropParams_.at(i).ispMinCropSize.expandedToAspectRatio(nativeCrop.size()); Size size = ispCrop.size().expandedTo(minSize); ispCrop = size.centeredTo(ispCrop.center()).enclosedIn(Rectangle(sensorInfo_.outputSize)); - if (ispCrop != cropParams.ispCrop) { - cropParams.ispCrop = ispCrop; - platformSetIspCrop(cropParams.ispIndex, ispCrop); + if (ispCrop != cropParams_.at(i).ispCrop) { + cropParams_.at(i).ispCrop = ispCrop; + platformSetIspCrop(cropParams_.at(i).ispIndex, ispCrop); } } } @@ -1478,10 +1512,18 @@ void CameraData::fillRequestMetadata(const ControlList &bufferControls, Request request->metadata().set(controls::SensorTimestamp, bufferControls.get(controls::SensorTimestamp).value_or(0)); - const auto cropParamsIt = cropParams_.find(0); - if (cropParamsIt != cropParams_.end()) - request->metadata().set(controls::ScalerCrop, - scaleIspCrop(cropParamsIt->second.ispCrop)); + if (cropParams_.size()) { + std::vector crops; + + for (auto const &[k, v] : cropParams_) + crops.push_back(scaleIspCrop(v.ispCrop)); + + request->metadata().set(controls::ScalerCrop, crops[0]); + if (crops.size() > 1) { + request->metadata().set(controls::rpi::ScalerCrops, + Span(crops.data(), crops.size())); + } + } } } /* namespace libcamera */