@forgesworn/qr
Version:
Dependency-free QR code encoder and decoder for TypeScript, browsers, workers and Node, with optional WebAssembly and tracked camera scanning.
75 lines (74 loc) • 3.63 kB
TypeScript
import { type Luminance, type Thresholds } from './binarise.js';
import { type ErrorCorrection } from './encode.js';
import type { Location, Work } from './locate.js';
import { type ModuleReader, type Payload } from './symbol.js';
/** Maps read again, at most, per decode. */
export declare const SECOND_LOOKS = 4;
/** A failed map retained for refinement, with its header evidence and polarity. */
export interface Candidate {
readonly location: Location;
readonly inverted: boolean;
readonly mirrored: boolean;
readonly ecc: ErrorCorrection;
readonly mask: number;
/** Header distance: maximum for the ordinary queue, minimum for curved-map recovery. */
readonly distance: number;
}
/**
* The format word both copies are nearest, read from sampled modules, when
* both lie within AGREEMENT bits of it; straight before mirrored, and within
* each the first word in level and mask order.
*/
export declare function agreement(modules: Uint8Array, size: number): {
mirrored: boolean;
ecc: ErrorCorrection;
mask: number;
distance: number;
} | undefined;
/** The same agreement check against a lazily sampled module reader. */
export declare function agreementRead(read: ModuleReader, size: number): {
mirrored: boolean;
ecc: ErrorCorrection;
mask: number;
distance: number;
} | undefined;
/**
* True when both format copies, read through `read`, lie within AGREEMENT
* bits of the format word for this level and mask. A read at reduced size
* counts only then (SPEC.md, decoder step 9).
*/
export declare function formatAgrees(read: ModuleReader, size: number, ecc: ErrorCorrection, mask: number): boolean;
/**
* False when a version block, read in the orientation the format copies
* agreed in, decodes to a version whose size is not the map's: readSymbol
* rejects such a map, so it is no candidate. A block that does not decode
* leaves the size to decide, as in readSymbol.
*/
export declare function sized(modules: Uint8Array, size: number, mirrored: boolean): boolean;
/** Keeps the best SECOND_LOOKS candidates: least distance first, then the order found. */
export declare function keep(list: Candidate[], candidate: Candidate): void;
/**
* Reads one candidate again; the result must keep the level and mask its
* format copies agreed on. With `strict`, the format copies of the modules
* read again must also agree on them, as every read at reduced size must.
* `late` enables the deferred recovery's extra alignment pass.
* After failure, `collectMesh` may retain the unrefined mesh for step 14.
*/
export declare function secondLook(image: Luminance, t: Thresholds, candidate: Candidate, work?: Work, strict?: boolean, late?: boolean, collectMesh?: (modules: Uint8Array) => void, collectFinal?: (modules: Uint8Array) => void, collectQuadratic?: (mesh: QuadraticMesh) => void): Payload | undefined;
/** The existing strict format rule for one supplied orientation, without cross-orientation ranking. */
export declare function singleFormatAgreement(read: ModuleReader, size: number): {
ecc: ErrorCorrection;
mask: number;
distance: number;
} | undefined;
/** Six measured nodes of a three-by-three lattice; synthetic corners are refitted later. */
export interface QuadraticMesh {
readonly location: Location;
readonly x: Float64Array;
readonly y: Float64Array;
}
/** One terminal curved-grid read from retained measurements, without another search. */
export declare function readQuadraticMesh(image: Luminance, candidate: Candidate, mesh: QuadraticMesh): {
payload: Payload;
mirrored: boolean;
} | undefined;