Completed some modest tweaks to new Data Matrix code based on IntelliJ suggestions

git-svn-id: https://zxing.googlecode.com/svn/trunk@265 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2008-03-11 15:01:02 +00:00
parent 916edd548e
commit 1b36bc820e
9 changed files with 99 additions and 213 deletions

View file

@ -14,10 +14,9 @@
* limitations under the License. * limitations under the License.
*/ */
package com.google.zxing.qrcode.detector; package com.google.zxing.common;
import com.google.zxing.ResultPoint; import com.google.zxing.ResultPoint;
import com.google.zxing.common.BitMatrix;
/** /**
* <p>Encapsulates the result of detecting a barcode in an image. This includes the raw * <p>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 BitMatrix bits;
private final ResultPoint[] points; private final ResultPoint[] points;
DetectorResult(BitMatrix bits, ResultPoint[] points) { public DetectorResult(BitMatrix bits, ResultPoint[] points) {
this.bits = bits; this.bits = bits;
this.points = points; this.points = points;
} }

View file

@ -17,7 +17,6 @@
package com.google.zxing.datamatrix; package com.google.zxing.datamatrix;
import com.google.zxing.BarcodeFormat; import com.google.zxing.BarcodeFormat;
import com.google.zxing.DecodeHintType;
import com.google.zxing.MonochromeBitmapSource; import com.google.zxing.MonochromeBitmapSource;
import com.google.zxing.Reader; import com.google.zxing.Reader;
import com.google.zxing.ReaderException; import com.google.zxing.ReaderException;
@ -25,8 +24,6 @@ import com.google.zxing.Result;
import com.google.zxing.ResultPoint; import com.google.zxing.ResultPoint;
import com.google.zxing.common.BitMatrix; import com.google.zxing.common.BitMatrix;
import com.google.zxing.datamatrix.decoder.Decoder; 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; import java.util.Hashtable;

View file

@ -40,7 +40,7 @@ final class BitMatrixParser {
} }
version = readVersion(bitMatrix); version = readVersion(bitMatrix);
this.mappingBitMatrix = ExtractDataRegion(bitMatrix, version); this.mappingBitMatrix = extractDataRegion(bitMatrix, version);
// TODO(bbrown): Make this work for rectangular symbols // TODO(bbrown): Make this work for rectangular symbols
this.readMappingMatrix = new BitMatrix(this.mappingBitMatrix.getDimension()); this.readMappingMatrix = new BitMatrix(this.mappingBitMatrix.getDimension());
} }
@ -81,8 +81,6 @@ final class BitMatrixParser {
byte[] result = new byte[version.getTotalCodewords()]; byte[] result = new byte[version.getTotalCodewords()];
int resultOffset = 0; int resultOffset = 0;
int currentByte = 0;
int bitsRead = 0;
int row = 4; int row = 4;
int column = 0; int column = 0;
@ -144,10 +142,10 @@ final class BitMatrixParser {
/** /**
* <p>Reads a bit of the mapping matrix accounting for boundry wrapping.</p> * <p>Reads a bit of the mapping matrix accounting for boundry wrapping.</p>
* *
* @param Row to read in the mapping matrix * @param row Row to read in the mapping matrix
* @param Column to read in the mapping matrix * @param column Column to read in the mapping matrix
* @param Number of rows in the mapping matrix * @param numRows Number of rows in the mapping matrix
* @param Number of columns in the mapping matrix * @param numColumns Number of columns in the mapping matrix
* @return value of the given bit in the mapping matrix * @return value of the given bit in the mapping matrix
*/ */
boolean readModule(int row, int column, int numRows, int numColumns) { boolean readModule(int row, int column, int numRows, int numColumns) {
@ -169,10 +167,10 @@ final class BitMatrixParser {
* *
* <p>See ISO 16022:2006, 5.8.1 Figure 6</p> * <p>See ISO 16022:2006, 5.8.1 Figure 6</p>
* *
* @param Current row in the mapping matrix, anchored at the 8th bit (LSB) of the pattern * @param row 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 column Current column in the mapping matrix, anchored at the 8th bit (LSB) of the pattern
* @param Number of rows in the mapping matrix * @param numRows Number of rows in the mapping matrix
* @param Number of columns in the mapping matrix * @param numColumns Number of columns in the mapping matrix
* @return byte from the utah shape * @return byte from the utah shape
*/ */
int readUtah(int row, int column, int numRows, int numColumns) { int readUtah(int row, int column, int numRows, int numColumns) {
@ -216,8 +214,8 @@ final class BitMatrixParser {
* *
* <p>See ISO 16022:2006, Figure F.3</p> * <p>See ISO 16022:2006, Figure F.3</p>
* *
* @param Number of rows in the mapping matrix * @param numRows Number of rows in the mapping matrix
* @param Number of columns in the mapping matrix * @param numColumns Number of columns in the mapping matrix
* @return byte from the Corner condition 1 * @return byte from the Corner condition 1
*/ */
int readCorner1(int numRows, int numColumns) { int readCorner1(int numRows, int numColumns) {
@ -261,8 +259,8 @@ final class BitMatrixParser {
* *
* <p>See ISO 16022:2006, Figure F.4</p> * <p>See ISO 16022:2006, Figure F.4</p>
* *
* @param Number of rows in the mapping matrix * @param numRows Number of rows in the mapping matrix
* @param Number of columns in the mapping matrix * @param numColumns Number of columns in the mapping matrix
* @return byte from the Corner condition 2 * @return byte from the Corner condition 2
*/ */
int readCorner2(int numRows, int numColumns) { int readCorner2(int numRows, int numColumns) {
@ -306,8 +304,8 @@ final class BitMatrixParser {
* *
* <p>See ISO 16022:2006, Figure F.5</p> * <p>See ISO 16022:2006, Figure F.5</p>
* *
* @param Number of rows in the mapping matrix * @param numRows Number of rows in the mapping matrix
* @param Number of columns in the mapping matrix * @param numColumns Number of columns in the mapping matrix
* @return byte from the Corner condition 3 * @return byte from the Corner condition 3
*/ */
int readCorner3(int numRows, int numColumns) { int readCorner3(int numRows, int numColumns) {
@ -351,8 +349,8 @@ final class BitMatrixParser {
* *
* <p>See ISO 16022:2006, Figure F.6</p> * <p>See ISO 16022:2006, Figure F.6</p>
* *
* @param Number of rows in the mapping matrix * @param numRows Number of rows in the mapping matrix
* @param Number of columns in the mapping matrix * @param numColumns Number of columns in the mapping matrix
* @return byte from the Corner condition 4 * @return byte from the Corner condition 4
*/ */
int readCorner4(int numRows, int numColumns) { int readCorner4(int numRows, int numColumns) {
@ -395,11 +393,11 @@ final class BitMatrixParser {
* <p>Extracts the data region from a {@link BitMatrix} that contains * <p>Extracts the data region from a {@link BitMatrix} that contains
* alignment patterns.</p> * alignment patterns.</p>
* *
* @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 * @param version {@link Version} information corresponding with the bitMatrix
* @return BitMatrix that has the alignment patterns removed * @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 symbolSizeRows = version.getSymbolSizeRows();
int symbolSizeColumns = version.getSymbolSizeColumns(); int symbolSizeColumns = version.getSymbolSizeColumns();

View file

@ -18,7 +18,6 @@ package com.google.zxing.datamatrix.decoder;
import com.google.zxing.ReaderException; import com.google.zxing.ReaderException;
import com.google.zxing.common.BitSource; import com.google.zxing.common.BitSource;
import java.io.UnsupportedEncodingException;
/** /**
* <p>Data Matrix Codes can encode text as bits in one of several modes, and can use multiple modes * <p>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, private static int decodeAsciiSegment(BitSource bits,
StringBuffer result) throws ReaderException { StringBuffer result) throws ReaderException {
char oneByte;
boolean upperShift = false; boolean upperShift = false;
int bytesProcessed = 0;
do { do {
oneByte = (char) bits.readBits(8); char oneByte = (char) bits.readBits(8);
if (oneByte == 0) { if (oneByte == '\0') {
// TODO(bbrown): I think this would be a bug, not sure // TODO(bbrown): I think this would be a bug, not sure
throw new ReaderException("0 is an invalid ASCII codeword"); throw new ReaderException("0 is an invalid ASCII codeword");
} else if (oneByte <= 128) { // ASCII data (ASCII value + 1) } else if (oneByte <= 128) { // ASCII data (ASCII value + 1)
@ -164,7 +161,6 @@ final class DecodedBitStreamParser {
StringBuffer result) throws ReaderException { StringBuffer result) throws ReaderException {
// Three C40 values are encoded in a 16-bit value as // Three C40 values are encoded in a 16-bit value as
// (1600 * C1) + (40 * C2) + C3 + 1 // (1600 * C1) + (40 * C2) + C3 + 1
char firstByte;
int shift = 0; int shift = 0;
// TODO(bbrown): The Upper Shift with C40 doesn't work in the 4 value scenario all the time // TODO(bbrown): The Upper Shift with C40 doesn't work in the 4 value scenario all the time
boolean upperShift = false; boolean upperShift = false;
@ -175,67 +171,67 @@ final class DecodedBitStreamParser {
return ASCII_ENCODE; return ASCII_ENCODE;
} }
firstByte = (char) bits.readBits(8); char firstByte = (char) bits.readBits(8);
if (firstByte == 254) { // Unlatch codeword if (firstByte == 254) { // Unlatch codeword
return ASCII_ENCODE; return ASCII_ENCODE;
} }
int fullBitValue = firstByte * 256 + bits.readBits(8) - 1; int fullBitValue = (firstByte << 8) + bits.readBits(8) - 1;
char[] CValues = new char[3]; char[] cValues = new char[3];
CValues[0] = (char) (fullBitValue / 1600); cValues[0] = (char) (fullBitValue / 1600);
fullBitValue -= CValues[0] * 1600; fullBitValue -= cValues[0] * 1600;
CValues[1] = (char) (fullBitValue / 40); cValues[1] = (char) (fullBitValue / 40);
fullBitValue -= CValues[1] * 40; fullBitValue -= cValues[1] * 40;
CValues[2] = (char) (fullBitValue); cValues[2] = (char) fullBitValue;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
if (shift == 0) { if (shift == 0) {
if (CValues[i] == 0) { // Shift 1 if (cValues[i] == 0) { // Shift 1
shift = 1; shift = 1;
continue; continue;
} else if (CValues[i] == 1) { // Shift 2 } else if (cValues[i] == 1) { // Shift 2
shift = 2; shift = 2;
continue; continue;
} else if (CValues[i] == 2) { // Shift 3 } else if (cValues[i] == 2) { // Shift 3
shift = 3; shift = 3;
continue; continue;
} }
if (upperShift) { if (upperShift) {
result.append((char)(C40_BASIC_SET_CHARS[CValues[i]] + 128)); result.append((char)(C40_BASIC_SET_CHARS[cValues[i]] + 128));
upperShift = false; upperShift = false;
} else { } else {
result.append(C40_BASIC_SET_CHARS[CValues[i]]); result.append(C40_BASIC_SET_CHARS[cValues[i]]);
} }
} else if (shift == 1) { } else if (shift == 1) {
if (upperShift) { if (upperShift) {
result.append((char) (CValues[i] + 128)); result.append((char) (cValues[i] + 128));
upperShift = false; upperShift = false;
} else { } else {
result.append((char) CValues[i]); result.append(cValues[i]);
} }
} else if (shift == 2) { } else if (shift == 2) {
if (CValues[i] < 27) { if (cValues[i] < 27) {
if(upperShift) { if(upperShift) {
result.append((char)(C40_SHIFT2_SET_CHARS[CValues[i]] + 128)); result.append((char)(C40_SHIFT2_SET_CHARS[cValues[i]] + 128));
upperShift = false; upperShift = false;
} else { } 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"); throw new ReaderException("Currently not supporting FNC1");
} else if (CValues[i] == 30) { // Upper Shirt } else if (cValues[i] == 30) { // Upper Shirt
upperShift = true; upperShift = true;
} else { } 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) { } else if (shift == 3) {
if (upperShift) { if (upperShift) {
result.append((char) (CValues[i] + 224)); result.append((char) (cValues[i] + 224));
upperShift = false; upperShift = false;
} else { } else {
result.append((char) CValues[i] + 96); result.append((char) cValues[i] + 96);
} }
} else { } else {
throw new ReaderException("Invalid shift value"); throw new ReaderException("Invalid shift value");
@ -252,7 +248,6 @@ final class DecodedBitStreamParser {
StringBuffer result) throws ReaderException { StringBuffer result) throws ReaderException {
// Three Text values are encoded in a 16-bit value as // Three Text values are encoded in a 16-bit value as
// (1600 * C1) + (40 * C2) + C3 + 1 // (1600 * C1) + (40 * C2) + C3 + 1
char firstByte;
int shift = 0; int shift = 0;
// TODO(bbrown): The Upper Shift with Text doesn't work in the 4 value scenario all the time // TODO(bbrown): The Upper Shift with Text doesn't work in the 4 value scenario all the time
boolean upperShift = false; boolean upperShift = false;
@ -263,68 +258,68 @@ final class DecodedBitStreamParser {
return ASCII_ENCODE; return ASCII_ENCODE;
} }
firstByte = (char) bits.readBits(8); char firstByte = (char) bits.readBits(8);
if (firstByte == 254) { // Unlatch codeword if (firstByte == 254) { // Unlatch codeword
return ASCII_ENCODE; return ASCII_ENCODE;
} }
int fullBitValue = firstByte * 256 + bits.readBits(8) - 1; int fullBitValue = (firstByte << 8) + bits.readBits(8) - 1;
char[] CValues = new char[3]; char[] cValues = new char[3];
CValues[0] = (char) (fullBitValue / 1600); cValues[0] = (char) (fullBitValue / 1600);
fullBitValue -= CValues[0] * 1600; fullBitValue -= cValues[0] * 1600;
CValues[1] = (char) (fullBitValue / 40); cValues[1] = (char) (fullBitValue / 40);
fullBitValue -= CValues[1] * 40; fullBitValue -= cValues[1] * 40;
CValues[2] = (char) (fullBitValue); cValues[2] = (char) fullBitValue;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
if (shift == 0) { if (shift == 0) {
if (CValues[i] == 0) { // Shift 1 if (cValues[i] == 0) { // Shift 1
shift = 1; shift = 1;
continue; continue;
} else if (CValues[i] == 1) { // Shift 2 } else if (cValues[i] == 1) { // Shift 2
shift = 2; shift = 2;
continue; continue;
} else if (CValues[i] == 2) { // Shift 3 } else if (cValues[i] == 2) { // Shift 3
shift = 3; shift = 3;
continue; continue;
} }
if (upperShift) { if (upperShift) {
result.append((char)(TEXT_BASIC_SET_CHARS[CValues[i]] + 128)); result.append((char)(TEXT_BASIC_SET_CHARS[cValues[i]] + 128));
upperShift = false; upperShift = false;
} else { } else {
result.append(TEXT_BASIC_SET_CHARS[CValues[i]]); result.append(TEXT_BASIC_SET_CHARS[cValues[i]]);
} }
} else if (shift == 1) { } else if (shift == 1) {
if (upperShift) { if (upperShift) {
result.append((char) (CValues[i] + 128)); result.append((char) (cValues[i] + 128));
upperShift = false; upperShift = false;
} else { } else {
result.append((char) CValues[i]); result.append((char) cValues[i]);
} }
} else if (shift == 2) { } else if (shift == 2) {
// Shift 2 for Text is the same encoding as C40 // Shift 2 for Text is the same encoding as C40
if (CValues[i] < 27) { if (cValues[i] < 27) {
if(upperShift) { if(upperShift) {
result.append((char)(C40_SHIFT2_SET_CHARS[CValues[i]] + 128)); result.append((char)(C40_SHIFT2_SET_CHARS[cValues[i]] + 128));
upperShift = false; upperShift = false;
} else { } 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"); throw new ReaderException("Currently not supporting FNC1");
} else if (CValues[i] == 30) { // Upper Shirt } else if (cValues[i] == 30) { // Upper Shirt
upperShift = true; upperShift = true;
} else { } 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) { } else if (shift == 3) {
if (upperShift) { if (upperShift) {
result.append((char)(TEXT_SHIFT3_SET_CHARS[CValues[i]] + 128)); result.append((char)(TEXT_SHIFT3_SET_CHARS[cValues[i]] + 128));
upperShift = false; upperShift = false;
} else { } else {
result.append(TEXT_SHIFT3_SET_CHARS[CValues[i]]); result.append(TEXT_SHIFT3_SET_CHARS[cValues[i]]);
} }
} else { } else {
throw new ReaderException("Invalid shift value"); throw new ReaderException("Invalid shift value");
@ -341,7 +336,6 @@ final class DecodedBitStreamParser {
StringBuffer result) throws ReaderException { StringBuffer result) throws ReaderException {
// Three ANSI X12 values are encoded in a 16-bit value as // Three ANSI X12 values are encoded in a 16-bit value as
// (1600 * C1) + (40 * C2) + C3 + 1 // (1600 * C1) + (40 * C2) + C3 + 1
char firstByte;
do { do {
// If there is only one byte left then it will be encoded as ASCII // If there is only one byte left then it will be encoded as ASCII
@ -349,37 +343,37 @@ final class DecodedBitStreamParser {
return ASCII_ENCODE; return ASCII_ENCODE;
} }
firstByte = (char) bits.readBits(8); char firstByte = (char) bits.readBits(8);
if (firstByte == 254) { // Unlatch codeword if (firstByte == 254) { // Unlatch codeword
return ASCII_ENCODE; return ASCII_ENCODE;
} }
int fullBitValue = firstByte * 256 + bits.readBits(8) - 1; int fullBitValue = (firstByte << 8) + bits.readBits(8) - 1;
char[] CValues = new char[3]; char[] cValues = new char[3];
CValues[0] = (char) (fullBitValue / 1600); cValues[0] = (char) (fullBitValue / 1600);
fullBitValue -= CValues[0] * 1600; fullBitValue -= cValues[0] * 1600;
CValues[1] = (char) (fullBitValue / 40); cValues[1] = (char) (fullBitValue / 40);
fullBitValue -= CValues[1] * 40; fullBitValue -= cValues[1] * 40;
CValues[2] = (char) (fullBitValue); cValues[2] = (char) fullBitValue;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
// TODO(bbrown): These really aren't X12 symbols, we are converting to ASCII chars // TODO(bbrown): These really aren't X12 symbols, we are converting to ASCII chars
if (CValues[i] == 0) { // X12 segment terminator <CR> if (cValues[i] == 0) { // X12 segment terminator <CR>
result.append("<CR>"); result.append("<CR>");
} else if (CValues[i] == 1) { // X12 segment separator * } else if (cValues[i] == 1) { // X12 segment separator *
result.append('*'); result.append('*');
} else if (CValues[i] == 2) { // X12 sub-element separator > } else if (cValues[i] == 2) { // X12 sub-element separator >
result.append('>'); result.append('>');
} else if (CValues[i] == 3) { // space } else if (cValues[i] == 3) { // space
result.append(' '); result.append(' ');
} else if (CValues[i] < 14) { // 0 - 9 } else if (cValues[i] < 14) { // 0 - 9
result.append((char) (CValues[i] + 44)); result.append((char) (cValues[i] + 44));
} else if (CValues[i] < 40) { // A - Z } else if (cValues[i] < 40) { // A - Z
result.append((char) (CValues[i] + 51)); result.append((char) (cValues[i] + 51));
} else { } else {
throw new ReaderException(Integer.toString(CValues[i]) + " is not valid in the ANSI X12 set"); throw new ReaderException(Integer.toString(cValues[i]) + " is not valid in the ANSI X12 set");
} }
} }
} while (bits.available() > 0); } while (bits.available() > 0);
@ -399,9 +393,8 @@ final class DecodedBitStreamParser {
return ASCII_ENCODE; return ASCII_ENCODE;
} }
char edifactValue;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
edifactValue = (char) bits.readBits(6); char edifactValue = (char) bits.readBits(6);
// Check for the unlatch character // Check for the unlatch character
if (edifactValue == 0x2B67) { // 011111 if (edifactValue == 0x2B67) { // 011111
@ -429,7 +422,7 @@ final class DecodedBitStreamParser {
StringBuffer result) throws ReaderException { StringBuffer result) throws ReaderException {
// Figure out how long the Base 256 Segment is. // Figure out how long the Base 256 Segment is.
char d1 = (char) bits.readBits(8); char d1 = (char) bits.readBits(8);
int count = 0; int count;
if (d1 == 0) { // Read the remainder of the symbol if (d1 == 0) { // Read the remainder of the symbol
count = bits.available() / 8; count = bits.available() / 8;
} else if (d1 < 250) { } else if (d1 < 250) {
@ -439,7 +432,7 @@ final class DecodedBitStreamParser {
} }
char[] readBytes = new char[count]; char[] readBytes = new char[count];
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
result.append((char)unrandomize255State((char) bits.readBits(8), count)); result.append(unrandomize255State((char) bits.readBits(8), count));
} }
return ASCII_ENCODE; return ASCII_ENCODE;

View file

@ -17,7 +17,6 @@
package com.google.zxing.datamatrix.decoder; package com.google.zxing.datamatrix.decoder;
import com.google.zxing.ReaderException; import com.google.zxing.ReaderException;
import com.google.zxing.common.BitMatrix;
/** /**
* The Version object encapsulates attributes about a particular * The Version object encapsulates attributes about a particular
@ -108,12 +107,10 @@ public final class Version {
int numVersions = VERSIONS.length; int numVersions = VERSIONS.length;
for (int i = 0; i < numVersions; ++i){ for (int i = 0; i < numVersions; ++i){
Version version = VERSIONS[i]; Version version = VERSIONS[i];
if (version.symbolSizeRows == numRows) { if (version.symbolSizeRows == numRows && version.symbolSizeColumns == numColumns) {
if (version.symbolSizeColumns == numColumns) {
return version; return version;
} }
} }
}
throw new ReaderException("Dimensions do not correspond to a valid Data Matrix Version."); throw new ReaderException("Dimensions do not correspond to a valid Data Matrix Version.");
} }

View file

@ -16,12 +16,9 @@
package com.google.zxing.datamatrix.detector; package com.google.zxing.datamatrix.detector;
import com.google.zxing.BlackPointEstimationMethod;
import com.google.zxing.MonochromeBitmapSource; import com.google.zxing.MonochromeBitmapSource;
import com.google.zxing.ReaderException; import com.google.zxing.ReaderException;
import com.google.zxing.ResultPoint; import com.google.zxing.common.DetectorResult;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.datamatrix.decoder.Version;
/** /**
* <p>Encapsulates logic that can detect a Data Matrix Code in an image, even if the Data Matrix Code * <p>Encapsulates logic that can detect a Data Matrix Code in an image, even if the Data Matrix Code

View file

@ -24,9 +24,9 @@ import com.google.zxing.ReaderException;
import com.google.zxing.Result; import com.google.zxing.Result;
import com.google.zxing.ResultPoint; import com.google.zxing.ResultPoint;
import com.google.zxing.common.BitMatrix; import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.DetectorResult;
import com.google.zxing.qrcode.decoder.Decoder; import com.google.zxing.qrcode.decoder.Decoder;
import com.google.zxing.qrcode.detector.Detector; import com.google.zxing.qrcode.detector.Detector;
import com.google.zxing.qrcode.detector.DetectorResult;
import java.util.Hashtable; import java.util.Hashtable;

View file

@ -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;
/**
* <p>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.</p>
*
* <p>This class is not thread-safe.</p>
*
* @author srowen@google.com (Sean Owen)
*/
final class BitSource {
private final byte[] bytes;
private int byteOffset;
private int bitOffset;
/**
* @param bytes bytes from which this will read bits. Bits will be read from the first byte first.
* Bits are read within a byte from most-significant to least-significant bit.
*/
BitSource(byte[] bytes) {
this.bytes = bytes;
}
/**
* @param numBits number of bits to read
* @return int representing the bits read. The bits will appear as the least-significant
* bits of the int
* @throws IllegalArgumentException if numBits isn't in [1,32]
*/
int readBits(int numBits) {
if (numBits < 1 || numBits > 32) {
throw new IllegalArgumentException();
}
int result = 0;
// First, read remainder from current byte
if (bitOffset > 0) {
int bitsLeft = 8 - bitOffset;
int toRead = numBits < bitsLeft ? numBits : bitsLeft;
int bitsToNotRead = bitsLeft - toRead;
int mask = (0xFF >> (8 - toRead)) << bitsToNotRead;
result = (bytes[byteOffset] & mask) >> bitsToNotRead;
numBits -= toRead;
bitOffset += toRead;
if (bitOffset == 8) {
bitOffset = 0;
byteOffset++;
}
}
// Next read whole bytes
if (numBits > 0) {
while (numBits >= 8) {
result = (result << 8) | (bytes[byteOffset] & 0xFF);
byteOffset++;
numBits -= 8;
}
// Finally read a partial byte
if (numBits > 0) {
int bitsToNotRead = 8 - numBits;
int mask = (0xFF >> bitsToNotRead) << bitsToNotRead;
result = (result << numBits) | ((bytes[byteOffset] & mask) >> bitsToNotRead);
bitOffset += numBits;
}
}
return result;
}
/**
* @return number of bits that can be read successfully
*/
int available() {
return 8 * (bytes.length - byteOffset) - bitOffset;
}
}

View file

@ -21,6 +21,7 @@ import com.google.zxing.MonochromeBitmapSource;
import com.google.zxing.ReaderException; import com.google.zxing.ReaderException;
import com.google.zxing.ResultPoint; import com.google.zxing.ResultPoint;
import com.google.zxing.common.BitMatrix; import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.DetectorResult;
import com.google.zxing.qrcode.decoder.Version; import com.google.zxing.qrcode.decoder.Version;
/** /**