Skip to content

Commit c7b64eb

Browse files
committed
Initial commit
0 parents  commit c7b64eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+8733
-0
lines changed

index.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?
2+
3+
include_once('./lib/QrReader.php');
4+
5+
6+
7+
8+
9+
$dir = scandir('qrcodes');
10+
foreach($dir as $file) {
11+
if($file=='.'||$file=='..') continue;
12+
13+
print $file;
14+
print ' --- ';
15+
$qrcode = new QrReader('qrcodes/'.$file);
16+
print $text = $qrcode->text();
17+
print "<br/>";
18+
19+
20+
}

lib/Binarizer.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
/*
3+
* Copyright 2009 ZXing authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
19+
namespace Zxing;
20+
21+
use Zxing\Common\BitArray;
22+
use Zxing\Common\BitMatrix;
23+
24+
/**
25+
* This class hierarchy provides a set of methods to convert luminance data to 1 bit data.
26+
* It allows the algorithm to vary polymorphically, for example allowing a very expensive
27+
* thresholding technique for servers and a fast one for mobile. It also permits the implementation
28+
* to vary, e.g. a JNI version for Android and a Java fallback version for other platforms.
29+
*
30+
* @author [email protected] (Daniel Switkin)
31+
*/
32+
abstract class Binarizer {
33+
34+
private $source;
35+
36+
protected function __construct($source) {
37+
$this->source = $source;
38+
}
39+
40+
public final function getLuminanceSource() {
41+
return $this->source;
42+
}
43+
44+
/**
45+
* Converts one row of luminance data to 1 bit data. May actually do the conversion, or return
46+
* cached data. Callers should assume this method is expensive and call it as seldom as possible.
47+
* This method is intended for decoding 1D barcodes and may choose to apply sharpening.
48+
* For callers which only examine one row of pixels at a time, the same BitArray should be reused
49+
* and passed in with each call for performance. However it is legal to keep more than one row
50+
* at a time if needed.
51+
*
52+
* @param y The row to fetch, which must be in [0, bitmap height)
53+
* @param row An optional preallocated array. If null or too small, it will be ignored.
54+
* If used, the Binarizer will call BitArray.clear(). Always use the returned object.
55+
* @return The array of bits for this row (true means black).
56+
* @throws NotFoundException if row can't be binarized
57+
*/
58+
public abstract function getBlackRow($y, $row);
59+
60+
/**
61+
* Converts a 2D array of luminance data to 1 bit data. As above, assume this method is expensive
62+
* and do not call it repeatedly. This method is intended for decoding 2D barcodes and may or
63+
* may not apply sharpening. Therefore, a row from this matrix may not be identical to one
64+
* fetched using getBlackRow(), so don't mix and match between them.
65+
*
66+
* @return The 2D array of bits for the image (true means black).
67+
* @throws NotFoundException if image can't be binarized to make a matrix
68+
*/
69+
public abstract function getBlackMatrix();
70+
71+
/**
72+
* Creates a new object with the same type as this Binarizer implementation, but with pristine
73+
* state. This is needed because Binarizer implementations may be stateful, e.g. keeping a cache
74+
* of 1 bit data. See Effective Java for why we can't use Java's clone() method.
75+
*
76+
* @param source The LuminanceSource this Binarizer will operate on.
77+
* @return A new concrete Binarizer implementation object.
78+
*/
79+
public abstract function createBinarizer($source);
80+
81+
public final function getWidth() {
82+
return $this->source->getWidth();
83+
}
84+
85+
public final function getHeight() {
86+
return $this->source->getHeight();
87+
}
88+
89+
}

lib/BinaryBitmap.php

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
<?php
2+
/*
3+
* Copyright 2009 ZXing authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace Zxing;
19+
20+
use Zxing\Common\BitArray;
21+
use Zxing\Common\BitMatrix;
22+
23+
24+
/**
25+
* This class is the core bitmap class used by ZXing to represent 1 bit data. Reader objects
26+
* accept a BinaryBitmap and attempt to decode it.
27+
*
28+
* @author [email protected] (Daniel Switkin)
29+
*/
30+
final class BinaryBitmap {
31+
32+
private $binarizer;
33+
private $matrix;
34+
35+
public function __construct($binarizer) {
36+
if ($binarizer == null) {
37+
throw new \InvalidArgumentException("Binarizer must be non-null.");
38+
}
39+
$this->binarizer = $binarizer;
40+
}
41+
42+
/**
43+
* @return The width of the bitmap.
44+
*/
45+
public function getWidth() {
46+
return $this->binarizer->getWidth();
47+
}
48+
49+
/**
50+
* @return The height of the bitmap.
51+
*/
52+
public function getHeight() {
53+
return $this->binarizer->getHeight();
54+
}
55+
56+
/**
57+
* Converts one row of luminance data to 1 bit data. May actually do the conversion, or return
58+
* cached data. Callers should assume this method is expensive and call it as seldom as possible.
59+
* This method is intended for decoding 1D barcodes and may choose to apply sharpening.
60+
*
61+
* @param y The row to fetch, which must be in [0, bitmap height)
62+
* @param row An optional preallocated array. If null or too small, it will be ignored.
63+
* If used, the Binarizer will call BitArray.clear(). Always use the returned object.
64+
* @return The array of bits for this row (true means black).
65+
* @throws NotFoundException if row can't be binarized
66+
*/
67+
public function getBlackRow($y, $row) {
68+
return $this->binarizer->getBlackRow($y, $row);
69+
}
70+
71+
/**
72+
* Converts a 2D array of luminance data to 1 bit. As above, assume this method is expensive
73+
* and do not call it repeatedly. This method is intended for decoding 2D barcodes and may or
74+
* may not apply sharpening. Therefore, a row from this matrix may not be identical to one
75+
* fetched using getBlackRow(), so don't mix and match between them.
76+
*
77+
* @return The 2D array of bits for the image (true means black).
78+
* @throws NotFoundException if image can't be binarized to make a matrix
79+
*/
80+
public function getBlackMatrix(){
81+
// The matrix is created on demand the first time it is requested, then cached. There are two
82+
// reasons for this:
83+
// 1. This work will never be done if the caller only installs 1D Reader objects, or if a
84+
// 1D Reader finds a barcode before the 2D Readers run.
85+
// 2. This work will only be done once even if the caller installs multiple 2D Readers.
86+
if ($this->matrix == null) {
87+
$this->matrix = $this->binarizer->getBlackMatrix();
88+
}
89+
return $this->matrix;
90+
}
91+
92+
/**
93+
* @return Whether this bitmap can be cropped.
94+
*/
95+
public function isCropSupported() {
96+
return $this->binarizer->getLuminanceSource()->isCropSupported();
97+
}
98+
99+
/**
100+
* Returns a new object with cropped image data. Implementations may keep a reference to the
101+
* original data rather than a copy. Only callable if isCropSupported() is true.
102+
*
103+
* @param left The left coordinate, which must be in [0,getWidth())
104+
* @param top The top coordinate, which must be in [0,getHeight())
105+
* @param width The width of the rectangle to crop.
106+
* @param height The height of the rectangle to crop.
107+
* @return A cropped version of this object.
108+
*/
109+
public function crop($left, $top, $width, $height) {
110+
$newSource = $this->binarizer->getLuminanceSource()->crop($left, $top, $width, $height);
111+
return new BinaryBitmap($this->binarizer->createBinarizer($newSource));
112+
}
113+
114+
/**
115+
* @return Whether this bitmap supports counter-clockwise rotation.
116+
*/
117+
public function isRotateSupported() {
118+
return $this->binarizer->getLuminanceSource()->isRotateSupported();
119+
}
120+
121+
/**
122+
* Returns a new object with rotated image data by 90 degrees counterclockwise.
123+
* Only callable if {@link #isRotateSupported()} is true.
124+
*
125+
* @return A rotated version of this object.
126+
*/
127+
public function rotateCounterClockwise() {
128+
$newSource = $this->binarizer->getLuminanceSource()->rotateCounterClockwise();
129+
return new BinaryBitmap($this->binarizer->createBinarizer($newSource));
130+
}
131+
132+
/**
133+
* Returns a new object with rotated image data by 45 degrees counterclockwise.
134+
* Only callable if {@link #isRotateSupported()} is true.
135+
*
136+
* @return A rotated version of this object.
137+
*/
138+
public function rotateCounterClockwise45() {
139+
$newSource = $this->binarizer->getLuminanceSource()->rotateCounterClockwise45();
140+
return new BinaryBitmap($this->binarizer->createBinarizer($newSource));
141+
}
142+
143+
//@Override
144+
public function toString() {
145+
try {
146+
return $this->getBlackMatrix()->toString();
147+
} catch (NotFoundException $e) {
148+
return "";
149+
}
150+
}
151+
152+
}

lib/ChecksumException.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/*
3+
* Copyright 2007 ZXing authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace Zxing;
19+
20+
/**
21+
* Thrown when a barcode was successfully detected and decoded, but
22+
* was not returned because its checksum feature failed.
23+
*
24+
* @author Sean Owen
25+
*/
26+
final class ChecksumException extends ReaderException {
27+
28+
private static $instance;
29+
30+
31+
32+
public static function getChecksumInstance($cause=null) {
33+
if (self::$isStackTrace) {
34+
return new ChecksumException($cause);
35+
} else {
36+
if(!self::$instance){
37+
self::$instance = new ChecksumException($cause);
38+
}
39+
return self::$instance;
40+
}
41+
}
42+
43+
44+
}

lib/FormatException.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/*
3+
* Copyright 2007 ZXing authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace Zxing;
19+
20+
/**
21+
* Thrown when a barcode was successfully detected, but some aspect of
22+
* the content did not conform to the barcode's format rules. This could have
23+
* been due to a mis-detection.
24+
*
25+
* @author Sean Owen
26+
*/
27+
final class FormatException extends ReaderException {
28+
29+
private static $instance;
30+
31+
32+
public function __construct($cause=null) {
33+
34+
if($cause){
35+
parent::__construct($cause);
36+
}
37+
38+
}
39+
40+
41+
public static function getFormatInstance($cause=null) {
42+
if(!self::$instance){
43+
self::$instance = new FormatException();
44+
}
45+
if (self::$isStackTrace) {
46+
return new FormatException($cause);
47+
} else {
48+
return self::$instance;
49+
}
50+
}
51+
}
52+

0 commit comments

Comments
 (0)