Update zxing-core to 3.2.1

This commit is contained in:
Daniel Martí 2015-09-05 22:14:18 -04:00
parent 3213fd2ba1
commit 45782355db
22 changed files with 92 additions and 138 deletions

View File

@ -22,7 +22,7 @@ if ( !hasProperty( 'sourceDeps' ) ) {
compile 'org.thoughtcrime.ssl.pinning:AndroidPinning:1.0.0'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'
compile 'com.google.zxing:core:3.2.0'
compile 'com.google.zxing:core:3.2.1'
compile 'eu.chainfire:libsuperuser:1.0.0.201504231659'
compile 'cc.mvdan.accesspoint:library:0.1.1'

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

View File

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>zxing-core</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.zxing" >
</manifest>

View File

@ -1,7 +0,0 @@
# Dummy value
target=android-19
android.library=true
source.dir=src/main/java
java.target=1.7
java.source=1.7

View File

@ -24,7 +24,10 @@ package com.google.zxing;
*/
public final class ChecksumException extends ReaderException {
private static final ChecksumException instance = new ChecksumException();
private static final ChecksumException INSTANCE = new ChecksumException();
static {
INSTANCE.setStackTrace(NO_TRACE); // since it's meaningless
}
private ChecksumException() {
// do nothing
@ -35,18 +38,10 @@ public final class ChecksumException extends ReaderException {
}
public static ChecksumException getChecksumInstance() {
if (isStackTrace) {
return new ChecksumException();
} else {
return instance;
}
return isStackTrace ? new ChecksumException() : INSTANCE;
}
public static ChecksumException getChecksumInstance(Throwable cause) {
if (isStackTrace) {
return new ChecksumException(cause);
} else {
return instance;
}
return isStackTrace ? new ChecksumException(cause) : INSTANCE;
}
}

View File

@ -27,7 +27,8 @@ public enum EncodeHintType {
* Specifies what degree of error correction to use, for example in QR Codes.
* Type depends on the encoder. For example for QR codes it's type
* {@link com.google.zxing.qrcode.decoder.ErrorCorrectionLevel ErrorCorrectionLevel}.
* For Aztec it is of type {@link Integer}, representing the minimal percentage of error correction words.
* For Aztec it is of type {@link Integer}, representing the minimal percentage of error correction words.
* For PDF417 it is of type {@link Integer}, valid values being 0 to 8.
* Note: an Aztec symbol should have a minimum of 25% EC words.
*/
ERROR_CORRECTION,

View File

@ -25,7 +25,10 @@ package com.google.zxing;
*/
public final class FormatException extends ReaderException {
private static final FormatException instance = new FormatException();
private static final FormatException INSTANCE = new FormatException();
static {
INSTANCE.setStackTrace(NO_TRACE); // since it's meaningless
}
private FormatException() {
}
@ -35,18 +38,10 @@ public final class FormatException extends ReaderException {
}
public static FormatException getFormatInstance() {
if (isStackTrace) {
return new FormatException();
} else {
return instance;
}
return isStackTrace ? new FormatException() : INSTANCE;
}
public static FormatException getFormatInstance(Throwable cause) {
if (isStackTrace) {
return new FormatException(cause);
} else {
return instance;
}
return isStackTrace ? new FormatException(cause) : INSTANCE;
}
}

View File

@ -24,14 +24,17 @@ package com.google.zxing;
*/
public final class NotFoundException extends ReaderException {
private static final NotFoundException instance = new NotFoundException();
private static final NotFoundException INSTANCE = new NotFoundException();
static {
INSTANCE.setStackTrace(NO_TRACE); // since it's meaningless
}
private NotFoundException() {
// do nothing
}
public static NotFoundException getNotFoundInstance() {
return instance;
return INSTANCE;
}
}

View File

@ -26,7 +26,9 @@ package com.google.zxing;
public abstract class ReaderException extends Exception {
// disable stack traces when not running inside test units
protected static final boolean isStackTrace = System.getProperty("surefire.test.class.path") != null;
protected static final boolean isStackTrace =
System.getProperty("surefire.test.class.path") != null;
protected static final StackTraceElement[] NO_TRACE = new StackTraceElement[0];
ReaderException() {
// do nothing

View File

@ -311,7 +311,7 @@ public final class Encoder {
case 12:
return GenericGF.AZTEC_DATA_12;
default:
return null;
throw new IllegalArgumentException("Unsupported word size " + wordSize);
}
}

View File

@ -230,15 +230,15 @@ public final class HighLevelEncoder {
// any other mode except possibly digit (which uses only 4 bits). Any
// other latch would be equally successful *after* this character, and
// so wouldn't save any bits.
State latch_state = stateNoBinary.latchAndAppend(mode, charInMode);
result.add(latch_state);
State latchState = stateNoBinary.latchAndAppend(mode, charInMode);
result.add(latchState);
}
// Try generating the character by switching to its mode.
if (!charInCurrentTable && SHIFT_TABLE[state.getMode()][mode] >= 0) {
// It never makes sense to temporarily shift to another mode if the
// character exists in the current mode. That can never save bits.
State shift_state = stateNoBinary.shiftAndAppend(mode, charInMode);
result.add(shift_state);
State shiftState = stateNoBinary.shiftAndAppend(mode, charInMode);
result.add(shiftState);
}
}
}
@ -270,10 +270,10 @@ public final class HighLevelEncoder {
}
if (pairCode == 3 || pairCode == 4) {
// both characters are in DIGITS. Sometimes better to just add two digits
State digit_state = stateNoBinary
State digitState = stateNoBinary
.latchAndAppend(MODE_DIGIT, 16 - pairCode) // period or comma in DIGIT
.latchAndAppend(MODE_DIGIT, 1); // space in DIGIT
result.add(digit_state);
result.add(digitState);
}
if (state.getBinaryShiftByteCount() > 0) {
// It only makes sense to do the characters as binary if we're already
@ -287,7 +287,7 @@ public final class HighLevelEncoder {
List<State> result = new LinkedList<>();
for (State newState : states) {
boolean add = true;
for (Iterator<State> iterator = result.iterator(); iterator.hasNext(); ) {
for (Iterator<State> iterator = result.iterator(); iterator.hasNext();) {
State oldState = iterator.next();
if (oldState.isBetterThanOrEqualTo(newState)) {
add = false;

View File

@ -69,11 +69,9 @@ public final class URIParsedResult extends ParsedResult {
private static String massageURI(String uri) {
uri = uri.trim();
int protocolEnd = uri.indexOf(':');
if (protocolEnd < 0) {
// No protocol, assume http
uri = "http://" + uri;
} else if (isColonFollowedByPortNumber(uri, protocolEnd)) {
// Found a colon, but it looks like it is after the host, so the protocol is still missing
if (protocolEnd < 0 || isColonFollowedByPortNumber(uri, protocolEnd)) {
// No protocol, or found a colon, but it looks like it is after the host, so the protocol is still missing,
// so assume http
uri = "http://" + uri;
}
return uri;

View File

@ -77,23 +77,20 @@ public final class BitMatrix implements Cloneable {
if (stringRepresentation.charAt(pos) == '\n' ||
stringRepresentation.charAt(pos) == '\r') {
if (bitsPos > rowStartPos) {
if(rowLength == -1) {
if (rowLength == -1) {
rowLength = bitsPos - rowStartPos;
}
else if (bitsPos - rowStartPos != rowLength) {
} else if (bitsPos - rowStartPos != rowLength) {
throw new IllegalArgumentException("row lengths do not match");
}
rowStartPos = bitsPos;
nRows++;
}
pos++;
}
else if (stringRepresentation.substring(pos, pos + setString.length()).equals(setString)) {
} else if (stringRepresentation.substring(pos, pos + setString.length()).equals(setString)) {
pos += setString.length();
bits[bitsPos] = true;
bitsPos++;
}
else if (stringRepresentation.substring(pos, pos + unsetString.length()).equals(unsetString)) {
} else if (stringRepresentation.substring(pos, pos + unsetString.length()).equals(unsetString)) {
pos += unsetString.length();
bits[bitsPos] = false;
bitsPos++;
@ -408,16 +405,28 @@ public final class BitMatrix implements Cloneable {
return hash;
}
/**
* @return string representation using "X" for set and " " for unset bits
*/
@Override
public String toString() {
return toString("X ", " ");
}
/**
* @param setString representation of a set bit
* @param unsetString representation of an unset bit
* @return string representation of entire matrix utilizing given strings
*/
public String toString(String setString, String unsetString) {
return toString(setString, unsetString, "\n");
}
/**
* @param setString representation of a set bit
* @param unsetString representation of an unset bit
* @param lineSeparator newline character in string representation
* @return string representation of entire matrix utilizing given strings and line separator
* @deprecated call {@link #toString(String,String)} only, which uses \n line separator always
*/
@Deprecated

View File

@ -60,7 +60,7 @@ public final class DataMatrixWriter implements Writer {
// Try to get force shape & min / max size
SymbolShapeHint shape = SymbolShapeHint.FORCE_NONE;
Dimension minSize = new Dimension(width, height);
Dimension minSize = null;
Dimension maxSize = null;
if (hints != null) {
SymbolShapeHint requestedShape = (SymbolShapeHint) hints.get(EncodeHintType.DATA_MATRIX_SHAPE);

View File

@ -223,11 +223,21 @@ public final class Code93Reader extends OneDReader {
}
break;
case 'b':
// %A to %E map to control codes ESC to US
if (next >= 'A' && next <= 'E') {
// %A to %E map to control codes ESC to USep
decodedChar = (char) (next - 38);
} else if (next >= 'F' && next <= 'W') {
} else if (next >= 'F' && next <= 'J') {
// %F to %J map to ; < = > ?
decodedChar = (char) (next - 11);
} else if (next >= 'K' && next <= 'O') {
// %K to %O map to [ \ ] ^ _
decodedChar = (char) (next + 16);
} else if (next >= 'P' && next <= 'S') {
// %P to %S map to { | } ~
decodedChar = (char) (next + 43);
} else if (next >= 'T' && next <= 'Z') {
// %T to %Z all map to DEL (127)
decodedChar = 127;
} else {
throw FormatException.getFormatInstance();
}

View File

@ -294,9 +294,6 @@ public final class ITFReader extends OneDReader {
private static int[] findGuardPattern(BitArray row,
int rowOffset,
int[] pattern) throws NotFoundException {
// TODO: This is very similar to implementation in UPCEANReader. Consider if they can be
// merged to a single method.
int patternLength = pattern.length;
int[] counters = new int[patternLength];
int width = row.getSize();

View File

@ -110,15 +110,12 @@ public final class RSSExpandedReader extends AbstractRSSReader {
{ FINDER_PAT_A, FINDER_PAT_A, FINDER_PAT_B, FINDER_PAT_B, FINDER_PAT_C, FINDER_PAT_D, FINDER_PAT_D, FINDER_PAT_E, FINDER_PAT_E, FINDER_PAT_F, FINDER_PAT_F },
};
//private static final int LONGEST_SEQUENCE_SIZE = FINDER_PATTERN_SEQUENCES[FINDER_PATTERN_SEQUENCES.length - 1].length;
private static final int MAX_PAIRS = 11;
private final List<ExpandedPair> pairs = new ArrayList<>(MAX_PAIRS);
private final List<ExpandedRow> rows = new ArrayList<>();
private final int [] startEnd = new int[2];
//private final int [] currentSequence = new int[LONGEST_SEQUENCE_SIZE];
private boolean startFromEven = false;
private boolean startFromEven;
@Override
public Result decodeRow(int rowNumber,
@ -153,7 +150,6 @@ public final class RSSExpandedReader extends AbstractRSSReader {
while (true){
ExpandedPair nextPair = retrieveNextPair(row, this.pairs, rowNumber);
this.pairs.add(nextPair);
//System.out.println(this.pairs.size()+" pairs found so far on row "+rowNumber+": "+this.pairs);
// exit this loop when retrieveNextPair() fails and throws
}
} catch (NotFoundException nfe) {
@ -171,7 +167,7 @@ public final class RSSExpandedReader extends AbstractRSSReader {
boolean wasReversed = false; // TODO: deal with reversed rows
storeRow(rowNumber, wasReversed);
if (tryStackedDecode) {
// When the image is 180-rotated, then rows are sorted in wrong dirrection.
// When the image is 180-rotated, then rows are sorted in wrong direction.
// Try twice with both the directions.
List<ExpandedPair> ps = checkRows(false);
if (ps != null) {
@ -189,7 +185,7 @@ public final class RSSExpandedReader extends AbstractRSSReader {
private List<ExpandedPair> checkRows(boolean reverse) {
// Limit number of rows we are checking
// We use recursive algorithm with pure complexity and don't want it to take forever
// Stacked barcode can have up to 11 rows, so 25 seems resonable enough
// Stacked barcode can have up to 11 rows, so 25 seems reasonable enough
if (this.rows.size() > 25) {
this.rows.clear(); // We will never have a chance to get result, so clear it
return null;
@ -306,7 +302,7 @@ public final class RSSExpandedReader extends AbstractRSSReader {
// Remove all the rows that contains only specified pairs
private static void removePartialRows(List<ExpandedPair> pairs, List<ExpandedRow> rows) {
for (Iterator<ExpandedRow> iterator = rows.iterator(); iterator.hasNext(); ) {
for (Iterator<ExpandedRow> iterator = rows.iterator(); iterator.hasNext();) {
ExpandedRow r = iterator.next();
if (r.getPairs().size() == pairs.size()) {
continue;

View File

@ -39,6 +39,11 @@ public final class PDF417Writer implements Writer {
*/
static final int WHITE_SPACE = 30;
/**
* default error correction level
*/
static final int DEFAULT_ERROR_CORRECTION_LEVEL = 2;
@Override
public BitMatrix encode(String contents,
BarcodeFormat format,
@ -51,6 +56,7 @@ public final class PDF417Writer implements Writer {
PDF417 encoder = new PDF417();
int margin = WHITE_SPACE;
int errorCorrectionLevel = DEFAULT_ERROR_CORRECTION_LEVEL;
if (hints != null) {
if (hints.containsKey(EncodeHintType.PDF417_COMPACT)) {
@ -69,13 +75,16 @@ public final class PDF417Writer implements Writer {
if (hints.containsKey(EncodeHintType.MARGIN)) {
margin = ((Number) hints.get(EncodeHintType.MARGIN)).intValue();
}
if (hints.containsKey(EncodeHintType.ERROR_CORRECTION)) {
errorCorrectionLevel = ((Number) hints.get(EncodeHintType.ERROR_CORRECTION)).intValue();
}
if (hints.containsKey(EncodeHintType.CHARACTER_SET)) {
String encoding = (String) hints.get(EncodeHintType.CHARACTER_SET);
encoder.setEncoding(Charset.forName(encoding));
}
}
return bitMatrixFromEncoder(encoder, contents, width, height, margin);
return bitMatrixFromEncoder(encoder, contents, errorCorrectionLevel, width, height, margin);
}
@Override
@ -91,15 +100,14 @@ public final class PDF417Writer implements Writer {
*/
private static BitMatrix bitMatrixFromEncoder(PDF417 encoder,
String contents,
int errorCorrectionLevel,
int width,
int height,
int margin) throws WriterException {
int errorCorrectionLevel = 2;
encoder.generateBarcodeLogic(contents, errorCorrectionLevel);
int lineThickness = 2;
int aspectRatio = 4;
byte[][] originalScale = encoder.getBarcodeMatrix().getScaledMatrix(lineThickness, aspectRatio * lineThickness);
byte[][] originalScale = encoder.getBarcodeMatrix().getScaledMatrix(1, aspectRatio);
boolean rotated = false;
if ((height > width) ^ (originalScale[0].length < originalScale.length)) {
originalScale = rotateArray(originalScale);
@ -118,7 +126,7 @@ public final class PDF417Writer implements Writer {
if (scale > 1) {
byte[][] scaledMatrix =
encoder.getBarcodeMatrix().getScaledMatrix(scale * lineThickness, scale * aspectRatio * lineThickness);
encoder.getBarcodeMatrix().getScaledMatrix(scale, scale * aspectRatio);
if (rotated) {
scaledMatrix = rotateArray(scaledMatrix);
}

View File

@ -88,7 +88,6 @@ final class BoundingBox {
if (newMinY < 0) {
newMinY = 0;
}
// TODO use existing points to better interpolate the new x positions
ResultPoint newTop = new ResultPoint(top.getX(), newMinY);
if (isLeft) {
newTopLeft = newTop;
@ -103,7 +102,6 @@ final class BoundingBox {
if (newMaxY >= image.getHeight()) {
newMaxY = image.getHeight() - 1;
}
// TODO use existing points to better interpolate the new x positions
ResultPoint newBottom = new ResultPoint(bottom.getX(), newMaxY);
if (isLeft) {
newBottomLeft = newBottom;

View File

@ -25,6 +25,7 @@ import com.google.zxing.common.CharacterSetECI;
import java.math.BigInteger;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.util.Arrays;
/**
@ -178,12 +179,11 @@ final class PDF417HighLevelEncoder {
int textSubMode = SUBMODE_ALPHA;
// User selected encoding mode
byte[] bytes = null; //Fill later and only if needed
if (compaction == Compaction.TEXT) {
encodeText(msg, p, len, sb, textSubMode);
} else if (compaction == Compaction.BYTE) {
bytes = msg.getBytes(encoding);
byte[] bytes = msg.getBytes(encoding);
encodeBinary(bytes, p, bytes.length, BYTE_COMPACTION, sb);
} else if (compaction == Compaction.NUMERIC) {
@ -211,19 +211,17 @@ final class PDF417HighLevelEncoder {
textSubMode = encodeText(msg, p, t, sb, textSubMode);
p += t;
} else {
if (bytes == null) {
bytes = msg.getBytes(encoding);
}
int b = determineConsecutiveBinaryCount(msg, bytes, p);
int b = determineConsecutiveBinaryCount(msg, p, encoding);
if (b == 0) {
b = 1;
}
if (b == 1 && encodingMode == TEXT_COMPACTION) {
byte[] bytes = msg.substring(p, p + b).getBytes(encoding);
if (bytes.length == 1 && encodingMode == TEXT_COMPACTION) {
//Switch for one byte (instead of latch)
encodeBinary(bytes, p, 1, TEXT_COMPACTION, sb);
encodeBinary(bytes, 0, 1, TEXT_COMPACTION, sb);
} else {
//Mode latch performed by encodeBinary()
encodeBinary(bytes, p, b, encodingMode, sb);
encodeBinary(bytes, 0, bytes.length, encodingMode, sb);
encodingMode = BYTE_COMPACTION;
textSubMode = SUBMODE_ALPHA; //Reset after latch
}
@ -530,12 +528,13 @@ final class PDF417HighLevelEncoder {
* Determines the number of consecutive characters that are encodable using binary compaction.
*
* @param msg the message
* @param bytes the message converted to a byte array
* @param startpos the start position within the message
* @param encoding the charset used to convert the message to a byte array
* @return the requested character count
*/
private static int determineConsecutiveBinaryCount(CharSequence msg, byte[] bytes, int startpos)
private static int determineConsecutiveBinaryCount(String msg, int startpos, Charset encoding)
throws WriterException {
final CharsetEncoder encoder = encoding.newEncoder();
int len = msg.length();
int idx = startpos;
while (idx < len) {
@ -556,10 +555,7 @@ final class PDF417HighLevelEncoder {
}
ch = msg.charAt(idx);
//Check if character is encodable
//Sun returns a ASCII 63 (?) for a character that cannot be mapped. Let's hope all
//other VMs do the same
if (bytes[idx] == 63 && ch != '?') {
if (!encoder.canEncode(ch)) {
throw new WriterException("Non-encodable character detected: " + ch + " (Unicode: " + (int) ch + ')');
}
idx++;

View File

@ -261,7 +261,7 @@ public class Detector {
/**
* See {@link #sizeOfBlackWhiteBlackRun(int, int, int, int)}; computes the total width of
* a finder pattern by looking for a black-white-black run from the center in the direction
* of another point (another finder pattern center), and in the opposite direction too.</p>
* of another point (another finder pattern center), and in the opposite direction too.
*/
private float sizeOfBlackWhiteBlackRunBothWays(int fromX, int fromY, int toX, int toY) {