Browse Source

Corrected height calculation, floored log2-output explicitly.

tags/0.3.3
tastytea 6 months ago
parent
commit
0425ee3fec
Signed by: tastytea <tastytea@tastytea.de> GPG Key ID: CFC39497F1B26E07
3 changed files with 6 additions and 5 deletions
  1. 1
    1
      CMakeLists.txt
  2. 2
    2
      src/checks.cpp
  3. 3
    2
      src/identiconpp.cpp

+ 1
- 1
CMakeLists.txt View File

@@ -1,6 +1,6 @@
1 1
 cmake_minimum_required (VERSION 3.2)
2 2
 project(identiconpp
3
-        VERSION 0.3.2
3
+        VERSION 0.3.3
4 4
         LANGUAGES CXX
5 5
 )
6 6
 

+ 2
- 2
src/checks.cpp View File

@@ -42,14 +42,14 @@ void Identiconpp::check_entropy(const string &digest, algorithm type)
42 42
             // We need bits for each field in half of the columns, +1 column if
43 43
             // they are uneven. Then we need enough bits to pick a color.
44 44
             entropy_required = (_columns / 2 + _columns % 2) * _rows
45
-                + std::log2(_foreground.size()) + 1;
45
+                + std::floor(std::log2(_foreground.size())) + 1;
46 46
             break;
47 47
         }
48 48
         case algorithm::ltr_asymmetric:
49 49
         {
50 50
             entropy_provided = digest.length() * 4;
51 51
             entropy_required = _columns * _rows
52
-                + std::log2(_foreground.size()) + 1;
52
+                + std::floor(std::log2(_foreground.size())) + 1;
53 53
             break;
54 54
         }
55 55
         case algorithm::sigil:

+ 3
- 2
src/identiconpp.cpp View File

@@ -46,7 +46,8 @@ Magick::Image Identiconpp::generate(const string &digest, const uint16_t width)
46 46
     ttdebug << "Using digest: " << digest << '\n';
47 47
     check_entropy(digest, _type);
48 48
     const uint16_t imgwidth = width - _padding[0] * 2;
49
-    const uint16_t imgheight = imgwidth / _columns * _rows;
49
+    const uint16_t imgheight =
50
+        std::round(static_cast<float>(imgwidth) / _columns * _rows);
50 51
     ttdebug << "width: " << std::to_string(imgwidth + _padding[0] * 2)
51 52
             << ", height: " << std::to_string(imgheight + _padding[1] * 2)
52 53
             << "\n";
@@ -101,7 +102,7 @@ Magick::Color Identiconpp::get_color(const uint16_t firstbit,
101 102
                                      const string &digest)
102 103
 {
103 104
     // Number of bits to use
104
-    const uint16_t colorbits = std::log2(_foreground.size()) + 1;
105
+    const uint16_t colorbits = std::floor(std::log2(_foreground.size())) + 1;
105 106
 
106 107
     // Extract approximation
107 108
     std::stringstream ss;

Loading…
Cancel
Save