identiconpp  0.4.0
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 
77  explicit Identiconpp(const uint8_t columns, const uint8_t rows,
79  const string &background = "ffffffff",
80  const vector<string> &foreground = { "000000ff" },
81  const array<const uint8_t, 2> &padding = { 0, 0 });
82 
91  Magick::Image generate(const string &digest, const uint16_t width = 100);
92 
93 private:
94  const uint8_t _rows;
95  const uint8_t _columns;
96  const algorithm _type;
97  const string _background;
98  const vector<string> _foreground;
99  const array<const uint8_t, 2> _padding;
100 
112  Magick::Image generate_ltr_symmetric(const string &digest);
113 
125  Magick::Image generate_ltr_asymmetric(const string &digest);
126 
138  Magick::Image generate_sigil(const string &digest);
139 
148  void check_entropy(const string &digest, algorithm type);
149 
158  bool get_bit(const uint16_t bit, const string &digest);
159 
170  Magick::Color get_color(const uint16_t firstbit, const string &digest);
171 
179  static bool not_hex(const char c);
180 
186  void check_color(const string &color);
187 };
188 
189 #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:52
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< const uint8_t, 2 > &padding={ 0, 0 })
Initialises an instance of Identiconpp.
Definition: identiconpp.cpp:24
Generates asymmetric identicons.