13
13
14
14
use chillerlan \QRCode \Common \{EccLevel , MaskPattern , Version };
15
15
use chillerlan \QRCode \Data \{QRCodeDataException , QRMatrix };
16
- use function array_fill , count ;
16
+ use function array_fill , array_map , array_reverse , count ;
17
17
use const PHP_INT_MAX , PHP_INT_SIZE ;
18
18
19
19
/**
@@ -63,6 +63,10 @@ final class BitMatrix extends QRMatrix{
63
63
64
64
private const FORMAT_INFO_MASK_QR = 0x5412 ; // 0101010000010010
65
65
66
+ /**
67
+ * This flag has effect only on the copyVersionBit() method.
68
+ * Before proceeding with readCodewords() the resetInfo() method should be called.
69
+ */
66
70
private bool $ mirror = false ;
67
71
68
72
/**
@@ -74,33 +78,26 @@ public function __construct(int $dimension){
74
78
}
75
79
76
80
/**
77
- * Prepare the parser for a mirrored operation.
78
- * This flag has effect only on the readFormatInformation() and the
79
- * readVersion() methods. Before proceeding with readCodewords() the
80
- * mirror() method should be called.
81
+ * Resets the current version info in order to attempt another reading
81
82
*/
82
- public function setMirror ( bool $ mirror ):self {
83
+ public function resetVersionInfo ( ):self {
83
84
$ this ->version = null ;
84
85
$ this ->eccLevel = null ;
85
86
$ this ->maskPattern = null ;
86
- $ this ->mirror = $ mirror ;
87
87
88
88
return $ this ;
89
89
}
90
90
91
91
/**
92
- * Mirror the bit matrix in order to attempt a second reading.
92
+ * Mirror the bit matrix diagonally in order to attempt a second reading.
93
93
*/
94
- public function mirror ():self {
94
+ public function mirrorDiagonal ():self {
95
+ $ this ->mirror = !$ this ->mirror ;
95
96
96
- for ($ x = 0 ; $ x < $ this ->moduleCount ; $ x ++){
97
- for ($ y = ($ x + 1 ); $ y < $ this ->moduleCount ; $ y ++){
98
- if ($ this ->get ($ x , $ y ) !== $ this ->get ($ y , $ x )){
99
- $ this ->flip ($ y , $ x );
100
- $ this ->flip ($ x , $ y );
101
- }
102
- }
103
- }
97
+ // mirror vertically
98
+ $ matrix = array_reverse ($ this ->matrix );
99
+ // rotate by 90 degrees clockwise
100
+ $ this ->matrix = array_map (fn (...$ a ) => array_reverse ($ a ), ...$ matrix );
104
101
105
102
return $ this ;
106
103
}
0 commit comments