Skip to content

Commit f2a398d

Browse files
committed
Merge branch 'feature/multi-qr-code-reader' of https://github.com/zxing-js/library into feature/multi-qr-code-reader
2 parents 9f073f9 + e0ae737 commit f2a398d

File tree

9 files changed

+659
-751
lines changed

9 files changed

+659
-751
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
6262
- `int` has 32 bits, signed, so `int[]` transforms to `Int32Array`.
6363
- `char` has 2 bytes, so `char[]` transforms to `Uint16Array`.
6464
- `long` has 64 bit two's complement `integer`, can be signed or unsigned.
65+
- `float[]` can be ported to `Float32Array`.
66+
- `double[]` can be ported to `Float64Array`.
6567

6668
### JavaScript's TypedArray
6769

@@ -71,8 +73,8 @@ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
7173

7274
- Take care of `int` -> `number` (integer to number) port when doing bitwise transformation especially `<<`. Do a `& 0xFFFFFFFF` for ints, a &0xFF for bytes.
7375
- Take care of array initialization, in Java `new Array(N)` initializes capacity NOT size/length.
74-
- Use `Math.floor` for any division of ints otherwise the `number` type is a floating point and keeps the numbers after the dot.
75-
- For `float` to `int` casting use `Math.trunc`, to replicate the same effect as Java casting does.
76+
- Use `Math.floor` for any division of `int`s otherwise the `number` type is a floating point and keeps the numbers after the dot.
77+
- For `float`/`number` to `int` casting use `Math.trunc`, to replicate the same effect as Java casting does.
7678

7779
## Encoding
7880

src/core/multi/qrcode/QRCodeMultiReader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export default /*public final*/ class QRCodeMultiReader extends QRCodeReader imp
175175
if (newByteSegment.size() > 0) {
176176
newResult.putMetadata(ResultMetadataType.BYTE_SEGMENTS, Collections.singletonList(newByteSegment.toByteArray()));
177177
}
178-
newResults.unshift(newResult); // TYPESCRIPTPORT: inserted element at the start of the array because it seems the Java version does that as well.
178+
newResults.push(newResult); // TYPESCRIPTPORT: inserted element at the start of the array because it seems the Java version does that as well.
179179
return newResults;
180180
}
181181

src/core/multi/qrcode/detector/MultiFinderPatternFinder.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { BitMatrix, NotFoundException, ResultPoint, DecodeHintType } from "src";
18-
import FinderPattern from "src/core/qrcode/detector/FinderPattern";
19-
import FinderPatternFinder from "src/core/qrcode/detector/FinderPatternFinder";
20-
import FinderPatternInfo from "src/core/qrcode/detector/FinderPatternInfo";
21-
import ResultPointCallback from "src/core/ResultPointCallback";
22-
import Collections from "src/core/util/Collections";
23-
import Comparator from "src/core/util/Comparator";
24-
import { double, float, int, List } from "src/customTypings";
17+
import BitMatrix from 'src/core/common/BitMatrix';
18+
import DecodeHintType from 'src/core/DecodeHintType';
19+
import NotFoundException from 'src/core/NotFoundException';
20+
import FinderPattern from 'src/core/qrcode/detector/FinderPattern';
21+
import FinderPatternFinder from 'src/core/qrcode/detector/FinderPatternFinder';
22+
import FinderPatternInfo from 'src/core/qrcode/detector/FinderPatternInfo';
23+
import ResultPoint from 'src/core/ResultPoint';
24+
import ResultPointCallback from 'src/core/ResultPointCallback';
25+
import Collections from 'src/core/util/Collections';
26+
import Comparator from 'src/core/util/Comparator';
27+
import { double, float, int, List } from 'src/customTypings';
2528

2629
// package com.google.zxing.multi.qrcode.detector;
2730

@@ -228,32 +231,32 @@ export default /* public final */ class MultiFinderPatternFinder extends FinderP
228231
// image, and then account for the center being 3 modules in size. This gives the smallest
229232
// number of pixels the center could be, so skip this often. When trying harder, look for all
230233
// QR versions regardless of how dense they are.
231-
let iSkip: int = (3 * maxI) / (4 * MultiFinderPatternFinder.MAX_MODULES);
234+
let iSkip: int = Math.trunc((3 * maxI) / (4 * MultiFinderPatternFinder.MAX_MODULES)); // TYPESCRIPTPORT: Java integer divisions always discard decimal chars.
232235
if (iSkip < MultiFinderPatternFinder.MIN_SKIP || tryHarder) {
233236
iSkip = MultiFinderPatternFinder.MIN_SKIP;
234237
}
235238

236239
const stateCount: Int32Array = Int32Array.from({ length: 5 });
237240
for (let i: int = iSkip - 1; i < maxI; i += iSkip) {
238241
// Get a row of black/white values
239-
MultiFinderPatternFinder.doClearCounts(stateCount);
242+
this.clearCounts(stateCount);
240243
let currentState: int = 0;
241244
for (let j: int = 0; j < maxJ; j++) {
242245
if (image.get(j, i)) {
243246
// Black pixel
244-
if ((currentState & 1) == 1) { // Counting white pixels
247+
if ((currentState & 1) === 1) { // Counting white pixels
245248
currentState++;
246249
}
247250
stateCount[currentState]++;
248251
} else { // White pixel
249-
if ((currentState & 1) == 0) { // Counting black pixels
250-
if (currentState == 4) { // A winner?
251-
if (MultiFinderPatternFinder.foundPatternCross(stateCount) && this.handlePossibleCenter2(stateCount, i, j)) { // Yes
252+
if ((currentState & 1) === 0) { // Counting black pixels
253+
if (currentState === 4) { // A winner?
254+
if (MultiFinderPatternFinder.foundPatternCross(stateCount) && this.handlePossibleCenter(stateCount, i, j)) { // Yes
252255
// Clear state to start looking again
253256
currentState = 0;
254-
MultiFinderPatternFinder.doClearCounts(stateCount);
257+
this.clearCounts(stateCount);
255258
} else { // No, shift counts back by two
256-
MultiFinderPatternFinder.doShiftCounts2(stateCount);
259+
this.shiftCounts2(stateCount);
257260
currentState = 3;
258261
}
259262
} else {
@@ -266,7 +269,7 @@ export default /* public final */ class MultiFinderPatternFinder extends FinderP
266269
} // for j=...
267270

268271
if (MultiFinderPatternFinder.foundPatternCross(stateCount)) {
269-
this.handlePossibleCenter2(stateCount, i, maxJ);
272+
this.handlePossibleCenter(stateCount, i, maxJ);
270273
}
271274
} // for i=iSkip-1 ...
272275
const patternInfo: FinderPattern[][] = this.selectMultipleBestPatterns();

0 commit comments

Comments
 (0)