Created
May 12, 2022 21:00
-
-
Save johnnyb/8e4c888aa0ca5d4503b5e52391f4207a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as ZXing from "html5-qrcode/third_party/zxing-js.umd" | |
| export function performMonkeyPatches() { | |
| console.log("Monkey patching") | |
| // Monkey-patch based on https://github.com/zxing-js/library/pull/420/commits/7644e279df9fd2e754e044c25f450576d2878e45 | |
| const oldFunc = ZXing.HTMLCanvasElementLuminanceSource.toGrayscaleBuffer; | |
| let inverterToggle = true; | |
| ZXing.HTMLCanvasElementLuminanceSource.toGrayscaleBuffer = function(imagebuffer, width, height) { | |
| const grayscaleBuffer = oldFunc(imagebuffer, width, height); | |
| const len = grayscaleBuffer.length; | |
| inverterToggle = !inverterToggle; | |
| if(inverterToggle) { | |
| for (let i = 0; i < len; i++) { | |
| grayscaleBuffer[i] = 0xFF - grayscaleBuffer[i]; | |
| } | |
| } | |
| return grayscaleBuffer; | |
| }; | |
| } |
Author
I call it on application start.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey thanks for implementing a patch!
but quick question where do i call this performMonkeyPatches() function?
but ZXing.HTMLCanvasElementLuminanceSource is undefined.
here is my qrscanner-patch.js