identiconpp  0.6.1
identiconpp.hpp
1 /* This file is part of identiconpp.
2  * Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef IDENTICONPP_HPP
18 #define IDENTICONPP_HPP
19 
20 #include <cstdint>
21 #include <string>
22 #include <vector>
23 #include <array>
24 #include <Magick++/Image.h>
25 
26 using std::uint8_t;
27 using std::uint16_t;
28 using std::string;
29 using std::vector;
30 using std::array;
31 
43 {
44 public:
45  friend class Testiconpp;
49  enum class algorithm
50  {
60  sigil
61  };
62 
79  explicit Identiconpp(const uint8_t columns, const uint8_t rows,
81  const string &background = "ffffffff",
82  const vector<string> &foreground = { "000000ff" },
83  const array<uint8_t, 2> &padding = { 0, 0 });
84 
95  Magick::Image generate(const string &digest, const uint16_t width = 100);
96 
108  const string generate_base64(const string &magick, const string &digest,
109  const uint16_t width = 100);
110 
111 private:
112  const uint8_t _rows;
113  const uint8_t _columns;
114  const algorithm _type;
115  const string _background;
116  const vector<string> _foreground;
117  const array<uint8_t, 2> _padding;
118 
132  Magick::Image generate_ltr_symmetric(const string &digest);
133 
147  Magick::Image generate_ltr_asymmetric(const string &digest);
148 
162  Magick::Image generate_sigil(const string &digest);
163 
174  void check_entropy(const string &digest, algorithm type);
175 
186  bool get_bit(const uint16_t bit, const string &digest);
187 
200  Magick::Color get_color(const uint16_t firstbit, const string &digest);
201 
211  static bool not_hex(const char c);
212 
220  void check_color(const string &color);
221 };
222 
223 #endif // IDENTICONPP_HPP
algorithm
List of identicon algorithms.
Definition: identiconpp.hpp:49
Magick::Image generate(const string &digest, const uint16_t width=100)
Generates identicon from digest.
Definition: identiconpp.cpp:53
Base class for identiconpp.
Definition: identiconpp.hpp:42
Generates symmetric (vertically mirrored) identicons.
Identiconpp(const uint8_t columns, const uint8_t rows, algorithm type=algorithm::ltr_symmetric, const string &background="ffffffff", const vector< string > &foreground={ "000000ff" }, const array< uint8_t, 2 > &padding={ 0, 0 })
Initialises an instance of Identiconpp.
Definition: identiconpp.cpp:25
Generates asymmetric identicons.
const string generate_base64(const string &magick, const string &digest, const uint16_t width=100)
Generates identicon from digest.
Definition: identiconpp.cpp:99