mirror of
https://github.com/zxing/zxing.git
synced 2024-11-09 20:44:03 -08:00
Plugin updates; misc code simplifications and optimizations
This commit is contained in:
parent
cfe8684669
commit
459c0197a7
|
@ -66,7 +66,7 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>biz.aQute.bnd</groupId>
|
<groupId>biz.aQute.bnd</groupId>
|
||||||
<artifactId>bnd-maven-plugin</artifactId>
|
<artifactId>bnd-maven-plugin</artifactId>
|
||||||
<version>4.2.0</version>
|
<version>4.3.1</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
|
|
|
@ -577,7 +577,7 @@ public final class Detector {
|
||||||
private final int y;
|
private final int y;
|
||||||
|
|
||||||
ResultPoint toResultPoint() {
|
ResultPoint toResultPoint() {
|
||||||
return new ResultPoint(getX(), getY());
|
return new ResultPoint(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
Point(int x, int y) {
|
Point(int x, int y) {
|
||||||
|
|
|
@ -28,8 +28,8 @@ package com.google.zxing.client.result;
|
||||||
*/
|
*/
|
||||||
abstract class AbstractDoCoMoResultParser extends ResultParser {
|
abstract class AbstractDoCoMoResultParser extends ResultParser {
|
||||||
|
|
||||||
static String[] matchDoCoMoPrefixedField(String prefix, String rawText, boolean trim) {
|
static String[] matchDoCoMoPrefixedField(String prefix, String rawText) {
|
||||||
return matchPrefixedField(prefix, rawText, ';', trim);
|
return matchPrefixedField(prefix, rawText, ';', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static String matchSingleDoCoMoPrefixedField(String prefix, String rawText, boolean trim) {
|
static String matchSingleDoCoMoPrefixedField(String prefix, String rawText, boolean trim) {
|
||||||
|
|
|
@ -44,8 +44,8 @@ public final class AddressBookAUResultParser extends ResultParser {
|
||||||
String name = matchSinglePrefixedField("NAME1:", rawText, '\r', true);
|
String name = matchSinglePrefixedField("NAME1:", rawText, '\r', true);
|
||||||
String pronunciation = matchSinglePrefixedField("NAME2:", rawText, '\r', true);
|
String pronunciation = matchSinglePrefixedField("NAME2:", rawText, '\r', true);
|
||||||
|
|
||||||
String[] phoneNumbers = matchMultipleValuePrefix("TEL", 3, rawText, true);
|
String[] phoneNumbers = matchMultipleValuePrefix("TEL", rawText);
|
||||||
String[] emails = matchMultipleValuePrefix("MAIL", 3, rawText, true);
|
String[] emails = matchMultipleValuePrefix("MAIL", rawText);
|
||||||
String note = matchSinglePrefixedField("MEMORY:", rawText, '\r', false);
|
String note = matchSinglePrefixedField("MEMORY:", rawText, '\r', false);
|
||||||
String address = matchSinglePrefixedField("ADD:", rawText, '\r', true);
|
String address = matchSinglePrefixedField("ADD:", rawText, '\r', true);
|
||||||
String[] addresses = address == null ? null : new String[] {address};
|
String[] addresses = address == null ? null : new String[] {address};
|
||||||
|
@ -67,18 +67,16 @@ public final class AddressBookAUResultParser extends ResultParser {
|
||||||
null);
|
null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String[] matchMultipleValuePrefix(String prefix,
|
private static String[] matchMultipleValuePrefix(String prefix, String rawText) {
|
||||||
int max,
|
|
||||||
String rawText,
|
|
||||||
boolean trim) {
|
|
||||||
List<String> values = null;
|
List<String> values = null;
|
||||||
for (int i = 1; i <= max; i++) {
|
// For now, always 3, and always trim
|
||||||
String value = matchSinglePrefixedField(prefix + i + ':', rawText, '\r', trim);
|
for (int i = 1; i <= 3; i++) {
|
||||||
|
String value = matchSinglePrefixedField(prefix + i + ':', rawText, '\r', true);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (values == null) {
|
if (values == null) {
|
||||||
values = new ArrayList<>(max); // lazy init
|
values = new ArrayList<>(3); // lazy init
|
||||||
}
|
}
|
||||||
values.add(value);
|
values.add(value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,22 +41,22 @@ public final class AddressBookDoCoMoResultParser extends AbstractDoCoMoResultPar
|
||||||
if (!rawText.startsWith("MECARD:")) {
|
if (!rawText.startsWith("MECARD:")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String[] rawName = matchDoCoMoPrefixedField("N:", rawText, true);
|
String[] rawName = matchDoCoMoPrefixedField("N:", rawText);
|
||||||
if (rawName == null) {
|
if (rawName == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String name = parseName(rawName[0]);
|
String name = parseName(rawName[0]);
|
||||||
String pronunciation = matchSingleDoCoMoPrefixedField("SOUND:", rawText, true);
|
String pronunciation = matchSingleDoCoMoPrefixedField("SOUND:", rawText, true);
|
||||||
String[] phoneNumbers = matchDoCoMoPrefixedField("TEL:", rawText, true);
|
String[] phoneNumbers = matchDoCoMoPrefixedField("TEL:", rawText);
|
||||||
String[] emails = matchDoCoMoPrefixedField("EMAIL:", rawText, true);
|
String[] emails = matchDoCoMoPrefixedField("EMAIL:", rawText);
|
||||||
String note = matchSingleDoCoMoPrefixedField("NOTE:", rawText, false);
|
String note = matchSingleDoCoMoPrefixedField("NOTE:", rawText, false);
|
||||||
String[] addresses = matchDoCoMoPrefixedField("ADR:", rawText, true);
|
String[] addresses = matchDoCoMoPrefixedField("ADR:", rawText);
|
||||||
String birthday = matchSingleDoCoMoPrefixedField("BDAY:", rawText, true);
|
String birthday = matchSingleDoCoMoPrefixedField("BDAY:", rawText, true);
|
||||||
if (!isStringOfDigits(birthday, 8)) {
|
if (!isStringOfDigits(birthday, 8)) {
|
||||||
// No reason to throw out the whole card because the birthday is formatted wrong.
|
// No reason to throw out the whole card because the birthday is formatted wrong.
|
||||||
birthday = null;
|
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
|
// 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.
|
// honor it when found in the wild.
|
||||||
|
|
|
@ -45,7 +45,7 @@ public final class BizcardResultParser extends AbstractDoCoMoResultParser {
|
||||||
String fullName = buildName(firstName, lastName);
|
String fullName = buildName(firstName, lastName);
|
||||||
String title = matchSingleDoCoMoPrefixedField("T:", rawText, true);
|
String title = matchSingleDoCoMoPrefixedField("T:", rawText, true);
|
||||||
String org = matchSingleDoCoMoPrefixedField("C:", 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 phoneNumber1 = matchSingleDoCoMoPrefixedField("B:", rawText, true);
|
||||||
String phoneNumber2 = matchSingleDoCoMoPrefixedField("M:", rawText, true);
|
String phoneNumber2 = matchSingleDoCoMoPrefixedField("M:", rawText, true);
|
||||||
String phoneNumber3 = matchSingleDoCoMoPrefixedField("F:", rawText, true);
|
String phoneNumber3 = matchSingleDoCoMoPrefixedField("F:", rawText, true);
|
||||||
|
|
|
@ -30,7 +30,7 @@ public final class BookmarkDoCoMoResultParser extends AbstractDoCoMoResultParser
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String title = matchSingleDoCoMoPrefixedField("TITLE:", rawText, true);
|
String title = matchSingleDoCoMoPrefixedField("TITLE:", rawText, true);
|
||||||
String[] rawUri = matchDoCoMoPrefixedField("URL:", rawText, true);
|
String[] rawUri = matchDoCoMoPrefixedField("URL:", rawText);
|
||||||
if (rawUri == null) {
|
if (rawUri == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ public final class EmailDoCoMoResultParser extends AbstractDoCoMoResultParser {
|
||||||
if (!rawText.startsWith("MATMSG:")) {
|
if (!rawText.startsWith("MATMSG:")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String[] tos = matchDoCoMoPrefixedField("TO:", rawText, true);
|
String[] tos = matchDoCoMoPrefixedField("TO:", rawText);
|
||||||
if (tos == null) {
|
if (tos == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,25 +36,25 @@ public final class VEventResultParser extends ResultParser {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String summary = matchSingleVCardPrefixedField("SUMMARY", rawText, true);
|
String summary = matchSingleVCardPrefixedField("SUMMARY", rawText);
|
||||||
String start = matchSingleVCardPrefixedField("DTSTART", rawText, true);
|
String start = matchSingleVCardPrefixedField("DTSTART", rawText);
|
||||||
if (start == null) {
|
if (start == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String end = matchSingleVCardPrefixedField("DTEND", rawText, true);
|
String end = matchSingleVCardPrefixedField("DTEND", rawText);
|
||||||
String duration = matchSingleVCardPrefixedField("DURATION", rawText, true);
|
String duration = matchSingleVCardPrefixedField("DURATION", rawText);
|
||||||
String location = matchSingleVCardPrefixedField("LOCATION", rawText, true);
|
String location = matchSingleVCardPrefixedField("LOCATION", rawText);
|
||||||
String organizer = stripMailto(matchSingleVCardPrefixedField("ORGANIZER", rawText, true));
|
String organizer = stripMailto(matchSingleVCardPrefixedField("ORGANIZER", rawText));
|
||||||
|
|
||||||
String[] attendees = matchVCardPrefixedField("ATTENDEE", rawText, true);
|
String[] attendees = matchVCardPrefixedField("ATTENDEE", rawText);
|
||||||
if (attendees != null) {
|
if (attendees != null) {
|
||||||
for (int i = 0; i < attendees.length; i++) {
|
for (int i = 0; i < attendees.length; i++) {
|
||||||
attendees[i] = stripMailto(attendees[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 latitude;
|
||||||
double longitude;
|
double longitude;
|
||||||
if (geoString == null) {
|
if (geoString == null) {
|
||||||
|
@ -90,14 +90,13 @@ public final class VEventResultParser extends ResultParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String matchSingleVCardPrefixedField(CharSequence prefix,
|
private static String matchSingleVCardPrefixedField(CharSequence prefix,
|
||||||
String rawText,
|
String rawText) {
|
||||||
boolean trim) {
|
List<String> values = VCardResultParser.matchSingleVCardPrefixedField(prefix, rawText, true, false);
|
||||||
List<String> values = VCardResultParser.matchSingleVCardPrefixedField(prefix, rawText, trim, false);
|
|
||||||
return values == null || values.isEmpty() ? null : values.get(0);
|
return values == null || values.isEmpty() ? null : values.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String[] matchVCardPrefixedField(CharSequence prefix, String rawText, boolean trim) {
|
private static String[] matchVCardPrefixedField(CharSequence prefix, String rawText) {
|
||||||
List<List<String>> values = VCardResultParser.matchVCardPrefixedField(prefix, rawText, trim, false);
|
List<List<String>> values = VCardResultParser.matchVCardPrefixedField(prefix, rawText, true, false);
|
||||||
if (values == null || values.isEmpty()) {
|
if (values == null || values.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,8 +196,7 @@ public final class BitMatrix implements Cloneable {
|
||||||
* @param mask XOR mask
|
* @param mask XOR mask
|
||||||
*/
|
*/
|
||||||
public void xor(BitMatrix mask) {
|
public void xor(BitMatrix mask) {
|
||||||
if (width != mask.getWidth() || height != mask.getHeight()
|
if (width != mask.width || height != mask.height || rowSize != mask.rowSize) {
|
||||||
|| rowSize != mask.getRowSize()) {
|
|
||||||
throw new IllegalArgumentException("input matrix dimensions do not match");
|
throw new IllegalArgumentException("input matrix dimensions do not match");
|
||||||
}
|
}
|
||||||
BitArray rowArray = new BitArray(width);
|
BitArray rowArray = new BitArray(width);
|
||||||
|
@ -281,17 +280,17 @@ public final class BitMatrix implements Cloneable {
|
||||||
* Modifies this {@code BitMatrix} to represent the same but rotated 180 degrees
|
* Modifies this {@code BitMatrix} to represent the same but rotated 180 degrees
|
||||||
*/
|
*/
|
||||||
public void rotate180() {
|
public void rotate180() {
|
||||||
int width = getWidth();
|
|
||||||
int height = getHeight();
|
|
||||||
BitArray topRow = new BitArray(width);
|
BitArray topRow = new BitArray(width);
|
||||||
BitArray bottomRow = 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);
|
topRow = getRow(i, topRow);
|
||||||
bottomRow = getRow(height - 1 - i, bottomRow);
|
int bottomRowIndex = height - 1 - i;
|
||||||
|
bottomRow = getRow(bottomRowIndex, bottomRow);
|
||||||
topRow.reverse();
|
topRow.reverse();
|
||||||
bottomRow.reverse();
|
bottomRow.reverse();
|
||||||
setRow(i, bottomRow);
|
setRow(i, bottomRow);
|
||||||
setRow(height - 1 - i, topRow);
|
setRow(bottomRowIndex, topRow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,10 +134,6 @@ public final class ErrorCorrection {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String createECCBlock(CharSequence codewords, int numECWords) {
|
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;
|
int table = -1;
|
||||||
for (int i = 0; i < FACTOR_SETS.length; i++) {
|
for (int i = 0; i < FACTOR_SETS.length; i++) {
|
||||||
if (FACTOR_SETS[i] == numECWords) {
|
if (FACTOR_SETS[i] == numECWords) {
|
||||||
|
@ -154,7 +150,7 @@ public final class ErrorCorrection {
|
||||||
for (int i = 0; i < numECWords; i++) {
|
for (int i = 0; i < numECWords; i++) {
|
||||||
ecc[i] = 0;
|
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);
|
int m = ecc[numECWords - 1] ^ codewords.charAt(i);
|
||||||
for (int k = numECWords - 1; k > 0; k--) {
|
for (int k = numECWords - 1; k > 0; k--) {
|
||||||
if (m != 0 && poly[k] != 0) {
|
if (m != 0 && poly[k] != 0) {
|
||||||
|
|
|
@ -235,7 +235,7 @@ final class MultiFinderPatternFinder extends FinderPatternFinder {
|
||||||
int[] stateCount = new int[5];
|
int[] stateCount = new int[5];
|
||||||
for (int i = iSkip - 1; i < maxI; i += iSkip) {
|
for (int i = iSkip - 1; i < maxI; i += iSkip) {
|
||||||
// Get a row of black/white values
|
// Get a row of black/white values
|
||||||
clearCounts(stateCount);
|
doClearCounts(stateCount);
|
||||||
int currentState = 0;
|
int currentState = 0;
|
||||||
for (int j = 0; j < maxJ; j++) {
|
for (int j = 0; j < maxJ; j++) {
|
||||||
if (image.get(j, i)) {
|
if (image.get(j, i)) {
|
||||||
|
@ -250,9 +250,9 @@ final class MultiFinderPatternFinder extends FinderPatternFinder {
|
||||||
if (foundPatternCross(stateCount) && handlePossibleCenter(stateCount, i, j)) { // Yes
|
if (foundPatternCross(stateCount) && handlePossibleCenter(stateCount, i, j)) { // Yes
|
||||||
// Clear state to start looking again
|
// Clear state to start looking again
|
||||||
currentState = 0;
|
currentState = 0;
|
||||||
clearCounts(stateCount);
|
doClearCounts(stateCount);
|
||||||
} else { // No, shift counts back by two
|
} else { // No, shift counts back by two
|
||||||
shiftCounts2(stateCount);
|
doShiftCounts2(stateCount);
|
||||||
currentState = 3;
|
currentState = 3;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -61,7 +61,7 @@ final class ExpandedRow {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ExpandedRow that = (ExpandedRow) o;
|
ExpandedRow that = (ExpandedRow) o;
|
||||||
return this.pairs.equals(that.getPairs()) && wasReversed == that.wasReversed;
|
return this.pairs.equals(that.pairs) && wasReversed == that.wasReversed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -65,14 +65,14 @@ final class BoundingBox {
|
||||||
|
|
||||||
BoundingBox(BoundingBox boundingBox) {
|
BoundingBox(BoundingBox boundingBox) {
|
||||||
this.image = boundingBox.image;
|
this.image = boundingBox.image;
|
||||||
this.topLeft = boundingBox.getTopLeft();
|
this.topLeft = boundingBox.topLeft;
|
||||||
this.bottomLeft = boundingBox.getBottomLeft();
|
this.bottomLeft = boundingBox.bottomLeft;
|
||||||
this.topRight = boundingBox.getTopRight();
|
this.topRight = boundingBox.topRight;
|
||||||
this.bottomRight = boundingBox.getBottomRight();
|
this.bottomRight = boundingBox.bottomRight;
|
||||||
this.minX = boundingBox.getMinX();
|
this.minX = boundingBox.minX;
|
||||||
this.maxX = boundingBox.getMaxX();
|
this.maxX = boundingBox.maxX;
|
||||||
this.minY = boundingBox.getMinY();
|
this.minY = boundingBox.minY;
|
||||||
this.maxY = boundingBox.getMaxY();
|
this.maxY = boundingBox.maxY;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BoundingBox merge(BoundingBox leftBox, BoundingBox rightBox) throws NotFoundException {
|
static BoundingBox merge(BoundingBox leftBox, BoundingBox rightBox) throws NotFoundException {
|
||||||
|
|
|
@ -94,7 +94,7 @@ public class FinderPatternFinder {
|
||||||
int[] stateCount = new int[5];
|
int[] stateCount = new int[5];
|
||||||
for (int i = iSkip - 1; i < maxI && !done; i += iSkip) {
|
for (int i = iSkip - 1; i < maxI && !done; i += iSkip) {
|
||||||
// Get a row of black/white values
|
// Get a row of black/white values
|
||||||
clearCounts(stateCount);
|
doClearCounts(stateCount);
|
||||||
int currentState = 0;
|
int currentState = 0;
|
||||||
for (int j = 0; j < maxJ; j++) {
|
for (int j = 0; j < maxJ; j++) {
|
||||||
if (image.get(j, i)) {
|
if (image.get(j, i)) {
|
||||||
|
@ -130,15 +130,15 @@ public class FinderPatternFinder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
shiftCounts2(stateCount);
|
doShiftCounts2(stateCount);
|
||||||
currentState = 3;
|
currentState = 3;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Clear state to start looking again
|
// Clear state to start looking again
|
||||||
currentState = 0;
|
currentState = 0;
|
||||||
clearCounts(stateCount);
|
doClearCounts(stateCount);
|
||||||
} else { // No, shift counts back by two
|
} else { // No, shift counts back by two
|
||||||
shiftCounts2(stateCount);
|
doShiftCounts2(stateCount);
|
||||||
currentState = 3;
|
currentState = 3;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -232,15 +232,25 @@ public class FinderPatternFinder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int[] getCrossCheckStateCount() {
|
private int[] getCrossCheckStateCount() {
|
||||||
clearCounts(crossCheckStateCount);
|
doClearCounts(crossCheckStateCount);
|
||||||
return crossCheckStateCount;
|
return crossCheckStateCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
protected final void clearCounts(int[] counts) {
|
protected final void clearCounts(int[] counts) {
|
||||||
|
doClearCounts(counts);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
protected final void shiftCounts2(int[] stateCount) {
|
||||||
|
doShiftCounts2(stateCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void doClearCounts(int[] counts) {
|
||||||
Arrays.fill(counts, 0);
|
Arrays.fill(counts, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void shiftCounts2(int[] stateCount) {
|
protected static void doShiftCounts2(int[] stateCount) {
|
||||||
stateCount[0] = stateCount[2];
|
stateCount[0] = stateCount[2];
|
||||||
stateCount[1] = stateCount[3];
|
stateCount[1] = stateCount[3];
|
||||||
stateCount[2] = stateCount[4];
|
stateCount[2] = stateCount[4];
|
||||||
|
|
|
@ -65,9 +65,9 @@ public final class BufferedImageLuminanceSource extends LuminanceSource {
|
||||||
// black (0 alpha, and then 0 RGB). They are often used, of course as the "white" area in a
|
// black (0 alpha, and then 0 RGB). They are often used, of course as the "white" area in a
|
||||||
// barcode image. Force any such pixel to be white:
|
// barcode image. Force any such pixel to be white:
|
||||||
if ((pixel & 0xFF000000) == 0) {
|
if ((pixel & 0xFF000000) == 0) {
|
||||||
pixel = 0xFFFFFFFF; // = white
|
// white, so we know its luminance is 255
|
||||||
}
|
buffer[x] = 0xFF;
|
||||||
|
} else {
|
||||||
// .299R + 0.587G + 0.114B (YUV/YIQ for PAL and NTSC),
|
// .299R + 0.587G + 0.114B (YUV/YIQ for PAL and NTSC),
|
||||||
// (306*R) >> 10 is approximately equal to R*0.299, and so on.
|
// (306*R) >> 10 is approximately equal to R*0.299, and so on.
|
||||||
// 0x200 >> 10 is 0.5, it implements rounding.
|
// 0x200 >> 10 is 0.5, it implements rounding.
|
||||||
|
@ -77,6 +77,7 @@ public final class BufferedImageLuminanceSource extends LuminanceSource {
|
||||||
117 * (pixel & 0xFF) +
|
117 * (pixel & 0xFF) +
|
||||||
0x200) >> 10;
|
0x200) >> 10;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
raster.setPixels(left, y, width, 1, buffer);
|
raster.setPixels(left, y, width, 1, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -125,14 +125,8 @@ public abstract class AbstractBlackBoxTestCase extends Assert {
|
||||||
return barcodeReader;
|
return barcodeReader;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This workaround is used because AbstractNegativeBlackBoxTestCase overrides this method but does
|
|
||||||
// not return SummaryResults.
|
|
||||||
@Test
|
@Test
|
||||||
public void testBlackBox() throws IOException {
|
public void testBlackBox() throws IOException {
|
||||||
testBlackBoxCountingResults(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testBlackBoxCountingResults(boolean assertOnFailure) throws IOException {
|
|
||||||
assertFalse(testResults.isEmpty());
|
assertFalse(testResults.isEmpty());
|
||||||
|
|
||||||
List<Path> imageFiles = getImageFiles();
|
List<Path> imageFiles = getImageFiles();
|
||||||
|
@ -235,7 +229,6 @@ public abstract class AbstractBlackBoxTestCase extends Assert {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then run through again and assert if any failed
|
// Then run through again and assert if any failed
|
||||||
if (assertOnFailure) {
|
|
||||||
for (int x = 0; x < testCount; x++) {
|
for (int x = 0; x < testCount; x++) {
|
||||||
TestResult testResult = testResults.get(x);
|
TestResult testResult = testResults.get(x);
|
||||||
String label = "Rotation " + testResult.getRotation() + " degrees: Too many images failed";
|
String label = "Rotation " + testResult.getRotation() + " degrees: Too many images failed";
|
||||||
|
@ -250,7 +243,6 @@ public abstract class AbstractBlackBoxTestCase extends Assert {
|
||||||
tryHarderMisreadCounts[x] <= testResult.getMaxTryHarderMisreads());
|
tryHarderMisreadCounts[x] <= testResult.getMaxTryHarderMisreads());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private boolean decode(BinaryBitmap source,
|
private boolean decode(BinaryBitmap source,
|
||||||
float rotation,
|
float rotation,
|
||||||
|
|
|
@ -69,10 +69,6 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void testBlackBox() throws IOException {
|
public void testBlackBox() throws IOException {
|
||||||
testPDF417BlackBoxCountingResults(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testPDF417BlackBoxCountingResults(boolean assertOnFailure) throws IOException {
|
|
||||||
assertFalse(testResults.isEmpty());
|
assertFalse(testResults.isEmpty());
|
||||||
|
|
||||||
Map<String,List<Path>> imageFiles = getImageFileLists();
|
Map<String,List<Path>> imageFiles = getImageFileLists();
|
||||||
|
@ -157,7 +153,6 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then run through again and assert if any failed
|
// Then run through again and assert if any failed
|
||||||
if (assertOnFailure) {
|
|
||||||
for (int x = 0; x < testCount; x++) {
|
for (int x = 0; x < testCount; x++) {
|
||||||
TestResult testResult = testResults.get(x);
|
TestResult testResult = testResults.get(x);
|
||||||
String label = "Rotation " + testResult.getRotation() + " degrees: Too many images failed";
|
String label = "Rotation " + testResult.getRotation() + " degrees: Too many images failed";
|
||||||
|
@ -165,7 +160,6 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
|
||||||
assertTrue("Try harder, " + label, tryHarderCounts[x] >= testResult.getTryHarderCount());
|
assertTrue("Try harder, " + label, tryHarderCounts[x] >= testResult.getTryHarderCount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static PDF417ResultMetadata getMeta(Result result) {
|
private static PDF417ResultMetadata getMeta(Result result) {
|
||||||
return result.getResultMetadata() == null ? null : (PDF417ResultMetadata) result.getResultMetadata().get(
|
return result.getResultMetadata() == null ? null : (PDF417ResultMetadata) result.getResultMetadata().get(
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.beust</groupId>
|
<groupId>com.beust</groupId>
|
||||||
<artifactId>jcommander</artifactId>
|
<artifactId>jcommander</artifactId>
|
||||||
<version>1.72</version>
|
<version>1.78</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.jai-imageio</groupId>
|
<groupId>com.github.jai-imageio</groupId>
|
||||||
|
|
|
@ -67,9 +67,9 @@ public final class BufferedImageLuminanceSource extends LuminanceSource {
|
||||||
// black (0 alpha, and then 0 RGB). They are often used, of course as the "white" area in a
|
// black (0 alpha, and then 0 RGB). They are often used, of course as the "white" area in a
|
||||||
// barcode image. Force any such pixel to be white:
|
// barcode image. Force any such pixel to be white:
|
||||||
if ((pixel & 0xFF000000) == 0) {
|
if ((pixel & 0xFF000000) == 0) {
|
||||||
pixel = 0xFFFFFFFF; // = white
|
// white, so we know its luminance is 255
|
||||||
}
|
buffer[x] = 0xFF;
|
||||||
|
} else {
|
||||||
// .299R + 0.587G + 0.114B (YUV/YIQ for PAL and NTSC),
|
// .299R + 0.587G + 0.114B (YUV/YIQ for PAL and NTSC),
|
||||||
// (306*R) >> 10 is approximately equal to R*0.299, and so on.
|
// (306*R) >> 10 is approximately equal to R*0.299, and so on.
|
||||||
// 0x200 >> 10 is 0.5, it implements rounding.
|
// 0x200 >> 10 is 0.5, it implements rounding.
|
||||||
|
@ -79,6 +79,7 @@ public final class BufferedImageLuminanceSource extends LuminanceSource {
|
||||||
117 * (pixel & 0xFF) +
|
117 * (pixel & 0xFF) +
|
||||||
0x200) >> 10;
|
0x200) >> 10;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
raster.setPixels(left, y, width, 1, buffer);
|
raster.setPixels(left, y, width, 1, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
29
pom.xml
29
pom.xml
|
@ -64,7 +64,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.13-beta-3</version>
|
<version>4.13-rc-2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -82,8 +82,9 @@
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<proguard.version>6.1.1</proguard.version>
|
<android.home>${env.ANDROID_HOME}</android.home>
|
||||||
<proguard.plugin.version>2.1.1</proguard.plugin.version>
|
<proguard.version>6.2.0</proguard.version>
|
||||||
|
<proguard.plugin.version>2.2.0</proguard.plugin.version>
|
||||||
<slf4j.version>1.8.0-beta4</slf4j.version>
|
<slf4j.version>1.8.0-beta4</slf4j.version>
|
||||||
<!-- This can't reference project.version as some subprojects version differently -->
|
<!-- This can't reference project.version as some subprojects version differently -->
|
||||||
<zxing.version>3.4.1-SNAPSHOT</zxing.version>
|
<zxing.version>3.4.1-SNAPSHOT</zxing.version>
|
||||||
|
@ -132,7 +133,7 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-enforcer-plugin</artifactId>
|
<artifactId>maven-enforcer-plugin</artifactId>
|
||||||
<version>3.0.0-M2</version>
|
<version>3.0.0-M3</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>enforce</id>
|
<id>enforce</id>
|
||||||
|
@ -142,7 +143,7 @@
|
||||||
<requireUpperBoundDeps />
|
<requireUpperBoundDeps />
|
||||||
<dependencyConvergence />
|
<dependencyConvergence />
|
||||||
<requireMavenVersion>
|
<requireMavenVersion>
|
||||||
<version>3.2.5</version>
|
<version>3.3.9</version>
|
||||||
</requireMavenVersion>
|
</requireMavenVersion>
|
||||||
<requireJavaVersion>
|
<requireJavaVersion>
|
||||||
<version>${java.version}</version>
|
<version>${java.version}</version>
|
||||||
|
@ -171,7 +172,7 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
<version>3.1.0</version>
|
<version>3.2.0</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>attach-sources</id>
|
<id>attach-sources</id>
|
||||||
|
@ -233,12 +234,12 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.1.2</version>
|
<version>3.2.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
<version>3.1.1</version>
|
<version>3.2.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
@ -325,7 +326,7 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>3.0.0-M3</version>
|
<version>3.0.0-M4</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<forkCount>0.5C</forkCount>
|
<forkCount>0.5C</forkCount>
|
||||||
<systemPropertyVariables>
|
<systemPropertyVariables>
|
||||||
|
@ -354,7 +355,7 @@
|
||||||
</executions>
|
</executions>
|
||||||
<configuration>
|
<configuration>
|
||||||
<sdk>
|
<sdk>
|
||||||
<path>${env.ANDROID_HOME}</path>
|
<path>${android.home}</path>
|
||||||
<platform>${android.platform}</platform>
|
<platform>${android.platform}</platform>
|
||||||
</sdk>
|
</sdk>
|
||||||
<artifactSet>
|
<artifactSet>
|
||||||
|
@ -463,7 +464,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.puppycrawl.tools</groupId>
|
<groupId>com.puppycrawl.tools</groupId>
|
||||||
<artifactId>checkstyle</artifactId>
|
<artifactId>checkstyle</artifactId>
|
||||||
<version>8.23</version>
|
<version>8.27</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
@ -526,7 +527,7 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.jacoco</groupId>
|
<groupId>org.jacoco</groupId>
|
||||||
<artifactId>jacoco-maven-plugin</artifactId>
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
<version>0.8.4</version>
|
<version>0.8.5</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
|
@ -729,7 +730,7 @@
|
||||||
<version>${android.platform}</version>
|
<version>${android.platform}</version>
|
||||||
<scope>system</scope>
|
<scope>system</scope>
|
||||||
<!-- ANDROID_HOME must be absolute, but redundant leading / may help Gradle Spring Boot plugin -->
|
<!-- ANDROID_HOME must be absolute, but redundant leading / may help Gradle Spring Boot plugin -->
|
||||||
<systemPath>/${env.ANDROID_HOME}/platforms/android-${android.platform}/android.jar</systemPath>
|
<systemPath>/${android.home}/platforms/android-${android.platform}/android.jar</systemPath>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
@ -764,7 +765,7 @@
|
||||||
<!-- repeat Android jar as library jar, as plugin ignores scope system deps -->
|
<!-- repeat Android jar as library jar, as plugin ignores scope system deps -->
|
||||||
<proguardOptions>
|
<proguardOptions>
|
||||||
<option>-libraryjars</option>
|
<option>-libraryjars</option>
|
||||||
<option>${env.ANDROID_HOME}/platforms/android-${android.platform}/android.jar</option>
|
<option>${android.home}/platforms/android-${android.platform}/android.jar</option>
|
||||||
</proguardOptions>
|
</proguardOptions>
|
||||||
<sign>
|
<sign>
|
||||||
<debug>false</debug>
|
<debug>false</debug>
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.guava</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
<version>27.1-android</version>
|
<version>28.1-android</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
|
@ -49,7 +49,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-test</artifactId>
|
<artifactId>spring-test</artifactId>
|
||||||
<version>5.1.8.RELEASE</version>
|
<version>5.2.2.RELEASE</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -23,6 +23,7 @@ import javax.servlet.ServletResponse;
|
||||||
import javax.servlet.annotation.WebFilter;
|
import javax.servlet.annotation.WebFilter;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redirects things to HTTPS, like the main decode page, which should prefer HTTPS.
|
* Redirects things to HTTPS, like the main decode page, which should prefer HTTPS.
|
||||||
|
@ -30,6 +31,8 @@ import java.io.IOException;
|
||||||
@WebFilter("/w/decode.jspx")
|
@WebFilter("/w/decode.jspx")
|
||||||
public final class HTTPSFilter extends AbstractFilter {
|
public final class HTTPSFilter extends AbstractFilter {
|
||||||
|
|
||||||
|
private static final Pattern HTTP_REGEX = Pattern.compile("http://");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doFilter(ServletRequest servletRequest,
|
public void doFilter(ServletRequest servletRequest,
|
||||||
ServletResponse servletResponse,
|
ServletResponse servletResponse,
|
||||||
|
@ -38,7 +41,8 @@ public final class HTTPSFilter extends AbstractFilter {
|
||||||
chain.doFilter(servletRequest, servletResponse);
|
chain.doFilter(servletRequest, servletResponse);
|
||||||
} else {
|
} else {
|
||||||
HttpServletRequest request = (HttpServletRequest) servletRequest;
|
HttpServletRequest request = (HttpServletRequest) servletRequest;
|
||||||
String target = request.getRequestURL().toString().replaceFirst("http://", "https://");
|
String url = request.getRequestURL().toString();
|
||||||
|
String target = HTTP_REGEX.matcher(url).replaceFirst("https://");
|
||||||
redirect(servletResponse, target);
|
redirect(servletResponse, target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue