Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fc690ea
WIP code
Dec 1, 2020
09c4ea3
WIP: commit meant to save the code
odahcam Dec 2, 2020
9d0fae6
dependecies: updated sharp
odahcam Dec 2, 2020
9a7527c
tests(multi qrcode): fix array equals assertion
odahcam Dec 2, 2020
abeafd7
image loading fix
odahcam Dec 2, 2020
7e7c13f
tests corrections
odahcam Dec 4, 2020
abcff1a
new finder pattern finder
odahcam Dec 4, 2020
e0ae737
added some notes
odahcam Dec 4, 2020
9f073f9
working on overloads
odahcam Dec 7, 2020
f2a398d
Merge branch 'feature/multi-qr-code-reader' of https://github.com/zxi…
odahcam Dec 7, 2020
384c84a
test: fix overload usage
odahcam Dec 7, 2020
562277e
Merge branch 'master' into feature/multi-qr-code-reader
odahcam Dec 9, 2020
f5212ac
fix implementation and overload names
odahcam Dec 22, 2020
ebd9756
fix spacing in func declarations
odahcam Dec 22, 2020
6efcdca
implemented overloading pattern
odahcam Dec 23, 2020
9e92e55
fix general build/test errors
odahcam Dec 23, 2020
e3c15b6
Merge branch 'master' into feature/multi-qr-code-reader
odahcam Apr 11, 2021
e5aac7c
updates and added info about porting overloads
odahcam Apr 11, 2021
49a0363
fixed tests build
odahcam Apr 11, 2021
07ec4e7
Merge branch 'master' into feature/multi-qr-code-reader
odahcam Apr 11, 2021
3599b38
ts-node launches
odahcam May 29, 2021
7c0beab
Remove duplicate import and add type to assertion to allow tests to run
shahrin-shahrulzaman-rakuten Aug 11, 2021
fa890ef
Remove duplicate import and add type to assertion to allow tests to run
shahrin-shahrulzaman-rakuten Aug 11, 2021
9f32092
Merge pull request #464 from shahrin014/fix/feature/multi-qr-code-reader
werthdavid Aug 11, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,26 @@
"./src/test/core/aztec/**/*.spec.ts"
],
"internalConsoleOptions": "openOnSessionStart"
},
{
"type": "node",
"request": "launch",
"name": "Multi-reader Tests - ts-node",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"--require",
"ts-node/register",
"--require",
"tsconfig-paths/register",
"-u",
"tdd",
"--timeout",
"999999",
"--colors",
"--recursive",
"./src/test/core/multi/**/*.spec.ts"
],
"internalConsoleOptions": "openOnSessionStart"
}
]
}
6 changes: 4 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
- `int` has 32 bits, signed, so `int[]` transforms to `Int32Array`.
- `char` has 2 bytes, so `char[]` transforms to `Uint16Array`.
- `long` has 64 bit two's complement `integer`, can be signed or unsigned.
- `float[]` can be ported to `Float32Array`.
- `double[]` can be ported to `Float64Array`.

### JavaScript's TypedArray

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

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

## Encoding

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"nyc": "^15.1.0",
"rollup": "^2.8.2",
"seedrandom": "^2.4.4",
"sharp": "^0.22.1",
"sharp": "^0.26.3",
"shx": "0.3.2",
"sinon": "^7.2.7",
"terser": "^5.3.7",
Expand Down
3 changes: 2 additions & 1 deletion src/core/Reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ interface Reader {
* @throws NotFoundException if no potential barcode is found
* @throws ChecksumException if a potential barcode is found but does not pass its checksum
* @throws FormatException if a potential barcode is found but format is invalid
* @override decode
*/
// decode(image: BinaryBitmap): Result /*throws NotFoundException, ChecksumException, FormatException*/
// decodeWithoutHints(image: BinaryBitmap): Result;

/**
* Locates and decodes a barcode in some format within an image. This method also accepts
Expand Down
139 changes: 102 additions & 37 deletions src/core/Result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import ResultPoint from './ResultPoint';
import BarcodeFormat from './BarcodeFormat';
import System from './util/System';
import ResultMetadataType from './ResultMetadataType';
import { long } from 'src/customTypings';
import { isBarcodeFormatValue } from './util/BarcodeFormaHelpers';

/**
* <p>Encapsulates the result of decoding a barcode within an image.</p>
Expand All @@ -31,44 +33,107 @@ import ResultMetadataType from './ResultMetadataType';
export default class Result {

private resultMetadata: Map<ResultMetadataType, Object>;

// public constructor(private text: string,
// Uint8Array rawBytes,
// ResultPoconst resultPoints: Int32Array,
// BarcodeFormat format) {
// this(text, rawBytes, resultPoints, format, System.currentTimeMillis())
// }

// public constructor(text: string,
// Uint8Array rawBytes,
// ResultPoconst resultPoints: Int32Array,
// BarcodeFormat format,
// long timestamp) {
// this(text, rawBytes, rawBytes == null ? 0 : 8 * rawBytes.length,
// resultPoints, format, timestamp)
// }

public constructor(private text: string,
private numBits: number;
private resultPoints: ResultPoint[];
private format: BarcodeFormat;

public constructor(
text: string,
rawBytes: Uint8Array,
resultPoints: ResultPoint[],
format: BarcodeFormat,
);
public constructor(
text: string,
rawBytes: Uint8Array,
resultPoints: ResultPoint[],
format: BarcodeFormat,
timestamp: long,
);
public constructor(
text: string,
rawBytes: Uint8Array,
numBits: number,
resultPoints: ResultPoint[],
format: BarcodeFormat,
timestamp: number
);
public constructor(
private text: string,
private rawBytes: Uint8Array,
private numBits: number /*int*/ = rawBytes == null ? 0 : 8 * rawBytes.length,
private resultPoints: ResultPoint[],
private format: BarcodeFormat,
private timestamp: number /*long*/ = System.currentTimeMillis()) {
this.text = text;
this.rawBytes = rawBytes;
if (undefined === numBits || null === numBits) {
this.numBits = (rawBytes === null || rawBytes === undefined) ? 0 : 8 * rawBytes.length;
} else {
this.numBits = numBits;
}
this.resultPoints = resultPoints;
this.format = format;
this.resultMetadata = null;
if (undefined === timestamp || null === timestamp) {
this.timestamp = System.currentTimeMillis();
} else {
this.timestamp = timestamp;
}
numBits_resultPoints: number | ResultPoint[],
resultPoints_format: ResultPoint[] | BarcodeFormat | any,
format_timestamp: BarcodeFormat | long | any = null,
private timestamp: long = System.currentTimeMillis()
) {
// checks overloading order from most to least params

// check overload 3
if (numBits_resultPoints instanceof Number && Array.isArray(resultPoints_format) && isBarcodeFormatValue(format_timestamp)) {
numBits_resultPoints = rawBytes == null ? 0 : 8 * rawBytes.length;
this.constructor_Overload3(text, rawBytes, numBits_resultPoints, resultPoints_format, format_timestamp, timestamp);
return;
}

// check overload 2
if (Array.isArray(resultPoints_format) && isBarcodeFormatValue(format_timestamp)) {
this.constructor_Overload2(text, rawBytes, resultPoints_format, format_timestamp, timestamp);
return;
}

// check overload 1
if (typeof text === 'string' && rawBytes instanceof Uint8Array && Array.isArray(numBits_resultPoints) && isBarcodeFormatValue(resultPoints_format)) {
this.constructor_Overload1(text, rawBytes, numBits_resultPoints, resultPoints_format);
return;
}

// throw no supported overload exception
throw new Error('No supported overload for the given combination of parameters.');
}

private constructor_Overload1(
text: string,
rawBytes: Uint8Array,
resultPoints: ResultPoint[],
format: BarcodeFormat,
) {
return this.constructor_Overload2(text, rawBytes, resultPoints, format, System.currentTimeMillis());
}

private constructor_Overload2(
text: string,
rawBytes: Uint8Array,
resultPoints: ResultPoint[],
format: BarcodeFormat,
timestamp: number /* long */,
) {
return this.constructor_Overload3(text, rawBytes, rawBytes == null ? 0 : 8 * rawBytes.length,
resultPoints, format, timestamp);
}

private constructor_Overload3(
text: string,
rawBytes: Uint8Array,
numBits: number,
resultPoints: ResultPoint[],
format: BarcodeFormat,
timestamp: number
) {
this.text = text;
this.rawBytes = rawBytes;
if (undefined === numBits || null === numBits) {
this.numBits = (rawBytes === null || rawBytes === undefined) ? 0 : 8 * rawBytes.length;
} else {
this.numBits = numBits;
}
this.resultPoints = resultPoints;
this.format = format;
this.resultMetadata = null;
if (undefined === timestamp || null === timestamp) {
this.timestamp = System.currentTimeMillis();
} else {
this.timestamp = timestamp;
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/core/multi/MultipleBarcodeReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default /*public*/ interface MultipleBarcodeReader {

/**
* @throws NotFoundException
* @override decodeMultiple
*/
decodeMultiple(image: BinaryBitmap): Result[];

Expand Down
Loading