zxing-js/library

Unable to read mirrored QR codes

vhtkrk opened this issue · 3 comments

vhtkrk commented

Describe the bug
If a QR code is mirrored, zxing library is unable to read it.

To Reproduce
Try to scan a mirrored QR code, such as the attached one. At least qrfy.com seems to generate these out of the box.

Expected behavior
The QR code contents ("test2") scanned succesfully.

Screenshots
SCR-20240606-lgbt

Desktop (please complete the following information):

  • OS: MacOS 14 tested
  • Browser: Chrome & Firefox tested
  • Version: Chrome 126, Firefox 126

Smartphone (please complete the following information):

  • Device: Samsung Galaxy Z Flip 5
  • OS: Android 14
  • Browser: Firefox
  • Version: 126

Additional context
So I dug around the source and seems like on a failed scan zxing already tries to mirror the QR code, but is unsuccesful. This seemed perplexing so I dug around and it seems like the fault is at src/core/qrcode/decoder/BitMatrixParser.ts: in remask() if I change the line var dataMask = DataMask.values[this.parsedFormatInfo.getDataMask()]; to var dataMask = DataMask.values.get(this.parsedFormatInfo.getDataMask()); I'm able to read the mirrored code.

good catch! Can you create a PR?

vhtkrk commented

I have to go for now but I'll get you a PR by tomorrow.

--> 0.21.1