Skip to content
Permalink
Browse files

Plugin updates; misc code simplifications and optimizations

  • Loading branch information
srowen committed Dec 11, 2019
1 parent cfe8684 commit 459c0197a7ce16ba9d2ce8d7acac2169a87fe066
Showing with 139 additions and 144 deletions.
  1. +1 −1 core/pom.xml
  2. +1 −1 core/src/main/java/com/google/zxing/aztec/detector/Detector.java
  3. +2 −2 core/src/main/java/com/google/zxing/client/result/AbstractDoCoMoResultParser.java
  4. +7 −9 core/src/main/java/com/google/zxing/client/result/AddressBookAUResultParser.java
  5. +6 −6 core/src/main/java/com/google/zxing/client/result/AddressBookDoCoMoResultParser.java
  6. +2 −2 core/src/main/java/com/google/zxing/client/result/BizcardResultParser.java
  7. +2 −2 core/src/main/java/com/google/zxing/client/result/BookmarkDoCoMoResultParser.java
  8. +2 −2 core/src/main/java/com/google/zxing/client/result/EmailDoCoMoResultParser.java
  9. +14 −15 core/src/main/java/com/google/zxing/client/result/VEventResultParser.java
  10. +6 −7 core/src/main/java/com/google/zxing/common/BitMatrix.java
  11. +1 −5 core/src/main/java/com/google/zxing/datamatrix/encoder/ErrorCorrection.java
  12. +3 −3 core/src/main/java/com/google/zxing/multi/qrcode/detector/MultiFinderPatternFinder.java
  13. +1 −1 core/src/main/java/com/google/zxing/oned/rss/expanded/ExpandedRow.java
  14. +8 −8 core/src/main/java/com/google/zxing/pdf417/decoder/BoundingBox.java
  15. +16 −6 core/src/main/java/com/google/zxing/qrcode/detector/FinderPatternFinder.java
  16. +11 −10 core/src/test/java/com/google/zxing/BufferedImageLuminanceSource.java
  17. +12 −20 core/src/test/java/com/google/zxing/common/AbstractBlackBoxTestCase.java
  18. +6 −12 core/src/test/java/com/google/zxing/pdf417/PDF417BlackBox4TestCase.java
  19. +2 −2 javase/pom.xml
  20. +11 −10 javase/src/main/java/com/google/zxing/client/j2se/BufferedImageLuminanceSource.java
  21. +15 −14 pom.xml
  22. +2 −2 zxingorg/pom.xml
  23. +8 −4 zxingorg/src/main/java/com/google/zxing/web/HTTPSFilter.java
@@ -66,7 +66,7 @@
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>4.2.0</version>
<version>4.3.1</version>
<executions>
<execution>
<goals>
@@ -577,7 +577,7 @@ private int getDimension() {
private final int y;

ResultPoint toResultPoint() {
return new ResultPoint(getX(), getY());
return new ResultPoint(x, y);
}

Point(int x, int y) {
@@ -28,8 +28,8 @@
*/
abstract class AbstractDoCoMoResultParser extends ResultParser {

static String[] matchDoCoMoPrefixedField(String prefix, String rawText, boolean trim) {
return matchPrefixedField(prefix, rawText, ';', trim);
static String[] matchDoCoMoPrefixedField(String prefix, String rawText) {
return matchPrefixedField(prefix, rawText, ';', true);
}

static String matchSingleDoCoMoPrefixedField(String prefix, String rawText, boolean trim) {
@@ -44,8 +44,8 @@ public AddressBookParsedResult parse(Result result) {
String name = matchSinglePrefixedField("NAME1:", rawText, '\r', true);
String pronunciation = matchSinglePrefixedField("NAME2:", rawText, '\r', true);

String[] phoneNumbers = matchMultipleValuePrefix("TEL", 3, rawText, true);
String[] emails = matchMultipleValuePrefix("MAIL", 3, rawText, true);
String[] phoneNumbers = matchMultipleValuePrefix("TEL", rawText);
String[] emails = matchMultipleValuePrefix("MAIL", rawText);
String note = matchSinglePrefixedField("MEMORY:", rawText, '\r', false);
String address = matchSinglePrefixedField("ADD:", rawText, '\r', true);
String[] addresses = address == null ? null : new String[] {address};
@@ -67,18 +67,16 @@ public AddressBookParsedResult parse(Result result) {
null);
}

private static String[] matchMultipleValuePrefix(String prefix,
int max,
String rawText,
boolean trim) {
private static String[] matchMultipleValuePrefix(String prefix, String rawText) {
List<String> values = null;
for (int i = 1; i <= max; i++) {
String value = matchSinglePrefixedField(prefix + i + ':', rawText, '\r', trim);
// For now, always 3, and always trim
for (int i = 1; i <= 3; i++) {
String value = matchSinglePrefixedField(prefix + i + ':', rawText, '\r', true);
if (value == null) {
break;
}
if (values == null) {
values = new ArrayList<>(max); // lazy init
values = new ArrayList<>(3); // lazy init
}
values.add(value);
}
@@ -29,7 +29,7 @@
*
* Our understanding of the MECARD format is based on this document:
*
* http://www.mobicode.org.tw/files/OMIA%20Mobile%20Bar%20Code%20Standard%20v3.2.1.doc
* http://www.mobicode.org.tw/files/OMIA%20Mobile%20Bar%20Code%20Standard%20v3.2.1.doc
*
* @author Sean Owen
*/
@@ -41,22 +41,22 @@ public AddressBookParsedResult parse(Result result) {
if (!rawText.startsWith("MECARD:")) {
return null;
}
String[] rawName = matchDoCoMoPrefixedField("N:", rawText, true);
String[] rawName = matchDoCoMoPrefixedField("N:", rawText);
if (rawName == null) {
return null;
}
String name = parseName(rawName[0]);
String pronunciation = matchSingleDoCoMoPrefixedField("SOUND:", rawText, true);
String[] phoneNumbers = matchDoCoMoPrefixedField("TEL:", rawText, true);
String[] emails = matchDoCoMoPrefixedField("EMAIL:", rawText, true);
String[] phoneNumbers = matchDoCoMoPrefixedField("TEL:", rawText);
String[] emails = matchDoCoMoPrefixedField("EMAIL:", rawText);
String note = matchSingleDoCoMoPrefixedField("NOTE:", rawText, false);
String[] addresses = matchDoCoMoPrefixedField("ADR:", rawText, true);
String[] addresses = matchDoCoMoPrefixedField("ADR:", rawText);
String birthday = matchSingleDoCoMoPrefixedField("BDAY:", rawText, true);
if (!isStringOfDigits(birthday, 8)) {
// No reason to throw out the whole card because the birthday is formatted wrong.
birthday = null;
}
String[] urls = matchDoCoMoPrefixedField("URL:", rawText, true);
String[] urls = matchDoCoMoPrefixedField("URL:", rawText);

// Although ORG may not be strictly legal in MECARD, it does exist in VCARD and we might as well
// honor it when found in the wild.
@@ -31,7 +31,7 @@
public final class BizcardResultParser extends AbstractDoCoMoResultParser {

// Yes, we extend AbstractDoCoMoResultParser since the format is very much
// like the DoCoMo MECARD format, but this is not technically one of
// like the DoCoMo MECARD format, but this is not technically one of
// DoCoMo's proposed formats

@Override
@@ -45,7 +45,7 @@ public AddressBookParsedResult parse(Result result) {
String fullName = buildName(firstName, lastName);
String title = matchSingleDoCoMoPrefixedField("T:", rawText, true);
String org = matchSingleDoCoMoPrefixedField("C:", rawText, true);
String[] addresses = matchDoCoMoPrefixedField("A:", rawText, true);
String[] addresses = matchDoCoMoPrefixedField("A:", rawText);
String phoneNumber1 = matchSingleDoCoMoPrefixedField("B:", rawText, true);
String phoneNumber2 = matchSingleDoCoMoPrefixedField("M:", rawText, true);
String phoneNumber3 = matchSingleDoCoMoPrefixedField("F:", rawText, true);
@@ -30,12 +30,12 @@ public URIParsedResult parse(Result result) {
return null;
}
String title = matchSingleDoCoMoPrefixedField("TITLE:", rawText, true);
String[] rawUri = matchDoCoMoPrefixedField("URL:", rawText, true);
String[] rawUri = matchDoCoMoPrefixedField("URL:", rawText);
if (rawUri == null) {
return null;
}
String uri = rawUri[0];
return URIResultParser.isBasicallyValidURI(uri) ? new URIParsedResult(uri, title) : null;
}

}
}
@@ -37,7 +37,7 @@ public EmailAddressParsedResult parse(Result result) {
if (!rawText.startsWith("MATMSG:")) {
return null;
}
String[] tos = matchDoCoMoPrefixedField("TO:", rawText, true);
String[] tos = matchDoCoMoPrefixedField("TO:", rawText);
if (tos == null) {
return null;
}
@@ -61,4 +61,4 @@ static boolean isBasicallyValidEmailAddress(String email) {
return email != null && ATEXT_ALPHANUMERIC.matcher(email).matches() && email.indexOf('@') >= 0;
}

}
}
@@ -36,25 +36,25 @@ public CalendarParsedResult parse(Result result) {
return null;
}

String summary = matchSingleVCardPrefixedField("SUMMARY", rawText, true);
String start = matchSingleVCardPrefixedField("DTSTART", rawText, true);
String summary = matchSingleVCardPrefixedField("SUMMARY", rawText);
String start = matchSingleVCardPrefixedField("DTSTART", rawText);
if (start == null) {
return null;
}
String end = matchSingleVCardPrefixedField("DTEND", rawText, true);
String duration = matchSingleVCardPrefixedField("DURATION", rawText, true);
String location = matchSingleVCardPrefixedField("LOCATION", rawText, true);
String organizer = stripMailto(matchSingleVCardPrefixedField("ORGANIZER", rawText, true));
String end = matchSingleVCardPrefixedField("DTEND", rawText);
String duration = matchSingleVCardPrefixedField("DURATION", rawText);
String location = matchSingleVCardPrefixedField("LOCATION", rawText);
String organizer = stripMailto(matchSingleVCardPrefixedField("ORGANIZER", rawText));

String[] attendees = matchVCardPrefixedField("ATTENDEE", rawText, true);
String[] attendees = matchVCardPrefixedField("ATTENDEE", rawText);
if (attendees != null) {
for (int i = 0; i < attendees.length; i++) {
attendees[i] = stripMailto(attendees[i]);
}
}
String description = matchSingleVCardPrefixedField("DESCRIPTION", rawText, true);
String description = matchSingleVCardPrefixedField("DESCRIPTION", rawText);

String geoString = matchSingleVCardPrefixedField("GEO", rawText, true);
String geoString = matchSingleVCardPrefixedField("GEO", rawText);
double latitude;
double longitude;
if (geoString == null) {
@@ -90,14 +90,13 @@ public CalendarParsedResult parse(Result result) {
}

private static String matchSingleVCardPrefixedField(CharSequence prefix,
String rawText,
boolean trim) {
List<String> values = VCardResultParser.matchSingleVCardPrefixedField(prefix, rawText, trim, false);
String rawText) {
List<String> values = VCardResultParser.matchSingleVCardPrefixedField(prefix, rawText, true, false);
return values == null || values.isEmpty() ? null : values.get(0);
}

private static String[] matchVCardPrefixedField(CharSequence prefix, String rawText, boolean trim) {
List<List<String>> values = VCardResultParser.matchVCardPrefixedField(prefix, rawText, trim, false);
private static String[] matchVCardPrefixedField(CharSequence prefix, String rawText) {
List<List<String>> values = VCardResultParser.matchVCardPrefixedField(prefix, rawText, true, false);
if (values == null || values.isEmpty()) {
return null;
}
@@ -116,4 +115,4 @@ private static String stripMailto(String s) {
return s;
}

}
}
@@ -196,8 +196,7 @@ public void flip(int x, int y) {
* @param mask XOR mask
*/
public void xor(BitMatrix mask) {
if (width != mask.getWidth() || height != mask.getHeight()
|| rowSize != mask.getRowSize()) {
if (width != mask.width || height != mask.height || rowSize != mask.rowSize) {
throw new IllegalArgumentException("input matrix dimensions do not match");
}
BitArray rowArray = new BitArray(width);
@@ -281,17 +280,17 @@ public void setRow(int y, BitArray row) {
* Modifies this {@code BitMatrix} to represent the same but rotated 180 degrees
*/
public void rotate180() {
int width = getWidth();
int height = getHeight();
BitArray topRow = new BitArray(width);
BitArray bottomRow = new BitArray(width);
for (int i = 0; i < (height + 1) / 2; i++) {
int maxHeight = (height + 1) / 2;
for (int i = 0; i < maxHeight; i++) {
topRow = getRow(i, topRow);
bottomRow = getRow(height - 1 - i, bottomRow);
int bottomRowIndex = height - 1 - i;
bottomRow = getRow(bottomRowIndex, bottomRow);
topRow.reverse();
bottomRow.reverse();
setRow(i, bottomRow);
setRow(height - 1 - i, topRow);
setRow(bottomRowIndex, topRow);
}
}

@@ -134,10 +134,6 @@ public static String encodeECC200(String codewords, SymbolInfo symbolInfo) {
}

private static String createECCBlock(CharSequence codewords, int numECWords) {
return createECCBlock(codewords, 0, codewords.length(), numECWords);
}

private static String createECCBlock(CharSequence codewords, int start, int len, int numECWords) {
int table = -1;
for (int i = 0; i < FACTOR_SETS.length; i++) {
if (FACTOR_SETS[i] == numECWords) {
@@ -154,7 +150,7 @@ private static String createECCBlock(CharSequence codewords, int start, int len,
for (int i = 0; i < numECWords; i++) {
ecc[i] = 0;
}
for (int i = start; i < start + len; i++) {
for (int i = 0; i < codewords.length(); i++) {
int m = ecc[numECWords - 1] ^ codewords.charAt(i);
for (int k = numECWords - 1; k > 0; k--) {
if (m != 0 && poly[k] != 0) {
@@ -235,7 +235,7 @@ public int compare(FinderPattern center1, FinderPattern center2) {
int[] stateCount = new int[5];
for (int i = iSkip - 1; i < maxI; i += iSkip) {
// Get a row of black/white values
clearCounts(stateCount);
doClearCounts(stateCount);
int currentState = 0;
for (int j = 0; j < maxJ; j++) {
if (image.get(j, i)) {
@@ -250,9 +250,9 @@ public int compare(FinderPattern center1, FinderPattern center2) {
if (foundPatternCross(stateCount) && handlePossibleCenter(stateCount, i, j)) { // Yes
// Clear state to start looking again
currentState = 0;
clearCounts(stateCount);
doClearCounts(stateCount);
} else { // No, shift counts back by two
shiftCounts2(stateCount);
doShiftCounts2(stateCount);
currentState = 3;
}
} else {
@@ -61,7 +61,7 @@ public boolean equals(Object o) {
return false;
}
ExpandedRow that = (ExpandedRow) o;
return this.pairs.equals(that.getPairs()) && wasReversed == that.wasReversed;
return this.pairs.equals(that.pairs) && wasReversed == that.wasReversed;
}

@Override
@@ -65,14 +65,14 @@

BoundingBox(BoundingBox boundingBox) {
this.image = boundingBox.image;
this.topLeft = boundingBox.getTopLeft();
this.bottomLeft = boundingBox.getBottomLeft();
this.topRight = boundingBox.getTopRight();
this.bottomRight = boundingBox.getBottomRight();
this.minX = boundingBox.getMinX();
this.maxX = boundingBox.getMaxX();
this.minY = boundingBox.getMinY();
this.maxY = boundingBox.getMaxY();
this.topLeft = boundingBox.topLeft;
this.bottomLeft = boundingBox.bottomLeft;
this.topRight = boundingBox.topRight;
this.bottomRight = boundingBox.bottomRight;
this.minX = boundingBox.minX;
this.maxX = boundingBox.maxX;
this.minY = boundingBox.minY;
this.maxY = boundingBox.maxY;
}

static BoundingBox merge(BoundingBox leftBox, BoundingBox rightBox) throws NotFoundException {
@@ -94,7 +94,7 @@ final FinderPatternInfo find(Map<DecodeHintType,?> hints) throws NotFoundExcepti
int[] stateCount = new int[5];
for (int i = iSkip - 1; i < maxI && !done; i += iSkip) {
// Get a row of black/white values
clearCounts(stateCount);
doClearCounts(stateCount);
int currentState = 0;
for (int j = 0; j < maxJ; j++) {
if (image.get(j, i)) {
@@ -130,15 +130,15 @@ final FinderPatternInfo find(Map<DecodeHintType,?> hints) throws NotFoundExcepti
}
}
} else {
shiftCounts2(stateCount);
doShiftCounts2(stateCount);
currentState = 3;
continue;
}
// Clear state to start looking again
currentState = 0;
clearCounts(stateCount);
doClearCounts(stateCount);
} else { // No, shift counts back by two
shiftCounts2(stateCount);
doShiftCounts2(stateCount);
currentState = 3;
}
} else {
@@ -232,15 +232,25 @@ protected static boolean foundPatternDiagonal(int[] stateCount) {
}

private int[] getCrossCheckStateCount() {
clearCounts(crossCheckStateCount);
doClearCounts(crossCheckStateCount);
return crossCheckStateCount;
}

@Deprecated
protected final void clearCounts(int[] counts) {
Arrays.fill(counts, 0);
doClearCounts(counts);
}

@Deprecated
protected final void shiftCounts2(int[] stateCount) {
doShiftCounts2(stateCount);
}

protected static void doClearCounts(int[] counts) {
Arrays.fill(counts, 0);
}

protected static void doShiftCounts2(int[] stateCount) {
stateCount[0] = stateCount[2];
stateCount[1] = stateCount[3];
stateCount[2] = stateCount[4];

0 comments on commit 459c019

Please sign in to comment.
You can’t perform that action at this time.