BGE/QrCode

Alias: BGE.QrCode


Static Methods

qrGetNumRawDataModules(ver: integer): integer

static

after all function modules are excluded (includes remainder bits, so may not be a multiple of 8). Result is in [208, 29648].

Parameters

  • ver (integer)

Returns

  • integer

qrGetNumDataCodewords(ver: integer, ecl: integer): integer

static

Code of this version/ECC level, with remainder bits discarded.

Parameters

  • ver (integer)
  • ecl (integer)

Returns

  • integer

qrReedSolomonComputeDivisor(degree: integer): dynamic

static

degree, coefficients stored highest-to-lowest power, leading term omitted (always 1). E.g. x^3 + 255x^2 + 8x + 93 is stored as [255, 8, 93].

Parameters

  • degree (integer)

Returns

  • dynamic

qrReedSolomonComputeRemainder( data: dynamic, divisor: dynamic, ): dynamic

static

Parameters

  • data (dynamic)
  • divisor (dynamic)

Returns

  • dynamic

qrReedSolomonMultiply(x: integer, y: integer): integer

static

result are unsigned 8-bit integers.

Parameters

  • x (integer)
  • y (integer)

Returns

  • integer

qrEncodeText(text: string, ecl: integer): BGE.QrCode.QrCode

static

Parameters

  • text (string) — Unicode text to encode
  • ecl (integer) — a BGE.QrCode.EccLevel value; may be boosted higher if it fits for free

Returns

  • BGE.QrCode.QrCode

qrEncodeBinary( data: Array.<integer>, ecl: integer, ): BGE.QrCode.QrCode

static

Parameters

  • data (Array.<integer>) — raw bytes, always encoded in byte mode (max 2953 bytes)
  • ecl (integer) — a BGE.QrCode.EccLevel value; may be boosted higher if it fits for free

Returns

  • BGE.QrCode.QrCode

qrEncodeSegments( segs: Array.<BGE.QrCode.QrSegment>, ecl: integer, minVersion?: integer, maxVersion?: integer, mask?: integer, boostEcl?: boolean, ): BGE.QrCode.QrCode

static

Mid-level entry point: encodes a custom sequence of segments (e.g. mixing numeric/alphanumeric/byte mode segments to save space).

Parameters

  • segs (Array.<BGE.QrCode.QrSegment>)
  • ecl (integer) — a BGE.QrCode.EccLevel value
  • minVersion (integer, optional, default: 1)
  • maxVersion (integer, optional, default: 40)
  • mask (integer, optional, default: -1) — 0 to 7 to force a mask, or -1 to auto-choose
  • boostEcl (boolean, optional, default: true) — allow a higher ECC level than ecl if it fits for free

Returns

  • BGE.QrCode.QrCode

eccFormatBits(level: integer): integer

static

The format-bits value (uint2) for each error correction level, indexed by EccLevel ordinal.

Parameters

  • level (integer)

Returns

  • integer

eccCodewordsPerBlock(): dynamic

static

ECC codewords per block, indexed [EccLevel ordinal][version]. Index 0 (version 0) is unused padding. See ISO/IEC 18004 table 9.

Returns

  • dynamic

numErrorCorrectionBlocks(): dynamic

static

Number of error correction blocks, indexed [EccLevel ordinal][version]. Index 0 (version 0) is unused padding. See ISO/IEC 18004 table 9.

Returns

  • dynamic

newQrMode(modeName: string): BGE.QrCode.QrMode

static

Parameters

  • modeName (string) — "NUMERIC", "ALPHANUMERIC", "BYTE", "KANJI", or "ECI"

Returns

  • BGE.QrCode.QrMode

draw( renderer: BGE.Renderer, x: float, y: float, code: string, width: float, darkRgba?: integer, lightRgba?: integer, ): boolean

static

Encodes code and draws it as a width x width square via renderer's own draw surface - the single call a game needs (see docs/qr-codes.md). Exposed as a BGE.QrCode function rather than a Renderer.drawQRCode() method: a toolchain limitation in this project's exact brighterscript/bslint/rooibos-roku version combo means a pre-existing file (Renderer.bs) can't reference a symbol from a brand-new file, in either direction of indirection - see project_bslint_rooibos_new_file_bug in engine dev notes. Renderer.getDraw2d()/ incrementDrawCalls() are the two tiny, itself-unaffected additions this needed.

to, or if code is too long to fit any QR version (matches every other Renderer.draw*'s fail-soft-rather-than-crash contract)

Parameters

  • renderer (BGE.Renderer)
  • x (float) — top-left x
  • y (float) — top-left y
  • code (string) — text to encode (e.g. a URL - see Game.getControllerConnectionInfo())
  • width (float) — rendered width/height in pixels (square)
  • darkRgba (integer, optional, default: "BGE.Colors.Black")
  • lightRgba (integer, optional, default: "BGE.Colors.White")

Returns

  • boolean — true if anything was drawn - false if there was nothing to draw

qrDrawModules( draw2d: ifDraw2d, qr: BGE.QrCode.QrCode, x: float, y: float, width: float, darkRgba?: integer, lightRgba?: integer, ): integer

static

Rasterizes an already-encoded QR Code onto draw2d as a width x width block of filled squares (one native DrawRect per module - a dense/high- version code costs more draw calls, same cost model as any other draw call). Used by draw() above, which owns the bounds-check/draw-call-count bookkeeping; this helper only rasterizes.

Parameters

  • draw2d (ifDraw2d)
  • qr (BGE.QrCode.QrCode)
  • x (float) — top-left x
  • y (float) — top-left y
  • width (float) — rendered width/height in pixels (square)
  • darkRgba (integer, optional, default: "BGE.Colors.Black")
  • lightRgba (integer, optional, default: "BGE.Colors.White")

Returns

  • integer

qrGetTotalBits(segs: dynamic, version: integer): integer

static

Calculates the number of bits needed to encode segs at version. Returns a very large sentinel if a segment's length doesn't fit its mode's character-count field width at this version.

Parameters

  • segs (dynamic)
  • version (integer)

Returns

  • integer

qrToUtf8ByteArray(str: string): dynamic

static

Parameters

  • str (string)

Returns

  • dynamic

qrIsNumeric(text: string): boolean

static

Parameters

  • text (string)

Returns

  • boolean

qrIsAlphanumeric(text: string): boolean

static

(0-9, A-Z, space, $ % * + - . / :).

Parameters

  • text (string)

Returns

  • boolean

qrMakeBytes(data: dynamic): BGE.QrCode.QrSegment

static

A segment representing the given binary data in byte mode.

Parameters

  • data (dynamic)

Returns

  • BGE.QrCode.QrSegment

qrMakeNumeric(digits: string): BGE.QrCode.QrSegment

static

A segment representing the given string of decimal digits in numeric mode.

Parameters

  • digits (string)

Returns

  • BGE.QrCode.QrSegment

qrMakeAlphanumeric(text: string): BGE.QrCode.QrSegment

static

A segment representing the given text string in alphanumeric mode (see qrIsAlphanumeric() for the allowed character set).

Parameters

  • text (string)

Returns

  • BGE.QrCode.QrSegment

qrMakeSegments(text: string): dynamic

static

Selects the most efficient segment encoding automatically for text - numeric, then alphanumeric, then byte (UTF-8) mode.

Parameters

  • text (string)

Returns

  • dynamic

qrAppendBits(value: integer, length: integer, bb: dynamic): void

static

Appends the low-order length bits of value (as individual 0/1 integers, MSB first) to bb. Requires 0 <= length <= 31 and 0 <= value < 2^length.

Parameters

  • value (integer)
  • length (integer)
  • bb (dynamic)

Returns

  • void

qrGetBit(x: integer, i: integer): boolean

static

Parameters

  • x (integer)
  • i (integer)

Returns

  • boolean

qrAssert(condition: boolean, message?: string): void

static

Throws if condition is false. Used throughout the ported algorithm to mirror the reference implementation's own internal sanity checks.

Parameters

  • condition (boolean)
  • message (string, optional, default: "\"Assertion error\"")

Returns

  • void

qrXor(x: integer, y: integer): integer

static

BrightScript has no bitwise XOR operator - see the original port's own comment.

Parameters

  • x (integer)
  • y (integer)

Returns

  • integer

qrFloor(f: float): integer

static

Parameters

  • f (float)

Returns

  • integer

qrCeil(f: float): integer

static

Parameters

  • f (float)

Returns

  • integer

qrMin(a: integer, b: integer): integer

static

Parameters

  • a (integer)
  • b (integer)

Returns

  • integer

qrMax(a: integer, b: integer): integer

static

Parameters

  • a (integer)
  • b (integer)

Returns

  • integer

qrSliceArray( arr: object, start?: integer, finish?: integer, ): object

static

A copy of array[start:finish) (JS-Array.slice-style), matching the ported reference's own slice helper exactly: omitting finish (or passing 0) copies the whole array; a negative start/finish counts back from the end.

Parameters

  • arr (object)
  • start (integer, optional, default: 0)
  • finish (integer, optional, default: 0)

Returns

  • object

qrSpliceArray( arr: object, start: integer, deleteCount?: integer, insert?: object, ): object

static

In-place: deletes deleteCount elements starting at start, then inserts insert's elements there - matching the ported reference's own splice, minus two off-by-one bugs the reference itself had (both compared against arr.Count() - 1 where plain arr.Count() was needed - the clamp/negative- index handling below, and the relocate-loop condition, which used to stop one element short of the end, silently reordering rather than inserting: e.g. qrSpliceArray([6, 38], 1, 0, [22]) gave [6, 38, 22] instead of [6, 22, 38] - exactly the case getAlignmentPatternPositions() hits for QR version 7+).

Parameters

  • arr (object)
  • start (integer)
  • deleteCount (integer, optional, default: 999999)
  • insert (object, optional, default: "[]")

Returns

  • object

Enums

BGE.QrCode.EccLevel

enumstaticreadonly

Properties

  • low (default: 0)
  • medium (default: 1)
  • quartile (default: 2)
  • high (default: 3)

Other

QrCode

static

A QR Code symbol: an immutable square grid of dark/light modules. Covers QR Code Model 2, versions 1-40, all 4 error correction levels. See QrConstants.bs's file doc comment for provenance.

modules/isFunction store each cell as an integer 0 (light) or 1 (dark) - not a real Boolean - since applyMask() flips cells with plain arithmetic.

Parameters

  • version (integer) — 1 to 40
  • errorCorrectionLevel (integer) — a BGE.QrCode.EccLevel value
  • dataCodewords (Array.<integer>)
  • msk (integer) — 0 to 7 to force a mask, or -1 to auto-choose the lowest-penalty one

Properties

  • version (integer)
  • errorCorrectionLevel (integer) — a BGE.QrCode.EccLevel value
  • size (integer) — a BGE.QrCode.EccLevel value
  • mask (integer)

Returns

  • BGE.QrCode.QrCode

MIN_VERSION

staticreadonly

Default: 1

MAX_VERSION

staticreadonly

Default: 40

PENALTY_N1

staticreadonly

Penalty weights used by QrCode.getPenaltyScore() when auto-selecting a mask.

Default: 3

PENALTY_N2

staticreadonly

Default: 3

PENALTY_N3

staticreadonly

Default: 40

PENALTY_N4

staticreadonly

Default: 10

QrMode

static

A QR Code data-segment mode (numeric/alphanumeric/byte/kanji/ECI) and its per-version-range character-count field width. See ISO/IEC 18004 table 3.

Parameters

  • modeBits (integer)
  • numBitsCharCount (dynamic)

Properties

  • modeBits (integer)
  • numBitsCharCount (dynamic)

Returns

  • BGE.QrCode.QrMode

ALPHANUMERIC_CHARSET

staticreadonly

The set of all legal characters in alphanumeric mode, indexed by character value.

Default: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:

QrSegment

static

A segment of character/binary/control data in a QR Code symbol. See QrConstants.bs's file doc comment for provenance.

Parameters

  • modeName (string)
  • numChars (integer)
  • bitData (dynamic)

Properties

  • mode (BGE.QrCode.QrMode)
  • numChars (integer) — Unencoded length: characters for numeric/alphanumeric/kanji, bytes for ' byte mode, 0 for ECI mode. Not the same as bitData's length.
  • bitData (dynamic) — This segment's data bits, each element an individual 0/1 integer.

Returns

  • BGE.QrCode.QrSegment