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.7k stars 607 forks source link

Binarizer performance improvements #115

Open danimoh opened 5 years ago

danimoh commented 5 years ago

Hi Cosmo. I noticed that in the binarizer new buffers are assigned for the grayscale image and binary image(s). However, these buffers can be assigned within the rgba image buffer, as this data is not needed anymore after conversion to grayscale / binarization. This saves allocation and garbage collection of up to 3 * pixelCount + blackPointsCount bytes. According to my tests, this makes the code 20%-30% faster.

(Sorry for the force-pushs. I couldn't run the tests locally and therefore had to rely on travis for testing.)

danimoh commented 5 years ago

I just noticed, that a canOverwriteImage value of false is not correctly assigned by the current options merge strategy. I opened https://github.com/cozmo/jsQR/pull/117 therefore, which would be a requirement for merging this PR.