identiconpp  0.6.1
Enumerations | Functions
identiconpp_c.h File Reference

C interface for identiconpp. More...

#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>

Go to the source code of this file.

Enumerations

enum  identiconpp_algorithm { identiconpp_ltr_symmetric, identiconpp_ltr_asymmetric, identiconpp_sigil }
 List of identicon algorithms. More...
 

Functions

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])
 Setup identicon parameters. More...
 
uint64_t identiconpp_generate (const char magick[], const char digest[], const uint16_t width)
 Generates identicon from digest. More...
 
const char * identiconpp_base64 ()
 Return base64-encoded string of the image generated with identiconpp_generate(). More...
 

Detailed Description

C interface for identiconpp.

Enumeration Type Documentation

◆ identiconpp_algorithm

List of identicon algorithms.

Enumerator
identiconpp_ltr_symmetric 

Generates symmetric (vertically mirrored) identicons.

identiconpp_ltr_asymmetric 

Generates asymmetric identicons.

identiconpp_sigil 

Generates the same results as sigil and pydenticon.

39  {
Generates asymmetric identicons.
Definition: identiconpp_c.h:43
Generates symmetric (vertically mirrored) identicons.
Definition: identiconpp_c.h:41
Definition: identiconpp_c.h:49
identiconpp_algorithm
List of identicon algorithms.
Definition: identiconpp_c.h:38

Function Documentation

◆ identiconpp_base64()

const char* identiconpp_base64 ( )

Return base64-encoded string of the image generated with identiconpp_generate().

Since
before 0.5.0
Examples:
example.c.
101 {
102  return base64.c_str();
103 }

◆ identiconpp_generate()

uint64_t identiconpp_generate ( const char  magick[],
const char  digest[],
const uint16_t  width 
)

Generates identicon from digest.

Parameters
magickSee http://imagemagick.org/script/formats.php
digestThe pre-computed digest
widthThe width of the identicon
Returns
Length of the generated base64-string, or 0 on error.
Since
before 0.5.0
Examples:
example.c.
83 {
84  try
85  {
86  Magick::Image img = identicon->generate(digest, width);
87  Magick::Blob blob;
88  img.magick(magick);
89  img.write(&blob);
90  base64 = blob.base64();
91  return blob.base64().length();
92  }
93  catch (const std::exception &e)
94  {
95  cerr << e.what() << endl;
96  return 0;
97  }
98 }

◆ identiconpp_setup()

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] 
)

Setup identicon parameters.

Parameters
columnsNumber of columns
rowsNumber of rows
typeThe algorithm to use
backgroundBackground color, hexadecimal, rrggbbaa
foregroundArray of foreground colors
foreground_lenLength of the array of foreground colors
paddingPadding in pixels { left & right, top & down }
Returns
false on error, true otherwise.
Since
before 0.5.0
Examples:
example.c.
39 {
41  switch (type)
42  {
44  {
46  break;
47  }
49  {
51  break;
52  }
53  case identiconpp_sigil:
54  {
56  break;
57  }
58  }
59 
60  std::vector<string> vforeground;
61  for (uint8_t i = 0; i < foreground_len; ++i)
62  {
63  vforeground.push_back(foreground[i]);
64  }
65 
66  try
67  {
68  identicon = std::make_unique<Identiconpp>(
69  Identiconpp(columns, rows, algo, background, vforeground,
70  { padding[0], padding[1] }));
71  }
72  catch (const std::exception &e)
73  {
74  cerr << e.what() << endl;
75  return false;
76  }
77 
78  return true;
79 }
Generates asymmetric identicons.
Definition: identiconpp_c.h:43
algorithm
List of identicon algorithms.
Definition: identiconpp.hpp:49
Generates symmetric (vertically mirrored) identicons.
Definition: identiconpp_c.h:41
Base class for identiconpp.
Definition: identiconpp.hpp:42
Definition: identiconpp_c.h:49
Generates symmetric (vertically mirrored) identicons.
Generates asymmetric identicons.