From patchwork Tue Sep 27 02:36:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17441 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 E23B7C0DA4 for ; Tue, 27 Sep 2022 02:37:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A830862379; Tue, 27 Sep 2022 04:37:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1664246269; bh=MVOLInGX5yVAIA9XLQDFWLFjXKy+lGpTeefmyExcEhw=; 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=cJKcLu0lJsipo2kA5CF373Fk7Had8BVGO4ztXo0nbcZgR+wN9op4myiNLd6chn6qy KAV5yTcYvqj94DRKlQyVzlur6iuhVVKXNJt5xjqxw9lfe6kh8iDxoXQBNH2j6725Fg eyUqXgZTh/6P9dFXp1I8NfHHQWA/4JFCRMo/6m1D++ZiZhMHNB4YCJlOSzPj7WVIZ9 uOOQ+4p6um4Uj9pQ/6eXh0DpFtba40Zjlp1vQUrsHG5QjSVgfZRZO/+Mg5NVfOQfnI ERRUM7b0AV2t+PvDb/PwBYBpw93/MdxzzYPVuozpiKRThtWFWjxC6UlEfhaiU9EVvD jfgtSRHjvTjaw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 99768622EE for ; Tue, 27 Sep 2022 04:37:46 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="l9yeaTN2"; 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 1DFC24F7 for ; Tue, 27 Sep 2022 04:37:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1664246266; bh=MVOLInGX5yVAIA9XLQDFWLFjXKy+lGpTeefmyExcEhw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=l9yeaTN2xVfcGM/cxv+qjmuCEceMMHoffo2LoQLPeX/CeQgpwQ7r2r2521WKUADXa QwU2elsBw+PXFKag2S95yC2UuQ6nPNnlIIRAFqCiI1ShrlciYVge4ug3eUM0aLM1gf aohVbK+GRJ7L8wC7rvO4388wtm6kSeCKZhe7cnhk= To: libcamera-devel@lists.libcamera.org Date: Tue, 27 Sep 2022 05:36:39 +0300 Message-Id: <20220927023642.12341-31-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220927023642.12341-1-laurent.pinchart@ideasonboard.com> References: <20220927023642.12341-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 30/33] 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 139c8239504f..59664d09b84c 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); } /*