329 lines
12 KiB
PHP
329 lines
12 KiB
PHP
|
|
<?php
|
||
|
|
/*
|
||
|
|
* PHP QR Code encoder
|
||
|
|
*
|
||
|
|
* Masking
|
||
|
|
*
|
||
|
|
* Based on libqrencode C library distributed under LGPL 2.1
|
||
|
|
* Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
|
||
|
|
*
|
||
|
|
* PHP QR Code is distributed under LGPL 3
|
||
|
|
* Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
||
|
|
*
|
||
|
|
* This library is free software; you can redistribute it and/or
|
||
|
|
* modify it under the terms of the GNU Lesser General Public
|
||
|
|
* License as published by the Free Software Foundation; either
|
||
|
|
* version 3 of the License, or any later version.
|
||
|
|
*
|
||
|
|
* This library is distributed in the hope that it will be useful,
|
||
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
|
* Lesser General Public License for more details.
|
||
|
|
*
|
||
|
|
* You should have received a copy of the GNU Lesser General Public
|
||
|
|
* License along with this library; if not, write to the Free Software
|
||
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||
|
|
*/
|
||
|
|
|
||
|
|
define('N1', 3);
|
||
|
|
define('N2', 3);
|
||
|
|
define('N3', 40);
|
||
|
|
define('N4', 10);
|
||
|
|
|
||
|
|
class QRmask {
|
||
|
|
|
||
|
|
public $runLength = array();
|
||
|
|
|
||
|
|
//----------------------------------------------------------------------
|
||
|
|
public function __construct()
|
||
|
|
{
|
||
|
|
$this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0);
|
||
|
|
}
|
||
|
|
|
||
|
|
//----------------------------------------------------------------------
|
||
|
|
public function writeFormatInformation($width, &$frame, $mask, $level)
|
||
|
|
{
|
||
|
|
$blacks = 0;
|
||
|
|
$format = QRspec::getFormatInfo($mask, $level);
|
||
|
|
|
||
|
|
for($i=0; $i<8; $i++) {
|
||
|
|
if($format & 1) {
|
||
|
|
$blacks += 2;
|
||
|
|
$v = 0x85;
|
||
|
|
} else {
|
||
|
|
$v = 0x84;
|
||
|
|
}
|
||
|
|
|
||
|
|
$frame[8][$width - 1 - $i] = chr($v);
|
||
|
|
if($i < 6) {
|
||
|
|
$frame[$i][8] = chr($v);
|
||
|
|
} else {
|
||
|
|
$frame[$i + 1][8] = chr($v);
|
||
|
|
}
|
||
|
|
$format = $format >> 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
for($i=0; $i<7; $i++) {
|
||
|
|
if($format & 1) {
|
||
|
|
$blacks += 2;
|
||
|
|
$v = 0x85;
|
||
|
|
} else {
|
||
|
|
$v = 0x84;
|
||
|
|
}
|
||
|
|
|
||
|
|
$frame[$width - 7 + $i][8] = chr($v);
|
||
|
|
if($i == 0) {
|
||
|
|
$frame[8][7] = chr($v);
|
||
|
|
} else {
|
||
|
|
$frame[8][6 - $i] = chr($v);
|
||
|
|
}
|
||
|
|
|
||
|
|
$format = $format >> 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
return $blacks;
|
||
|
|
}
|
||
|
|
|
||
|
|
//----------------------------------------------------------------------
|
||
|
|
public function mask0($x, $y) { return ($x+$y)&1; }
|
||
|
|
public function mask1($x, $y) { return ($y&1); }
|
||
|
|
public function mask2($x, $y) { return ($x%3); }
|
||
|
|
public function mask3($ |