summary refs log tree commit diff
path: root/third_party/blurhash/blurhash.cpp
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2022-10-26 01:10:35 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2022-10-26 01:10:35 +0200
commitb28fa86e6ab633b2d3d9bfdb4642c661ff8c45fc (patch)
treee3500273bcd79fc9e6389e8dcc626607a2677678 /third_party/blurhash/blurhash.cpp
parentMerge pull request #1215 from foxB612/fix-thumbnail-size (diff)
downloadnheko-b28fa86e6ab633b2d3d9bfdb4642c661ff8c45fc.tar.xz
Enable -Wconversion
Diffstat (limited to '')
-rw-r--r--third_party/blurhash/blurhash.cpp14
1 files changed, 6 insertions, 8 deletions
diff --git a/third_party/blurhash/blurhash.cpp b/third_party/blurhash/blurhash.cpp
index 78f72f9b..7eb9c827 100644
--- a/third_party/blurhash/blurhash.cpp
+++ b/third_party/blurhash/blurhash.cpp
@@ -4,6 +4,7 @@
 #include <array>
 #include <cassert>
 #include <cmath>
+#include <numbers>
 #include <stdexcept>
 
 #ifdef DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
@@ -17,9 +18,6 @@
 using namespace std::literals;
 
 namespace {
-template<class T>
-T pi = 3.14159265358979323846;
-
 constexpr std::array<char, 84> int_to_b83{
   "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~"};
 
@@ -93,7 +91,7 @@ decode83(std::string_view value)
 float
 decodeMaxAC(int quantizedMaxAC) noexcept
 {
-        return (quantizedMaxAC + 1) / 166.;
+        return static_cast<float>(quantizedMaxAC + 1) / 166.f;
 }
 
 float
@@ -123,7 +121,7 @@ srgbToLinear(int value) noexcept
                         return std::pow((x + 0.055f) / 1.055f, 2.4f);
         };
 
-        return srgbToLinearF(value / 255.f);
+        return srgbToLinearF(static_cast<float>(value) / 255.f);
 }
 
 int
@@ -234,7 +232,7 @@ std::vector<float>
 bases_for(size_t dimension, size_t components)
 {
         std::vector<float> bases(dimension * components, 0.f);
-        auto scale = pi<float> / float(dimension);
+        auto scale = std::numbers::pi_v<float> / float(dimension);
         for (size_t x = 0; x < dimension; x++) {
                 for (size_t nx = 0; nx < size_t(components); nx++) {
                         bases[x * components + nx] = std::cos(scale * float(nx * x));
@@ -323,7 +321,7 @@ encode(unsigned char *image, size_t width, size_t height, int components_x, int
                                      srgbToLinear(image[3 * x + 2 + y * width * 3])};
 
                         // other half of normalization.
-                        linear *= 1.f / width;
+                        linear *= 1.f / static_cast<float>(width);
 
                         for (size_t ny = 0; ny < size_t(components_y); ny++) {
                                 for (size_t nx = 0; nx < size_t(components_x); nx++) {
@@ -339,7 +337,7 @@ encode(unsigned char *image, size_t width, size_t height, int components_x, int
         // too far outside the float range.
         for (size_t i = 0; i < factors.size(); i++) {
                 float normalisation = (i == 0) ? 1 : 2;
-                float scale         = normalisation / (height);
+                float scale         = normalisation / static_cast<float>(height);
                 factors[i] *= scale;
         }