Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402]

(no description)

Author: Nicola Asuni
Version: 1.0.010
File Size: 2842 lines (79 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

QRcode:: (98 methods):
  __construct()
  getBarcodeArray()
  binarize()
  encodeString()
  encodeMask()
  setFrameAt()
  getFrameAt()
  getNextPosition()
  init()
  getCode()
  writeFormatInformation()
  mask0()
  mask1()
  mask2()
  mask3()
  mask4()
  mask5()
  mask6()
  mask7()
  generateMaskNo()
  makeMaskNo()
  makeMask()
  calcN1N3()
  evaluateSymbol()
  mask()
  isdigitat()
  isalnumat()
  identifyMode()
  eatNum()
  eatAn()
  eatKanji()
  eat8()
  splitString()
  toUpper()
  newInputItem()
  encodeModeNum()
  encodeModeAn()
  encodeMode8()
  encodeModeKanji()
  encodeModeStructure()
  encodeBitStream()
  appendNewInputItem()
  insertStructuredAppendHeader()
  calcParity()
  checkModeNum()
  lookAnTable()
  checkModeAn()
  estimateBitsModeNum()
  estimateBitsModeAn()
  estimateBitsMode8()
  estimateBitsModeKanji()
  checkModeKanji()
  check()
  estimateBitStreamSize()
  estimateVersion()
  lengthOfCode()
  createBitStream()
  convertData()
  appendPaddingBit()
  mergeBitStream()
  getBitStream()
  getByteStream()
  allocate()
  newFromNum()
  newFromBytes()
  appendBitstream()
  appendNum()
  appendBytes()
  bitstreamToByte()
  qrstrset()
  getDataLength()
  getECCLength()
  getWidth()
  getRemainder()
  getMinimumVersion()
  lengthIndicator()
  maximumWords()
  getEccSpec()
  putAlignmentMarker()
  putAlignmentPattern()
  getVersionPattern()
  getFormatInfo()
  putFinderPattern()
  createFrame()
  newFrame()
  rsBlockNum()
  rsBlockNum1()
  rsDataCodes1()
  rsEccCodes1()
  rsBlockNum2()
  rsDataCodes2()
  rsEccCodes2()
  rsDataLength()
  rsEccLength()
  init_rs()
  modnn()
  init_rs_char()
  encode_rs_char()


Class: QRcode  - X-Ref


__construct($code, $eclevel = 'L')   X-Ref
This is the class constructor.
Creates a QRcode object

param: string $code code to represent using QRcode
param: string $eclevel error level: <ul><li>L : About 7% or less errors can be corrected.</li><li>M : About 15% or less errors can be corrected.</li><li>Q : About 25% or less errors can be corrected.</li><li>H : About 30% or less errors can be corrected.</li></ul>

getBarcodeArray()   X-Ref
Returns a barcode array which is readable by TCPDF

return: array barcode array readable by TCPDF;

binarize($frame)   X-Ref
Convert the frame in binary form

param: array $frame array to binarize
return: array frame in binary form

encodeString($string)   X-Ref
Encode the input string to QR code

param: string $string input string to encode

encodeMask($mask)   X-Ref
Encode mask

param: int $mask masking mode

setFrameAt($at, $val)   X-Ref
Set frame value at specified position

param: array $at x,y position
param: int $val value of the character to set

getFrameAt($at)   X-Ref
Get frame value at specified position

param: array $at x,y position
return: value at specified position

getNextPosition()   X-Ref
Return the next frame position

return: array of x,y coordinates

init($spec)   X-Ref
Initialize code.

param: array $spec array of ECC specification
return: int 0 in case of success, -1 in case of error

getCode()   X-Ref
Return Reed-Solomon block code.

return: array rsblocks

writeFormatInformation($width, &$frame, $mask, $level)   X-Ref
Write Format Information on frame and returns the number of black bits

param: int $width frame width
param: array $frame frame
param: array $mask masking mode
param: int $level error correction level
return: int blacks

mask0($x, $y)   X-Ref
mask0

param: int $x X position
param: int $y Y position
return: int mask

mask1($x, $y)   X-Ref
mask1

param: int $x X position
param: int $y Y position
return: int mask

mask2($x, $y)   X-Ref
mask2

param: int $x X position
param: int $y Y position
return: int mask

mask3($x, $y)   X-Ref
mask3

param: int $x X position
param: int $y Y position
return: int mask

mask4($x, $y)   X-Ref
mask4

param: int $x X position
param: int $y Y position
return: int mask

mask5($x, $y)   X-Ref
mask5

param: int $x X position
param: int $y Y position
return: int mask

mask6($x, $y)   X-Ref
mask6

param: int $x X position
param: int $y Y position
return: int mask

mask7($x, $y)   X-Ref
mask7

param: int $x X position
param: int $y Y position
return: int mask

generateMaskNo($maskNo, $width, $frame)   X-Ref
Return bitmask

param: int $maskNo mask number
param: int $width width
param: array $frame frame
return: array bitmask

makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly=false)   X-Ref
makeMaskNo

param: int $maskNo
param: int $width
param: int $s
param: int $d
param: boolean $maskGenOnly
return: int b

makeMask($width, $frame, $maskNo, $level)   X-Ref
makeMask

param: int $width
param: array $frame
param: int $maskNo
param: int $level
return: array mask

calcN1N3($length)   X-Ref
calcN1N3

param: int $length
return: int demerit

evaluateSymbol($width, $frame)   X-Ref
evaluateSymbol

param: int $width
param: array $frame
return: int demerit

mask($width, $frame, $level)   X-Ref
mask

param: int $width
param: array $frame
param: int $level
return: array best mask

isdigitat($str, $pos)   X-Ref
Return true if the character at specified position is a number

param: string $str string
param: int $pos characted position
return: boolean true of false

isalnumat($str, $pos)   X-Ref
Return true if the character at specified position is an alphanumeric character

param: string $str string
param: int $pos characted position
return: boolean true of false

identifyMode($pos)   X-Ref
identifyMode

param: int $pos
return: int mode

eatNum()   X-Ref
eatNum

return: int run

eatAn()   X-Ref
eatAn

return: int run

eatKanji()   X-Ref
eatKanji

return: int run

eat8()   X-Ref
eat8

return: int run

splitString()   X-Ref
splitString

return: int

toUpper()   X-Ref
toUpper


newInputItem($mode, $size, $data, $bstream=null)   X-Ref
newInputItem

param: int $mode
param: int $size
param: array $data
param: array $bstream
return: array input item

encodeModeNum($inputitem, $version)   X-Ref
encodeModeNum

param: array $inputitem
param: int $version
return: array input item

encodeModeAn($inputitem, $version)   X-Ref
encodeModeAn

param: array $inputitem
param: int $version
return: array input item

encodeMode8($inputitem, $version)   X-Ref
encodeMode8

param: array $inputitem
param: int $version
return: array input item

encodeModeKanji($inputitem, $version)   X-Ref
encodeModeKanji

param: array $inputitem
param: int $version
return: array input item

encodeModeStructure($inputitem)   X-Ref
encodeModeStructure

param: array $inputitem
return: array input item

encodeBitStream($inputitem, $version)   X-Ref
encodeBitStream

param: array $inputitem
param: int $version
return: array input item

appendNewInputItem($items, $mode, $size, $data)   X-Ref
Append data to an input object.
The data is copied and appended to the input object.

param: array $items input items
param: int $mode encoding mode.
param: int $size size of data (byte).
param: array $data array of input data.
return: array items

insertStructuredAppendHeader($items, $size, $index, $parity)   X-Ref
insertStructuredAppendHeader

param: array $items
param: int $size
param: int $index
param: int $parity
return: array items

calcParity($items)   X-Ref
calcParity

param: array $items
return: int parity

checkModeNum($size, $data)   X-Ref
checkModeNum

param: int $size
param: array $data
return: boolean true or false

lookAnTable($c)   X-Ref
Look up the alphabet-numeric conversion table (see JIS X0510:2004, pp.19).

param: int $c character value
return: int value

checkModeAn($size, $data)   X-Ref
checkModeAn

param: int $size
param: array $data
return: boolean true or false

estimateBitsModeNum($size)   X-Ref
estimateBitsModeNum

param: int $size
return: int number of bits

estimateBitsModeAn($size)   X-Ref
estimateBitsModeAn

param: int $size
return: int number of bits

estimateBitsMode8($size)   X-Ref
estimateBitsMode8

param: int $size
return: int number of bits

estimateBitsModeKanji($size)   X-Ref
estimateBitsModeKanji

param: int $size
return: int number of bits

checkModeKanji($size, $data)   X-Ref
checkModeKanji

param: int $size
param: array $data
return: boolean true or false

check($mode, $size, $data)   X-Ref
Validate the input data.

param: int $mode encoding mode.
param: int $size size of data (byte).
param: array $data data to validate
return: boolean true in case of valid data, false otherwise

estimateBitStreamSize($items, $version)   X-Ref
estimateBitStreamSize

param: array $items
param: int $version
return: int bits

estimateVersion($items)   X-Ref
estimateVersion

param: array $items
return: int version

lengthOfCode($mode, $version, $bits)   X-Ref
lengthOfCode

param: int $mode
param: int $version
param: int $bits
return: int size

createBitStream($items)   X-Ref
createBitStream

param: array $items
return: array of items and total bits

convertData($items)   X-Ref
convertData

param: array $items
return: array items

appendPaddingBit($bstream)   X-Ref
Append Padding Bit to bitstream

param: array $bstream
return: array bitstream

mergeBitStream($items)   X-Ref
mergeBitStream

param: array $items items
return: array bitstream

getBitStream($items)   X-Ref
Returns a stream of bits.

param: int $items
return: array padded merged byte stream

getByteStream($items)   X-Ref
Pack all bit streams padding bits into a byte array.

param: int $items
return: array padded merged byte stream

allocate($setLength)   X-Ref
Return an array with zeros

param: int $setLength array size
return: array

newFromNum($bits, $num)   X-Ref
Return new bitstream from number

param: int $bits number of bits
param: int $num number
return: array bitstream

newFromBytes($size, $data)   X-Ref
Return new bitstream from bytes

param: int $size size
param: array $data bytes
return: array bitstream

appendBitstream($bitstream, $append)   X-Ref
Append one bitstream to another

param: array $bitstream original bitstream
param: array $append bitstream to append
return: array bitstream

appendNum($bitstream, $bits, $num)   X-Ref
Append one bitstream created from number to another

param: array $bitstream original bitstream
param: int $bits number of bits
param: int $num number
return: array bitstream

appendBytes($bitstream, $size, $data)   X-Ref
Append one bitstream created from bytes to another

param: array $bitstream original bitstream
param: int $size size
param: array $data bytes
return: array bitstream

bitstreamToByte($bstream)   X-Ref
Convert bitstream to bytes

param: array $bstream original bitstream
return: array of bytes

qrstrset($srctab, $x, $y, $repl, $replLen=false)   X-Ref
Replace a value on the array at the specified position

param: array $srctab
param: int $x X position
param: int $y Y position
param: string $repl value to replace
param: int $replLen length of the repl string
return: array srctab

getDataLength($version, $level)   X-Ref
Return maximum data code length (bytes) for the version.

param: int $version version
param: int $level error correction level
return: int maximum size (bytes)

getECCLength($version, $level)   X-Ref
Return maximum error correction code length (bytes) for the version.

param: int $version version
param: int $level error correction level
return: int ECC size (bytes)

getWidth($version)   X-Ref
Return the width of the symbol for the version.

param: int $version version
return: int width

getRemainder($version)   X-Ref
Return the numer of remainder bits.

param: int $version version
return: int number of remainder bits

getMinimumVersion($size, $level)   X-Ref
Return a version number that satisfies the input code length.

param: int $size input code length (bytes)
param: int $level error correction level
return: int version number

lengthIndicator($mode, $version)   X-Ref
Return the size of length indicator for the mode and version.

param: int $mode encoding mode
param: int $version version
return: int the size of the appropriate length indicator (bits).

maximumWords($mode, $version)   X-Ref
Return the maximum length for the mode and version.

param: int $mode encoding mode
param: int $version version
return: int the maximum length (bytes)

getEccSpec($version, $level, $spec)   X-Ref
Return an array of ECC specification.

param: int $version version
param: int $level error correction level
param: array $spec an array of ECC specification contains as following: {# of type1 blocks, # of data code, # of ecc code, # of type2 blocks, # of data code}
return: array spec

putAlignmentMarker($frame, $ox, $oy)   X-Ref
Put an alignment marker.

param: array $frame frame
param: int $ox X center coordinate of the pattern
param: int $oy Y center coordinate of the pattern
return: array frame

putAlignmentPattern($version, $frame, $width)   X-Ref
Put an alignment pattern.

param: int $version version
param: array $frame frame
param: int $width width
return: array frame

getVersionPattern($version)   X-Ref
Return BCH encoded version information pattern that is used for the symbol of version 7 or greater. Use lower 18 bits.

param: int $version version
return: string BCH encoded version information pattern

getFormatInfo($mask, $level)   X-Ref
Return BCH encoded format information pattern.

param: array $mask
param: int $level error correction level
return: string BCH encoded format information pattern

putFinderPattern($frame, $ox, $oy)   X-Ref
Put a finder pattern.

param: array $frame frame
param: int $ox X center coordinate of the pattern
param: int $oy Y center coordinate of the pattern
return: array frame

createFrame($version)   X-Ref
Return a copy of initialized frame.

param: int $version version
return: array array of unsigned char.

newFrame($version)   X-Ref
Set new frame for the specified version.

param: int $version version
return: array array of unsigned char.

rsBlockNum($spec)   X-Ref
Return block number 0

param: array $spec
return: int value

rsBlockNum1($spec)   X-Ref
Return block number 1

param: array $spec
return: int value

rsDataCodes1($spec)   X-Ref
Return data codes 1

param: array $spec
return: int value

rsEccCodes1($spec)   X-Ref
Return ecc codes 1

param: array $spec
return: int value

rsBlockNum2($spec)   X-Ref
Return block number 2

param: array $spec
return: int value

rsDataCodes2($spec)   X-Ref
Return data codes 2

param: array $spec
return: int value

rsEccCodes2($spec)   X-Ref
Return ecc codes 2

param: array $spec
return: int value

rsDataLength($spec)   X-Ref
Return data length

param: array $spec
return: int value

rsEccLength($spec)   X-Ref
Return ecc length

param: array $spec
return: int value

init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)   X-Ref
Initialize a Reed-Solomon codec and add it to existing rsitems

param: int $symsize symbol size, bits
param: int $gfpoly  Field generator polynomial coefficients
param: int $fcr  first root of RS code generator polynomial, index form
param: int $prim  primitive element to generate polynomial roots
param: int $nroots RS code generator polynomial degree (number of roots)
param: int $pad  padding bytes at front of shortened block
return: array Array of RS values:<ul><li>mm = Bits per symbol;</li><li>nn = Symbols per block;</li><li>alpha_to = log lookup table array;</li><li>index_of = Antilog lookup table array;</li><li>genpoly = Generator polynomial array;</li><li>nroots = Number of generator;</li><li>roots = number of parity symbols;</li><li>fcr = First consecutive root, index form;</li><li>prim = Primitive element, index form;</li><li>iprim = prim-th root of 1, index form;</li><li>pad = Padding bytes in shortened block;</li><li>gfpoly</ul>.

modnn($rs, $x)   X-Ref
modnn

param: array $rs RS values
param: int $x X position
return: int X osition

init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)   X-Ref
Initialize a Reed-Solomon codec and returns an array of values.

param: int $symsize symbol size, bits
param: int $gfpoly  Field generator polynomial coefficients
param: int $fcr  first root of RS code generator polynomial, index form
param: int $prim  primitive element to generate polynomial roots
param: int $nroots RS code generator polynomial degree (number of roots)
param: int $pad  padding bytes at front of shortened block
return: array Array of RS values:<ul><li>mm = Bits per symbol;</li><li>nn = Symbols per block;</li><li>alpha_to = log lookup table array;</li><li>index_of = Antilog lookup table array;</li><li>genpoly = Generator polynomial array;</li><li>nroots = Number of generator;</li><li>roots = number of parity symbols;</li><li>fcr = First consecutive root, index form;</li><li>prim = Primitive element, index form;</li><li>iprim = prim-th root of 1, index form;</li><li>pad = Padding bytes in shortened block;</li><li>gfpoly</ul>.

encode_rs_char($rs, $data, $parity)   X-Ref
Encode a Reed-Solomon codec and returns the parity array

param: array $rs RS values
param: array $data data
param: array $parity parity
return: parity array