|
30 | 30 | */
|
31 | 31 | abstract class Binarizer
|
32 | 32 | {
|
33 |
| - private $source; |
| 33 | + protected function __construct(private $source) |
| 34 | + { |
| 35 | + } |
34 | 36 |
|
35 |
| - protected function __construct($source) |
36 |
| - { |
37 |
| - $this->source = $source; |
38 |
| - } |
| 37 | + /** |
| 38 | + * @return LuminanceSource |
| 39 | + */ |
| 40 | + final public function getLuminanceSource() |
| 41 | + { |
| 42 | + return $this->source; |
| 43 | + } |
39 | 44 |
|
40 |
| - /** |
41 |
| - * @return LuminanceSource |
42 |
| - */ |
43 |
| - public final function getLuminanceSource() |
44 |
| - { |
45 |
| - return $this->source; |
46 |
| - } |
| 45 | + /** |
| 46 | + * Converts one row of luminance data to 1 bit data. May actually do the conversion, or return |
| 47 | + * cached data. Callers should assume this method is expensive and call it as seldom as possible. |
| 48 | + * This method is intended for decoding 1D barcodes and may choose to apply sharpening. |
| 49 | + * For callers which only examine one row of pixels at a time, the same BitArray should be reused |
| 50 | + * and passed in with each call for performance. However it is legal to keep more than one row |
| 51 | + * at a time if needed. |
| 52 | + * |
| 53 | + * @param $y The row to fetch, which must be in [0, bitmap height) |
| 54 | + * @param An $row optional preallocated array. If null or too small, it will be ignored. |
| 55 | + * If used, the Binarizer will call BitArray.clear(). Always use the returned object. |
| 56 | + * |
| 57 | + * @return array The array of bits for this row (true means black). |
| 58 | + * @throws NotFoundException if row can't be binarized |
| 59 | + */ |
| 60 | + abstract public function getBlackRow($y, $row); |
47 | 61 |
|
48 |
| - /** |
49 |
| - * Converts one row of luminance data to 1 bit data. May actually do the conversion, or return |
50 |
| - * cached data. Callers should assume this method is expensive and call it as seldom as possible. |
51 |
| - * This method is intended for decoding 1D barcodes and may choose to apply sharpening. |
52 |
| - * For callers which only examine one row of pixels at a time, the same BitArray should be reused |
53 |
| - * and passed in with each call for performance. However it is legal to keep more than one row |
54 |
| - * at a time if needed. |
55 |
| - * |
56 |
| - * @param y The row to fetch, which must be in [0, bitmap height) |
57 |
| - * @param row An optional preallocated array. If null or too small, it will be ignored. |
58 |
| - * If used, the Binarizer will call BitArray.clear(). Always use the returned object. |
59 |
| - * |
60 |
| - * @return array The array of bits for this row (true means black). |
61 |
| - * @throws NotFoundException if row can't be binarized |
62 |
| - */ |
63 |
| - public abstract function getBlackRow($y, $row); |
| 62 | + /** |
| 63 | + * Converts a 2D array of luminance data to 1 bit data. As above, assume this method is expensive |
| 64 | + * and do not call it repeatedly. This method is intended for decoding 2D barcodes and may or |
| 65 | + * may not apply sharpening. Therefore, a row from this matrix may not be identical to one |
| 66 | + * fetched using getBlackRow(), so don't mix and match between them. |
| 67 | + * |
| 68 | + * @return BitMatrix The 2D array of bits for the image (true means black). |
| 69 | + * @throws NotFoundException if image can't be binarized to make a matrix |
| 70 | + */ |
| 71 | + abstract public function getBlackMatrix(); |
64 | 72 |
|
65 |
| - /** |
66 |
| - * Converts a 2D array of luminance data to 1 bit data. As above, assume this method is expensive |
67 |
| - * and do not call it repeatedly. This method is intended for decoding 2D barcodes and may or |
68 |
| - * may not apply sharpening. Therefore, a row from this matrix may not be identical to one |
69 |
| - * fetched using getBlackRow(), so don't mix and match between them. |
70 |
| - * |
71 |
| - * @return BitMatrix The 2D array of bits for the image (true means black). |
72 |
| - * @throws NotFoundException if image can't be binarized to make a matrix |
73 |
| - */ |
74 |
| - public abstract function getBlackMatrix(); |
| 73 | + /** |
| 74 | + * Creates a new object with the same type as this Binarizer implementation, but with pristine |
| 75 | + * state. This is needed because Binarizer implementations may be stateful, e.g. keeping a cache |
| 76 | + * of 1 bit data. See Effective Java for why we can't use Java's clone() method. |
| 77 | + * |
| 78 | + * @param $source The LuminanceSource this Binarizer will operate on. |
| 79 | + * |
| 80 | + * @return Binarizer A new concrete Binarizer implementation object. |
| 81 | + */ |
| 82 | + abstract public function createBinarizer($source); |
75 | 83 |
|
76 |
| - /** |
77 |
| - * Creates a new object with the same type as this Binarizer implementation, but with pristine |
78 |
| - * state. This is needed because Binarizer implementations may be stateful, e.g. keeping a cache |
79 |
| - * of 1 bit data. See Effective Java for why we can't use Java's clone() method. |
80 |
| - * |
81 |
| - * @param source The LuminanceSource this Binarizer will operate on. |
82 |
| - * |
83 |
| - * @return Binarizer A new concrete Binarizer implementation object. |
84 |
| - */ |
85 |
| - public abstract function createBinarizer($source); |
| 84 | + final public function getWidth() |
| 85 | + { |
| 86 | + return $this->source->getWidth(); |
| 87 | + } |
86 | 88 |
|
87 |
| - public final function getWidth() |
88 |
| - { |
89 |
| - return $this->source->getWidth(); |
90 |
| - } |
91 |
| - |
92 |
| - public final function getHeight() |
93 |
| - { |
94 |
| - return $this->source->getHeight(); |
95 |
| - } |
| 89 | + final public function getHeight() |
| 90 | + { |
| 91 | + return $this->source->getHeight(); |
| 92 | + } |
96 | 93 | }
|
0 commit comments