TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
Classes | Functions
qrencode.c File Reference
#include "config.h"
#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"

Go to the source code of this file.

Classes

struct  RSblock
 qrencode - QR Code encoder More...
 
struct  QRRawCode
 
struct  MQRRawCode
 
struct  FrameFiller
 

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)
 
void QRcode_free (QRcode *qrcode)
 Free the instance of QRcode class. More...
 
STATIC_IN_RELEASE QRcodeQRcode_encodeMask (QRinput *input, int mask)
 
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)
 
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)
 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)
 

Function Documentation

static unsigned char* FrameFiller_next ( FrameFiller filler)
static
static void FrameFiller_set ( FrameFiller filler,
int  width,
unsigned char *  frame,
int  mqr 
)
static
STATIC_IN_RELEASE void MQRraw_free ( MQRRawCode raw)

Definition at line 261 of file qrencode.c.

References MQRRawCode::datacode, MQRRawCode::ecccode, free(), and MQRRawCode::rsblock.

Referenced by MQRraw_new(), and QRcode_encodeMaskMQR().

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 246 of file qrencode.c.

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

Referenced by QRcode_encodeMaskMQR().

STATIC_IN_RELEASE MQRRawCode* MQRraw_new ( QRinput input)
void QRcode_APIVersion ( int major_version,
int minor_version,
int micro_version 
)

Return a string that identifies the library version.

Parameters
major_versionmajor version number
minor_versionminor version number
micro_versionmicro version number

Definition at line 915 of file qrencode.c.

References MAJOR_VERSION, MICRO_VERSION, and MINOR_VERSION.

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 928 of file qrencode.c.

References VERSION.

void QRcode_clearCache ( void  )
Deprecated:

Definition at line 933 of file qrencode.c.

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 696 of file qrencode.c.

References QRcode_encodeDataReal().

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 710 of file qrencode.c.

References MQRSPEC_VERSION_MAX, and QRcode_encodeDataReal().

static QRcode* QRcode_encodeDataReal ( const unsigned char *  data,
int  length,
int  version,
QRecLevel  level,
int  mqr 
)
static
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 890 of file qrencode.c.

References QR_MODE_NUL, and QRcode_encodeDataStructuredReal().

Referenced by QRcode_encodeString8bitStructured().

static QRcode_List* QRcode_encodeDataStructuredReal ( int  size,
const unsigned char *  data,
int  version,
QRecLevel  level,
int  eightbit,
QRencodeMode  hint,
int  casesensitive 
)
static
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 605 of file qrencode.c.

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

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

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 808 of file qrencode.c.

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

Referenced by QRcode_encodeInputToStructured().

static QRcode_List* QRcode_encodeInputToStructured ( QRinput input)
static
STATIC_IN_RELEASE QRcode* QRcode_encodeMask ( QRinput input,
int  mask 
)
STATIC_IN_RELEASE QRcode* QRcode_encodeMaskMQR ( QRinput input,
int  mask 
)
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 647 of file qrencode.c.

References QRcode_encodeStringReal().

Referenced by QRCodeQWidget::paintEvent().

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 701 of file qrencode.c.

References QRcode_encodeDataReal().

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 725 of file qrencode.c.

References MQRSPEC_VERSION_MAX, and QRcode_encodeDataReal().

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 894 of file qrencode.c.

References QRcode_encodeDataStructured().

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 652 of file qrencode.c.

References MQRSPEC_VERSION_MAX, and QRcode_encodeStringReal().

static QRcode* QRcode_encodeStringReal ( const char *  string,
int  version,
QRecLevel  level,
int  mqr,
QRencodeMode  hint,
int  casesensitive 
)
static
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 902 of file qrencode.c.

References QRcode_encodeDataStructuredReal().

void QRcode_free ( QRcode qrcode)

Free the instance of QRcode class.

Parameters
qrcodean instance of QRcode class.

Definition at line 421 of file qrencode.c.

References QRcode::data, and free().

Referenced by QRCodeQWidget::paintEvent(), and QRcode_List_freeEntry().

void QRcode_List_free ( QRcode_List qrlist)

Free the QRcode_List.

Parameters
qrlista head entry of a QRcode_List.

Definition at line 770 of file qrencode.c.

References _QRcode_List::next, and QRcode_List_freeEntry().

Referenced by QRcode_encodeInputStructured().

static void QRcode_List_freeEntry ( QRcode_List entry)
static

Definition at line 762 of file qrencode.c.

References _QRcode_List::code, free(), and QRcode_free().

Referenced by QRcode_List_free().

static QRcode_List* QRcode_List_newEntry ( void  )
static

Definition at line 749 of file qrencode.c.

References _QRcode_List::code, malloc(), and _QRcode_List::next.

Referenced by QRcode_encodeInputStructured().

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 781 of file qrencode.c.

References _QRcode_List::next.

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

Definition at line 407 of file qrencode.c.

References QRcode::data, malloc(), QRcode::version, and QRcode::width.

Referenced by QRcode_encodeMask(), and QRcode_encodeMaskMQR().

STATIC_IN_RELEASE void QRraw_free ( QRRawCode raw)

Definition at line 178 of file qrencode.c.

References QRRawCode::datacode, QRRawCode::ecccode, free(), and QRRawCode::rsblock.

Referenced by QRcode_encodeMask(), and QRraw_new().

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 155 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().

STATIC_IN_RELEASE QRRawCode* QRraw_new ( QRinput input)
static int RSblock_init ( RSblock blocks,
int  spec[5],
unsigned char *  data,
unsigned char *  ecc 
)
static
static void RSblock_initBlock ( RSblock block,
int  dl,
unsigned char *  data,
int  el,
unsigned char *  ecc 
)
static

Definition at line 60 of file qrencode.c.

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

Referenced by MQRraw_new(), and RSblock_init().