{"id":21373,"url":"https://patchwork.libcamera.org/api/1.1/patches/21373/?format=json","web_url":"https://patchwork.libcamera.org/patch/21373/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20240925221210.12331-1-laurent.pinchart@ideasonboard.com>","date":"2024-09-25T22:12:10","name":"ipa: rpi: Use std::abs()","commit_ref":"8b378a56060fd4df8cd072d863832d49c34267b9","pull_url":null,"state":"accepted","archived":false,"hash":"4e0ef70d570053da81c550d8c3630d9b32748aab","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/21373/mbox/","series":[{"id":4626,"url":"https://patchwork.libcamera.org/api/1.1/series/4626/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4626","date":"2024-09-25T22:12:10","name":"ipa: rpi: Use std::abs()","version":1,"mbox":"https://patchwork.libcamera.org/series/4626/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/21373/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/21373/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 86B8EC3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 25 Sep 2024 22:12:15 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A11E76350E;\n\tThu, 26 Sep 2024 00:12:14 +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 69BB5634FB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 00:12:12 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5E750163;\n\tThu, 26 Sep 2024 00:10:44 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"EepsjrjL\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727302244;\n\tbh=5ESKKSdZjyDpVBlfK67AtSsgvgCm7REA9Acaqz7HHL4=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=EepsjrjL4L7fDXN931yE1Ga+i28l9id+jioRLs/J/HWClS2S4aU5saf1ntFXpqun8\n\twqTFMl121OOcGe2RvI7JayD8tuBPaGooOlJxC1r6SMb1pZFVusMpMQ4R/V/0i3jeL/\n\t10X9yhzrkr1Pz89Z/MzjDazB6W4Hf9XX6cjUL5uQ=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Naushir Patuck <naush@raspberrypi.com>,\n\tDavid Plowman <david.plowman@raspberrypi.com>,\n\tMilan Zamazal <mzamazal@redhat.com>, Maarten Lankhorst <dev@lankhorst.se>","Subject":"[PATCH] ipa: rpi: Use std::abs()","Date":"Thu, 26 Sep 2024 01:12:10 +0300","Message-ID":"<20240925221210.12331-1-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.45.2","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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":"As explained in the coding style document, usage of std::abs() is\npreferred over abs() or fabs() as it picks the correct function based on\nthe argument type. Replace calls to abs() and fabs() with std::abs() in\nthe Raspberry Pi algorithms.\n\nThis fixes a reported warning from clang:\n\n../src/ipa/rpi/controller/rpi/awb.cpp:508:6: error: using integer absolute value function 'abs' when argument is of floating point type [-Werror,-Wabsolute-value]\n        if (abs(denominator) > eps) {\n            ^\n../src/ipa/rpi/controller/rpi/awb.cpp:508:6: note: use function 'std::abs' instead\n        if (abs(denominator) > eps) {\n            ^~~\n            std::abs\n\nReported-by: Maarten Lankhorst <dev@lankhorst.se>\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\nNaush, David, I have only compile-tested this patch, could you give it a\ntry to make sure it doesn't break anything ?\n---\n src/ipa/rpi/controller/rpi/alsc.cpp | 18 +++++++++---------\n src/ipa/rpi/controller/rpi/awb.cpp  |  3 ++-\n 2 files changed, 11 insertions(+), 10 deletions(-)\n\n\nbase-commit: f2088eb91fd6477b152233b9031cb115ca1ae824","diff":"diff --git a/src/ipa/rpi/controller/rpi/alsc.cpp b/src/ipa/rpi/controller/rpi/alsc.cpp\nindex 161fd45526ec..21edb819ad1c 100644\n--- a/src/ipa/rpi/controller/rpi/alsc.cpp\n+++ b/src/ipa/rpi/controller/rpi/alsc.cpp\n@@ -6,8 +6,8 @@\n  */\n \n #include <algorithm>\n+#include <cmath>\n #include <functional>\n-#include <math.h>\n #include <numeric>\n #include <vector>\n \n@@ -252,12 +252,12 @@ static bool compareModes(CameraMode const &cm0, CameraMode const &cm1)\n \t */\n \tif (cm0.transform != cm1.transform)\n \t\treturn true;\n-\tint leftDiff = abs(cm0.cropX - cm1.cropX);\n-\tint topDiff = abs(cm0.cropY - cm1.cropY);\n-\tint rightDiff = fabs(cm0.cropX + cm0.scaleX * cm0.width -\n-\t\t\t     cm1.cropX - cm1.scaleX * cm1.width);\n-\tint bottomDiff = fabs(cm0.cropY + cm0.scaleY * cm0.height -\n-\t\t\t      cm1.cropY - cm1.scaleY * cm1.height);\n+\tint leftDiff = std::abs(cm0.cropX - cm1.cropX);\n+\tint topDiff = std::abs(cm0.cropY - cm1.cropY);\n+\tint rightDiff = std::abs(cm0.cropX + cm0.scaleX * cm0.width -\n+\t\t\t\t cm1.cropX - cm1.scaleX * cm1.width);\n+\tint bottomDiff = std::abs(cm0.cropY + cm0.scaleY * cm0.height -\n+\t\t\t\t  cm1.cropY - cm1.scaleY * cm1.height);\n \t/*\n \t * These thresholds are a rather arbitrary amount chosen to trigger\n \t * when carrying on with the previously calculated tables might be\n@@ -732,7 +732,7 @@ static double gaussSeidel2Sor(const SparseArray<double> &M, double omega,\n \tdouble maxDiff = 0;\n \tfor (i = 0; i < XY; i++) {\n \t\tlambda[i] = oldLambda[i] + (lambda[i] - oldLambda[i]) * omega;\n-\t\tif (fabs(lambda[i] - oldLambda[i]) > fabs(maxDiff))\n+\t\tif (std::abs(lambda[i] - oldLambda[i]) > std::abs(maxDiff))\n \t\t\tmaxDiff = lambda[i] - oldLambda[i];\n \t}\n \treturn maxDiff;\n@@ -764,7 +764,7 @@ static void runMatrixIterations(const Array2D<double> &C,\n \tconstructM(C, W, M);\n \tdouble lastMaxDiff = std::numeric_limits<double>::max();\n \tfor (unsigned int i = 0; i < nIter; i++) {\n-\t\tdouble maxDiff = fabs(gaussSeidel2Sor(M, omega, lambda, lambdaBound));\n+\t\tdouble maxDiff = std::abs(gaussSeidel2Sor(M, omega, lambda, lambdaBound));\n \t\tif (maxDiff < threshold) {\n \t\t\tLOG(RPiAlsc, Debug)\n \t\t\t\t<< \"Stop after \" << i + 1 << \" iterations\";\ndiff --git a/src/ipa/rpi/controller/rpi/awb.cpp b/src/ipa/rpi/controller/rpi/awb.cpp\nindex f45525bce2d1..e5d51092605e 100644\n--- a/src/ipa/rpi/controller/rpi/awb.cpp\n+++ b/src/ipa/rpi/controller/rpi/awb.cpp\n@@ -6,6 +6,7 @@\n  */\n \n #include <assert.h>\n+#include <cmath>\n #include <functional>\n \n #include <libcamera/base/log.h>\n@@ -505,7 +506,7 @@ static double interpolateQuadatric(ipa::Pwl::Point const &a, ipa::Pwl::Point con\n \tconst double eps = 1e-3;\n \tipa::Pwl::Point ca = c - a, ba = b - a;\n \tdouble denominator = 2 * (ba.y() * ca.x() - ca.y() * ba.x());\n-\tif (abs(denominator) > eps) {\n+\tif (std::abs(denominator) > eps) {\n \t\tdouble numerator = ba.y() * ca.x() * ca.x() - ca.y() * ba.x() * ba.x();\n \t\tdouble result = numerator / denominator + a.x();\n \t\treturn std::max(a.x(), std::min(c.x(), result));\n","prefixes":[]}