From patchwork Thu Sep 8 01:42:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17341 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 6C46CC327D for ; Thu, 8 Sep 2022 01:43:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 13C686209D; Thu, 8 Sep 2022 03:43:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1662601384; bh=cxjIAz7fxkLpqHRIBc5gwql1/d+wyi2dDUmV7Xjien8=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=h/zTC3nfok7fB02mjWg4X83b+DPn01Pxm1UqCZC7AxaxE/9/GNfDDoCYNDVCXERks EcEfnPAuvASp2h58yQqmRzvCHbd0QijdCARg169vs0BilDRJakM4kHjAieGiOEwsA5 NtKoL12Fch7EQlHmQ5tbzT7wNdQyPShT9vmnVHEd59E3Ob+3hh9lPYt8epTzJZpNrp ColAFGHsooVtzZ1ViCjIOKV5XoFY7Nzhs4GgMqXaqVz6Ic7yVt4EYDooQ5bx9utb4C Tv9yLkkHwEU0S6eebivdZY0GTz6f12OEkTaW1BPTMpK4KKZeee9kKfKZhVyeCv89VD 8CjR858M3TdpA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E6D436209D for ; Thu, 8 Sep 2022 03:43:02 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="sdB8TXB0"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 73246888 for ; Thu, 8 Sep 2022 03:43:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1662601382; bh=cxjIAz7fxkLpqHRIBc5gwql1/d+wyi2dDUmV7Xjien8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=sdB8TXB0VjoPe7zLwH1FirGynywDyi6rI489+Z3AIRJTGld05bsgRjC/kuFDsCEae G3AQ20QroDV1YwZcVAbI+97zIMDo1hgC4ceaVdyUIYr3nguAmfVYztjX96ioeM7cbD iC9oi18eDMHb2gx4zAPU6Lfwo5NZ9XdOpcnL0os4= To: libcamera-devel@lists.libcamera.org Date: Thu, 8 Sep 2022 04:42:00 +0300 Message-Id: <20220908014200.28728-33-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220908014200.28728-1-laurent.pinchart@ideasonboard.com> References: <20220908014200.28728-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 32/32] ipa: rkisp1: awb: Remove bias from gain calculation 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The red and blue gains are computed by dividing the green mean by the red and blue means respectively. An offset of 1 is added to the dividers to avoid divisions by zero. This introduces a bias in the gain values. Fix it by clamping the divisors to a minimum of 1.0 instead of adding an offset. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/ipa/rkisp1/algorithms/awb.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index 404ad66e6953..fe1ba09a99a2 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -280,10 +280,11 @@ void Awb::process(IPAContext &context, /* * Estimate the red and blue gains to apply in a grey world. The green - * gain is hardcoded to 0. + * gain is hardcoded to 0. Avoid divisions by zero by clamping the + * divisor to a minimum value of 1.0. */ - double redGain = greenMean / (redMean + 1); - double blueGain = greenMean / (blueMean + 1); + double redGain = greenMean / std::max(redMean, 1.0); + double blueGain = greenMean / std::max(blueMean, 1.0); /* * Clamp the gain values to the hardware, which expresses gains as Q2.8