decodeBits static method

List<UCode> decodeBits(
  1. UBitMatrix matrix, [
  2. UCodeScanOptions options = const UCodeScanOptions()
])

Decodes an already-binarized matrix.

Implementation

static List<UCode> decodeBits(UBitMatrix matrix, [UCodeScanOptions options = const UCodeScanOptions()]) {
  final List<UCode> results = <UCode>[];
  final Set<UCodeFormat> formats = options.effectiveFormats;

  if (formats.contains(UCodeFormat.qr)) {
    for (final UQrDetectorResult detected in UQrDetector(matrix).detect(tryHarder: options.tryHarder, maxSymbols: options.maxSymbols)) {
      try {
        results.add(UQrMatrixDecoder.decode(detected.bits, detected.points));
        if (!options.multiple) return results;
      } catch (_) {
        continue;
      }
    }
  }

  if (formats.contains(UCodeFormat.dataMatrix)) {
    final List<UCode> found = UDataMatrixScanner.scan(matrix, options);
    results.addAll(found);
    if (found.isNotEmpty && !options.multiple) return results;
  }

  if (formats.contains(UCodeFormat.aztec)) {
    final List<UCode> found = UAztecScanner.scan(matrix, options);
    results.addAll(found);
    if (found.isNotEmpty && !options.multiple) return results;
  }

  if (formats.contains(UCodeFormat.pdf417)) {
    final List<UCode> found = UPdf417Scanner.scan(matrix, options);
    results.addAll(found);
    if (found.isNotEmpty && !options.multiple) return results;
  }

  final List<UCode> linear = ULinearScanner.scan(matrix, options);
  results.addAll(linear);
  if (results.isNotEmpty || !options.tryRotate) return results;

  final UBitMatrix rotated = matrix.rotate90();
  final List<UCode> rotatedResults = <UCode>[];
  if (formats.contains(UCodeFormat.qr)) {
    for (final UQrDetectorResult detected in UQrDetector(rotated).detect(tryHarder: options.tryHarder, maxSymbols: options.maxSymbols)) {
      try {
        rotatedResults.add(UQrMatrixDecoder.decode(detected.bits, detected.points));
      } catch (_) {
        continue;
      }
    }
  }
  rotatedResults.addAll(ULinearScanner.scan(rotated, options));
  for (final UCode code in rotatedResults) {
    results.add(_unrotate(code, matrix.width, matrix.height));
  }
  return results;
}