Patch Detail
Show a patch.
GET /api/patches/13536/?format=api
{ "id": 13536, "url": "https://patchwork.libcamera.org/api/patches/13536/?format=api", "web_url": "https://patchwork.libcamera.org/patch/13536/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20210827080227.26370-2-jeanmichel.hautbois@ideasonboard.com>", "date": "2021-08-27T08:02:24", "name": "[libcamera-devel,v2,1/4] ipa: ipu3: Move the AWB stats structures", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "becb62d3befb939268b1d85bf88a750739da3bc0", "submitter": { "id": 75, "url": "https://patchwork.libcamera.org/api/people/75/?format=api", "name": "Jean-Michel Hautbois", "email": "jeanmichel.hautbois@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/13536/mbox/", "series": [ { "id": 2407, "url": "https://patchwork.libcamera.org/api/series/2407/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2407", "date": "2021-08-27T08:02:23", "name": "IPU3: AWB and AGC improvements", "version": 2, "mbox": "https://patchwork.libcamera.org/series/2407/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/13536/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/13536/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id C5B13C3241\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 27 Aug 2021 08:02:35 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 85DEC68941;\n\tFri, 27 Aug 2021 10:02:35 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CFBF568891\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 27 Aug 2021 10:02:32 +0200 (CEST)", "from tatooine.ideasonboard.com (unknown\n\t[IPv6:2a01:e0a:169:7140:ccf5:c267:eba8:cbb5])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 923735A1;\n\tFri, 27 Aug 2021 10:02:32 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"fZMS1ePW\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1630051352;\n\tbh=roLTNhhQ6mwaUArnd99VQn+pHjsSMQk8+O43g1eD6+k=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=fZMS1ePWTf9q/NJC037NWzSlTI61C3rZXXJesNfKCsIoBWLusfXOcjRRtwjbaZ03o\n\tyUoOpZWDPfvfwJAvOJ70ZhRicNBz3j9TmsZ7iH9iNiW1hZSQeXR8L7Bk7nA93BY602\n\tYxvM1rW3K27aOF8iNXXlGhtwKaBbOxyTnmBvGZ9U=", "From": "Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Fri, 27 Aug 2021 10:02:24 +0200", "Message-Id": "<20210827080227.26370-2-jeanmichel.hautbois@ideasonboard.com>", "X-Mailer": "git-send-email 2.30.2", "In-Reply-To": "<20210827080227.26370-1-jeanmichel.hautbois@ideasonboard.com>", "References": "<20210827080227.26370-1-jeanmichel.hautbois@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 1/4] ipa: ipu3: Move the AWB stats\n\tstructures", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "The structure Ipu3AwbCell describes the AWB stats layout on the kernel\nside. We will need it to be used by the AGC algorithm to be introduced\nlater, so let's make it visible from ipa::ipu3::algorithms and not only\nfor the AWB class.\n\nThis structure should probably go into the intel-ipu3.h file, whichs\nmeans a kernel patch, let's keep it in mind for the moment.\n\n- IspStatsRegion is renamed Accumulator, and is storing the total number\n of pixels along with the counted pixels now.\n\n- The RGB structure is a more generic structure, it should be in a more\n generic header.\n\n- AwbStatus is used for the internal storage of the awb gains to update\n the context in prepare. Align the IPAFrameContext to have the same\n structure layout.\n\nSigned-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n---\n src/ipa/ipu3/algorithms/awb.cpp | 47 ++++++++++---------\n src/ipa/ipu3/algorithms/awb.h | 81 +++++++++++++++++----------------\n src/ipa/ipu3/ipa_context.h | 1 +\n src/ipa/ipu3/ipu3.cpp | 3 ++\n 4 files changed, 71 insertions(+), 61 deletions(-)", "diff": "diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp\nindex e05647c9..136e79e0 100644\n--- a/src/ipa/ipu3/algorithms/awb.cpp\n+++ b/src/ipa/ipu3/algorithms/awb.cpp\n@@ -21,25 +21,27 @@ static constexpr uint32_t kMinZonesCounted = 16;\n static constexpr uint32_t kMinGreenLevelInZone = 32;\n \n /**\n- * \\struct IspStatsRegion\n+ * \\struct Accumulator\n * \\brief RGB statistics for a given region\n *\n- * The IspStatsRegion structure is intended to abstract the ISP specific\n- * statistics and use an agnostic algorithm to compute AWB.\n+ * The Accumulator structure stores the sum of the pixel values in a region of\n+ * the image, as well as the number of relevant pixels in this same region. A\n+ * relevant pixel is an unsaturated pixel for this algorithm.\n+ * \\todo extend the notion of relevant to something else ?\n *\n- * \\var IspStatsRegion::counted\n- * \\brief Number of pixels used to calculate the sums\n+ * \\var Accumulator::total\n+ * \\brief Total number of pixels in the region\n *\n- * \\var IspStatsRegion::uncounted\n- * \\brief Remaining number of pixels in the region\n+ * \\var Accumulator::counted\n+ * \\brief Number of relevant pixels used to calculate the sums\n *\n- * \\var IspStatsRegion::rSum\n+ * \\var Accumulator::rSum\n * \\brief Sum of the red values in the region\n *\n- * \\var IspStatsRegion::gSum\n+ * \\var Accumulator::gSum\n * \\brief Sum of the green values in the region\n *\n- * \\var IspStatsRegion::bSum\n+ * \\var Accumulator::bSum\n * \\brief Sum of the blue values in the region\n */\n \n@@ -117,9 +119,9 @@ static const struct ipu3_uapi_ccm_mat_config imguCssCcmDefault = {\n Awb::Awb()\n \t: Algorithm()\n {\n-\tasyncResults_.blueGain = 1.0;\n-\tasyncResults_.greenGain = 1.0;\n-\tasyncResults_.redGain = 1.0;\n+\tasyncResults_.gains.blue = 1.0;\n+\tasyncResults_.gains.green = 1.0;\n+\tasyncResults_.gains.red = 1.0;\n \tasyncResults_.temperatureK = 4500;\n \n \tzones_.reserve(kAwbStatsSizeX * kAwbStatsSizeY);\n@@ -204,6 +206,7 @@ void Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats,\n \t\t\t\tawbStats_[awbRegionPosition].rSum += currentCell->redAvg;\n \t\t\t\tawbStats_[awbRegionPosition].bSum += currentCell->blueAvg;\n \t\t\t}\n+\t\t\tawbStats_[awbRegionPosition].total++;\n \t\t}\n \t}\n }\n@@ -215,7 +218,7 @@ void Awb::clearAwbStats()\n \t\tawbStats_[i].rSum = 0;\n \t\tawbStats_[i].gSum = 0;\n \t\tawbStats_[i].counted = 0;\n-\t\tawbStats_[i].uncounted = 0;\n+\t\tawbStats_[i].total = 0;\n \t}\n }\n \n@@ -254,9 +257,9 @@ void Awb::awbGreyWorld()\n \n \t/* Color temperature is not relevant in Grey world but still useful to estimate it :-) */\n \tasyncResults_.temperatureK = estimateCCT(sumRed.R, sumRed.G, sumBlue.B);\n-\tasyncResults_.redGain = redGain;\n-\tasyncResults_.greenGain = 1.0;\n-\tasyncResults_.blueGain = blueGain;\n+\tasyncResults_.gains.red = redGain;\n+\tasyncResults_.gains.green = 1.0;\n+\tasyncResults_.gains.blue = blueGain;\n }\n \n void Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats,\n@@ -270,8 +273,8 @@ void Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats,\n \tLOG(IPU3Awb, Debug) << \"Valid zones: \" << zones_.size();\n \tif (zones_.size() > 10) {\n \t\tawbGreyWorld();\n-\t\tLOG(IPU3Awb, Debug) << \"Gain found for red: \" << asyncResults_.redGain\n-\t\t\t\t << \" and for blue: \" << asyncResults_.blueGain;\n+\t\tLOG(IPU3Awb, Debug) << \"Gain found for red: \" << asyncResults_.gains.red\n+\t\t\t\t << \" and for blue: \" << asyncResults_.gains.blue;\n \t}\n }\n \n@@ -284,9 +287,9 @@ void Awb::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)\n \t * The results are cached, so if no results were calculated, we set the\n \t * cached values from asyncResults_ here.\n \t */\n-\tcontext.frameContext.awb.gains.blue = asyncResults_.blueGain;\n-\tcontext.frameContext.awb.gains.green = asyncResults_.greenGain;\n-\tcontext.frameContext.awb.gains.red = asyncResults_.redGain;\n+\tcontext.frameContext.awb.gains.blue = asyncResults_.gains.blue;\n+\tcontext.frameContext.awb.gains.green = asyncResults_.gains.green;\n+\tcontext.frameContext.awb.gains.red = asyncResults_.gains.red;\n }\n \n void Awb::prepare(IPAContext &context, ipu3_uapi_params *params)\ndiff --git a/src/ipa/ipu3/algorithms/awb.h b/src/ipa/ipu3/algorithms/awb.h\nindex a16dd68d..f7e2f4cd 100644\n--- a/src/ipa/ipu3/algorithms/awb.h\n+++ b/src/ipa/ipu3/algorithms/awb.h\n@@ -23,6 +23,38 @@ namespace ipa::ipu3::algorithms {\n static constexpr uint32_t kAwbStatsSizeX = 16;\n static constexpr uint32_t kAwbStatsSizeY = 12;\n \n+/* \\todo Move the cell layout into intel-ipu3.h kernel header */\n+struct Ipu3AwbCell {\n+\tunsigned char greenRedAvg;\n+\tunsigned char redAvg;\n+\tunsigned char blueAvg;\n+\tunsigned char greenBlueAvg;\n+\tunsigned char satRatio;\n+\tunsigned char padding[3];\n+} __attribute__((packed));\n+\n+/* \\todo Make these structs available to all the ISPs ? */\n+struct RGB {\n+\tRGB(double _R = 0, double _G = 0, double _B = 0)\n+\t\t: R(_R), G(_G), B(_B)\n+\t{\n+\t}\n+\tdouble R, G, B;\n+\tRGB &operator+=(RGB const &other)\n+\t{\n+\t\tR += other.R, G += other.G, B += other.B;\n+\t\treturn *this;\n+\t}\n+};\n+\n+struct Accumulator {\n+\tunsigned int total;\n+\tunsigned int counted;\n+\tunsigned long long rSum;\n+\tunsigned long long gSum;\n+\tunsigned long long bSum;\n+};\n+\n class Awb : public Algorithm\n {\n public:\n@@ -32,44 +64,6 @@ public:\n \tvoid prepare(IPAContext &context, ipu3_uapi_params *params) override;\n \tvoid process(IPAContext &context, const ipu3_uapi_stats_3a *stats) override;\n \n-\tstruct Ipu3AwbCell {\n-\t\tunsigned char greenRedAvg;\n-\t\tunsigned char redAvg;\n-\t\tunsigned char blueAvg;\n-\t\tunsigned char greenBlueAvg;\n-\t\tunsigned char satRatio;\n-\t\tunsigned char padding[3];\n-\t} __attribute__((packed));\n-\n-\t/* \\todo Make these three structs available to all the ISPs ? */\n-\tstruct RGB {\n-\t\tRGB(double _R = 0, double _G = 0, double _B = 0)\n-\t\t\t: R(_R), G(_G), B(_B)\n-\t\t{\n-\t\t}\n-\t\tdouble R, G, B;\n-\t\tRGB &operator+=(RGB const &other)\n-\t\t{\n-\t\t\tR += other.R, G += other.G, B += other.B;\n-\t\t\treturn *this;\n-\t\t}\n-\t};\n-\n-\tstruct IspStatsRegion {\n-\t\tunsigned int counted;\n-\t\tunsigned int uncounted;\n-\t\tunsigned long long rSum;\n-\t\tunsigned long long gSum;\n-\t\tunsigned long long bSum;\n-\t};\n-\n-\tstruct AwbStatus {\n-\t\tdouble temperatureK;\n-\t\tdouble redGain;\n-\t\tdouble greenGain;\n-\t\tdouble blueGain;\n-\t};\n-\n private:\n \tvoid calculateWBGains(const ipu3_uapi_stats_3a *stats,\n \t\t\t const ipu3_uapi_grid_config &grid);\n@@ -80,8 +74,17 @@ private:\n \tvoid awbGreyWorld();\n \tuint32_t estimateCCT(double red, double green, double blue);\n \n+\tstruct AwbStatus {\n+\t\tdouble temperatureK;\n+\t\tstruct {\n+\t\t\tdouble red;\n+\t\t\tdouble green;\n+\t\t\tdouble blue;\n+\t\t} gains;\n+\t};\n+\n \tstd::vector<RGB> zones_;\n-\tIspStatsRegion awbStats_[kAwbStatsSizeX * kAwbStatsSizeY];\n+\tAccumulator awbStats_[kAwbStatsSizeX * kAwbStatsSizeY];\n \tAwbStatus asyncResults_;\n };\n \ndiff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h\nindex 9d9444dc..3a292ad7 100644\n--- a/src/ipa/ipu3/ipa_context.h\n+++ b/src/ipa/ipu3/ipa_context.h\n@@ -30,6 +30,7 @@ struct IPAFrameContext {\n \t} agc;\n \n \tstruct {\n+\t\tdouble temperatureK;\n \t\tstruct {\n \t\t\tdouble red;\n \t\t\tdouble green;\ndiff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\nindex 0ed0a6f1..cbb3f440 100644\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -112,6 +112,9 @@\n * \\struct IPAFrameContext::awb\n * \\brief Context for the Automatic White Balance algorithm\n *\n+ * \\var IPAFrameContext::awb::temperatureK\n+ * \\brief Estimated color temperature in Kelvin\n+ *\n * \\struct IPAFrameContext::awb::gains\n * \\brief White balance gains\n *\n", "prefixes": [ "libcamera-devel", "v2", "1/4" ] }