|
@@ -286,7 +286,14 @@ class QRMatrix{
|
|
|
public function set(int $x, int $y, bool $value, int $M_TYPE):self{
|
|
public function set(int $x, int $y, bool $value, int $M_TYPE):self{
|
|
|
|
|
|
|
|
if(isset($this->matrix[$y][$x])){
|
|
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;
|
|
return $this;
|
|
@@ -322,15 +329,16 @@ class QRMatrix{
|
|
|
* Checks whether the module at ($x, $y) is of the given $M_TYPE
|
|
* Checks whether the module at ($x, $y) is of the given $M_TYPE
|
|
|
*
|
|
*
|
|
|
* true => $value & $M_TYPE === $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{
|
|
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)
|
|
* 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{
|
|
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;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $value = 0;
|
|
|
|
|
|
|
+ $this->matrix[$y][$x] = $this::M_DATA;
|
|
|
|
|
|
|
|
if($iByte < $byteCount && (($data[$iByte] >> $iBit--) & 1) === 1){
|
|
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){
|
|
if($iBit === -1){
|
|
|
$iByte++;
|
|
$iByte++;
|
|
|
$iBit = 7;
|
|
$iBit = 7;
|
|
@@ -792,11 +800,7 @@ class QRMatrix{
|
|
|
foreach($this->matrix as $y => $row){
|
|
foreach($this->matrix as $y => $row){
|
|
|
foreach($row as $x => $val){
|
|
foreach($row as $x => $val){
|
|
|
// skip non-data modules
|
|
// 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);
|
|
$this->flip($x, $y);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|