Corrected height calculation, floored log2-output explicitly.
the build was successful Details

This commit is contained in:
tastytea 2018-12-27 22:24:36 +01:00
parent 36dd2b7e5a
commit 0425ee3fec
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
3 changed files with 6 additions and 5 deletions

View File

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

View File

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

View File

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