控制台应用,yzncms本身基于tp5.1框架,里面的队列用不了,bug,坑
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LuminanceSource.php 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. namespace Zxing;
  18. /**
  19. * The purpose of this class hierarchy is to abstract different bitmap implementations across
  20. * platforms into a standard interface for requesting greyscale luminance values. The interface
  21. * only provides immutable methods; therefore crop and rotation create copies. This is to ensure
  22. * that one Reader does not modify the original luminance source and leave it in an unknown state
  23. * for other Readers in the chain.
  24. *
  25. * @author dswitkin@google.com (Daniel Switkin)
  26. */
  27. abstract class LuminanceSource
  28. {
  29. public function __construct(private $width, private $height)
  30. {
  31. }
  32. /**
  33. * Fetches luminance data for the underlying bitmap. Values should be fetched using:
  34. * {@code int luminance = array[y * width + x] & 0xff}
  35. *
  36. * @return A row-major 2D array of luminance values. Do not use result.length as it may be
  37. * larger than width * height bytes on some platforms. Do not modify the contents
  38. * of the result.
  39. */
  40. abstract public function getMatrix();
  41. /**
  42. * @return float The width of the bitmap.
  43. */
  44. final public function getWidth(): float
  45. {
  46. return $this->width;
  47. }
  48. /**
  49. * @return float The height of the bitmap.
  50. */
  51. final public function getHeight(): float
  52. {
  53. return $this->height;
  54. }
  55. /**
  56. * @return bool Whether this subclass supports cropping.
  57. */
  58. public function isCropSupported(): bool
  59. {
  60. return false;
  61. }
  62. /**
  63. * Returns a new object with cropped image data. Implementations may keep a reference to the
  64. * original data rather than a copy. Only callable if isCropSupported() is true.
  65. *
  66. * @param $left The left coordinate, which must be in [0,getWidth())
  67. * @param $top The top coordinate, which must be in [0,getHeight())
  68. * @param $width The width of the rectangle to crop.
  69. * @param $height The height of the rectangle to crop.
  70. *
  71. * @return mixed A cropped version of this object.
  72. */
  73. public function crop($left, $top, $width, $height)
  74. {
  75. throw new \Exception("This luminance source does not support cropping.");
  76. }
  77. /**
  78. * @return bool Whether this subclass supports counter-clockwise rotation.
  79. */
  80. public function isRotateSupported(): bool
  81. {
  82. return false;
  83. }
  84. /**
  85. * @return a wrapper of this {@code LuminanceSource} which inverts the luminances it returns -- black becomes
  86. * white and vice versa, and each value becomes (255-value).
  87. */
  88. // public function invert()
  89. // {
  90. // return new InvertedLuminanceSource($this);
  91. // }
  92. /**
  93. * Returns a new object with rotated image data by 90 degrees counterclockwise.
  94. * Only callable if {@link #isRotateSupported()} is true.
  95. *
  96. * @return mixed A rotated version of this object.
  97. */
  98. public function rotateCounterClockwise()
  99. {
  100. throw new \Exception("This luminance source does not support rotation by 90 degrees.");
  101. }
  102. /**
  103. * Returns a new object with rotated image data by 45 degrees counterclockwise.
  104. * Only callable if {@link #isRotateSupported()} is true.
  105. *
  106. * @return mixed A rotated version of this object.
  107. */
  108. public function rotateCounterClockwise45()
  109. {
  110. throw new \Exception("This luminance source does not support rotation by 45 degrees.");
  111. }
  112. final public function toString()
  113. {
  114. $row = [];
  115. $result = '';
  116. for ($y = 0; $y < $this->height; $y++) {
  117. $row = $this->getRow($y, $row);
  118. for ($x = 0; $x < $this->width; $x++) {
  119. $luminance = $row[$x] & 0xFF;
  120. $c = '';
  121. if ($luminance < 0x40) {
  122. $c = '#';
  123. } elseif ($luminance < 0x80) {
  124. $c = '+';
  125. } elseif ($luminance < 0xC0) {
  126. $c = '.';
  127. } else {
  128. $c = ' ';
  129. }
  130. $result .= ($c);
  131. }
  132. $result .= ('\n');
  133. }
  134. return $result;
  135. }
  136. /**
  137. * Fetches one row of luminance data from the underlying platform's bitmap. Values range from
  138. * 0 (black) to 255 (white). Because Java does not have an unsigned byte type, callers will have
  139. * to bitwise and with 0xff for each value. It is preferable for implementations of this method
  140. * to only fetch this row rather than the whole image, since no 2D Readers may be installed and
  141. * getMatrix() may never be called.
  142. *
  143. * @param $y ; The row to fetch, which must be in [0,getHeight())
  144. * @param $row ; An optional preallocated array. If null or too small, it will be ignored.
  145. * Always use the returned object, and ignore the .length of the array.
  146. *
  147. * @return array
  148. * An array containing the luminance data.
  149. */
  150. abstract public function getRow($y, $row);
  151. }