From 0dfc578d15843957905f41d764101927f556251a Mon Sep 17 00:00:00 2001 From: LakeGH Date: Thu, 14 Nov 2019 12:55:55 -0500 Subject: [PATCH 1/4] Fix "onlyInvert" inversionAttempts option. `shouldInvert` should also be true if `options.inversionAttempts` equals "onlyInvert". --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 65116049..7843e2ef 100644 --- a/src/index.ts +++ b/src/index.ts @@ -69,7 +69,7 @@ function jsQR(data: Uint8ClampedArray, width: number, height: number, providedOp (options as any)[opt] = (providedOptions as any)[opt] || (options as any)[opt]; }); - const shouldInvert = options.inversionAttempts === "attemptBoth" || options.inversionAttempts === "invertFirst"; + const shouldInvert = options.inversionAttempts === "attemptBoth" || options.inversionAttempts === "invertFirst" || options.inversionAttempts === "onlyInvert"; const tryInvertedFirst = options.inversionAttempts === "onlyInvert" || options.inversionAttempts === "invertFirst"; const {binarized, inverted} = binarize(data, width, height, shouldInvert); let result = scan(tryInvertedFirst ? inverted : binarized); From 4f3fef8c6e180a5534b9df4e730b7a9059f9e378 Mon Sep 17 00:00:00 2001 From: LakeGH Date: Thu, 14 Nov 2019 13:12:12 -0500 Subject: [PATCH 2/4] Change order of inversionAttempts check for tslint --- src/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 7843e2ef..507bf92d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -69,8 +69,9 @@ function jsQR(data: Uint8ClampedArray, width: number, height: number, providedOp (options as any)[opt] = (providedOptions as any)[opt] || (options as any)[opt]; }); - const shouldInvert = options.inversionAttempts === "attemptBoth" || options.inversionAttempts === "invertFirst" || options.inversionAttempts === "onlyInvert"; const tryInvertedFirst = options.inversionAttempts === "onlyInvert" || options.inversionAttempts === "invertFirst"; + const shouldInvert = options.inversionAttempts === "attemptBoth" || tryInvertedFirst; + const {binarized, inverted} = binarize(data, width, height, shouldInvert); let result = scan(tryInvertedFirst ? inverted : binarized); if (!result && (options.inversionAttempts === "attemptBoth" || options.inversionAttempts === "invertFirst")) { From 13843e5ac62a813afaf4b8565742e2d71410f280 Mon Sep 17 00:00:00 2001 From: LakeGH Date: Thu, 14 Nov 2019 13:14:50 -0500 Subject: [PATCH 3/4] Remove trailing whitespace for tslint --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 507bf92d..c0336971 100644 --- a/src/index.ts +++ b/src/index.ts @@ -71,7 +71,7 @@ function jsQR(data: Uint8ClampedArray, width: number, height: number, providedOp const tryInvertedFirst = options.inversionAttempts === "onlyInvert" || options.inversionAttempts === "invertFirst"; const shouldInvert = options.inversionAttempts === "attemptBoth" || tryInvertedFirst; - + const {binarized, inverted} = binarize(data, width, height, shouldInvert); let result = scan(tryInvertedFirst ? inverted : binarized); if (!result && (options.inversionAttempts === "attemptBoth" || options.inversionAttempts === "invertFirst")) { From e7f282af2c04a7ff237773ae3c26540f15b2b6f0 Mon Sep 17 00:00:00 2001 From: LakeGH Date: Thu, 14 Nov 2019 13:29:15 -0500 Subject: [PATCH 4/4] Removing unneeded whitespace. --- src/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index c0336971..71bd6eb5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -71,7 +71,6 @@ function jsQR(data: Uint8ClampedArray, width: number, height: number, providedOp const tryInvertedFirst = options.inversionAttempts === "onlyInvert" || options.inversionAttempts === "invertFirst"; const shouldInvert = options.inversionAttempts === "attemptBoth" || tryInvertedFirst; - const {binarized, inverted} = binarize(data, width, height, shouldInvert); let result = scan(tryInvertedFirst ? inverted : binarized); if (!result && (options.inversionAttempts === "attemptBoth" || options.inversionAttempts === "invertFirst")) {