From patchwork Mon Sep 6 19:47:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Michel Hautbois X-Patchwork-Id: 13634 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 406BABEFBE for ; Mon, 6 Sep 2021 19:48:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4D1376916C; Mon, 6 Sep 2021 21:48:02 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="gGgCCMvf"; dkim-atps=neutral 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 9A65269167 for ; Mon, 6 Sep 2021 21:47:59 +0200 (CEST) Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:eb18:8e30:9b7:f998]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2B713F49; Mon, 6 Sep 2021 21:47:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1630957679; bh=xja9h82q4iWa3Ti+Kgy1RkAwvN3ON2fmFF9+qFsXmVo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gGgCCMvfCLD7Uuubd58g+V1tCuT6XwmzI8glvOafNtDh7Fo25nsTL8fQTmIQl0izU g2M9P1HKkgetEfrjmSe101/ARFPDmox5ctPB3B+4g30rhW3rexRbrxy1tUai4AjwTj atDEu0xECwNkYFV+juEJLMSs/+KkbLlPzTZ81gaY= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Mon, 6 Sep 2021 21:47:52 +0200 Message-Id: <20210906194755.106953-2-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210906194755.106953-1-jeanmichel.hautbois@ideasonboard.com> References: <20210906194755.106953-1-jeanmichel.hautbois@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 1/4] ipa: ipu3: Move the AWB stats structures 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 structure Ipu3AwbCell describes the AWB stats layout on the kernel side. We will need it to be used by the AGC algorithm to be introduced later, so let's make it visible from ipa::ipu3::algorithms and not only for the AWB class. The IspStatsRegion will be needed by AGC too, so let's move it in the same namespace too. Signed-off-by: Jean-Michel Hautbois Reviewed-by: Kieran Bingham --- src/ipa/ipu3/algorithms/awb.h | 37 ++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/ipa/ipu3/algorithms/awb.h b/src/ipa/ipu3/algorithms/awb.h index a16dd68d..cc848060 100644 --- a/src/ipa/ipu3/algorithms/awb.h +++ b/src/ipa/ipu3/algorithms/awb.h @@ -23,6 +23,24 @@ namespace ipa::ipu3::algorithms { static constexpr uint32_t kAwbStatsSizeX = 16; static constexpr uint32_t kAwbStatsSizeY = 12; +/* \todo Move the cell layout into intel-ipu3.h kernel header */ +struct Ipu3AwbCell { + unsigned char greenRedAvg; + unsigned char redAvg; + unsigned char blueAvg; + unsigned char greenBlueAvg; + unsigned char satRatio; + unsigned char padding[3]; +} __attribute__((packed)); + +struct IspStatsRegion { + unsigned int counted; + unsigned int uncounted; + unsigned long long rSum; + unsigned long long gSum; + unsigned long long bSum; +}; + class Awb : public Algorithm { public: @@ -32,16 +50,7 @@ public: void prepare(IPAContext &context, ipu3_uapi_params *params) override; void process(IPAContext &context, const ipu3_uapi_stats_3a *stats) override; - struct Ipu3AwbCell { - unsigned char greenRedAvg; - unsigned char redAvg; - unsigned char blueAvg; - unsigned char greenBlueAvg; - unsigned char satRatio; - unsigned char padding[3]; - } __attribute__((packed)); - - /* \todo Make these three structs available to all the ISPs ? */ + /* \todo Make these structs available to all the ISPs ? */ struct RGB { RGB(double _R = 0, double _G = 0, double _B = 0) : R(_R), G(_G), B(_B) @@ -55,14 +64,6 @@ public: } }; - struct IspStatsRegion { - unsigned int counted; - unsigned int uncounted; - unsigned long long rSum; - unsigned long long gSum; - unsigned long long bSum; - }; - struct AwbStatus { double temperatureK; double redGain; From patchwork Mon Sep 6 19:47:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Michel Hautbois X-Patchwork-Id: 13635 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 D04BFC3242 for ; Mon, 6 Sep 2021 19:48:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9C06E69173; Mon, 6 Sep 2021 21:48:02 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ku9PL0VT"; dkim-atps=neutral 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 BA0CA69168 for ; Mon, 6 Sep 2021 21:47:59 +0200 (CEST) Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:eb18:8e30:9b7:f998]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5EB34F84; Mon, 6 Sep 2021 21:47:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1630957679; bh=FSGHgMVWpUfExg9en1xDalbB7IRNLwV7bhh/opRTRAs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ku9PL0VT/O4IjAmgOj3fsA1+SRnsBsDOI9k6DV9nG58nEAkQXNBiQGtlslksFDw87 bzMxd6kkCksQihTijla9FQoJom4GAMHFpwR7Et+dHQefiNEN6MTohQjFgb+viu5mot 6x/aKY5OPjBVq09MbBZeMi8CNYCjDPbsyjxnRh7k= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Mon, 6 Sep 2021 21:47:53 +0200 Message-Id: <20210906194755.106953-3-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210906194755.106953-1-jeanmichel.hautbois@ideasonboard.com> References: <20210906194755.106953-1-jeanmichel.hautbois@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 2/4] ipa: ipu3: Rename IspStatsRegion to Accumulator 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 IspStatsRegion structure was introduced as an attempt to prepare for a generic AWB algorithm structure. The structure name by itseld is not explicit and it is too optimistic to try and make a generic one for now. Its role is to accumulate the pixels in a given region. Rename it to accumulator, and remove the uncounted field at the same time. It is always possible to know how many pixels are not relevant for the algorithm by calculating total-counted. The uncounted field was only declared and not used. Amend the documentation accordingly. Signed-off-by: Jean-Michel Hautbois --- src/ipa/ipu3/algorithms/awb.cpp | 36 ++++++++++++++++++++------------- src/ipa/ipu3/algorithms/awb.h | 5 ++--- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp index e05647c9..97f5839f 100644 --- a/src/ipa/ipu3/algorithms/awb.cpp +++ b/src/ipa/ipu3/algorithms/awb.cpp @@ -21,26 +21,35 @@ static constexpr uint32_t kMinZonesCounted = 16; static constexpr uint32_t kMinGreenLevelInZone = 32; /** - * \struct IspStatsRegion + * \struct Accumulator * \brief RGB statistics for a given region * - * The IspStatsRegion structure is intended to abstract the ISP specific - * statistics and use an agnostic algorithm to compute AWB. + * A frame is divided into zones, each zone is made of multiple regions which + * are defined by the grid configuration. The algorithm works with a fixed + * number of zones \a kAwbStatsSizeX x \a kAwbStatsSizeY. + * For example, a frame of 1280x720 is divided into 81x45 regions of [16x16] + * pixels because the BDS output size will be calculated as 1296x720. In the + * case of \a kAwbStatsSizeX=16 and \a kAwbStatsSizeY=12 the zones are made of + * [5x4] regions. The regions are left-aligned and calculated by + * IPAIPU3::calculateBdsGrid(). * - * \var IspStatsRegion::counted - * \brief Number of pixels used to calculate the sums + * The Accumulator structure stores the sum of the pixel values in a zone of + * the image, as well as the number of relevant regions in this same zone. A + * relevant region is an unsaturated region here, depending on the awb + * thresholds. + * \todo extend the notion of relevant to something else ? * - * \var IspStatsRegion::uncounted - * \brief Remaining number of pixels in the region + * \var Accumulator::counted + * \brief Number of relevant regions used to calculate the sums * - * \var IspStatsRegion::rSum - * \brief Sum of the red values in the region + * \var Accumulator::rSum + * \brief Sum of the red values in the zone * - * \var IspStatsRegion::gSum - * \brief Sum of the green values in the region + * \var Accumulator::gSum + * \brief Sum of the green values in the zone * - * \var IspStatsRegion::bSum - * \brief Sum of the blue values in the region + * \var Accumulator::bSum + * \brief Sum of the blue values in the zone */ /** @@ -215,7 +224,6 @@ void Awb::clearAwbStats() awbStats_[i].rSum = 0; awbStats_[i].gSum = 0; awbStats_[i].counted = 0; - awbStats_[i].uncounted = 0; } } diff --git a/src/ipa/ipu3/algorithms/awb.h b/src/ipa/ipu3/algorithms/awb.h index cc848060..ac8ccc84 100644 --- a/src/ipa/ipu3/algorithms/awb.h +++ b/src/ipa/ipu3/algorithms/awb.h @@ -33,9 +33,8 @@ struct Ipu3AwbCell { unsigned char padding[3]; } __attribute__((packed)); -struct IspStatsRegion { +struct Accumulator { unsigned int counted; - unsigned int uncounted; unsigned long long rSum; unsigned long long gSum; unsigned long long bSum; @@ -82,7 +81,7 @@ private: uint32_t estimateCCT(double red, double green, double blue); std::vector zones_; - IspStatsRegion awbStats_[kAwbStatsSizeX * kAwbStatsSizeY]; + Accumulator awbStats_[kAwbStatsSizeX * kAwbStatsSizeY]; AwbStatus asyncResults_; };