Skip to content

Commit

Permalink
Merge pull request #507 from hadrien-f/master
Browse files Browse the repository at this point in the history
fix/set dimensions greater or equal patch size
  • Loading branch information
ericblade authored Oct 21, 2023
2 parents 2155bf7 + 336d709 commit cd9f869
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@
"Sudham Jayanthi <[email protected]>",
"Ben Khoo <[email protected]>",
"Andy Edinborough <[email protected]>",
"Claudio Cocciarelli <[email protected]>"
"Claudio Cocciarelli <[email protected]>",
"Hadrien Foucault <[email protected]>"
],
"license": "MIT",
"engines": {
Expand Down
4 changes: 2 additions & 2 deletions src/locator/barcode_locator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Binary file added test/fixtures/no_code/image-001.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 51 additions & 1 deletion test/integration/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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' },
]
);
});
});

0 comments on commit cd9f869

Please sign in to comment.