QRrawcode

The Gravity Forms QRrawcode class.

Defined (1)

The class is defined in the following location(s).

/includes/phpqrcode/phpqrcode.php  
  1. class QRrawcode { 
  2. public $version; 
  3. public $datacode = array(); 
  4. public $ecccode = array(); 
  5. public $blocks; 
  6. public $rsblocks = array(); //of RSblock 
  7. public $count; 
  8. public $dataLength; 
  9. public $eccLength; 
  10. public $b1; 
  11.  
  12. //---------------------------------------------------------------------- 
  13. public function __construct(QRinput $input) 
  14. $spec = array(0, 0, 0, 0, 0); 
  15.  
  16. $this->datacode = $input->getByteStream(); 
  17. if(is_null($this->datacode)) { 
  18. throw new Exception('null imput string'); 
  19.  
  20. QRspec::getEccSpec($input->getVersion(), $input->getErrorCorrectionLevel(), $spec); 
  21.  
  22. $this->version = $input->getVersion(); 
  23. $this->b1 = QRspec::rsBlockNum1($spec); 
  24. $this->dataLength = QRspec::rsDataLength($spec); 
  25. $this->eccLength = QRspec::rsEccLength($spec); 
  26. $this->ecccode = array_fill(0, $this->eccLength, 0); 
  27. $this->blocks = QRspec::rsBlockNum($spec); 
  28.  
  29. $ret = $this->init($spec); 
  30. if($ret < 0) { 
  31. throw new Exception('block alloc error'); 
  32. return null; 
  33.  
  34. $this->count = 0; 
  35.  
  36. //---------------------------------------------------------------------- 
  37. public function init(array $spec) 
  38. $dl = QRspec::rsDataCodes1($spec); 
  39. $el = QRspec::rsEccCodes1($spec); 
  40. $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); 
  41.  
  42.  
  43. $blockNo = 0; 
  44. $dataPos = 0; 
  45. $eccPos = 0; 
  46. for($i=0; $i<QRspec::rsBlockNum1($spec); $i++) { 
  47. $ecc = array_slice($this->ecccode, $eccPos); 
  48. $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); 
  49. $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc); 
  50.  
  51. $dataPos += $dl; 
  52. $eccPos += $el; 
  53. $blockNo++; 
  54.  
  55. if(QRspec::rsBlockNum2($spec) == 0) 
  56. return 0; 
  57.  
  58. $dl = QRspec::rsDataCodes2($spec); 
  59. $el = QRspec::rsEccCodes2($spec); 
  60. $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); 
  61.  
  62. if($rs == NULL) return -1; 
  63.  
  64. for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) { 
  65. $ecc = array_slice($this->ecccode, $eccPos); 
  66. $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); 
  67. $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc); 
  68.  
  69. $dataPos += $dl; 
  70. $eccPos += $el; 
  71. $blockNo++; 
  72.  
  73. return 0; 
  74.  
  75. //---------------------------------------------------------------------- 
  76. public function getCode() 
  77. $ret; 
  78.  
  79. if($this->count < $this->dataLength) { 
  80. $row = $this->count % $this->blocks; 
  81. $col = $this->count / $this->blocks; 
  82. if($col >= $this->rsblocks[0]->dataLength) { 
  83. $row += $this->b1; 
  84. $ret = $this->rsblocks[$row]->data[$col]; 
  85. } else if($this->count < $this->dataLength + $this->eccLength) { 
  86. $row = ($this->count - $this->dataLength) % $this->blocks; 
  87. $col = ($this->count - $this->dataLength) / $this->blocks; 
  88. $ret = $this->rsblocks[$row]->ecc[$col]; 
  89. } else { 
  90. return 0; 
  91. $this->count++; 
  92.  
  93. return $ret;