static Version DecodeVersionInformation(int versionBits) { int bestDifference = int.MaxValue; int bestVersion = 0; for (int i = 0; i < VERSION_DECODE_INFO.Length; i++) { int targetVersion = VERSION_DECODE_INFO[i]; // Do the version info bits match exactly? done. if (targetVersion == versionBits) { return(GetVersionForNumber(i + 7)); } // Otherwise see if this is the closest to a real version info bit string // we have seen so far int bitsDifference = FormatInformation.NumBitsDiffering(versionBits, targetVersion); if (bitsDifference < bestDifference) { bestVersion = i + 7; bestDifference = bitsDifference; } } // We can tolerate up to 3 bits of error since no two version info codewords will // differ in less than 4 bits. if (bestDifference <= 3) { return(GetVersionForNumber(bestVersion)); } // If we didn't find a close enough match, fail return(null); }
public override bool Equals(Object o) { if (!(o is FormatInformation)) { return(false); } FormatInformation other = (FormatInformation)o; return(this.errorCorrectionLevel == other.errorCorrectionLevel && this.dataMask == other.dataMask); }
/** * @param maskedFormatInfo1 format info indicator, with mask still applied * @param maskedFormatInfo2 second copy of same info; both are checked at the same time * to establish best match * @return information about the format it specifies, or <code>null</code> * if doesn't seem to match any known pattern */ public static FormatInformation DecodeFormatInformation(int maskedFormatInfo1, int maskedFormatInfo2) { FormatInformation formatInfo = DoDecodeFormatInformation(maskedFormatInfo1, maskedFormatInfo2); if (formatInfo != null) { return(formatInfo); } // Should return null, but, some QR codes apparently // do not mask this info. Try again by actually masking the pattern // first return(DoDecodeFormatInformation(maskedFormatInfo1 ^ FORMAT_INFO_MASK_QR, maskedFormatInfo2 ^ FORMAT_INFO_MASK_QR)); }