decode method

  1. @override
Result decode(
  1. BinaryBitmap image, [
  2. Map<DecodeHintType, Object>? hints
])
override

Locates and decodes a barcode in some format within an image. This method also accepts hints, each possibly associated to some data, which may help the implementation decode.

@param image image of barcode to decode @param hints passed as a Map from DecodeHintType to arbitrary data. The meaning of the data depends upon the hint type. The implementation may or may not do anything with these hints. @return String which the barcode encodes @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

Implementation

@override
Result decode(BinaryBitmap image, [Map<DecodeHintType, Object>? hints]) {
  late DecoderResult decoderResult;
  late List<ResultPoint> points;
  if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {
    final bits = _extractPureBits(image.blackMatrix);
    decoderResult = _decoder.decodeMatrix(bits, hints);
    points = _noPoints;
  } else {
    final detectorResult = Detector(image.blackMatrix).detect(hints);
    decoderResult = _decoder.decodeMatrix(detectorResult.bits, hints);
    points = detectorResult.points;
  }

  // If the code was mirrored: swap the bottom-left and the top-right points.
  if (decoderResult.other is QRCodeDecoderMetaData) {
    (decoderResult.other as QRCodeDecoderMetaData)
        .applyMirroredCorrection(points);
  }

  final result = Result(
    decoderResult.text,
    decoderResult.rawBytes,
    points,
    BarcodeFormat.QR_CODE,
  );
  final byteSegments = decoderResult.byteSegments;
  if (byteSegments != null) {
    result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments);
  }
  final ecLevel = decoderResult.ecLevel;
  if (ecLevel != null) {
    result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
  }
  if (decoderResult.hasStructuredAppend) {
    result.putMetadata(
      ResultMetadataType.STRUCTURED_APPEND_SEQUENCE,
      decoderResult.structuredAppendSequenceNumber,
    );
    result.putMetadata(
      ResultMetadataType.STRUCTURED_APPEND_PARITY,
      decoderResult.structuredAppendParity,
    );
  }
  result.putMetadata(
    ResultMetadataType.SYMBOLOGY_IDENTIFIER,
    ']Q${decoderResult.symbologyModifier}',
  );
  return result;
}