ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
QRcode Class Reference

Class to create QR-code arrays for TCPDF class. More...

+ Collaboration diagram for QRcode:

Public Member Functions

 __construct ($code, $eclevel='L')
 This is the class constructor. More...
 
 getBarcodeArray ()
 Returns a barcode array which is readable by TCPDF. More...
 

Protected Member Functions

 binarize ($frame)
 Convert the frame in binary form. More...
 
 encodeString ($string)
 Encode the input string to QR code. More...
 
 encodeMask ($mask)
 Encode mask. More...
 
 setFrameAt ($at, $val)
 Set frame value at specified position. More...
 
 getFrameAt ($at)
 Get frame value at specified position. More...
 
 getNextPosition ()
 Return the next frame position. More...
 
 init ($spec)
 Initialize code. More...
 
 getCode ()
 Return Reed-Solomon block code. More...
 
 writeFormatInformation ($width, &$frame, $mask, $level)
 Write Format Information on frame and returns the number of black bits. More...
 
 mask0 ($x, $y)
 mask0 More...
 
 mask1 ($x, $y)
 mask1 More...
 
 mask2 ($x, $y)
 mask2 More...
 
 mask3 ($x, $y)
 mask3 More...
 
 mask4 ($x, $y)
 mask4 More...
 
 mask5 ($x, $y)
 mask5 More...
 
 mask6 ($x, $y)
 mask6 More...
 
 mask7 ($x, $y)
 mask7 More...
 
 generateMaskNo ($maskNo, $width, $frame)
 Return bitmask. More...
 
 makeMaskNo ($maskNo, $width, $s, &$d, $maskGenOnly=false)
 makeMaskNo More...
 
 makeMask ($width, $frame, $maskNo, $level)
 makeMask More...
 
 calcN1N3 ($length)
 calcN1N3 More...
 
 evaluateSymbol ($width, $frame)
 evaluateSymbol More...
 
 mask ($width, $frame, $level)
 mask More...
 
 isdigitat ($str, $pos)
 Return true if the character at specified position is a number. More...
 
 isalnumat ($str, $pos)
 Return true if the character at specified position is an alphanumeric character. More...
 
 identifyMode ($pos)
 identifyMode More...
 
 eatNum ()
 eatNum More...
 
 eatAn ()
 eatAn More...
 
 eatKanji ()
 eatKanji More...
 
 eat8 ()
 eat8 More...
 
 splitString ()
 splitString More...
 
 toUpper ()
 toUpper More...
 
 newInputItem ($mode, $size, $data, $bstream=null)
 newInputItem More...
 
 encodeModeNum ($inputitem, $version)
 encodeModeNum More...
 
 encodeModeAn ($inputitem, $version)
 encodeModeAn More...
 
 encodeMode8 ($inputitem, $version)
 encodeMode8 More...
 
 encodeModeKanji ($inputitem, $version)
 encodeModeKanji More...
 
 encodeModeStructure ($inputitem)
 encodeModeStructure More...
 
 encodeBitStream ($inputitem, $version)
 encodeBitStream More...
 
 appendNewInputItem ($items, $mode, $size, $data)
 Append data to an input object. More...
 
 insertStructuredAppendHeader ($items, $size, $index, $parity)
 insertStructuredAppendHeader More...
 
 calcParity ($items)
 calcParity More...
 
 checkModeNum ($size, $data)
 checkModeNum More...
 
 lookAnTable ($c)
 Look up the alphabet-numeric convesion table (see JIS X0510:2004, pp.19). More...
 
 checkModeAn ($size, $data)
 checkModeAn More...
 
 estimateBitsModeNum ($size)
 estimateBitsModeNum More...
 
 estimateBitsModeAn ($size)
 estimateBitsModeAn More...
 
 estimateBitsMode8 ($size)
 estimateBitsMode8 More...
 
 estimateBitsModeKanji ($size)
 estimateBitsModeKanji More...
 
 checkModeKanji ($size, $data)
 checkModeKanji More...
 
 check ($mode, $size, $data)
 Validate the input data. More...
 
 estimateBitStreamSize ($items, $version)
 estimateBitStreamSize More...
 
 estimateVersion ($items)
 estimateVersion More...
 
 lengthOfCode ($mode, $version, $bits)
 lengthOfCode More...
 
 createBitStream ($items)
 createBitStream More...
 
 convertData ($items)
 convertData More...
 
 appendPaddingBit ($bstream)
 Append Padding Bit to bitstream. More...
 
 mergeBitStream ($items)
 mergeBitStream More...
 
 getBitStream ($items)
 Returns a stream of bits. More...
 
 getByteStream ($items)
 Pack all bit streams padding bits into a byte array. More...
 
 allocate ($setLength)
 Return an array with zeros. More...
 
 newFromNum ($bits, $num)
 Return new bitstream from number. More...
 
 newFromBytes ($size, $data)
 Return new bitstream from bytes. More...
 
 appendBitstream ($bitstream, $append)
 Append one bitstream to another. More...
 
 appendNum ($bitstream, $bits, $num)
 Append one bitstream created from number to another. More...
 
 appendBytes ($bitstream, $size, $data)
 Append one bitstream created from bytes to another. More...
 
 bitstreamToByte ($bstream)
 Convert bitstream to bytes. More...
 
 qrstrset ($srctab, $x, $y, $repl, $replLen=false)
 Replace a value on the array at the specified position. More...
 
 getDataLength ($version, $level)
 Return maximum data code length (bytes) for the version. More...
 
 getECCLength ($version, $level)
 Return maximum error correction code length (bytes) for the version. More...
 
 getWidth ($version)
 Return the width of the symbol for the version. More...
 
 getRemainder ($version)
 Return the numer of remainder bits. More...
 
 getMinimumVersion ($size, $level)
 Return a version number that satisfies the input code length. More...
 
 lengthIndicator ($mode, $version)
 Return the size of length indicator for the mode and version. More...
 
 maximumWords ($mode, $version)
 Return the maximum length for the mode and version. More...
 
 getEccSpec ($version, $level, $spec)
 Return an array of ECC specification. More...
 
 putAlignmentMarker ($frame, $ox, $oy)
 Put an alignment marker. More...
 
 putAlignmentPattern ($version, $frame, $width)
 Put an alignment pattern. More...
 
 getVersionPattern ($version)
 Return BCH encoded version information pattern that is used for the symbol of version 7 or greater. More...
 
 getFormatInfo ($mask, $level)
 Return BCH encoded format information pattern. More...
 
 putFinderPattern ($frame, $ox, $oy)
 Put a finder pattern. More...
 
 createFrame ($version)
 Return a copy of initialized frame. More...
 
 newFrame ($version)
 Set new frame for the specified version. More...
 
 rsBlockNum ($spec)
 Return block number 0. More...
 
 rsBlockNum1 ($spec)
 Return block number 1. More...
 
 rsDataCodes1 ($spec)
 Return data codes 1. More...
 
 rsEccCodes1 ($spec)
 Return ecc codes 1. More...
 
 rsBlockNum2 ($spec)
 Return block number 2. More...
 
 rsDataCodes2 ($spec)
 Return data codes 2. More...
 
 rsEccCodes2 ($spec)
 Return ecc codes 2. More...
 
 rsDataLength ($spec)
 Return data length. More...
 
 rsEccLength ($spec)
 Return ecc length. More...
 
 init_rs ($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)
 Initialize a Reed-Solomon codec and add it to existing rsitems. More...
 
 modnn ($rs, $x)
 modnn More...
 
 init_rs_char ($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)
 Initialize a Reed-Solomon codec and returns an array of values. More...
 
 encode_rs_char ($rs, $data, $parity)
 Encode a Reed-Solomon codec and returns the parity array. More...
 

Protected Attributes

 $barcode_array = array()
 Barcode array to be returned which is readable by TCPDF. More...
 
 $version = 0
 QR code version. More...
 
 $level = QR_ECLEVEL_L
 Levels of error correction. More...
 
 $hint = QR_MODE_8B
 Encoding mode. More...
 
 $casesensitive = true
 Boolean flag, if true the input string will be converted to uppercase. More...
 
 $structured = 0
 Structured QR code (not supported yet). More...
 
 $data
 Mask data. More...
 
 $width
 Width. More...
 
 $frame
 Frame. More...
 
 $x
 X position of bit. More...
 
 $y
 Y position of bit. More...
 
 $dir
 Direction. More...
 
 $bit
 Single bit value. More...
 
 $datacode = array()
 Data code. More...
 
 $ecccode = array()
 Error correction code. More...
 
 $blocks
 Blocks. More...
 
 $rsblocks = array()
 Reed-Solomon blocks. More...
 
 $count
 Counter. More...
 
 $dataLength
 Data length. More...
 
 $eccLength
 Error correction length. More...
 
 $b1
 Value b1. More...
 
 $runLength = array()
 Run length. More...
 
 $dataStr = ''
 Input data string. More...
 
 $items
 Input items. More...
 
 $rsitems = array()
 Reed-Solomon items. More...
 
 $frames = array()
 Array of frames. More...
 
 $anTable
 Alphabet-numeric convesion table. More...
 
 $capacity
 Array Table of the capacity of symbols. More...
 
 $lengthTableBits
 Array Length indicator. More...
 
 $eccTable
 Array Table of the error correction code (Reed-Solomon block). More...
 
 $alignmentPattern
 Array Positions of alignment patterns. More...
 
 $versionPattern
 Array Version information pattern (BCH coded). More...
 
 $formatInfo
 Array Format information. More...
 

Detailed Description

Class to create QR-code arrays for TCPDF class.

QR Code symbol is a 2D barcode that can be scanned by handy terminals such as a mobile phone with CCD. The capacity of QR Code is up to 7000 digits or 4000 characters, and has high robustness. This class supports QR Code model 2, described in JIS (Japanese Industrial Standards) X0510:2004 or ISO/IEC 18004. Currently the following features are not supported: ECI and FNC1 mode, Micro QR Code, QR Code model 1, Structured mode.

This class is derived from "PHP QR Code encoder" by Dominik Dzienia (http://phpqrcode.sourceforge.net/) based on "libqrencode C library 3.1.1." by Kentaro Fukuchi (http://megaui.net/fukuchi/works/qrencode/index.en.html), contains Reed-Solomon code written by Phil Karn, KA9Q. QR Code is registered trademark of DENSO WAVE INCORPORATED (http://www.denso-wave.com/qrcode/index-e.html). Please read comments on this class source file for full copyright and license information.

Definition at line 291 of file qrcode.php.

Constructor & Destructor Documentation

◆ __construct()

QRcode::__construct (   $code,
  $eclevel = 'L' 
)

This is the class constructor.

Creates a QRcode object

Parameters
$code(string) code to represent using QRcode
$eclevel(string) error level:
  • L : About 7% or less errors can be corrected.
  • M : About 15% or less errors can be corrected.
  • Q : About 25% or less errors can be corrected.
  • H : About 30% or less errors can be corrected.
Since
1.0.000

Definition at line 639 of file qrcode.php.

References $barcode_array, $code, $size, binarize(), data, and encodeString().

639  {
640  $barcode_array = array();
641  if ((is_null($code)) OR ($code == '\0') OR ($code == '')) {
642  return false;
643  }
644  // set error correction level
645  $this->level = array_search($eclevel, array('L', 'M', 'Q', 'H'));
646  if ($this->level === false) {
647  $this->level = QR_ECLEVEL_L;
648  }
649  if (($this->hint != QR_MODE_8B) AND ($this->hint != QR_MODE_KJ)) {
650  return false;
651  }
652  if (($this->version < 0) OR ($this->version > QRSPEC_VERSION_MAX)) {
653  return false;
654  }
655  $this->items = array();
656  $this->encodeString($code);
657  if (is_null($this->data)) {
658  return false;
659  }
660  $qrTab = $this->binarize($this->data);
661  $size = count($qrTab);
662  $barcode_array['num_rows'] = $size;
663  $barcode_array['num_cols'] = $size;
664  $barcode_array['bcode'] = array();
665  foreach ($qrTab as $line) {
666  $arrAdd = array();
667  foreach (str_split($line) as $char) {
668  $arrAdd[] = ($char=='1')?1:0;
669  }
670  $barcode_array['bcode'][] = $arrAdd;
671  }
672  $this->barcode_array = $barcode_array;
673  }
$size
Definition: RandomTest.php:84
$code
Definition: example_050.php:99
binarize($frame)
Convert the frame in binary form.
Definition: qrcode.php:689
encodeString($string)
Encode the input string to QR code.
Definition: qrcode.php:704
$this data['403_header']
$barcode_array
Barcode array to be returned which is readable by TCPDF.
Definition: qrcode.php:297
+ Here is the call graph for this function:

Member Function Documentation

◆ allocate()

QRcode::allocate (   $setLength)
protected

Return an array with zeros.

Parameters
$setLength(int) array size
Returns
array

Definition at line 2129 of file qrcode.php.

Referenced by newFromBytes(), and newFromNum().

2129  {
2130  return array_fill(0, $setLength, 0);
2131  }
+ Here is the caller graph for this function:

◆ appendBitstream()

QRcode::appendBitstream (   $bitstream,
  $append 
)
protected

Append one bitstream to another.

Parameters
$bitstream(array) original bitstream
$append(array) bitstream to append
Returns
array bitstream

Definition at line 2183 of file qrcode.php.

Referenced by appendBytes(), appendNum(), appendPaddingBit(), encodeBitStream(), and mergeBitStream().

2183  {
2184  if ((!is_array($append)) OR (count($append) == 0)) {
2185  return $bitstream;
2186  }
2187  if (count($bitstream) == 0) {
2188  return $append;
2189  }
2190  return array_values(array_merge($bitstream, $append));
2191  }
+ Here is the caller graph for this function:

◆ appendBytes()

QRcode::appendBytes (   $bitstream,
  $size,
  $data 
)
protected

Append one bitstream created from bytes to another.

Parameters
$bitstream(array) original bitstream
$size(int) size
$data(array) bytes
Returns
array bitstream

Definition at line 2215 of file qrcode.php.

References $data, $size, appendBitstream(), and newFromBytes().

Referenced by appendPaddingBit().

2215  {
2216  if ($size == 0) {
2217  return 0;
2218  }
2219  $b = $this->newFromBytes($size, $data);
2220  return $this->appendBitstream($bitstream, $b);
2221  }
$size
Definition: RandomTest.php:84
newFromBytes($size, $data)
Return new bitstream from bytes.
Definition: qrcode.php:2159
$data
Mask data.
Definition: qrcode.php:333
appendBitstream($bitstream, $append)
Append one bitstream to another.
Definition: qrcode.php:2183
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ appendNewInputItem()

QRcode::appendNewInputItem (   $items,
  $mode,
  $size,
  $data 
)
protected

Append data to an input object.

The data is copied and appended to the input object.

Parameters
$items(arrray) input items
$mode(int) encoding mode.
$size(int) size of data (byte).
$data(array) array of input data.
Returns
items

Definition at line 1696 of file qrcode.php.

References $data, $items, $size, and newInputItem().

Referenced by eat8(), eatAn(), eatKanji(), and eatNum().

1696  {
1697  $newitem = $this->newInputItem($mode, $size, $data);
1698  if (!empty($newitem)) {
1699  $items[] = $newitem;
1700  }
1701  return $items;
1702  }
$size
Definition: RandomTest.php:84
$items
Input items.
Definition: qrcode.php:443
$data
Mask data.
Definition: qrcode.php:333
newInputItem($mode, $size, $data, $bstream=null)
newInputItem
Definition: qrcode.php:1513
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ appendNum()

QRcode::appendNum (   $bitstream,
  $bits,
  $num 
)
protected

Append one bitstream created from number to another.

Parameters
$bitstream(array) original bitstream
$bits(int) number of bits
$num(int) number
Returns
array bitstream

Definition at line 2200 of file qrcode.php.

References appendBitstream(), and newFromNum().

Referenced by appendPaddingBit(), encodeMode8(), encodeModeAn(), encodeModeKanji(), encodeModeNum(), and encodeModeStructure().

2200  {
2201  if ($bits == 0) {
2202  return 0;
2203  }
2204  $b = $this->newFromNum($bits, $num);
2205  return $this->appendBitstream($bitstream, $b);
2206  }
newFromNum($bits, $num)
Return new bitstream from number.
Definition: qrcode.php:2139
appendBitstream($bitstream, $append)
Append one bitstream to another.
Definition: qrcode.php:2183
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ appendPaddingBit()

QRcode::appendPaddingBit (   $bstream)
protected

Append Padding Bit to bitstream.

Parameters
$bstream(array)
Returns
array bitstream

Definition at line 2055 of file qrcode.php.

References $i, appendBitstream(), appendBytes(), appendNum(), and getDataLength().

Referenced by getBitStream().

2055  {
2056  if (is_null($bstream)) {
2057  return null;
2058  }
2059  $bits = count($bstream);
2060  $maxwords = $this->getDataLength($this->version, $this->level);
2061  $maxbits = $maxwords * 8;
2062  if ($maxbits == $bits) {
2063  return $bstream;
2064  }
2065  if ($maxbits - $bits < 5) {
2066  return $this->appendNum($bstream, $maxbits - $bits, 0);
2067  }
2068  $bits += 4;
2069  $words = (int)(($bits + 7) / 8);
2070  $padding = array();
2071  $padding = $this->appendNum($padding, $words * 8 - $bits + 4, 0);
2072  $padlen = $maxwords - $words;
2073  if ($padlen > 0) {
2074  $padbuf = array();
2075  for ($i=0; $i<$padlen; ++$i) {
2076  $padbuf[$i] = ($i&1)?0x11:0xec;
2077  }
2078  $padding = $this->appendBytes($padding, $padlen, $padbuf);
2079  }
2080  return $this->appendBitstream($bstream, $padding);
2081  }
appendNum($bitstream, $bits, $num)
Append one bitstream created from number to another.
Definition: qrcode.php:2200
getDataLength($version, $level)
Return maximum data code length (bytes) for the version.
Definition: qrcode.php:2284
appendBytes($bitstream, $size, $data)
Append one bitstream created from bytes to another.
Definition: qrcode.php:2215
appendBitstream($bitstream, $append)
Append one bitstream to another.
Definition: qrcode.php:2183
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ binarize()

QRcode::binarize (   $frame)
protected

Convert the frame in binary form.

Parameters
$frame(array) array to binarize
Returns
array frame in binary form

Definition at line 689 of file qrcode.php.

References $frame, and $i.

Referenced by __construct().

689  {
690  $len = count($frame);
691  // the frame is square (width = height)
692  foreach ($frame as &$frameLine) {
693  for ($i=0; $i<$len; $i++) {
694  $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0';
695  }
696  }
697  return $frame;
698  }
$i
Definition: disco.tpl.php:19
$frame
Frame.
Definition: qrcode.php:347
+ Here is the caller graph for this function:

◆ bitstreamToByte()

QRcode::bitstreamToByte (   $bstream)
protected

Convert bitstream to bytes.

Parameters
$bstream(array) original bitstream
Returns
array of bytes

Definition at line 2228 of file qrcode.php.

References $data, $i, and $size.

Referenced by getByteStream().

2228  {
2229  if (is_null($bstream)) {
2230  return null;
2231  }
2232  $size = count($bstream);
2233  if ($size == 0) {
2234  return array();
2235  }
2236  $data = array_fill(0, (int)(($size + 7) / 8), 0);
2237  $bytes = (int)($size / 8);
2238  $p = 0;
2239  for ($i=0; $i<$bytes; $i++) {
2240  $v = 0;
2241  for ($j=0; $j<8; $j++) {
2242  $v = $v << 1;
2243  $v |= $bstream[$p];
2244  $p++;
2245  }
2246  $data[$i] = $v;
2247  }
2248  if ($size & 7) {
2249  $v = 0;
2250  for ($j=0; $j<($size & 7); $j++) {
2251  $v = $v << 1;
2252  $v |= $bstream[$p];
2253  $p++;
2254  }
2255  $data[$bytes] = $v;
2256  }
2257  return $data;
2258  }
$size
Definition: RandomTest.php:84
$data
Mask data.
Definition: qrcode.php:333
$i
Definition: disco.tpl.php:19
+ Here is the caller graph for this function:

◆ calcN1N3()

QRcode::calcN1N3 (   $length)
protected

calcN1N3

Parameters
$length(int)
Returns
int demerit

Definition at line 1127 of file qrcode.php.

References $i.

Referenced by evaluateSymbol().

1127  {
1128  $demerit = 0;
1129  for ($i=0; $i<$length; ++$i) {
1130  if ($this->runLength[$i] >= 5) {
1131  $demerit += (N1 + ($this->runLength[$i] - 5));
1132  }
1133  if ($i & 1) {
1134  if (($i >= 3) AND ($i < ($length-2)) AND ($this->runLength[$i] % 3 == 0)) {
1135  $fact = (int)($this->runLength[$i] / 3);
1136  if (($this->runLength[$i-2] == $fact)
1137  AND ($this->runLength[$i-1] == $fact)
1138  AND ($this->runLength[$i+1] == $fact)
1139  AND ($this->runLength[$i+2] == $fact)) {
1140  if (($this->runLength[$i-3] < 0) OR ($this->runLength[$i-3] >= (4 * $fact))) {
1141  $demerit += N3;
1142  } elseif ((($i+3) >= $length) OR ($this->runLength[$i+3] >= (4 * $fact))) {
1143  $demerit += N3;
1144  }
1145  }
1146  }
1147  }
1148  }
1149  return $demerit;
1150  }
$i
Definition: disco.tpl.php:19
+ Here is the caller graph for this function:

◆ calcParity()

QRcode::calcParity (   $items)
protected

calcParity

Parameters
$items(array)
Returns
int parity

Definition at line 1730 of file qrcode.php.

References $i, and $items.

1730  {
1731  $parity = 0;
1732  foreach ($items as $item) {
1733  if ($item['mode'] != QR_MODE_ST) {
1734  for ($i=$item['size']-1; $i>=0; --$i) {
1735  $parity ^= $item['data'][$i];
1736  }
1737  }
1738  }
1739  return $parity;
1740  }
$items
Input items.
Definition: qrcode.php:443
$i
Definition: disco.tpl.php:19

◆ check()

QRcode::check (   $mode,
  $size,
  $data 
)
protected

Validate the input data.

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

Definition at line 1859 of file qrcode.php.

References $data, $size, checkModeAn(), checkModeKanji(), and checkModeNum().

Referenced by newInputItem().

1859  {
1860  if ($size <= 0) {
1861  return false;
1862  }
1863  switch($mode) {
1864  case QR_MODE_NM: {
1865  return $this->checkModeNum($size, $data);
1866  }
1867  case QR_MODE_AN: {
1868  return $this->checkModeAn($size, $data);
1869  }
1870  case QR_MODE_KJ: {
1871  return $this->checkModeKanji($size, $data);
1872  }
1873  case QR_MODE_8B: {
1874  return true;
1875  }
1876  case QR_MODE_ST: {
1877  return true;
1878  }
1879  default: {
1880  break;
1881  }
1882  }
1883  return false;
1884  }
checkModeAn($size, $data)
checkModeAn
Definition: qrcode.php:1772
$size
Definition: RandomTest.php:84
checkModeNum($size, $data)
checkModeNum
Definition: qrcode.php:1748
checkModeKanji($size, $data)
checkModeKanji
Definition: qrcode.php:1839
$data
Mask data.
Definition: qrcode.php:333
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkModeAn()

QRcode::checkModeAn (   $size,
  $data 
)
protected

checkModeAn

Parameters
$size(int)
$data(array)
Returns
boolean true or false

Definition at line 1772 of file qrcode.php.

References $data, $i, $size, and lookAnTable().

Referenced by check().

1772  {
1773  for ($i=0; $i<$size; ++$i) {
1774  if ($this->lookAnTable(ord($data[$i])) == -1) {
1775  return false;
1776  }
1777  }
1778  return true;
1779  }
$size
Definition: RandomTest.php:84
lookAnTable($c)
Look up the alphabet-numeric convesion table (see JIS X0510:2004, pp.19).
Definition: qrcode.php:1762
$data
Mask data.
Definition: qrcode.php:333
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkModeKanji()

QRcode::checkModeKanji (   $size,
  $data 
)
protected

checkModeKanji

Parameters
$size(int)
$data(array)
Returns
boolean true or false

Definition at line 1839 of file qrcode.php.

References $data, $i, and $size.

Referenced by check().

1839  {
1840  if ($size & 1) {
1841  return false;
1842  }
1843  for ($i=0; $i<$size; $i+=2) {
1844  $val = (ord($data[$i]) << 8) | ord($data[$i+1]);
1845  if (($val < 0x8140) OR (($val > 0x9ffc) AND ($val < 0xe040)) OR ($val > 0xebbf)) {
1846  return false;
1847  }
1848  }
1849  return true;
1850  }
$size
Definition: RandomTest.php:84
$data
Mask data.
Definition: qrcode.php:333
$i
Definition: disco.tpl.php:19
+ Here is the caller graph for this function:

◆ checkModeNum()

QRcode::checkModeNum (   $size,
  $data 
)
protected

checkModeNum

Parameters
$size(int)
$data(array)
Returns
boolean true or false

Definition at line 1748 of file qrcode.php.

References $data, $i, and $size.

Referenced by check().

1748  {
1749  for ($i=0; $i<$size; ++$i) {
1750  if ((ord($data[$i]) < ord('0')) OR (ord($data[$i]) > ord('9'))){
1751  return false;
1752  }
1753  }
1754  return true;
1755  }
$size
Definition: RandomTest.php:84
$data
Mask data.
Definition: qrcode.php:333
$i
Definition: disco.tpl.php:19
+ Here is the caller graph for this function:

◆ convertData()

QRcode::convertData (   $items)
protected

convertData

Parameters
$items(array)
Returns
array items

Definition at line 2026 of file qrcode.php.

References $items, createBitStream(), estimateVersion(), and getMinimumVersion().

Referenced by mergeBitStream().

2026  {
2027  $ver = $this->estimateVersion($items);
2028  if ($ver > $this->version) {
2029  $this->version = $ver;
2030  }
2031  while (true) {
2032  $cbs = $this->createBitStream($items);
2033  $items = $cbs[0];
2034  $bits = $cbs[1];
2035  if ($bits < 0) {
2036  return -1;
2037  }
2038  $ver = $this->getMinimumVersion((int)(($bits + 7) / 8), $this->level);
2039  if ($ver < 0) {
2040  return -1;
2041  } elseif ($ver > $this->version) {
2042  $this->version = $ver;
2043  } else {
2044  break;
2045  }
2046  }
2047  return $items;
2048  }
estimateVersion($items)
estimateVersion
Definition: qrcode.php:1935
$items
Input items.
Definition: qrcode.php:443
createBitStream($items)
createBitStream
Definition: qrcode.php:2011
getMinimumVersion($size, $level)
Return a version number that satisfies the input code length.
Definition: qrcode.php:2322
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createBitStream()

QRcode::createBitStream (   $items)
protected

createBitStream

Parameters
$items(array)
Returns
array of items and total bits

Definition at line 2011 of file qrcode.php.

References $items, $key, $total, and encodeBitStream().

Referenced by convertData().

2011  {
2012  $total = 0;
2013  foreach ($items as $key => $item) {
2014  $items[$key] = $this->encodeBitStream($item, $this->version);
2015  $bits = count($items[$key]['bstream']);
2016  $total += $bits;
2017  }
2018  return array($items, $total);
2019  }
encodeBitStream($inputitem, $version)
encodeBitStream
Definition: qrcode.php:1641
$total
Definition: Utf8Test.php:87
$items
Input items.
Definition: qrcode.php:443
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createFrame()

QRcode::createFrame (   $version)
protected

Return a copy of initialized frame.

Parameters
$version(int) version
Returns
Array of unsigned char.

Definition at line 2530 of file qrcode.php.

References $frame, $i, $version, $width, $x, $y, getVersionPattern(), putAlignmentPattern(), putFinderPattern(), and qrstrset().

Referenced by newFrame().

2530  {
2531  $width = $this->capacity[$version][QRCAP_WIDTH];
2532  $frameLine = str_repeat ("\0", $width);
2533  $frame = array_fill(0, $width, $frameLine);
2534  // Finder pattern
2535  $frame = $this->putFinderPattern($frame, 0, 0);
2536  $frame = $this->putFinderPattern($frame, $width - 7, 0);
2537  $frame = $this->putFinderPattern($frame, 0, $width - 7);
2538  // Separator
2539  $yOffset = $width - 7;
2540  for ($y=0; $y < 7; ++$y) {
2541  $frame[$y][7] = "\xc0";
2542  $frame[$y][$width - 8] = "\xc0";
2543  $frame[$yOffset][7] = "\xc0";
2544  ++$yOffset;
2545  }
2546  $setPattern = str_repeat("\xc0", 8);
2547  $frame = $this->qrstrset($frame, 0, 7, $setPattern);
2548  $frame = $this->qrstrset($frame, $width-8, 7, $setPattern);
2549  $frame = $this->qrstrset($frame, 0, $width - 8, $setPattern);
2550  // Format info
2551  $setPattern = str_repeat("\x84", 9);
2552  $frame = $this->qrstrset($frame, 0, 8, $setPattern);
2553  $frame = $this->qrstrset($frame, $width - 8, 8, $setPattern, 8);
2554  $yOffset = $width - 8;
2555  for ($y=0; $y < 8; ++$y,++$yOffset) {
2556  $frame[$y][8] = "\x84";
2557  $frame[$yOffset][8] = "\x84";
2558  }
2559  // Timing pattern
2560  $wo = $width - 15;
2561  for ($i=1; $i < $wo; ++$i) {
2562  $frame[6][7+$i] = chr(0x90 | ($i & 1));
2563  $frame[7+$i][6] = chr(0x90 | ($i & 1));
2564  }
2565  // Alignment pattern
2567  // Version information
2568  if ($version >= 7) {
2569  $vinf = $this->getVersionPattern($version);
2570  $v = $vinf;
2571  for ($x=0; $x<6; ++$x) {
2572  for ($y=0; $y<3; ++$y) {
2573  $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1));
2574  $v = $v >> 1;
2575  }
2576  }
2577  $v = $vinf;
2578  for ($y=0; $y<6; ++$y) {
2579  for ($x=0; $x<3; ++$x) {
2580  $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1));
2581  $v = $v >> 1;
2582  }
2583  }
2584  }
2585  // and a little bit...
2586  $frame[$width - 8][8] = "\x81";
2587  return $frame;
2588  }
putFinderPattern($frame, $ox, $oy)
Put a finder pattern.
Definition: qrcode.php:2509
$version
QR code version.
Definition: qrcode.php:303
getVersionPattern($version)
Return BCH encoded version information pattern that is used for the symbol of version 7 or greater...
Definition: qrcode.php:2479
putAlignmentPattern($version, $frame, $width)
Put an alignment pattern.
Definition: qrcode.php:2439
$y
Y position of bit.
Definition: qrcode.php:359
qrstrset($srctab, $x, $y, $repl, $replLen=false)
Replace a value on the array at the specified position.
Definition: qrcode.php:2273
$width
Width.
Definition: qrcode.php:341
$i
Definition: disco.tpl.php:19
$frame
Frame.
Definition: qrcode.php:347
$x
X position of bit.
Definition: qrcode.php:353
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ eat8()

QRcode::eat8 ( )
protected

eat8

Returns
int run

Definition at line 1396 of file qrcode.php.

References appendNewInputItem(), estimateBitsMode8(), estimateBitsModeAn(), estimateBitsModeNum(), identifyMode(), isalnumat(), isdigitat(), and lengthIndicator().

Referenced by eatAn(), eatNum(), and splitString().

1396  {
1397  $la = $this->lengthIndicator(QR_MODE_AN, $this->version);
1398  $ln = $this->lengthIndicator(QR_MODE_NM, $this->version);
1399  $p = 1;
1400  $dataStrLen = strlen($this->dataStr);
1401  while($p < $dataStrLen) {
1402  $mode = $this->identifyMode($p);
1403  if ($mode == QR_MODE_KJ) {
1404  break;
1405  }
1406  if ($mode == QR_MODE_NM) {
1407  $q = $p;
1408  while($this->isdigitat($this->dataStr, $q)) {
1409  $q++;
1410  }
1411  $dif = $this->estimateBitsMode8($p) // + 4 + l8
1412  + $this->estimateBitsModeNum($q - $p) + 4 + $ln
1413  - $this->estimateBitsMode8($q); // - 4 - l8
1414  if ($dif < 0) {
1415  break;
1416  } else {
1417  $p = $q;
1418  }
1419  } elseif ($mode == QR_MODE_AN) {
1420  $q = $p;
1421  while($this->isalnumat($this->dataStr, $q)) {
1422  $q++;
1423  }
1424  $dif = $this->estimateBitsMode8($p) // + 4 + l8
1425  + $this->estimateBitsModeAn($q - $p) + 4 + $la
1426  - $this->estimateBitsMode8($q); // - 4 - l8
1427  if ($dif < 0) {
1428  break;
1429  } else {
1430  $p = $q;
1431  }
1432  } else {
1433  $p++;
1434  }
1435  }
1436  $run = $p;
1437  $this->items = $this->appendNewInputItem($this->items, QR_MODE_8B, $run, str_split($this->dataStr));
1438  return $run;
1439  }
estimateBitsModeAn($size)
estimateBitsModeAn
Definition: qrcode.php:1807
isdigitat($str, $pos)
Return true if the character at specified position is a number.
Definition: qrcode.php:1262
estimateBitsMode8($size)
estimateBitsMode8
Definition: qrcode.php:1820
appendNewInputItem($items, $mode, $size, $data)
Append data to an input object.
Definition: qrcode.php:1696
isalnumat($str, $pos)
Return true if the character at specified position is an alphanumeric character.
Definition: qrcode.php:1275
estimateBitsModeNum($size)
estimateBitsModeNum
Definition: qrcode.php:1786
identifyMode($pos)
identifyMode
Definition: qrcode.php:1287
lengthIndicator($mode, $version)
Return the size of length indicator for the mode and version.
Definition: qrcode.php:2339
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ eatAn()

QRcode::eatAn ( )
protected

eatAn

Returns
int run

Definition at line 1344 of file qrcode.php.

References appendNewInputItem(), eat8(), estimateBitsMode8(), estimateBitsModeAn(), estimateBitsModeNum(), isalnumat(), isdigitat(), and lengthIndicator().

Referenced by eatNum(), and splitString().

1344  {
1345  $la = $this->lengthIndicator(QR_MODE_AN, $this->version);
1346  $ln = $this->lengthIndicator(QR_MODE_NM, $this->version);
1347  $p =1 ;
1348  while($this->isalnumat($this->dataStr, $p)) {
1349  if ($this->isdigitat($this->dataStr, $p)) {
1350  $q = $p;
1351  while($this->isdigitat($this->dataStr, $q)) {
1352  $q++;
1353  }
1354  $dif = $this->estimateBitsModeAn($p) // + 4 + la
1355  + $this->estimateBitsModeNum($q - $p) + 4 + $ln
1356  - $this->estimateBitsModeAn($q); // - 4 - la
1357  if ($dif < 0) {
1358  break;
1359  } else {
1360  $p = $q;
1361  }
1362  } else {
1363  $p++;
1364  }
1365  }
1366  $run = $p;
1367  if (!$this->isalnumat($this->dataStr, $p)) {
1368  $dif = $this->estimateBitsModeAn($run) + 4 + $la
1369  + $this->estimateBitsMode8(1) // + 4 + l8
1370  - $this->estimateBitsMode8($run + 1); // - 4 - l8
1371  if ($dif > 0) {
1372  return $this->eat8();
1373  }
1374  }
1375  $this->items = $this->appendNewInputItem($this->items, QR_MODE_AN, $run, str_split($this->dataStr));
1376  return $run;
1377  }
estimateBitsModeAn($size)
estimateBitsModeAn
Definition: qrcode.php:1807
isdigitat($str, $pos)
Return true if the character at specified position is a number.
Definition: qrcode.php:1262
eat8()
eat8
Definition: qrcode.php:1396
estimateBitsMode8($size)
estimateBitsMode8
Definition: qrcode.php:1820
appendNewInputItem($items, $mode, $size, $data)
Append data to an input object.
Definition: qrcode.php:1696
isalnumat($str, $pos)
Return true if the character at specified position is an alphanumeric character.
Definition: qrcode.php:1275
estimateBitsModeNum($size)
estimateBitsModeNum
Definition: qrcode.php:1786
lengthIndicator($mode, $version)
Return the size of length indicator for the mode and version.
Definition: qrcode.php:2339
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ eatKanji()

QRcode::eatKanji ( )
protected

eatKanji

Returns
int run

Definition at line 1383 of file qrcode.php.

References appendNewInputItem(), and identifyMode().

Referenced by splitString().

1383  {
1384  $p = 0;
1385  while($this->identifyMode($p) == QR_MODE_KJ) {
1386  $p += 2;
1387  }
1388  $this->items = $this->appendNewInputItem($this->items, QR_MODE_KJ, $p, str_split($this->dataStr));
1389  return $run;
1390  }
appendNewInputItem($items, $mode, $size, $data)
Append data to an input object.
Definition: qrcode.php:1696
identifyMode($pos)
identifyMode
Definition: qrcode.php:1287
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ eatNum()

QRcode::eatNum ( )
protected

eatNum

Returns
int run

Definition at line 1312 of file qrcode.php.

References appendNewInputItem(), eat8(), eatAn(), estimateBitsMode8(), estimateBitsModeAn(), estimateBitsModeNum(), identifyMode(), isdigitat(), and lengthIndicator().

Referenced by splitString().

1312  {
1313  $ln = $this->lengthIndicator(QR_MODE_NM, $this->version);
1314  $p = 0;
1315  while($this->isdigitat($this->dataStr, $p)) {
1316  $p++;
1317  }
1318  $run = $p;
1319  $mode = $this->identifyMode($p);
1320  if ($mode == QR_MODE_8B) {
1321  $dif = $this->estimateBitsModeNum($run) + 4 + $ln
1322  + $this->estimateBitsMode8(1) // + 4 + l8
1323  - $this->estimateBitsMode8($run + 1); // - 4 - l8
1324  if ($dif > 0) {
1325  return $this->eat8();
1326  }
1327  }
1328  if ($mode == QR_MODE_AN) {
1329  $dif = $this->estimateBitsModeNum($run) + 4 + $ln
1330  + $this->estimateBitsModeAn(1) // + 4 + la
1331  - $this->estimateBitsModeAn($run + 1);// - 4 - la
1332  if ($dif > 0) {
1333  return $this->eatAn();
1334  }
1335  }
1336  $this->items = $this->appendNewInputItem($this->items, QR_MODE_NM, $run, str_split($this->dataStr));
1337  return $run;
1338  }
estimateBitsModeAn($size)
estimateBitsModeAn
Definition: qrcode.php:1807
eatAn()
eatAn
Definition: qrcode.php:1344
isdigitat($str, $pos)
Return true if the character at specified position is a number.
Definition: qrcode.php:1262
eat8()
eat8
Definition: qrcode.php:1396
estimateBitsMode8($size)
estimateBitsMode8
Definition: qrcode.php:1820
appendNewInputItem($items, $mode, $size, $data)
Append data to an input object.
Definition: qrcode.php:1696
estimateBitsModeNum($size)
estimateBitsModeNum
Definition: qrcode.php:1786
identifyMode($pos)
identifyMode
Definition: qrcode.php:1287
lengthIndicator($mode, $version)
Return the size of length indicator for the mode and version.
Definition: qrcode.php:2339
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encode_rs_char()

QRcode::encode_rs_char (   $rs,
  $data,
  $parity 
)
protected

Encode a Reed-Solomon codec and returns the parity array.

Parameters
$rs(array) RS values
$data(array) data
$parity(array) parity
Returns
parity array

Definition at line 2828 of file qrcode.php.

References $data, $i, and modnn().

Referenced by init().

2828  {
2829  $MM =& $rs['mm']; // bits per symbol
2830  $NN =& $rs['nn']; // the total number of symbols in a RS block
2831  $ALPHA_TO =& $rs['alpha_to']; // the address of an array of NN elements to convert Galois field elements in index (log) form to polynomial form
2832  $INDEX_OF =& $rs['index_of']; // the address of an array of NN elements to convert Galois field elements in polynomial form to index (log) form
2833  $GENPOLY =& $rs['genpoly']; // an array of NROOTS+1 elements containing the generator polynomial in index form
2834  $NROOTS =& $rs['nroots']; // the number of roots in the RS code generator polynomial, which is the same as the number of parity symbols in a block
2835  $FCR =& $rs['fcr']; // first consecutive root, index form
2836  $PRIM =& $rs['prim']; // primitive element, index form
2837  $IPRIM =& $rs['iprim']; // prim-th root of 1, index form
2838  $PAD =& $rs['pad']; // the number of pad symbols in a block
2839  $A0 =& $NN;
2840  $parity = array_fill(0, $NROOTS, 0);
2841  for ($i=0; $i < ($NN - $NROOTS - $PAD); $i++) {
2842  $feedback = $INDEX_OF[$data[$i] ^ $parity[0]];
2843  if ($feedback != $A0) {
2844  // feedback term is non-zero
2845  // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must
2846  // always be for the polynomials constructed by init_rs()
2847  $feedback = $this->modnn($rs, $NN - $GENPOLY[$NROOTS] + $feedback);
2848  for ($j=1; $j < $NROOTS; ++$j) {
2849  $parity[$j] ^= $ALPHA_TO[$this->modnn($rs, $feedback + $GENPOLY[($NROOTS - $j)])];
2850  }
2851  }
2852  // Shift
2853  array_shift($parity);
2854  if ($feedback != $A0) {
2855  array_push($parity, $ALPHA_TO[$this->modnn($rs, $feedback + $GENPOLY[0])]);
2856  } else {
2857  array_push($parity, 0);
2858  }
2859  }
2860  return $parity;
2861  }
modnn($rs, $x)
modnn
Definition: qrcode.php:2726
$data
Mask data.
Definition: qrcode.php:333
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encodeBitStream()

QRcode::encodeBitStream (   $inputitem,
  $version 
)
protected

encodeBitStream

Parameters
$inputitem(array)
$version(int)
Returns
array input item

Definition at line 1641 of file qrcode.php.

References $version, appendBitstream(), encodeMode8(), encodeModeAn(), encodeModeKanji(), encodeModeNum(), encodeModeStructure(), maximumWords(), and newInputItem().

Referenced by createBitStream().

1641  {
1642  $inputitem['bstream'] = array();
1643  $words = $this->maximumWords($inputitem['mode'], $version);
1644  if ($inputitem['size'] > $words) {
1645  $st1 = $this->newInputItem($inputitem['mode'], $words, $inputitem['data']);
1646  $st2 = $this->newInputItem($inputitem['mode'], $inputitem['size'] - $words, array_slice($inputitem['data'], $words));
1647  $st1 = $this->encodeBitStream($st1, $version);
1648  $st2 = $this->encodeBitStream($st2, $version);
1649  $inputitem['bstream'] = array();
1650  $inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st1['bstream']);
1651  $inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st2['bstream']);
1652  } else {
1653  switch($inputitem['mode']) {
1654  case QR_MODE_NM: {
1655  $inputitem = $this->encodeModeNum($inputitem, $version);
1656  break;
1657  }
1658  case QR_MODE_AN: {
1659  $inputitem = $this->encodeModeAn($inputitem, $version);
1660  break;
1661  }
1662  case QR_MODE_8B: {
1663  $inputitem = $this->encodeMode8($inputitem, $version);
1664  break;
1665  }
1666  case QR_MODE_KJ: {
1667  $inputitem = $this->encodeModeKanji($inputitem, $version);
1668  break;
1669  }
1670  case QR_MODE_ST: {
1671  $inputitem = $this->encodeModeStructure($inputitem);
1672  break;
1673  }
1674  default: {
1675  break;
1676  }
1677  }
1678  }
1679  return $inputitem;
1680  }
encodeModeKanji($inputitem, $version)
encodeModeKanji
Definition: qrcode.php:1603
maximumWords($mode, $version)
Return the maximum length for the mode and version.
Definition: qrcode.php:2359
$version
QR code version.
Definition: qrcode.php:303
encodeModeAn($inputitem, $version)
encodeModeAn
Definition: qrcode.php:1564
encodeBitStream($inputitem, $version)
encodeBitStream
Definition: qrcode.php:1641
encodeModeStructure($inputitem)
encodeModeStructure
Definition: qrcode.php:1626
appendBitstream($bitstream, $append)
Append one bitstream to another.
Definition: qrcode.php:2183
encodeModeNum($inputitem, $version)
encodeModeNum
Definition: qrcode.php:1535
encodeMode8($inputitem, $version)
encodeMode8
Definition: qrcode.php:1587
newInputItem($mode, $size, $data, $bstream=null)
newInputItem
Definition: qrcode.php:1513
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encodeMask()

QRcode::encodeMask (   $mask)
protected

Encode mask.

Parameters
$mask(int) masking mode

Definition at line 720 of file qrcode.php.

References $bit, $code, $eccLength, $i, $mask, $ret, data, getByteStream(), getCode(), getEccSpec(), getNextPosition(), getRemainder(), getWidth(), init(), makeMask(), mask(), newFrame(), rsBlockNum(), rsBlockNum1(), rsDataLength(), rsEccLength(), and setFrameAt().

Referenced by encodeString().

720  {
721  $spec = array(0, 0, 0, 0, 0);
722  $this->datacode = $this->getByteStream($this->items);
723 
724  if (is_null($this->datacode)) {
725  return NULL;
726  }
727  $spec = $this->getEccSpec($this->version, $this->level, $spec);
728  $this->b1 = $this->rsBlockNum1($spec);
729  $this->dataLength = $this->rsDataLength($spec);
730  $this->eccLength = $this->rsEccLength($spec);
731  $this->ecccode = array_fill(0, $this->eccLength, 0);
732  $this->blocks = $this->rsBlockNum($spec);
733  $ret = $this->init($spec);
734  if ($ret < 0) {
735  return NULL;
736  }
737  $this->count = 0;
738  $this->width = $this->getWidth($this->version);
739  $this->frame = $this->newFrame($this->version);
740  $this->x = $this->width - 1;
741  $this->y = $this->width - 1;
742  $this->dir = -1;
743  $this->bit = -1;
744  // inteleaved data and ecc codes
745  for ($i=0; $i < ($this->dataLength + $this->eccLength); $i++) {
746  $code = $this->getCode();
747  $bit = 0x80;
748  for ($j=0; $j<8; $j++) {
749  $addr = $this->getNextPosition();
750  $this->setFrameAt($addr, 0x02 | (($bit & $code) != 0));
751  $bit = $bit >> 1;
752  }
753  }
754  // remainder bits
755  $j = $this->getRemainder($this->version);
756  for ($i=0; $i<$j; $i++) {
757  $addr = $this->getNextPosition();
758  $this->setFrameAt($addr, 0x02);
759  }
760  // masking
761  $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0);
762  if ($mask < 0) {
763  if (QR_FIND_BEST_MASK) {
764  $masked = $this->mask($this->width, $this->frame, $this->level);
765  } else {
766  $masked = $this->makeMask($this->width, $this->frame, (intval(QR_DEFAULT_MASK) % 8), $this->level);
767  }
768  } else {
769  $masked = $this->makeMask($this->width, $this->frame, $mask, $this->level);
770  }
771  if ($masked == NULL) {
772  return NULL;
773  }
774  $this->data = $masked;
775  }
$bit
Single bit value.
Definition: qrcode.php:371
getRemainder($version)
Return the numer of remainder bits.
Definition: qrcode.php:2312
rsDataLength($spec)
Return data length.
Definition: qrcode.php:2676
getEccSpec($version, $level, $spec)
Return an array of ECC specification.
Definition: qrcode.php:2385
setFrameAt($at, $val)
Set frame value at specified position.
Definition: qrcode.php:786
$code
Definition: example_050.php:99
getWidth($version)
Return the width of the symbol for the version.
Definition: qrcode.php:2303
rsBlockNum1($spec)
Return block number 1.
Definition: qrcode.php:2622
newFrame($version)
Set new frame for the specified version.
Definition: qrcode.php:2595
makeMask($width, $frame, $maskNo, $level)
makeMask
Definition: qrcode.php:1115
getCode()
Return Reed-Solomon block code.
Definition: qrcode.php:910
$mask
Definition: example_042.php:90
getNextPosition()
Return the next frame position.
Definition: qrcode.php:803
getByteStream($items)
Pack all bit streams padding bits into a byte array.
Definition: qrcode.php:2115
rsEccLength($spec)
Return ecc length.
Definition: qrcode.php:2685
rsBlockNum($spec)
Return block number 0.
Definition: qrcode.php:2613
$this data['403_header']
$ret
Definition: parser.php:6
$i
Definition: disco.tpl.php:19
init($spec)
Initialize code.
Definition: qrcode.php:859
mask($width, $frame, $level)
mask
Definition: qrcode.php:1220
$eccLength
Error correction length.
Definition: qrcode.php:415
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encodeMode8()

QRcode::encodeMode8 (   $inputitem,
  $version 
)
protected

encodeMode8

Parameters
$inputitem(array)
$version(int)
Returns
array input item

Definition at line 1587 of file qrcode.php.

References $i, $version, appendNum(), and lengthIndicator().

Referenced by encodeBitStream().

1587  {
1588  $inputitem['bstream'] = array();
1589  $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x4);
1590  $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_8B, $version), $inputitem['size']);
1591  for ($i=0; $i < $inputitem['size']; ++$i) {
1592  $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 8, ord($inputitem['data'][$i]));
1593  }
1594  return $inputitem;
1595  }
$version
QR code version.
Definition: qrcode.php:303
appendNum($bitstream, $bits, $num)
Append one bitstream created from number to another.
Definition: qrcode.php:2200
$i
Definition: disco.tpl.php:19
lengthIndicator($mode, $version)
Return the size of length indicator for the mode and version.
Definition: qrcode.php:2339
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encodeModeAn()

QRcode::encodeModeAn (   $inputitem,
  $version 
)
protected

encodeModeAn

Parameters
$inputitem(array)
$version(int)
Returns
array input item

Definition at line 1564 of file qrcode.php.

References $i, $version, appendNum(), lengthIndicator(), and lookAnTable().

Referenced by encodeBitStream().

1564  {
1565  $words = (int)($inputitem['size'] / 2);
1566  $inputitem['bstream'] = array();
1567  $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x02);
1568  $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_AN, $version), $inputitem['size']);
1569  for ($i=0; $i < $words; ++$i) {
1570  $val = (int)($this->lookAnTable(ord($inputitem['data'][$i*2])) * 45);
1571  $val += (int)($this->lookAnTable(ord($inputitem['data'][($i*2)+1])));
1572  $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 11, $val);
1573  }
1574  if ($inputitem['size'] & 1) {
1575  $val = $this->lookAnTable(ord($inputitem['data'][($words * 2)]));
1576  $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 6, $val);
1577  }
1578  return $inputitem;
1579  }
$version
QR code version.
Definition: qrcode.php:303
appendNum($bitstream, $bits, $num)
Append one bitstream created from number to another.
Definition: qrcode.php:2200
lookAnTable($c)
Look up the alphabet-numeric convesion table (see JIS X0510:2004, pp.19).
Definition: qrcode.php:1762
$i
Definition: disco.tpl.php:19
lengthIndicator($mode, $version)
Return the size of length indicator for the mode and version.
Definition: qrcode.php:2339
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encodeModeKanji()

QRcode::encodeModeKanji (   $inputitem,
  $version 
)
protected

encodeModeKanji

Parameters
$inputitem(array)
$version(int)
Returns
array input item

Definition at line 1603 of file qrcode.php.

References $h, $i, $version, appendNum(), and lengthIndicator().

Referenced by encodeBitStream().

1603  {
1604  $inputitem['bstream'] = array();
1605  $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x8);
1606  $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_KJ, $version), (int)($inputitem['size'] / 2));
1607  for ($i=0; $i<$inputitem['size']; $i+=2) {
1608  $val = (ord($inputitem['data'][$i]) << 8) | ord($inputitem['data'][$i+1]);
1609  if ($val <= 0x9ffc) {
1610  $val -= 0x8140;
1611  } else {
1612  $val -= 0xc140;
1613  }
1614  $h = ($val >> 8) * 0xc0;
1615  $val = ($val & 0xff) + $h;
1616  $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 13, $val);
1617  }
1618  return $inputitem;
1619  }
$version
QR code version.
Definition: qrcode.php:303
$h
appendNum($bitstream, $bits, $num)
Append one bitstream created from number to another.
Definition: qrcode.php:2200
$i
Definition: disco.tpl.php:19
lengthIndicator($mode, $version)
Return the size of length indicator for the mode and version.
Definition: qrcode.php:2339
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encodeModeNum()

QRcode::encodeModeNum (   $inputitem,
  $version 
)
protected

encodeModeNum

Parameters
$inputitem(array)
$version(int)
Returns
array input item

Definition at line 1535 of file qrcode.php.

References $i, $version, appendNum(), and lengthIndicator().

Referenced by encodeBitStream().

1535  {
1536  $words = (int)($inputitem['size'] / 3);
1537  $inputitem['bstream'] = array();
1538  $val = 0x1;
1539  $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val);
1540  $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_NM, $version), $inputitem['size']);
1541  for ($i=0; $i < $words; ++$i) {
1542  $val = (ord($inputitem['data'][$i*3 ]) - ord('0')) * 100;
1543  $val += (ord($inputitem['data'][$i*3+1]) - ord('0')) * 10;
1544  $val += (ord($inputitem['data'][$i*3+2]) - ord('0'));
1545  $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 10, $val);
1546  }
1547  if ($inputitem['size'] - $words * 3 == 1) {
1548  $val = ord($inputitem['data'][$words*3]) - ord('0');
1549  $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val);
1550  } elseif (($inputitem['size'] - ($words * 3)) == 2) {
1551  $val = (ord($inputitem['data'][$words*3 ]) - ord('0')) * 10;
1552  $val += (ord($inputitem['data'][$words*3+1]) - ord('0'));
1553  $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 7, $val);
1554  }
1555  return $inputitem;
1556  }
$version
QR code version.
Definition: qrcode.php:303
appendNum($bitstream, $bits, $num)
Append one bitstream created from number to another.
Definition: qrcode.php:2200
$i
Definition: disco.tpl.php:19
lengthIndicator($mode, $version)
Return the size of length indicator for the mode and version.
Definition: qrcode.php:2339
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encodeModeStructure()

QRcode::encodeModeStructure (   $inputitem)
protected

encodeModeStructure

Parameters
$inputitem(array)
Returns
array input item

Definition at line 1626 of file qrcode.php.

References appendNum().

Referenced by encodeBitStream().

1626  {
1627  $inputitem['bstream'] = array();
1628  $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x03);
1629  $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, ord($inputitem['data'][1]) - 1);
1630  $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, ord($inputitem['data'][0]) - 1);
1631  $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 8, ord($inputitem['data'][2]));
1632  return $inputitem;
1633  }
appendNum($bitstream, $bits, $num)
Append one bitstream created from number to another.
Definition: qrcode.php:2200
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encodeString()

QRcode::encodeString (   $string)
protected

Encode the input string to QR code.

Parameters
$string(string) input string to encode

Definition at line 704 of file qrcode.php.

References $ret, encodeMask(), splitString(), and toUpper().

Referenced by __construct().

704  {
705  $this->dataStr = $string;
706  if (!$this->casesensitive) {
707  $this->toUpper();
708  }
709  $ret = $this->splitString();
710  if ($ret < 0) {
711  return NULL;
712  }
713  $this->encodeMask(-1);
714  }
encodeMask($mask)
Encode mask.
Definition: qrcode.php:720
splitString()
splitString
Definition: qrcode.php:1445
toUpper()
toUpper
Definition: qrcode.php:1484
$ret
Definition: parser.php:6
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ estimateBitsMode8()

QRcode::estimateBitsMode8 (   $size)
protected

estimateBitsMode8

Parameters
$size(int)
Returns
int number of bits

Definition at line 1820 of file qrcode.php.

References $size.

Referenced by eat8(), eatAn(), eatNum(), and estimateBitStreamSize().

1820  {
1821  return (int)($size * 8);
1822  }
$size
Definition: RandomTest.php:84
+ Here is the caller graph for this function:

◆ estimateBitsModeAn()

QRcode::estimateBitsModeAn (   $size)
protected

estimateBitsModeAn

Parameters
$size(int)
Returns
int number of bits

Definition at line 1807 of file qrcode.php.

References $size.

Referenced by eat8(), eatAn(), eatNum(), and estimateBitStreamSize().

1807  {
1808  $bits = (int)($size * 5.5); // (size / 2 ) * 11
1809  if ($size & 1) {
1810  $bits += 6;
1811  }
1812  return $bits;
1813  }
$size
Definition: RandomTest.php:84
+ Here is the caller graph for this function:

◆ estimateBitsModeKanji()

QRcode::estimateBitsModeKanji (   $size)
protected

estimateBitsModeKanji

Parameters
$size(int)
Returns
int number of bits

Definition at line 1829 of file qrcode.php.

References $size.

Referenced by estimateBitStreamSize().

1829  {
1830  return (int)($size * 6.5); // (size / 2 ) * 13
1831  }
$size
Definition: RandomTest.php:84
+ Here is the caller graph for this function:

◆ estimateBitsModeNum()

QRcode::estimateBitsModeNum (   $size)
protected

estimateBitsModeNum

Parameters
$size(int)
Returns
int number of bits

Definition at line 1786 of file qrcode.php.

References $size, and $w.

Referenced by eat8(), eatAn(), eatNum(), and estimateBitStreamSize().

1786  {
1787  $w = (int)($size / 3);
1788  $bits = ($w * 10);
1789  switch($size - ($w * 3)) {
1790  case 1: {
1791  $bits += 4;
1792  break;
1793  }
1794  case 2: {
1795  $bits += 7;
1796  break;
1797  }
1798  }
1799  return $bits;
1800  }
$size
Definition: RandomTest.php:84
$w
+ Here is the caller graph for this function:

◆ estimateBitStreamSize()

QRcode::estimateBitStreamSize (   $items,
  $version 
)
protected

estimateBitStreamSize

Parameters
$items(array)
$version(int)
Returns
int bits

Definition at line 1892 of file qrcode.php.

References $items, $l, $m, $version, estimateBitsMode8(), estimateBitsModeAn(), estimateBitsModeKanji(), estimateBitsModeNum(), and lengthIndicator().

Referenced by estimateVersion().

1892  {
1893  $bits = 0;
1894  if ($version == 0) {
1895  $version = 1;
1896  }
1897  foreach ($items as $item) {
1898  switch($item['mode']) {
1899  case QR_MODE_NM: {
1900  $bits = $this->estimateBitsModeNum($item['size']);
1901  break;
1902  }
1903  case QR_MODE_AN: {
1904  $bits = $this->estimateBitsModeAn($item['size']);
1905  break;
1906  }
1907  case QR_MODE_8B: {
1908  $bits = $this->estimateBitsMode8($item['size']);
1909  break;
1910  }
1911  case QR_MODE_KJ: {
1912  $bits = $this->estimateBitsModeKanji($item['size']);
1913  break;
1914  }
1915  case QR_MODE_ST: {
1916  return STRUCTURE_HEADER_BITS;
1917  }
1918  default: {
1919  return 0;
1920  }
1921  }
1922  $l = $this->lengthIndicator($item['mode'], $version);
1923  $m = 1 << $l;
1924  $num = (int)(($item['size'] + $m - 1) / $m);
1925  $bits += $num * (4 + $l);
1926  }
1927  return $bits;
1928  }
estimateBitsModeAn($size)
estimateBitsModeAn
Definition: qrcode.php:1807
estimateBitsModeKanji($size)
estimateBitsModeKanji
Definition: qrcode.php:1829
$version
QR code version.
Definition: qrcode.php:303
estimateBitsMode8($size)
estimateBitsMode8
Definition: qrcode.php:1820
$items
Input items.
Definition: qrcode.php:443
estimateBitsModeNum($size)
estimateBitsModeNum
Definition: qrcode.php:1786
global $l
Definition: afr.php:30
lengthIndicator($mode, $version)
Return the size of length indicator for the mode and version.
Definition: qrcode.php:2339
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ estimateVersion()

QRcode::estimateVersion (   $items)
protected

estimateVersion

Parameters
$items(array)
Returns
int version

Definition at line 1935 of file qrcode.php.

References $items, $version, estimateBitStreamSize(), and getMinimumVersion().

Referenced by convertData().

1935  {
1936  $version = 0;
1937  $prev = 0;
1938  do {
1939  $prev = $version;
1940  $bits = $this->estimateBitStreamSize($items, $prev);
1941  $version = $this->getMinimumVersion((int)(($bits + 7) / 8), $this->level);
1942  if ($version < 0) {
1943  return -1;
1944  }
1945  } while ($version > $prev);
1946  return $version;
1947  }
$version
QR code version.
Definition: qrcode.php:303
estimateBitStreamSize($items, $version)
estimateBitStreamSize
Definition: qrcode.php:1892
$items
Input items.
Definition: qrcode.php:443
getMinimumVersion($size, $level)
Return a version number that satisfies the input code length.
Definition: qrcode.php:2322
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ evaluateSymbol()

QRcode::evaluateSymbol (   $width,
  $frame 
)
protected

evaluateSymbol

Parameters
$width(int)
$frame(array)
Returns
int demerit

Definition at line 1158 of file qrcode.php.

References $frame, $width, $x, $y, and calcN1N3().

Referenced by mask().

1158  {
1159  $head = 0;
1160  $demerit = 0;
1161  for ($y=0; $y<$width; ++$y) {
1162  $head = 0;
1163  $this->runLength[0] = 1;
1164  $frameY = $frame[$y];
1165  if ($y > 0) {
1166  $frameYM = $frame[$y-1];
1167  }
1168  for ($x=0; $x<$width; ++$x) {
1169  if (($x > 0) AND ($y > 0)) {
1170  $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]);
1171  $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]);
1172  if (($b22 | ($w22 ^ 1)) & 1) {
1173  $demerit += N2;
1174  }
1175  }
1176  if (($x == 0) AND (ord($frameY[$x]) & 1)) {
1177  $this->runLength[0] = -1;
1178  $head = 1;
1179  $this->runLength[$head] = 1;
1180  } elseif ($x > 0) {
1181  if ((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) {
1182  $head++;
1183  $this->runLength[$head] = 1;
1184  } else {
1185  $this->runLength[$head]++;
1186  }
1187  }
1188  }
1189  $demerit += $this->calcN1N3($head+1);
1190  }
1191  for ($x=0; $x<$width; ++$x) {
1192  $head = 0;
1193  $this->runLength[0] = 1;
1194  for ($y=0; $y<$width; ++$y) {
1195  if (($y == 0) AND (ord($frame[$y][$x]) & 1)) {
1196  $this->runLength[0] = -1;
1197  $head = 1;
1198  $this->runLength[$head] = 1;
1199  } elseif ($y > 0) {
1200  if ((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) {
1201  $head++;
1202  $this->runLength[$head] = 1;
1203  } else {
1204  $this->runLength[$head]++;
1205  }
1206  }
1207  }
1208  $demerit += $this->calcN1N3($head+1);
1209  }
1210  return $demerit;
1211  }
calcN1N3($length)
calcN1N3
Definition: qrcode.php:1127
$y
Y position of bit.
Definition: qrcode.php:359
$width
Width.
Definition: qrcode.php:341
$frame
Frame.
Definition: qrcode.php:347
$x
X position of bit.
Definition: qrcode.php:353
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ generateMaskNo()

QRcode::generateMaskNo (   $maskNo,
  $width,
  $frame 
)
protected

Return bitmask.

Parameters
$maskNo(int) mask number
$width(int) width
$frame(array) frame
Returns
array bitmask

Definition at line 1064 of file qrcode.php.

References $frame, $width, $x, and $y.

Referenced by makeMaskNo().

1064  {
1065  $bitMask = array_fill(0, $width, array_fill(0, $width, 0));
1066  for ($y=0; $y<$width; ++$y) {
1067  for ($x=0; $x<$width; ++$x) {
1068  if (ord($frame[$y][$x]) & 0x80) {
1069  $bitMask[$y][$x] = 0;
1070  } else {
1071  $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y);
1072  $bitMask[$y][$x] = ($maskFunc == 0)?1:0;
1073  }
1074  }
1075  }
1076  return $bitMask;
1077  }
$y
Y position of bit.
Definition: qrcode.php:359
$width
Width.
Definition: qrcode.php:341
$frame
Frame.
Definition: qrcode.php:347
$x
X position of bit.
Definition: qrcode.php:353
+ Here is the caller graph for this function:

◆ getBarcodeArray()

QRcode::getBarcodeArray ( )

Returns a barcode array which is readable by TCPDF.

Returns
array barcode array readable by TCPDF;

Definition at line 680 of file qrcode.php.

References $barcode_array.

680  {
681  return $this->barcode_array;
682  }
$barcode_array
Barcode array to be returned which is readable by TCPDF.
Definition: qrcode.php:297

◆ getBitStream()

QRcode::getBitStream (   $items)
protected

Returns a stream of bits.

Parameters
$items(int)
Returns
array padded merged byte stream

Definition at line 2105 of file qrcode.php.

References $items, appendPaddingBit(), and mergeBitStream().

Referenced by getByteStream().

2105  {
2106  $bstream = $this->mergeBitStream($items);
2107  return $this->appendPaddingBit($bstream);
2108  }
$items
Input items.
Definition: qrcode.php:443
appendPaddingBit($bstream)
Append Padding Bit to bitstream.
Definition: qrcode.php:2055
mergeBitStream($items)
mergeBitStream
Definition: qrcode.php:2088
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getByteStream()

QRcode::getByteStream (   $items)
protected

Pack all bit streams padding bits into a byte array.

Parameters
$items(int)
Returns
array padded merged byte stream

Definition at line 2115 of file qrcode.php.

References $items, bitstreamToByte(), and getBitStream().

Referenced by encodeMask().

2115  {
2116  $bstream = $this->getBitStream($items);
2117  return $this->bitstreamToByte($bstream);
2118  }
getBitStream($items)
Returns a stream of bits.
Definition: qrcode.php:2105
$items
Input items.
Definition: qrcode.php:443
bitstreamToByte($bstream)
Convert bitstream to bytes.
Definition: qrcode.php:2228
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCode()

QRcode::getCode ( )
protected

Return Reed-Solomon block code.

Returns
array rsblocks

Definition at line 910 of file qrcode.php.

References $b1, $blocks, $dataLength, $ret, and $row.

Referenced by encodeMask().

910  {
911  if ($this->count < $this->dataLength) {
912  $row = $this->count % $this->blocks;
913  $col = $this->count / $this->blocks;
914  if ($col >= $this->rsblocks[0]['dataLength']) {
915  $row += $this->b1;
916  }
917  $ret = $this->rsblocks[$row]['data'][$col];
918  } elseif ($this->count < $this->dataLength + $this->eccLength) {
919  $row = ($this->count - $this->dataLength) % $this->blocks;
920  $col = ($this->count - $this->dataLength) / $this->blocks;
921  $ret = $this->rsblocks[$row]['ecc'][$col];
922  } else {
923  return 0;
924  }
925  $this->count++;
926  return $ret;
927  }
$b1
Value b1.
Definition: qrcode.php:421
$row
$blocks
Blocks.
Definition: qrcode.php:391
$ret
Definition: parser.php:6
$dataLength
Data length.
Definition: qrcode.php:409
+ Here is the caller graph for this function:

◆ getDataLength()

QRcode::getDataLength (   $version,
  $level 
)
protected

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

Parameters
$version(int) version
$level(int) error correction level
Returns
int maximum size (bytes)

Definition at line 2284 of file qrcode.php.

References $level, and $version.

Referenced by appendPaddingBit(), and getEccSpec().

2284  {
2285  return $this->capacity[$version][QRCAP_WORDS] - $this->capacity[$version][QRCAP_EC][$level];
2286  }
$version
QR code version.
Definition: qrcode.php:303
$level
Levels of error correction.
Definition: qrcode.php:309
+ Here is the caller graph for this function:

◆ getECCLength()

QRcode::getECCLength (   $version,
  $level 
)
protected

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

Parameters
$version(int) version
$level(int) error correction level
Returns
int ECC size (bytes)

Definition at line 2294 of file qrcode.php.

References $level, and $version.

Referenced by getEccSpec().

2294  {
2295  return $this->capacity[$version][QRCAP_EC][$level];
2296  }
$version
QR code version.
Definition: qrcode.php:303
$level
Levels of error correction.
Definition: qrcode.php:309
+ Here is the caller graph for this function:

◆ getEccSpec()

QRcode::getEccSpec (   $version,
  $level,
  $spec 
)
protected

Return an array of ECC specification.

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

Definition at line 2385 of file qrcode.php.

References $b1, $data, $level, $version, getDataLength(), and getECCLength().

Referenced by encodeMask().

2385  {
2386  if (count($spec) < 5) {
2387  $spec = array(0, 0, 0, 0, 0);
2388  }
2389  $b1 = $this->eccTable[$version][$level][0];
2390  $b2 = $this->eccTable[$version][$level][1];
2391  $data = $this->getDataLength($version, $level);
2392  $ecc = $this->getECCLength($version, $level);
2393  if ($b2 == 0) {
2394  $spec[0] = $b1;
2395  $spec[1] = (int)($data / $b1);
2396  $spec[2] = (int)($ecc / $b1);
2397  $spec[3] = 0;
2398  $spec[4] = 0;
2399  } else {
2400  $spec[0] = $b1;
2401  $spec[1] = (int)($data / ($b1 + $b2));
2402  $spec[2] = (int)($ecc / ($b1 + $b2));
2403  $spec[3] = $b2;
2404  $spec[4] = $spec[1] + 1;
2405  }
2406  return $spec;
2407  }
$b1
Value b1.
Definition: qrcode.php:421
$version
QR code version.
Definition: qrcode.php:303
$level
Levels of error correction.
Definition: qrcode.php:309
getECCLength($version, $level)
Return maximum error correction code length (bytes) for the version.
Definition: qrcode.php:2294
getDataLength($version, $level)
Return maximum data code length (bytes) for the version.
Definition: qrcode.php:2284
$data
Mask data.
Definition: qrcode.php:333
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFormatInfo()

QRcode::getFormatInfo (   $mask,
  $level 
)
protected

Return BCH encoded format information pattern.

Parameters
$mask(array)
$level(int) error correction level
Returns
BCH encoded format information pattern

Definition at line 2492 of file qrcode.php.

References $level, and $mask.

Referenced by writeFormatInformation().

2492  {
2493  if (($mask < 0) OR ($mask > 7)) {
2494  return 0;
2495  }
2496  if (($level < 0) OR ($level > 3)) {
2497  return 0;
2498  }
2499  return $this->formatInfo[$level][$mask];
2500  }
$level
Levels of error correction.
Definition: qrcode.php:309
$mask
Definition: example_042.php:90
+ Here is the caller graph for this function:

◆ getFrameAt()

QRcode::getFrameAt (   $at)
protected

Get frame value at specified position.

Parameters
$at(array) x,y position
Returns
value at specified position

Definition at line 795 of file qrcode.php.

795  {
796  return ord($this->frame[$at['y']][$at['x']]);
797  }

◆ getMinimumVersion()

QRcode::getMinimumVersion (   $size,
  $level 
)
protected

Return a version number that satisfies the input code length.

Parameters
$size(int) input code length (bytes)
$level(int) error correction level
Returns
int version number

Definition at line 2322 of file qrcode.php.

References $i, $level, and $size.

Referenced by convertData(), and estimateVersion().

2322  {
2323  for ($i = 1; $i <= QRSPEC_VERSION_MAX; ++$i) {
2324  $words = ($this->capacity[$i][QRCAP_WORDS] - $this->capacity[$i][QRCAP_EC][$level]);
2325  if ($words >= $size) {
2326  return $i;
2327  }
2328  }
2329  // the size of input data is greater than QR capacity, try to lover the error correction mode
2330  return -1;
2331  }
$size
Definition: RandomTest.php:84
$level
Levels of error correction.
Definition: qrcode.php:309
$i
Definition: disco.tpl.php:19
+ Here is the caller graph for this function:

◆ getNextPosition()

QRcode::getNextPosition ( )
protected

Return the next frame position.

Returns
array of x,y coordinates

Definition at line 803 of file qrcode.php.

References $dir, $w, $width, $x, and $y.

Referenced by encodeMask().

803  {
804  do {
805  if ($this->bit == -1) {
806  $this->bit = 0;
807  return array('x'=>$this->x, 'y'=>$this->y);
808  }
809  $x = $this->x;
810  $y = $this->y;
811  $w = $this->width;
812  if ($this->bit == 0) {
813  $x--;
814  $this->bit++;
815  } else {
816  $x++;
817  $y += $this->dir;
818  $this->bit--;
819  }
820  if ($this->dir < 0) {
821  if ($y < 0) {
822  $y = 0;
823  $x -= 2;
824  $this->dir = 1;
825  if ($x == 6) {
826  $x--;
827  $y = 9;
828  }
829  }
830  } else {
831  if ($y == $w) {
832  $y = $w - 1;
833  $x -= 2;
834  $this->dir = -1;
835  if ($x == 6) {
836  $x--;
837  $y -= 8;
838  }
839  }
840  }
841  if (($x < 0) OR ($y < 0)) {
842  return NULL;
843  }
844  $this->x = $x;
845  $this->y = $y;
846  } while(ord($this->frame[$y][$x]) & 0x80);
847  return array('x'=>$x, 'y'=>$y);
848  }
$w
$y
Y position of bit.
Definition: qrcode.php:359
$width
Width.
Definition: qrcode.php:341
$dir
Direction.
Definition: qrcode.php:365
$x
X position of bit.
Definition: qrcode.php:353
+ Here is the caller graph for this function:

◆ getRemainder()

QRcode::getRemainder (   $version)
protected

Return the numer of remainder bits.

Parameters
$version(int) version
Returns
int number of remainder bits

Definition at line 2312 of file qrcode.php.

References $version.

Referenced by encodeMask().

2312  {
2313  return $this->capacity[$version][QRCAP_REMINDER];
2314  }
$version
QR code version.
Definition: qrcode.php:303
+ Here is the caller graph for this function:

◆ getVersionPattern()

QRcode::getVersionPattern (   $version)
protected

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

Use lower 18 bits.

Parameters
$version(int) version
Returns
BCH encoded version information pattern

Definition at line 2479 of file qrcode.php.

References $version.

Referenced by createFrame().

2479  {
2480  if (($version < 7) OR ($version > QRSPEC_VERSION_MAX)) {
2481  return 0;
2482  }
2483  return $this->versionPattern[($version - 7)];
2484  }
$version
QR code version.
Definition: qrcode.php:303
+ Here is the caller graph for this function:

◆ getWidth()

QRcode::getWidth (   $version)
protected

Return the width of the symbol for the version.

Parameters
$version(int) version
Returns
int width

Definition at line 2303 of file qrcode.php.

References $version.

Referenced by encodeMask().

2303  {
2304  return $this->capacity[$version][QRCAP_WIDTH];
2305  }
$version
QR code version.
Definition: qrcode.php:303
+ Here is the caller graph for this function:

◆ identifyMode()

QRcode::identifyMode (   $pos)
protected

identifyMode

Parameters
$pos(int)
Returns
int mode

Definition at line 1287 of file qrcode.php.

References $c, $d, isalnumat(), and isdigitat().

Referenced by eat8(), eatKanji(), eatNum(), splitString(), and toUpper().

1287  {
1288  if ($pos >= strlen($this->dataStr)) {
1289  return QR_MODE_NL;
1290  }
1291  $c = $this->dataStr[$pos];
1292  if ($this->isdigitat($this->dataStr, $pos)) {
1293  return QR_MODE_NM;
1294  } elseif ($this->isalnumat($this->dataStr, $pos)) {
1295  return QR_MODE_AN;
1296  } elseif ($this->hint == QR_MODE_KJ) {
1297  if ($pos+1 < strlen($this->dataStr)) {
1298  $d = $this->dataStr[$pos+1];
1299  $word = (ord($c) << 8) | ord($d);
1300  if (($word >= 0x8140 && $word <= 0x9ffc) OR ($word >= 0xe040 && $word <= 0xebbf)) {
1301  return QR_MODE_KJ;
1302  }
1303  }
1304  }
1305  return QR_MODE_8B;
1306  }
isdigitat($str, $pos)
Return true if the character at specified position is a number.
Definition: qrcode.php:1262
isalnumat($str, $pos)
Return true if the character at specified position is an alphanumeric character.
Definition: qrcode.php:1275
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init()

QRcode::init (   $spec)
protected

Initialize code.

Parameters
$spec(array) array of ECC specification
Returns
0 in case of success, -1 in case of error

Definition at line 859 of file qrcode.php.

References $i, encode_rs_char(), init_rs(), rsBlockNum1(), rsBlockNum2(), rsDataCodes1(), rsDataCodes2(), rsEccCodes1(), and rsEccCodes2().

Referenced by encodeMask().

859  {
860  $dl = $this->rsDataCodes1($spec);
861  $el = $this->rsEccCodes1($spec);
862  $rs = $this->init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
863  $blockNo = 0;
864  $dataPos = 0;
865  $eccPos = 0;
866  $endfor = $this->rsBlockNum1($spec);
867  for ($i=0; $i < $endfor; ++$i) {
868  $ecc = array_slice($this->ecccode, $eccPos);
869  $this->rsblocks[$blockNo] = array();
870  $this->rsblocks[$blockNo]['dataLength'] = $dl;
871  $this->rsblocks[$blockNo]['data'] = array_slice($this->datacode, $dataPos);
872  $this->rsblocks[$blockNo]['eccLength'] = $el;
873  $ecc = $this->encode_rs_char($rs, $this->rsblocks[$blockNo]['data'], $ecc);
874  $this->rsblocks[$blockNo]['ecc'] = $ecc;
875  $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);
876  $dataPos += $dl;
877  $eccPos += $el;
878  $blockNo++;
879  }
880  if ($this->rsBlockNum2($spec) == 0) {
881  return 0;
882  }
883  $dl = $this->rsDataCodes2($spec);
884  $el = $this->rsEccCodes2($spec);
885  $rs = $this->init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
886  if ($rs == NULL) {
887  return -1;
888  }
889  $endfor = $this->rsBlockNum2($spec);
890  for ($i=0; $i < $endfor; ++$i) {
891  $ecc = array_slice($this->ecccode, $eccPos);
892  $this->rsblocks[$blockNo] = array();
893  $this->rsblocks[$blockNo]['dataLength'] = $dl;
894  $this->rsblocks[$blockNo]['data'] = array_slice($this->datacode, $dataPos);
895  $this->rsblocks[$blockNo]['eccLength'] = $el;
896  $ecc = $this->encode_rs_char($rs, $this->rsblocks[$blockNo]['data'], $ecc);
897  $this->rsblocks[$blockNo]['ecc'] = $ecc;
898  $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc);
899  $dataPos += $dl;
900  $eccPos += $el;
901  $blockNo++;
902  }
903  return 0;
904  }
rsDataCodes2($spec)
Return data codes 2.
Definition: qrcode.php:2658
rsEccCodes1($spec)
Return ecc codes 1.
Definition: qrcode.php:2640
rsDataCodes1($spec)
Return data codes 1.
Definition: qrcode.php:2631
rsBlockNum2($spec)
Return block number 2.
Definition: qrcode.php:2649
rsBlockNum1($spec)
Return block number 1.
Definition: qrcode.php:2622
encode_rs_char($rs, $data, $parity)
Encode a Reed-Solomon codec and returns the parity array.
Definition: qrcode.php:2828
rsEccCodes2($spec)
Return ecc codes 2.
Definition: qrcode.php:2667
init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)
Initialize a Reed-Solomon codec and add it to existing rsitems.
Definition: qrcode.php:2703
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_rs()

QRcode::init_rs (   $symsize,
  $gfpoly,
  $fcr,
  $prim,
  $nroots,
  $pad 
)
protected

Initialize a Reed-Solomon codec and add it to existing rsitems.

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

Definition at line 2703 of file qrcode.php.

References init_rs_char().

Referenced by init().

2703  {
2704  foreach ($this->rsitems as $rs) {
2705  if (($rs['pad'] != $pad) OR ($rs['nroots'] != $nroots) OR ($rs['mm'] != $symsize)
2706  OR ($rs['gfpoly'] != $gfpoly) OR ($rs['fcr'] != $fcr) OR ($rs['prim'] != $prim)) {
2707  continue;
2708  }
2709  return $rs;
2710  }
2711  $rs = $this->init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad);
2712  array_unshift($this->rsitems, $rs);
2713  return $rs;
2714  }
init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)
Initialize a Reed-Solomon codec and returns an array of values.
Definition: qrcode.php:2744
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_rs_char()

QRcode::init_rs_char (   $symsize,
  $gfpoly,
  $fcr,
  $prim,
  $nroots,
  $pad 
)
protected

Initialize a Reed-Solomon codec and returns an array of values.

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

Definition at line 2744 of file qrcode.php.

References $i, $root, and modnn().

Referenced by init_rs().

2744  {
2745  // Based on Reed solomon encoder by Phil Karn, KA9Q (GNU-LGPLv2)
2746  $rs = null;
2747  // Check parameter ranges
2748  if (($symsize < 0) OR ($symsize > 8)) {
2749  return $rs;
2750  }
2751  if (($fcr < 0) OR ($fcr >= (1<<$symsize))) {
2752  return $rs;
2753  }
2754  if (($prim <= 0) OR ($prim >= (1<<$symsize))) {
2755  return $rs;
2756  }
2757  if (($nroots < 0) OR ($nroots >= (1<<$symsize))) {
2758  return $rs;
2759  }
2760  if (($pad < 0) OR ($pad >= ((1<<$symsize) -1 - $nroots))) {
2761  return $rs;
2762  }
2763  $rs = array();
2764  $rs['mm'] = $symsize;
2765  $rs['nn'] = (1 << $symsize) - 1;
2766  $rs['pad'] = $pad;
2767  $rs['alpha_to'] = array_fill(0, ($rs['nn'] + 1), 0);
2768  $rs['index_of'] = array_fill(0, ($rs['nn'] + 1), 0);
2769  // PHP style macro replacement ;)
2770  $NN =& $rs['nn'];
2771  $A0 =& $NN;
2772  // Generate Galois field lookup tables
2773  $rs['index_of'][0] = $A0; // log(zero) = -inf
2774  $rs['alpha_to'][$A0] = 0; // alpha**-inf = 0
2775  $sr = 1;
2776  for ($i=0; $i<$rs['nn']; ++$i) {
2777  $rs['index_of'][$sr] = $i;
2778  $rs['alpha_to'][$i] = $sr;
2779  $sr <<= 1;
2780  if ($sr & (1 << $symsize)) {
2781  $sr ^= $gfpoly;
2782  }
2783  $sr &= $rs['nn'];
2784  }
2785  if ($sr != 1) {
2786  // field generator polynomial is not primitive!
2787  return NULL;
2788  }
2789  // Form RS code generator polynomial from its roots
2790  $rs['genpoly'] = array_fill(0, ($nroots + 1), 0);
2791  $rs['fcr'] = $fcr;
2792  $rs['prim'] = $prim;
2793  $rs['nroots'] = $nroots;
2794  $rs['gfpoly'] = $gfpoly;
2795  // Find prim-th root of 1, used in decoding
2796  for ($iprim=1; ($iprim % $prim) != 0; $iprim += $rs['nn']) {
2797  ; // intentional empty-body loop!
2798  }
2799  $rs['iprim'] = (int)($iprim / $prim);
2800  $rs['genpoly'][0] = 1;
2801  for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) {
2802  $rs['genpoly'][$i+1] = 1;
2803  // Multiply rs->genpoly[] by @**(root + x)
2804  for ($j = $i; $j > 0; --$j) {
2805  if ($rs['genpoly'][$j] != 0) {
2806  $rs['genpoly'][$j] = $rs['genpoly'][$j-1] ^ $rs['alpha_to'][$this->modnn($rs, $rs['index_of'][$rs['genpoly'][$j]] + $root)];
2807  } else {
2808  $rs['genpoly'][$j] = $rs['genpoly'][$j-1];
2809  }
2810  }
2811  // rs->genpoly[0] can never be zero
2812  $rs['genpoly'][0] = $rs['alpha_to'][$this->modnn($rs, $rs['index_of'][$rs['genpoly'][0]] + $root)];
2813  }
2814  // convert rs->genpoly[] to index form for quicker encoding
2815  for ($i = 0; $i <= $nroots; ++$i) {
2816  $rs['genpoly'][$i] = $rs['index_of'][$rs['genpoly'][$i]];
2817  }
2818  return $rs;
2819  }
modnn($rs, $x)
modnn
Definition: qrcode.php:2726
$root
Definition: sabredav.php:45
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insertStructuredAppendHeader()

QRcode::insertStructuredAppendHeader (   $items,
  $size,
  $index,
  $parity 
)
protected

insertStructuredAppendHeader

Parameters
$items(array)
$size(int)
$index(int)
$parity(int)
Returns
array items

Definition at line 1712 of file qrcode.php.

References $index, $items, $size, and newInputItem().

1712  {
1713  if ($size > MAX_STRUCTURED_SYMBOLS) {
1714  return -1;
1715  }
1716  if (($index <= 0) OR ($index > MAX_STRUCTURED_SYMBOLS)) {
1717  return -1;
1718  }
1719  $buf = array($size, $index, $parity);
1720  $entry = $this->newInputItem(QR_MODE_ST, 3, buf);
1721  array_unshift($items, $entry);
1722  return $items;
1723  }
$size
Definition: RandomTest.php:84
$index
Definition: metadata.php:60
$items
Input items.
Definition: qrcode.php:443
newInputItem($mode, $size, $data, $bstream=null)
newInputItem
Definition: qrcode.php:1513
+ Here is the call graph for this function:

◆ isalnumat()

QRcode::isalnumat (   $str,
  $pos 
)
protected

Return true if the character at specified position is an alphanumeric character.

Parameters
$str(string) string
$pos(int) characted position
Returns
boolean true of false

Definition at line 1275 of file qrcode.php.

References lookAnTable().

Referenced by eat8(), eatAn(), and identifyMode().

1275  {
1276  if ($pos >= strlen($str)) {
1277  return false;
1278  }
1279  return ($this->lookAnTable(ord($str[$pos])) >= 0);
1280  }
lookAnTable($c)
Look up the alphabet-numeric convesion table (see JIS X0510:2004, pp.19).
Definition: qrcode.php:1762
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isdigitat()

QRcode::isdigitat (   $str,
  $pos 
)
protected

Return true if the character at specified position is a number.

Parameters
$str(string) string
$pos(int) characted position
Returns
boolean true of false

Definition at line 1262 of file qrcode.php.

Referenced by eat8(), eatAn(), eatNum(), and identifyMode().

1262  {
1263  if ($pos >= strlen($str)) {
1264  return false;
1265  }
1266  return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
1267  }
+ Here is the caller graph for this function:

◆ lengthIndicator()

QRcode::lengthIndicator (   $mode,
  $version 
)
protected

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

Parameters
$mode(int) encoding mode
$version(int) version
Returns
int the size of the appropriate length indicator (bits).

Definition at line 2339 of file qrcode.php.

References $l, and $version.

Referenced by eat8(), eatAn(), eatNum(), encodeMode8(), encodeModeAn(), encodeModeKanji(), encodeModeNum(), estimateBitStreamSize(), and lengthOfCode().

2339  {
2340  if ($mode == QR_MODE_ST) {
2341  return 0;
2342  }
2343  if ($version <= 9) {
2344  $l = 0;
2345  } elseif ($version <= 26) {
2346  $l = 1;
2347  } else {
2348  $l = 2;
2349  }
2350  return $this->lengthTableBits[$mode][$l];
2351  }
$version
QR code version.
Definition: qrcode.php:303
global $l
Definition: afr.php:30
+ Here is the caller graph for this function:

◆ lengthOfCode()

QRcode::lengthOfCode (   $mode,
  $version,
  $bits 
)
protected

lengthOfCode

Parameters
$mode(int)
$version(int)
$bits(int)
Returns
int size

Definition at line 1956 of file qrcode.php.

References $size, $version, lengthIndicator(), and maximumWords().

1956  {
1957  $payload = $bits - 4 - $this->lengthIndicator($mode, $version);
1958  switch($mode) {
1959  case QR_MODE_NM: {
1960  $chunks = (int)($payload / 10);
1961  $remain = $payload - $chunks * 10;
1962  $size = $chunks * 3;
1963  if ($remain >= 7) {
1964  $size += 2;
1965  } elseif ($remain >= 4) {
1966  $size += 1;
1967  }
1968  break;
1969  }
1970  case QR_MODE_AN: {
1971  $chunks = (int)($payload / 11);
1972  $remain = $payload - $chunks * 11;
1973  $size = $chunks * 2;
1974  if ($remain >= 6) {
1975  ++$size;
1976  }
1977  break;
1978  }
1979  case QR_MODE_8B: {
1980  $size = (int)($payload / 8);
1981  break;
1982  }
1983  case QR_MODE_KJ: {
1984  $size = (int)(($payload / 13) * 2);
1985  break;
1986  }
1987  case QR_MODE_ST: {
1988  $size = (int)($payload / 8);
1989  break;
1990  }
1991  default: {
1992  $size = 0;
1993  break;
1994  }
1995  }
1996  $maxsize = $this->maximumWords($mode, $version);
1997  if ($size < 0) {
1998  $size = 0;
1999  }
2000  if ($size > $maxsize) {
2001  $size = $maxsize;
2002  }
2003  return $size;
2004  }
maximumWords($mode, $version)
Return the maximum length for the mode and version.
Definition: qrcode.php:2359
$size
Definition: RandomTest.php:84
$version
QR code version.
Definition: qrcode.php:303
lengthIndicator($mode, $version)
Return the size of length indicator for the mode and version.
Definition: qrcode.php:2339
+ Here is the call graph for this function:

◆ lookAnTable()

QRcode::lookAnTable (   $c)
protected

Look up the alphabet-numeric convesion table (see JIS X0510:2004, pp.19).

Parameters
$c(int) character value
Returns
value

Definition at line 1762 of file qrcode.php.

References $c.

Referenced by checkModeAn(), encodeModeAn(), and isalnumat().

1762  {
1763  return (($c > 127)?-1:$this->anTable[$c]);
1764  }
+ Here is the caller graph for this function:

◆ makeMask()

QRcode::makeMask (   $width,
  $frame,
  $maskNo,
  $level 
)
protected

makeMask

Parameters
$width(int)
$frame(array)
$maskNo(int)
$level(int)
Returns
array mask

Definition at line 1115 of file qrcode.php.

References $frame, $level, $width, makeMaskNo(), and writeFormatInformation().

Referenced by encodeMask().

1115  {
1116  $masked = array_fill(0, $width, str_repeat("\0", $width));
1117  $this->makeMaskNo($maskNo, $width, $frame, $masked);
1118  $this->writeFormatInformation($width, $masked, $maskNo, $level);
1119  return $masked;
1120  }
$level
Levels of error correction.
Definition: qrcode.php:309
makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly=false)
makeMaskNo
Definition: qrcode.php:1088
$width
Width.
Definition: qrcode.php:341
writeFormatInformation($width, &$frame, $mask, $level)
Write Format Information on frame and returns the number of black bits.
Definition: qrcode.php:941
$frame
Frame.
Definition: qrcode.php:347
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ makeMaskNo()

QRcode::makeMaskNo (   $maskNo,
  $width,
  $s,
$d,
  $maskGenOnly = false 
)
protected

makeMaskNo

Parameters
$maskNo(int)
$width(int)
$s(int)
$d(int)
$maskGenOnly(boolean)
Returns
int b

Definition at line 1088 of file qrcode.php.

References $d, $s, $width, $x, $y, and generateMaskNo().

Referenced by makeMask(), and mask().

1088  {
1089  $b = 0;
1090  $bitMask = array();
1091  $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d);
1092  if ($maskGenOnly) {
1093  return;
1094  }
1095  $d = $s;
1096  for ($y=0; $y<$width; ++$y) {
1097  for ($x=0; $x<$width; ++$x) {
1098  if ($bitMask[$y][$x] == 1) {
1099  $d[$y][$x] = chr(ord($s[$y][$x]) ^ ((int)($bitMask[$y][$x])));
1100  }
1101  $b += (int)(ord($d[$y][$x]) & 1);
1102  }
1103  }
1104  return $b;
1105  }
$s
Definition: pwgen.php:45
generateMaskNo($maskNo, $width, $frame)
Return bitmask.
Definition: qrcode.php:1064
$y
Y position of bit.
Definition: qrcode.php:359
$width
Width.
Definition: qrcode.php:341
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
$x
X position of bit.
Definition: qrcode.php:353
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mask()

QRcode::mask (   $width,
  $frame,
  $level 
)
protected

mask

Parameters
$width(int)
$frame(array)
$level(int)
Returns
array best mask

Definition at line 1220 of file qrcode.php.

References $frame, $i, $level, $mask, $width, evaluateSymbol(), makeMaskNo(), and writeFormatInformation().

Referenced by encodeMask().

1220  {
1221  $minDemerit = PHP_INT_MAX;
1222  $bestMaskNum = 0;
1223  $bestMask = array();
1224  $checked_masks = array(0, 1, 2, 3, 4, 5, 6, 7);
1225  if (QR_FIND_FROM_RANDOM !== false) {
1226  $howManuOut = 8 - (QR_FIND_FROM_RANDOM % 9);
1227  for ($i = 0; $i < $howManuOut; ++$i) {
1228  $remPos = rand (0, count($checked_masks)-1);
1229  unset($checked_masks[$remPos]);
1230  $checked_masks = array_values($checked_masks);
1231  }
1232  }
1233  $bestMask = $frame;
1234  foreach ($checked_masks as $i) {
1235  $mask = array_fill(0, $width, str_repeat("\0", $width));
1236  $demerit = 0;
1237  $blacks = 0;
1238  $blacks = $this->makeMaskNo($i, $width, $frame, $mask);
1239  $blacks += $this->writeFormatInformation($width, $mask, $i, $level);
1240  $blacks = (int)(100 * $blacks / ($width * $width));
1241  $demerit = (int)((int)(abs($blacks - 50) / 5) * N4);
1242  $demerit += $this->evaluateSymbol($width, $mask);
1243  if ($demerit < $minDemerit) {
1244  $minDemerit = $demerit;
1245  $bestMask = $mask;
1246  $bestMaskNum = $i;
1247  }
1248  }
1249  return $bestMask;
1250  }
$level
Levels of error correction.
Definition: qrcode.php:309
makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly=false)
makeMaskNo
Definition: qrcode.php:1088
$mask
Definition: example_042.php:90
$width
Width.
Definition: qrcode.php:341
$i
Definition: disco.tpl.php:19
writeFormatInformation($width, &$frame, $mask, $level)
Write Format Information on frame and returns the number of black bits.
Definition: qrcode.php:941
$frame
Frame.
Definition: qrcode.php:347
evaluateSymbol($width, $frame)
evaluateSymbol
Definition: qrcode.php:1158
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mask0()

QRcode::mask0 (   $x,
  $y 
)
protected

mask0

Parameters
$x(int) X position
$y(int) Y position
Returns
int mask

Definition at line 983 of file qrcode.php.

References $x, and $y.

983  {
984  return ($x + $y) & 1;
985  }
$y
Y position of bit.
Definition: qrcode.php:359
$x
X position of bit.
Definition: qrcode.php:353

◆ mask1()

QRcode::mask1 (   $x,
  $y 
)
protected

mask1

Parameters
$x(int) X position
$y(int) Y position
Returns
int mask

Definition at line 993 of file qrcode.php.

References $y.

993  {
994  return ($y & 1);
995  }
$y
Y position of bit.
Definition: qrcode.php:359

◆ mask2()

QRcode::mask2 (   $x,
  $y 
)
protected

mask2

Parameters
$x(int) X position
$y(int) Y position
Returns
int mask

Definition at line 1003 of file qrcode.php.

References $x.

1003  {
1004  return ($x % 3);
1005  }
$x
X position of bit.
Definition: qrcode.php:353

◆ mask3()

QRcode::mask3 (   $x,
  $y 
)
protected

mask3

Parameters
$x(int) X position
$y(int) Y position
Returns
int mask

Definition at line 1013 of file qrcode.php.

References $x, and $y.

1013  {
1014  return ($x + $y) % 3;
1015  }
$y
Y position of bit.
Definition: qrcode.php:359
$x
X position of bit.
Definition: qrcode.php:353

◆ mask4()

QRcode::mask4 (   $x,
  $y 
)
protected

mask4

Parameters
$x(int) X position
$y(int) Y position
Returns
int mask

Definition at line 1023 of file qrcode.php.

References $x, and $y.

1023  {
1024  return (((int)($y / 2)) + ((int)($x / 3))) & 1;
1025  }
$y
Y position of bit.
Definition: qrcode.php:359
$x
X position of bit.
Definition: qrcode.php:353

◆ mask5()

QRcode::mask5 (   $x,
  $y 
)
protected

mask5

Parameters
$x(int) X position
$y(int) Y position
Returns
int mask

Definition at line 1033 of file qrcode.php.

References $x, and $y.

1033  {
1034  return (($x * $y) & 1) + ($x * $y) % 3;
1035  }
$y
Y position of bit.
Definition: qrcode.php:359
$x
X position of bit.
Definition: qrcode.php:353

◆ mask6()

QRcode::mask6 (   $x,
  $y 
)
protected

mask6

Parameters
$x(int) X position
$y(int) Y position
Returns
int mask

Definition at line 1043 of file qrcode.php.

References $x, and $y.

1043  {
1044  return ((($x * $y) & 1) + ($x * $y) % 3) & 1;
1045  }
$y
Y position of bit.
Definition: qrcode.php:359
$x
X position of bit.
Definition: qrcode.php:353

◆ mask7()

QRcode::mask7 (   $x,
  $y 
)
protected

mask7

Parameters
$x(int) X position
$y(int) Y position
Returns
int mask

Definition at line 1053 of file qrcode.php.

References $x, and $y.

1053  {
1054  return ((($x * $y) % 3) + (($x + $y) & 1)) & 1;
1055  }
$y
Y position of bit.
Definition: qrcode.php:359
$x
X position of bit.
Definition: qrcode.php:353

◆ maximumWords()

QRcode::maximumWords (   $mode,
  $version 
)
protected

Return the maximum length for the mode and version.

Parameters
$mode(int) encoding mode
$version(int) version
Returns
int the maximum length (bytes)

Definition at line 2359 of file qrcode.php.

References $l, and $version.

Referenced by encodeBitStream(), and lengthOfCode().

2359  {
2360  if ($mode == QR_MODE_ST) {
2361  return 3;
2362  }
2363  if ($version <= 9) {
2364  $l = 0;
2365  } else if ($version <= 26) {
2366  $l = 1;
2367  } else {
2368  $l = 2;
2369  }
2370  $bits = $this->lengthTableBits[$mode][$l];
2371  $words = (1 << $bits) - 1;
2372  if ($mode == QR_MODE_KJ) {
2373  $words *= 2; // the number of bytes is required
2374  }
2375  return $words;
2376  }
$version
QR code version.
Definition: qrcode.php:303
global $l
Definition: afr.php:30
+ Here is the caller graph for this function:

◆ mergeBitStream()

QRcode::mergeBitStream (   $items)
protected

mergeBitStream

Parameters
$items(array) items
Returns
array bitstream

Definition at line 2088 of file qrcode.php.

References $items, appendBitstream(), and convertData().

Referenced by getBitStream().

2088  {
2089  $items = $this->convertData($items);
2090  if (!is_array($items)) {
2091  return null;
2092  }
2093  $bstream = array();
2094  foreach ($items as $item) {
2095  $bstream = $this->appendBitstream($bstream, $item['bstream']);
2096  }
2097  return $bstream;
2098  }
$items
Input items.
Definition: qrcode.php:443
convertData($items)
convertData
Definition: qrcode.php:2026
appendBitstream($bitstream, $append)
Append one bitstream to another.
Definition: qrcode.php:2183
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ modnn()

QRcode::modnn (   $rs,
  $x 
)
protected

modnn

Parameters
$rs(array) RS values
$x(int) X position
Returns
int X osition

Definition at line 2726 of file qrcode.php.

References $x.

Referenced by encode_rs_char(), and init_rs_char().

2726  {
2727  while ($x >= $rs['nn']) {
2728  $x -= $rs['nn'];
2729  $x = ($x >> $rs['mm']) + ($x & $rs['nn']);
2730  }
2731  return $x;
2732  }
$x
X position of bit.
Definition: qrcode.php:353
+ Here is the caller graph for this function:

◆ newFrame()

QRcode::newFrame (   $version)
protected

Set new frame for the specified version.

Parameters
$version(int) version
Returns
Array of unsigned char.

Definition at line 2595 of file qrcode.php.

References $version, and createFrame().

Referenced by encodeMask().

2595  {
2596  if (($version < 1) OR ($version > QRSPEC_VERSION_MAX)) {
2597  return NULL;
2598  }
2599  if (!isset($this->frames[$version])) {
2600  $this->frames[$version] = $this->createFrame($version);
2601  }
2602  if (is_null($this->frames[$version])) {
2603  return NULL;
2604  }
2605  return $this->frames[$version];
2606  }
$version
QR code version.
Definition: qrcode.php:303
createFrame($version)
Return a copy of initialized frame.
Definition: qrcode.php:2530
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ newFromBytes()

QRcode::newFromBytes (   $size,
  $data 
)
protected

Return new bitstream from bytes.

Parameters
$size(int) size
$data(array) bytes
Returns
array bitstream

Definition at line 2159 of file qrcode.php.

References $data, $i, $mask, $size, and allocate().

Referenced by appendBytes().

2159  {
2160  $bstream = $this->allocate($size * 8);
2161  $p=0;
2162  for ($i=0; $i<$size; ++$i) {
2163  $mask = 0x80;
2164  for ($j=0; $j<8; ++$j) {
2165  if ($data[$i] & $mask) {
2166  $bstream[$p] = 1;
2167  } else {
2168  $bstream[$p] = 0;
2169  }
2170  $p++;
2171  $mask = $mask >> 1;
2172  }
2173  }
2174  return $bstream;
2175  }
$size
Definition: RandomTest.php:84
$mask
Definition: example_042.php:90
$data
Mask data.
Definition: qrcode.php:333
$i
Definition: disco.tpl.php:19
allocate($setLength)
Return an array with zeros.
Definition: qrcode.php:2129
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ newFromNum()

QRcode::newFromNum (   $bits,
  $num 
)
protected

Return new bitstream from number.

Parameters
$bits(int) number of bits
$num(int) number
Returns
array bitstream

Definition at line 2139 of file qrcode.php.

References $i, $mask, and allocate().

Referenced by appendNum().

2139  {
2140  $bstream = $this->allocate($bits);
2141  $mask = 1 << ($bits - 1);
2142  for ($i=0; $i<$bits; ++$i) {
2143  if ($num & $mask) {
2144  $bstream[$i] = 1;
2145  } else {
2146  $bstream[$i] = 0;
2147  }
2148  $mask = $mask >> 1;
2149  }
2150  return $bstream;
2151  }
$mask
Definition: example_042.php:90
$i
Definition: disco.tpl.php:19
allocate($setLength)
Return an array with zeros.
Definition: qrcode.php:2129
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ newInputItem()

QRcode::newInputItem (   $mode,
  $size,
  $data,
  $bstream = null 
)
protected

newInputItem

Parameters
$mode(int)
$size(int)
$data(array)
$bstream(array)
Returns
array input item

Definition at line 1513 of file qrcode.php.

References $data, $size, and check().

Referenced by appendNewInputItem(), encodeBitStream(), and insertStructuredAppendHeader().

1513  {
1514  $setData = array_slice($data, 0, $size);
1515  if (count($setData) < $size) {
1516  $setData = array_merge($setData, array_fill(0, ($size - count($setData)), 0));
1517  }
1518  if (!$this->check($mode, $size, $setData)) {
1519  return NULL;
1520  }
1521  $inputitem = array();
1522  $inputitem['mode'] = $mode;
1523  $inputitem['size'] = $size;
1524  $inputitem['data'] = $setData;
1525  $inputitem['bstream'] = $bstream;
1526  return $inputitem;
1527  }
$size
Definition: RandomTest.php:84
check($mode, $size, $data)
Validate the input data.
Definition: qrcode.php:1859
$data
Mask data.
Definition: qrcode.php:333
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ putAlignmentMarker()

QRcode::putAlignmentMarker (   $frame,
  $ox,
  $oy 
)
protected

Put an alignment marker.

Parameters
$frame(array) frame
$ox(int) X center coordinate of the pattern
$oy(int) Y center coordinate of the pattern
Returns
array frame

Definition at line 2416 of file qrcode.php.

References $frame, $y, and qrstrset().

Referenced by putAlignmentPattern().

2416  {
2417  $finder = array(
2418  "\xa1\xa1\xa1\xa1\xa1",
2419  "\xa1\xa0\xa0\xa0\xa1",
2420  "\xa1\xa0\xa1\xa0\xa1",
2421  "\xa1\xa0\xa0\xa0\xa1",
2422  "\xa1\xa1\xa1\xa1\xa1"
2423  );
2424  $yStart = $oy - 2;
2425  $xStart = $ox - 2;
2426  for ($y=0; $y < 5; $y++) {
2427  $frame = $this->qrstrset($frame, $xStart, $yStart+$y, $finder[$y]);
2428  }
2429  return $frame;
2430  }
$y
Y position of bit.
Definition: qrcode.php:359
qrstrset($srctab, $x, $y, $repl, $replLen=false)
Replace a value on the array at the specified position.
Definition: qrcode.php:2273
$frame
Frame.
Definition: qrcode.php:347
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ putAlignmentPattern()

QRcode::putAlignmentPattern (   $version,
  $frame,
  $width 
)
protected

Put an alignment pattern.

Parameters
$version(int) version
$frame(array) frame
$width(int) width
Returns
array frame

Definition at line 2439 of file qrcode.php.

References $d, $frame, $version, $w, $width, $x, $y, and putAlignmentMarker().

Referenced by createFrame().

2439  {
2440  if ($version < 2) {
2441  return $frame;
2442  }
2443  $d = $this->alignmentPattern[$version][1] - $this->alignmentPattern[$version][0];
2444  if ($d < 0) {
2445  $w = 2;
2446  } else {
2447  $w = (int)(($width - $this->alignmentPattern[$version][0]) / $d + 2);
2448  }
2449  if ($w * $w - 3 == 1) {
2450  $x = $this->alignmentPattern[$version][0];
2451  $y = $this->alignmentPattern[$version][0];
2452  $frame = $this->putAlignmentMarker($frame, $x, $y);
2453  return $frame;
2454  }
2455  $cx = $this->alignmentPattern[$version][0];
2456  $wo = $w - 1;
2457  for ($x=1; $x < $wo; ++$x) {
2458  $frame = $this->putAlignmentMarker($frame, 6, $cx);
2459  $frame = $this->putAlignmentMarker($frame, $cx, 6);
2460  $cx += $d;
2461  }
2462  $cy = $this->alignmentPattern[$version][0];
2463  for ($y=0; $y < $wo; ++$y) {
2464  $cx = $this->alignmentPattern[$version][0];
2465  for ($x=0; $x < $wo; ++$x) {
2466  $frame = $this->putAlignmentMarker($frame, $cx, $cy);
2467  $cx += $d;
2468  }
2469  $cy += $d;
2470  }
2471  return $frame;
2472  }
$version
QR code version.
Definition: qrcode.php:303
putAlignmentMarker($frame, $ox, $oy)
Put an alignment marker.
Definition: qrcode.php:2416
$w
$y
Y position of bit.
Definition: qrcode.php:359
$width
Width.
Definition: qrcode.php:341
$frame
Frame.
Definition: qrcode.php:347
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
$x
X position of bit.
Definition: qrcode.php:353
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ putFinderPattern()

QRcode::putFinderPattern (   $frame,
  $ox,
  $oy 
)
protected

Put a finder pattern.

Parameters
$frame(array) frame
$ox(int) X center coordinate of the pattern
$oy(int) Y center coordinate of the pattern
Returns
array frame

Definition at line 2509 of file qrcode.php.

References $frame, $y, and qrstrset().

Referenced by createFrame().

2509  {
2510  $finder = array(
2511  "\xc1\xc1\xc1\xc1\xc1\xc1\xc1",
2512  "\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
2513  "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
2514  "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
2515  "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
2516  "\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
2517  "\xc1\xc1\xc1\xc1\xc1\xc1\xc1"
2518  );
2519  for ($y=0; $y < 7; $y++) {
2520  $frame = $this->qrstrset($frame, $ox, ($oy + $y), $finder[$y]);
2521  }
2522  return $frame;
2523  }
$y
Y position of bit.
Definition: qrcode.php:359
qrstrset($srctab, $x, $y, $repl, $replLen=false)
Replace a value on the array at the specified position.
Definition: qrcode.php:2273
$frame
Frame.
Definition: qrcode.php:347
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qrstrset()

QRcode::qrstrset (   $srctab,
  $x,
  $y,
  $repl,
  $replLen = false 
)
protected

Replace a value on the array at the specified position.

Parameters
$srctab(array)
$x(int) X position
$y(int) Y position
$repl(string) value to replace
$replLen(int) length of the repl string
Returns
array srctab

Definition at line 2273 of file qrcode.php.

References $x, and $y.

Referenced by createFrame(), putAlignmentMarker(), and putFinderPattern().

2273  {
2274  $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl));
2275  return $srctab;
2276  }
$y
Y position of bit.
Definition: qrcode.php:359
$x
X position of bit.
Definition: qrcode.php:353
+ Here is the caller graph for this function:

◆ rsBlockNum()

QRcode::rsBlockNum (   $spec)
protected

Return block number 0.

Parameters
$spec(array)
Returns
int value

Definition at line 2613 of file qrcode.php.

Referenced by encodeMask().

2613  {
2614  return ($spec[0] + $spec[3]);
2615  }
+ Here is the caller graph for this function:

◆ rsBlockNum1()

QRcode::rsBlockNum1 (   $spec)
protected

Return block number 1.

Parameters
$spec(array)
Returns
int value

Definition at line 2622 of file qrcode.php.

Referenced by encodeMask(), and init().

2622  {
2623  return $spec[0];
2624  }
+ Here is the caller graph for this function:

◆ rsBlockNum2()

QRcode::rsBlockNum2 (   $spec)
protected

Return block number 2.

Parameters
$spec(array)
Returns
int value

Definition at line 2649 of file qrcode.php.

Referenced by init().

2649  {
2650  return $spec[3];
2651  }
+ Here is the caller graph for this function:

◆ rsDataCodes1()

QRcode::rsDataCodes1 (   $spec)
protected

Return data codes 1.

Parameters
$spec(array)
Returns
int value

Definition at line 2631 of file qrcode.php.

Referenced by init().

2631  {
2632  return $spec[1];
2633  }
+ Here is the caller graph for this function:

◆ rsDataCodes2()

QRcode::rsDataCodes2 (   $spec)
protected

Return data codes 2.

Parameters
$spec(array)
Returns
int value

Definition at line 2658 of file qrcode.php.

Referenced by init().

2658  {
2659  return $spec[4];
2660  }
+ Here is the caller graph for this function:

◆ rsDataLength()

QRcode::rsDataLength (   $spec)
protected

Return data length.

Parameters
$spec(array)
Returns
int value

Definition at line 2676 of file qrcode.php.

Referenced by encodeMask().

2676  {
2677  return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]);
2678  }
+ Here is the caller graph for this function:

◆ rsEccCodes1()

QRcode::rsEccCodes1 (   $spec)
protected

Return ecc codes 1.

Parameters
$spec(array)
Returns
int value

Definition at line 2640 of file qrcode.php.

Referenced by init().

2640  {
2641  return $spec[2];
2642  }
+ Here is the caller graph for this function:

◆ rsEccCodes2()

QRcode::rsEccCodes2 (   $spec)
protected

Return ecc codes 2.

Parameters
$spec(array)
Returns
int value

Definition at line 2667 of file qrcode.php.

Referenced by init().

2667  {
2668  return $spec[2];
2669  }
+ Here is the caller graph for this function:

◆ rsEccLength()

QRcode::rsEccLength (   $spec)
protected

Return ecc length.

Parameters
$spec(array)
Returns
int value

Definition at line 2685 of file qrcode.php.

Referenced by encodeMask().

2685  {
2686  return ($spec[0] + $spec[3]) * $spec[2];
2687  }
+ Here is the caller graph for this function:

◆ setFrameAt()

QRcode::setFrameAt (   $at,
  $val 
)
protected

Set frame value at specified position.

Parameters
$at(array) x,y position
$val(int) value of the character to set

Definition at line 786 of file qrcode.php.

Referenced by encodeMask().

786  {
787  $this->frame[$at['y']][$at['x']] = chr($val);
788  }
+ Here is the caller graph for this function:

◆ splitString()

QRcode::splitString ( )
protected

splitString

Returns
(int)

Definition at line 1445 of file qrcode.php.

References $hint, eat8(), eatAn(), eatKanji(), eatNum(), and identifyMode().

Referenced by encodeString().

1445  {
1446  while (strlen($this->dataStr) > 0) {
1447  $mode = $this->identifyMode(0);
1448  switch ($mode) {
1449  case QR_MODE_NM: {
1450  $length = $this->eatNum();
1451  break;
1452  }
1453  case QR_MODE_AN: {
1454  $length = $this->eatAn();
1455  break;
1456  }
1457  case QR_MODE_KJ: {
1458  if ($hint == QR_MODE_KJ) {
1459  $length = $this->eatKanji();
1460  } else {
1461  $length = $this->eat8();
1462  }
1463  break;
1464  }
1465  default: {
1466  $length = $this->eat8();
1467  break;
1468  }
1469  }
1470  if ($length == 0) {
1471  return 0;
1472  }
1473  if ($length < 0) {
1474  return -1;
1475  }
1476  $this->dataStr = substr($this->dataStr, $length);
1477  }
1478  return 0;
1479  }
eatAn()
eatAn
Definition: qrcode.php:1344
eat8()
eat8
Definition: qrcode.php:1396
$hint
Encoding mode.
Definition: qrcode.php:315
eatKanji()
eatKanji
Definition: qrcode.php:1383
eatNum()
eatNum
Definition: qrcode.php:1312
identifyMode($pos)
identifyMode
Definition: qrcode.php:1287
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toUpper()

QRcode::toUpper ( )
protected

toUpper

Definition at line 1484 of file qrcode.php.

References $dataStr, and identifyMode().

Referenced by encodeString().

1484  {
1485  $stringLen = strlen($this->dataStr);
1486  $p = 0;
1487  while ($p < $stringLen) {
1488  $mode = $this->identifyMode(substr($this->dataStr, $p), $this->hint);
1489  if ($mode == QR_MODE_KJ) {
1490  $p += 2;
1491  } else {
1492  if ((ord($this->dataStr[$p]) >= ord('a')) AND (ord($this->dataStr[$p]) <= ord('z'))) {
1493  $this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32);
1494  }
1495  $p++;
1496  }
1497  }
1498  return $this->dataStr;
1499  }
$dataStr
Input data string.
Definition: qrcode.php:437
identifyMode($pos)
identifyMode
Definition: qrcode.php:1287
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeFormatInformation()

QRcode::writeFormatInformation (   $width,
$frame,
  $mask,
  $level 
)
protected

Write Format Information on frame and returns the number of black bits.

Parameters
$width(int) frame width
$frame(array) frame
$mask(array) masking mode
$level(int) error correction level
Returns
int blacks

Definition at line 941 of file qrcode.php.

References $format, $frame, $i, $level, $mask, $width, and getFormatInfo().

Referenced by makeMask(), and mask().

941  {
942  $blacks = 0;
943  $format = $this->getFormatInfo($mask, $level);
944  for ($i=0; $i<8; ++$i) {
945  if ($format & 1) {
946  $blacks += 2;
947  $v = 0x85;
948  } else {
949  $v = 0x84;
950  }
951  $frame[8][$width - 1 - $i] = chr($v);
952  if ($i < 6) {
953  $frame[$i][8] = chr($v);
954  } else {
955  $frame[$i + 1][8] = chr($v);
956  }
957  $format = $format >> 1;
958  }
959  for ($i=0; $i<7; ++$i) {
960  if ($format & 1) {
961  $blacks += 2;
962  $v = 0x85;
963  } else {
964  $v = 0x84;
965  }
966  $frame[$width - 7 + $i][8] = chr($v);
967  if ($i == 0) {
968  $frame[8][7] = chr($v);
969  } else {
970  $frame[8][6 - $i] = chr($v);
971  }
972  $format = $format >> 1;
973  }
974  return $blacks;
975  }
$format
Definition: metadata.php:141
$level
Levels of error correction.
Definition: qrcode.php:309
$mask
Definition: example_042.php:90
$width
Width.
Definition: qrcode.php:341
$i
Definition: disco.tpl.php:19
$frame
Frame.
Definition: qrcode.php:347
getFormatInfo($mask, $level)
Return BCH encoded format information pattern.
Definition: qrcode.php:2492
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $alignmentPattern

QRcode::$alignmentPattern
protected
Initial value:
= array(
array( 0, 0),
array( 0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0),
array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50),
array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48),
array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62),
array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58),
array(30, 58), array(34, 62), array(26, 50), array(30, 54), array(26, 52),
array(30, 56), array(34, 60), array(30, 58), array(34, 62), array(30, 54),
array(24, 50), array(28, 54), array(32, 58), array(26, 54), array(30, 58)
)

Array 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 589 of file qrcode.php.

◆ $anTable

QRcode::$anTable
protected
Initial value:
= array(
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1,
-1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
)

Alphabet-numeric convesion table.

Definition at line 463 of file qrcode.php.

◆ $b1

QRcode::$b1
protected

Value b1.

Definition at line 421 of file qrcode.php.

Referenced by getCode(), and getEccSpec().

◆ $barcode_array

QRcode::$barcode_array = array()
protected

Barcode array to be returned which is readable by TCPDF.

Definition at line 297 of file qrcode.php.

Referenced by __construct(), and getBarcodeArray().

◆ $bit

QRcode::$bit
protected

Single bit value.

Definition at line 371 of file qrcode.php.

Referenced by encodeMask().

◆ $blocks

QRcode::$blocks
protected

Blocks.

Definition at line 391 of file qrcode.php.

Referenced by getCode().

◆ $capacity

QRcode::$capacity
protected

Array Table of the capacity of symbols.

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

Definition at line 479 of file qrcode.php.

◆ $casesensitive

QRcode::$casesensitive = true
protected

Boolean flag, if true the input string will be converted to uppercase.

Definition at line 321 of file qrcode.php.

◆ $count

QRcode::$count
protected

Counter.

Definition at line 403 of file qrcode.php.

◆ $data

◆ $datacode

QRcode::$datacode = array()
protected

Data code.

Definition at line 379 of file qrcode.php.

◆ $dataLength

QRcode::$dataLength
protected

Data length.

Definition at line 409 of file qrcode.php.

Referenced by getCode().

◆ $dataStr

QRcode::$dataStr = ''
protected

Input data string.

Definition at line 437 of file qrcode.php.

Referenced by toUpper().

◆ $dir

QRcode::$dir
protected

Direction.

Definition at line 365 of file qrcode.php.

Referenced by getNextPosition().

◆ $ecccode

QRcode::$ecccode = array()
protected

Error correction code.

Definition at line 385 of file qrcode.php.

◆ $eccLength

QRcode::$eccLength
protected

Error correction length.

Definition at line 415 of file qrcode.php.

Referenced by encodeMask().

◆ $eccTable

QRcode::$eccTable
protected

Array Table of the error correction code (Reed-Solomon block).

See Table 12-16 (pp.30-36), JIS X0510:2004.

Definition at line 539 of file qrcode.php.

◆ $formatInfo

QRcode::$formatInfo
protected
Initial value:
= array(
array(0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976),
array(0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0),
array(0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed),
array(0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b)
)

Array Format information.

Definition at line 619 of file qrcode.php.

◆ $frame

◆ $frames

QRcode::$frames = array()
protected

Array of frames.

Definition at line 457 of file qrcode.php.

◆ $hint

QRcode::$hint = QR_MODE_8B
protected

Encoding mode.

Definition at line 315 of file qrcode.php.

Referenced by splitString().

◆ $items

◆ $lengthTableBits

QRcode::$lengthTableBits
protected
Initial value:
= array(
array(10, 12, 14),
array( 9, 11, 13),
array( 8, 16, 16),
array( 8, 10, 12)
)

Array Length indicator.

Definition at line 527 of file qrcode.php.

◆ $level

QRcode::$level = QR_ECLEVEL_L
protected

Levels of error correction.

See definitions for possible values.

Definition at line 309 of file qrcode.php.

Referenced by getDataLength(), getECCLength(), getEccSpec(), getFormatInfo(), getMinimumVersion(), makeMask(), mask(), and writeFormatInformation().

◆ $rsblocks

QRcode::$rsblocks = array()
protected

Reed-Solomon blocks.

Definition at line 397 of file qrcode.php.

◆ $rsitems

QRcode::$rsitems = array()
protected

Reed-Solomon items.

Definition at line 451 of file qrcode.php.

◆ $runLength

QRcode::$runLength = array()
protected

Run length.

Definition at line 429 of file qrcode.php.

◆ $structured

QRcode::$structured = 0
protected

Structured QR code (not supported yet).

Definition at line 327 of file qrcode.php.

◆ $version

QRcode::$version = 0
protected

QR code version.

Size of QRcode is defined as version. Version is from 1 to 40. Version 1 is 21*21 matrix. And 4 modules increases whenever 1 version increases. So version 40 is 177*177 matrix.

Definition at line 303 of file qrcode.php.

Referenced by createFrame(), encodeBitStream(), encodeMode8(), encodeModeAn(), encodeModeKanji(), encodeModeNum(), estimateBitStreamSize(), estimateVersion(), getDataLength(), getECCLength(), getEccSpec(), getRemainder(), getVersionPattern(), getWidth(), lengthIndicator(), lengthOfCode(), maximumWords(), newFrame(), and putAlignmentPattern().

◆ $versionPattern

QRcode::$versionPattern
protected
Initial value:
= array(
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
)

Array Version information pattern (BCH coded).

See Table 1 in Appendix D (pp.68) of JIS X0510:2004. size: [QRSPEC_VERSION_MAX - 6]

Definition at line 607 of file qrcode.php.

◆ $width

QRcode::$width
protected

◆ $x

QRcode::$x
protected

◆ $y


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