From 99934867e776f14b8b9ebc901db127b3255e5d8d Mon Sep 17 00:00:00 2001 From: srowen Date: Tue, 11 Mar 2008 15:01:02 +0000 Subject: [PATCH] Completed some modest tweaks to new Data Matrix code based on IntelliJ suggestions git-svn-id: http://zxing.googlecode.com/svn/trunk@265 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../detector => common}/DetectorResult.java | 5 +- .../zxing/datamatrix/DataMatrixReader.java | 3 - .../datamatrix/decoder/BitMatrixParser.java | 40 +++-- .../decoder/DecodedBitStreamParser.java | 153 +++++++++--------- .../zxing/datamatrix/decoder/Version.java | 7 +- .../zxing/datamatrix/detector/Detector.java | 5 +- .../com/google/zxing/qrcode/QRCodeReader.java | 2 +- .../zxing/qrcode/decoder/BitSource.java | 96 ----------- .../zxing/qrcode/detector/Detector.java | 1 + 9 files changed, 99 insertions(+), 213 deletions(-) rename core/src/com/google/zxing/{qrcode/detector => common}/DetectorResult.java (89%) delete mode 100755 core/src/com/google/zxing/qrcode/decoder/BitSource.java 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 15fb78c0..1dbfae5f 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 5d7b4a30..e5bff731 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 3bc61cd8..a14eb951 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 9d6f2079..09dcebe5 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 + if (cValues[i] == 0) { // X12 segment terminator result.append(""); - } else if (CValues[i] == 1) { // X12 segment separator * + } else if (cValues[i] == 1) { // X12 segment separator * result.append('*'); - } else if (CValues[i] == 2) { // X12 sub-element separator > + } else if (cValues[i] == 2) { // X12 sub-element separator > result.append('>'); - } else if (CValues[i] == 3) { // space + } else if (cValues[i] == 3) { // space result.append(' '); - } else if (CValues[i] < 14) { // 0 - 9 - result.append((char) (CValues[i] + 44)); - } else if (CValues[i] < 40) { // A - Z - result.append((char) (CValues[i] + 51)); + } else if (cValues[i] < 14) { // 0 - 9 + result.append((char) (cValues[i] + 44)); + } else if (cValues[i] < 40) { // A - Z + result.append((char) (cValues[i] + 51)); } 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); @@ -398,11 +392,10 @@ final class DecodedBitStreamParser { if (bits.available() <= 16) { return ASCII_ENCODE; } - - char edifactValue; + for (int i = 0; i < 4; i++) { - edifactValue = (char) bits.readBits(6); - + char edifactValue = (char) bits.readBits(6); + // Check for the unlatch character if (edifactValue == 0x2B67) { // 011111 unlatch = true; @@ -429,7 +422,7 @@ final class DecodedBitStreamParser { StringBuffer result) throws ReaderException { // Figure out how long the Base 256 Segment is. char d1 = (char) bits.readBits(8); - int count = 0; + int count; if (d1 == 0) { // Read the remainder of the symbol count = bits.available() / 8; } else if (d1 < 250) { @@ -439,7 +432,7 @@ final class DecodedBitStreamParser { } char[] readBytes = new char[count]; 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; diff --git a/core/src/com/google/zxing/datamatrix/decoder/Version.java b/core/src/com/google/zxing/datamatrix/decoder/Version.java index dc6469b5..a7dbdc05 100644 --- a/core/src/com/google/zxing/datamatrix/decoder/Version.java +++ b/core/src/com/google/zxing/datamatrix/decoder/Version.java @@ -17,7 +17,6 @@ package com.google.zxing.datamatrix.decoder; import com.google.zxing.ReaderException; -import com.google.zxing.common.BitMatrix; /** * The Version object encapsulates attributes about a particular @@ -108,10 +107,8 @@ public final class Version { int numVersions = VERSIONS.length; for (int i = 0; i < numVersions; ++i){ Version version = VERSIONS[i]; - if (version.symbolSizeRows == numRows) { - if (version.symbolSizeColumns == numColumns) { - return version; - } + if (version.symbolSizeRows == numRows && version.symbolSizeColumns == numColumns) { + return version; } } diff --git a/core/src/com/google/zxing/datamatrix/detector/Detector.java b/core/src/com/google/zxing/datamatrix/detector/Detector.java index e445976e..11e63ff9 100644 --- a/core/src/com/google/zxing/datamatrix/detector/Detector.java +++ b/core/src/com/google/zxing/datamatrix/detector/Detector.java @@ -16,12 +16,9 @@ package com.google.zxing.datamatrix.detector; -import com.google.zxing.BlackPointEstimationMethod; import com.google.zxing.MonochromeBitmapSource; import com.google.zxing.ReaderException; -import com.google.zxing.ResultPoint; -import com.google.zxing.common.BitMatrix; -import com.google.zxing.datamatrix.decoder.Version; +import com.google.zxing.common.DetectorResult; /** *

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 7001576a..36723773 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 c19e34dc..00000000 --- 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.

- * - * @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; - } - -} diff --git a/core/src/com/google/zxing/qrcode/detector/Detector.java b/core/src/com/google/zxing/qrcode/detector/Detector.java index 940476b4..3b5f94f1 100644 --- a/core/src/com/google/zxing/qrcode/detector/Detector.java +++ b/core/src/com/google/zxing/qrcode/detector/Detector.java @@ -21,6 +21,7 @@ import com.google.zxing.MonochromeBitmapSource; import com.google.zxing.ReaderException; import com.google.zxing.ResultPoint; import com.google.zxing.common.BitMatrix; +import com.google.zxing.common.DetectorResult; import com.google.zxing.qrcode.decoder.Version; /** -- 2.20.1