cozmo / jsQR

A pure javascript QR code reading library. This library takes in raw images and will locate, extract and parse any QR code found within.
https://cozmo.github.io/jsQR/
Apache License 2.0
3.64k stars 602 forks source link

else-if with same conditions in decode() #191

Closed severus-sn4pe closed 3 years ago

severus-sn4pe commented 3 years ago

In decode(), the two else if condition blocks on lines 972-983 have the same condition as the if block at L966.

https://github.com/cozmo/jsQR/blob/8851ab5cc5fecd646be668ccd34612ccc236d9c3/dist/jsQR.js#L966-L983

This smells like a bug. or does readBits() somehow modify the state and this works as intended? Anyway, it looks strange for sure.

cozmo commented 3 years ago

read bits does modify state - there may be a way to clean this up, but the stateful consumption of bits off of the bitStream always ends up being a little gross - it's the most stateful portion of a generally pretty stateless codebase.

Would welcome a PR if you were interested in making this more intuitive, but as it's not an actual bug I'm going to close the issue.