{"id":21374,"url":"https://patchwork.libcamera.org/api/1.1/patches/21374/?format=json","web_url":"https://patchwork.libcamera.org/patch/21374/","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":"<20240926002335.27509-1-laurent.pinchart@ideasonboard.com>","date":"2024-09-26T00:23:35","name":"libcamera: Replace usage of lroundf() with std::lround()","commit_ref":"fa2dfd55cc9e86589e505f9edc82a94b57405677","pull_url":null,"state":"accepted","archived":false,"hash":"0d62ea3eede0094106f87938987d16630a71bf2f","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/21374/mbox/","series":[{"id":4627,"url":"https://patchwork.libcamera.org/api/1.1/series/4627/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4627","date":"2024-09-26T00:23:35","name":"libcamera: Replace usage of lroundf() with std::lround()","version":1,"mbox":"https://patchwork.libcamera.org/series/4627/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/21374/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/21374/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 DCBB6C3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Sep 2024 00:23:40 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E77336350E;\n\tThu, 26 Sep 2024 02:23:39 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 03CD3634FB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 02:23:37 +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 0C324169\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 02:22:09 +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=\"JCpI8aDL\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727310130;\n\tbh=4QgfbP6sMNIa/z4R0U/svIc8EzqcPup2zZK8NpDTctY=;\n\th=From:To:Subject:Date:From;\n\tb=JCpI8aDLU3CVmzwcC8JEGNoZg89NFjtH65bg9FDju45jMcOk68CzUi8FdwMzACRPp\n\tV0L7xc9KTDL/b9Xlk9ZcILU87yPkdV3G4divrQbR1gTQ/cV7JqUDIlEGBlRFAc1tps\n\twe37hrC+odjTnxBBne8FFQp28ytsLq7tZQRad7q8=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Subject":"[PATCH] libcamera: Replace usage of lroundf() with std::lround()","Date":"Thu, 26 Sep 2024 03:23:35 +0300","Message-ID":"<20240926002335.27509-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::lround() is\npreferred over lroundf() as it picks the correct function based on\nthe argument type. Replace calls to lroundf() with std::lround() through\nlibcamera.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n Documentation/guides/pipeline-handler.rst    | 4 ++--\n src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 8 ++++----\n src/libcamera/pipeline/vimc/vimc.cpp         | 4 ++--\n 3 files changed, 8 insertions(+), 8 deletions(-)\n\n\nbase-commit: f2088eb91fd6477b152233b9031cb115ca1ae824","diff":"diff --git a/Documentation/guides/pipeline-handler.rst b/Documentation/guides/pipeline-handler.rst\nindex 26aea43341d4..69e832a5587e 100644\n--- a/Documentation/guides/pipeline-handler.rst\n+++ b/Documentation/guides/pipeline-handler.rst\n@@ -1350,7 +1350,7 @@ before being set.\n                         continue;\n                  }\n \n-                 int32_t value = lroundf(it.second.get<float>() * 128 + offset);\n+                 int32_t value = std::lround(it.second.get<float>() * 128 + offset);\n                  controls.set(cid, std::clamp(value, 0, 255));\n           }\n \n@@ -1414,7 +1414,7 @@ value translation operations:\n \n .. code-block:: cpp\n \n-   #include <math.h>\n+   #include <cmath>\n \n Frame completion and event handling\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\ndiff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\nindex 6b32fa18799b..7fa01bb71744 100644\n--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n@@ -6,9 +6,9 @@\n  */\n \n #include <algorithm>\n+#include <cmath>\n #include <fstream>\n #include <map>\n-#include <math.h>\n #include <memory>\n #include <set>\n #include <string>\n@@ -320,14 +320,14 @@ int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id,\n \tcase V4L2_CID_BRIGHTNESS: {\n \t\tfloat scale = std::max(max - def, def - min);\n \t\tfloat fvalue = value.get<float>() * scale + def;\n-\t\tcontrols->set(cid, static_cast<int32_t>(lroundf(fvalue)));\n+\t\tcontrols->set(cid, static_cast<int32_t>(std::lround(fvalue)));\n \t\tbreak;\n \t}\n \n \tcase V4L2_CID_SATURATION: {\n \t\tfloat scale = def - min;\n \t\tfloat fvalue = value.get<float>() * scale + min;\n-\t\tcontrols->set(cid, static_cast<int32_t>(lroundf(fvalue)));\n+\t\tcontrols->set(cid, static_cast<int32_t>(std::lround(fvalue)));\n \t\tbreak;\n \t}\n \n@@ -354,7 +354,7 @@ int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id,\n \t\t}\n \n \t\tfloat fvalue = (value.get<float>() - p) / m;\n-\t\tcontrols->set(cid, static_cast<int32_t>(lroundf(fvalue)));\n+\t\tcontrols->set(cid, static_cast<int32_t>(std::lround(fvalue)));\n \t\tbreak;\n \t}\n \ndiff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp\nindex 325174b90087..2165bae890cb 100644\n--- a/src/libcamera/pipeline/vimc/vimc.cpp\n+++ b/src/libcamera/pipeline/vimc/vimc.cpp\n@@ -6,9 +6,9 @@\n  */\n \n #include <algorithm>\n+#include <cmath>\n #include <iomanip>\n #include <map>\n-#include <math.h>\n #include <tuple>\n \n #include <linux/media-bus-format.h>\n@@ -420,7 +420,7 @@ int PipelineHandlerVimc::processControls(VimcCameraData *data, Request *request)\n \t\t\tcontinue;\n \t\t}\n \n-\t\tint32_t value = lroundf(it.second.get<float>() * 128 + offset);\n+\t\tint32_t value = std::lround(it.second.get<float>() * 128 + offset);\n \t\tcontrols.set(cid, std::clamp(value, 0, 255));\n \t}\n \n","prefixes":[]}