From 437c5f177f5de0cc5a434a7e886e3458685c2784 Mon Sep 17 00:00:00 2001 From: srowen Date: Wed, 2 May 2012 21:52:41 +0000 Subject: [PATCH] Back out PDF417 erasures change; doesn't quite work. But improve test and remove some dead EC code while we're here git-svn-id: https://zxing.googlecode.com/svn/trunk@2281 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../reedsolomon/ReedSolomonDecoder.java | 5 -- .../pdf417/decoder/ec/ErrorCorrection.java | 9 +--- .../decoder/ec/ErrorCorrectionTestCase.java | 48 ++++++++++--------- 3 files changed, 28 insertions(+), 34 deletions(-) diff --git a/core/src/com/google/zxing/common/reedsolomon/ReedSolomonDecoder.java b/core/src/com/google/zxing/common/reedsolomon/ReedSolomonDecoder.java index 49333ac45..1da9cef3c 100644 --- a/core/src/com/google/zxing/common/reedsolomon/ReedSolomonDecoder.java +++ b/core/src/com/google/zxing/common/reedsolomon/ReedSolomonDecoder.java @@ -98,18 +98,14 @@ public final class ReedSolomonDecoder { GenericGFPoly rLast = a; GenericGFPoly r = b; - GenericGFPoly sLast = field.getOne(); - GenericGFPoly s = field.getZero(); GenericGFPoly tLast = field.getZero(); GenericGFPoly t = field.getOne(); // Run Euclidean algorithm until r's degree is less than R/2 while (r.getDegree() >= R / 2) { GenericGFPoly rLastLast = rLast; - GenericGFPoly sLastLast = sLast; GenericGFPoly tLastLast = tLast; rLast = r; - sLast = s; tLast = t; // Divide rLastLast by rLast, with quotient in q and remainder in r @@ -128,7 +124,6 @@ public final class ReedSolomonDecoder { r = r.addOrSubtract(rLast.multiplyByMonomial(degreeDiff, scale)); } - s = q.multiply(sLast).addOrSubtract(sLastLast); t = q.multiply(tLast).addOrSubtract(tLastLast); } diff --git a/core/src/com/google/zxing/pdf417/decoder/ec/ErrorCorrection.java b/core/src/com/google/zxing/pdf417/decoder/ec/ErrorCorrection.java index aa72c7a35..0bfa65eaf 100644 --- a/core/src/com/google/zxing/pdf417/decoder/ec/ErrorCorrection.java +++ b/core/src/com/google/zxing/pdf417/decoder/ec/ErrorCorrection.java @@ -61,14 +61,14 @@ public final class ErrorCorrection { } ModulusPoly syndrome = new ModulusPoly(field, S); - syndrome = syndrome.multiply(knownErrors); + //syndrome = syndrome.multiply(knownErrors); ModulusPoly[] sigmaOmega = runEuclideanAlgorithm(field.buildMonomial(numECCodewords, 1), syndrome, numECCodewords); ModulusPoly sigma = sigmaOmega[0]; ModulusPoly omega = sigmaOmega[1]; - sigma = sigma.multiply(knownErrors); + //sigma = sigma.multiply(knownErrors); int[] errorLocations = findErrorLocations(sigma); int[] errorMagnitudes = findErrorMagnitudes(omega, sigma, errorLocations); @@ -94,18 +94,14 @@ public final class ErrorCorrection { ModulusPoly rLast = a; ModulusPoly r = b; - ModulusPoly sLast = field.getOne(); - ModulusPoly s = field.getZero(); ModulusPoly tLast = field.getZero(); ModulusPoly t = field.getOne(); // Run Euclidean algorithm until r's degree is less than R/2 while (r.getDegree() >= R / 2) { ModulusPoly rLastLast = rLast; - ModulusPoly sLastLast = sLast; ModulusPoly tLastLast = tLast; rLast = r; - sLast = s; tLast = t; // Divide rLastLast by rLast, with quotient in q and remainder in r @@ -124,7 +120,6 @@ public final class ErrorCorrection { r = r.subtract(rLast.multiplyByMonomial(degreeDiff, scale)); } - s = q.multiply(sLast).subtract(sLastLast).negative(); t = q.multiply(tLast).subtract(tLastLast).negative(); } diff --git a/core/test/src/com/google/zxing/pdf417/decoder/ec/ErrorCorrectionTestCase.java b/core/test/src/com/google/zxing/pdf417/decoder/ec/ErrorCorrectionTestCase.java index 54698d86d..3d99db1c5 100644 --- a/core/test/src/com/google/zxing/pdf417/decoder/ec/ErrorCorrectionTestCase.java +++ b/core/test/src/com/google/zxing/pdf417/decoder/ec/ErrorCorrectionTestCase.java @@ -27,17 +27,37 @@ import java.util.Random; public final class ErrorCorrectionTestCase extends AbstractErrorCorrectionTestCase { /** See ISO 15438, Annex Q */ + //private static final int[] PDF417_TEST = + // { 5, 453, 178, 121, 239 }; + //private static final int[] PDF417_TEST_WITH_EC = + // { 5, 453, 178, 121, 239, 452, 327, 657, 619 }; + private static final int[] PDF417_TEST = - { 5, 453, 178, 121, 239 }; + { 48,901, 56,141,627,856,330, 69,244,900, + 852,169,843,895,852,895,913,154,845,778, + 387, 89,869,901,219,474,543,650,169,201, + 9,160, 35, 70,900,900,900,900,900,900, + 900,900,900,900,900,900,900,900}; private static final int[] PDF417_TEST_WITH_EC = - { 5, 453, 178, 121, 239, 452, 327, 657, 619 }; + { 48,901, 56,141,627,856,330, 69,244,900, + 852,169,843,895,852,895,913,154,845,778, + 387, 89,869,901,219,474,543,650,169,201, + 9,160, 35, 70,900,900,900,900,900,900, + 900,900,900,900,900,900,900,900,769,843, + 591,910,605,206,706,917,371,469, 79,718, + 47,777,249,262,193,620,597,477,450,806, + 908,309,153,871,686,838,185,674, 68,679, + 691,794,497,479,234,250,496, 43,347,582, + 882,536,322,317,273,194,917,237,420,859, + 340,115,222,808,866,836,417,121,833,459, + 64,159}; private static final int ECC_BYTES = PDF417_TEST_WITH_EC.length - PDF417_TEST.length; // Example is EC level 1 (s=1). The number of erasures (l) and substitutions (f) must obey: // l + 2f <= 2^(s+1) - 3 - private static final int EC_LEVEL = 1; + private static final int EC_LEVEL = 5; private static final int ERROR_LIMIT = (1 << (EC_LEVEL + 1)) - 3; private static final int MAX_ERRORS = ERROR_LIMIT / 2; - private static final int MAX_ERASURES = ERROR_LIMIT; + //private static final int MAX_ERASURES = ERROR_LIMIT; private final ErrorCorrection ec = new ErrorCorrection(); @@ -81,6 +101,7 @@ public final class ErrorCorrectionTestCase extends AbstractErrorCorrectionTestCa } } + /* @Test public void testMaxErasures() throws ChecksumException { Random random = getRandom(); @@ -103,24 +124,7 @@ public final class ErrorCorrectionTestCase extends AbstractErrorCorrectionTestCa // good } } - - @Test - public void testErasureAndError() throws ChecksumException { - // Not sure this is valid according to the spec but it's correctable - Random random = getRandom(); - for (int i = 0; i < PDF417_TEST_WITH_EC.length; i++) { - int[] received = PDF417_TEST_WITH_EC.clone(); - received[i] = random.nextInt(256); - for (int j = 0; j < PDF417_TEST_WITH_EC.length; j++) { - if (i == j) { - continue; - } - received[j] = 0; - int[] erasures = {j}; - checkDecode(received, erasures); - } - } - } + */ private void checkDecode(int[] received) throws ChecksumException { checkDecode(received, new int[0]);