readFormatInformation method
Reads format information from one of its two locations within the QR Code.
@return FormatInformation encapsulating the QR Code's format info @throws FormatException if both format information locations cannot be parsed as the valid encoding of format information
Implementation
FormatInformation readFormatInformation() {
if (_parsedFormatInfo != null) {
return _parsedFormatInfo!;
}
// Read top-left format info bits
int formatInfoBits1 = 0;
for (int i = 0; i < 6; i++) {
formatInfoBits1 = _copyBit(i, 8, formatInfoBits1);
}
// .. and skip a bit in the timing pattern ...
formatInfoBits1 = _copyBit(7, 8, formatInfoBits1);
formatInfoBits1 = _copyBit(8, 8, formatInfoBits1);
formatInfoBits1 = _copyBit(8, 7, formatInfoBits1);
// .. and skip a bit in the timing pattern ...
for (int j = 5; j >= 0; j--) {
formatInfoBits1 = _copyBit(8, j, formatInfoBits1);
}
// Read the top-right/bottom-left pattern too
final dimension = _bitMatrix.height;
int formatInfoBits2 = 0;
final jMin = dimension - 7;
for (int j = dimension - 1; j >= jMin; j--) {
formatInfoBits2 = _copyBit(8, j, formatInfoBits2);
}
for (int i = dimension - 8; i < dimension; i++) {
formatInfoBits2 = _copyBit(i, 8, formatInfoBits2);
}
_parsedFormatInfo = FormatInformation.decodeFormatInformation(
formatInfoBits1,
formatInfoBits2,
);
if (_parsedFormatInfo != null) {
return _parsedFormatInfo!;
}
throw FormatsException.instance;
}