Skip to content

Commit

Permalink
Merge pull request #474 from ericblade/dev
Browse files Browse the repository at this point in the history
implement #459 add InputStream option willReadFrequently
  • Loading branch information
ericblade authored Dec 26, 2022
2 parents 41b1379 + 9f1351e commit 394960c
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 40 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"wrap-iife": [ "error", "outside" ],
"import/no-named-as-default": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/prefer-namespace-keyword": "off",
// STYLE
"brace-style": ["error", "1tbs"],
"comma-spacing": ["error", { "before": false, "after": true }],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ericblade/quagga2",
"version": "1.7.7",
"version": "1.8.0",
"description": "An advanced barcode-scanner written in JavaScript",
"main": "lib/quagga.js",
"types": "type-definitions/quagga.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion src/input/frame_grabber_browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ FrameGrabber.create = function (inputStream, canvas) {
let _canvas;
let _ctx = null;
let _data = null;
const { willReadFrequently } = _streamConfig;

_canvas = canvas || document.createElement('canvas');
_canvas.width = _canvasSize.x;
_canvas.height = _canvasSize.y;
_ctx = _canvas.getContext('2d');
_ctx = _canvas.getContext('2d', { willReadFrequently: !!willReadFrequently }); // double not because we have an optional bool that needs to pass as a bool
_data = new Uint8Array(_size.x * _size.y);
if (ENV.development) {
console.log('FrameGrabber', JSON.stringify({
Expand Down
108 changes: 70 additions & 38 deletions type-definitions/quagga.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export interface BarcodeReaderConfig {

export enum BarcodeDirection {
Forward = 1,
Reverse = -1
Reverse = -1,
}
type BarcodeFormat = string;

Expand All @@ -129,11 +129,11 @@ export interface BarcodeCorrection {
}

export interface BarcodePosition {
start: number;
startCounter?: number;
end: number;
endCounter?: number;
error?: number;
start: number;
startCounter?: number;
}

export interface BarcodeInfo extends BarcodePosition {
Expand All @@ -156,18 +156,18 @@ export interface Barcode {
}

export interface ThresholdSize {
size: number;
counts: number;
min: number;
max: number;
min: number;
size: number;
}

export interface Threshold {
space: {
bar: {
narrow: ThresholdSize;
wide: ThresholdSize;
};
bar: {
space: {
narrow: ThresholdSize;
wide: ThresholdSize;
};
Expand All @@ -176,14 +176,17 @@ export interface Threshold {
export declare module Readers {
export abstract class BarcodeReader {
_row: Array<number>;

SINGLE_CODE_ERROR: number;

FORMAT: BarcodeFormat;

CONFIG_KEYS: BarcodeReaderConfig;

static get Exception(): {
StartNotFoundException: string;
CodeNotFoundException: string;
PatternNotFoundException: string;
StartNotFoundException: string;
};

constructor(config: BarcodeReaderConfig, supplements?: Array<BarcodeReader>);
Expand All @@ -209,7 +212,9 @@ export declare module Readers {

export class TwoOfFiveReader extends BarcodeReader {
FORMAT: string;

SINGLE_CODE_ERROR: number;

AVG_CODE_ERROR: number;

decode(row?: Array<number>, start?: BarcodePosition): Barcode | null;
Expand Down Expand Up @@ -259,17 +264,29 @@ export declare module Readers {

export class Code128Reader extends BarcodeReader {
CODE_SHIFT: number;

CODE_C: number;

CODE_B: number;

CODE_A: number;

START_CODE_A: number;

START_CODE_B: number;

START_CODE_C: number;

STOP_CODE: number;

CODE_PATTERN: number[][];

SINGLE_CODE_ERROR: number;

AVG_CODE_ERROR: number;

FORMAT: string;

MODULE_INDICES: {
bar: number[];
space: number[];
Expand All @@ -288,16 +305,6 @@ export declare module Readers {
protected _verifyTrailingWhitespace(endInfo: BarcodeInfo): BarcodeInfo | null;
}

export class Code32Reader extends Code39Reader {
FORMAT: string;

decode(row?: Array<number>, start?: BarcodePosition): Barcode | null;

protected _decodeCode32(code: string): string | null;

protected _checkChecksum(code: string): boolean;
}

export class Code39Reader extends BarcodeReader {
FORMAT: string;

Expand All @@ -314,6 +321,16 @@ export declare module Readers {
protected _verifyTrailingWhitespace(lastStart: number, nextStart: number, counters: Uint16Array): boolean;
}

export class Code32Reader extends Code39Reader {
FORMAT: string;

decode(row?: Array<number>, start?: BarcodePosition): Barcode | null;

protected _decodeCode32(code: string): string | null;

protected _checkChecksum(code: string): boolean;
}

export class Code39VINReader extends Code39Reader {
FORMAT: string;

Expand Down Expand Up @@ -342,24 +359,6 @@ export declare module Readers {
protected _verifyChecksums(charArray: Array<string>): boolean;
}

export class EAN2Reader extends EANReader {
FORMAT: string;

decode(row?: Array<number>, start?: number): Barcode | null;
}

export class EAN5Reader extends EANReader {
FORMAT: string;

decode(row?: Array<number>, start?: number): Barcode | null;
}

export class EAN8Reader extends EANReader {
FORMAT: string;

protected _decodePayload(inCode: BarcodePosition, result: Array<number>, decodedCodes: Array<BarcodePosition>): BarcodeInfo | null;
}

export class EANReader extends BarcodeReader {
FORMAT: string;
SINGLE_CODE_ERROR: number;
Expand All @@ -384,13 +383,37 @@ export declare module Readers {
protected _checksum(result: Array<number>): boolean;
}

export class EAN2Reader extends EANReader {
FORMAT: string;

decode(row?: Array<number>, start?: number): Barcode | null;
}

export class EAN5Reader extends EANReader {
FORMAT: string;

decode(row?: Array<number>, start?: number): Barcode | null;
}

export class EAN8Reader extends EANReader {
FORMAT: string;

protected _decodePayload(inCode: BarcodePosition, result: Array<number>, decodedCodes: Array<BarcodePosition>): BarcodeInfo | null;
}

export class I2of5Reader extends BarcodeReader {
SINGLE_CODE_ERROR: number;

AVG_CODE_ERROR: number;

START_PATTERN: number[];

STOP_PATTERN: number[];

CODE_PATTERN: number[][];

MAX_CORRECTION_FACTOR: number;

FORMAT: string;

constructor(opts: BarcodeReaderConfig);
Expand Down Expand Up @@ -418,7 +441,9 @@ export declare module Readers {

export class UPCEReader extends EANReader {
CODE_FREQUENCY: number[][];

STOP_PATTERN: number[];

FORMAT: string;

protected _decodePayload(inCode: BarcodePosition, result: Array<number>, decodedCodes: Array<BarcodePosition>): BarcodeInfo | null;
Expand Down Expand Up @@ -768,6 +793,13 @@ export interface QuaggaJSConfigObject {
*/
type?: InputStreamType;

/**
* Use canvas.getContext('2d', { willReadFrequently: true }) for browser frame grabber operations
* @default false
* ... defaulting false because historically this wasn't an option, so i don't want to change behavior
*/
willReadFrequently?: boolean;

target?: Element | string;

constraints?: MediaTrackConstraints;
Expand Down Expand Up @@ -939,16 +971,16 @@ export interface QuaggaJSConfigObject {
}

export interface QuaggaJSReaderConfig {
format: string;
config: {
supplements: string[];
};
format: string;
}

export interface MediaTrackConstraintsWithDeprecated extends MediaTrackConstraints {
facing?: string;
maxAspectRatio?: number; // i don't see this in the documentation anywhere, but it's in the original test suite...
minAspectRatio?: number;
facing?: string;
}

export type TypedArrayConstructor =
Expand Down

0 comments on commit 394960c

Please sign in to comment.