<div dir="ltr"><div dir="ltr">Hi all,<div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 25 Sept 2024 at 23:12, Laurent Pinchart <<a href="mailto:laurent.pinchart@ideasonboard.com">laurent.pinchart@ideasonboard.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">As explained in the coding style document, usage of std::abs() is<br>
preferred over abs() or fabs() as it picks the correct function based on<br>
the argument type. Replace calls to abs() and fabs() with std::abs() in<br>
the Raspberry Pi algorithms.<br>
<br>
This fixes a reported warning from clang:<br>
<br>
../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]<br>
if (abs(denominator) > eps) {<br>
^<br>
../src/ipa/rpi/controller/rpi/awb.cpp:508:6: note: use function 'std::abs' instead<br>
if (abs(denominator) > eps) {<br>
^~~<br>
std::abs<br>
<br>
Reported-by: Maarten Lankhorst <<a href="mailto:dev@lankhorst.se" target="_blank">dev@lankhorst.se</a>><br>
Signed-off-by: Laurent Pinchart <<a href="mailto:laurent.pinchart@ideasonboard.com" target="_blank">laurent.pinchart@ideasonboard.com</a>><br>
---<br>
Naush, David, I have only compile-tested this patch, could you give it a<br>
try to make sure it doesn't break anything ?<br></blockquote><div><br></div><div>I've done some brief testing and nothing seems to go wrong running with these changes.</div><div><br></div><div>Tested-by: Naushir Patuck <<a href="mailto:naush@raspberrypi.com">naush@raspberrypi.com</a>> </div><div>Reviewed-by: Naushir Patuck <<a href="mailto:naush@raspberrypi.com">naush@raspberrypi.com</a>><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
---<br>
src/ipa/rpi/controller/rpi/alsc.cpp | 18 +++++++++---------<br>
src/ipa/rpi/controller/rpi/awb.cpp | 3 ++-<br>
2 files changed, 11 insertions(+), 10 deletions(-)<br>
<br>
diff --git a/src/ipa/rpi/controller/rpi/alsc.cpp b/src/ipa/rpi/controller/rpi/alsc.cpp<br>
index 161fd45526ec..21edb819ad1c 100644<br>
--- a/src/ipa/rpi/controller/rpi/alsc.cpp<br>
+++ b/src/ipa/rpi/controller/rpi/alsc.cpp<br>
@@ -6,8 +6,8 @@<br>
*/<br>
<br>
#include <algorithm><br>
+#include <cmath><br>
#include <functional><br>
-#include <math.h><br>
#include <numeric><br>
#include <vector><br>
<br>
@@ -252,12 +252,12 @@ static bool compareModes(CameraMode const &cm0, CameraMode const &cm1)<br>
*/<br>
if (cm0.transform != cm1.transform)<br>
return true;<br>
- int leftDiff = abs(cm0.cropX - cm1.cropX);<br>
- int topDiff = abs(cm0.cropY - cm1.cropY);<br>
- int rightDiff = fabs(cm0.cropX + cm0.scaleX * cm0.width -<br>
- cm1.cropX - cm1.scaleX * cm1.width);<br>
- int bottomDiff = fabs(cm0.cropY + cm0.scaleY * cm0.height -<br>
- cm1.cropY - cm1.scaleY * cm1.height);<br>
+ int leftDiff = std::abs(cm0.cropX - cm1.cropX);<br>
+ int topDiff = std::abs(cm0.cropY - cm1.cropY);<br>
+ int rightDiff = std::abs(cm0.cropX + cm0.scaleX * cm0.width -<br>
+ cm1.cropX - cm1.scaleX * cm1.width);<br>
+ int bottomDiff = std::abs(cm0.cropY + cm0.scaleY * cm0.height -<br>
+ cm1.cropY - cm1.scaleY * cm1.height);<br>
/*<br>
* These thresholds are a rather arbitrary amount chosen to trigger<br>
* when carrying on with the previously calculated tables might be<br>
@@ -732,7 +732,7 @@ static double gaussSeidel2Sor(const SparseArray<double> &M, double omega,<br>
double maxDiff = 0;<br>
for (i = 0; i < XY; i++) {<br>
lambda[i] = oldLambda[i] + (lambda[i] - oldLambda[i]) * omega;<br>
- if (fabs(lambda[i] - oldLambda[i]) > fabs(maxDiff))<br>
+ if (std::abs(lambda[i] - oldLambda[i]) > std::abs(maxDiff))<br>
maxDiff = lambda[i] - oldLambda[i];<br>
}<br>
return maxDiff;<br>
@@ -764,7 +764,7 @@ static void runMatrixIterations(const Array2D<double> &C,<br>
constructM(C, W, M);<br>
double lastMaxDiff = std::numeric_limits<double>::max();<br>
for (unsigned int i = 0; i < nIter; i++) {<br>
- double maxDiff = fabs(gaussSeidel2Sor(M, omega, lambda, lambdaBound));<br>
+ double maxDiff = std::abs(gaussSeidel2Sor(M, omega, lambda, lambdaBound));<br>
if (maxDiff < threshold) {<br>
LOG(RPiAlsc, Debug)<br>
<< "Stop after " << i + 1 << " iterations";<br>
diff --git a/src/ipa/rpi/controller/rpi/awb.cpp b/src/ipa/rpi/controller/rpi/awb.cpp<br>
index f45525bce2d1..e5d51092605e 100644<br>
--- a/src/ipa/rpi/controller/rpi/awb.cpp<br>
+++ b/src/ipa/rpi/controller/rpi/awb.cpp<br>
@@ -6,6 +6,7 @@<br>
*/<br>
<br>
#include <assert.h><br>
+#include <cmath><br>
#include <functional><br>
<br>
#include <libcamera/base/log.h><br>
@@ -505,7 +506,7 @@ static double interpolateQuadatric(ipa::Pwl::Point const &a, ipa::Pwl::Point con<br>
const double eps = 1e-3;<br>
ipa::Pwl::Point ca = c - a, ba = b - a;<br>
double denominator = 2 * (ba.y() * ca.x() - ca.y() * ba.x());<br>
- if (abs(denominator) > eps) {<br>
+ if (std::abs(denominator) > eps) {<br>
double numerator = ba.y() * ca.x() * ca.x() - ca.y() * ba.x() * ba.x();<br>
double result = numerator / denominator + a.x();<br>
return std::max(a.x(), std::min(c.x(), result));<br>
<br>
base-commit: f2088eb91fd6477b152233b9031cb115ca1ae824<br>
-- <br>
Regards,<br>
<br>
Laurent Pinchart<br>
<br>
</blockquote></div></div>