ericblade / quagga2

An advanced barcode-scanner written in Javascript and TypeScript - Continuation from https://github.com/serratus/quaggajs
MIT License
758 stars 85 forks source link

Allow `decodeImage` to be async #399

Closed justwiebe closed 2 years ago

justwiebe commented 2 years ago

I'm working on implementing a QR Reader, based off of your other project, but with the "qr-scanner" dependency instead (looks smaller). The problem is, that is async, so I'm having to look into how to force it to be synchronous. It would be great if decodeFromImage was async https://github.com/ericblade/quagga2/blob/master/src/decoder/barcode_decoder.js#L258

github-actions[bot] commented 2 years ago

Thank you for filing an issue! Please be patient. :-)

ericblade commented 2 years ago

I'm having a little bit of brainfog this evening, so I'm not sure what all might have to be changed for that function to work asynchronously, I'd need to do a little investigation when I'm thinking a little more clearly.

You might just be able to do something like

async decodeImage(inputImageWrapper: ImageWrapper) {
        const data = inputImageWrapper.getAsRGBA();
        const result = await (howeverYouAccessQrScanner());
        ....
        return result;
}

however, i feel like that might not be quite enough there. :|

ericblade commented 2 years ago

@BakoviDagi I took a quick stab at this problem, if you've got capability to give it a try and see if it suits your needs, that'd be great.

I'm not publishing it straight away, as it's presently breaking the code-32 tests, which i'll need to spend some real time digging into to discover if the tests are broken or if the code 32 code or the code it inherits from is broken.

ericblade commented 2 years ago

@BakoviDagi i just merged that, it should be publishing as 1.5.0 shortly. If you could give it a spin and lmk that'd be great.

ericblade commented 2 years ago

... and i just discovered that my version publisher is broken. so, it'll be up as soon as i figure out how to fix that.

ericblade commented 2 years ago

OK, manual publishing it is! Please let me know if 1.5.0 works!

justwiebe commented 2 years ago

@ericblade Thanks! I'll test it on Monday and let you know!

justwiebe commented 2 years ago

@ericblade It works great, thanks!