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)  

qrspec.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "qrspec.h"
#include "qrinput.h"
Include dependency graph for qrspec.c:

Go to the source code of this file.

Data Structures

struct  QRspec_Capacity
 Version and capacity. More...
 

Functions

int QRspec_getDataLength (int version, QRecLevel level)
 Return maximum data code length (bytes) for the version. More...
 
int QRspec_getECCLength (int version, QRecLevel level)
 Return maximum error correction code length (bytes) for the version. More...
 
int QRspec_getMinimumVersion (int size, QRecLevel level)
 Return a version number that satisfies the input code length. More...
 
int QRspec_getWidth (int version)
 Return the width of the symbol for the version. More...
 
int QRspec_getRemainder (int version)
 Return the numer of remainder bits. More...
 
int QRspec_lengthIndicator (QRencodeMode mode, int version)
 Length indicator. More...
 
int QRspec_maximumWords (QRencodeMode mode, int version)
 Return the maximum length for the mode and version. More...
 
void QRspec_getEccSpec (int version, QRecLevel level, int spec[5])
 Error correction code. More...
 
static void QRspec_putAlignmentMarker (unsigned char *frame, int width, int ox, int oy)
 Put an alignment marker. More...
 
static void QRspec_putAlignmentPattern (int version, unsigned char *frame, int width)
 
unsigned int QRspec_getVersionPattern (int version)
 Version information pattern. More...
 
unsigned int QRspec_getFormatInfo (int mask, QRecLevel level)
 Format information. More...
 
static void putFinderPattern (unsigned char *frame, int width, int ox, int oy)
 Frame. More...
 
static unsigned char * QRspec_createFrame (int version)
 
unsigned char * QRspec_newFrame (int version)
 Frame. More...
 

Variables

static const QRspec_Capacity qrspecCapacity [40+1]
 Table of the capacity of symbols See Table 1 (pp.13) and Table 12-16 (pp.30-36), JIS X0510:2004. More...
 
static const int lengthTableBits [4][3]
 Length indicator. More...
 
static const int eccTable [40+1][4][2]
 Error correction code. More...
 
static const int alignmentPattern [40+1][2]
 Alignment pattern. More...
 
static const unsigned int versionPattern [40 - 6]
 Version information pattern. More...
 
static const unsigned int formatInfo [4][8]
 Format information. More...
 

Function Documentation

◆ putFinderPattern()

static void putFinderPattern ( unsigned char *  frame,
int  width,
int  ox,
int  oy 
)
static

Frame.

Put a finder pattern.

Parameters
frame
width
ox,oyupper-left coordinate of the pattern

Definition at line 400 of file qrspec.c.

Referenced by QRspec_createFrame().

◆ QRspec_createFrame()

static unsigned char * QRspec_createFrame ( int  version)
static

◆ QRspec_getDataLength()

int QRspec_getDataLength ( int  version,
QRecLevel  level 
)

Return maximum data code length (bytes) for the version.

Parameters
versionversion of the symbol
levelerror correction level
Returns
maximum size (bytes)

Definition at line 98 of file qrspec.c.

References QRspec_Capacity::ec, level, qrspecCapacity, version, and QRspec_Capacity::words.

Referenced by QRinput_appendPaddingBit(), QRinput_splitQRinputToStruct(), and QRspec_getEccSpec().

◆ QRspec_getECCLength()

int QRspec_getECCLength ( int  version,
QRecLevel  level 
)

Return maximum error correction code length (bytes) for the version.

Parameters
versionversion of the symbol
levelerror correction level
Returns
ECC size (bytes)

Definition at line 103 of file qrspec.c.

References QRspec_Capacity::ec, level, qrspecCapacity, and version.

Referenced by QRspec_getEccSpec().

◆ QRspec_getEccSpec()

void QRspec_getEccSpec ( int  version,
QRecLevel  level,
int  spec[5] 
)

Error correction code.

Return an array of ECC specification.

Parameters
versionversion of the symbol
levelerror correction level
specan array of ECC specification contains as following: {# of type1 blocks, # of data code, # of ecc code,

of type2 blocks, # of data code}

Definition at line 234 of file qrspec.c.

References eccTable, level, QRspec_getDataLength(), QRspec_getECCLength(), and version.

Referenced by QRraw_new().

◆ QRspec_getFormatInfo()

unsigned int QRspec_getFormatInfo ( int  mask,
QRecLevel  level 
)

Format information.

Return BCH encoded format information pattern.

Parameters
maskmask number
levelerror correction level
Returns
BCH encoded format information pattern

Definition at line 383 of file qrspec.c.

References formatInfo, and level.

Referenced by Mask_writeFormatInformation().

◆ QRspec_getMinimumVersion()

int QRspec_getMinimumVersion ( int  size,
QRecLevel  level 
)

Return a version number that satisfies the input code length.

Parameters
sizeinput code length (byte)
levelerror correction level
Returns
version number

Definition at line 108 of file qrspec.c.

References QRspec_Capacity::ec, level, QRSPEC_VERSION_MAX, qrspecCapacity, size, and QRspec_Capacity::words.

Referenced by QRinput_convertData(), and QRinput_estimateVersion().

◆ QRspec_getRemainder()

int QRspec_getRemainder ( int  version)

Return the numer of remainder bits.

Parameters
versionvesion of the symbol
Returns
number of remainder bits

Definition at line 126 of file qrspec.c.

References qrspecCapacity, QRspec_Capacity::remainder, and version.

Referenced by QRcode_encodeMask().

◆ QRspec_getVersionPattern()

unsigned int QRspec_getVersionPattern ( int  version)

Version information pattern.

Return BCH encoded version information pattern that is used for the symbol of version 7 or greater. Use lower 18 bits.

Parameters
versionversion of the symbol
Returns
BCH encoded version information pattern

Definition at line 364 of file qrspec.c.

References QRSPEC_VERSION_MAX, version, and versionPattern.

Referenced by QRspec_createFrame().

◆ QRspec_getWidth()

int QRspec_getWidth ( int  version)

Return the width of the symbol for the version.

Parameters
versionvesion of the symbol
Returns
width of the symbol

Definition at line 121 of file qrspec.c.

References qrspecCapacity, version, and QRspec_Capacity::width.

Referenced by QRcode_encodeMask().

◆ QRspec_lengthIndicator()

int QRspec_lengthIndicator ( QRencodeMode  mode,
int  version 
)

Length indicator.

Return the size of length indicator for the mode and version.

Parameters
modeencode mode
versionvesion of the symbol
Returns
the size of the appropriate length indicator (bits).

Definition at line 142 of file qrspec.c.

References lengthTableBits, QRinput_isSplittableMode(), and version.

Referenced by QRinput_encodeMode8(), QRinput_encodeModeAn(), QRinput_encodeModeKanji(), QRinput_encodeModeNum(), QRinput_estimateBitStreamSizeOfEntry(), QRinput_lengthOfCode(), Split_eat8(), Split_eatAn(), and Split_eatNum().

◆ QRspec_maximumWords()

int QRspec_maximumWords ( QRencodeMode  mode,
int  version 
)

Return the maximum length for the mode and version.

Parameters
modeencode mode
versionvesion of the symbol
Returns
the maximum length (bytes)

Definition at line 158 of file qrspec.c.

References lengthTableBits, QR_MODE_KANJI, QRinput_isSplittableMode(), and version.

Referenced by QRinput_encodeBitStream(), and QRinput_lengthOfCode().

◆ QRspec_newFrame()

unsigned char * QRspec_newFrame ( int  version)

Frame.

Return a copy of initialized frame.

Parameters
versionversion of the symbol
Returns
Array of unsigned char. You can free it by free().

Definition at line 509 of file qrspec.c.

References QRspec_createFrame(), QRSPEC_VERSION_MAX, and version.

Referenced by QRcode_encodeMask().

◆ QRspec_putAlignmentMarker()

static void QRspec_putAlignmentMarker ( unsigned char *  frame,
int  width,
int  ox,
int  oy 
)
static

Put an alignment marker.

Parameters
frame
width
ox,oycenter coordinate of the pattern

Definition at line 287 of file qrspec.c.

Referenced by QRspec_putAlignmentPattern().

◆ QRspec_putAlignmentPattern()

static void QRspec_putAlignmentPattern ( int  version,
unsigned char *  frame,
int  width 
)
static

Definition at line 310 of file qrspec.c.

References alignmentPattern, QRspec_putAlignmentMarker(), and version.

Referenced by QRspec_createFrame().

Variable Documentation

◆ alignmentPattern

const int alignmentPattern[40+1][2]
static
Initial value:
= {
{ 0, 0},
{ 0, 0}, {18, 0}, {22, 0}, {26, 0}, {30, 0},
{34, 0}, {22, 38}, {24, 42}, {26, 46}, {28, 50},
{30, 54}, {32, 58}, {34, 62}, {26, 46}, {26, 48},
{26, 50}, {30, 54}, {30, 56}, {30, 58}, {34, 62},
{28, 50}, {26, 50}, {30, 54}, {28, 54}, {32, 58},
{30, 58}, {34, 62}, {26, 50}, {30, 54}, {26, 52},
{30, 56}, {34, 60}, {30, 58}, {34, 62}, {30, 54},
{24, 50}, {28, 54}, {32, 58}, {26, 54}, {30, 58},
}

Alignment pattern.

Positions of alignment patterns. This array includes only the second and the third position of the alignment patterns. Rest of them can be calculated from the distance between them.

See Table 1 in Appendix E (pp.71) of JIS X0510:2004.

Definition at line 269 of file qrspec.c.

Referenced by QRspec_putAlignmentPattern().

◆ eccTable

const int eccTable[40+1][4][2]
static

Error correction code.

Table of the error correction code (Reed-Solomon block) See Table 12-16 (pp.30-36), JIS X0510:2004.

Definition at line 190 of file qrspec.c.

Referenced by QRspec_getEccSpec().

◆ formatInfo

const unsigned int formatInfo[4][8]
static
Initial value:
= {
{0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976},
{0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0},
{0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed},
{0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b}
}

Format information.

Definition at line 376 of file qrspec.c.

Referenced by QRspec_getFormatInfo().

◆ lengthTableBits

const int lengthTableBits[4][3]
static
Initial value:
= {
{10, 12, 14},
{ 9, 11, 13},
{ 8, 16, 16},
{ 8, 10, 12}
}

Length indicator.

Definition at line 135 of file qrspec.c.

Referenced by QRspec_lengthIndicator(), and QRspec_maximumWords().

◆ qrspecCapacity

const QRspec_Capacity qrspecCapacity[40+1]
static

Table of the capacity of symbols See Table 1 (pp.13) and Table 12-16 (pp.30-36), JIS X0510:2004.

Definition at line 54 of file qrspec.c.

Referenced by QRspec_createFrame(), QRspec_getDataLength(), QRspec_getECCLength(), QRspec_getMinimumVersion(), QRspec_getRemainder(), and QRspec_getWidth().

◆ versionPattern

const unsigned int versionPattern[40 - 6]
static
Initial value:
= {
0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d,
0x0f928, 0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9,
0x177ec, 0x18ec4, 0x191e1, 0x1afab, 0x1b08e, 0x1cc1a, 0x1d33f, 0x1ed75,
0x1f250, 0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64,
0x27541, 0x28c69
}

Version information pattern.

Version information pattern (BCH coded). See Table 1 in Appendix D (pp.68) of JIS X0510:2004.

Definition at line 356 of file qrspec.c.

Referenced by QRspec_getVersionPattern().