internal static int GetLostPoint(QRCode qrCode) { int moduleCount = qrCode.GetModuleCount(); int lostPoint = 0; // LEVEL1 for (int row = 0; row < moduleCount; row++) { for (int col = 0; col < moduleCount; col++) { int sameCount = 0; bool dark = qrCode.IsDark(row, col); for (int r = -1; r <= 1; r++) { if (row + r < 0 || moduleCount <= row + r) { continue; } for (int c = -1; c <= 1; c++) { if (col + c < 0 || moduleCount <= col + c) { continue; } if (r == 0 && c == 0) { continue; } if (dark == qrCode.IsDark(row + r, col + c)) { sameCount++; } } } if (sameCount > 5) { lostPoint += (3 + sameCount - 5); } } } // LEVEL2 for (int row = 0; row < moduleCount - 1; row++) { for (int col = 0; col < moduleCount - 1; col++) { int count = 0; if (qrCode.IsDark(row, col)) { count++; } if (qrCode.IsDark(row + 1, col)) { count++; } if (qrCode.IsDark(row, col + 1)) { count++; } if (qrCode.IsDark(row + 1, col + 1)) { count++; } if (count == 0 || count == 4) { lostPoint += 3; } } } // LEVEL3 for (int row = 0; row < moduleCount; row++) { for (int col = 0; col < moduleCount - 6; col++) { if (qrCode.IsDark(row, col) && !qrCode.IsDark(row, col + 1) && qrCode.IsDark(row, col + 2) && qrCode.IsDark(row, col + 3) && qrCode.IsDark(row, col + 4) && !qrCode.IsDark(row, col + 5) && qrCode.IsDark(row, col + 6)) { lostPoint += 40; } } } for (int col = 0; col < moduleCount; col++) { for (int row = 0; row < moduleCount - 6; row++) { if (qrCode.IsDark(row, col) && !qrCode.IsDark(row + 1, col) && qrCode.IsDark(row + 2, col) && qrCode.IsDark(row + 3, col) && qrCode.IsDark(row + 4, col) && !qrCode.IsDark(row + 5, col) && qrCode.IsDark(row + 6, col)) { lostPoint += 40; } } } // LEVEL4 int darkCount = 0; for (int col = 0; col < moduleCount; col++) { for (int row = 0; row < moduleCount; row++) { if (qrCode.IsDark(row, col)) { darkCount++; } } } int ratio = Math.Abs(100 * darkCount / moduleCount / moduleCount - 50) / 5; lostPoint += ratio * 10; return(lostPoint); }
internal static int GetLostPoint(QRCode qrCode) { int moduleCount = qrCode.GetModuleCount(); int num = 0; for (int i = 0; i < moduleCount; i++) { for (int j = 0; j < moduleCount; j++) { int num2 = 0; bool flag = qrCode.IsDark(i, j); for (int k = -1; k <= 1; k++) { if (i + k >= 0 && moduleCount > i + k) { for (int l = -1; l <= 1; l++) { if (j + l >= 0 && moduleCount > j + l && (k != 0 || l != 0) && flag == qrCode.IsDark(i + k, j + l)) { num2++; } } } } if (num2 > 5) { num += 3 + num2 - 5; } } } for (int m = 0; m < moduleCount - 1; m++) { for (int n = 0; n < moduleCount - 1; n++) { int num3 = 0; if (qrCode.IsDark(m, n)) { num3++; } if (qrCode.IsDark(m + 1, n)) { num3++; } if (qrCode.IsDark(m, n + 1)) { num3++; } if (qrCode.IsDark(m + 1, n + 1)) { num3++; } if (num3 == 0 || num3 == 4) { num += 3; } } } for (int num4 = 0; num4 < moduleCount; num4++) { for (int num5 = 0; num5 < moduleCount - 6; num5++) { if (qrCode.IsDark(num4, num5) && !qrCode.IsDark(num4, num5 + 1) && qrCode.IsDark(num4, num5 + 2) && qrCode.IsDark(num4, num5 + 3) && qrCode.IsDark(num4, num5 + 4) && !qrCode.IsDark(num4, num5 + 5) && qrCode.IsDark(num4, num5 + 6)) { num += 40; } } } for (int num6 = 0; num6 < moduleCount; num6++) { for (int num7 = 0; num7 < moduleCount - 6; num7++) { if (qrCode.IsDark(num7, num6) && !qrCode.IsDark(num7 + 1, num6) && qrCode.IsDark(num7 + 2, num6) && qrCode.IsDark(num7 + 3, num6) && qrCode.IsDark(num7 + 4, num6) && !qrCode.IsDark(num7 + 5, num6) && qrCode.IsDark(num7 + 6, num6)) { num += 40; } } } int num8 = 0; for (int num9 = 0; num9 < moduleCount; num9++) { for (int num10 = 0; num10 < moduleCount; num10++) { if (qrCode.IsDark(num10, num9)) { num8++; } } } int num11 = Math.Abs(100 * num8 / moduleCount / moduleCount - 50) / 5; return(num + num11 * 10); }
internal static int GetLostPoint(QRCode qrCode) { int moduleCount = qrCode.GetModuleCount(); int lostPoint = 0; // LEVEL1 for (int row = 0; row < moduleCount; row++) { for (int col = 0; col < moduleCount; col++) { int sameCount = 0; bool dark = qrCode.IsDark(row, col); for (int r = -1; r <= 1; r++) { if (row + r < 0 || moduleCount <= row + r) { continue; } for (int c = -1; c <= 1; c++) { if (col + c < 0 || moduleCount <= col + c) { continue; } if (r == 0 && c == 0) { continue; } if (dark == qrCode.IsDark(row + r, col + c)) { sameCount++; } } } if (sameCount > 5) { lostPoint += (3 + sameCount - 5); } } } // LEVEL2 for (int row = 0; row < moduleCount - 1; row++) { for (int col = 0; col < moduleCount - 1; col++) { int count = 0; if (qrCode.IsDark(row, col )) count++; if (qrCode.IsDark(row + 1, col )) count++; if (qrCode.IsDark(row, col + 1)) count++; if (qrCode.IsDark(row + 1, col + 1)) count++; if (count == 0 || count == 4) { lostPoint += 3; } } } // LEVEL3 for (int row = 0; row < moduleCount; row++) { for (int col = 0; col < moduleCount - 6; col++) { if (qrCode.IsDark(row, col) && !qrCode.IsDark(row, col + 1) && qrCode.IsDark(row, col + 2) && qrCode.IsDark(row, col + 3) && qrCode.IsDark(row, col + 4) && !qrCode.IsDark(row, col + 5) && qrCode.IsDark(row, col + 6)) { lostPoint += 40; } } } for (int col = 0; col < moduleCount; col++) { for (int row = 0; row < moduleCount - 6; row++) { if (qrCode.IsDark(row, col) && !qrCode.IsDark(row + 1, col) && qrCode.IsDark(row + 2, col) && qrCode.IsDark(row + 3, col) && qrCode.IsDark(row + 4, col) && !qrCode.IsDark(row + 5, col) && qrCode.IsDark(row + 6, col)) { lostPoint += 40; } } } // LEVEL4 int darkCount = 0; for (int col = 0; col < moduleCount; col++) { for (int row = 0; row < moduleCount; row++) { if (qrCode.IsDark(row, col)) { darkCount++; } } } int ratio = Math.Abs(100 * darkCount / moduleCount / moduleCount - 50) / 5; lostPoint += ratio * 10; return lostPoint; }