mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-11-21 02:06:15 +00:00
:octocat: minor optimizations
This commit is contained in:
+21
-17
@@ -286,7 +286,14 @@ class QRMatrix{
|
||||
public function set(int $x, int $y, bool $value, int $M_TYPE):self{
|
||||
|
||||
if(isset($this->matrix[$y][$x])){
|
||||
$this->matrix[$y][$x] = (($M_TYPE & ~$this::IS_DARK) | (($value) ? $this::IS_DARK : 0));
|
||||
// we don't know whether the input is dark, so we remove the dark bit
|
||||
$M_TYPE &= ~$this::IS_DARK;
|
||||
|
||||
if($value === true){
|
||||
$M_TYPE |= $this::IS_DARK;
|
||||
}
|
||||
|
||||
$this->matrix[$y][$x] = $M_TYPE;
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -322,15 +329,16 @@ class QRMatrix{
|
||||
* Checks whether the module at ($x, $y) is of the given $M_TYPE
|
||||
*
|
||||
* true => $value & $M_TYPE === $M_TYPE
|
||||
*
|
||||
* Also, returns false if the given coordinates are out of range.
|
||||
*/
|
||||
public function checkType(int $x, int $y, int $M_TYPE):bool{
|
||||
$val = $this->get($x, $y);
|
||||
|
||||
if($val === -1){
|
||||
return false;
|
||||
if(isset($this->matrix[$y][$x])){
|
||||
return ($this->matrix[$y][$x] & $M_TYPE) === $M_TYPE;
|
||||
}
|
||||
|
||||
return ($val & $M_TYPE) === $M_TYPE;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -350,14 +358,16 @@ class QRMatrix{
|
||||
|
||||
/**
|
||||
* Checks whether the module at ($x, $y) is true (dark) or false (light)
|
||||
*
|
||||
* Also, returns false if the given coordinates are out of range.
|
||||
*/
|
||||
public function check(int $x, int $y):bool{
|
||||
|
||||
if(!isset($this->matrix[$y][$x])){
|
||||
return false;
|
||||
if(isset($this->matrix[$y][$x])){
|
||||
return $this->isDark($this->matrix[$y][$x]);
|
||||
}
|
||||
|
||||
return $this->isDark($this->matrix[$y][$x]);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -759,14 +769,12 @@ class QRMatrix{
|
||||
continue;
|
||||
}
|
||||
|
||||
$value = 0;
|
||||
$this->matrix[$y][$x] = $this::M_DATA;
|
||||
|
||||
if($iByte < $byteCount && (($data[$iByte] >> $iBit--) & 1) === 1){
|
||||
$value = $this::IS_DARK;
|
||||
$this->matrix[$y][$x] |= $this::IS_DARK;
|
||||
}
|
||||
|
||||
$this->matrix[$y][$x] = ($this::M_DATA | $value);
|
||||
|
||||
if($iBit === -1){
|
||||
$iByte++;
|
||||
$iBit = 7;
|
||||
@@ -792,11 +800,7 @@ class QRMatrix{
|
||||
foreach($this->matrix as $y => $row){
|
||||
foreach($row as $x => $val){
|
||||
// skip non-data modules
|
||||
if(($val & $this::M_DATA) !== $this::M_DATA){
|
||||
continue;
|
||||
}
|
||||
|
||||
if($mask($x, $y)){
|
||||
if(($val & $this::M_DATA) === $this::M_DATA && $mask($x, $y)){
|
||||
$this->flip($x, $y);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user