diff --git a/CMakeLists.txt b/CMakeLists.txt index f02bf79..86cb185 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.2) project(identiconpp - VERSION 0.1.2 + VERSION 0.2.0 LANGUAGES CXX ) diff --git a/example.cpp b/example.cpp index 3ca8e3f..517550a 100644 --- a/example.cpp +++ b/example.cpp @@ -20,7 +20,7 @@ int main(int argc, char *argv[]) } { - Identiconpp identicon(13, 10, Identiconpp::identicon_type::simple, + Identiconpp identicon(5, 5, Identiconpp::algorithm::ltr_symmetric, "ffffff88", { "000000ff", @@ -31,11 +31,11 @@ int main(int argc, char *argv[]) "0000ffff" }); img = identicon.generate(digest, 500); - img.write("identicon_example_simple.png"); + img.write("identicon_example_ltr_symmetric.png"); } { - Identiconpp identicon(5, 5, Identiconpp::identicon_type::libravatar, + Identiconpp identicon(5, 5, Identiconpp::algorithm::sigil, "ffffffff", { "000000ff", @@ -45,8 +45,8 @@ int main(int argc, char *argv[]) "00ffffff", "0000ffff" }); - img = identicon.generate("5a105e8b9d40e1329780d62ea2265d8a", 500); - img.write("identicon_example_libravatar.png"); + img = identicon.generate(digest, 500); + img.write("identicon_example_sigil.png"); } return 0; diff --git a/src/checks.cpp b/src/checks.cpp index e910a55..a0faa99 100644 --- a/src/checks.cpp +++ b/src/checks.cpp @@ -20,13 +20,13 @@ #include "identiconpp.hpp" #include "debug.hpp" -void Identiconpp::check_entropy(const string &digest, identicon_type type) +void Identiconpp::check_entropy(const string &digest, algorithm type) { uint16_t entropy_provided; uint16_t entropy_required; switch (type) { - case identicon_type::simple: + case algorithm::ltr_symmetric: { // Every char is 4 bit entropy_provided = digest.length() * 4; @@ -36,8 +36,7 @@ void Identiconpp::check_entropy(const string &digest, identicon_type type) + (_foreground.size() / 2 + _foreground.size() % 2); break; } - case identicon_type::libravatar: - case identicon_type::sigil: + case algorithm::sigil: { entropy_provided = digest.length() / 2 * 8; entropy_required = (_columns / 2 + _columns % 2) * _rows + 8; diff --git a/src/identiconpp.cpp b/src/identiconpp.cpp index 9d41c16..f2e9381 100644 --- a/src/identiconpp.cpp +++ b/src/identiconpp.cpp @@ -22,7 +22,7 @@ #include "debug.hpp" Identiconpp::Identiconpp(const uint8_t rows, const uint8_t columns, - identicon_type type, + algorithm type, const string &background, const vector &foreground) : _rows(rows) @@ -48,14 +48,13 @@ Magick::Image Identiconpp::generate(const string &digest, const uint16_t width) switch (_type) { - case identicon_type::simple: + case algorithm::ltr_symmetric: { - return generate_simple(digest, width, height); + return generate_ltr_symmetric(digest, width, height); } - case identicon_type::libravatar: - case identicon_type::sigil: + case algorithm::sigil: { - return generate_libravatar(digest, width, height); + return generate_sigil(digest, width, height); } } } diff --git a/src/identiconpp.hpp b/src/identiconpp.hpp index 42e972c..3b55958 100644 --- a/src/identiconpp.hpp +++ b/src/identiconpp.hpp @@ -34,14 +34,11 @@ class Identiconpp { public: /*! - * @brief List of identicon types - * - * libravatar and sigil are synonymous. + * @brief List of identicon algorithms */ - enum class identicon_type + enum class algorithm { - simple, - libravatar, + ltr_symmetric, sigil }; @@ -59,7 +56,7 @@ public: * @param foreground vector of foreground colors */ explicit Identiconpp(const uint8_t rows, const uint8_t columns, - identicon_type type = identicon_type::simple, + algorithm type = algorithm::ltr_symmetric, const string &background = "ffffffff", const vector &foreground = { "000000ff" } ); @@ -76,7 +73,7 @@ public: private: const uint8_t _rows; const uint8_t _columns; - const identicon_type _type; + const algorithm _type; const string _background; const vector _foreground; @@ -93,12 +90,12 @@ private: * * @return The image */ - Magick::Image generate_simple(const string &digest, - const uint16_t width, - const uint16_t height); + Magick::Image generate_ltr_symmetric(const string &digest, + const uint16_t width, + const uint16_t height); /*! - * @brief Generate libravatar-style / sigil identicon. + * @brief Generate sigil identicon. * * Use bits 9 to (columns / 2 + columns % 2) * _rows, use the first * 8 bits to determine foreground color. Squares are drawn from top @@ -110,9 +107,9 @@ private: * * @return The image */ - Magick::Image generate_libravatar(const string &digest, - const uint16_t width, - const uint16_t height); + Magick::Image generate_sigil(const string &digest, + const uint16_t width, + const uint16_t height); /*! * @brief Check if the digest contains enough entropy. @@ -122,7 +119,7 @@ private: * @param digest The pre-computed digest * @param type The type of identicon */ - void check_entropy(const string &digest, identicon_type type); + void check_entropy(const string &digest, algorithm type); /*! * @brief Determines if the n-th bit of passed digest is 1 or 0. diff --git a/src/simple.cpp b/src/ltr_symmetric.cpp similarity index 87% rename from src/simple.cpp rename to src/ltr_symmetric.cpp index 5b7367a..ccb2cd9 100644 --- a/src/simple.cpp +++ b/src/ltr_symmetric.cpp @@ -17,9 +17,9 @@ #include "identiconpp.hpp" #include "debug.hpp" -Magick::Image Identiconpp::generate_simple(const string &digest, - const uint16_t width, - const uint16_t height) +Magick::Image Identiconpp::generate_ltr_symmetric(const string &digest, + const uint16_t width, + const uint16_t height) { Magick::Image img(Magick::Geometry(_columns, _rows), Magick::Color("#" + _background)); diff --git a/src/libravatar.cpp b/src/sigil.cpp similarity index 88% rename from src/libravatar.cpp rename to src/sigil.cpp index 95fbfec..45b18ae 100644 --- a/src/libravatar.cpp +++ b/src/sigil.cpp @@ -17,9 +17,9 @@ #include "identiconpp.hpp" #include "debug.hpp" -Magick::Image Identiconpp::generate_libravatar(const string &digest, - const uint16_t width, - const uint16_t height) +Magick::Image Identiconpp::generate_sigil(const string &digest, + const uint16_t width, + const uint16_t height) { // throw "Not implemented."; Magick::Image img(Magick::Geometry(_columns, _rows),