/* This file is part of identiconpp. * Copyright © 2018 tastytea * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include using std::uint8_t; using std::uint32_t; using std::string; using std::vector; /*! * @brief Base class for identiconpp. * * Use this class for all your identicons. */ class Identiconpp { public: /*! * @brief Return type for images. */ struct Image { uint8_t error; Magick::Image data; }; /*! * @brief List of identicon types * * libravatar and sigil are synonymous. */ enum class identicon_type { simple, libravatar, sigil }; /*! * @brief Initialises an instance of Identiconpp. * * The instance can be used for creating identicons with differing * image formats and sizes. * * @param rows Number of rows * @param columns Number of columns * @param background Background color, hexadecimal, rrggbbaa * @param foreground vector of foreground colors */ explicit Identiconpp(const uint8_t rows, const uint8_t columns, const uint32_t background = 0xffffffff, const vector &foreground = { 0x000000ff } ); /*! * @brief Generates identicon from digest. * * @param digest The pre-computed digest * * @return 0 and an image on success, 1 and an empty image on error. */ Image generate(const string &digest, identicon_type type); private: const uint8_t _rows; const uint8_t _columns; const uint32_t _background; const vector _foreground; /*! * @brief Generate simple identicon. * * @param digest The pre-computed digest * * @return 0 and an image on success, 1 and an empty image on error. */ Image generate_simple(const string &digest); /*! * @brief Generate libravatar-style identicon. * * @param digest The pre-computed digest * * @return 0 and an image on success, 1 and an empty image on error. */ Image generate_libravatar(const string &digest); };