port FindBestFormatInfo

This commit is contained in:
Henry Schimke
2023-03-31 16:36:15 -05:00
parent 76fb937ca9
commit 612ef458f2

View File

@@ -91,27 +91,34 @@ impl FormatInformation {
fi fi
} }
#[inline(always)]
pub fn MirrorBits(bits: u32) -> u32 { pub fn MirrorBits(bits: u32) -> u32 {
(bits.reverse_bits()) >> 17 (bits.reverse_bits()) >> 17
} }
pub fn FindBestFormatInfo(mask: u32, lookup: [[u32; 2]; 32], bits: &[u32]) -> Self { pub fn FindBestFormatInfo(mask: u32, lookup: [[u32; 2]; 32], bits: &[u32]) -> Self {
todo!() let mut fi = FormatInformation::default();
// FormatInformation fi;
// // Some QR codes apparently do not apply the XOR mask. Try without and with additional masking. // Some QR codes apparently do not apply the XOR mask. Try without and with additional masking.
// for (auto mask : {0, mask}) for mask in [0, mask] {
// for (int bitsIndex = 0; bitsIndex < Size(bits); ++bitsIndex) // for (auto mask : {0, mask})
// for (const auto& [pattern, index] : lookup) { for bitsIndex in 0..bits.len() {
// // Find the int in lookup with fewest bits differing // for (int bitsIndex = 0; bitsIndex < Size(bits); ++bitsIndex)
// if (int hammingDist = BitHacks::CountBitsSet((bits[bitsIndex] ^ mask) ^ pattern); hammingDist < fi.hammingDistance) { for [pattern, index] in lookup {
// fi.index = index; // for (const auto& [pattern, index] : lookup) {
// fi.hammingDistance = hammingDist; // Find the int in lookup with fewest bits differing
// fi.bitsIndex = bitsIndex; let hammingDist = ((bits[bitsIndex] ^ mask) ^ pattern).count_ones();
// } if hammingDist < fi.hammingDistance {
// } // if (int hammingDist = BitHacks::CountBitsSet((bits[bitsIndex] ^ mask) ^ pattern); hammingDist < fi.hammingDistance) {
fi.index = index as u8;
fi.hammingDistance = hammingDist;
fi.bitsIndex = bitsIndex as u8;
}
}
}
}
// return fi; fi
} }
// Hamming distance of the 32 masked codes is 7, by construction, so <= 3 bits differing means we found a match // Hamming distance of the 32 masked codes is 7, by construction, so <= 3 bits differing means we found a match