qrencode  4.1.1
About: libqrencode is a fast and compact library and command-line utility for encoding data in a QR Code symbol.
  Fossies Dox: qrencode-4.1.1.tar.bz2  ("unofficial" and yet experimental doxygen-generated source code documentation)  

qrencode.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "qrencode.h"
#include "qrspec.h"
#include "mqrspec.h"
#include "bitstream.h"
#include "qrinput.h"
#include "rsecc.h"
#include "split.h"
#include "mask.h"
#include "mmask.h"
Include dependency graph for qrencode.c:

Go to the source code of this file.

Data Structures

struct  RSblock
 Raw code. More...
 
struct  QRRawCode
 
struct  MQRRawCode
 Raw code for Micro QR Code. More...
 
struct  FrameFiller
 Frame filling. More...
 

Functions

static void RSblock_initBlock (RSblock *block, int dl, unsigned char *data, int el, unsigned char *ecc)
 
static int RSblock_init (RSblock *blocks, int spec[5], unsigned char *data, unsigned char *ecc)
 
STATIC_IN_RELEASE void QRraw_free (QRRawCode *raw)
 
STATIC_IN_RELEASE QRRawCodeQRraw_new (QRinput *input)
 
STATIC_IN_RELEASE unsigned char QRraw_getCode (QRRawCode *raw)
 Return a code (byte). More...
 
STATIC_IN_RELEASE void MQRraw_free (MQRRawCode *raw)
 
STATIC_IN_RELEASE MQRRawCodeMQRraw_new (QRinput *input)
 
STATIC_IN_RELEASE unsigned char MQRraw_getCode (MQRRawCode *raw)
 Return a code (byte). More...
 
static void FrameFiller_set (FrameFiller *filler, int width, unsigned char *frame, int mqr)
 
static unsigned char * FrameFiller_next (FrameFiller *filler)
 
STATIC_IN_RELEASE QRcodeQRcode_new (int version, int width, unsigned char *data)
 QR-code encoding. More...
 
void QRcode_free (QRcode *qrcode)
 Free the instance of QRcode class. More...
 
STATIC_IN_RELEASE QRcodeQRcode_encodeMask (QRinput *input, int mask)
 QR-code encoding. More...
 
STATIC_IN_RELEASE QRcodeQRcode_encodeMaskMQR (QRinput *input, int mask)
 
QRcodeQRcode_encodeInput (QRinput *input)
 Create a symbol from the input data. More...
 
static QRcodeQRcode_encodeStringReal (const char *string, int version, QRecLevel level, int mqr, QRencodeMode hint, int casesensitive)
 
QRcodeQRcode_encodeString (const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive)
 Create a symbol from the string. More...
 
QRcodeQRcode_encodeStringMQR (const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive)
 Micro QR Code version of QRcode_encodeString(). More...
 
static QRcodeQRcode_encodeDataReal (const unsigned char *data, int length, int version, QRecLevel level, int mqr)
 
QRcodeQRcode_encodeData (int size, const unsigned char *data, int version, QRecLevel level)
 Encode byte stream (may include '\0') in 8-bit mode. More...
 
QRcodeQRcode_encodeString8bit (const char *string, int version, QRecLevel level)
 Same to QRcode_encodeString(), but encode whole data in 8-bit mode. More...
 
QRcodeQRcode_encodeDataMQR (int size, const unsigned char *data, int version, QRecLevel level)
 Micro QR Code version of QRcode_encodeData(). More...
 
QRcodeQRcode_encodeString8bitMQR (const char *string, int version, QRecLevel level)
 Micro QR Code version of QRcode_encodeString8bit(). More...
 
static QRcode_ListQRcode_List_newEntry (void)
 Structured QR-code encoding. More...
 
static void QRcode_List_freeEntry (QRcode_List *entry)
 
void QRcode_List_free (QRcode_List *qrlist)
 Free the QRcode_List. More...
 
int QRcode_List_size (QRcode_List *qrlist)
 Return the number of symbols included in a QRcode_List. More...
 
QRcode_ListQRcode_encodeInputStructured (QRinput_Struct *s)
 Create structured symbols from the input data. More...
 
static QRcode_ListQRcode_encodeInputToStructured (QRinput *input)
 
static QRcode_ListQRcode_encodeDataStructuredReal (int size, const unsigned char *data, int version, QRecLevel level, int eightbit, QRencodeMode hint, int casesensitive)
 
QRcode_ListQRcode_encodeDataStructured (int size, const unsigned char *data, int version, QRecLevel level)
 Create structured symbols from byte stream (may include '\0'). More...
 
QRcode_ListQRcode_encodeString8bitStructured (const char *string, int version, QRecLevel level)
 Same to QRcode_encodeStringStructured(), but encode whole data in 8-bit mode. More...
 
QRcode_ListQRcode_encodeStringStructured (const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive)
 Create structured symbols from the string. More...
 
void QRcode_APIVersion (int *major_version, int *minor_version, int *micro_version)
 System utilities. More...
 
char * QRcode_APIVersionString (void)
 Return a string that identifies the library version. More...
 
void QRcode_clearCache (void)
 

Function Documentation

◆ FrameFiller_next()

static unsigned char * FrameFiller_next ( FrameFiller filler)
static

◆ FrameFiller_set()

static void FrameFiller_set ( FrameFiller filler,
int  width,
unsigned char *  frame,
int  mqr 
)
static

◆ MQRraw_free()

STATIC_IN_RELEASE void MQRraw_free ( MQRRawCode raw)

Definition at line 263 of file qrencode.c.

References MQRRawCode::datacode, MQRRawCode::ecccode, and MQRRawCode::rsblock.

Referenced by MQRraw_new(), and QRcode_encodeMaskMQR().

◆ MQRraw_getCode()

STATIC_IN_RELEASE unsigned char MQRraw_getCode ( MQRRawCode raw)

Return a code (byte).

This function can be called iteratively.

Parameters
rawraw code.
Returns
code

Definition at line 248 of file qrencode.c.

References MQRRawCode::count, MQRRawCode::datacode, MQRRawCode::dataLength, MQRRawCode::ecccode, and MQRRawCode::eccLength.

Referenced by QRcode_encodeMaskMQR().

◆ MQRraw_new()

◆ QRcode_APIVersion()

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

System utilities.

Return a string that identifies the library version.

Parameters
major_versionmajor version number
minor_versionminor version number
micro_versionmicro version number

Definition at line 917 of file qrencode.c.

◆ 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.

Definition at line 930 of file qrencode.c.

Referenced by usage(), and writeSVG().

◆ QRcode_clearCache()

void QRcode_clearCache ( void  )
Deprecated:

Definition at line 935 of file qrencode.c.

◆ 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
sizesize of the input data.
datainput data.
versionversion of the symbol. If 0, the library chooses the minimum version for the given input data.
levelerror correction level.
Exceptions
EINVALinvalid input object.
ENOMEMunable to allocate memory for input objects.
ERANGEinput data is too large.

Definition at line 698 of file qrencode.c.

References level, QRcode_encodeDataReal(), size, and version.

Referenced by encode().

◆ 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.

Definition at line 712 of file qrencode.c.

References level, MQRSPEC_VERSION_MAX, QRcode_encodeDataReal(), size, and version.

Referenced by encode().

◆ QRcode_encodeDataReal()

static QRcode * QRcode_encodeDataReal ( const unsigned char *  data,
int  length,
int  version,
QRecLevel  level,
int  mqr 
)
static

◆ 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
sizesize of the input data.
datainput dat.
versionversion of the symbol.
levelerror 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
EINVALinvalid input object.
ENOMEMunable to allocate memory for input objects.

Definition at line 892 of file qrencode.c.

References level, QR_MODE_NUL, QRcode_encodeDataStructuredReal(), size, and version.

Referenced by encodeStructured(), and QRcode_encodeString8bitStructured().

◆ QRcode_encodeDataStructuredReal()

static QRcode_List * QRcode_encodeDataStructuredReal ( int  size,
const unsigned char *  data,
int  version,
QRecLevel  level,
int  eightbit,
QRencodeMode  hint,
int  casesensitive 
)
static

◆ 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
inputinput 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
EINVALinvalid input object.
ENOMEMunable to allocate memory for input objects.

Definition at line 607 of file qrencode.c.

References _QRinput::mqr, QRcode_encodeMask(), and QRcode_encodeMaskMQR().

Referenced by QRcode_encodeDataReal(), QRcode_encodeInputStructured(), and QRcode_encodeStringReal().

◆ 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
sinput data, structured.
Returns
a singly-linked list of QRcode.

Definition at line 810 of file qrencode.c.

References _QRcode_List::code, _QRinput_Struct::head, _QRinput_InputList::input, _QRcode_List::next, _QRinput_InputList::next, QRcode_encodeInput(), QRcode_List_free(), and QRcode_List_newEntry().

Referenced by QRcode_encodeInputToStructured().

◆ QRcode_encodeInputToStructured()

static QRcode_List * QRcode_encodeInputToStructured ( QRinput input)
static

◆ QRcode_encodeMask()

◆ QRcode_encodeMaskMQR()

◆ 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
stringinput string. It must be NUL terminated.
versionversion of the symbol. If 0, the library chooses the minimum version for the given input data.
levelerror correction level.
hinttell 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.
casesensitivecase-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
EINVALinvalid input object.
ENOMEMunable to allocate memory for input objects.
ERANGEinput data is too large.

Definition at line 649 of file qrencode.c.

References casesensitive, hint, level, QRcode_encodeStringReal(), and version.

Referenced by encode().

◆ 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.

Definition at line 703 of file qrencode.c.

References level, QRcode_encodeDataReal(), and version.

◆ 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.

Definition at line 727 of file qrencode.c.

References level, MQRSPEC_VERSION_MAX, QRcode_encodeDataReal(), and version.

◆ 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.

Definition at line 896 of file qrencode.c.

References level, QRcode_encodeDataStructured(), and version.

◆ 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.

Definition at line 654 of file qrencode.c.

References casesensitive, hint, level, MQRSPEC_VERSION_MAX, QRcode_encodeStringReal(), and version.

Referenced by encode().

◆ QRcode_encodeStringReal()

static QRcode * QRcode_encodeStringReal ( const char *  string,
int  version,
QRecLevel  level,
int  mqr,
QRencodeMode  hint,
int  casesensitive 
)
static

◆ 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
stringinput string. It must be NUL terminated.
versionversion of the symbol.
levelerror correction level.
hinttell 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.
casesensitivecase-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
EINVALinvalid input object.
ENOMEMunable to allocate memory for input objects.

Definition at line 904 of file qrencode.c.

References casesensitive, hint, level, QRcode_encodeDataStructuredReal(), and version.

Referenced by encodeStructured().

◆ QRcode_free()

void QRcode_free ( QRcode qrcode)

Free the instance of QRcode class.

Parameters
qrcodean instance of QRcode class.

Definition at line 423 of file qrencode.c.

References QRcode::data.

Referenced by QRcode_List_freeEntry(), and qrencode().

◆ QRcode_List_free()

void QRcode_List_free ( QRcode_List qrlist)

Free the QRcode_List.

Parameters
qrlista head entry of a QRcode_List.

Definition at line 772 of file qrencode.c.

References _QRcode_List::next, and QRcode_List_freeEntry().

Referenced by QRcode_encodeInputStructured(), and qrencodeStructured().

◆ QRcode_List_freeEntry()

static void QRcode_List_freeEntry ( QRcode_List entry)
static

Definition at line 764 of file qrencode.c.

References _QRcode_List::code, and QRcode_free().

Referenced by QRcode_List_free().

◆ QRcode_List_newEntry()

static QRcode_List * QRcode_List_newEntry ( void  )
static

Structured QR-code encoding.

Definition at line 751 of file qrencode.c.

References _QRcode_List::code, and _QRcode_List::next.

Referenced by QRcode_encodeInputStructured().

◆ QRcode_List_size()

int QRcode_List_size ( QRcode_List qrlist)

Return the number of symbols included in a QRcode_List.

Parameters
qrlista head entry of a QRcode_List.
Returns
number of symbols in the list.

Definition at line 783 of file qrencode.c.

References _QRcode_List::next, and size.

◆ QRcode_new()

STATIC_IN_RELEASE QRcode * QRcode_new ( int  version,
int  width,
unsigned char *  data 
)

QR-code encoding.

Definition at line 409 of file qrencode.c.

References QRcode::data, version, QRcode::version, and QRcode::width.

Referenced by QRcode_encodeMask(), and QRcode_encodeMaskMQR().

◆ QRraw_free()

STATIC_IN_RELEASE void QRraw_free ( QRRawCode raw)

Definition at line 180 of file qrencode.c.

References QRRawCode::datacode, QRRawCode::ecccode, and QRRawCode::rsblock.

Referenced by QRcode_encodeMask(), and QRraw_new().

◆ QRraw_getCode()

STATIC_IN_RELEASE unsigned char QRraw_getCode ( QRRawCode raw)

Return a code (byte).

This function can be called iteratively.

Parameters
rawraw code.
Returns
code

Definition at line 157 of file qrencode.c.

References QRRawCode::b1, QRRawCode::blocks, QRRawCode::count, RSblock::data, RSblock::dataLength, QRRawCode::dataLength, RSblock::ecc, QRRawCode::eccLength, and QRRawCode::rsblock.

Referenced by QRcode_encodeMask().

◆ QRraw_new()

◆ RSblock_init()

static int RSblock_init ( RSblock blocks,
int  spec[5],
unsigned char *  data,
unsigned char *  ecc 
)
static

◆ RSblock_initBlock()

static void RSblock_initBlock ( RSblock block,
int  dl,
unsigned char *  data,
int  el,
unsigned char *  ecc 
)
static

Definition at line 62 of file qrencode.c.

References RSblock::data, RSblock::dataLength, RSblock::ecc, RSblock::eccLength, and RSECC_encode().

Referenced by MQRraw_new(), and RSblock_init().