decode method

DecoderResult decode(
  1. BitMatrix bits, [
  2. DecodeHint? hints
])

Implementation

DecoderResult decode(BitMatrix bits, [DecodeHint? hints]) {
  final parser = BitMatrixParser(bits);
  final codewords = parser.readCodewords();

  int errorsCorrected = _correctErrors(codewords, 0, 10, 10, _all);
  final mode = codewords[0] & 0x0F;
  late Uint8List datawords;
  switch (mode) {
    case 2:
    case 3:
    case 4:
      errorsCorrected += _correctErrors(codewords, 20, 84, 40, _even);
      errorsCorrected += _correctErrors(codewords, 20, 84, 40, _odd);
      datawords = Uint8List(94);
      break;
    case 5:
      errorsCorrected += _correctErrors(codewords, 20, 68, 56, _even);
      errorsCorrected += _correctErrors(codewords, 20, 68, 56, _odd);
      datawords = Uint8List(78);
      break;
    default:
      throw FormatsException.instance;
  }

  List.copyRange(datawords, 0, codewords, 0, 10);
  List.copyRange(datawords, 10, codewords, 20, datawords.length + 10);

  final result = DecodedBitStreamParser.decode(datawords, mode);
  result.errorsCorrected = errorsCorrected;
  return result;
}