identiconpp/src/identiconpp.hpp

105 lines
2.8 KiB
C++
Raw Normal View History

2018-12-25 18:33:19 +01:00
/* This file is part of identiconpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <cstdint>
#include <string>
#include <vector>
#include <tuple>
#include <Magick++/Image.h>
2018-12-25 18:33:19 +01:00
using std::uint8_t;
2018-12-25 22:17:17 +01:00
using std::uint32_t;
2018-12-25 18:33:19 +01:00
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
};
2018-12-25 18:33:19 +01:00
/*!
* @brief Initialises an instance of Identiconpp.
*
* The instance can be used for creating identicons with differing
* image formats and sizes.
2018-12-25 18:33:19 +01:00
*
* @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,
2018-12-25 22:17:17 +01:00
const uint32_t background = 0xffffffff,
const vector<uint32_t> &foreground = { 0x000000ff } );
2018-12-25 18:33:19 +01:00
/*!
* @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);
2018-12-25 18:33:19 +01:00
private:
const uint8_t _rows;
const uint8_t _columns;
2018-12-25 22:17:17 +01:00
const uint32_t _background;
const vector<uint32_t> _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);
2018-12-25 18:33:19 +01:00
};