summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorSean Owen <srowen@gmail.com>2017-11-16 20:53:40 +0300
committerSean Owen <srowen@gmail.com>2017-11-16 20:53:40 +0300
commit63bcf0ca9cfa62ee20da1eca02deaef4e1721320 (patch)
tree8b46b8b5bfa8ef7c8fe6e5bde69b6321d741d835 /core/src
parent5409e6b6fdc256ac1077f18c39ecda4e255a7595 (diff)
downloadzxing-63bcf0ca9cfa62ee20da1eca02deaef4e1721320.tar.xz
Closes #909
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/java/com/google/zxing/oned/ITFReader.java36
-rw-r--r--core/src/main/java/com/google/zxing/oned/ITFWriter.java22
-rw-r--r--core/src/test/java/com/google/zxing/oned/ITFBlackBox1TestCase.java4
3 files changed, 52 insertions, 10 deletions
diff --git a/core/src/main/java/com/google/zxing/oned/ITFReader.java b/core/src/main/java/com/google/zxing/oned/ITFReader.java
index d346d9ef2..da5c05533 100644
--- a/core/src/main/java/com/google/zxing/oned/ITFReader.java
+++ b/core/src/main/java/com/google/zxing/oned/ITFReader.java
@@ -45,9 +45,10 @@ import java.util.Map;
public final class ITFReader extends OneDReader {
private static final float MAX_AVG_VARIANCE = 0.38f;
- private static final float MAX_INDIVIDUAL_VARIANCE = 0.78f;
+ private static final float MAX_INDIVIDUAL_VARIANCE = 0.5f;
- private static final int W = 3; // Pixel width of a wide line
+ private static final int W = 3; // Pixel width of a 3x wide line
+ private static final int w = 2; // Pixel width of a 2x wide line
private static final int N = 1; // Pixed width of a narrow line
/** Valid ITF lengths. Anything longer than the largest value is also allowed. */
@@ -63,12 +64,27 @@ public final class ITFReader extends OneDReader {
* searching for the END_PATTERN
*/
private static final int[] START_PATTERN = {N, N, N, N};
- private static final int[] END_PATTERN_REVERSED = {N, N, W};
+ private static final int[][] END_PATTERN_REVERSED = {
+ {N, N, w}, // 2x
+ {N, N, W} // 3x
+ };
+
+ // See ITFWriter.PATTERNS
/**
* Patterns of Wide / Narrow lines to indicate each digit
*/
- static final int[][] PATTERNS = {
+ private static final int[][] PATTERNS = {
+ {N, N, w, w, N}, // 0
+ {w, N, N, N, w}, // 1
+ {N, w, N, N, w}, // 2
+ {w, w, N, N, N}, // 3
+ {N, N, w, N, w}, // 4
+ {w, N, w, N, N}, // 5
+ {N, w, w, N, N}, // 6
+ {N, N, N, w, w}, // 7
+ {w, N, N, w, N}, // 8
+ {N, w, N, w, N}, // 9
{N, N, W, W, N}, // 0
{W, N, N, N, W}, // 1
{N, W, N, N, W}, // 2
@@ -259,7 +275,12 @@ public final class ITFReader extends OneDReader {
row.reverse();
try {
int endStart = skipWhiteSpace(row);
- int[] endPattern = findGuardPattern(row, endStart, END_PATTERN_REVERSED);
+ int[] endPattern;
+ try {
+ endPattern = findGuardPattern(row, endStart, END_PATTERN_REVERSED[0]);
+ } catch (NotFoundException nfe) {
+ endPattern = findGuardPattern(row, endStart, END_PATTERN_REVERSED[1]);
+ }
// The start & end patterns must be pre/post fixed by a quiet zone. This
// zone must be at least 10 times the width of a narrow line.
@@ -340,10 +361,13 @@ public final class ITFReader extends OneDReader {
if (variance < bestVariance) {
bestVariance = variance;
bestMatch = i;
+ } else if (variance == bestVariance) {
+ // if we find a second 'best match' with the same variance, we can not reliably report to have a suitable match
+ bestMatch = -1;
}
}
if (bestMatch >= 0) {
- return bestMatch;
+ return bestMatch % 10;
} else {
throw NotFoundException.getNotFoundInstance();
}
diff --git a/core/src/main/java/com/google/zxing/oned/ITFWriter.java b/core/src/main/java/com/google/zxing/oned/ITFWriter.java
index 8cfa1e7f1..28b0e581e 100644
--- a/core/src/main/java/com/google/zxing/oned/ITFWriter.java
+++ b/core/src/main/java/com/google/zxing/oned/ITFWriter.java
@@ -33,6 +33,24 @@ public final class ITFWriter extends OneDimensionalCodeWriter {
private static final int[] START_PATTERN = {1, 1, 1, 1};
private static final int[] END_PATTERN = {3, 1, 1};
+ private static final int W = 3; // Pixel width of a 3x wide line
+ private static final int N = 1; // Pixed width of a narrow line
+
+ // See ITFReader.PATTERNS
+
+ private static final int[][] PATTERNS = {
+ {N, N, W, W, N}, // 0
+ {W, N, N, N, W}, // 1
+ {N, W, N, N, W}, // 2
+ {W, W, N, N, N}, // 3
+ {N, N, W, N, W}, // 4
+ {W, N, W, N, N}, // 5
+ {N, W, W, N, N}, // 6
+ {N, N, N, W, W}, // 7
+ {W, N, N, W, N}, // 8
+ {N, W, N, W, N} // 9
+ };
+
@Override
public BitMatrix encode(String contents,
BarcodeFormat format,
@@ -63,8 +81,8 @@ public final class ITFWriter extends OneDimensionalCodeWriter {
int two = Character.digit(contents.charAt(i + 1), 10);
int[] encoding = new int[10];
for (int j = 0; j < 5; j++) {
- encoding[2 * j] = ITFReader.PATTERNS[one][j];
- encoding[2 * j + 1] = ITFReader.PATTERNS[two][j];
+ encoding[2 * j] = PATTERNS[one][j];
+ encoding[2 * j + 1] = PATTERNS[two][j];
}
pos += appendPattern(result, pos, encoding, true);
}
diff --git a/core/src/test/java/com/google/zxing/oned/ITFBlackBox1TestCase.java b/core/src/test/java/com/google/zxing/oned/ITFBlackBox1TestCase.java
index 4e16649b6..393b62227 100644
--- a/core/src/test/java/com/google/zxing/oned/ITFBlackBox1TestCase.java
+++ b/core/src/test/java/com/google/zxing/oned/ITFBlackBox1TestCase.java
@@ -27,8 +27,8 @@ public final class ITFBlackBox1TestCase extends AbstractBlackBoxTestCase {
public ITFBlackBox1TestCase() {
super("src/test/resources/blackbox/itf-1", new MultiFormatReader(), BarcodeFormat.ITF);
- addTest(9, 13, 0.0f);
- addTest(12, 13, 180.0f);
+ addTest(14, 14, 0.0f);
+ addTest(14, 14, 180.0f);
}
}