123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php
- namespace Zxing;
- abstract class LuminanceSource
- {
- private $width;
- private $height;
- public function __construct($width, $height)
- {
- $this->width = $width;
- $this->height = $height;
- }
-
- public abstract function getMatrix();
-
- public final function getWidth()
- {
- return $this->width;
- }
-
- public final function getHeight()
- {
- return $this->height;
- }
-
- public function isCropSupported()
- {
- return false;
- }
-
- public function crop($left, $top, $width, $height)
- {
- throw new \Exception("This luminance source does not support cropping.");
- }
-
- public function isRotateSupported()
- {
- return false;
- }
-
- public function invert()
- {
- return new InvertedLuminanceSource($this);
- }
-
- public function rotateCounterClockwise()
- {
- throw new \Exception("This luminance source does not support rotation by 90 degrees.");
- }
-
- public function rotateCounterClockwise45()
- {
- throw new \Exception("This luminance source does not support rotation by 45 degrees.");
- }
- public final function toString()
- {
- $row = [];
- $result = '';
- for ($y = 0; $y < $this->height; $y++) {
- $row = $this->getRow($y, $row);
- for ($x = 0; $x < $this->width; $x++) {
- $luminance = $row[$x] & 0xFF;
- $c = '';
- if ($luminance < 0x40) {
- $c = '#';
- } else if ($luminance < 0x80) {
- $c = '+';
- } else if ($luminance < 0xC0) {
- $c = '.';
- } else {
- $c = ' ';
- }
- $result .= ($c);
- }
- $result .= ('\n');
- }
- return $result;
- }
-
- public abstract function getRow($y, $row);
- }
|