decode method

Uint8List decode(
  1. Uint8List input
)

Implementation

Uint8List decode(Uint8List input) {
  _data = input;
  _bitPosition = 0;
  final int width = columns <= 0 ? 1728 : columns;
  final int rowBytes = (width + 7) >> 3;
  final int maxRows = rows > 0 ? rows : 1 << 20;
  final List<int> out = <int>[];
  List<int> reference = <int>[width, width];
  int row = 0;
  while (row < maxRows && !_atEnd) {
    final List<int> changes = k < 0 ? _decode2D(reference, width) : (k == 0 ? _decode1D(width) : _decodeMixed(reference, width));
    if (changes.isEmpty) break;
    final Uint8List line = Uint8List(rowBytes);
    int color = 0;
    int position = 0;
    for (final int change in changes) {
      final int end = change > width ? width : change;
      if (color == 1) {
        for (int x = position; x < end; x++) {
          line[x >> 3] |= 0x80 >> (x & 7);
        }
      }
      position = end;
      color ^= 1;
      if (position >= width) break;
    }
    if (color == 1 && position < width) {
      for (int x = position; x < width; x++) {
        line[x >> 3] |= 0x80 >> (x & 7);
      }
    }
    out.addAll(line);
    reference = changes;
    row++;
    if (byteAlign) _bitPosition = (_bitPosition + 7) & ~7;
  }
  while (rows > 0 && out.length < rows * rowBytes) {
    out.add(0);
  }
  final Uint8List result = Uint8List.fromList(out);
  if (!blackIs1) {
    for (int i = 0; i < result.length; i++) {
      result[i] = ~result[i] & 0xFF;
    }
  }
  return result;
}