decode static method

List<UCode> decode(
  1. UGrayImage image, [
  2. UCodeScanOptions options = const UCodeScanOptions()
])

Decodes every enabled symbology from a grayscale image.

Implementation

static List<UCode> decode(UGrayImage image, [UCodeScanOptions options = const UCodeScanOptions()]) {
  if (image.isEmpty) return const <UCode>[];
  UGrayImage working = image;
  final Rect? region = options.region;
  if (region != null) {
    working = image.crop(region.left.round(), region.top.round(), region.width.round(), region.height.round());
    if (working.isEmpty) return const <UCode>[];
  }

  List<UCode> results = _decodeGray(working, options);
  if (results.isEmpty && options.tryDownscale && working.width > 640) {
    results = _decodeGray(working.downscale(2), options);
    if (results.isNotEmpty) results = results.map((UCode code) => _scale(code, 2)).toList(growable: false);
  }
  if (results.isEmpty && options.tryInvert) {
    results = _decodeGray(working.inverted(), options);
    results = results
        .map(
          (UCode code) => UCode(
            format: code.format,
            text: code.text,
            bytes: code.bytes,
            corners: code.corners,
            eci: code.eci,
            inverted: true,
            structuredAppend: code.structuredAppend,
            errorCorrectionLevel: code.errorCorrectionLevel,
            version: code.version,
            mask: code.mask,
          ),
        )
        .toList(growable: false);
  }
  if (results.isEmpty) return const <UCode>[];
  if (working.left == 0 && working.top == 0) return results;
  return results.map((UCode code) => code.translated(working.left.toDouble(), working.top.toDouble())).toList(growable: false);
}