diff --git a/core/src/com/google/zxing/qrcode/detector/DetectorResult.java b/core/src/com/google/zxing/common/DetectorResult.java similarity index 89% rename from core/src/com/google/zxing/qrcode/detector/DetectorResult.java rename to core/src/com/google/zxing/common/DetectorResult.java index 15fb78c0e..1dbfae5fb 100644 --- a/core/src/com/google/zxing/qrcode/detector/DetectorResult.java +++ b/core/src/com/google/zxing/common/DetectorResult.java @@ -14,10 +14,9 @@ * limitations under the License. */ -package com.google.zxing.qrcode.detector; +package com.google.zxing.common; import com.google.zxing.ResultPoint; -import com.google.zxing.common.BitMatrix; /** *
Encapsulates the result of detecting a barcode in an image. This includes the raw @@ -31,7 +30,7 @@ public final class DetectorResult { private final BitMatrix bits; private final ResultPoint[] points; - DetectorResult(BitMatrix bits, ResultPoint[] points) { + public DetectorResult(BitMatrix bits, ResultPoint[] points) { this.bits = bits; this.points = points; } diff --git a/core/src/com/google/zxing/datamatrix/DataMatrixReader.java b/core/src/com/google/zxing/datamatrix/DataMatrixReader.java index 5d7b4a30b..e5bff7310 100644 --- a/core/src/com/google/zxing/datamatrix/DataMatrixReader.java +++ b/core/src/com/google/zxing/datamatrix/DataMatrixReader.java @@ -17,7 +17,6 @@ package com.google.zxing.datamatrix; import com.google.zxing.BarcodeFormat; -import com.google.zxing.DecodeHintType; import com.google.zxing.MonochromeBitmapSource; import com.google.zxing.Reader; import com.google.zxing.ReaderException; @@ -25,8 +24,6 @@ import com.google.zxing.Result; import com.google.zxing.ResultPoint; import com.google.zxing.common.BitMatrix; import com.google.zxing.datamatrix.decoder.Decoder; -import com.google.zxing.datamatrix.detector.Detector; -import com.google.zxing.datamatrix.detector.DetectorResult; import java.util.Hashtable; diff --git a/core/src/com/google/zxing/datamatrix/decoder/BitMatrixParser.java b/core/src/com/google/zxing/datamatrix/decoder/BitMatrixParser.java index 3bc61cd8d..a14eb9514 100644 --- a/core/src/com/google/zxing/datamatrix/decoder/BitMatrixParser.java +++ b/core/src/com/google/zxing/datamatrix/decoder/BitMatrixParser.java @@ -40,7 +40,7 @@ final class BitMatrixParser { } version = readVersion(bitMatrix); - this.mappingBitMatrix = ExtractDataRegion(bitMatrix, version); + this.mappingBitMatrix = extractDataRegion(bitMatrix, version); // TODO(bbrown): Make this work for rectangular symbols this.readMappingMatrix = new BitMatrix(this.mappingBitMatrix.getDimension()); } @@ -81,8 +81,6 @@ final class BitMatrixParser { byte[] result = new byte[version.getTotalCodewords()]; int resultOffset = 0; - int currentByte = 0; - int bitsRead = 0; int row = 4; int column = 0; @@ -144,10 +142,10 @@ final class BitMatrixParser { /** *
Reads a bit of the mapping matrix accounting for boundry wrapping.
* - * @param Row to read in the mapping matrix - * @param Column to read in the mapping matrix - * @param Number of rows in the mapping matrix - * @param Number of columns in the mapping matrix + * @param row Row to read in the mapping matrix + * @param column Column to read in the mapping matrix + * @param numRows Number of rows in the mapping matrix + * @param numColumns Number of columns in the mapping matrix * @return value of the given bit in the mapping matrix */ boolean readModule(int row, int column, int numRows, int numColumns) { @@ -169,10 +167,10 @@ final class BitMatrixParser { * *See ISO 16022:2006, 5.8.1 Figure 6
* - * @param Current row in the mapping matrix, anchored at the 8th bit (LSB) of the pattern - * @param Current column in the mapping matrix, anchored at the 8th bit (LSB) of the pattern - * @param Number of rows in the mapping matrix - * @param Number of columns in the mapping matrix + * @param row Current row in the mapping matrix, anchored at the 8th bit (LSB) of the pattern + * @param column Current column in the mapping matrix, anchored at the 8th bit (LSB) of the pattern + * @param numRows Number of rows in the mapping matrix + * @param numColumns Number of columns in the mapping matrix * @return byte from the utah shape */ int readUtah(int row, int column, int numRows, int numColumns) { @@ -216,8 +214,8 @@ final class BitMatrixParser { * *See ISO 16022:2006, Figure F.3
* - * @param Number of rows in the mapping matrix - * @param Number of columns in the mapping matrix + * @param numRows Number of rows in the mapping matrix + * @param numColumns Number of columns in the mapping matrix * @return byte from the Corner condition 1 */ int readCorner1(int numRows, int numColumns) { @@ -261,8 +259,8 @@ final class BitMatrixParser { * *See ISO 16022:2006, Figure F.4
* - * @param Number of rows in the mapping matrix - * @param Number of columns in the mapping matrix + * @param numRows Number of rows in the mapping matrix + * @param numColumns Number of columns in the mapping matrix * @return byte from the Corner condition 2 */ int readCorner2(int numRows, int numColumns) { @@ -306,8 +304,8 @@ final class BitMatrixParser { * *See ISO 16022:2006, Figure F.5
* - * @param Number of rows in the mapping matrix - * @param Number of columns in the mapping matrix + * @param numRows Number of rows in the mapping matrix + * @param numColumns Number of columns in the mapping matrix * @return byte from the Corner condition 3 */ int readCorner3(int numRows, int numColumns) { @@ -351,8 +349,8 @@ final class BitMatrixParser { * *See ISO 16022:2006, Figure F.6
* - * @param Number of rows in the mapping matrix - * @param Number of columns in the mapping matrix + * @param numRows Number of rows in the mapping matrix + * @param numColumns Number of columns in the mapping matrix * @return byte from the Corner condition 4 */ int readCorner4(int numRows, int numColumns) { @@ -395,11 +393,11 @@ final class BitMatrixParser { *Extracts the data region from a {@link BitMatrix} that contains * alignment patterns.
* - * @param bitMarix Original {@link BitMatrix} with alignment patterns + * @param bitMatrix Original {@link BitMatrix} with alignment patterns * @param version {@link Version} information corresponding with the bitMatrix * @return BitMatrix that has the alignment patterns removed */ - BitMatrix ExtractDataRegion(BitMatrix bitMatrix, Version version) { + BitMatrix extractDataRegion(BitMatrix bitMatrix, Version version) { int symbolSizeRows = version.getSymbolSizeRows(); int symbolSizeColumns = version.getSymbolSizeColumns(); diff --git a/core/src/com/google/zxing/datamatrix/decoder/DecodedBitStreamParser.java b/core/src/com/google/zxing/datamatrix/decoder/DecodedBitStreamParser.java index 9d6f2079d..09dcebe5d 100644 --- a/core/src/com/google/zxing/datamatrix/decoder/DecodedBitStreamParser.java +++ b/core/src/com/google/zxing/datamatrix/decoder/DecodedBitStreamParser.java @@ -18,7 +18,6 @@ package com.google.zxing.datamatrix.decoder; import com.google.zxing.ReaderException; import com.google.zxing.common.BitSource; -import java.io.UnsupportedEncodingException; /** *Data Matrix Codes can encode text as bits in one of several modes, and can use multiple modes
@@ -104,12 +103,10 @@ final class DecodedBitStreamParser {
*/
private static int decodeAsciiSegment(BitSource bits,
StringBuffer result) throws ReaderException {
- char oneByte;
boolean upperShift = false;
- int bytesProcessed = 0;
do {
- oneByte = (char) bits.readBits(8);
- if (oneByte == 0) {
+ char oneByte = (char) bits.readBits(8);
+ if (oneByte == '\0') {
// TODO(bbrown): I think this would be a bug, not sure
throw new ReaderException("0 is an invalid ASCII codeword");
} else if (oneByte <= 128) { // ASCII data (ASCII value + 1)
@@ -164,7 +161,6 @@ final class DecodedBitStreamParser {
StringBuffer result) throws ReaderException {
// Three C40 values are encoded in a 16-bit value as
// (1600 * C1) + (40 * C2) + C3 + 1
- char firstByte;
int shift = 0;
// TODO(bbrown): The Upper Shift with C40 doesn't work in the 4 value scenario all the time
boolean upperShift = false;
@@ -175,67 +171,67 @@ final class DecodedBitStreamParser {
return ASCII_ENCODE;
}
- firstByte = (char) bits.readBits(8);
-
+ char firstByte = (char) bits.readBits(8);
+
if (firstByte == 254) { // Unlatch codeword
return ASCII_ENCODE;
}
- int fullBitValue = firstByte * 256 + bits.readBits(8) - 1;
+ int fullBitValue = (firstByte << 8) + bits.readBits(8) - 1;
- char[] CValues = new char[3];
- CValues[0] = (char) (fullBitValue / 1600);
- fullBitValue -= CValues[0] * 1600;
- CValues[1] = (char) (fullBitValue / 40);
- fullBitValue -= CValues[1] * 40;
- CValues[2] = (char) (fullBitValue);
+ char[] cValues = new char[3];
+ cValues[0] = (char) (fullBitValue / 1600);
+ fullBitValue -= cValues[0] * 1600;
+ cValues[1] = (char) (fullBitValue / 40);
+ fullBitValue -= cValues[1] * 40;
+ cValues[2] = (char) fullBitValue;
for (int i = 0; i < 3; i++) {
if (shift == 0) {
- if (CValues[i] == 0) { // Shift 1
+ if (cValues[i] == 0) { // Shift 1
shift = 1;
continue;
- } else if (CValues[i] == 1) { // Shift 2
+ } else if (cValues[i] == 1) { // Shift 2
shift = 2;
continue;
- } else if (CValues[i] == 2) { // Shift 3
+ } else if (cValues[i] == 2) { // Shift 3
shift = 3;
continue;
}
if (upperShift) {
- result.append((char)(C40_BASIC_SET_CHARS[CValues[i]] + 128));
+ result.append((char)(C40_BASIC_SET_CHARS[cValues[i]] + 128));
upperShift = false;
} else {
- result.append(C40_BASIC_SET_CHARS[CValues[i]]);
+ result.append(C40_BASIC_SET_CHARS[cValues[i]]);
}
} else if (shift == 1) {
if (upperShift) {
- result.append((char) (CValues[i] + 128));
+ result.append((char) (cValues[i] + 128));
upperShift = false;
} else {
- result.append((char) CValues[i]);
+ result.append(cValues[i]);
}
} else if (shift == 2) {
- if (CValues[i] < 27) {
+ if (cValues[i] < 27) {
if(upperShift) {
- result.append((char)(C40_SHIFT2_SET_CHARS[CValues[i]] + 128));
+ result.append((char)(C40_SHIFT2_SET_CHARS[cValues[i]] + 128));
upperShift = false;
} else {
- result.append(C40_SHIFT2_SET_CHARS[CValues[i]]);
+ result.append(C40_SHIFT2_SET_CHARS[cValues[i]]);
}
- } else if (CValues[i] == 27) { // FNC1
+ } else if (cValues[i] == 27) { // FNC1
throw new ReaderException("Currently not supporting FNC1");
- } else if (CValues[i] == 30) { // Upper Shirt
+ } else if (cValues[i] == 30) { // Upper Shirt
upperShift = true;
} else {
- throw new ReaderException(Integer.toString(CValues[i]) + " is not valid in the C40 Shift 2 set");
+ throw new ReaderException(Integer.toString(cValues[i]) + " is not valid in the C40 Shift 2 set");
}
} else if (shift == 3) {
if (upperShift) {
- result.append((char) (CValues[i] + 224));
+ result.append((char) (cValues[i] + 224));
upperShift = false;
} else {
- result.append((char) CValues[i] + 96);
+ result.append((char) cValues[i] + 96);
}
} else {
throw new ReaderException("Invalid shift value");
@@ -252,7 +248,6 @@ final class DecodedBitStreamParser {
StringBuffer result) throws ReaderException {
// Three Text values are encoded in a 16-bit value as
// (1600 * C1) + (40 * C2) + C3 + 1
- char firstByte;
int shift = 0;
// TODO(bbrown): The Upper Shift with Text doesn't work in the 4 value scenario all the time
boolean upperShift = false;
@@ -263,68 +258,68 @@ final class DecodedBitStreamParser {
return ASCII_ENCODE;
}
- firstByte = (char) bits.readBits(8);
-
+ char firstByte = (char) bits.readBits(8);
+
if (firstByte == 254) { // Unlatch codeword
return ASCII_ENCODE;
}
- int fullBitValue = firstByte * 256 + bits.readBits(8) - 1;
+ int fullBitValue = (firstByte << 8) + bits.readBits(8) - 1;
- char[] CValues = new char[3];
- CValues[0] = (char) (fullBitValue / 1600);
- fullBitValue -= CValues[0] * 1600;
- CValues[1] = (char) (fullBitValue / 40);
- fullBitValue -= CValues[1] * 40;
- CValues[2] = (char) (fullBitValue);
+ char[] cValues = new char[3];
+ cValues[0] = (char) (fullBitValue / 1600);
+ fullBitValue -= cValues[0] * 1600;
+ cValues[1] = (char) (fullBitValue / 40);
+ fullBitValue -= cValues[1] * 40;
+ cValues[2] = (char) fullBitValue;
for (int i = 0; i < 3; i++) {
if (shift == 0) {
- if (CValues[i] == 0) { // Shift 1
+ if (cValues[i] == 0) { // Shift 1
shift = 1;
continue;
- } else if (CValues[i] == 1) { // Shift 2
+ } else if (cValues[i] == 1) { // Shift 2
shift = 2;
continue;
- } else if (CValues[i] == 2) { // Shift 3
+ } else if (cValues[i] == 2) { // Shift 3
shift = 3;
continue;
}
if (upperShift) {
- result.append((char)(TEXT_BASIC_SET_CHARS[CValues[i]] + 128));
+ result.append((char)(TEXT_BASIC_SET_CHARS[cValues[i]] + 128));
upperShift = false;
} else {
- result.append(TEXT_BASIC_SET_CHARS[CValues[i]]);
+ result.append(TEXT_BASIC_SET_CHARS[cValues[i]]);
}
} else if (shift == 1) {
if (upperShift) {
- result.append((char) (CValues[i] + 128));
+ result.append((char) (cValues[i] + 128));
upperShift = false;
} else {
- result.append((char) CValues[i]);
+ result.append((char) cValues[i]);
}
} else if (shift == 2) {
// Shift 2 for Text is the same encoding as C40
- if (CValues[i] < 27) {
+ if (cValues[i] < 27) {
if(upperShift) {
- result.append((char)(C40_SHIFT2_SET_CHARS[CValues[i]] + 128));
+ result.append((char)(C40_SHIFT2_SET_CHARS[cValues[i]] + 128));
upperShift = false;
} else {
- result.append(C40_SHIFT2_SET_CHARS[CValues[i]]);
+ result.append(C40_SHIFT2_SET_CHARS[cValues[i]]);
}
- } else if (CValues[i] == 27) { // FNC1
+ } else if (cValues[i] == 27) { // FNC1
throw new ReaderException("Currently not supporting FNC1");
- } else if (CValues[i] == 30) { // Upper Shirt
+ } else if (cValues[i] == 30) { // Upper Shirt
upperShift = true;
} else {
- throw new ReaderException(Integer.toString(CValues[i]) + " is not valid in the C40 Shift 2 set");
+ throw new ReaderException(Integer.toString(cValues[i]) + " is not valid in the C40 Shift 2 set");
}
} else if (shift == 3) {
if (upperShift) {
- result.append((char)(TEXT_SHIFT3_SET_CHARS[CValues[i]] + 128));
+ result.append((char)(TEXT_SHIFT3_SET_CHARS[cValues[i]] + 128));
upperShift = false;
} else {
- result.append(TEXT_SHIFT3_SET_CHARS[CValues[i]]);
+ result.append(TEXT_SHIFT3_SET_CHARS[cValues[i]]);
}
} else {
throw new ReaderException("Invalid shift value");
@@ -341,7 +336,6 @@ final class DecodedBitStreamParser {
StringBuffer result) throws ReaderException {
// Three ANSI X12 values are encoded in a 16-bit value as
// (1600 * C1) + (40 * C2) + C3 + 1
- char firstByte;
do {
// If there is only one byte left then it will be encoded as ASCII
@@ -349,37 +343,37 @@ final class DecodedBitStreamParser {
return ASCII_ENCODE;
}
- firstByte = (char) bits.readBits(8);
-
+ char firstByte = (char) bits.readBits(8);
+
if (firstByte == 254) { // Unlatch codeword
return ASCII_ENCODE;
}
- int fullBitValue = firstByte * 256 + bits.readBits(8) - 1;
+ int fullBitValue = (firstByte << 8) + bits.readBits(8) - 1;
- char[] CValues = new char[3];
- CValues[0] = (char) (fullBitValue / 1600);
- fullBitValue -= CValues[0] * 1600;
- CValues[1] = (char) (fullBitValue / 40);
- fullBitValue -= CValues[1] * 40;
- CValues[2] = (char) (fullBitValue);
+ char[] cValues = new char[3];
+ cValues[0] = (char) (fullBitValue / 1600);
+ fullBitValue -= cValues[0] * 1600;
+ cValues[1] = (char) (fullBitValue / 40);
+ fullBitValue -= cValues[1] * 40;
+ cValues[2] = (char) fullBitValue;
for (int i = 0; i < 3; i++) {
// TODO(bbrown): These really aren't X12 symbols, we are converting to ASCII chars
- if (CValues[i] == 0) { // X12 segment terminator Encapsulates logic that can detect a Data Matrix Code in an image, even if the Data Matrix Code
diff --git a/core/src/com/google/zxing/qrcode/QRCodeReader.java b/core/src/com/google/zxing/qrcode/QRCodeReader.java
index 7001576a2..36723773e 100644
--- a/core/src/com/google/zxing/qrcode/QRCodeReader.java
+++ b/core/src/com/google/zxing/qrcode/QRCodeReader.java
@@ -24,9 +24,9 @@ import com.google.zxing.ReaderException;
import com.google.zxing.Result;
import com.google.zxing.ResultPoint;
import com.google.zxing.common.BitMatrix;
+import com.google.zxing.common.DetectorResult;
import com.google.zxing.qrcode.decoder.Decoder;
import com.google.zxing.qrcode.detector.Detector;
-import com.google.zxing.qrcode.detector.DetectorResult;
import java.util.Hashtable;
diff --git a/core/src/com/google/zxing/qrcode/decoder/BitSource.java b/core/src/com/google/zxing/qrcode/decoder/BitSource.java
deleted file mode 100755
index c19e34dca..000000000
--- a/core/src/com/google/zxing/qrcode/decoder/BitSource.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright 2007 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.zxing.qrcode.decoder;
-
-/**
- * This provides an easy abstraction to read bits at a time from a sequence of bytes, where the
- * number of bits read is not often a multiple of 8. This class is not thread-safe.