From patchwork Thu Oct 15 22:36:03 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ray Strode X-Patchwork-Id: 28469 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 E6BFEC3316 for ; Thu, 15 Oct 2026 22:36:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E9CFA68E2E; Fri, 16 Oct 2026 00:36:21 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="TE1XqpPK"; dkim-atps=neutral Received: from mail-vk1-xa35.google.com (mail-vk1-xa35.google.com [IPv6:2607:f8b0:4864:20::a35]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 83DFE68E1F for ; Fri, 16 Oct 2026 00:36:17 +0200 (CEST) Received: by mail-vk1-xa35.google.com with SMTP id 71dfb90a1353d-5e9528732b4so3311916e0c.0 for ; Thu, 15 Oct 2026 15:36:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792103776; x=1792708576; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=d0ZIPEqnqMbbVlotQ+4T3vD1D97n+6qK2eVOnrf5BaI=; b=TE1XqpPK69w3Lp8G1ujpsrIgzYN9CxoczdcrKi2Cgz/B9R6A1wEsxrxBT0+R1uz8y1 gx9bV1x+uvhO3XukHb37sjHoc+E6H2Zu4c3d7EFOyszqQJ+c2MbKJ+6Mxys6rGt9KytO +7Ny4DVDs1yVS9QnwO8INpvxgCQiK8kkjsZ7QFc6nH4DS2wfh12kn2Y7+Wu8TKjIU1oT acQQ3GtPiTr2wkztwiil74WxrKQ7WszxDYQfFp3LSIogUqYWYwM4TZDroFCAQpVqFyGA CJQ2y13MOVfHC3B64nWtATYgIZA1Vyz9GVKuQi7GsgbAEaiIVgKbofKbh3JdnMCJMGeR PmcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792103776; x=1792708576; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=d0ZIPEqnqMbbVlotQ+4T3vD1D97n+6qK2eVOnrf5BaI=; b=rVPxCPscVbgo+/uqI4Jc16LqtBQ0KhjatVgZfzxr0DULToDFLlYc9IHem+ZalHtI43 v1ObfiFWy7t6fdzvLOkkShkA+cyorQx2GZQV4R5gksSjyXVbbTliWrg3vaktXBc+ERMs p6qTRlysZJ1KP8YQNUcKOxWsVM0bRhf09//3+6sWeRKugOHyQyHYKwntpX55S7lsDC6Y oZT3QHwo8JujXIaXyE/nbC082eevsJ9vrglnAEBs5KTOcsjeSpY0AGqNHMhuDCiTz2Gu fvHYpz6arCn89GD8KO98GgVXn6usmMSBZyCA6Z0xxplMM2f3F4RG9fmimgDLxQLA0Odk toZA== X-Gm-Message-State: AFq9FYIIn4dkEJ2PX0oOqmH5t7coWnWY+3Q+Rj3mGED2UH4Pv50hjxkl Wjj2RcsMimPou7JuRZ4OHXJAOs9OgVZ44kGpCnXu7enohHOBaKIXtlEiT8tUKftbS7Ic1A== X-Gm-Gg: AYBFou0G7VPrEWm++HlYhY35F5rQAZDRUYB3g6FaLZotM22RdY7TARvzwNauy4aNfAt tboYC6UrsCRKJSPOpSN1eJxxsKlEpu7UMvBf26nlD3pIAd0GXXVbF0RiEIhNcoPMJ5uajWhiT8F Ic+pK9h80hxf8uIlj1Vp9jCPHQ7Mnm8P924BYW6pxv6TTKRWOFfPvmic+JKfwDnaVRhazR/5YOQ 9w/2nCf6zH9nR0OU1po7ajGmbd7M+eqA2M5Q9D9vKWtAs6P7g8yxE9F97xahxJB9jDs2XOGI0c/ hh4ZVxxBjWXl1NJN2rqFWbscaYErYzKtdLjimS6uBrl5JTSJK2+uXAx84W6/SXXL2VrXyO4yeQ0 8EGHNFZA5CZqqjm/Z+5A1B23TpjTcaDQTbZ9Fuw21VpotrLqPKADhMQyCH5y86DcKq/FQ5/2TNu nSyFlgZ+sN2xCbjvZJUEXcKxvqLdi5jcFzQ3FgTJEowkWRRm77H/MMWVe6qb+bmenA76prYF6Ms JtgPc43w2sN4hEytBwtyyq0NhNR X-Received: by 2002:a05:6102:149d:b0:7a7:ad9f:53e2 with SMTP id ada2fe7eead31-7cb36987a53mr7848502137.1.1792103776290; Thu, 15 Oct 2026 15:36:16 -0700 (PDT) Received: from localhost ([2601:19c:4a00:897d:3391:ed89:5571:41a8]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-7cc198794desm909192137.9.2026.10.15.15.36.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Oct 2026 15:36:15 -0700 (PDT) From: Ray Strode To: libcamera-devel@lists.libcamera.org Subject: [PATCH v2 3/4] software-isp: Meter the visible sensor crop Date: Thu, 15 Oct 2026 18:36:03 -0400 Message-ID: <20261015223604.311616-4-halfline@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261015223604.311616-1-halfline@gmail.com> References: <20261015194335.287960-1-halfline@gmail.com> <20261015223604.311616-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 The GPU debayer path draws a centered sensor crop into the requested output size, while CPU statistics read the original input buffer. The statistics window still follows the output dimensions, so metering covers a different part of the sensor when output sizes or aspect ratios change. This commit derives the visible crop in sensor coordinates and centers the statistics window on that region. 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 6c10ecb8..c6359cde 100644 --- a/include/libcamera/internal/software_isp/debayer_geometry.h +++ b/include/libcamera/internal/software_isp/debayer_geometry.h @@ -38,4 +38,12 @@ inline std::array debayerProjection(const Size &inputSize, }; } +/* 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_;