getTopLeftOnBit method

List<int>? getTopLeftOnBit()

This is useful in detecting a corner of a 'pure' barcode.

@return {@code x,y} coordinate of top-left-most 1 bit, or null if it is all white

Implementation

List<int>? getTopLeftOnBit() {
  int bitsOffset = 0;
  while (bitsOffset < _bits.length && _bits[bitsOffset] == 0) {
    bitsOffset++;
  }
  if (bitsOffset == _bits.length) {
    return null;
  }
  final int y = bitsOffset ~/ _rowSize;
  int x = (bitsOffset % _rowSize) * 32;

  final theBits = _bits[bitsOffset];
  int bit = 0;
  while ((theBits << (31 - bit)).toUnsigned(32) == 0) {
    bit++;
  }
  x += bit;
  return [x, y];
}