Changelog
Error Robustness
- MultiFormatReader: Non-
ReaderExceptionerrors (TypeError, RangeError, etc.) are now logged instead of silently swallowed during decode attempts. Previously, programming errors were invisible and produced misleading "no barcode found" results. (src/core/MultiFormatReader.ts) - MultiFormatReader: Skip redundant
setHints()calls when the same hints object is passed todecode()repeatedly, avoiding unnecessary reader reconstruction. (src/core/MultiFormatReader.ts) - BrowserCodeReader: Unexpected errors in the continuous scan loop are now logged via
console.error. Previously the loop would stop silently with no indication of what went wrong. (src/browser/BrowserCodeReader.ts)
Scanning Quality
- OneDReader: Increased default row sampling from 15 to 25 lines, covering ~78% of image height (up from ~47%). This improves detection of 1D barcodes positioned away from the image center without requiring
TRY_HARDERmode. (src/core/oned/OneDReader.ts) - BrowserCodeReader: Added
GlobalHistogramBinarizerfallback whenHybridBinarizerfails withNotFoundException. Local thresholding can fail on very small barcodes or uniform-background images where a single global threshold works better. The fallback only triggers on failure, so the normal fast path is unaffected. (src/browser/BrowserCodeReader.ts)
Performance
- HTMLCanvasElementLuminanceSource: Merged two duplicate 25-line grayscale conversion loops (normal vs. inverted) into a single loop using an XOR mask. Reduces code and eliminates a branch. (
src/browser/HTMLCanvasElementLuminanceSource.ts) - HTMLCanvasElementLuminanceSource: Use
subarray()instead ofslice()ingetRow()to avoid an intermediate buffer copy on every row read. (src/browser/HTMLCanvasElementLuminanceSource.ts) - HTMLCanvasElementLuminanceSource + BrowserCodeReader: Added optional grayscale buffer reuse across frames during continuous scanning, avoiding a ~900KB
Uint8ClampedArrayallocation per frame on 1280x720 video. (src/browser/HTMLCanvasElementLuminanceSource.ts,src/browser/BrowserCodeReader.ts) - BitMatrix: Replaced
Math.floor(x / 32)with bitwise(x >> 5)in all hot-path methods (get,set,unset,flip,setRegion, constructor). These are the innermost operations in binarization and grid sampling. (src/core/common/BitMatrix.ts) - BitMatrix: Replaced manual zeroing loop in
clear()with nativeInt32Array.fill(0). (src/core/common/BitMatrix.ts) - DefaultGridSampler: Replaced
Math.floor()with bitwise| 0in the inner grid sampling loop, called per-pixel for every 2D barcode module. (src/core/common/DefaultGridSampler.ts) - GlobalHistogramBinarizer: Replaced manual bucket zeroing loop with
Int32Array.fill(0). (src/core/common/GlobalHistogramBinarizer.ts) - FinderPatternFinder: Replaced manual 5-element array zeroing with
Int32Array.fill(0)in 3 locations. (src/core/qrcode/detector/FinderPatternFinder.ts)
New Format: MaxiCode
- MaxiCodeReader: Full MaxiCode 2D barcode decoding support (modes 2–5), ported from the Java ZXing reference implementation. MaxiCode is a fixed-size hexagonal barcode used primarily by UPS for package sorting. (
src/core/maxicode/MaxiCodeReader.ts) - MaxiCode Decoder: Reed-Solomon error correction with interleaved EVEN/ODD codeword processing, supporting structured carrier messages (modes 2–3 with postal code, country, and service class) and standard/enhanced error correction messages (modes 4–5). (
src/core/maxicode/decoder/Decoder.ts,src/core/maxicode/decoder/BitMatrixParser.ts,src/core/maxicode/decoder/DecodedBitStreamParser.ts) - MultiFormatReader: MaxiCode is now included in both format-specific and default reader lists. (
src/core/MultiFormatReader.ts) - ReedSolomonDecoder: Added
decodeWithECCount()method that returns the number of corrected errors, used by the MaxiCode decoder to report error correction statistics. (src/core/common/reedsolomon/ReedSolomonDecoder.ts) - ResultMetadataType: Added
ERRORS_CORRECTEDenum value for reporting error correction counts in decode results. (src/core/ResultMetadataType.ts)