mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Issue 1758: revert last change, applying penalty at edge is necessary. Try new change from original code to avoid applying in the "2 1 3 1 1" case
git-svn-id: https://zxing.googlecode.com/svn/trunk@2867 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
8d18bab224
commit
23ab47533b
|
@ -75,44 +75,48 @@ final class MaskUtil {
|
|||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
byte[] arrayY = array[y]; // We can at least optimize this access
|
||||
if (x + 8 < width &&
|
||||
arrayY[x] == 0 &&
|
||||
arrayY[x + 1] == 1 &&
|
||||
arrayY[x + 2] == 0 &&
|
||||
arrayY[x + 3] == 1 &&
|
||||
arrayY[x + 4] == 1 &&
|
||||
arrayY[x + 5] == 1 &&
|
||||
arrayY[x + 6] == 0 &&
|
||||
arrayY[x + 7] == 1 &&
|
||||
arrayY[x + 8] == 0 &&
|
||||
((x + 11 < width &&
|
||||
if (x + 6 < width &&
|
||||
(x == 0 || arrayY[x-1] == 0) &&
|
||||
arrayY[x] == 1 &&
|
||||
arrayY[x + 1] == 0 &&
|
||||
arrayY[x + 2] == 1 &&
|
||||
arrayY[x + 3] == 1 &&
|
||||
arrayY[x + 4] == 1 &&
|
||||
arrayY[x + 5] == 0 &&
|
||||
arrayY[x + 6] == 1 &&
|
||||
(x + 7 >= width || arrayY[x+7] == 0) &&
|
||||
((x + 10 < width &&
|
||||
arrayY[x + 7] == 0 &&
|
||||
arrayY[x + 8] == 0 &&
|
||||
arrayY[x + 9] == 0 &&
|
||||
arrayY[x + 10] == 0 &&
|
||||
arrayY[x + 11] == 0) ||
|
||||
(x - 3 >= 0 &&
|
||||
arrayY[x - 1] == 0 &&
|
||||
arrayY[x - 2] == 0 &&
|
||||
arrayY[x - 3] == 0))) {
|
||||
arrayY[x + 10] == 0) ||
|
||||
(x - 4 >= 0 &&
|
||||
arrayY[x - 1] == 0 &&
|
||||
arrayY[x - 2] == 0 &&
|
||||
arrayY[x - 3] == 0 &&
|
||||
arrayY[x - 4] == 0))) {
|
||||
numPenalties++;
|
||||
}
|
||||
if (y + 8 < height &&
|
||||
array[y][x] == 0 &&
|
||||
array[y + 1][x] == 1 &&
|
||||
array[y + 2][x] == 0 &&
|
||||
array[y + 3][x] == 1 &&
|
||||
array[y + 4][x] == 1 &&
|
||||
array[y + 5][x] == 1 &&
|
||||
array[y + 6][x] == 0 &&
|
||||
array[y + 7][x] == 1 &&
|
||||
array[y + 8][x] == 0 &&
|
||||
((y + 11 < height &&
|
||||
if (y + 6 < height &&
|
||||
(y == 0 || array[y-1][x] == 0) &&
|
||||
array[y][x] == 1 &&
|
||||
array[y + 1][x] == 0 &&
|
||||
array[y + 2][x] == 1 &&
|
||||
array[y + 3][x] == 1 &&
|
||||
array[y + 4][x] == 1 &&
|
||||
array[y + 5][x] == 0 &&
|
||||
array[y + 6][x] == 1 &&
|
||||
(y + 7 >= height || array[y+7][x] == 0) &&
|
||||
((y + 10 < height &&
|
||||
array[y + 7][x] == 0 &&
|
||||
array[y + 8][x] == 0 &&
|
||||
array[y + 9][x] == 0 &&
|
||||
array[y + 10][x] == 0 &&
|
||||
array[y + 11][x] == 0) ||
|
||||
(y - 3 >= 0 &&
|
||||
array[y - 1][x] == 0 &&
|
||||
array[y - 2][x] == 0 &&
|
||||
array[y - 3][x] == 0))) {
|
||||
array[y + 10][x] == 0) ||
|
||||
(y - 4 >= 0 &&
|
||||
array[y - 1][x] == 0 &&
|
||||
array[y - 2][x] == 0 &&
|
||||
array[y - 3][x] == 0 &&
|
||||
array[y - 4][x] == 0))) {
|
||||
numPenalties++;
|
||||
}
|
||||
}
|
||||
|
|
BIN
core/test/data/golden/qrcode/renderer-test-02.png
Normal file
BIN
core/test/data/golden/qrcode/renderer-test-02.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 189 B |
BIN
core/test/data/golden/qrcode/renderer-test-03.png
Normal file
BIN
core/test/data/golden/qrcode/renderer-test-03.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 280 B |
|
@ -128,6 +128,18 @@ public final class QRCodeWriterTestCase extends Assert {
|
|||
public void testRegressionTest() throws Exception {
|
||||
compareToGoldenFile("http://www.google.com/", ErrorCorrectionLevel.M, 99,
|
||||
"renderer-test-01.png");
|
||||
|
||||
compareToGoldenFile("12345", ErrorCorrectionLevel.L, 58, "renderer-test-02.png");
|
||||
|
||||
// Test in Katakana in Shift_JIS.
|
||||
// TODO: this test is bogus now that byte mode has been basically fixed to assuming ISO-8859-1 encoding
|
||||
// The real solution is to implement Kanji mode, in which case the golden file will be wrong again
|
||||
/*
|
||||
compareToGoldenFile(
|
||||
new String(new byte[] {(byte)0x83, 0x65, (byte)0x83, 0x58, (byte)0x83, 0x67}, "Shift_JIS"),
|
||||
ErrorCorrectionLevel.H, 145,
|
||||
"renderer-test-03.png");
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -137,29 +137,29 @@ public final class EncoderTestCase extends Assert {
|
|||
" mode: BYTE\n" +
|
||||
" ecLevel: H\n" +
|
||||
" version: 1\n" +
|
||||
" maskPattern: 0\n" +
|
||||
" maskPattern: 3\n" +
|
||||
" matrix:\n" +
|
||||
" 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 1 1 1 1 1 1\n" +
|
||||
" 1 0 0 0 0 0 1 0 0 1 1 0 1 0 1 0 0 0 0 0 1\n" +
|
||||
" 1 0 1 1 1 0 1 0 0 1 0 1 1 0 1 0 1 1 1 0 1\n" +
|
||||
" 1 0 1 1 1 0 1 0 1 1 1 1 0 0 1 0 1 1 1 0 1\n" +
|
||||
" 1 0 1 1 1 0 1 0 0 0 0 1 0 0 1 0 1 1 1 0 1\n" +
|
||||
" 1 0 0 0 0 0 1 0 0 1 1 1 1 0 1 0 0 0 0 0 1\n" +
|
||||
" 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1\n" +
|
||||
" 1 0 0 0 0 0 1 0 0 0 1 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 1\n" +
|
||||
" 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0\n" +
|
||||
" 0 0 1 1 0 0 1 1 1 1 0 0 0 1 1 0 1 0 0 0 0\n" +
|
||||
" 0 0 1 1 1 0 0 0 0 0 1 1 0 0 0 1 0 1 1 1 0\n" +
|
||||
" 0 1 0 1 0 1 1 1 0 1 0 1 0 0 0 0 0 1 1 1 1\n" +
|
||||
" 1 1 0 0 1 0 0 1 1 0 0 1 1 1 1 0 1 0 1 1 0\n" +
|
||||
" 0 0 0 0 1 0 1 1 1 1 0 0 0 0 0 1 0 0 1 0 0\n" +
|
||||
" 0 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 0 0 0 1\n" +
|
||||
" 1 1 1 1 1 1 1 0 1 1 1 0 1 0 1 1 0 0 1 0 0\n" +
|
||||
" 1 0 0 0 0 0 1 0 0 0 1 0 0 1 1 1 1 1 1 0 1\n" +
|
||||
" 1 0 1 1 1 0 1 0 0 1 0 0 0 0 1 1 0 0 0 0 0\n" +
|
||||
" 1 0 1 1 1 0 1 0 1 1 1 0 1 0 0 0 1 1 0 0 0\n" +
|
||||
" 1 0 1 1 1 0 1 0 1 1 0 0 0 1 0 0 1 0 0 0 0\n" +
|
||||
" 1 0 0 0 0 0 1 0 0 0 0 1 1 0 1 0 1 0 1 1 0\n" +
|
||||
" 1 1 1 1 1 1 1 0 0 1 0 1 1 1 0 1 1 0 0 0 0\n" +
|
||||
">>\n";
|
||||
assertEquals(expected, qrCode.toString());
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ public final class MaskUtilTestCase extends Assert {
|
|||
@Test
|
||||
public void testApplyMaskPenaltyRule3() {
|
||||
// Horizontal 00001011101.
|
||||
ByteMatrix matrix = new ByteMatrix(12, 1);
|
||||
ByteMatrix matrix = new ByteMatrix(11, 1);
|
||||
matrix.set(0, 0, 0);
|
||||
matrix.set(1, 0, 0);
|
||||
matrix.set(2, 0, 0);
|
||||
|
@ -103,25 +103,23 @@ public final class MaskUtilTestCase extends Assert {
|
|||
matrix.set(8, 0, 1);
|
||||
matrix.set(9, 0, 0);
|
||||
matrix.set(10, 0, 1);
|
||||
matrix.set(11, 0, 0);
|
||||
assertEquals(40, MaskUtil.applyMaskPenaltyRule3(matrix));
|
||||
// Horizontal 10111010000.
|
||||
matrix = new ByteMatrix(12, 1);
|
||||
matrix.set(0, 0, 0);
|
||||
matrix.set(1, 0, 1);
|
||||
matrix.set(2, 0, 0);
|
||||
matrix = new ByteMatrix(11, 1);
|
||||
matrix.set(0, 0, 1);
|
||||
matrix.set(1, 0, 0);
|
||||
matrix.set(2, 0, 1);
|
||||
matrix.set(3, 0, 1);
|
||||
matrix.set(4, 0, 1);
|
||||
matrix.set(5, 0, 1);
|
||||
matrix.set(6, 0, 0);
|
||||
matrix.set(7, 0, 1);
|
||||
matrix.set(5, 0, 0);
|
||||
matrix.set(6, 0, 1);
|
||||
matrix.set(7, 0, 0);
|
||||
matrix.set(8, 0, 0);
|
||||
matrix.set(9, 0, 0);
|
||||
matrix.set(10, 0, 0);
|
||||
matrix.set(11, 0, 0);
|
||||
assertEquals(40, MaskUtil.applyMaskPenaltyRule3(matrix));
|
||||
// Vertical 00001011101.
|
||||
matrix = new ByteMatrix(1, 12);
|
||||
matrix = new ByteMatrix(1, 11);
|
||||
matrix.set(0, 0, 0);
|
||||
matrix.set(0, 1, 0);
|
||||
matrix.set(0, 2, 0);
|
||||
|
@ -133,22 +131,20 @@ public final class MaskUtilTestCase extends Assert {
|
|||
matrix.set(0, 8, 1);
|
||||
matrix.set(0, 9, 0);
|
||||
matrix.set(0, 10, 1);
|
||||
matrix.set(0, 11, 0);
|
||||
assertEquals(40, MaskUtil.applyMaskPenaltyRule3(matrix));
|
||||
// Vertical 10111010000.
|
||||
matrix = new ByteMatrix(1, 12);
|
||||
matrix.set(0, 0, 0);
|
||||
matrix.set(0, 1, 1);
|
||||
matrix.set(0, 2, 0);
|
||||
matrix = new ByteMatrix(1, 11);
|
||||
matrix.set(0, 0, 1);
|
||||
matrix.set(0, 1, 0);
|
||||
matrix.set(0, 2, 1);
|
||||
matrix.set(0, 3, 1);
|
||||
matrix.set(0, 4, 1);
|
||||
matrix.set(0, 5, 1);
|
||||
matrix.set(0, 6, 0);
|
||||
matrix.set(0, 7, 1);
|
||||
matrix.set(0, 5, 0);
|
||||
matrix.set(0, 6, 1);
|
||||
matrix.set(0, 7, 0);
|
||||
matrix.set(0, 8, 0);
|
||||
matrix.set(0, 9, 0);
|
||||
matrix.set(0, 10, 0);
|
||||
matrix.set(0, 11, 0);
|
||||
assertEquals(40, MaskUtil.applyMaskPenaltyRule3(matrix));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue