diff --git a/package.json b/package.json index 169c762..ebf8861 100644 --- a/package.json +++ b/package.json @@ -136,7 +136,8 @@ "Sudham Jayanthi ", "Ben Khoo ", "Andy Edinborough ", - "Claudio Cocciarelli " + "Claudio Cocciarelli ", + "Hadrien Foucault " ], "license": "MIT", "engines": { diff --git a/src/locator/barcode_locator.js b/src/locator/barcode_locator.js index 5c4c267..3bcb560 100644 --- a/src/locator/barcode_locator.js +++ b/src/locator/barcode_locator.js @@ -582,8 +582,8 @@ export default { console.log(`Patch-Size: ${JSON.stringify(patchSize)}`); } - inputStream.setWidth(Math.floor(Math.floor(size.x / patchSize.x) * (1 / thisHalfSample) * patchSize.x)); - inputStream.setHeight(Math.floor(Math.floor(size.y / patchSize.y) * (1 / thisHalfSample) * patchSize.y)); + inputStream.setWidth(Math.max(Math.floor(Math.floor(size.x / patchSize.x) * (1 / thisHalfSample) * patchSize.x), patchSize.x)); + inputStream.setHeight(Math.max(Math.floor(Math.floor(size.y / patchSize.y) * (1 / thisHalfSample) * patchSize.y), patchSize.y)); if ((inputStream.getWidth() % patchSize.x) === 0 && (inputStream.getHeight() % patchSize.y) === 0) { return true; diff --git a/test/fixtures/no_code/image-001.jpg b/test/fixtures/no_code/image-001.jpg new file mode 100644 index 0000000..27c1dff Binary files /dev/null and b/test/fixtures/no_code/image-001.jpg differ diff --git a/test/integration/integration.spec.ts b/test/integration/integration.spec.ts index f049838..c8e9c0f 100644 --- a/test/integration/integration.spec.ts +++ b/test/integration/integration.spec.ts @@ -17,7 +17,7 @@ if (typeof it.allowFail === 'undefined') { return Promise.resolve().then(() => { return callback.apply(this, arguments); }).catch((err) => { - console.trace('* error during test', err); + console.trace('* error during test', title, err); this.skip(); }); }); @@ -47,6 +47,28 @@ function runDecoderTest(name: string, config: QuaggaJSConfigObject, testSet: Arr }); } +// run test that should not fail but no barcode is in the images +function runNoCodeTest(name: string, config: QuaggaJSConfigObject, testSet: Array<{ name: string, result: string, format: string }>) { + describe(`Not decoding ${name}`, () => { + testSet.forEach((sample) => { + it('should run without error', async function() { + this.timeout(20000); // need to set a long timeout because laptops sometimes lag like hell in tests when they go low power + const thisConfig = { + ...config, + src: `${typeof window !== 'undefined' ? '/' : ''}test/fixtures/${name}/${sample.name}`, + }; + const result = await Quagga.decodeSingle(thisConfig); + expect(result).to.be.an('Array'); + expect(result).to.be.empty; + // // console.warn(`* Expect result ${JSON.stringify(result)} to be an object`); + expect(Quagga.canvas).to.be.an('Object'); + expect(Quagga.canvas.dom).to.be.an('Object'); + expect(Quagga.canvas.ctx).to.be.an('Object'); + }); + }); + }); +} + function generateConfig(configOverride: QuaggaJSConfigObject = {}) { const config: QuaggaJSConfigObject = { inputStream: { @@ -410,3 +432,31 @@ describe('External Reader Test, using stock code_128 reader', () => { ); }); }); + +describe('Canvas Update Test, avoid DOMException', () => { + describe('works', () => { + runNoCodeTest( + 'no_code', + generateConfig({ + decoder: { + readers: ['code_128_reader', 'ean_reader'], + }, + inputStream: { + constraints: { + width: NaN, + height: NaN + }, + singleChannel: false, + }, + locate: false, + locator: { + halfSample: true, + patchSize: 'x-large' + } + }), + [ + { 'name': 'image-001.jpg', 'result': null, format: 'code_128' }, + ] + ); + }); +});