NDEVR
API Documentation
QrCodefinal

A QR Code symbol, which is a type of two-dimensional barcode. More...

Public Types

enum class  Ecc { LOW = 0 , MEDIUM , QUARTILE , HIGH }
 The error correction level in a QR Code symbol. More...

Public Member Functions

 QrCode (int ver, Ecc ecl, const Buffer< std::uint8_t > &dataCodewords, int msk)
 Creates a new QR Code with the given version number, error correction level, data codeword bytes, and mask number.
Ecc getErrorCorrectionLevel () const
 Returns this QR Code's error correction level.
int getMask () const
 Returns this QR Code's mask pattern index.
bool getModule (int x, int y) const
 Returns the color of the module (pixel) at the given coordinates.
int getSize () const
 Returns this QR Code's size (width and height in modules).
int getVersion () const
 Returns this QR Code's version number.
String toSVG (uint04 border, RGBColor color, RGBColor background=Constant< RGBColor >::Invalid) const
 Generates an SVG (Scalable Vector Graphics) string representation of this QR Code.

Static Public Member Functions

static QrCode encodeBinary (const uint01 *data, uint04 size, Ecc ecl)
 Returns a QR Code representing the given binary data at the given error correction level.
static QrCode encodeLink (const char *text, Ecc ecl)
 Returns a QR Code representing the given link text at the given error correction level.
static QrCode encodeSegments (const QrSegmentBuffer &segs, Ecc ecl, int minVersion=1, int maxVersion=40, int mask=-1, bool boostEcl=true)
 Returns a QR Code representing the given segments with the given encoding parameters.
static QrCode encodeText (const char *text, Ecc ecl)
 Returns a QR Code representing the given Unicode text string at the given error correction level.

Static Public Attributes

static constexpr int MAX_VERSION = 40
 The maximum QR Code version number (40).
static constexpr int MIN_VERSION = 1
 The minimum QR Code version number (1).

Detailed Description

A QR Code symbol, which is a type of two-dimensional barcode.

Invented by Denso Wave and described in the ISO/IEC 18004 standard. Instances of this class represent an immutable square grid of dark and light cells. The class provides static factory functions to create a QR Code from text or binary data. The class covers the QR Code Model 2 specification, supporting all versions (sizes) from 1 to 40, all 4 error correction levels, and 4 character encoding modes.

Ways to create a QR Code object:

  • High level: Take the payload data and call QrCode::encodeText() or QrCode::encodeBinary().
  • Mid level: Custom-make the list of segments and call QrCode::encodeSegments().
  • Low level: Custom-make the array of data codeword bytes (including segment headers and final padding, excluding error correction codewords), supply the appropriate version number, and call the QrCode() constructor.

Definition at line 281 of file QRCode.h.

Member Enumeration Documentation

◆ Ecc

enum class QrCode::Ecc
strong

The error correction level in a QR Code symbol.

Enumerator
LOW 

The QR Code can tolerate about 7% erroneous codewords.

MEDIUM 

The QR Code can tolerate about 15% erroneous codewords.

QUARTILE 

The QR Code can tolerate about 25% erroneous codewords.

HIGH 

The QR Code can tolerate about 30% erroneous codewords.

Definition at line 288 of file QRCode.h.

Constructor & Destructor Documentation

◆ QrCode()

QrCode::QrCode ( int ver,
Ecc ecl,
const Buffer< std::uint8_t > & dataCodewords,
int msk )

Creates a new QR Code with the given version number, error correction level, data codeword bytes, and mask number.

This is a low-level API that most users should not use directly. A mid-level API is the encodeSegments() function.

Parameters
[in]verThe version number (1 to 40).
[in]eclThe error correction level.
[in]dataCodewordsThe raw data codeword bytes (excluding error correction).
[in]mskThe mask pattern to apply (0-7), or -1 for automatic selection.

Referenced by encodeBinary(), encodeLink(), encodeSegments(), and encodeText().

Member Function Documentation

◆ encodeBinary()

QrCode QrCode::encodeBinary ( const uint01 * data,
uint04 size,
Ecc ecl )
static

Returns a QR Code representing the given binary data at the given error correction level.

This function always encodes using the binary segment mode, not any text mode. The maximum number of bytes allowed is 2953. The smallest possible QR Code version is automatically chosen for the output. The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.

Parameters
[in]dataPointer to the raw binary data to encode.
[in]sizeThe number of bytes in the data array.
[in]eclThe minimum error correction level to use.
Returns
A QrCode encoding the given binary data.

References QrCode().

◆ encodeLink()

QrCode QrCode::encodeLink ( const char * text,
Ecc ecl )
static

Returns a QR Code representing the given link text at the given error correction level.

Note
The exact difference in behavior compared to encodeText() is unclear from the declaration alone. Likely applies link-specific encoding or formatting.
Parameters
[in]textA null-terminated text string representing a link/URL.
[in]eclThe minimum error correction level to use.
Returns
A QrCode encoding the given link.

References QrCode().

◆ encodeSegments()

QrCode QrCode::encodeSegments ( const QrSegmentBuffer & segs,
Ecc ecl,
int minVersion = 1,
int maxVersion = 40,
int mask = -1,
bool boostEcl = true )
static

Returns a QR Code representing the given segments with the given encoding parameters.

The smallest possible QR Code version within the given range is automatically chosen for the output. If boostEcl is true, then the ECC level of the result may be higher than the ecl argument if it can be done without increasing the version. The mask number is either between 0 to 7 (inclusive) to force that mask, or -1 to automatically choose an appropriate mask (which may be slow). This function allows the user to create a custom sequence of segments that switches between modes (such as alphanumeric and byte) to encode text in less space.

Parameters
[in]segsThe buffer of QrSegment objects to encode.
[in]eclThe minimum error correction level to use.
[in]minVersionThe minimum QR Code version to consider (default 1).
[in]maxVersionThe maximum QR Code version to consider (default 40).
[in]maskThe mask pattern to use (0-7), or -1 for automatic selection (default -1).
[in]boostEclWhether to boost the ECC level if possible without increasing version (default true).
Returns
A QrCode encoding the given segments.

References QrCode().

◆ encodeText()

QrCode QrCode::encodeText ( const char * text,
Ecc ecl )
static

Returns a QR Code representing the given Unicode text string at the given error correction level.

As a conservative upper bound, this function is guaranteed to succeed for strings that have 2953 or fewer UTF-8 code units (not Unicode code points) if the low error correction level is used. The smallest possible QR Code version is automatically chosen for the output. The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.

Parameters
[in]textA null-terminated UTF-8 encoded text string.
[in]eclThe minimum error correction level to use.
Returns
A QrCode encoding the given text.

References QrCode().

◆ getErrorCorrectionLevel()

Ecc QrCode::getErrorCorrectionLevel ( ) const

Returns this QR Code's error correction level.

Returns
The Ecc level used by this QR Code.

◆ getMask()

int QrCode::getMask ( ) const

Returns this QR Code's mask pattern index.

Returns
The mask, in the range [0, 7].

◆ getModule()

bool QrCode::getModule ( int x,
int y ) const

Returns the color of the module (pixel) at the given coordinates.

Returns false for light or true for dark. The top left corner has the coordinates (x=0, y=0). If the given coordinates are out of bounds, then false (light) is returned.

Parameters
[in]xThe horizontal coordinate (column index).
[in]yThe vertical coordinate (row index).
Returns
True if the module is dark, false if light or out of bounds.

◆ getSize()

int QrCode::getSize ( ) const

Returns this QR Code's size (width and height in modules).

Returns
The size, in the range [21, 177].

◆ getVersion()

int QrCode::getVersion ( ) const

Returns this QR Code's version number.

Returns
The version, in the range [1, 40].

◆ toSVG()

String QrCode::toSVG ( uint04 border,
RGBColor color,
RGBColor background = ConstantRGBColor >::Invalid ) const

Generates an SVG (Scalable Vector Graphics) string representation of this QR Code.

Parameters
[in]borderThe number of border modules (quiet zone) to add around the QR Code.
[in]colorThe foreground color for dark modules.
[in]backgroundThe background color for light modules. If invalid, no background is drawn.
Returns
A String containing the SVG markup.

The documentation for this class was generated from the following file: