mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-08-19 02:00:07 +00:00
:octocat: LuminanceSourceInterface: remove property getters in favor of asymmetric visibility
This commit is contained in:
@@ -27,10 +27,28 @@ use function array_slice, file_exists, is_file, is_readable, realpath;
|
||||
abstract class LuminanceSourceAbstract implements LuminanceSourceInterface{
|
||||
|
||||
protected SettingsContainerInterface|QROptions $options;
|
||||
/** @var int[] */
|
||||
protected array $luminances = [];
|
||||
protected int $width;
|
||||
protected int $height;
|
||||
|
||||
/**
|
||||
* Fetches luminance data for the underlying bitmap. Values should be fetched using:
|
||||
* `int luminance = array[y * width + x] & 0xff`
|
||||
*
|
||||
* @return int[] A row-major 2D array of luminance values. Do not use result $length as it may be
|
||||
* larger than $width * $height bytes on some platforms. Do not modify the contents
|
||||
* of the result.
|
||||
*
|
||||
* @var int[]
|
||||
*/
|
||||
protected(set) array $luminances = [];
|
||||
|
||||
/**
|
||||
* The width of the bitmap.
|
||||
*/
|
||||
protected(set) int $width;
|
||||
|
||||
/**
|
||||
* The height of the bitmap.
|
||||
*/
|
||||
protected(set) int $height;
|
||||
|
||||
public function __construct(int $width, int $height, SettingsContainerInterface|QROptions $options = new QROptions){
|
||||
$this->width = $width;
|
||||
@@ -38,18 +56,6 @@ abstract class LuminanceSourceAbstract implements LuminanceSourceInterface{
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
public function getLuminances():array{
|
||||
return $this->luminances;
|
||||
}
|
||||
|
||||
public function getWidth():int{
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
public function getHeight():int{
|
||||
return $this->height;
|
||||
}
|
||||
|
||||
public function getRow(int $y):array{
|
||||
|
||||
if($y < 0 || $y >= $this->height){
|
||||
|
||||
@@ -16,29 +16,13 @@ use chillerlan\Settings\SettingsContainerInterface;
|
||||
|
||||
/**
|
||||
* Interface for the luminance sources
|
||||
*
|
||||
* @property int[] $luminances
|
||||
* @property int $width
|
||||
* @property int $height
|
||||
*/
|
||||
interface LuminanceSourceInterface{
|
||||
|
||||
/**
|
||||
* Fetches luminance data for the underlying bitmap. Values should be fetched using:
|
||||
* `int luminance = array[y * width + x] & 0xff`
|
||||
*
|
||||
* @return int[] A row-major 2D array of luminance values. Do not use result $length as it may be
|
||||
* larger than $width * $height bytes on some platforms. Do not modify the contents
|
||||
* of the result.
|
||||
*/
|
||||
public function getLuminances():array;
|
||||
|
||||
/**
|
||||
* @return int The width of the bitmap.
|
||||
*/
|
||||
public function getWidth():int;
|
||||
|
||||
/**
|
||||
* @return int The height of the bitmap.
|
||||
*/
|
||||
public function getHeight():int;
|
||||
|
||||
/**
|
||||
* Fetches one row of luminance data from the underlying platform's bitmap. Values range from
|
||||
* 0 (black) to 255 (white). Because Java does not have an unsigned byte type, callers will have
|
||||
|
||||
@@ -53,7 +53,7 @@ final class Binarizer{
|
||||
|
||||
public function __construct(LuminanceSourceInterface $source){
|
||||
$this->source = $source;
|
||||
$this->luminances = $this->source->getLuminances();
|
||||
$this->luminances = $this->source->luminances;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,8 +137,8 @@ final class Binarizer{
|
||||
* @return \chillerlan\QRCode\Decoder\BitMatrix The 2D array of bits for the image (true means black).
|
||||
*/
|
||||
public function getBlackMatrix():BitMatrix{
|
||||
$width = $this->source->getWidth();
|
||||
$height = $this->source->getHeight();
|
||||
$width = $this->source->width;
|
||||
$height = $this->source->height;
|
||||
|
||||
if($width >= self::MINIMUM_DIMENSION && $height >= self::MINIMUM_DIMENSION){
|
||||
$subWidth = ($width >> self::BLOCK_SIZE_POWER);
|
||||
|
||||
Reference in New Issue
Block a user