{"id":15572,"url":"https://patchwork.libcamera.org/api/patches/15572/?format=json","web_url":"https://patchwork.libcamera.org/patch/15572/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20220328120336.10834-2-laurent.pinchart@ideasonboard.com>","date":"2022-03-28T12:03:33","name":"[libcamera-devel,1/4] libipa: camera_sensor_helper: Reorganize gain constants","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"64bf71a192b6066cf8ba891f8951ba851c10abf7","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/15572/mbox/","series":[{"id":3008,"url":"https://patchwork.libcamera.org/api/series/3008/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3008","date":"2022-03-28T12:03:32","name":"IPA sensor helpers for IMX290 and IMX296","version":1,"mbox":"https://patchwork.libcamera.org/series/3008/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/15572/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/15572/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 5F872C3265\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 28 Mar 2022 12:03:45 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6B29865637;\n\tMon, 28 Mar 2022 14:03:44 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2602B601F5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 28 Mar 2022 14:03:42 +0200 (CEST)","from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C2A8FE0A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 28 Mar 2022 14:03:41 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1648469024;\n\tbh=dCdO5KC0qS8Expo4HQ/g6DfXtFRZn5qq3lY+qK221lI=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=yR1doETy88D3/GdlI2yru0WiRWmyNFSAFoMNAySMsBTezLtMG0qf3IGO5zxc7F6ZS\n\tk7e69nJBc3bbnDsfDnxztv3N6PSjCmkp+XXE5rd8BzELAPXd1ZC6eW41EFwNEKUSme\n\tT54nmGz5JtM7TFiquI0vXvYTv942CAMbywlqsxXJxh2KhQrqTsdeo9BrxFEDo7VLW6\n\ttiKxu0J6fszEvYfFZJnW+MhNCEEgWln1BCroMwPEF070+E+hjOxE2VSFLMCS3G6n5U\n\t/qcpMomQhCSZzObNITGNOFpqnru/bveOojC5nl+TWqVfuA5WwwPhD/yG+w0v0qKiVj\n\tQa7mYarYHD/ww==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1648469021;\n\tbh=dCdO5KC0qS8Expo4HQ/g6DfXtFRZn5qq3lY+qK221lI=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=dPgpZ8AEwIsQRhJ6WSfN8dHqwZBo422ts/4ReCjuP/ZD72mIKns4YwlFKESZi5E96\n\taTxWjvsFeNqD5ybMlgIYH4ditLfOP/pqoQL+ciB3Gm4QohqR2yipgAB66shySArQHN\n\t1vJA9Rwh63MF1Lk5yzREwEa8/BqfB72wQv7pE5DE="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"dPgpZ8AE\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 28 Mar 2022 15:03:33 +0300","Message-Id":"<20220328120336.10834-2-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20220328120336.10834-1-laurent.pinchart@ideasonboard.com>","References":"<20220328120336.10834-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 1/4] libipa: camera_sensor_helper:\n\tReorganize gain constants","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>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"To prepare for other gain models than the linear model, store the gain\nconstants in a union with per-model members. Due to the lack of\ndesignated initializer support in gcc with C++17, initializing a single\ncomplex structure that includes a union will be difficult. Split the\ngain model type to a separate variable to work around this issue.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/ipa/libipa/camera_sensor_helper.cpp | 102 ++++++++++++++----------\n src/ipa/libipa/camera_sensor_helper.h   |  10 ++-\n 2 files changed, 65 insertions(+), 47 deletions(-)","diff":"diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp\nindex c953def04fd7..714cd86f039f 100644\n--- a/src/ipa/libipa/camera_sensor_helper.cpp\n+++ b/src/ipa/libipa/camera_sensor_helper.cpp\n@@ -58,11 +58,13 @@ namespace ipa {\n  */\n uint32_t CameraSensorHelper::gainCode(double gain) const\n {\n-\tASSERT(analogueGainConstants_.m0 == 0 || analogueGainConstants_.m1 == 0);\n-\tASSERT(analogueGainConstants_.type == AnalogueGainLinear);\n+\tconst AnalogueGainConstants &k = gainConstants_;\n \n-\treturn (analogueGainConstants_.c0 - analogueGainConstants_.c1 * gain) /\n-\t       (analogueGainConstants_.m1 * gain - analogueGainConstants_.m0);\n+\tASSERT(gainType_ == AnalogueGainLinear);\n+\tASSERT(k.linear.m0 == 0 || k.linear.m1 == 0);\n+\n+\treturn (k.linear.c0 - k.linear.c1 * gain) /\n+\t       (k.linear.m1 * gain - k.linear.m0);\n }\n \n /**\n@@ -80,11 +82,13 @@ uint32_t CameraSensorHelper::gainCode(double gain) const\n  */\n double CameraSensorHelper::gain(uint32_t gainCode) const\n {\n-\tASSERT(analogueGainConstants_.m0 == 0 || analogueGainConstants_.m1 == 0);\n-\tASSERT(analogueGainConstants_.type == AnalogueGainLinear);\n+\tconst AnalogueGainConstants &k = gainConstants_;\n \n-\treturn (analogueGainConstants_.m0 * static_cast<double>(gainCode) + analogueGainConstants_.c0) /\n-\t       (analogueGainConstants_.m1 * static_cast<double>(gainCode) + analogueGainConstants_.c1);\n+\tASSERT(gainType_ == AnalogueGainLinear);\n+\tASSERT(k.linear.m0 == 0 || k.linear.m1 == 0);\n+\n+\treturn (k.linear.m0 * static_cast<double>(gainCode) + k.linear.c0) /\n+\t       (k.linear.m1 * static_cast<double>(gainCode) + k.linear.c1);\n }\n \n /**\n@@ -127,42 +131,45 @@ double CameraSensorHelper::gain(uint32_t gainCode) const\n  * \\todo not implemented in libipa\n  */\n \n+/**\n+ * \\struct CameraSensorHelper::AnalogueGainLinearConstants\n+ * \\brief Analogue gain constants for the linear gain model\n+ *\n+ * \\var CameraSensorHelper::AnalogueGainLinearConstants::m0\n+ * \\brief Constant used in the linear gain coding/decoding\n+ *\n+ * \\note Either m0 or m1 shall be zero.\n+ *\n+ * \\var CameraSensorHelper::AnalogueGainLinearConstants::c0\n+ * \\brief Constant used in the linear gain coding/decoding\n+ *\n+ * \\var CameraSensorHelper::AnalogueGainLinearConstants::m1\n+ * \\brief Constant used in the linear gain coding/decoding\n+ *\n+ * \\note Either m0 or m1 shall be zero.\n+ *\n+ * \\var CameraSensorHelper::AnalogueGainLinearConstants::c1\n+ * \\brief Constant used in the linear gain coding/decoding\n+ */\n+\n /**\n  * \\struct CameraSensorHelper::AnalogueGainConstants\n- * \\brief Analogue gain constants used for gain calculation\n- */\n-\n-/**\n- * \\var CameraSensorHelper::AnalogueGainConstants::type\n- * \\brief Analogue gain calculation mode\n- */\n-\n-/**\n- * \\var CameraSensorHelper::AnalogueGainConstants::m0\n- * \\brief Constant used in the analogue Gain coding/decoding\n+ * \\brief Analogue gain model constants\n  *\n- * \\note Either m0 or m1 shall be zero.\n- */\n-\n-/**\n- * \\var CameraSensorHelper::AnalogueGainConstants::c0\n- * \\brief Constant used in the analogue gain coding/decoding\n- */\n-\n-/**\n- * \\var CameraSensorHelper::AnalogueGainConstants::m1\n- * \\brief Constant used in the analogue gain coding/decoding\n+ * This union stores the constants used to calculate the analogue gain. The\n+ * CameraSensorHelper::gainType_ variable selects which union member is valid.\n  *\n- * \\note Either m0 or m1 shall be zero.\n+ * \\var CameraSensorHelper::AnalogueGainConstants::linear\n+ * \\brief Constants for the linear gain model\n  */\n \n /**\n- * \\var CameraSensorHelper::AnalogueGainConstants::c1\n- * \\brief Constant used in the analogue gain coding/decoding\n+ * \\var CameraSensorHelper::gainType_\n+ * \\brief The analogue gain model type\n  */\n \n /**\n- * \\var CameraSensorHelper::analogueGainConstants_\n+ * \\var CameraSensorHelper::gainConstants_\n  * \\brief The analogue gain parameters used for calculation\n  *\n  * The analogue gain is calculated through a formula, and its parameters are\n@@ -290,7 +297,8 @@ class CameraSensorHelperImx219 : public CameraSensorHelper\n public:\n \tCameraSensorHelperImx219()\n \t{\n-\t\tanalogueGainConstants_ = { AnalogueGainLinear, 0, 256, -1, 256 };\n+\t\tgainType_ = AnalogueGainLinear;\n+\t\tgainConstants_.linear = { 0, 256, -1, 256 };\n \t}\n };\n REGISTER_CAMERA_SENSOR_HELPER(\"imx219\", CameraSensorHelperImx219)\n@@ -298,10 +306,11 @@ REGISTER_CAMERA_SENSOR_HELPER(\"imx219\", CameraSensorHelperImx219)\n class CameraSensorHelperImx258 : public CameraSensorHelper\n {\n public:\n-        CameraSensorHelperImx258()\n-        {\n-                analogueGainConstants_ = { AnalogueGainLinear, 0, 512, -1, 512 };\n-        }\n+\tCameraSensorHelperImx258()\n+\t{\n+\t\tgainType_ = AnalogueGainLinear;\n+\t\tgainConstants_.linear = { 0, 512, -1, 512 };\n+\t}\n };\n REGISTER_CAMERA_SENSOR_HELPER(\"imx258\", CameraSensorHelperImx258)\n \n@@ -310,7 +319,8 @@ class CameraSensorHelperOv2740 : public CameraSensorHelper\n public:\n \tCameraSensorHelperOv2740()\n \t{\n-\t\tanalogueGainConstants_ = { AnalogueGainLinear, 1, 0, 0, 128 };\n+\t\tgainType_ = AnalogueGainLinear;\n+\t\tgainConstants_.linear = { 1, 0, 0, 128 };\n \t}\n };\n REGISTER_CAMERA_SENSOR_HELPER(\"ov2740\", CameraSensorHelperOv2740)\n@@ -320,7 +330,8 @@ class CameraSensorHelperOv5670 : public CameraSensorHelper\n public:\n \tCameraSensorHelperOv5670()\n \t{\n-\t\tanalogueGainConstants_ = { AnalogueGainLinear, 1, 0, 0, 128 };\n+\t\tgainType_ = AnalogueGainLinear;\n+\t\tgainConstants_.linear = { 1, 0, 0, 128 };\n \t}\n };\n REGISTER_CAMERA_SENSOR_HELPER(\"ov5670\", CameraSensorHelperOv5670)\n@@ -330,7 +341,8 @@ class CameraSensorHelperOv5693 : public CameraSensorHelper\n public:\n \tCameraSensorHelperOv5693()\n \t{\n-\t\tanalogueGainConstants_ = { AnalogueGainLinear, 1, 0, 0, 16 };\n+\t\tgainType_ = AnalogueGainLinear;\n+\t\tgainConstants_.linear = { 1, 0, 0, 16 };\n \t}\n };\n REGISTER_CAMERA_SENSOR_HELPER(\"ov5693\", CameraSensorHelperOv5693)\n@@ -340,7 +352,8 @@ class CameraSensorHelperOv8865 : public CameraSensorHelper\n public:\n \tCameraSensorHelperOv8865()\n \t{\n-\t\tanalogueGainConstants_ = { AnalogueGainLinear, 1, 0, 0, 128 };\n+\t\tgainType_ = AnalogueGainLinear;\n+\t\tgainConstants_.linear = { 1, 0, 0, 128 };\n \t}\n };\n REGISTER_CAMERA_SENSOR_HELPER(\"ov8865\", CameraSensorHelperOv8865)\n@@ -350,7 +363,8 @@ class CameraSensorHelperOv13858 : public CameraSensorHelper\n public:\n \tCameraSensorHelperOv13858()\n \t{\n-\t\tanalogueGainConstants_ = { AnalogueGainLinear, 1, 0, 0, 128 };\n+\t\tgainType_ = AnalogueGainLinear;\n+\t\tgainConstants_.linear = { 1, 0, 0, 128 };\n \t}\n };\n REGISTER_CAMERA_SENSOR_HELPER(\"ov13858\", CameraSensorHelperOv13858)\ndiff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h\nindex 26adfcb5955f..6b96520ba601 100644\n--- a/src/ipa/libipa/camera_sensor_helper.h\n+++ b/src/ipa/libipa/camera_sensor_helper.h\n@@ -34,15 +34,19 @@ protected:\n \t\tAnalogueGainExponential,\n \t};\n \n-\tstruct AnalogueGainConstants {\n-\t\tAnalogueGainType type;\n+\tstruct AnalogueGainLinearConstants {\n \t\tint16_t m0;\n \t\tint16_t c0;\n \t\tint16_t m1;\n \t\tint16_t c1;\n \t};\n \n-\tAnalogueGainConstants analogueGainConstants_;\n+\tunion AnalogueGainConstants {\n+\t\tAnalogueGainLinearConstants linear;\n+\t};\n+\n+\tAnalogueGainType gainType_;\n+\tAnalogueGainConstants gainConstants_;\n \n private:\n \tLIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelper)\n","prefixes":["libcamera-devel","1/4"]}