{"id":15053,"url":"https://patchwork.libcamera.org/api/patches/15053/?format=json","web_url":"https://patchwork.libcamera.org/patch/15053/","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":"<20211206152644.4863-3-laurent.pinchart@ideasonboard.com>","date":"2021-12-06T15:26:44","name":"[libcamera-devel,2/2] libcamera: Use utils::abs_diff()","commit_ref":"e7888073718aadd7c35a78f88792a73a4e3a8300","pull_url":null,"state":"accepted","archived":false,"hash":"361765c1ebccce4427e07c40d1f5f81c20be230c","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":{"id":14,"url":"https://patchwork.libcamera.org/api/users/14/?format=json","username":"pinchartl","first_name":"Laurent","last_name":"Pinchart","email":"laurent.pinchart@ideasonboard.com"},"mbox":"https://patchwork.libcamera.org/patch/15053/mbox/","series":[{"id":2819,"url":"https://patchwork.libcamera.org/api/series/2819/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2819","date":"2021-12-06T15:26:42","name":"libcamera: Introduce utils::abs_diff()","version":1,"mbox":"https://patchwork.libcamera.org/series/2819/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/15053/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/15053/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 3A296C324B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  6 Dec 2021 15:27:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 89BF560872;\n\tMon,  6 Dec 2021 16:27:19 +0100 (CET)","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 9097E60725\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  6 Dec 2021 16:27:17 +0100 (CET)","from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2F40BEE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  6 Dec 2021 16:27:17 +0100 (CET)"],"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=\"WrQTMAI4\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1638804437;\n\tbh=GIOM/Vi7n4eFp5C0umwzL4zXPb8iMvz2VZA/H+RrvMQ=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=WrQTMAI46FxHfmOCYCU7sfABTXh5ETrJEfT6fEIBwjGEhOs6MLUk6hlyj6AFCHEOK\n\td3rAZTKpR0nUXZEj3mce292HeN/BXkplciSE09+v+PnFQ9ubnJBQGcvaVvwB6wym26\n\tcVz4lHwIjkfxOoV0U42EMLd8pRNylJZLNWxpk6kc=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon,  6 Dec 2021 17:26:44 +0200","Message-Id":"<20211206152644.4863-3-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.32.0","In-Reply-To":"<20211206152644.4863-1-laurent.pinchart@ideasonboard.com>","References":"<20211206152644.4863-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 2/2] libcamera: Use utils::abs_diff()","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":"Use the new utils::abs_diff() function where appropriate to replace\nmanual implementations.\n\nWhile at it fix a header ordering issue in\nsrc/libcamera/pipeline/raspberrypi/raspberrypi.cpp.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/ipa/ipu3/algorithms/agc.cpp                    | 3 ++-\n src/ipa/ipu3/ipu3.cpp                              | 4 ++--\n src/ipa/rkisp1/algorithms/agc.cpp                  | 3 ++-\n src/libcamera/pipeline/ipu3/imgu.cpp               | 4 ++--\n src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 5 ++---\n 5 files changed, 10 insertions(+), 9 deletions(-)","diff":"diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\nindex 582f0ae1b54b..8d6f18f60aed 100644\n--- a/src/ipa/ipu3/algorithms/agc.cpp\n+++ b/src/ipa/ipu3/algorithms/agc.cpp\n@@ -12,6 +12,7 @@\n #include <cmath>\n \n #include <libcamera/base/log.h>\n+#include <libcamera/base/utils.h>\n \n #include <libcamera/ipa/core_ipa_interface.h>\n \n@@ -188,7 +189,7 @@ void Agc::computeExposure(IPAFrameContext &frameContext, double yGain,\n \tdouble evGain = std::max(yGain, iqMeanGain);\n \n \t/* Consider within 1% of the target as correctly exposed */\n-\tif (std::abs(evGain - 1.0) < 0.01)\n+\tif (utils::abs_diff(evGain, 1.0) < 0.01)\n \t\tLOG(IPU3Agc, Debug) << \"We are well exposed (evGain = \"\n \t\t\t\t    << evGain << \")\";\n \ndiff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\nindex 7618258725a8..3d30770867b9 100644\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -354,7 +354,7 @@ void IPAIPU3::calculateBdsGrid(const Size &bdsOutputSize)\n \t\t\t\t\t    kMaxGridWidth);\n \n \t\twidth = width << shift;\n-\t\tuint32_t error = std::abs(static_cast<int>(width - bdsOutputSize.width));\n+\t\tuint32_t error = utils::abs_diff(width, bdsOutputSize.width);\n \t\tif (error >= minError)\n \t\t\tcontinue;\n \n@@ -370,7 +370,7 @@ void IPAIPU3::calculateBdsGrid(const Size &bdsOutputSize)\n \t\t\t\t\t     kMaxGridHeight);\n \n \t\theight = height << shift;\n-\t\tuint32_t error = std::abs(static_cast<int>(height - bdsOutputSize.height));\n+\t\tuint32_t error = utils::abs_diff(height, bdsOutputSize.height);\n \t\tif (error >= minError)\n \t\t\tcontinue;\n \ndiff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp\nindex d6abdc310f35..dd97afc00813 100644\n--- a/src/ipa/rkisp1/algorithms/agc.cpp\n+++ b/src/ipa/rkisp1/algorithms/agc.cpp\n@@ -12,6 +12,7 @@\n #include <cmath>\n \n #include <libcamera/base/log.h>\n+#include <libcamera/base/utils.h>\n \n #include <libcamera/ipa/core_ipa_interface.h>\n \n@@ -145,7 +146,7 @@ void Agc::computeExposure(IPAContext &context, double yGain)\n \t\t\t\t\t  kMaxAnalogueGain);\n \n \t/* Consider within 1% of the target as correctly exposed. */\n-\tif (std::abs(yGain - 1.0) < 0.01)\n+\tif (utils::abs_diff(yGain, 1.0) < 0.01)\n \t\treturn;\n \n \t/* extracted from Rpi::Agc::computeTargetExposure. */\ndiff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp\nindex 3ef0ef144301..e5bbc3829c68 100644\n--- a/src/libcamera/pipeline/ipu3/imgu.cpp\n+++ b/src/libcamera/pipeline/ipu3/imgu.cpp\n@@ -81,7 +81,7 @@ float findScaleFactor(float sf, const std::vector<float> &range,\n \tfloat bestDiff = std::numeric_limits<float>::max();\n \tunsigned int index = 0;\n \tfor (unsigned int i = 0; i < range.size(); ++i) {\n-\t\tfloat diff = std::abs(sf - range[i]);\n+\t\tfloat diff = utils::abs_diff(sf, range[i]);\n \t\tif (diff < bestDiff) {\n \t\t\tbestDiff = diff;\n \t\t\tindex = i;\n@@ -99,7 +99,7 @@ bool isSameRatio(const Size &in, const Size &out)\n \tfloat inRatio = static_cast<float>(in.width) / in.height;\n \tfloat outRatio = static_cast<float>(out.width) / out.height;\n \n-\tif (std::abs(inRatio - outRatio) > 0.1)\n+\tif (utils::abs_diff(inRatio, outRatio) > 0.1)\n \t\treturn false;\n \n \treturn true;\ndiff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex 321b72adbbf7..2cb0267ccf4c 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -14,6 +14,7 @@\n #include <unordered_set>\n \n #include <libcamera/base/shared_fd.h>\n+#include <libcamera/base/utils.h>\n \n #include <libcamera/camera.h>\n #include <libcamera/control_ids.h>\n@@ -25,8 +26,6 @@\n #include <libcamera/property_ids.h>\n #include <libcamera/request.h>\n \n-#include <libcamera/base/utils.h>\n-\n #include <linux/bcm2835-isp.h>\n #include <linux/media-bus-format.h>\n #include <linux/videodev2.h>\n@@ -154,7 +153,7 @@ V4L2SubdeviceFormat findBestFormat(const SensorFormats &formatsMap, const Size &\n \t\t\tscore += penaltyAr * scoreFormat(reqAr, fmtAr);\n \n \t\t\t/* Add any penalties... this is not an exact science! */\n-\t\t\tscore += std::abs(static_cast<int>(info.bitsPerPixel - bitDepth)) * penaltyBitDepth;\n+\t\t\tscore += utils::abs_diff(info.bitsPerPixel, bitDepth) * penaltyBitDepth;\n \n \t\t\tif (score <= bestScore) {\n \t\t\t\tbestScore = score;\n","prefixes":["libcamera-devel","2/2"]}