mirror of
https://github.com/status-im/QR-Code-generator.git
synced 2026-08-31 01:31:10 +00:00
Somewhat simplified black/white balance penalty calculation in all language versions.
This commit is contained in:
+4
-3
@@ -485,10 +485,11 @@ long QrCode::getPenaltyScore() const {
|
||||
black++;
|
||||
}
|
||||
}
|
||||
// Note that size is odd, so black/total != 1/2
|
||||
int total = size * size;
|
||||
// Find smallest k such that (45-5k)% <= dark/total <= (55+5k)%
|
||||
for (int k = 0; black*20L < (9L-k)*total || black*20L > (11L+k)*total; k++)
|
||||
result += PENALTY_N4;
|
||||
// Compute the smallest integer k >= 0 such that (45-5k)% <= black/total <= (55+5k)%
|
||||
int k = static_cast<int>((std::abs(black * 20L - total * 10L) + total - 1) / total) - 1;
|
||||
result += k * PENALTY_N4;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user