Corrected the "how many bits do i need for n colors"-algorithm.
the build was successful Details

This commit is contained in:
tastytea 2018-12-27 21:56:50 +01:00
parent 42e7fd9a18
commit 36dd2b7e5a
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
4 changed files with 9 additions and 5 deletions

View File

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

View File

@ -1,4 +1,4 @@
**identiconpp** is a library to generate identicons. Written in C++.
**identiconpp** is a library to generate identicons for C++.
You get the images as `Magick::Image`. This allows you to make all kinds of
modifications.
@ -119,6 +119,7 @@ and you are welcome to redistribute it under certain conditions.
* Use bits from digest to determine if a pixel is painted(1) or not(0).
* Mirror the pixels vertically.
* Use the following bits to pick the foreground color.
* You need `log2(n_colors) + 1` bits.
* Scale image proportionally to requested width.
```PLAIN
@ -139,6 +140,7 @@ Implemented in [ltr_symmetric.cpp]
* Pixels are drawn from left to right, top to bottom.
* Use bits from digest to determine if a pixel is painted(1) or not(0).
* Use the following bits to pick the foreground color.
* * You need `log2(n_colors) + 1` bits.
* Scale image proportionally to requested width.
```PLAIN

View File

@ -17,6 +17,7 @@
#include <exception>
#include <stdexcept>
#include <algorithm>
#include <cmath>
#include "identiconpp.hpp"
#include "debug.hpp"
@ -41,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
// they are uneven. Then we need enough bits to pick a color.
entropy_required = (_columns / 2 + _columns % 2) * _rows
+ (_foreground.size() / 2 + _foreground.size() % 2);
+ std::log2(_foreground.size()) + 1;
break;
}
case algorithm::ltr_asymmetric:
{
entropy_provided = digest.length() * 4;
entropy_required = _columns * _rows
+ (_foreground.size() / 2 + _foreground.size() % 2);
+ std::log2(_foreground.size()) + 1;
break;
}
case algorithm::sigil:

View File

@ -17,6 +17,7 @@
#include <exception>
#include <stdexcept>
#include <sstream>
#include <cmath>
#include "identiconpp.hpp"
#include "debug.hpp"
@ -100,7 +101,7 @@ Magick::Color Identiconpp::get_color(const uint16_t firstbit,
const string &digest)
{
// Number of bits to use
const uint16_t colorbits = _foreground.size() / 2 + _foreground.size() % 2;
const uint16_t colorbits = std::log2(_foreground.size()) + 1;
// Extract approximation
std::stringstream ss;