qrcode.php 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286
  1. <?php
  2. /****************************************************************************\
  3. qrcode.php - Generate QR Codes. MIT license.
  4. Copyright for portions of this project are held by Kreative Software, 2016-2018.
  5. All other copyright for the project are held by Donald Becker, 2019
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. DEALINGS IN THE SOFTWARE.
  21. \****************************************************************************/
  22. if (realpath(__FILE__) == realpath($_SERVER['SCRIPT_FILENAME'])) {
  23. $generator = new QRCode($_REQUEST['d'], $_REQUEST);
  24. $generator->output_image();
  25. exit(0);
  26. }
  27. class QRCode {
  28. private $data;
  29. private $options;
  30. public function __construct($data, $options = []) {
  31. $defaults = [
  32. 's' => 'qrl'
  33. ];
  34. if(!is_array($options)) $options = [];
  35. $this->data = $data;
  36. $this->options = array_merge($defaults, $options);
  37. }
  38. public function output_image() {
  39. $image = $this->render_image();
  40. header('Content-Type: image/png');
  41. imagepng($image);
  42. imagedestroy($image);
  43. }
  44. public function render_image() {
  45. list($code, $widths, $width, $height, $x, $y, $w, $h) = $this->encode_and_calculate_size($this->data, $this->options);
  46. $image = imagecreatetruecolor($width, $height);
  47. imagesavealpha($image, true);
  48. $bgcolor = (isset($this->options['bc']) ? $this->options['bc'] : 'FFFFFF');
  49. $bgcolor = $this->allocate_color($image, $bgcolor);
  50. imagefill($image, 0, 0, $bgcolor);
  51. $fgcolor = (isset($this->options['fc']) ? $this->options['fc'] : '000000');
  52. $fgcolor = $this->allocate_color($image, $fgcolor);
  53. $colors = array($bgcolor, $fgcolor);
  54. $density = (isset($this->options['md']) ? (float)$this->options['md'] : 1);
  55. list($width, $height) = $this->calculate_size($code, $widths);
  56. if ($width && $height) {
  57. $scale = min($w / $width, $h / $height);
  58. $scale = (($scale > 1) ? floor($scale) : 1);
  59. $x = floor($x + ($w - $width * $scale) / 2);
  60. $y = floor($y + ($h - $height * $scale) / 2);
  61. } else {
  62. $scale = 1;
  63. $x = floor($x + $w / 2);
  64. $y = floor($y + $h / 2);
  65. }
  66. $x += $code['q'][3] * $widths[0] * $scale;
  67. $y += $code['q'][0] * $widths[0] * $scale;
  68. $wh = $widths[1] * $scale;
  69. foreach ($code['b'] as $by => $row) {
  70. $y1 = $y + $by * $wh;
  71. foreach ($row as $bx => $color) {
  72. $x1 = $x + $bx * $wh;
  73. $mc = $colors[$color ? 1 : 0];
  74. $rx = floor($x1 + (1 - $density) * $wh / 2);
  75. $ry = floor($y1 + (1 - $density) * $wh / 2);
  76. $rw = ceil($wh * $density);
  77. $rh = ceil($wh * $density);
  78. imagefilledrectangle($image, $rx, $ry, $rx+$rw-1, $ry+$rh-1, $mc);
  79. }
  80. }
  81. return $image;
  82. }
  83. /* - - - - INTERNAL FUNCTIONS - - - - */
  84. private function encode_and_calculate_size($data, $options) {
  85. $code = $this->dispatch_encode($data, $options);
  86. $widths = array(
  87. (isset($options['wq']) ? (int)$options['wq'] : 1),
  88. (isset($options['wm']) ? (int)$options['wm'] : 1),
  89. );
  90. $size = $this->calculate_size($code, $widths);
  91. $dscale = 4;
  92. $scale = (isset($options['sf']) ? (float)$options['sf'] : $dscale);
  93. $scalex = (isset($options['sx']) ? (float)$options['sx'] : $scale);
  94. $scaley = (isset($options['sy']) ? (float)$options['sy'] : $scale);
  95. $dpadding = 0;
  96. $padding = (isset($options['p']) ? (int)$options['p'] : $dpadding);
  97. $vert = (isset($options['pv']) ? (int)$options['pv'] : $padding);
  98. $horiz = (isset($options['ph']) ? (int)$options['ph'] : $padding);
  99. $top = (isset($options['pt']) ? (int)$options['pt'] : $vert);
  100. $left = (isset($options['pl']) ? (int)$options['pl'] : $horiz);
  101. $right = (isset($options['pr']) ? (int)$options['pr'] : $horiz);
  102. $bottom = (isset($options['pb']) ? (int)$options['pb'] : $vert);
  103. $dwidth = ceil($size[0] * $scalex) + $left + $right;
  104. $dheight = ceil($size[1] * $scaley) + $top + $bottom;
  105. $iwidth = (isset($options['w']) ? (int)$options['w'] : $dwidth);
  106. $iheight = (isset($options['h']) ? (int)$options['h'] : $dheight);
  107. $swidth = $iwidth - $left - $right;
  108. $sheight = $iheight - $top - $bottom;
  109. return array($code, $widths, $iwidth, $iheight, $left, $top, $swidth, $sheight);
  110. }
  111. private function allocate_color($image, $color) {
  112. $color = preg_replace('/[^0-9A-Fa-f]/', '', $color);
  113. $r = hexdec(substr($color, 0, 2));
  114. $g = hexdec(substr($color, 2, 2));
  115. $b = hexdec(substr($color, 4, 2));
  116. return imagecolorallocate($image, $r, $g, $b);
  117. }
  118. /* - - - - DISPATCH - - - - */
  119. private function dispatch_encode($data, $options) {
  120. switch (strtolower(preg_replace('/[^A-Za-z0-9]/', '', $options['s']))) {
  121. case 'qrl': return $this->qr_encode($data, 0);
  122. case 'qrm': return $this->qr_encode($data, 1);
  123. case 'qrq': return $this->qr_encode($data, 2);
  124. case 'qrh': return $this->qr_encode($data, 3);
  125. default: return $this->qr_encode($data, 0);
  126. }
  127. return null;
  128. }
  129. /* - - - - MATRIX BARCODE RENDERER - - - - */
  130. private function calculate_size($code, $widths) {
  131. $width = (
  132. $code['q'][3] * $widths[0] +
  133. $code['s'][0] * $widths[1] +
  134. $code['q'][1] * $widths[0]
  135. );
  136. $height = (
  137. $code['q'][0] * $widths[0] +
  138. $code['s'][1] * $widths[1] +
  139. $code['q'][2] * $widths[0]
  140. );
  141. return array($width, $height);
  142. }
  143. /* - - - - QR ENCODER - - - - */
  144. private function qr_encode($data, $ecl) {
  145. list($mode, $vers, $ec, $data) = $this->qr_encode_data($data, $ecl);
  146. $data = $this->qr_encode_ec($data, $ec, $vers);
  147. list($size, $mtx) = $this->qr_create_matrix($vers, $data);
  148. list($mask, $mtx) = $this->qr_apply_best_mask($mtx, $size);
  149. $mtx = $this->qr_finalize_matrix($mtx, $size, $ecl, $mask, $vers);
  150. return array(
  151. 'q' => array(4, 4, 4, 4),
  152. 's' => array($size, $size),
  153. 'b' => $mtx
  154. );
  155. }
  156. private function qr_encode_data($data, $ecl) {
  157. $mode = $this->qr_detect_mode($data);
  158. $version = $this->qr_detect_version($data, $mode, $ecl);
  159. $version_group = (($version < 10) ? 0 : (($version < 27) ? 1 : 2));
  160. $ec_params = $this->qr_ec_params[($version - 1) * 4 + $ecl];
  161. /* Don't cut off mid-character if exceeding capacity. */
  162. $max_chars = $this->qr_capacity[$version - 1][$ecl][$mode];
  163. if ($mode == 3) $max_chars <<= 1;
  164. $data = substr($data, 0, $max_chars);
  165. /* Convert from character level to bit level. */
  166. switch ($mode) {
  167. case 0:
  168. $code = $this->qr_encode_numeric($data, $version_group);
  169. break;
  170. case 1:
  171. $code = $this->qr_encode_alphanumeric($data, $version_group);
  172. break;
  173. case 2:
  174. $code = $this->qr_encode_binary($data, $version_group);
  175. break;
  176. case 3:
  177. $code = $this->qr_encode_kanji($data, $version_group);
  178. break;
  179. }
  180. for ($i = 0; $i < 4; $i++) $code[] = 0;
  181. while (count($code) % 8) $code[] = 0;
  182. /* Convert from bit level to byte level. */
  183. $data = array();
  184. for ($i = 0, $n = count($code); $i < $n; $i += 8) {
  185. $byte = 0;
  186. if ($code[$i + 0]) $byte |= 0x80;
  187. if ($code[$i + 1]) $byte |= 0x40;
  188. if ($code[$i + 2]) $byte |= 0x20;
  189. if ($code[$i + 3]) $byte |= 0x10;
  190. if ($code[$i + 4]) $byte |= 0x08;
  191. if ($code[$i + 5]) $byte |= 0x04;
  192. if ($code[$i + 6]) $byte |= 0x02;
  193. if ($code[$i + 7]) $byte |= 0x01;
  194. $data[] = $byte;
  195. }
  196. for ($i = count($data), $a = 1, $n = $ec_params[0]; $i < $n; $i++, $a ^= 1) {
  197. $data[] = $a ? 236 : 17;
  198. }
  199. /* Return. */
  200. return array($mode, $version, $ec_params, $data);
  201. }
  202. private function qr_detect_mode($data) {
  203. $numeric = '/^[0-9]*$/';
  204. $alphanumeric = '/^[0-9A-Z .\/:$%*+-]*$/';
  205. $kanji = '/^([\x81-\x9F\xE0-\xEA][\x40-\xFC]|[\xEB][\x40-\xBF])*$/';
  206. if (preg_match($numeric, $data)) return 0;
  207. if (preg_match($alphanumeric, $data)) return 1;
  208. if (preg_match($kanji, $data)) return 3;
  209. return 2;
  210. }
  211. private function qr_detect_version($data, $mode, $ecl) {
  212. $length = strlen($data);
  213. if ($mode == 3) $length >>= 1;
  214. for ($v = 0; $v < 40; $v++) {
  215. if ($length <= $this->qr_capacity[$v][$ecl][$mode]) {
  216. return $v + 1;
  217. }
  218. }
  219. return 40;
  220. }
  221. private function qr_encode_numeric($data, $version_group) {
  222. $code = array(0, 0, 0, 1);
  223. $length = strlen($data);
  224. switch ($version_group) {
  225. case 2: /* 27 - 40 */
  226. $code[] = $length & 0x2000;
  227. $code[] = $length & 0x1000;
  228. case 1: /* 10 - 26 */
  229. $code[] = $length & 0x0800;
  230. $code[] = $length & 0x0400;
  231. case 0: /* 1 - 9 */
  232. $code[] = $length & 0x0200;
  233. $code[] = $length & 0x0100;
  234. $code[] = $length & 0x0080;
  235. $code[] = $length & 0x0040;
  236. $code[] = $length & 0x0020;
  237. $code[] = $length & 0x0010;
  238. $code[] = $length & 0x0008;
  239. $code[] = $length & 0x0004;
  240. $code[] = $length & 0x0002;
  241. $code[] = $length & 0x0001;
  242. }
  243. for ($i = 0; $i < $length; $i += 3) {
  244. $group = substr($data, $i, 3);
  245. switch (strlen($group)) {
  246. case 3:
  247. $code[] = $group & 0x200;
  248. $code[] = $group & 0x100;
  249. $code[] = $group & 0x080;
  250. case 2:
  251. $code[] = $group & 0x040;
  252. $code[] = $group & 0x020;
  253. $code[] = $group & 0x010;
  254. case 1:
  255. $code[] = $group & 0x008;
  256. $code[] = $group & 0x004;
  257. $code[] = $group & 0x002;
  258. $code[] = $group & 0x001;
  259. }
  260. }
  261. return $code;
  262. }
  263. private function qr_encode_alphanumeric($data, $version_group) {
  264. $alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:';
  265. $code = array(0, 0, 1, 0);
  266. $length = strlen($data);
  267. switch ($version_group) {
  268. case 2: /* 27 - 40 */
  269. $code[] = $length & 0x1000;
  270. $code[] = $length & 0x0800;
  271. case 1: /* 10 - 26 */
  272. $code[] = $length & 0x0400;
  273. $code[] = $length & 0x0200;
  274. case 0: /* 1 - 9 */
  275. $code[] = $length & 0x0100;
  276. $code[] = $length & 0x0080;
  277. $code[] = $length & 0x0040;
  278. $code[] = $length & 0x0020;
  279. $code[] = $length & 0x0010;
  280. $code[] = $length & 0x0008;
  281. $code[] = $length & 0x0004;
  282. $code[] = $length & 0x0002;
  283. $code[] = $length & 0x0001;
  284. }
  285. for ($i = 0; $i < $length; $i += 2) {
  286. $group = substr($data, $i, 2);
  287. if (strlen($group) > 1) {
  288. $c1 = strpos($alphabet, substr($group, 0, 1));
  289. $c2 = strpos($alphabet, substr($group, 1, 1));
  290. $ch = $c1 * 45 + $c2;
  291. $code[] = $ch & 0x400;
  292. $code[] = $ch & 0x200;
  293. $code[] = $ch & 0x100;
  294. $code[] = $ch & 0x080;
  295. $code[] = $ch & 0x040;
  296. $code[] = $ch & 0x020;
  297. $code[] = $ch & 0x010;
  298. $code[] = $ch & 0x008;
  299. $code[] = $ch & 0x004;
  300. $code[] = $ch & 0x002;
  301. $code[] = $ch & 0x001;
  302. } else {
  303. $ch = strpos($alphabet, $group);
  304. $code[] = $ch & 0x020;
  305. $code[] = $ch & 0x010;
  306. $code[] = $ch & 0x008;
  307. $code[] = $ch & 0x004;
  308. $code[] = $ch & 0x002;
  309. $code[] = $ch & 0x001;
  310. }
  311. }
  312. return $code;
  313. }
  314. private function qr_encode_binary($data, $version_group) {
  315. $code = array(0, 1, 0, 0);
  316. $length = strlen($data);
  317. switch ($version_group) {
  318. case 2: /* 27 - 40 */
  319. case 1: /* 10 - 26 */
  320. $code[] = $length & 0x8000;
  321. $code[] = $length & 0x4000;
  322. $code[] = $length & 0x2000;
  323. $code[] = $length & 0x1000;
  324. $code[] = $length & 0x0800;
  325. $code[] = $length & 0x0400;
  326. $code[] = $length & 0x0200;
  327. $code[] = $length & 0x0100;
  328. case 0: /* 1 - 9 */
  329. $code[] = $length & 0x0080;
  330. $code[] = $length & 0x0040;
  331. $code[] = $length & 0x0020;
  332. $code[] = $length & 0x0010;
  333. $code[] = $length & 0x0008;
  334. $code[] = $length & 0x0004;
  335. $code[] = $length & 0x0002;
  336. $code[] = $length & 0x0001;
  337. }
  338. for ($i = 0; $i < $length; $i++) {
  339. $ch = ord(substr($data, $i, 1));
  340. $code[] = $ch & 0x80;
  341. $code[] = $ch & 0x40;
  342. $code[] = $ch & 0x20;
  343. $code[] = $ch & 0x10;
  344. $code[] = $ch & 0x08;
  345. $code[] = $ch & 0x04;
  346. $code[] = $ch & 0x02;
  347. $code[] = $ch & 0x01;
  348. }
  349. return $code;
  350. }
  351. private function qr_encode_kanji($data, $version_group) {
  352. $code = array(1, 0, 0, 0);
  353. $length = strlen($data);
  354. switch ($version_group) {
  355. case 2: /* 27 - 40 */
  356. $code[] = $length & 0x1000;
  357. $code[] = $length & 0x0800;
  358. case 1: /* 10 - 26 */
  359. $code[] = $length & 0x0400;
  360. $code[] = $length & 0x0200;
  361. case 0: /* 1 - 9 */
  362. $code[] = $length & 0x0100;
  363. $code[] = $length & 0x0080;
  364. $code[] = $length & 0x0040;
  365. $code[] = $length & 0x0020;
  366. $code[] = $length & 0x0010;
  367. $code[] = $length & 0x0008;
  368. $code[] = $length & 0x0004;
  369. $code[] = $length & 0x0002;
  370. }
  371. for ($i = 0; $i < $length; $i += 2) {
  372. $group = substr($data, $i, 2);
  373. $c1 = ord(substr($group, 0, 1));
  374. $c2 = ord(substr($group, 1, 1));
  375. if ($c1 >= 0x81 && $c1 <= 0x9F && $c2 >= 0x40 && $c2 <= 0xFC) {
  376. $ch = ($c1 - 0x81) * 0xC0 + ($c2 - 0x40);
  377. } else if (
  378. ($c1 >= 0xE0 && $c1 <= 0xEA && $c2 >= 0x40 && $c2 <= 0xFC) ||
  379. ($c1 == 0xEB && $c2 >= 0x40 && $c2 <= 0xBF)
  380. ) {
  381. $ch = ($c1 - 0xC1) * 0xC0 + ($c2 - 0x40);
  382. } else {
  383. $ch = 0;
  384. }
  385. $code[] = $ch & 0x1000;
  386. $code[] = $ch & 0x0800;
  387. $code[] = $ch & 0x0400;
  388. $code[] = $ch & 0x0200;
  389. $code[] = $ch & 0x0100;
  390. $code[] = $ch & 0x0080;
  391. $code[] = $ch & 0x0040;
  392. $code[] = $ch & 0x0020;
  393. $code[] = $ch & 0x0010;
  394. $code[] = $ch & 0x0008;
  395. $code[] = $ch & 0x0004;
  396. $code[] = $ch & 0x0002;
  397. $code[] = $ch & 0x0001;
  398. }
  399. return $code;
  400. }
  401. private function qr_encode_ec($data, $ec_params, $version) {
  402. $blocks = $this->qr_ec_split($data, $ec_params);
  403. $ec_blocks = array();
  404. for ($i = 0, $n = count($blocks); $i < $n; $i++) {
  405. $ec_blocks[] = $this->qr_ec_divide($blocks[$i], $ec_params);
  406. }
  407. $data = $this->qr_ec_interleave($blocks);
  408. $ec_data = $this->qr_ec_interleave($ec_blocks);
  409. $code = array();
  410. foreach ($data as $ch) {
  411. $code[] = $ch & 0x80;
  412. $code[] = $ch & 0x40;
  413. $code[] = $ch & 0x20;
  414. $code[] = $ch & 0x10;
  415. $code[] = $ch & 0x08;
  416. $code[] = $ch & 0x04;
  417. $code[] = $ch & 0x02;
  418. $code[] = $ch & 0x01;
  419. }
  420. foreach ($ec_data as $ch) {
  421. $code[] = $ch & 0x80;
  422. $code[] = $ch & 0x40;
  423. $code[] = $ch & 0x20;
  424. $code[] = $ch & 0x10;
  425. $code[] = $ch & 0x08;
  426. $code[] = $ch & 0x04;
  427. $code[] = $ch & 0x02;
  428. $code[] = $ch & 0x01;
  429. }
  430. for ($n = $this->qr_remainder_bits[$version - 1]; $n > 0; $n--) {
  431. $code[] = 0;
  432. }
  433. return $code;
  434. }
  435. private function qr_ec_split($data, $ec_params) {
  436. $blocks = array();
  437. $offset = 0;
  438. for ($i = $ec_params[2], $length = $ec_params[3]; $i > 0; $i--) {
  439. $blocks[] = array_slice($data, $offset, $length);
  440. $offset += $length;
  441. }
  442. for ($i = $ec_params[4], $length = $ec_params[5]; $i > 0; $i--) {
  443. $blocks[] = array_slice($data, $offset, $length);
  444. $offset += $length;
  445. }
  446. return $blocks;
  447. }
  448. private function qr_ec_divide($data, $ec_params) {
  449. $num_data = count($data);
  450. $num_error = $ec_params[1];
  451. $generator = $this->qr_ec_polynomials[$num_error];
  452. $message = $data;
  453. for ($i = 0; $i < $num_error; $i++) {
  454. $message[] = 0;
  455. }
  456. for ($i = 0; $i < $num_data; $i++) {
  457. if ($message[$i]) {
  458. $leadterm = $this->qr_log[$message[$i]];
  459. for ($j = 0; $j <= $num_error; $j++) {
  460. $term = ($generator[$j] + $leadterm) % 255;
  461. $message[$i + $j] ^= $this->qr_exp[$term];
  462. }
  463. }
  464. }
  465. return array_slice($message, $num_data, $num_error);
  466. }
  467. private function qr_ec_interleave($blocks) {
  468. $data = array();
  469. $num_blocks = count($blocks);
  470. for ($offset = 0; true; $offset++) {
  471. $break = true;
  472. for ($i = 0; $i < $num_blocks; $i++) {
  473. if (isset($blocks[$i][$offset])) {
  474. $data[] = $blocks[$i][$offset];
  475. $break = false;
  476. }
  477. }
  478. if ($break) break;
  479. }
  480. return $data;
  481. }
  482. private function qr_create_matrix($version, $data) {
  483. $size = $version * 4 + 17;
  484. $matrix = array();
  485. for ($i = 0; $i < $size; $i++) {
  486. $row = array();
  487. for ($j = 0; $j < $size; $j++) {
  488. $row[] = 0;
  489. }
  490. $matrix[] = $row;
  491. }
  492. /* Finder patterns. */
  493. for ($i = 0; $i < 8; $i++) {
  494. for ($j = 0; $j < 8; $j++) {
  495. $m = (($i == 7 || $j == 7) ? 2 :
  496. (($i == 0 || $j == 0 || $i == 6 || $j == 6) ? 3 :
  497. (($i == 1 || $j == 1 || $i == 5 || $j == 5) ? 2 : 3)));
  498. $matrix[$i][$j] = $m;
  499. $matrix[$size - $i - 1][$j] = $m;
  500. $matrix[$i][$size - $j - 1] = $m;
  501. }
  502. }
  503. /* Alignment patterns. */
  504. if ($version >= 2) {
  505. $alignment = $this->qr_alignment_patterns[$version - 2];
  506. foreach ($alignment as $i) {
  507. foreach ($alignment as $j) {
  508. if (!$matrix[$i][$j]) {
  509. for ($ii = -2; $ii <= 2; $ii++) {
  510. for ($jj = -2; $jj <= 2; $jj++) {
  511. $m = (max(abs($ii), abs($jj)) & 1) ^ 3;
  512. $matrix[$i + $ii][$j + $jj] = $m;
  513. }
  514. }
  515. }
  516. }
  517. }
  518. }
  519. /* Timing patterns. */
  520. for ($i = $size - 9; $i >= 8; $i--) {
  521. $matrix[$i][6] = ($i & 1) ^ 3;
  522. $matrix[6][$i] = ($i & 1) ^ 3;
  523. }
  524. /* Dark module. Such an ominous name for such an innocuous thing. */
  525. $matrix[$size - 8][8] = 3;
  526. /* Format information area. */
  527. for ($i = 0; $i <= 8; $i++) {
  528. if (!$matrix[$i][8]) $matrix[$i][8] = 1;
  529. if (!$matrix[8][$i]) $matrix[8][$i] = 1;
  530. if ($i && !$matrix[$size - $i][8]) $matrix[$size - $i][8] = 1;
  531. if ($i && !$matrix[8][$size - $i]) $matrix[8][$size - $i] = 1;
  532. }
  533. /* Version information area. */
  534. if ($version >= 7) {
  535. for ($i = 9; $i < 12; $i++) {
  536. for ($j = 0; $j < 6; $j++) {
  537. $matrix[$size - $i][$j] = 1;
  538. $matrix[$j][$size - $i] = 1;
  539. }
  540. }
  541. }
  542. /* Data. */
  543. $col = $size - 1;
  544. $row = $size - 1;
  545. $dir = -1;
  546. $offset = 0;
  547. $length = count($data);
  548. while ($col > 0 && $offset < $length) {
  549. if (!$matrix[$row][$col]) {
  550. $matrix[$row][$col] = $data[$offset] ? 5 : 4;
  551. $offset++;
  552. }
  553. if (!$matrix[$row][$col - 1]) {
  554. $matrix[$row][$col - 1] = $data[$offset] ? 5 : 4;
  555. $offset++;
  556. }
  557. $row += $dir;
  558. if ($row < 0 || $row >= $size) {
  559. $dir = -$dir;
  560. $row += $dir;
  561. $col -= 2;
  562. if ($col == 6) $col--;
  563. }
  564. }
  565. return array($size, $matrix);
  566. }
  567. private function qr_apply_best_mask($matrix, $size) {
  568. $best_mask = 0;
  569. $best_matrix = $this->qr_apply_mask($matrix, $size, $best_mask);
  570. $best_penalty = $this->qr_penalty($best_matrix, $size);
  571. for ($test_mask = 1; $test_mask < 8; $test_mask++) {
  572. $test_matrix = $this->qr_apply_mask($matrix, $size, $test_mask);
  573. $test_penalty = $this->qr_penalty($test_matrix, $size);
  574. if ($test_penalty < $best_penalty) {
  575. $best_mask = $test_mask;
  576. $best_matrix = $test_matrix;
  577. $best_penalty = $test_penalty;
  578. }
  579. }
  580. return array($best_mask, $best_matrix);
  581. }
  582. private function qr_apply_mask($matrix, $size, $mask) {
  583. for ($i = 0; $i < $size; $i++) {
  584. for ($j = 0; $j < $size; $j++) {
  585. if ($matrix[$i][$j] >= 4) {
  586. if ($this->qr_mask($mask, $i, $j)) {
  587. $matrix[$i][$j] ^= 1;
  588. }
  589. }
  590. }
  591. }
  592. return $matrix;
  593. }
  594. private function qr_mask($mask, $r, $c) {
  595. switch ($mask) {
  596. case 0: return !( ($r + $c) % 2 );
  597. case 1: return !( ($r ) % 2 );
  598. case 2: return !( ( $c) % 3 );
  599. case 3: return !( ($r + $c) % 3 );
  600. case 4: return !( (floor(($r) / 2) + floor(($c) / 3)) % 2 );
  601. case 5: return !( ((($r * $c) % 2) + (($r * $c) % 3)) );
  602. case 6: return !( ((($r * $c) % 2) + (($r * $c) % 3)) % 2 );
  603. case 7: return !( ((($r + $c) % 2) + (($r * $c) % 3)) % 2 );
  604. }
  605. }
  606. private function qr_penalty(&$matrix, $size) {
  607. $score = $this->qr_penalty_1($matrix, $size);
  608. $score += $this->qr_penalty_2($matrix, $size);
  609. $score += $this->qr_penalty_3($matrix, $size);
  610. $score += $this->qr_penalty_4($matrix, $size);
  611. return $score;
  612. }
  613. private function qr_penalty_1(&$matrix, $size) {
  614. $score = 0;
  615. for ($i = 0; $i < $size; $i++) {
  616. $rowvalue = 0;
  617. $rowcount = 0;
  618. $colvalue = 0;
  619. $colcount = 0;
  620. for ($j = 0; $j < $size; $j++) {
  621. $rv = ($matrix[$i][$j] == 5 || $matrix[$i][$j] == 3) ? 1 : 0;
  622. $cv = ($matrix[$j][$i] == 5 || $matrix[$j][$i] == 3) ? 1 : 0;
  623. if ($rv == $rowvalue) {
  624. $rowcount++;
  625. } else {
  626. if ($rowcount >= 5) $score += $rowcount - 2;
  627. $rowvalue = $rv;
  628. $rowcount = 1;
  629. }
  630. if ($cv == $colvalue) {
  631. $colcount++;
  632. } else {
  633. if ($colcount >= 5) $score += $colcount - 2;
  634. $colvalue = $cv;
  635. $colcount = 1;
  636. }
  637. }
  638. if ($rowcount >= 5) $score += $rowcount - 2;
  639. if ($colcount >= 5) $score += $colcount - 2;
  640. }
  641. return $score;
  642. }
  643. private function qr_penalty_2(&$matrix, $size) {
  644. $score = 0;
  645. for ($i = 1; $i < $size; $i++) {
  646. for ($j = 1; $j < $size; $j++) {
  647. $v1 = $matrix[$i - 1][$j - 1];
  648. $v2 = $matrix[$i - 1][$j ];
  649. $v3 = $matrix[$i ][$j - 1];
  650. $v4 = $matrix[$i ][$j ];
  651. $v1 = ($v1 == 5 || $v1 == 3) ? 1 : 0;
  652. $v2 = ($v2 == 5 || $v2 == 3) ? 1 : 0;
  653. $v3 = ($v3 == 5 || $v3 == 3) ? 1 : 0;
  654. $v4 = ($v4 == 5 || $v4 == 3) ? 1 : 0;
  655. if ($v1 == $v2 && $v2 == $v3 && $v3 == $v4) $score += 3;
  656. }
  657. }
  658. return $score;
  659. }
  660. private function qr_penalty_3(&$matrix, $size) {
  661. $score = 0;
  662. for ($i = 0; $i < $size; $i++) {
  663. $rowvalue = 0;
  664. $colvalue = 0;
  665. for ($j = 0; $j < 11; $j++) {
  666. $rv = ($matrix[$i][$j] == 5 || $matrix[$i][$j] == 3) ? 1 : 0;
  667. $cv = ($matrix[$j][$i] == 5 || $matrix[$j][$i] == 3) ? 1 : 0;
  668. $rowvalue = (($rowvalue << 1) & 0x7FF) | $rv;
  669. $colvalue = (($colvalue << 1) & 0x7FF) | $cv;
  670. }
  671. if ($rowvalue == 0x5D0 || $rowvalue == 0x5D) $score += 40;
  672. if ($colvalue == 0x5D0 || $colvalue == 0x5D) $score += 40;
  673. for ($j = 11; $j < $size; $j++) {
  674. $rv = ($matrix[$i][$j] == 5 || $matrix[$i][$j] == 3) ? 1 : 0;
  675. $cv = ($matrix[$j][$i] == 5 || $matrix[$j][$i] == 3) ? 1 : 0;
  676. $rowvalue = (($rowvalue << 1) & 0x7FF) | $rv;
  677. $colvalue = (($colvalue << 1) & 0x7FF) | $cv;
  678. if ($rowvalue == 0x5D0 || $rowvalue == 0x5D) $score += 40;
  679. if ($colvalue == 0x5D0 || $colvalue == 0x5D) $score += 40;
  680. }
  681. }
  682. return $score;
  683. }
  684. private function qr_penalty_4(&$matrix, $size) {
  685. $dark = 0;
  686. for ($i = 0; $i < $size; $i++) {
  687. for ($j = 0; $j < $size; $j++) {
  688. if ($matrix[$i][$j] == 5 || $matrix[$i][$j] == 3) {
  689. $dark++;
  690. }
  691. }
  692. }
  693. $dark *= 20;
  694. $dark /= $size * $size;
  695. $a = abs(floor($dark) - 10);
  696. $b = abs(ceil($dark) - 10);
  697. return min($a, $b) * 10;
  698. }
  699. private function qr_finalize_matrix($matrix, $size, $ecl, $mask, $version) {
  700. /* Format Info */
  701. $format = $this->qr_format_info[$ecl * 8 + $mask];
  702. $matrix[8][0] = $format[0];
  703. $matrix[8][1] = $format[1];
  704. $matrix[8][2] = $format[2];
  705. $matrix[8][3] = $format[3];
  706. $matrix[8][4] = $format[4];
  707. $matrix[8][5] = $format[5];
  708. $matrix[8][7] = $format[6];
  709. $matrix[8][8] = $format[7];
  710. $matrix[7][8] = $format[8];
  711. $matrix[5][8] = $format[9];
  712. $matrix[4][8] = $format[10];
  713. $matrix[3][8] = $format[11];
  714. $matrix[2][8] = $format[12];
  715. $matrix[1][8] = $format[13];
  716. $matrix[0][8] = $format[14];
  717. $matrix[$size - 1][8] = $format[0];
  718. $matrix[$size - 2][8] = $format[1];
  719. $matrix[$size - 3][8] = $format[2];
  720. $matrix[$size - 4][8] = $format[3];
  721. $matrix[$size - 5][8] = $format[4];
  722. $matrix[$size - 6][8] = $format[5];
  723. $matrix[$size - 7][8] = $format[6];
  724. $matrix[8][$size - 8] = $format[7];
  725. $matrix[8][$size - 7] = $format[8];
  726. $matrix[8][$size - 6] = $format[9];
  727. $matrix[8][$size - 5] = $format[10];
  728. $matrix[8][$size - 4] = $format[11];
  729. $matrix[8][$size - 3] = $format[12];
  730. $matrix[8][$size - 2] = $format[13];
  731. $matrix[8][$size - 1] = $format[14];
  732. /* Version Info */
  733. if ($version >= 7) {
  734. $version = $this->qr_version_info[$version - 7];
  735. for ($i = 0; $i < 18; $i++) {
  736. $r = $size - 9 - ($i % 3);
  737. $c = 5 - floor($i / 3);
  738. $matrix[$r][$c] = $version[$i];
  739. $matrix[$c][$r] = $version[$i];
  740. }
  741. }
  742. /* Patterns & Data */
  743. for ($i = 0; $i < $size; $i++) {
  744. for ($j = 0; $j < $size; $j++) {
  745. $matrix[$i][$j] &= 1;
  746. }
  747. }
  748. return $matrix;
  749. }
  750. /* maximum encodable characters = $qr_capacity [ (version - 1) ] */
  751. /* [ (0 for L, 1 for M, 2 for Q, 3 for H) ] */
  752. /* [ (0 for numeric, 1 for alpha, 2 for binary, 3 for kanji) ] */
  753. private $qr_capacity = array(
  754. array(array( 41, 25, 17, 10), array( 34, 20, 14, 8), array( 27, 16, 11, 7), array( 17, 10, 7, 4)),
  755. array(array( 77, 47, 32, 20), array( 63, 38, 26, 16), array( 48, 29, 20, 12), array( 34, 20, 14, 8)),
  756. array(array( 127, 77, 53, 32), array( 101, 61, 42, 26), array( 77, 47, 32, 20), array( 58, 35, 24, 15)),
  757. array(array( 187, 114, 78, 48), array( 149, 90, 62, 38), array( 111, 67, 46, 28), array( 82, 50, 34, 21)),
  758. array(array( 255, 154, 106, 65), array( 202, 122, 84, 52), array( 144, 87, 60, 37), array( 106, 64, 44, 27)),
  759. array(array( 322, 195, 134, 82), array( 255, 154, 106, 65), array( 178, 108, 74, 45), array( 139, 84, 58, 36)),
  760. array(array( 370, 224, 154, 95), array( 293, 178, 122, 75), array( 207, 125, 86, 53), array( 154, 93, 64, 39)),
  761. array(array( 461, 279, 192, 118), array( 365, 221, 152, 93), array( 259, 157, 108, 66), array( 202, 122, 84, 52)),
  762. array(array( 552, 335, 230, 141), array( 432, 262, 180, 111), array( 312, 189, 130, 80), array( 235, 143, 98, 60)),
  763. array(array( 652, 395, 271, 167), array( 513, 311, 213, 131), array( 364, 221, 151, 93), array( 288, 174, 119, 74)),
  764. array(array( 772, 468, 321, 198), array( 604, 366, 251, 155), array( 427, 259, 177, 109), array( 331, 200, 137, 85)),
  765. array(array( 883, 535, 367, 226), array( 691, 419, 287, 177), array( 489, 296, 203, 125), array( 374, 227, 155, 96)),
  766. array(array(1022, 619, 425, 262), array( 796, 483, 331, 204), array( 580, 352, 241, 149), array( 427, 259, 177, 109)),
  767. array(array(1101, 667, 458, 282), array( 871, 528, 362, 223), array( 621, 376, 258, 159), array( 468, 283, 194, 120)),
  768. array(array(1250, 758, 520, 320), array( 991, 600, 412, 254), array( 703, 426, 292, 180), array( 530, 321, 220, 136)),
  769. array(array(1408, 854, 586, 361), array(1082, 656, 450, 277), array( 775, 470, 322, 198), array( 602, 365, 250, 154)),
  770. array(array(1548, 938, 644, 397), array(1212, 734, 504, 310), array( 876, 531, 364, 224), array( 674, 408, 280, 173)),
  771. array(array(1725, 1046, 718, 442), array(1346, 816, 560, 345), array( 948, 574, 394, 243), array( 746, 452, 310, 191)),
  772. array(array(1903, 1153, 792, 488), array(1500, 909, 624, 384), array(1063, 644, 442, 272), array( 813, 493, 338, 208)),
  773. array(array(2061, 1249, 858, 528), array(1600, 970, 666, 410), array(1159, 702, 482, 297), array( 919, 557, 382, 235)),
  774. array(array(2232, 1352, 929, 572), array(1708, 1035, 711, 438), array(1224, 742, 509, 314), array( 969, 587, 403, 248)),
  775. array(array(2409, 1460, 1003, 618), array(1872, 1134, 779, 480), array(1358, 823, 565, 348), array(1056, 640, 439, 270)),
  776. array(array(2620, 1588, 1091, 672), array(2059, 1248, 857, 528), array(1468, 890, 611, 376), array(1108, 672, 461, 284)),
  777. array(array(2812, 1704, 1171, 721), array(2188, 1326, 911, 561), array(1588, 963, 661, 407), array(1228, 744, 511, 315)),
  778. array(array(3057, 1853, 1273, 784), array(2395, 1451, 997, 614), array(1718, 1041, 715, 440), array(1286, 779, 535, 330)),
  779. array(array(3283, 1990, 1367, 842), array(2544, 1542, 1059, 652), array(1804, 1094, 751, 462), array(1425, 864, 593, 365)),
  780. array(array(3517, 2132, 1465, 902), array(2701, 1637, 1125, 692), array(1933, 1172, 805, 496), array(1501, 910, 625, 385)),
  781. array(array(3669, 2223, 1528, 940), array(2857, 1732, 1190, 732), array(2085, 1263, 868, 534), array(1581, 958, 658, 405)),
  782. array(array(3909, 2369, 1628, 1002), array(3035, 1839, 1264, 778), array(2181, 1322, 908, 559), array(1677, 1016, 698, 430)),
  783. array(array(4158, 2520, 1732, 1066), array(3289, 1994, 1370, 843), array(2358, 1429, 982, 604), array(1782, 1080, 742, 457)),
  784. array(array(4417, 2677, 1840, 1132), array(3486, 2113, 1452, 894), array(2473, 1499, 1030, 634), array(1897, 1150, 790, 486)),
  785. array(array(4686, 2840, 1952, 1201), array(3693, 2238, 1538, 947), array(2670, 1618, 1112, 684), array(2022, 1226, 842, 518)),
  786. array(array(4965, 3009, 2068, 1273), array(3909, 2369, 1628, 1002), array(2805, 1700, 1168, 719), array(2157, 1307, 898, 553)),
  787. array(array(5253, 3183, 2188, 1347), array(4134, 2506, 1722, 1060), array(2949, 1787, 1228, 756), array(2301, 1394, 958, 590)),
  788. array(array(5529, 3351, 2303, 1417), array(4343, 2632, 1809, 1113), array(3081, 1867, 1283, 790), array(2361, 1431, 983, 605)),
  789. array(array(5836, 3537, 2431, 1496), array(4588, 2780, 1911, 1176), array(3244, 1966, 1351, 832), array(2524, 1530, 1051, 647)),
  790. array(array(6153, 3729, 2563, 1577), array(4775, 2894, 1989, 1224), array(3417, 2071, 1423, 876), array(2625, 1591, 1093, 673)),
  791. array(array(6479, 3927, 2699, 1661), array(5039, 3054, 2099, 1292), array(3599, 2181, 1499, 923), array(2735, 1658, 1139, 701)),
  792. array(array(6743, 4087, 2809, 1729), array(5313, 3220, 2213, 1362), array(3791, 2298, 1579, 972), array(2927, 1774, 1219, 750)),
  793. array(array(7089, 4296, 2953, 1817), array(5596, 3391, 2331, 1435), array(3993, 2420, 1663, 1024), array(3057, 1852, 1273, 784)),
  794. );
  795. /* $qr_ec_params[ */
  796. /* 4 * (version - 1) + (0 for L, 1 for M, 2 for Q, 3 for H) */
  797. /* ] = array( */
  798. /* total number of data codewords, */
  799. /* number of error correction codewords per block, */
  800. /* number of blocks in first group, */
  801. /* number of data codewords per block in first group, */
  802. /* number of blocks in second group, */
  803. /* number of data codewords per block in second group */
  804. /* ); */
  805. private $qr_ec_params = array(
  806. array( 19, 7, 1, 19, 0, 0 ),
  807. array( 16, 10, 1, 16, 0, 0 ),
  808. array( 13, 13, 1, 13, 0, 0 ),
  809. array( 9, 17, 1, 9, 0, 0 ),
  810. array( 34, 10, 1, 34, 0, 0 ),
  811. array( 28, 16, 1, 28, 0, 0 ),
  812. array( 22, 22, 1, 22, 0, 0 ),
  813. array( 16, 28, 1, 16, 0, 0 ),
  814. array( 55, 15, 1, 55, 0, 0 ),
  815. array( 44, 26, 1, 44, 0, 0 ),
  816. array( 34, 18, 2, 17, 0, 0 ),
  817. array( 26, 22, 2, 13, 0, 0 ),
  818. array( 80, 20, 1, 80, 0, 0 ),
  819. array( 64, 18, 2, 32, 0, 0 ),
  820. array( 48, 26, 2, 24, 0, 0 ),
  821. array( 36, 16, 4, 9, 0, 0 ),
  822. array( 108, 26, 1, 108, 0, 0 ),
  823. array( 86, 24, 2, 43, 0, 0 ),
  824. array( 62, 18, 2, 15, 2, 16 ),
  825. array( 46, 22, 2, 11, 2, 12 ),
  826. array( 136, 18, 2, 68, 0, 0 ),
  827. array( 108, 16, 4, 27, 0, 0 ),
  828. array( 76, 24, 4, 19, 0, 0 ),
  829. array( 60, 28, 4, 15, 0, 0 ),
  830. array( 156, 20, 2, 78, 0, 0 ),
  831. array( 124, 18, 4, 31, 0, 0 ),
  832. array( 88, 18, 2, 14, 4, 15 ),
  833. array( 66, 26, 4, 13, 1, 14 ),
  834. array( 194, 24, 2, 97, 0, 0 ),
  835. array( 154, 22, 2, 38, 2, 39 ),
  836. array( 110, 22, 4, 18, 2, 19 ),
  837. array( 86, 26, 4, 14, 2, 15 ),
  838. array( 232, 30, 2, 116, 0, 0 ),
  839. array( 182, 22, 3, 36, 2, 37 ),
  840. array( 132, 20, 4, 16, 4, 17 ),
  841. array( 100, 24, 4, 12, 4, 13 ),
  842. array( 274, 18, 2, 68, 2, 69 ),
  843. array( 216, 26, 4, 43, 1, 44 ),
  844. array( 154, 24, 6, 19, 2, 20 ),
  845. array( 122, 28, 6, 15, 2, 16 ),
  846. array( 324, 20, 4, 81, 0, 0 ),
  847. array( 254, 30, 1, 50, 4, 51 ),
  848. array( 180, 28, 4, 22, 4, 23 ),
  849. array( 140, 24, 3, 12, 8, 13 ),
  850. array( 370, 24, 2, 92, 2, 93 ),
  851. array( 290, 22, 6, 36, 2, 37 ),
  852. array( 206, 26, 4, 20, 6, 21 ),
  853. array( 158, 28, 7, 14, 4, 15 ),
  854. array( 428, 26, 4, 107, 0, 0 ),
  855. array( 334, 22, 8, 37, 1, 38 ),
  856. array( 244, 24, 8, 20, 4, 21 ),
  857. array( 180, 22, 12, 11, 4, 12 ),
  858. array( 461, 30, 3, 115, 1, 116 ),
  859. array( 365, 24, 4, 40, 5, 41 ),
  860. array( 261, 20, 11, 16, 5, 17 ),
  861. array( 197, 24, 11, 12, 5, 13 ),
  862. array( 523, 22, 5, 87, 1, 88 ),
  863. array( 415, 24, 5, 41, 5, 42 ),
  864. array( 295, 30, 5, 24, 7, 25 ),
  865. array( 223, 24, 11, 12, 7, 13 ),
  866. array( 589, 24, 5, 98, 1, 99 ),
  867. array( 453, 28, 7, 45, 3, 46 ),
  868. array( 325, 24, 15, 19, 2, 20 ),
  869. array( 253, 30, 3, 15, 13, 16 ),
  870. array( 647, 28, 1, 107, 5, 108 ),
  871. array( 507, 28, 10, 46, 1, 47 ),
  872. array( 367, 28, 1, 22, 15, 23 ),
  873. array( 283, 28, 2, 14, 17, 15 ),
  874. array( 721, 30, 5, 120, 1, 121 ),
  875. array( 563, 26, 9, 43, 4, 44 ),
  876. array( 397, 28, 17, 22, 1, 23 ),
  877. array( 313, 28, 2, 14, 19, 15 ),
  878. array( 795, 28, 3, 113, 4, 114 ),
  879. array( 627, 26, 3, 44, 11, 45 ),
  880. array( 445, 26, 17, 21, 4, 22 ),
  881. array( 341, 26, 9, 13, 16, 14 ),
  882. array( 861, 28, 3, 107, 5, 108 ),
  883. array( 669, 26, 3, 41, 13, 42 ),
  884. array( 485, 30, 15, 24, 5, 25 ),
  885. array( 385, 28, 15, 15, 10, 16 ),
  886. array( 932, 28, 4, 116, 4, 117 ),
  887. array( 714, 26, 17, 42, 0, 0 ),
  888. array( 512, 28, 17, 22, 6, 23 ),
  889. array( 406, 30, 19, 16, 6, 17 ),
  890. array( 1006, 28, 2, 111, 7, 112 ),
  891. array( 782, 28, 17, 46, 0, 0 ),
  892. array( 568, 30, 7, 24, 16, 25 ),
  893. array( 442, 24, 34, 13, 0, 0 ),
  894. array( 1094, 30, 4, 121, 5, 122 ),
  895. array( 860, 28, 4, 47, 14, 48 ),
  896. array( 614, 30, 11, 24, 14, 25 ),
  897. array( 464, 30, 16, 15, 14, 16 ),
  898. array( 1174, 30, 6, 117, 4, 118 ),
  899. array( 914, 28, 6, 45, 14, 46 ),
  900. array( 664, 30, 11, 24, 16, 25 ),
  901. array( 514, 30, 30, 16, 2, 17 ),
  902. array( 1276, 26, 8, 106, 4, 107 ),
  903. array( 1000, 28, 8, 47, 13, 48 ),
  904. array( 718, 30, 7, 24, 22, 25 ),
  905. array( 538, 30, 22, 15, 13, 16 ),
  906. array( 1370, 28, 10, 114, 2, 115 ),
  907. array( 1062, 28, 19, 46, 4, 47 ),
  908. array( 754, 28, 28, 22, 6, 23 ),
  909. array( 596, 30, 33, 16, 4, 17 ),
  910. array( 1468, 30, 8, 122, 4, 123 ),
  911. array( 1128, 28, 22, 45, 3, 46 ),
  912. array( 808, 30, 8, 23, 26, 24 ),
  913. array( 628, 30, 12, 15, 28, 16 ),
  914. array( 1531, 30, 3, 117, 10, 118 ),
  915. array( 1193, 28, 3, 45, 23, 46 ),
  916. array( 871, 30, 4, 24, 31, 25 ),
  917. array( 661, 30, 11, 15, 31, 16 ),
  918. array( 1631, 30, 7, 116, 7, 117 ),
  919. array( 1267, 28, 21, 45, 7, 46 ),
  920. array( 911, 30, 1, 23, 37, 24 ),
  921. array( 701, 30, 19, 15, 26, 16 ),
  922. array( 1735, 30, 5, 115, 10, 116 ),
  923. array( 1373, 28, 19, 47, 10, 48 ),
  924. array( 985, 30, 15, 24, 25, 25 ),
  925. array( 745, 30, 23, 15, 25, 16 ),
  926. array( 1843, 30, 13, 115, 3, 116 ),
  927. array( 1455, 28, 2, 46, 29, 47 ),
  928. array( 1033, 30, 42, 24, 1, 25 ),
  929. array( 793, 30, 23, 15, 28, 16 ),
  930. array( 1955, 30, 17, 115, 0, 0 ),
  931. array( 1541, 28, 10, 46, 23, 47 ),
  932. array( 1115, 30, 10, 24, 35, 25 ),
  933. array( 845, 30, 19, 15, 35, 16 ),
  934. array( 2071, 30, 17, 115, 1, 116 ),
  935. array( 1631, 28, 14, 46, 21, 47 ),
  936. array( 1171, 30, 29, 24, 19, 25 ),
  937. array( 901, 30, 11, 15, 46, 16 ),
  938. array( 2191, 30, 13, 115, 6, 116 ),
  939. array( 1725, 28, 14, 46, 23, 47 ),
  940. array( 1231, 30, 44, 24, 7, 25 ),
  941. array( 961, 30, 59, 16, 1, 17 ),
  942. array( 2306, 30, 12, 121, 7, 122 ),
  943. array( 1812, 28, 12, 47, 26, 48 ),
  944. array( 1286, 30, 39, 24, 14, 25 ),
  945. array( 986, 30, 22, 15, 41, 16 ),
  946. array( 2434, 30, 6, 121, 14, 122 ),
  947. array( 1914, 28, 6, 47, 34, 48 ),
  948. array( 1354, 30, 46, 24, 10, 25 ),
  949. array( 1054, 30, 2, 15, 64, 16 ),
  950. array( 2566, 30, 17, 122, 4, 123 ),
  951. array( 1992, 28, 29, 46, 14, 47 ),
  952. array( 1426, 30, 49, 24, 10, 25 ),
  953. array( 1096, 30, 24, 15, 46, 16 ),
  954. array( 2702, 30, 4, 122, 18, 123 ),
  955. array( 2102, 28, 13, 46, 32, 47 ),
  956. array( 1502, 30, 48, 24, 14, 25 ),
  957. array( 1142, 30, 42, 15, 32, 16 ),
  958. array( 2812, 30, 20, 117, 4, 118 ),
  959. array( 2216, 28, 40, 47, 7, 48 ),
  960. array( 1582, 30, 43, 24, 22, 25 ),
  961. array( 1222, 30, 10, 15, 67, 16 ),
  962. array( 2956, 30, 19, 118, 6, 119 ),
  963. array( 2334, 28, 18, 47, 31, 48 ),
  964. array( 1666, 30, 34, 24, 34, 25 ),
  965. array( 1276, 30, 20, 15, 61, 16 ),
  966. );
  967. private $qr_ec_polynomials = array(
  968. 7 => array(
  969. 0, 87, 229, 146, 149, 238, 102, 21
  970. ),
  971. 10 => array(
  972. 0, 251, 67, 46, 61, 118, 70, 64, 94, 32, 45
  973. ),
  974. 13 => array(
  975. 0, 74, 152, 176, 100, 86, 100,
  976. 106, 104, 130, 218, 206, 140, 78
  977. ),
  978. 15 => array(
  979. 0, 8, 183, 61, 91, 202, 37, 51,
  980. 58, 58, 237, 140, 124, 5, 99, 105
  981. ),
  982. 16 => array(
  983. 0, 120, 104, 107, 109, 102, 161, 76, 3,
  984. 91, 191, 147, 169, 182, 194, 225, 120
  985. ),
  986. 17 => array(
  987. 0, 43, 139, 206, 78, 43, 239, 123, 206,
  988. 214, 147, 24, 99, 150, 39, 243, 163, 136
  989. ),
  990. 18 => array(
  991. 0, 215, 234, 158, 94, 184, 97, 118, 170, 79,
  992. 187, 152, 148, 252, 179, 5, 98, 96, 153
  993. ),
  994. 20 => array(
  995. 0, 17, 60, 79, 50, 61, 163, 26, 187, 202, 180,
  996. 221, 225, 83, 239, 156, 164, 212, 212, 188, 190
  997. ),
  998. 22 => array(
  999. 0, 210, 171, 247, 242, 93, 230, 14, 109, 221, 53, 200,
  1000. 74, 8, 172, 98, 80, 219, 134, 160, 105, 165, 231
  1001. ),
  1002. 24 => array(
  1003. 0, 229, 121, 135, 48, 211, 117, 251, 126, 159, 180, 169,
  1004. 152, 192, 226, 228, 218, 111, 0, 117, 232, 87, 96, 227, 21
  1005. ),
  1006. 26 => array(
  1007. 0, 173, 125, 158, 2, 103, 182, 118, 17,
  1008. 145, 201, 111, 28, 165, 53, 161, 21, 245,
  1009. 142, 13, 102, 48, 227, 153, 145, 218, 70
  1010. ),
  1011. 28 => array(
  1012. 0, 168, 223, 200, 104, 224, 234, 108, 180,
  1013. 110, 190, 195, 147, 205, 27, 232, 201, 21, 43,
  1014. 245, 87, 42, 195, 212, 119, 242, 37, 9, 123
  1015. ),
  1016. 30 => array(
  1017. 0, 41, 173, 145, 152, 216, 31, 179, 182, 50, 48,
  1018. 110, 86, 239, 96, 222, 125, 42, 173, 226, 193,
  1019. 224, 130, 156, 37, 251, 216, 238, 40, 192, 180
  1020. ),
  1021. );
  1022. private $qr_log = array(
  1023. 0, 0, 1, 25, 2, 50, 26, 198,
  1024. 3, 223, 51, 238, 27, 104, 199, 75,
  1025. 4, 100, 224, 14, 52, 141, 239, 129,
  1026. 28, 193, 105, 248, 200, 8, 76, 113,
  1027. 5, 138, 101, 47, 225, 36, 15, 33,
  1028. 53, 147, 142, 218, 240, 18, 130, 69,
  1029. 29, 181, 194, 125, 106, 39, 249, 185,
  1030. 201, 154, 9, 120, 77, 228, 114, 166,
  1031. 6, 191, 139, 98, 102, 221, 48, 253,
  1032. 226, 152, 37, 179, 16, 145, 34, 136,
  1033. 54, 208, 148, 206, 143, 150, 219, 189,
  1034. 241, 210, 19, 92, 131, 56, 70, 64,
  1035. 30, 66, 182, 163, 195, 72, 126, 110,
  1036. 107, 58, 40, 84, 250, 133, 186, 61,
  1037. 202, 94, 155, 159, 10, 21, 121, 43,
  1038. 78, 212, 229, 172, 115, 243, 167, 87,
  1039. 7, 112, 192, 247, 140, 128, 99, 13,
  1040. 103, 74, 222, 237, 49, 197, 254, 24,
  1041. 227, 165, 153, 119, 38, 184, 180, 124,
  1042. 17, 68, 146, 217, 35, 32, 137, 46,
  1043. 55, 63, 209, 91, 149, 188, 207, 205,
  1044. 144, 135, 151, 178, 220, 252, 190, 97,
  1045. 242, 86, 211, 171, 20, 42, 93, 158,
  1046. 132, 60, 57, 83, 71, 109, 65, 162,
  1047. 31, 45, 67, 216, 183, 123, 164, 118,
  1048. 196, 23, 73, 236, 127, 12, 111, 246,
  1049. 108, 161, 59, 82, 41, 157, 85, 170,
  1050. 251, 96, 134, 177, 187, 204, 62, 90,
  1051. 203, 89, 95, 176, 156, 169, 160, 81,
  1052. 11, 245, 22, 235, 122, 117, 44, 215,
  1053. 79, 174, 213, 233, 230, 231, 173, 232,
  1054. 116, 214, 244, 234, 168, 80, 88, 175,
  1055. );
  1056. private $qr_exp = array(
  1057. 1, 2, 4, 8, 16, 32, 64, 128,
  1058. 29, 58, 116, 232, 205, 135, 19, 38,
  1059. 76, 152, 45, 90, 180, 117, 234, 201,
  1060. 143, 3, 6, 12, 24, 48, 96, 192,
  1061. 157, 39, 78, 156, 37, 74, 148, 53,
  1062. 106, 212, 181, 119, 238, 193, 159, 35,
  1063. 70, 140, 5, 10, 20, 40, 80, 160,
  1064. 93, 186, 105, 210, 185, 111, 222, 161,
  1065. 95, 190, 97, 194, 153, 47, 94, 188,
  1066. 101, 202, 137, 15, 30, 60, 120, 240,
  1067. 253, 231, 211, 187, 107, 214, 177, 127,
  1068. 254, 225, 223, 163, 91, 182, 113, 226,
  1069. 217, 175, 67, 134, 17, 34, 68, 136,
  1070. 13, 26, 52, 104, 208, 189, 103, 206,
  1071. 129, 31, 62, 124, 248, 237, 199, 147,
  1072. 59, 118, 236, 197, 151, 51, 102, 204,
  1073. 133, 23, 46, 92, 184, 109, 218, 169,
  1074. 79, 158, 33, 66, 132, 21, 42, 84,
  1075. 168, 77, 154, 41, 82, 164, 85, 170,
  1076. 73, 146, 57, 114, 228, 213, 183, 115,
  1077. 230, 209, 191, 99, 198, 145, 63, 126,
  1078. 252, 229, 215, 179, 123, 246, 241, 255,
  1079. 227, 219, 171, 75, 150, 49, 98, 196,
  1080. 149, 55, 110, 220, 165, 87, 174, 65,
  1081. 130, 25, 50, 100, 200, 141, 7, 14,
  1082. 28, 56, 112, 224, 221, 167, 83, 166,
  1083. 81, 162, 89, 178, 121, 242, 249, 239,
  1084. 195, 155, 43, 86, 172, 69, 138, 9,
  1085. 18, 36, 72, 144, 61, 122, 244, 245,
  1086. 247, 243, 251, 235, 203, 139, 11, 22,
  1087. 44, 88, 176, 125, 250, 233, 207, 131,
  1088. 27, 54, 108, 216, 173, 71, 142, 1,
  1089. );
  1090. private $qr_remainder_bits = array(
  1091. 0, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3,
  1092. 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0,
  1093. );
  1094. private $qr_alignment_patterns = array(
  1095. array(6, 18),
  1096. array(6, 22),
  1097. array(6, 26),
  1098. array(6, 30),
  1099. array(6, 34),
  1100. array(6, 22, 38),
  1101. array(6, 24, 42),
  1102. array(6, 26, 46),
  1103. array(6, 28, 50),
  1104. array(6, 30, 54),
  1105. array(6, 32, 58),
  1106. array(6, 34, 62),
  1107. array(6, 26, 46, 66),
  1108. array(6, 26, 48, 70),
  1109. array(6, 26, 50, 74),
  1110. array(6, 30, 54, 78),
  1111. array(6, 30, 56, 82),
  1112. array(6, 30, 58, 86),
  1113. array(6, 34, 62, 90),
  1114. array(6, 28, 50, 72, 94),
  1115. array(6, 26, 50, 74, 98),
  1116. array(6, 30, 54, 78, 102),
  1117. array(6, 28, 54, 80, 106),
  1118. array(6, 32, 58, 84, 110),
  1119. array(6, 30, 58, 86, 114),
  1120. array(6, 34, 62, 90, 118),
  1121. array(6, 26, 50, 74, 98, 122),
  1122. array(6, 30, 54, 78, 102, 126),
  1123. array(6, 26, 52, 78, 104, 130),
  1124. array(6, 30, 56, 82, 108, 134),
  1125. array(6, 34, 60, 86, 112, 138),
  1126. array(6, 30, 58, 86, 114, 142),
  1127. array(6, 34, 62, 90, 118, 146),
  1128. array(6, 30, 54, 78, 102, 126, 150),
  1129. array(6, 24, 50, 76, 102, 128, 154),
  1130. array(6, 28, 54, 80, 106, 132, 158),
  1131. array(6, 32, 58, 84, 110, 136, 162),
  1132. array(6, 26, 54, 82, 110, 138, 166),
  1133. array(6, 30, 58, 86, 114, 142, 170),
  1134. );
  1135. /* format info string = $qr_format_info[ */
  1136. /* (0 for L, 8 for M, 16 for Q, 24 for H) + mask */
  1137. /* ]; */
  1138. private $qr_format_info = array(
  1139. array( 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0 ),
  1140. array( 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1 ),
  1141. array( 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0 ),
  1142. array( 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1 ),
  1143. array( 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1 ),
  1144. array( 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0 ),
  1145. array( 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 ),
  1146. array( 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0 ),
  1147. array( 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0 ),
  1148. array( 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1 ),
  1149. array( 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0 ),
  1150. array( 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1 ),
  1151. array( 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1 ),
  1152. array( 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0 ),
  1153. array( 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1 ),
  1154. array( 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0 ),
  1155. array( 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1 ),
  1156. array( 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0 ),
  1157. array( 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1 ),
  1158. array( 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0 ),
  1159. array( 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0 ),
  1160. array( 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1 ),
  1161. array( 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0 ),
  1162. array( 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1 ),
  1163. array( 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1 ),
  1164. array( 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0 ),
  1165. array( 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1 ),
  1166. array( 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0 ),
  1167. array( 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0 ),
  1168. array( 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1 ),
  1169. array( 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0 ),
  1170. array( 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1 ),
  1171. );
  1172. /* version info string = $qr_version_info[ (version - 7) ] */
  1173. private $qr_version_info = array(
  1174. array( 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0 ),
  1175. array( 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0 ),
  1176. array( 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1 ),
  1177. array( 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1 ),
  1178. array( 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0 ),
  1179. array( 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0 ),
  1180. array( 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1 ),
  1181. array( 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1 ),
  1182. array( 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0 ),
  1183. array( 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0 ),
  1184. array( 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1 ),
  1185. array( 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1 ),
  1186. array( 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0 ),
  1187. array( 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0 ),
  1188. array( 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1 ),
  1189. array( 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1 ),
  1190. array( 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0 ),
  1191. array( 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0 ),
  1192. array( 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1 ),
  1193. array( 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1 ),
  1194. array( 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0 ),
  1195. array( 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0 ),
  1196. array( 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1 ),
  1197. array( 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1 ),
  1198. array( 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0 ),
  1199. array( 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1 ),
  1200. array( 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0 ),
  1201. array( 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0 ),
  1202. array( 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1 ),
  1203. array( 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1 ),
  1204. array( 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0 ),
  1205. array( 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0 ),
  1206. array( 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1 ),
  1207. array( 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1 ),
  1208. );
  1209. }