QRencode QR Code encoder

Data Structures | Macros | Typedefs | Enumerations | Functions
qrencode.h File Reference

Go to the source code of this file.

## Data Structures
struct | QRcode
| QRcode class. More...
struct | QRcode_List
| Singly-linked list of QRcode. More...

## Macros
#define | QRSPEC_VERSION_MAX 40
| Maximum version (size) of QR-code symbol. More...
#define | MQRSPEC_VERSION_MAX 4
| Maximum version (size) of QR-code symbol. More...

## Typedefs
typedef struct _QRinput | QRinput
| Singly linked list to contain input strings. More...
typedef struct _QRinput_Struct | QRinput_Struct
| Set of QRinput for structured symbols. More...

## Enumerations
enum | QRencodeMode { QR_MODE_NUL = -1, QR_MODE_NUM = 0, QR_MODE_AN, QR_MODE_8, QR_MODE_KANJI, QR_MODE_STRUCTURE, QR_MODE_ECI, QR_MODE_FNC1FIRST, QR_MODE_FNC1SECOND }
| Encoding mode. More...
enum | QRecLevel { QR_ECLEVEL_L = 0, QR_ECLEVEL_M, QR_ECLEVEL_Q, QR_ECLEVEL_H }
| Level of error correction. More...

## Functions
QRinput * | QRinput_new (void)
| Instantiate an input data object. More...
QRinput * | QRinput_new2 (int version, QRecLevel level)
| Instantiate an input data object. More...
QRinput * | QRinput_newMQR (int version, QRecLevel level)
| Instantiate an input data object. More...
int | QRinput_append (QRinput *input, QRencodeMode mode, int size, const unsigned char *data)
| Append data to an input object. More...
int | QRinput_appendECIheader (QRinput *input, unsigned int ecinum)
| Append ECI header. More...
int | QRinput_getVersion (QRinput *input)
| Get current version. More...
int | QRinput_setVersion (QRinput *input, int version)
| Set version of the QR code that is to be encoded. More...
QRecLevel | QRinput_getErrorCorrectionLevel (QRinput *input)
| Get current error correction level. More...
int | QRinput_setErrorCorrectionLevel (QRinput *input, QRecLevel level)
| Set error correction level of the QR code that is to be encoded. More...
int | QRinput_setVersionAndErrorCorrectionLevel (QRinput *input, int version, QRecLevel level)
| Set version and error correction level of the QR code at once. More...
void | QRinput_free (QRinput *input)
| Free the input object. More...
int | QRinput_check (QRencodeMode mode, int size, const unsigned char *data)
| Validate the input data. More...
QRinput_Struct * | QRinput_Struct_new (void)
| Instantiate a set of input data object. More...
void | QRinput_Struct_setParity (QRinput_Struct *s, unsigned char parity)
| Set parity of structured symbols. More...
int | QRinput_Struct_appendInput (QRinput_Struct *s, QRinput *input)
| Append a QRinput object to the set. More...
void | QRinput_Struct_free (QRinput_Struct *s)
| Free all of QRinput in the set. More...
QRinput_Struct * | QRinput_splitQRinputToStruct (QRinput *input)
| Split a QRinput to QRinput_Struct. More...
int | QRinput_Struct_insertStructuredAppendHeaders (QRinput_Struct *s)
| Insert structured-append headers to the input structure. More...
int | QRinput_setFNC1First (QRinput *input)
| Set FNC1-1st position flag. More...
int | QRinput_setFNC1Second (QRinput *input, unsigned char appid)
| Set FNC1-2nd position flag and application identifier. More...
QRcode * | QRcode_encodeInput (QRinput *input)
| Create a symbol from the input data. More...
QRcode * | QRcode_encodeString (const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive)
| Create a symbol from the string. More...
QRcode * | QRcode_encodeString8bit (const char *string, int version, QRecLevel level)
| Same to QRcode_encodeString(), but encode whole data in 8-bit mode. More...
QRcode * | QRcode_encodeStringMQR (const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive)
| Micro QR Code version of QRcode_encodeString(). More...
QRcode * | QRcode_encodeString8bitMQR (const char *string, int version, QRecLevel level)
| Micro QR Code version of QRcode_encodeString8bit(). More...
QRcode * | QRcode_encodeData (int size, const unsigned char *data, int version, QRecLevel level)
| Encode byte stream (may include '\0') in 8-bit mode. More...
QRcode * | QRcode_encodeDataMQR (int size, const unsigned char *data, int version, QRecLevel level)
| Micro QR Code version of QRcode_encodeData(). More...
void | QRcode_free (QRcode *qrcode)
| Free the instance of QRcode class. More...
QRcode_List * | QRcode_encodeInputStructured (QRinput_Struct *s)
| Create structured symbols from the input data. More...
QRcode_List * | QRcode_encodeStringStructured (const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive)
| Create structured symbols from the string. More...
QRcode_List * | QRcode_encodeString8bitStructured (const char *string, int version, QRecLevel level)
| Same to QRcode_encodeStringStructured(), but encode whole data in 8-bit mode. More...
QRcode_List * | QRcode_encodeDataStructured (int size, const unsigned char *data, int version, QRecLevel level)
| Create structured symbols from byte stream (may include '\0'). More...
int | QRcode_List_size (QRcode_List *qrlist)
| Return the number of symbols included in a QRcode_List. More...
void | QRcode_List_free (QRcode_List *qrlist)
| Free the QRcode_List. More...
void | QRcode_APIVersion (int *major_version, int *minor_version, int *micro_version)
| Return a string that identifies the library version. More...
char * | QRcode_APIVersionString (void)
| Return a string that identifies the library version. More...
void | QRcode_clearCache (void) __attribute__((deprecated))

## Macro Definition Documentation

## ◆ QRSPEC_VERSION_MAX

#define QRSPEC_VERSION_MAX 40

Maximum version (size) of QR-code symbol.

## ◆ MQRSPEC_VERSION_MAX

#define MQRSPEC_VERSION_MAX 4

Maximum version (size) of QR-code symbol.

## Typedef Documentation

## ◆ QRinput

typedef struct _QRinput QRinput

Singly linked list to contain input strings.

An instance of this class contains its version and error correction level too. It is required to set them by QRinput_setVersion() and QRinput_setErrorCorrectionLevel(), or use QRinput_new2() to instantiate an object.

## ◆ QRinput_Struct

typedef struct _QRinput_Struct QRinput_Struct

Set of QRinput for structured symbols.

## Enumeration Type Documentation

## ◆ QRencodeMode

enum QRencodeMode

Encoding mode.

Enumerator
QR_MODE_NUL | Terminator (NUL character). Internal use only.
QR_MODE_NUM | Numeric mode.
QR_MODE_AN | Alphabet-numeric mode.
QR_MODE_8 | 8-bit data mode
QR_MODE_KANJI | Kanji (shift-jis) mode.
QR_MODE_STRUCTURE | Internal use only.
QR_MODE_ECI | ECI mode.
QR_MODE_FNC1FIRST | FNC1, first position.
QR_MODE_FNC1SECOND | FNC1, second position.

## ◆ QRecLevel

enum QRecLevel

Level of error correction.

Enumerator
QR_ECLEVEL_L | lowest
QR_ECLEVEL_M |
QR_ECLEVEL_Q |
QR_ECLEVEL_H | highest

## Function Documentation

## ◆ QRinput_new()

QRinput* QRinput_new | ( | void |  | ) |

Instantiate an input data object.

The version is set to 0 (auto-select) and the error correction level is set to QR_ECLEVEL_L.

Returns
  an input object (initialized). On error, NULL is returned and errno is set to indicate the error.

Exceptions

  ENOMEM | unable to allocate memory.

## ◆ QRinput_new2()

QRinput* QRinput_new2 | ( | int | version,
|  | QRecLevel | level
| ) |  |

Instantiate an input data object.

Parameters

  version | version number.
  level | Error correction level.

Returns
  an input object (initialized). On error, NULL is returned and errno is set to indicate the error.

Exceptions

  ENOMEM | unable to allocate memory for input objects.
  EINVAL | invalid arguments.

## ◆ QRinput_newMQR()

QRinput* QRinput_newMQR | ( | int | version,
|  | QRecLevel | level
| ) |  |

Instantiate an input data object.

Object's Micro QR Code flag is set. Unlike with full-sized QR Code, version number must be specified (>0).

Parameters

  version | version number (1–4).
  level | Error correction level.

Returns
  an input object (initialized). On error, NULL is returned and errno is set to indicate the error.

Exceptions

  ENOMEM | unable to allocate memory for input objects.
  EINVAL | invalid arguments.

## ◆ QRinput_append()

int QRinput_append | ( | QRinput * | input,
|  | QRencodeMode | mode,
|  | int | size,
|  | const unsigned char * | data
| ) |  |

Append data to an input object.

The data is copied and appended to the input object.

Parameters

  input | input object.
  mode | encoding mode.
  size | size of data (byte).
  data | a pointer to the memory area of the input data.

Return values

  0 | success.
  -1 | an error occurred and errno is set to indeicate the error. See Execptions for the details.

Exceptions

  ENOMEM | unable to allocate memory.
  EINVAL | input data is invalid.

## ◆ QRinput_appendECIheader()

int QRinput_appendECIheader | ( | QRinput * | input,
|  | unsigned int | ecinum
| ) |  |

Append ECI header.

Parameters

  input | input object.
  ecinum | ECI indicator number (0 - 999999)

Return values

  0 | success.
  -1 | an error occurred and errno is set to indeicate the error. See Execptions for the details.

Exceptions

  ENOMEM | unable to allocate memory.
  EINVAL | input data is invalid.

## ◆ QRinput_getVersion()

int QRinput_getVersion | ( | QRinput * | input | ) |

Get current version.

Parameters

  input | input object.

Returns
  current version.

## ◆ QRinput_setVersion()

int QRinput_setVersion | ( | QRinput * | input,
|  | int | version
| ) |  |

Set version of the QR code that is to be encoded.

This function cannot be applied to Micro QR Code.

Parameters

  input | input object.
  version | version number (0 = auto)

Return values

  0 | success.
  -1 | invalid argument.

## ◆ QRinput_getErrorCorrectionLevel()

QRecLevel QRinput_getErrorCorrectionLevel | ( | QRinput * | input | ) |

Get current error correction level.

Parameters

  input | input object.

Returns
  Current error correcntion level.

## ◆ QRinput_setErrorCorrectionLevel()

int QRinput_setErrorCorrectionLevel | ( | QRinput * | input,
|  | QRecLevel | level
| ) |  |

Set error correction level of the QR code that is to be encoded.

This function cannot be applied to Micro QR Code.

Parameters

  input | input object.
  level | Error correction level.

Return values

  0 | success.
  -1 | invalid argument.

## ◆ QRinput_setVersionAndErrorCorrectionLevel()

int QRinput_setVersionAndErrorCorrectionLevel | ( | QRinput * | input,
|  | int | version,
|  | QRecLevel | level
| ) |  |

Set version and error correction level of the QR code at once.

This function is recommened for Micro QR Code.

Parameters

  input | input object.
  version | version number (0 = auto)
  level | Error correction level.

Return values

  0 | success.
  -1 | invalid argument.

## ◆ QRinput_free()

void QRinput_free | ( | QRinput * | input | ) |

Free the input object.

All of data chunks in the input object are freed too.

Parameters

  input | input object.

## ◆ QRinput_check()

int QRinput_check | ( | QRencodeMode | mode,
|  | int | size,
|  | const unsigned char * | data
| ) |  |

Validate the input data.

Parameters

  mode | encoding mode.
  size | size of data (byte).
  data | a pointer to the memory area of the input data.

Return values

  0 | success.
  -1 | invalid arguments.

## ◆ QRinput_Struct_new()

QRinput_Struct* QRinput_Struct_new | ( | void |  | ) |

Instantiate a set of input data object.

Returns
  an instance of QRinput_Struct. On error, NULL is returned and errno is set to indicate the error.

Exceptions

  ENOMEM | unable to allocate memory.

## ◆ QRinput_Struct_setParity()

void QRinput_Struct_setParity | ( | QRinput_Struct * | s,
|  | unsigned char | parity
| ) |  |

Set parity of structured symbols.

Parameters

  s | structured input object.
  parity | parity of s.

## ◆ QRinput_Struct_appendInput()

int QRinput_Struct_appendInput | ( | QRinput_Struct * | s,
|  | QRinput * | input
| ) |  |

Append a QRinput object to the set.

QRinput created by QRinput_newMQR() will be rejected.

Warning
  never append the same QRinput object twice or more.

Parameters

  s | structured input object.
  input | an input object.

Return values

  >0 | number of input objects in the structure.
  -1 | an error occurred. See Exceptions for the details.

Exceptions

  ENOMEM | unable to allocate memory.
  EINVAL | invalid arguments.

## ◆ QRinput_Struct_free()

void QRinput_Struct_free | ( | QRinput_Struct * | s | ) |

Free all of QRinput in the set.

Parameters

  s | a structured input object.

## ◆ QRinput_splitQRinputToStruct()

QRinput_Struct* QRinput_splitQRinputToStruct | ( | QRinput * | input | ) |

Split a QRinput to QRinput_Struct.

It calculates a parity, set it, then insert structured-append headers. QRinput created by QRinput_newMQR() will be rejected.

Parameters

  input | input object. Version number and error correction level must be set.

Returns
  a set of input data. On error, NULL is returned, and errno is set to indicate the error. See Exceptions for the details.

Exceptions

  ERANGE | input data is too large.
  EINVAL | invalid input data.
  ENOMEM | unable to allocate memory.

## ◆ QRinput_Struct_insertStructuredAppendHeaders()

int QRinput_Struct_insertStructuredAppendHeaders | ( | QRinput_Struct * | s | ) |

Insert structured-append headers to the input structure.

It calculates a parity and set it if the parity is not set yet.

Parameters

  s | input structure

Return values

  0 | success.
  -1 | an error occurred and errno is set to indeicate the error. See Execptions for the details.

Exceptions

  EINVAL | invalid input object.
  ENOMEM | unable to allocate memory.

## ◆ QRinput_setFNC1First()

int QRinput_setFNC1First | ( | QRinput * | input | ) |

Set FNC1-1st position flag.

## ◆ QRinput_setFNC1Second()

int QRinput_setFNC1Second | ( | QRinput * | input,
|  | unsigned char | appid
| ) |  |

Set FNC1-2nd position flag and application identifier.

## ◆ QRcode_encodeInput()

QRcode* QRcode_encodeInput | ( | QRinput * | input | ) |

Create a symbol from the input data.

Warning
  This function is THREAD UNSAFE when pthread is disabled.

Parameters

  input | input data.

Returns
  an instance of QRcode class. The version of the result QRcode may be larger than the designated version. On error, NULL is returned, and errno is set to indicate the error. See Exceptions for the details.

Exceptions

  EINVAL | invalid input object.
  ENOMEM | unable to allocate memory for input objects.

## ◆ QRcode_encodeString()

QRcode* QRcode_encodeString | ( | const char * | string,
|  | int | version,
|  | QRecLevel | level,
|  | QRencodeMode | hint,
|  | int | casesensitive
| ) |  |

Create a symbol from the string.

The library automatically parses the input string and encodes in a QR Code symbol.

Warning
  This function is THREAD UNSAFE when pthread is disabled.

Parameters

  string | input string. It must be NUL terminated.
  version | version of the symbol. If 0, the library chooses the minimum version for the given input data.
  level | error correction level.
  hint | tell the library how Japanese Kanji characters should be encoded. If QR_MODE_KANJI is given, the library assumes that the given string contains Shift-JIS characters and encodes them in Kanji-mode. If QR_MODE_8 is given, all of non-alphanumerical characters will be encoded as is. If you want to embed UTF-8 string, choose this. Other mode will cause EINVAL error.
  casesensitive | case-sensitive(1) or not(0).

Returns
  an instance of QRcode class. The version of the result QRcode may be larger than the designated version. On error, NULL is returned, and errno is set to indicate the error. See Exceptions for the details.

Exceptions

  EINVAL | invalid input object.
  ENOMEM | unable to allocate memory for input objects.
  ERANGE | input data is too large.

## ◆ QRcode_encodeString8bit()

QRcode* QRcode_encodeString8bit | ( | const char * | string,
|  | int | version,
|  | QRecLevel | level
| ) |  |

Same to QRcode_encodeString(), but encode whole data in 8-bit mode.

Warning
  This function is THREAD UNSAFE when pthread is disabled.

## ◆ QRcode_encodeStringMQR()

QRcode* QRcode_encodeStringMQR | ( | const char * | string,
|  | int | version,
|  | QRecLevel | level,
|  | QRencodeMode | hint,
|  | int | casesensitive
| ) |  |

Micro QR Code version of QRcode_encodeString().

Warning
  This function is THREAD UNSAFE when pthread is disabled.

## ◆ QRcode_encodeString8bitMQR()

QRcode* QRcode_encodeString8bitMQR | ( | const char * | string,
|  | int | version,
|  | QRecLevel | level
| ) |  |

Micro QR Code version of QRcode_encodeString8bit().

Warning
  This function is THREAD UNSAFE when pthread is disabled.

## ◆ QRcode_encodeData()

QRcode* QRcode_encodeData | ( | int | size,
|  | const unsigned char * | data,
|  | int | version,
|  | QRecLevel | level
| ) |  |

Encode byte stream (may include '\0') in 8-bit mode.

Warning
  This function is THREAD UNSAFE when pthread is disabled.

Parameters

  size | size of the input data.
  data | input data.
  version | version of the symbol. If 0, the library chooses the minimum version for the given input data.
  level | error correction level.

Exceptions

  EINVAL | invalid input object.
  ENOMEM | unable to allocate memory for input objects.
  ERANGE | input data is too large.

## ◆ QRcode_encodeDataMQR()

QRcode* QRcode_encodeDataMQR | ( | int | size,
|  | const unsigned char * | data,
|  | int | version,
|  | QRecLevel | level
| ) |  |

Micro QR Code version of QRcode_encodeData().

Warning
  This function is THREAD UNSAFE when pthread is disabled.

## ◆ QRcode_free()

void QRcode_free | ( | QRcode * | qrcode | ) |

Free the instance of QRcode class.

Parameters

  qrcode | an instance of QRcode class.

## ◆ QRcode_encodeInputStructured()

QRcode_List* QRcode_encodeInputStructured | ( | QRinput_Struct * | s | ) |

Create structured symbols from the input data.

Warning
  This function is THREAD UNSAFE when pthread is disabled.

Parameters

  s | input data, structured.

Returns
  a singly-linked list of QRcode.

## ◆ QRcode_encodeStringStructured()

QRcode_List* QRcode_encodeStringStructured | ( | const char * | string,
|  | int | version,
|  | QRecLevel | level,
|  | QRencodeMode | hint,
|  | int | casesensitive
| ) |  |

Create structured symbols from the string.

The library automatically parses the input string and encodes in a QR Code symbol.

Warning
  This function is THREAD UNSAFE when pthread is disabled.

Parameters

  string | input string. It must be NUL terminated.
  version | version of the symbol.
  level | error correction level.
  hint | tell the library how Japanese Kanji characters should be encoded. If QR_MODE_KANJI is given, the library assumes that the given string contains Shift-JIS characters and encodes them in Kanji-mode. If QR_MODE_8 is given, all of non-alphanumerical characters will be encoded as is. If you want to embed UTF-8 string, choose this. Other mode will cause EINVAL error.
  casesensitive | case-sensitive(1) or not(0).

Returns
  a singly-linked list of QRcode. On error, NULL is returned, and errno is set to indicate the error. See Exceptions for the details.

Exceptions

  EINVAL | invalid input object.
  ENOMEM | unable to allocate memory for input objects.

## ◆ QRcode_encodeString8bitStructured()

QRcode_List* QRcode_encodeString8bitStructured | ( | const char * | string,
|  | int | version,
|  | QRecLevel | level
| ) |  |

Same to QRcode_encodeStringStructured(), but encode whole data in 8-bit mode.

Warning
  This function is THREAD UNSAFE when pthread is disabled.

## ◆ QRcode_encodeDataStructured()

QRcode_List* QRcode_encodeDataStructured | ( | int | size,
|  | const unsigned char * | data,
|  | int | version,
|  | QRecLevel | level
| ) |  |

Create structured symbols from byte stream (may include '\0').

Wholde data are encoded in 8-bit mode.

Warning
  This function is THREAD UNSAFE when pthread is disabled.

Parameters

  size | size of the input data.
  data | input dat.
  version | version of the symbol.
  level | error correction level.

Returns
  a singly-linked list of QRcode. On error, NULL is returned, and errno is set to indicate the error. See Exceptions for the details.

Exceptions

  EINVAL | invalid input object.
  ENOMEM | unable to allocate memory for input objects.

## ◆ QRcode_List_size()

int QRcode_List_size | ( | QRcode_List * | qrlist | ) |

Return the number of symbols included in a QRcode_List.

Parameters

  qrlist | a head entry of a QRcode_List.

Returns
  number of symbols in the list.

## ◆ QRcode_List_free()

void QRcode_List_free | ( | QRcode_List * | qrlist | ) |

Free the QRcode_List.

Parameters

  qrlist | a head entry of a QRcode_List.

## ◆ QRcode_APIVersion()

void QRcode_APIVersion | ( | int * | major_version,
|  | int * | minor_version,
|  | int * | micro_version
| ) |  |

Return a string that identifies the library version.

Parameters

  major_version | major version number
  minor_version | minor version number
  micro_version | micro version number

## ◆ QRcode_APIVersionString()

char* QRcode_APIVersionString | ( | void |  | ) |

Return a string that identifies the library version.

Returns
  a string identifies the library version. The string is held by the library. Do NOT free it.

## ◆ QRcode_clearCache()

void QRcode_clearCache | ( | void |  | ) |

Deprecated: