From patchwork Mon May 18 14:22:27 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 26767 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 8111EBDCBD for ; Mon, 18 May 2026 14:26:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 654EE62FD3; Mon, 18 May 2026 16:26:06 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="WNe2QW2H"; 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 52C3E62FB1 for ; Mon, 18 May 2026 16:26:04 +0200 (CEST) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-488b8bc6bc9so13584055e9.3 for ; Mon, 18 May 2026 07:26:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1779114363; x=1779719163; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=mrk23Gkd1SxujjgkYP6Pca+LtlEzBxLVI0f/pr7Kbqs=; b=WNe2QW2HVMWryjUyHNHq6BsPA50lyjNgXRepxc2JxNVAfGJs3Bhq5UT7yUXBztkqp/ Ceriaccqtt2aoFVPSdoOagMoqZ+q65uh4IoGrfFO3jE6nNw1qQXDw/mt1EzUiZOXOf9v R3brcSmbkP+EtpKbRUlnx6ETyG3NDohSsapQGjT1r0qy5SkgXxFxdhs4Rjzkjrv3dbqw do/D4a41w5xft8u4M8KK+H1V5Lwcsr1X0wSsuJttQEtZHCZo3jGDyjZ+HzAKo0ucXb7/ jiZMbQdouNBHgb+VH/AV3MuBA6fhOaSnoIWOEx0R+/8/SU/VxNQso040mFYlnRBgFJsk 1sOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779114363; x=1779719163; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=mrk23Gkd1SxujjgkYP6Pca+LtlEzBxLVI0f/pr7Kbqs=; b=nJFylEAruYDL2Np3tkLNT3n2jjIA8YaZlesdC/sG5SeEgQB4f44aliMxEDtfkcyvoj n7BCQNR+CLPLGelFUA85x7IcJNRb1AJ8s0dcmzGxLDXWsn77FFH0lWsjAfgD1ShmcCs3 A9HcflajCoyyHjLJr2xnYVoSnApJjpNWUvF56bbig+esJ8Onvc1N2A3s8cAXWFcMu+PT zGQtsqSiU6nHBo5C54D7RL1RMdKkMStJN0j7sjnME5fPG9We+GqlmitWkVGzKi8CR3QW tueHHFJuLk479rHAk9YrYCLKzMZy7yLZKzrhP4xUJZYVM6aucSzzbDferuvZKZVuCJJb wZEA== X-Gm-Message-State: AOJu0YzoJsfCV3nGvE4uVS69L7rAdOJXhSgANF0GN2lPXOo9PnbmzzNj KgWB+NrZ77+h7RPmoQ+xx6Qx970K8FkPyE8IOeOP/MGbUvHoDIhPMK4xVzV2grfgWHGyvOcIhP1 X31qnhlU= X-Gm-Gg: Acq92OFaFl0fAwE0o5b5RUozdY4ImiBEgg6TPG9O6eOvqOD4T7/tcGa+TUyb+Hfnl/h 7i+/URH5/wplMOLc6oGL9YIKYK+kOUPqlBC+TtHIEH9zqXpH6nx3h1EGrpQvDiLkdnfUw/hfDQt Al9JnkzfkfSrfnkkqcjfU+poz7wQXKy+qj9C06KG2yk2C4EV1iNKP7lz0HPJOApycng1WQP1UMo AS2hoUKYsZKGX2YQRSRv7VCxqRVUo7gRK6JGU99qMniNfoghZSuBmpq2PiM518W87Q7avmpWKBr NnAQAW9rijFcF0LnX4RUdrxC1Y+yTyaUsU6MtmsoY80UxHegz1sO5o+RzMtXUvww4sykwxp+q3s MBYcosWX/yaFrlh8XZs+L5FnhEd/8MeiwqzTqGYwcgP7aNMfEuqezxLU52yYruIDdEpHyzR9n7g AsBTKQ6hcoIWCiIFGoqBK80pUqreIBSFxEke8mGCNHGm9ssROHwnA72/lQksYbQMuZp01VYE6Ch jub9bCwbxLHtajrP4v+FMfy0yjRkOhavVXgX7Xf41g= X-Received: by 2002:a05:600c:c096:b0:48f:d1b8:9aaa with SMTP id 5b1f17b1804b1-48fe60e525bmr176321795e9.6.1779114363490; Mon, 18 May 2026 07:26:03 -0700 (PDT) Received: from davidp-pi5.pitowers.org ([2a00:1098:3142:1f:fcab:48df:35ab:5c26]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48fffb9aac4sm255817905e9.9.2026.05.18.07.26.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 07:26:03 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: David Plowman Subject: [PATCH v1] ipa: rpi: Improve control over which sensor modes require "debinning" Date: Mon, 18 May 2026 15:22:27 +0100 Message-ID: <20260518142600.6546-1-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.47.3 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" "Debinning" is the process that corrects the spatial sampling of pixels when this has been disturbed by the standard binning process. However, debinning is not required for sensors that do it themselves, or for quad Bayer sensors at 2x2 binning where the spatial sampling is already correct. Here we add a getMinDebinFactor() to the CamHelper which allows us to customise at what binning (or downscaling) factor we need to apply the correction. This value is then used to decide whether to enable the relevant PiSP block. Signed-off-by: David Plowman --- src/ipa/rpi/cam_helper/cam_helper.cpp | 6 ++++++ src/ipa/rpi/cam_helper/cam_helper.h | 6 ++++++ src/ipa/rpi/cam_helper/cam_helper_imx708.cpp | 7 +++++++ src/ipa/rpi/pisp/pisp.cpp | 8 +++++--- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/ipa/rpi/cam_helper/cam_helper.cpp b/src/ipa/rpi/cam_helper/cam_helper.cpp index a78db9c1..dfdcd167 100644 --- a/src/ipa/rpi/cam_helper/cam_helper.cpp +++ b/src/ipa/rpi/cam_helper/cam_helper.cpp @@ -204,6 +204,12 @@ unsigned int CamHelper::mistrustFramesModeSwitch() const return 0; } +unsigned int CamHelper::getMinDebinFactor() const +{ + /* Most cameras require debinning from 2x2 binning upwards. */ + return 2; +} + void CamHelper::parseEmbeddedData(Span buffer, Metadata &metadata) { diff --git a/src/ipa/rpi/cam_helper/cam_helper.h b/src/ipa/rpi/cam_helper/cam_helper.h index 4a826690..349891c4 100644 --- a/src/ipa/rpi/cam_helper/cam_helper.h +++ b/src/ipa/rpi/cam_helper/cam_helper.h @@ -62,6 +62,11 @@ namespace RPiController { * MistrustFramesModeSwitch(): The number of frames, after a mode switch * (other than start-up), for which control algorithms should not run * (for example, metadata may be unreliable). + * getMinDebinFactor(): the binning factor after which we should apply + * "debinning", which corrects for the uneven spatial sampling of the + * standard binning process. A return value of 2 means to enable + * debinning for camera modes using 2x2, or larger, binning. A return + * value of zero means never to enable binning. */ class CamHelper @@ -93,6 +98,7 @@ public: virtual unsigned int hideFramesModeSwitch() const; virtual unsigned int mistrustFramesStartup() const; virtual unsigned int mistrustFramesModeSwitch() const; + virtual unsigned int getMinDebinFactor() const; protected: void parseEmbeddedData(libcamera::Span buffer, diff --git a/src/ipa/rpi/cam_helper/cam_helper_imx708.cpp b/src/ipa/rpi/cam_helper/cam_helper_imx708.cpp index 6150909c..e7b8d671 100644 --- a/src/ipa/rpi/cam_helper/cam_helper_imx708.cpp +++ b/src/ipa/rpi/cam_helper/cam_helper_imx708.cpp @@ -58,6 +58,7 @@ public: double getModeSensitivity(const CameraMode &mode) const override; unsigned int hideFramesModeSwitch() const override; unsigned int hideFramesStartup() const override; + unsigned int getMinDebinFactor() const override; private: /* @@ -237,6 +238,12 @@ unsigned int CamHelperImx708::hideFramesStartup() const return hideFramesModeSwitch(); } +unsigned int CamHelperImx708::getMinDebinFactor() const +{ + /* Quad-Bayer sensor, so debinning required only at 4x4 binning. */ + return 4; +} + void CamHelperImx708::populateMetadata(const MdParser::RegisterMap ®isters, Metadata &metadata) const { diff --git a/src/ipa/rpi/pisp/pisp.cpp b/src/ipa/rpi/pisp/pisp.cpp index de2a6afe..fd28fc38 100644 --- a/src/ipa/rpi/pisp/pisp.cpp +++ b/src/ipa/rpi/pisp/pisp.cpp @@ -1078,12 +1078,14 @@ void IpaPiSP::setStatsAndDebin() pisp_be_global_config beGlobal; be_->GetGlobal(beGlobal); - if (mode_.binX > 1 || mode_.binY > 1) { + unsigned int minDebinFactor = helper_->getMinDebinFactor(); + if (minDebinFactor && + (mode_.binX >= minDebinFactor || mode_.binY >= minDebinFactor)) { pisp_be_debin_config debin; be_->GetDebin(debin); - debin.h_enable = (mode_.binX > 1); - debin.v_enable = (mode_.binY > 1); + debin.h_enable = (mode_.binX >= minDebinFactor); + debin.v_enable = (mode_.binY >= minDebinFactor); be_->SetDebin(debin); beGlobal.bayer_enables |= PISP_BE_BAYER_ENABLE_DEBIN; } else