From patchwork Fri Oct 16 20:28:10 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ray Strode X-Patchwork-Id: 28475 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 3930BC324C for ; Fri, 16 Oct 2026 20:28:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 01AC168E42; Fri, 16 Oct 2026 22:28:36 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Amy0+IR1"; dkim-atps=neutral Received: from mail-vk1-xa2c.google.com (mail-vk1-xa2c.google.com [IPv6:2607:f8b0:4864:20::a2c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9E74E68E44 for ; Fri, 16 Oct 2026 22:28:32 +0200 (CEST) Received: by mail-vk1-xa2c.google.com with SMTP id 71dfb90a1353d-5e9528732b4so242025e0c.0 for ; Fri, 16 Oct 2026 13:28:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792182511; x=1792787311; 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:content-type; bh=ESp1FMYlRGar1R88XIXlQKmy4hkriyl4lEm0aN2dmdk=; b=Amy0+IR16gZYwfdYcAntuhgiQ5hlAK7HCKP0kC1rB+qsQN8xHA+1GYPnK3z7dAHt1X DII/t7irRTvlKYkAsIna0TfR6ut10Q3dab+HEg7RDLV0YK4bsvlsJhdWz4qvGibKR5l5 KQbZb74IIYCpnzuPJgP5VE40R8awQa0cPW1u/aCdsQLdgpw0c8Iz5KH0IUVXCU20NzVo zndfitjag3mbeoEYmxX6iSdAKDDHV+VvN+lKce8lb82Z5kVuQJQ04TqUJ6ApQz60K7SV /mWEitQypjEzji7NI9Y11Ucya6liFHcKV1UDH/xCwQd4dWmDSIZTSQNc8l9UgUhpm0mV 0qJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792182511; x=1792787311; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=ESp1FMYlRGar1R88XIXlQKmy4hkriyl4lEm0aN2dmdk=; b=LnBse+fcbVa4R8IGZ7b/lAUqkarldYyaIxy9XvjgjMMyH3ermGoM2doWFNs8hXAiIT wscts+k+UNMfeLzIVZRrfPZoCybT2GKpX+QotEv9auyFZBDJ3ZG1mqeMcRIHcL2FPRKT CXdWSlHFTntC6s5qoXmt0jUYC1G6/zDi7Bxi2Kg8nWnbAco1hyWcPx12Rml0Om6IHqfk d/WNGAo0PGOuP638Po5wCxX5Z3GYGHmYHkXOtaDL2Oyo5p1+P/4xuFV8cSOXex72s0Ho 7wo6xwAUsUX74dHfIgRfjg3L/MWzkux5F7YxXX1nFKNWzUcux7H87h3SXyV14po8rpwJ gO/w== X-Gm-Message-State: AFq9FYKKeCzeADj6/KOXmvtFB5sFJVMDAwL5TZmQ7lyqYTLQnBkEud2t za7Zcvi/RPE+64kG07JGf975uPF6Ja9wNM9MSd3aoxcKm+jboLWS+Wb3X9mtTjW4wWU= X-Gm-Gg: AYBFou2UBIGv0ucIjV8b8sjI9ENrwFaF+h/92twKVrH12SV7HW6u2SsYFtXH/h+UqVh dfgtAWZenFNM6iZOvk/y+GzO0Nf1WGq0wOs+jFzacc7UYr5E4IJkeNrcGNDKIZPI9V3NcUUKcGy 7M2nPHtCUSgNgm9wUceVUt1SmbAa3B6zDrggVl9kVFL+3lPfn09bQmaZDBUXq+uPEXIzrdVpDC9 Z0meejw3434lAAixRPz+hrLKmNe43h6P2d/n/j0gxdvLWNhZ7mw5a/5AwelWRznvyHJayUZhXKR ucZ23kyFCvSKsO6KE0Eh+jWRLxlcn+2h3ch0eGZBpatcQm0BiVsINq2IqPwK1/33atnV2i8nabI SShEcXWtNhgwY59gvz5JCEfqlTu+cbFt3vhC3G+D0B+ICOfpPqb0FetJweYdIFIpAROS89foO1I vUYWoKQxgO6Qr7Z8BvBZz0o4OZk25NSXjj/zSa3HV7Qw5MCfIWD1S4RVfUuiS0NtYZge/Aycol8 Ztn0oluTw/hfqMhqHFndVW1S3bP X-Received: by 2002:a05:6122:4886:b0:5ea:a1ad:637d with SMTP id 71dfb90a1353d-5eaaa0f91f6mr728108e0c.1.1792182511528; Fri, 16 Oct 2026 13:28:31 -0700 (PDT) Received: from localhost ([2601:19c:4a00:897d:3391:ed89:5571:41a8]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-5ea9b2fef79sm2422500e0c.1.2026.10.16.13.28.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Oct 2026 13:28:30 -0700 (PDT) From: Ray Strode To: libcamera-devel@lists.libcamera.org Cc: kieran.bingham@ideasonboard.com, bod.linux@nxsw.ie, laurent.pinchart@ideasonboard.com Subject: [PATCH v3 03/11] software-isp: Align statistics with the visible sensor crop Date: Fri, 16 Oct 2026 16:28:10 -0400 Message-ID: <20261016202818.1405645-4-halfline@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261016202818.1405645-1-halfline@gmail.com> References: <20261015223604.311616-1-halfline@gmail.com> <20261016202818.1405645-1-halfline@gmail.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" From: Ray Strode This commit changes statistics gathering to follow the sensor area visible in the GPU output. The GPU debayer path fills the requested output with a centered crop of the sensor image. CPU statistics read the original sensor buffer, but their window uses the output dimensions and starts at the buffer's origin. A centered origin is calculated but never passed to the statistics engine. Metering therefore covers a different sensor region when the image is cropped or scaled. The window is now derived in sensor coordinates, accounting for Bayer border removal and cropping to the output aspect ratio, and centered in the sensor buffer. Changing resolution without changing aspect ratio leaves the rectangle unchanged. The statistics engine retains its existing Bayer alignment. Signed-off-by: Ray Strode --- .../internal/software_isp/debayer_geometry.h | 8 ++++++++ src/libcamera/software_isp/debayer_egl.cpp | 13 +++---------- src/libcamera/software_isp/debayer_egl.h | 1 - 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/libcamera/internal/software_isp/debayer_geometry.h b/include/libcamera/internal/software_isp/debayer_geometry.h index 70ae6a8b..46721753 100644 --- a/include/libcamera/internal/software_isp/debayer_geometry.h +++ b/include/libcamera/internal/software_isp/debayer_geometry.h @@ -40,4 +40,12 @@ inline std::array debayerProjection(const Size &inputSize, /* clang-format on */ } +/* Return the visible sensor rectangle, before statistics Bayer alignment. */ +inline Rectangle debayerCrop(const Size &inputSize, const Size &nativeSize, + const Size &outputSize) +{ + const Size visibleSize = nativeSize.boundedToAspectRatio(outputSize); + return visibleSize.centeredTo(Rectangle(inputSize).center()); +} + } /* namespace libcamera */ diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp index 1a7ad25c..9f3dc752 100644 --- a/src/libcamera/software_isp/debayer_egl.cpp +++ b/src/libcamera/software_isp/debayer_egl.cpp @@ -323,18 +323,11 @@ int DebayerEGL::configure(const StreamConfiguration &inputCfg, outputSize_ = outputCfg.size; nativeOutputSize_ = outSizeRange.max; - window_.x = ((inputCfg.size.width - outputCfg.size.width) / 2) & - ~(inputConfig_.patternSize.width - 1); - window_.y = ((inputCfg.size.height - outputCfg.size.height) / 2) & - ~(inputConfig_.patternSize.height - 1); - window_.width = outputCfg.size.width; - window_.height = outputCfg.size.height; - /* - * Don't pass x,y from window_ since process() already adjusts for it. - * But crop the window to 2/3 of its width and height for speedup. + * The GPU scales the visible sensor crop to outputSize_. Statistics + * consume the original input buffer, so use sensor coordinates here. */ - stats_->setWindow(Rectangle(window_.size())); + stats_->setWindow(debayerCrop(inputCfg.size, nativeOutputSize_, outputSize_)); inputBufferCount_ = inputCfg.bufferCount; outputBufferCount_ = outputCfg.bufferCount; diff --git a/src/libcamera/software_isp/debayer_egl.h b/src/libcamera/software_isp/debayer_egl.h index 30e51a47..52b8aa07 100644 --- a/src/libcamera/software_isp/debayer_egl.h +++ b/src/libcamera/software_isp/debayer_egl.h @@ -111,7 +111,6 @@ private: GLint contrastExpUniformDataIn_; Size nativeOutputSize_; - Rectangle window_; std::unique_ptr stats_; eGL egl_; uint32_t width_;