From patchwork Thu Sep 8 01:41:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17338 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 ECDFDC327D for ; Thu, 8 Sep 2022 01:43:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9ACA16210E; Thu, 8 Sep 2022 03:43:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1662601380; bh=7UvmQ3qSqI6o2mLkcewEM7KdUj4KP3LM/xCTrOi3RAg=; 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=aoa6Xg6eWpxq+DFRzS6N+eCE9BIT3PJjiTpuPfkinw41Qd6xQ9eiCxtpyf72uQLdm K+BKpGi/3HCcuOAdtwlXyPXN8bjGgoA10I0gXkaw0rYokbm0K/c4dEtohzSCevlkR+ ov4PNK0CJRanGQ+VjDRY6UeDuKDyGhljN5SLuwnmaKBj/bAKQK0vm//q0ayC2ID529 U7jiTCYr4lWDlMZIaKDDhXP1EcXihx4kYlfOhj4+Ars6yaH1xcNx2yDa9j/ntS0l6S Mo8JPkfxeUR/h3qp6dJXspI1Gk+z3t5MevE0Mw/Wk8pJ+Vd4KQbVAYaz35cQNX12I6 53johcu1G6D9g== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6C0C5620FC for ; Thu, 8 Sep 2022 03:42:58 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="tEtScMoF"; 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 E362C8F1 for ; Thu, 8 Sep 2022 03:42:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1662601378; bh=7UvmQ3qSqI6o2mLkcewEM7KdUj4KP3LM/xCTrOi3RAg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=tEtScMoFV83L2ZG2QJlkYel6G0CI4bSbKEQF57IHik5esgtmZZ9m9tLWyqDcDfDpt nNlsT1SmlqXVtb8IQ3eE6Oh5z1PVZoZ7/fPFfdl3Cg6zYeRKjfiNvWHUlnxHTVXZEC qwX9xOGHE54Ih1yKX52uGXaBeEj+xIQPWV+xRS+0= To: libcamera-devel@lists.libcamera.org Date: Thu, 8 Sep 2022 04:41:57 +0300 Message-Id: <20220908014200.28728-30-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 29/32] ipa: rkisp1: awb: Prevent RGB means from being negative 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" Due to hardware rounding errors in the YCbCr means, the calculated RGB means may be negative. This would lead to negative gains, messing up calculation. Prevent this by clamping the means to positive values. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi --- src/ipa/rkisp1/algorithms/awb.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index ed91e9277a16..de54c4d24650 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -242,6 +242,16 @@ void Awb::process(IPAContext &context, redMean = 1.1636 * yMean - 0.0623 * cbMean + 1.6008 * crMean; greenMean = 1.1636 * yMean - 0.4045 * cbMean - 0.7949 * crMean; blueMean = 1.1636 * yMean + 1.9912 * cbMean - 0.0250 * crMean; + + /* + * Due to hardware rounding errors in the YCbCr means, the + * calculated RGB means may be negative. This would lead to + * negative gains, messing up calculation. Prevent this by + * clamping the means to positive values. + */ + redMean = std::max(redMean, 0.0); + greenMean = std::max(greenMean, 0.0); + blueMean = std::max(blueMean, 0.0); } /*