1313
1414use chillerlan \QRCode \Common \{EccLevel , MaskPattern , Version };
1515use chillerlan \QRCode \Data \{QRCodeDataException , QRMatrix };
16- use function array_fill , count ;
16+ use function array_fill , array_map , array_reverse , count ;
1717use const PHP_INT_MAX , PHP_INT_SIZE ;
1818
1919/**
@@ -63,6 +63,10 @@ final class BitMatrix extends QRMatrix{
6363
6464 private const FORMAT_INFO_MASK_QR = 0x5412 ; // 0101010000010010
6565
66+ /**
67+ * This flag has effect only on the copyVersionBit() method.
68+ * Before proceeding with readCodewords() the resetInfo() method should be called.
69+ */
6670 private bool $ mirror = false ;
6771
6872 /**
@@ -74,33 +78,26 @@ public function __construct(int $dimension){
7478 }
7579
7680 /**
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
8182 */
82- public function setMirror ( bool $ mirror ):self {
83+ public function resetVersionInfo ( ):self {
8384 $ this ->version = null ;
8485 $ this ->eccLevel = null ;
8586 $ this ->maskPattern = null ;
86- $ this ->mirror = $ mirror ;
8787
8888 return $ this ;
8989 }
9090
9191 /**
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.
9393 */
94- public function mirror ():self {
94+ public function mirrorDiagonal ():self {
95+ $ this ->mirror = !$ this ->mirror ;
9596
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 );
104101
105102 return $ this ;
106103 }
0 commit comments