Corrected the "how many bits do i need for n colors"-algorithm.
the build was successful
Details
the build was successful
Details
This commit is contained in:
parent
42e7fd9a18
commit
36dd2b7e5a
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required (VERSION 3.2)
|
cmake_minimum_required (VERSION 3.2)
|
||||||
project(identiconpp
|
project(identiconpp
|
||||||
VERSION 0.3.1
|
VERSION 0.3.2
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -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
|
You get the images as `Magick::Image`. This allows you to make all kinds of
|
||||||
modifications.
|
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).
|
* Use bits from digest to determine if a pixel is painted(1) or not(0).
|
||||||
* Mirror the pixels vertically.
|
* Mirror the pixels vertically.
|
||||||
* Use the following bits to pick the foreground color.
|
* Use the following bits to pick the foreground color.
|
||||||
|
* You need `log2(n_colors) + 1` bits.
|
||||||
* Scale image proportionally to requested width.
|
* Scale image proportionally to requested width.
|
||||||
|
|
||||||
```PLAIN
|
```PLAIN
|
||||||
|
@ -139,6 +140,7 @@ Implemented in [ltr_symmetric.cpp]
|
||||||
* Pixels are drawn from left to right, top to bottom.
|
* 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 bits from digest to determine if a pixel is painted(1) or not(0).
|
||||||
* Use the following bits to pick the foreground color.
|
* Use the following bits to pick the foreground color.
|
||||||
|
* * You need `log2(n_colors) + 1` bits.
|
||||||
* Scale image proportionally to requested width.
|
* Scale image proportionally to requested width.
|
||||||
|
|
||||||
```PLAIN
|
```PLAIN
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cmath>
|
||||||
#include "identiconpp.hpp"
|
#include "identiconpp.hpp"
|
||||||
#include "debug.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
|
// 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
|
||||||
+ (_foreground.size() / 2 + _foreground.size() % 2);
|
+ 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
|
||||||
+ (_foreground.size() / 2 + _foreground.size() % 2);
|
+ std::log2(_foreground.size()) + 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case algorithm::sigil:
|
case algorithm::sigil:
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <cmath>
|
||||||
#include "identiconpp.hpp"
|
#include "identiconpp.hpp"
|
||||||
#include "debug.hpp"
|
#include "debug.hpp"
|
||||||
|
|
||||||
|
@ -100,7 +101,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 = _foreground.size() / 2 + _foreground.size() % 2;
|
const uint16_t colorbits = std::log2(_foreground.size()) + 1;
|
||||||
|
|
||||||
// Extract approximation
|
// Extract approximation
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
|
Loading…
Reference in New Issue