From patchwork Fri Sep 19 09:40:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 24422 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 DC578C328C for ; Fri, 19 Sep 2025 09:41:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 72BBF6B5C2; Fri, 19 Sep 2025 11:41:36 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="NMOmdyKi"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 930C26B5BA for ; Fri, 19 Sep 2025 11:41:31 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:4d54:eab8:98ca:163b]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 6765FD3E; Fri, 19 Sep 2025 11:40:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1758274811; bh=/pVOmLIZnIp1gu90GepU9SqG6OJvbmpojHTW1RnqeNs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NMOmdyKi+1e/l/xGkZorhz4dM+wfrIOPLYfXWNeVXRu05nx5t6So92rRgyCn8Enwy i5eMm3GczXqBIp967OZnE+BzBVgm+aqBvn8QQ2soTE4PJ5pANpsxH5wMB3a+Tp/o7D gquZ0od8tQFKzis2uikqOEDWW8M7roYpojPlHqRw= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Paul Elder , Kieran Bingham Subject: [PATCH v5 13/19] ipa: rkisp1: Switch histogram to RGB combined mode Date: Fri, 19 Sep 2025 11:40:28 +0200 Message-ID: <20250919094041.183031-14-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250919094041.183031-1-stefan.klug@ideasonboard.com> References: <20250919094041.183031-1-stefan.klug@ideasonboard.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" The Y mode of the histogram gets captured at the ISP output, before the output formatter. This has the side effect that the first and the last bins are empty in case of limited YUV range. Another side effect is that gamma and GWDR processing is included in the histogram which makes algorithm development very difficult. In RGB mode the histogram is taken after xtalk (CCM) and is therefore independent of gamma and WDR. The limited range issue also does not apply. In the ISP reference it is however stated that "it is not possible to calculate a luminance or grayscale histogram from an RGB histogram since the position information is lost during its generation". During testing the RGB histogram provided good data and better algorithmic stability at a possible (but not measured) inaccuracy. Another option would be to pass the color space information into the IPA and strip the histogram accordingly. For ease of implementation switch to the RGB mode. Signed-off-by: Stefan Klug Reviewed-by: Paul Elder Reviewed-by: Kieran Bingham --- Changes in v4: - Tiny fixes in the block comment (no doxygen & whitespace) - Collected tags Changes in v3: - Added block comment inside the code --- src/ipa/rkisp1/algorithms/agc.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp index fe2f66cf6ee4..174d810edc65 100644 --- a/src/ipa/rkisp1/algorithms/agc.cpp +++ b/src/ipa/rkisp1/algorithms/agc.cpp @@ -397,7 +397,24 @@ void Agc::prepare(IPAContext &context, const uint32_t frame, hstConfig.setEnabled(true); hstConfig->meas_window = context.configuration.agc.measureWindow; - hstConfig->mode = RKISP1_CIF_ISP_HISTOGRAM_MODE_Y_HISTOGRAM; + /* + * The Y mode of the histogram gets captured at the ISP output, before + * the output formatter. This has the side effect that the first and + * the last bins are empty in case of limited YUV range. Another side + * effect is that gamma and GWDR processing is included in the histogram + * which makes algorithm development very difficult. In RGB mode the + * histogram is taken after xtalk (CCM) and is therefore independent of + * gamma and WDR. The limited range issue also does not apply. In the + * ISP reference it is however stated that "it is not possible to + * calculate a luminance or grayscale histogram from an RGB histogram + * since the position information is lost during its generation". + * + * During testing the RGB histogram provided good data and better + * algorithmic stability at a possible (but not measured) inaccuracy. + * + * \todo For a proper fix support for HIST64 is needed. + */ + hstConfig->mode = RKISP1_CIF_ISP_HISTOGRAM_MODE_RGB_COMBINED; Span weights{ hstConfig->hist_weight,