Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not scanning white barcodes #907

Open
Mbengparis opened this issue Apr 1, 2024 · 4 comments
Open

Not scanning white barcodes #907

Mbengparis opened this issue Apr 1, 2024 · 4 comments

Comments

@Mbengparis
Copy link

Mbengparis commented Apr 1, 2024

Describe the bug
Nothing happens when white codes are scanned.

To Reproduce
Steps to reproduce the behavior:

Go to https://blog.minhazav.dev/research/html5-qrcode
Request camera permissions
Scan any white barcode
Nothing happens

Expected behavior
It is supposed to show the link of the barcode

Tested on iOS and android.

@Gspohu
Copy link

Gspohu commented Sep 27, 2024

I can confirm, I use this in my Svelte WebApp and White QrCode aren't recognized.

Tested with this one
QRCode(30)

@Mbengparis
Copy link
Author

i finally got it to work by tweaking the code. I added the inverter_counter and the invert variable. The invert variable checks if the code has been inverted or not.

Use this part in the class B extends O as follows:

class B extends O {
constructor(t) { super(t.width, t.height), this.canvas = t, this.tempCanvasElement = null, this.buffer = B.makeBufferFromCanvasImageData(t) } static makeBufferFromCanvasImageData(t) {
const e = t.getContext("2d").getImageData(0, 0, t.width, t.height);
return B.toGrayscaleBuffer(e.data, t.width, t.height)
}

            static inverter_counter=0;
            static toGrayscaleBuffer(t, e, r) { 
               B.inverter_counter++; 
               var invert=(B.inverter_counter % 4 === 2 || B.inverter_counter % 4 === 3);

                const n = new Uint8ClampedArray(e * r); 
                 for (let e = 0, r = 0, i = t.length; e < i; e += 4, r++) { 
                  let i; 
                   i = 0 === t[e + 3] ? 255 : 306 * t[e] + 601 * t[e + 1] + 117 * t[e + 2] + 512 >> 10, 
                   n[r] = invert?(255-i):i 
                } 
                   return n 

            }

@Gspohu
Copy link

Gspohu commented Sep 27, 2024

Oh, finally this issue is duplicated here: #94

and there is a PR in progress on this topic here: #766
but it seems dead.

Regarding what you're saying, @Mbengparis what are you modifying and where?

@Mbengparis
Copy link
Author

Before you use the library, you have to import it to your site. Open the code in the library you have imported, and search for the class B extends O. In there you will see a code similar to what i posted but without the inverter_counter and the invert variables. Just add as i wrote it up there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants