zxing-js / library

Multi-format 1D/2D barcode image processing library, usable in JavaScript ecosystem.
https://zxing-js.github.io/library/
Apache License 2.0
2.5k stars 546 forks source link

Unable to read mirrored QR codes #604

Closed vhtkrk closed 5 months ago

vhtkrk commented 5 months ago

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):

Smartphone (please complete the following information):

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.

werthdavid commented 5 months ago

good catch! Can you create a PR?

vhtkrk commented 5 months ago

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

werthdavid commented 5 months ago

--> 0.21.1