diff --git a/src/c_interface.cpp b/src/c_interface.cpp index 174782d..e25a9f4 100644 --- a/src/c_interface.cpp +++ b/src/c_interface.cpp @@ -23,7 +23,8 @@ #include "debug.hpp" #include "identiconpp_c.h" -std::unique_ptr identicon; +static std::unique_ptr identicon; +static string base64; bool identiconpp_setup(const uint8_t columns, const uint8_t rows, identiconpp_algorithm type, @@ -72,11 +73,19 @@ bool identiconpp_setup(const uint8_t columns, const uint8_t rows, return true; } -bool identiconpp_generate(MagickWand *wand, - const char digest[], const uint16_t width) +uint64_t identiconpp_generate(const char magick[], + const char digest[], const uint16_t width) { Magick::Image img = identicon->generate(digest, width); Magick::Blob blob; + img.magick(magick); img.write(&blob); - MagickReadImageBlob(wand, blob.data(), blob.length()); + base64 = blob.base64(); + + return blob.base64().length(); +} + +const char *identiconpp_base64() +{ + return base64.c_str(); } diff --git a/src/identiconpp_c.h b/src/identiconpp_c.h index eef1e1f..dec0f5f 100644 --- a/src/identiconpp_c.h +++ b/src/identiconpp_c.h @@ -25,8 +25,18 @@ extern "C" #include #include #include - #include + /*! + * @example example.c + */ + + /*! + * @brief C interface for identiconpp. + */ + + /*! + * @brief List of identicon algorithms + */ typedef enum { identiconpp_ltr_symmetric, @@ -34,14 +44,38 @@ extern "C" identiconpp_sigil } identiconpp_algorithm; + /*! + * @brief Setup identicon parameters. + * + * @param columns Number of columns + * @param rows Number of rows + * @param type The algorithm to use + * @param background Background color, hexadecimal, rrggbbaa + * @param foreground Array of foreground colors + * @param foreground_len Length of the array of foreground colors + * @param padding Padding in pixels { left & right, top & down } + * + * @return { description_of_the_return_value } + */ bool identiconpp_setup(const uint8_t columns, const uint8_t rows, identiconpp_algorithm type, const char background[9], const char foreground[][9], const uint8_t foreground_len, const uint8_t padding[2]); - bool identiconpp_generate(MagickWand *wand, - const char digest[], const uint16_t width); + + /*! + * @brief Generates identicon from digest. + * + * @param magick See http://imagemagick.org/script/formats.php + * @param digest The pre-computed digest + * @param width The width of the identicon + * + * @return Length of the generated base64-string + */ + uint64_t identiconpp_generate(const char magick[], + const char digest[], const uint16_t width); + const char *identiconpp_base64(); #ifdef __cplusplus }