mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Fix typos; avoid use of java.util.Date; other small improvements from inspection; deprecate some accidentally-public methods
This commit is contained in:
parent
64eb07747e
commit
0dfda08078
|
@ -67,7 +67,6 @@ import android.widget.Toast;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -557,7 +556,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
|
||||||
|
|
||||||
DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
||||||
TextView timeTextView = (TextView) findViewById(R.id.time_text_view);
|
TextView timeTextView = (TextView) findViewById(R.id.time_text_view);
|
||||||
timeTextView.setText(formatter.format(new Date(rawResult.getTimestamp())));
|
timeTextView.setText(formatter.format(rawResult.getTimestamp()));
|
||||||
|
|
||||||
|
|
||||||
TextView metaTextView = (TextView) findViewById(R.id.meta_text_view);
|
TextView metaTextView = (TextView) findViewById(R.id.meta_text_view);
|
||||||
|
|
|
@ -41,7 +41,6 @@ import java.io.OutputStreamWriter;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -299,8 +298,7 @@ public final class HistoryManager {
|
||||||
|
|
||||||
// Add timestamp again, formatted
|
// Add timestamp again, formatted
|
||||||
long timestamp = cursor.getLong(3);
|
long timestamp = cursor.getLong(3);
|
||||||
historyText.append('"').append(massageHistoryField(
|
historyText.append('"').append(massageHistoryField(format.format(timestamp))).append("\",");
|
||||||
format.format(new Date(timestamp)))).append("\",");
|
|
||||||
|
|
||||||
// Above we're preserving the old ordering of columns which had formatted data in position 5
|
// Above we're preserving the old ordering of columns which had formatted data in position 5
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,6 @@ import android.text.style.StyleSpan;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -151,15 +150,15 @@ public final class AddressBookResultHandler extends ResultHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Date parseDate(String s) {
|
private static long parseDate(String s) {
|
||||||
for (DateFormat currentFormat : DATE_FORMATS) {
|
for (DateFormat currentFormat : DATE_FORMATS) {
|
||||||
try {
|
try {
|
||||||
return currentFormat.parse(s);
|
return currentFormat.parse(s).getTime();
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
// continue
|
// continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return -1L;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overriden so we can hyphenate phone numbers, format birthdays, and bold the name.
|
// Overriden so we can hyphenate phone numbers, format birthdays, and bold the name.
|
||||||
|
@ -193,9 +192,9 @@ public final class AddressBookResultHandler extends ResultHandler {
|
||||||
|
|
||||||
String birthday = result.getBirthday();
|
String birthday = result.getBirthday();
|
||||||
if (birthday != null && !birthday.isEmpty()) {
|
if (birthday != null && !birthday.isEmpty()) {
|
||||||
Date date = parseDate(birthday);
|
long date = parseDate(birthday);
|
||||||
if (date != null) {
|
if (date >= 0L) {
|
||||||
ParsedResult.maybeAppend(DateFormat.getDateInstance(DateFormat.MEDIUM).format(date.getTime()), contents);
|
ParsedResult.maybeAppend(DateFormat.getDateInstance(DateFormat.MEDIUM).format(date), contents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ParsedResult.maybeAppend(result.getNote(), contents);
|
ParsedResult.maybeAppend(result.getNote(), contents);
|
||||||
|
|
|
@ -26,7 +26,6 @@ import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles calendar entries encoded in QR Codes.
|
* Handles calendar entries encoded in QR Codes.
|
||||||
|
@ -72,9 +71,9 @@ public final class CalendarResultHandler extends ResultHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
addCalendarEvent(calendarResult.getSummary(),
|
addCalendarEvent(calendarResult.getSummary(),
|
||||||
calendarResult.getStart(),
|
calendarResult.getStartTimestamp(),
|
||||||
calendarResult.isStartAllDay(),
|
calendarResult.isStartAllDay(),
|
||||||
calendarResult.getEnd(),
|
calendarResult.getEndTimestamp(),
|
||||||
calendarResult.getLocation(),
|
calendarResult.getLocation(),
|
||||||
description,
|
description,
|
||||||
calendarResult.getAttendees());
|
calendarResult.getAttendees());
|
||||||
|
@ -88,37 +87,33 @@ public final class CalendarResultHandler extends ResultHandler {
|
||||||
* @param summary A description of the event
|
* @param summary A description of the event
|
||||||
* @param start The start time
|
* @param start The start time
|
||||||
* @param allDay if true, event is considered to be all day starting from start time
|
* @param allDay if true, event is considered to be all day starting from start time
|
||||||
* @param end The end time (optional)
|
* @param end The end time (optional; can be < 0 if not specified)
|
||||||
* @param location a text description of the event location
|
* @param location a text description of the event location
|
||||||
* @param description a text description of the event itself
|
* @param description a text description of the event itself
|
||||||
* @param attendees attendees to invite
|
* @param attendees attendees to invite
|
||||||
*/
|
*/
|
||||||
private void addCalendarEvent(String summary,
|
private void addCalendarEvent(String summary,
|
||||||
Date start,
|
long start,
|
||||||
boolean allDay,
|
boolean allDay,
|
||||||
Date end,
|
long end,
|
||||||
String location,
|
String location,
|
||||||
String description,
|
String description,
|
||||||
String[] attendees) {
|
String[] attendees) {
|
||||||
Intent intent = new Intent(Intent.ACTION_INSERT);
|
Intent intent = new Intent(Intent.ACTION_INSERT);
|
||||||
intent.setType("vnd.android.cursor.item/event");
|
intent.setType("vnd.android.cursor.item/event");
|
||||||
long startMilliseconds = start.getTime();
|
intent.putExtra("beginTime", start);
|
||||||
intent.putExtra("beginTime", startMilliseconds);
|
|
||||||
if (allDay) {
|
if (allDay) {
|
||||||
intent.putExtra("allDay", true);
|
intent.putExtra("allDay", true);
|
||||||
}
|
}
|
||||||
long endMilliseconds;
|
if (end < 0L) {
|
||||||
if (end == null) {
|
|
||||||
if (allDay) {
|
if (allDay) {
|
||||||
// + 1 day
|
// + 1 day
|
||||||
endMilliseconds = startMilliseconds + 24 * 60 * 60 * 1000;
|
end = start + 24 * 60 * 60 * 1000;
|
||||||
} else {
|
} else {
|
||||||
endMilliseconds = startMilliseconds;
|
end = start;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
endMilliseconds = end.getTime();
|
|
||||||
}
|
}
|
||||||
intent.putExtra("endTime", endMilliseconds);
|
intent.putExtra("endTime", end);
|
||||||
intent.putExtra("title", summary);
|
intent.putExtra("title", summary);
|
||||||
intent.putExtra("eventLocation", location);
|
intent.putExtra("eventLocation", location);
|
||||||
intent.putExtra("description", description);
|
intent.putExtra("description", description);
|
||||||
|
@ -147,17 +142,17 @@ public final class CalendarResultHandler extends ResultHandler {
|
||||||
|
|
||||||
ParsedResult.maybeAppend(calResult.getSummary(), result);
|
ParsedResult.maybeAppend(calResult.getSummary(), result);
|
||||||
|
|
||||||
Date start = calResult.getStart();
|
long start = calResult.getStartTimestamp();
|
||||||
ParsedResult.maybeAppend(format(calResult.isStartAllDay(), start), result);
|
ParsedResult.maybeAppend(format(calResult.isStartAllDay(), start), result);
|
||||||
|
|
||||||
Date end = calResult.getEnd();
|
long end = calResult.getEndTimestamp();
|
||||||
if (end != null) {
|
if (end >= 0L) {
|
||||||
if (calResult.isEndAllDay() && !start.equals(end)) {
|
if (calResult.isEndAllDay() && start != end) {
|
||||||
// Show only year/month/day
|
// Show only year/month/day
|
||||||
// if it's all-day and this is the end date, it's exclusive, so show the user
|
// if it's all-day and this is the end date, it's exclusive, so show the user
|
||||||
// that it ends on the day before to make more intuitive sense.
|
// that it ends on the day before to make more intuitive sense.
|
||||||
// But don't do it if the event already (incorrectly?) specifies the same start/end
|
// But don't do it if the event already (incorrectly?) specifies the same start/end
|
||||||
end = new Date(end.getTime() - 24 * 60 * 60 * 1000);
|
end -= 24 * 60 * 60 * 1000;
|
||||||
}
|
}
|
||||||
ParsedResult.maybeAppend(format(calResult.isEndAllDay(), end), result);
|
ParsedResult.maybeAppend(format(calResult.isEndAllDay(), end), result);
|
||||||
}
|
}
|
||||||
|
@ -169,8 +164,8 @@ public final class CalendarResultHandler extends ResultHandler {
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String format(boolean allDay, Date date) {
|
private static String format(boolean allDay, long date) {
|
||||||
if (date == null) {
|
if (date < 0L) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
DateFormat format = allDay
|
DateFormat format = allDay
|
||||||
|
|
|
@ -133,7 +133,7 @@ public final class Decoder {
|
||||||
String str = getCharacter(shiftTable, code);
|
String str = getCharacter(shiftTable, code);
|
||||||
if (str.startsWith("CTRL_")) {
|
if (str.startsWith("CTRL_")) {
|
||||||
// Table changes
|
// Table changes
|
||||||
// ISO/IEC 24778:2008 prescibes ending a shift sequence in the mode from which it was invoked.
|
// ISO/IEC 24778:2008 prescribes ending a shift sequence in the mode from which it was invoked.
|
||||||
// That's including when that mode is a shift.
|
// That's including when that mode is a shift.
|
||||||
// Our test case dlusbs.png for issue #642 exercises that.
|
// Our test case dlusbs.png for issue #642 exercises that.
|
||||||
latchTable = shiftTable; // Latch the current mode, so as to return to Upper after U/S B/S
|
latchTable = shiftTable; // Latch the current mode, so as to return to Upper after U/S B/S
|
||||||
|
|
|
@ -48,9 +48,9 @@ public final class CalendarParsedResult extends ParsedResult {
|
||||||
private static final Pattern DATE_TIME = Pattern.compile("[0-9]{8}(T[0-9]{6}Z?)?");
|
private static final Pattern DATE_TIME = Pattern.compile("[0-9]{8}(T[0-9]{6}Z?)?");
|
||||||
|
|
||||||
private final String summary;
|
private final String summary;
|
||||||
private final Date start;
|
private final long start;
|
||||||
private final boolean startAllDay;
|
private final boolean startAllDay;
|
||||||
private final Date end;
|
private final long end;
|
||||||
private final boolean endAllDay;
|
private final boolean endAllDay;
|
||||||
private final String location;
|
private final String location;
|
||||||
private final String organizer;
|
private final String organizer;
|
||||||
|
@ -80,7 +80,7 @@ public final class CalendarParsedResult extends ParsedResult {
|
||||||
|
|
||||||
if (endString == null) {
|
if (endString == null) {
|
||||||
long durationMS = parseDurationMS(durationString);
|
long durationMS = parseDurationMS(durationString);
|
||||||
end = durationMS < 0L ? null : new Date(start.getTime() + durationMS);
|
end = durationMS < 0L ? -1L : start + durationMS;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
this.end = parseDate(endString);
|
this.end = parseDate(endString);
|
||||||
|
@ -106,8 +106,18 @@ public final class CalendarParsedResult extends ParsedResult {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return start time
|
* @return start time
|
||||||
|
* @deprecated use {@link #getStartTimestamp()}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public Date getStart() {
|
public Date getStart() {
|
||||||
|
return new Date(start);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return start time
|
||||||
|
* @see #getEndTimestamp()
|
||||||
|
*/
|
||||||
|
public long getStartTimestamp() {
|
||||||
return start;
|
return start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,9 +130,18 @@ public final class CalendarParsedResult extends ParsedResult {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return event end {@link Date}, or {@code null} if event has no duration
|
* @return event end {@link Date}, or {@code null} if event has no duration
|
||||||
* @see #getStart()
|
* @deprecated use {@link #getEndTimestamp()}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public Date getEnd() {
|
public Date getEnd() {
|
||||||
|
return end < 0L ? null : new Date(end);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return event end {@link Date}, or -1 if event has no duration
|
||||||
|
* @see #getStartTimestamp()
|
||||||
|
*/
|
||||||
|
public long getEndTimestamp() {
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,36 +196,35 @@ public final class CalendarParsedResult extends ParsedResult {
|
||||||
* @param when The string to parse
|
* @param when The string to parse
|
||||||
* @throws ParseException if not able to parse as a date
|
* @throws ParseException if not able to parse as a date
|
||||||
*/
|
*/
|
||||||
private static Date parseDate(String when) throws ParseException {
|
private static long parseDate(String when) throws ParseException {
|
||||||
if (!DATE_TIME.matcher(when).matches()) {
|
if (!DATE_TIME.matcher(when).matches()) {
|
||||||
throw new ParseException(when, 0);
|
throw new ParseException(when, 0);
|
||||||
}
|
}
|
||||||
if (when.length() == 8) {
|
if (when.length() == 8) {
|
||||||
// Show only year/month/day
|
// Show only year/month/day
|
||||||
return buildDateFormat().parse(when);
|
DateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.ENGLISH);
|
||||||
} else {
|
// For dates without a time, for purposes of interacting with Android, the resulting timestamp
|
||||||
// The when string can be local time, or UTC if it ends with a Z
|
// needs to be midnight of that day in GMT. See:
|
||||||
Date date;
|
// http://code.google.com/p/android/issues/detail?id=8330
|
||||||
if (when.length() == 16 && when.charAt(15) == 'Z') {
|
format.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||||
date = buildDateTimeFormat().parse(when.substring(0, 15));
|
return format.parse(when).getTime();
|
||||||
Calendar calendar = new GregorianCalendar();
|
|
||||||
long milliseconds = date.getTime();
|
|
||||||
// Account for time zone difference
|
|
||||||
milliseconds += calendar.get(Calendar.ZONE_OFFSET);
|
|
||||||
// Might need to correct for daylight savings time, but use target time since
|
|
||||||
// now might be in DST but not then, or vice versa
|
|
||||||
calendar.setTime(new Date(milliseconds));
|
|
||||||
milliseconds += calendar.get(Calendar.DST_OFFSET);
|
|
||||||
date = new Date(milliseconds);
|
|
||||||
} else {
|
|
||||||
date = buildDateTimeFormat().parse(when);
|
|
||||||
}
|
|
||||||
return date;
|
|
||||||
}
|
}
|
||||||
|
// The when string can be local time, or UTC if it ends with a Z
|
||||||
|
if (when.length() == 16 && when.charAt(15) == 'Z') {
|
||||||
|
long milliseconds = parseDateTimeString(when.substring(0, 15));
|
||||||
|
Calendar calendar = new GregorianCalendar();
|
||||||
|
// Account for time zone difference
|
||||||
|
milliseconds += calendar.get(Calendar.ZONE_OFFSET);
|
||||||
|
// Might need to correct for daylight savings time, but use target time since
|
||||||
|
// now might be in DST but not then, or vice versa
|
||||||
|
calendar.setTime(new Date(milliseconds));
|
||||||
|
return milliseconds + calendar.get(Calendar.DST_OFFSET);
|
||||||
|
}
|
||||||
|
return parseDateTimeString(when);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String format(boolean allDay, Date date) {
|
private static String format(boolean allDay, long date) {
|
||||||
if (date == null) {
|
if (date < 0L) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
DateFormat format = allDay
|
DateFormat format = allDay
|
||||||
|
@ -233,17 +251,9 @@ public final class CalendarParsedResult extends ParsedResult {
|
||||||
return durationMS;
|
return durationMS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DateFormat buildDateFormat() {
|
private static long parseDateTimeString(String dateTimeString) throws ParseException {
|
||||||
DateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.ENGLISH);
|
DateFormat format = new SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.ENGLISH);
|
||||||
// For dates without a time, for purposes of interacting with Android, the resulting timestamp
|
return format.parse(dateTimeString).getTime();
|
||||||
// needs to be midnight of that day in GMT. See:
|
|
||||||
// http://code.google.com/p/android/issues/detail?id=8330
|
|
||||||
format.setTimeZone(TimeZone.getTimeZone("GMT"));
|
|
||||||
return format;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static DateFormat buildDateTimeFormat() {
|
|
||||||
return new SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.ENGLISH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -404,7 +404,7 @@ final class BitMatrixParser {
|
||||||
int symbolSizeColumns = version.getSymbolSizeColumns();
|
int symbolSizeColumns = version.getSymbolSizeColumns();
|
||||||
|
|
||||||
if (bitMatrix.getHeight() != symbolSizeRows) {
|
if (bitMatrix.getHeight() != symbolSizeRows) {
|
||||||
throw new IllegalArgumentException("Dimension of bitMarix must match the version size");
|
throw new IllegalArgumentException("Dimension of bitMatrix must match the version size");
|
||||||
}
|
}
|
||||||
|
|
||||||
int dataRegionSizeRows = version.getDataRegionSizeRows();
|
int dataRegionSizeRows = version.getDataRegionSizeRows();
|
||||||
|
|
|
@ -156,7 +156,7 @@ public final class Detector {
|
||||||
BitMatrix bits;
|
BitMatrix bits;
|
||||||
ResultPoint correctedTopRight;
|
ResultPoint correctedTopRight;
|
||||||
|
|
||||||
// Rectanguar symbols are 6x16, 6x28, 10x24, 10x32, 14x32, or 14x44. If one dimension is more
|
// Rectangular symbols are 6x16, 6x28, 10x24, 10x32, 14x32, or 14x44. If one dimension is more
|
||||||
// than twice the other, it's certainly rectangular, but to cut a bit more slack we accept it as
|
// than twice the other, it's certainly rectangular, but to cut a bit more slack we accept it as
|
||||||
// rectangular if the bigger side is at least 7/4 times the other:
|
// rectangular if the bigger side is at least 7/4 times the other:
|
||||||
if (4 * dimensionTop >= 7 * dimensionRight || 4 * dimensionRight >= 7 * dimensionTop) {
|
if (4 * dimensionTop >= 7 * dimensionRight || 4 * dimensionRight >= 7 * dimensionTop) {
|
||||||
|
|
|
@ -52,17 +52,17 @@ public final class CodaBarReader extends OneDReader {
|
||||||
0x00c, 0x018, 0x045, 0x051, 0x054, 0x015, 0x01A, 0x029, 0x00B, 0x00E, // -$:/.+ABCD
|
0x00c, 0x018, 0x045, 0x051, 0x054, 0x015, 0x01A, 0x029, 0x00B, 0x00E, // -$:/.+ABCD
|
||||||
};
|
};
|
||||||
|
|
||||||
// minimal number of characters that should be present (inclusing start and stop characters)
|
// minimal number of characters that should be present (including start and stop characters)
|
||||||
// under normal circumstances this should be set to 3, but can be set higher
|
// under normal circumstances this should be set to 3, but can be set higher
|
||||||
// as a last-ditch attempt to reduce false positives.
|
// as a last-ditch attempt to reduce false positives.
|
||||||
private static final int MIN_CHARACTER_LENGTH = 3;
|
private static final int MIN_CHARACTER_LENGTH = 3;
|
||||||
|
|
||||||
// official start and end patterns
|
// official start and end patterns
|
||||||
private static final char[] STARTEND_ENCODING = {'A', 'B', 'C', 'D'};
|
private static final char[] STARTEND_ENCODING = {'A', 'B', 'C', 'D'};
|
||||||
// some codabar generator allow the codabar string to be closed by every
|
// some Codabar generator allow the Codabar string to be closed by every
|
||||||
// character. This will cause lots of false positives!
|
// character. This will cause lots of false positives!
|
||||||
|
|
||||||
// some industries use a checksum standard but this is not part of the original codabar standard
|
// some industries use a checksum standard but this is not part of the original Codabar standard
|
||||||
// for more information see : http://www.mecsw.com/specs/codabar.html
|
// for more information see : http://www.mecsw.com/specs/codabar.html
|
||||||
|
|
||||||
// Keep some instance variables to avoid reallocations
|
// Keep some instance variables to avoid reallocations
|
||||||
|
@ -238,7 +238,7 @@ public final class CodaBarReader extends OneDReader {
|
||||||
boolean isWhite = true;
|
boolean isWhite = true;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
while (i < end) {
|
while (i < end) {
|
||||||
if (row.get(i) ^ isWhite) { // that is, exactly one is true
|
if (row.get(i) != isWhite) {
|
||||||
count++;
|
count++;
|
||||||
} else {
|
} else {
|
||||||
counterAppend(count);
|
counterAppend(count);
|
||||||
|
|
|
@ -177,7 +177,7 @@ public final class Code128Reader extends OneDReader {
|
||||||
int patternLength = counters.length;
|
int patternLength = counters.length;
|
||||||
|
|
||||||
for (int i = rowOffset; i < width; i++) {
|
for (int i = rowOffset; i < width; i++) {
|
||||||
if (row.get(i) ^ isWhite) {
|
if (row.get(i) != isWhite) {
|
||||||
counters[counterPosition]++;
|
counters[counterPosition]++;
|
||||||
} else {
|
} else {
|
||||||
if (counterPosition == patternLength - 1) {
|
if (counterPosition == patternLength - 1) {
|
||||||
|
@ -197,9 +197,9 @@ public final class Code128Reader extends OneDReader {
|
||||||
return new int[]{patternStart, i, bestMatch};
|
return new int[]{patternStart, i, bestMatch};
|
||||||
}
|
}
|
||||||
patternStart += counters[0] + counters[1];
|
patternStart += counters[0] + counters[1];
|
||||||
System.arraycopy(counters, 2, counters, 0, patternLength - 2);
|
System.arraycopy(counters, 2, counters, 0, counterPosition - 1);
|
||||||
counters[patternLength - 2] = 0;
|
counters[counterPosition - 1] = 0;
|
||||||
counters[patternLength - 1] = 0;
|
counters[counterPosition] = 0;
|
||||||
counterPosition--;
|
counterPosition--;
|
||||||
} else {
|
} else {
|
||||||
counterPosition++;
|
counterPosition++;
|
||||||
|
|
|
@ -187,7 +187,7 @@ public final class Code39Reader extends OneDReader {
|
||||||
int patternLength = counters.length;
|
int patternLength = counters.length;
|
||||||
|
|
||||||
for (int i = rowOffset; i < width; i++) {
|
for (int i = rowOffset; i < width; i++) {
|
||||||
if (row.get(i) ^ isWhite) {
|
if (row.get(i) != isWhite) {
|
||||||
counters[counterPosition]++;
|
counters[counterPosition]++;
|
||||||
} else {
|
} else {
|
||||||
if (counterPosition == patternLength - 1) {
|
if (counterPosition == patternLength - 1) {
|
||||||
|
@ -197,9 +197,9 @@ public final class Code39Reader extends OneDReader {
|
||||||
return new int[]{patternStart, i};
|
return new int[]{patternStart, i};
|
||||||
}
|
}
|
||||||
patternStart += counters[0] + counters[1];
|
patternStart += counters[0] + counters[1];
|
||||||
System.arraycopy(counters, 2, counters, 0, patternLength - 2);
|
System.arraycopy(counters, 2, counters, 0, counterPosition - 1);
|
||||||
counters[patternLength - 2] = 0;
|
counters[counterPosition - 1] = 0;
|
||||||
counters[patternLength - 1] = 0;
|
counters[counterPosition] = 0;
|
||||||
counterPosition--;
|
counterPosition--;
|
||||||
} else {
|
} else {
|
||||||
counterPosition++;
|
counterPosition++;
|
||||||
|
|
|
@ -140,7 +140,7 @@ public final class Code93Reader extends OneDReader {
|
||||||
|
|
||||||
int counterPosition = 0;
|
int counterPosition = 0;
|
||||||
for (int i = rowOffset; i < width; i++) {
|
for (int i = rowOffset; i < width; i++) {
|
||||||
if (row.get(i) ^ isWhite) {
|
if (row.get(i) != isWhite) {
|
||||||
theCounters[counterPosition]++;
|
theCounters[counterPosition]++;
|
||||||
} else {
|
} else {
|
||||||
if (counterPosition == patternLength - 1) {
|
if (counterPosition == patternLength - 1) {
|
||||||
|
@ -148,9 +148,9 @@ public final class Code93Reader extends OneDReader {
|
||||||
return new int[]{patternStart, i};
|
return new int[]{patternStart, i};
|
||||||
}
|
}
|
||||||
patternStart += theCounters[0] + theCounters[1];
|
patternStart += theCounters[0] + theCounters[1];
|
||||||
System.arraycopy(theCounters, 2, theCounters, 0, patternLength - 2);
|
System.arraycopy(theCounters, 2, theCounters, 0, counterPosition - 1);
|
||||||
theCounters[patternLength - 2] = 0;
|
theCounters[counterPosition - 1] = 0;
|
||||||
theCounters[patternLength - 1] = 0;
|
theCounters[counterPosition] = 0;
|
||||||
counterPosition--;
|
counterPosition--;
|
||||||
} else {
|
} else {
|
||||||
counterPosition++;
|
counterPosition++;
|
||||||
|
|
|
@ -48,36 +48,36 @@ public class Code93Writer extends OneDimensionalCodeWriter {
|
||||||
//each character is encoded by 9 of 0/1's
|
//each character is encoded by 9 of 0/1's
|
||||||
int[] widths = new int[9];
|
int[] widths = new int[9];
|
||||||
|
|
||||||
//lenght of code + 2 start/stop characters + 2 checksums, each of 9 bits, plus a termination bar
|
//length of code + 2 start/stop characters + 2 checksums, each of 9 bits, plus a termination bar
|
||||||
int codeWidth = (contents.length() + 2 + 2) * 9 + 1;
|
int codeWidth = (contents.length() + 2 + 2) * 9 + 1;
|
||||||
|
|
||||||
boolean[] result = new boolean[codeWidth];
|
|
||||||
|
|
||||||
//start character (*)
|
//start character (*)
|
||||||
toIntArray(Code93Reader.CHARACTER_ENCODINGS[47], widths);
|
toIntArray(Code93Reader.CHARACTER_ENCODINGS[47], widths);
|
||||||
int pos = appendPattern(result, 0, widths, true);
|
|
||||||
|
boolean[] result = new boolean[codeWidth];
|
||||||
|
int pos = appendPattern(result, 0, widths);
|
||||||
|
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
int indexInString = Code93Reader.ALPHABET_STRING.indexOf(contents.charAt(i));
|
int indexInString = Code93Reader.ALPHABET_STRING.indexOf(contents.charAt(i));
|
||||||
toIntArray(Code93Reader.CHARACTER_ENCODINGS[indexInString], widths);
|
toIntArray(Code93Reader.CHARACTER_ENCODINGS[indexInString], widths);
|
||||||
pos += appendPattern(result, pos, widths, true);
|
pos += appendPattern(result, pos, widths);
|
||||||
}
|
}
|
||||||
|
|
||||||
//add two checksums
|
//add two checksums
|
||||||
int check1 = computeChecksumIndex(contents, 20);
|
int check1 = computeChecksumIndex(contents, 20);
|
||||||
toIntArray(Code93Reader.CHARACTER_ENCODINGS[check1], widths);
|
toIntArray(Code93Reader.CHARACTER_ENCODINGS[check1], widths);
|
||||||
pos += appendPattern(result, pos, widths, true);
|
pos += appendPattern(result, pos, widths);
|
||||||
|
|
||||||
//append the contents to reflect the first checksum added
|
//append the contents to reflect the first checksum added
|
||||||
contents += Code93Reader.ALPHABET_STRING.charAt(check1);
|
contents += Code93Reader.ALPHABET_STRING.charAt(check1);
|
||||||
|
|
||||||
int check2 = computeChecksumIndex(contents, 15);
|
int check2 = computeChecksumIndex(contents, 15);
|
||||||
toIntArray(Code93Reader.CHARACTER_ENCODINGS[check2], widths);
|
toIntArray(Code93Reader.CHARACTER_ENCODINGS[check2], widths);
|
||||||
pos += appendPattern(result, pos, widths, true);
|
pos += appendPattern(result, pos, widths);
|
||||||
|
|
||||||
//end character (*)
|
//end character (*)
|
||||||
toIntArray(Code93Reader.CHARACTER_ENCODINGS[47], widths);
|
toIntArray(Code93Reader.CHARACTER_ENCODINGS[47], widths);
|
||||||
pos += appendPattern(result, pos, widths, true);
|
pos += appendPattern(result, pos, widths);
|
||||||
|
|
||||||
//termination bar (single black bar)
|
//termination bar (single black bar)
|
||||||
result[pos] = true;
|
result[pos] = true;
|
||||||
|
@ -92,7 +92,20 @@ public class Code93Writer extends OneDimensionalCodeWriter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param target output to append to
|
||||||
|
* @param pos start position
|
||||||
|
* @param pattern pattern to append
|
||||||
|
* @param startColor unused
|
||||||
|
* @return 9
|
||||||
|
* @deprecated without replacement; intended as an internal-only method
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
protected static int appendPattern(boolean[] target, int pos, int[] pattern, boolean startColor) {
|
protected static int appendPattern(boolean[] target, int pos, int[] pattern, boolean startColor) {
|
||||||
|
return appendPattern(target, pos, pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int appendPattern(boolean[] target, int pos, int[] pattern) {
|
||||||
for (int bit : pattern) {
|
for (int bit : pattern) {
|
||||||
target[pos++] = bit != 0;
|
target[pos++] = bit != 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -300,7 +300,7 @@ public final class ITFReader extends OneDReader {
|
||||||
int counterPosition = 0;
|
int counterPosition = 0;
|
||||||
int patternStart = rowOffset;
|
int patternStart = rowOffset;
|
||||||
for (int x = rowOffset; x < width; x++) {
|
for (int x = rowOffset; x < width; x++) {
|
||||||
if (row.get(x) ^ isWhite) {
|
if (row.get(x) != isWhite) {
|
||||||
counters[counterPosition]++;
|
counters[counterPosition]++;
|
||||||
} else {
|
} else {
|
||||||
if (counterPosition == patternLength - 1) {
|
if (counterPosition == patternLength - 1) {
|
||||||
|
@ -308,9 +308,9 @@ public final class ITFReader extends OneDReader {
|
||||||
return new int[]{patternStart, x};
|
return new int[]{patternStart, x};
|
||||||
}
|
}
|
||||||
patternStart += counters[0] + counters[1];
|
patternStart += counters[0] + counters[1];
|
||||||
System.arraycopy(counters, 2, counters, 0, patternLength - 2);
|
System.arraycopy(counters, 2, counters, 0, counterPosition - 1);
|
||||||
counters[patternLength - 2] = 0;
|
counters[counterPosition - 1] = 0;
|
||||||
counters[patternLength - 1] = 0;
|
counters[counterPosition] = 0;
|
||||||
counterPosition--;
|
counterPosition--;
|
||||||
} else {
|
} else {
|
||||||
counterPosition++;
|
counterPosition++;
|
||||||
|
|
|
@ -106,7 +106,6 @@ public abstract class OneDReader implements Reader {
|
||||||
int height = image.getHeight();
|
int height = image.getHeight();
|
||||||
BitArray row = new BitArray(width);
|
BitArray row = new BitArray(width);
|
||||||
|
|
||||||
int middle = height >> 1;
|
|
||||||
boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);
|
boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);
|
||||||
int rowStep = Math.max(1, height >> (tryHarder ? 8 : 5));
|
int rowStep = Math.max(1, height >> (tryHarder ? 8 : 5));
|
||||||
int maxLines;
|
int maxLines;
|
||||||
|
@ -116,6 +115,7 @@ public abstract class OneDReader implements Reader {
|
||||||
maxLines = 15; // 15 rows spaced 1/32 apart is roughly the middle half of the image
|
maxLines = 15; // 15 rows spaced 1/32 apart is roughly the middle half of the image
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int middle = height / 2;
|
||||||
for (int x = 0; x < maxLines; x++) {
|
for (int x = 0; x < maxLines; x++) {
|
||||||
|
|
||||||
// Scanning from the middle out. Determine which row we're looking at next:
|
// Scanning from the middle out. Determine which row we're looking at next:
|
||||||
|
@ -200,11 +200,10 @@ public abstract class OneDReader implements Reader {
|
||||||
int counterPosition = 0;
|
int counterPosition = 0;
|
||||||
int i = start;
|
int i = start;
|
||||||
while (i < end) {
|
while (i < end) {
|
||||||
if (row.get(i) ^ isWhite) { // that is, exactly one is true
|
if (row.get(i) != isWhite) {
|
||||||
counters[counterPosition]++;
|
counters[counterPosition]++;
|
||||||
} else {
|
} else {
|
||||||
counterPosition++;
|
if (++counterPosition == numCounters) {
|
||||||
if (counterPosition == numCounters) {
|
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
counters[counterPosition] = 1;
|
counters[counterPosition] = 1;
|
||||||
|
|
|
@ -324,7 +324,7 @@ public abstract class UPCEANReader extends OneDReader {
|
||||||
int patternLength = pattern.length;
|
int patternLength = pattern.length;
|
||||||
boolean isWhite = whiteFirst;
|
boolean isWhite = whiteFirst;
|
||||||
for (int x = rowOffset; x < width; x++) {
|
for (int x = rowOffset; x < width; x++) {
|
||||||
if (row.get(x) ^ isWhite) {
|
if (row.get(x) != isWhite) {
|
||||||
counters[counterPosition]++;
|
counters[counterPosition]++;
|
||||||
} else {
|
} else {
|
||||||
if (counterPosition == patternLength - 1) {
|
if (counterPosition == patternLength - 1) {
|
||||||
|
@ -332,9 +332,9 @@ public abstract class UPCEANReader extends OneDReader {
|
||||||
return new int[]{patternStart, x};
|
return new int[]{patternStart, x};
|
||||||
}
|
}
|
||||||
patternStart += counters[0] + counters[1];
|
patternStart += counters[0] + counters[1];
|
||||||
System.arraycopy(counters, 2, counters, 0, patternLength - 2);
|
System.arraycopy(counters, 2, counters, 0, counterPosition - 1);
|
||||||
counters[patternLength - 2] = 0;
|
counters[counterPosition - 1] = 0;
|
||||||
counters[patternLength - 1] = 0;
|
counters[counterPosition] = 0;
|
||||||
counterPosition--;
|
counterPosition--;
|
||||||
} else {
|
} else {
|
||||||
counterPosition++;
|
counterPosition++;
|
||||||
|
|
|
@ -133,7 +133,7 @@ public final class RSS14Reader extends AbstractRSSReader {
|
||||||
ResultPoint[] leftPoints = leftPair.getFinderPattern().getResultPoints();
|
ResultPoint[] leftPoints = leftPair.getFinderPattern().getResultPoints();
|
||||||
ResultPoint[] rightPoints = rightPair.getFinderPattern().getResultPoints();
|
ResultPoint[] rightPoints = rightPair.getFinderPattern().getResultPoints();
|
||||||
return new Result(
|
return new Result(
|
||||||
String.valueOf(buffer.toString()),
|
buffer.toString(),
|
||||||
null,
|
null,
|
||||||
new ResultPoint[] { leftPoints[0], leftPoints[1], rightPoints[0], rightPoints[1], },
|
new ResultPoint[] { leftPoints[0], leftPoints[1], rightPoints[0], rightPoints[1], },
|
||||||
BarcodeFormat.RSS_14);
|
BarcodeFormat.RSS_14);
|
||||||
|
@ -159,7 +159,7 @@ public final class RSS14Reader extends AbstractRSSReader {
|
||||||
|
|
||||||
private Pair decodePair(BitArray row, boolean right, int rowNumber, Map<DecodeHintType,?> hints) {
|
private Pair decodePair(BitArray row, boolean right, int rowNumber, Map<DecodeHintType,?> hints) {
|
||||||
try {
|
try {
|
||||||
int[] startEnd = findFinderPattern(row, 0, right);
|
int[] startEnd = findFinderPattern(row, right);
|
||||||
FinderPattern pattern = parseFoundFinderPattern(row, rowNumber, right, startEnd);
|
FinderPattern pattern = parseFoundFinderPattern(row, rowNumber, right, startEnd);
|
||||||
|
|
||||||
ResultPointCallback resultPointCallback = hints == null ? null :
|
ResultPointCallback resultPointCallback = hints == null ? null :
|
||||||
|
@ -281,7 +281,7 @@ public final class RSS14Reader extends AbstractRSSReader {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int[] findFinderPattern(BitArray row, int rowOffset, boolean rightFinderPattern)
|
private int[] findFinderPattern(BitArray row, boolean rightFinderPattern)
|
||||||
throws NotFoundException {
|
throws NotFoundException {
|
||||||
|
|
||||||
int[] counters = getDecodeFinderCounters();
|
int[] counters = getDecodeFinderCounters();
|
||||||
|
@ -292,6 +292,7 @@ public final class RSS14Reader extends AbstractRSSReader {
|
||||||
|
|
||||||
int width = row.getSize();
|
int width = row.getSize();
|
||||||
boolean isWhite = false;
|
boolean isWhite = false;
|
||||||
|
int rowOffset = 0;
|
||||||
while (rowOffset < width) {
|
while (rowOffset < width) {
|
||||||
isWhite = !row.get(rowOffset);
|
isWhite = !row.get(rowOffset);
|
||||||
if (rightFinderPattern == isWhite) {
|
if (rightFinderPattern == isWhite) {
|
||||||
|
@ -304,7 +305,7 @@ public final class RSS14Reader extends AbstractRSSReader {
|
||||||
int counterPosition = 0;
|
int counterPosition = 0;
|
||||||
int patternStart = rowOffset;
|
int patternStart = rowOffset;
|
||||||
for (int x = rowOffset; x < width; x++) {
|
for (int x = rowOffset; x < width; x++) {
|
||||||
if (row.get(x) ^ isWhite) {
|
if (row.get(x) != isWhite) {
|
||||||
counters[counterPosition]++;
|
counters[counterPosition]++;
|
||||||
} else {
|
} else {
|
||||||
if (counterPosition == 3) {
|
if (counterPosition == 3) {
|
||||||
|
@ -334,7 +335,7 @@ public final class RSS14Reader extends AbstractRSSReader {
|
||||||
boolean firstIsBlack = row.get(startEnd[0]);
|
boolean firstIsBlack = row.get(startEnd[0]);
|
||||||
int firstElementStart = startEnd[0] - 1;
|
int firstElementStart = startEnd[0] - 1;
|
||||||
// Locate element 1
|
// Locate element 1
|
||||||
while (firstElementStart >= 0 && firstIsBlack ^ row.get(firstElementStart)) {
|
while (firstElementStart >= 0 && firstIsBlack != row.get(firstElementStart)) {
|
||||||
firstElementStart--;
|
firstElementStart--;
|
||||||
}
|
}
|
||||||
firstElementStart++;
|
firstElementStart++;
|
||||||
|
|
|
@ -491,7 +491,7 @@ public final class RSSExpandedReader extends AbstractRSSReader {
|
||||||
int counterPosition = 0;
|
int counterPosition = 0;
|
||||||
int patternStart = rowOffset;
|
int patternStart = rowOffset;
|
||||||
for (int x = rowOffset; x < width; x++) {
|
for (int x = rowOffset; x < width; x++) {
|
||||||
if (row.get(x) ^ isWhite) {
|
if (row.get(x) != isWhite) {
|
||||||
counters[counterPosition]++;
|
counters[counterPosition]++;
|
||||||
} else {
|
} else {
|
||||||
if (counterPosition == 3) {
|
if (counterPosition == 3) {
|
||||||
|
|
|
@ -109,7 +109,7 @@ public final class PDF417Writer implements Writer {
|
||||||
int aspectRatio = 4;
|
int aspectRatio = 4;
|
||||||
byte[][] originalScale = encoder.getBarcodeMatrix().getScaledMatrix(1, aspectRatio);
|
byte[][] originalScale = encoder.getBarcodeMatrix().getScaledMatrix(1, aspectRatio);
|
||||||
boolean rotated = false;
|
boolean rotated = false;
|
||||||
if ((height > width) ^ (originalScale[0].length < originalScale.length)) {
|
if ((height > width) != (originalScale[0].length < originalScale.length)) {
|
||||||
originalScale = rotateArray(originalScale);
|
originalScale = rotateArray(originalScale);
|
||||||
rotated = true;
|
rotated = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ final class BarcodeValue {
|
||||||
return PDF417Common.toIntArray(result);
|
return PDF417Common.toIntArray(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getConfidence(int value) {
|
Integer getConfidence(int value) {
|
||||||
return values.get(value);
|
return values.get(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -249,7 +249,7 @@ final class DetectionResult {
|
||||||
return barcodeMetadata.getErrorCorrectionLevel();
|
return barcodeMetadata.getErrorCorrectionLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBoundingBox(BoundingBox boundingBox) {
|
void setBoundingBox(BoundingBox boundingBox) {
|
||||||
this.boundingBox = boundingBox;
|
this.boundingBox = boundingBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -234,9 +234,7 @@ public final class Detector {
|
||||||
result[3] = new ResultPoint(previousRowLoc[1], stopRow);
|
result[3] = new ResultPoint(previousRowLoc[1], stopRow);
|
||||||
}
|
}
|
||||||
if (stopRow - startRow < BARCODE_MIN_HEIGHT) {
|
if (stopRow - startRow < BARCODE_MIN_HEIGHT) {
|
||||||
for (int i = 0; i < result.length; i++) {
|
Arrays.fill(result, null);
|
||||||
result[i] = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -271,7 +269,7 @@ public final class Detector {
|
||||||
int patternLength = pattern.length;
|
int patternLength = pattern.length;
|
||||||
for (boolean isWhite = whiteFirst; x < width; x++) {
|
for (boolean isWhite = whiteFirst; x < width; x++) {
|
||||||
boolean pixel = matrix.get(x, row);
|
boolean pixel = matrix.get(x, row);
|
||||||
if (pixel ^ isWhite) {
|
if (pixel != isWhite) {
|
||||||
counters[counterPosition]++;
|
counters[counterPosition]++;
|
||||||
} else {
|
} else {
|
||||||
if (counterPosition == patternLength - 1) {
|
if (counterPosition == patternLength - 1) {
|
||||||
|
@ -279,9 +277,9 @@ public final class Detector {
|
||||||
return new int[] {patternStart, x};
|
return new int[] {patternStart, x};
|
||||||
}
|
}
|
||||||
patternStart += counters[0] + counters[1];
|
patternStart += counters[0] + counters[1];
|
||||||
System.arraycopy(counters, 2, counters, 0, patternLength - 2);
|
System.arraycopy(counters, 2, counters, 0, counterPosition - 1);
|
||||||
counters[patternLength - 2] = 0;
|
counters[counterPosition - 1] = 0;
|
||||||
counters[patternLength - 1] = 0;
|
counters[counterPosition] = 0;
|
||||||
counterPosition--;
|
counterPosition--;
|
||||||
} else {
|
} else {
|
||||||
counterPosition++;
|
counterPosition++;
|
||||||
|
@ -290,10 +288,9 @@ public final class Detector {
|
||||||
isWhite = !isWhite;
|
isWhite = !isWhite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (counterPosition == patternLength - 1) {
|
if (counterPosition == patternLength - 1 &&
|
||||||
if (patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE) {
|
patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE) {
|
||||||
return new int[] {patternStart, x - 1};
|
return new int[] {patternStart, x - 1};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
package com.google.zxing.pdf417.encoder;
|
package com.google.zxing.pdf417.encoder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds all of the information for a barcode in a format where it can be easily accessable
|
* Holds all of the information for a barcode in a format where it can be easily accessible
|
||||||
*
|
*
|
||||||
* @author Jacob Haynes
|
* @author Jacob Haynes
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -653,7 +653,7 @@ public class FinderPatternFinder {
|
||||||
public int compare(FinderPattern center1, FinderPattern center2) {
|
public int compare(FinderPattern center1, FinderPattern center2) {
|
||||||
float dA = Math.abs(center2.getEstimatedModuleSize() - average);
|
float dA = Math.abs(center2.getEstimatedModuleSize() - average);
|
||||||
float dB = Math.abs(center1.getEstimatedModuleSize() - average);
|
float dB = Math.abs(center1.getEstimatedModuleSize() - average);
|
||||||
return dA < dB ? -1 : dA == dB ? 0 : 1;
|
return dA < dB ? -1 : dA > dB ? 1 : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -670,7 +670,7 @@ public class FinderPatternFinder {
|
||||||
if (center2.getCount() == center1.getCount()) {
|
if (center2.getCount() == center1.getCount()) {
|
||||||
float dA = Math.abs(center2.getEstimatedModuleSize() - average);
|
float dA = Math.abs(center2.getEstimatedModuleSize() - average);
|
||||||
float dB = Math.abs(center1.getEstimatedModuleSize() - average);
|
float dB = Math.abs(center1.getEstimatedModuleSize() - average);
|
||||||
return dA < dB ? 1 : dA == dB ? 0 : -1;
|
return dA < dB ? 1 : dA > dB ? -1 : 0;
|
||||||
} else {
|
} else {
|
||||||
return center2.getCount() - center1.getCount();
|
return center2.getCount() - center1.getCount();
|
||||||
}
|
}
|
||||||
|
|
|
@ -298,7 +298,7 @@ final class MatrixUtil {
|
||||||
// The return value is 0xc94 (1100 1001 0100)
|
// The return value is 0xc94 (1100 1001 0100)
|
||||||
//
|
//
|
||||||
// Since all coefficients in the polynomials are 1 or 0, we can do the calculation by bit
|
// Since all coefficients in the polynomials are 1 or 0, we can do the calculation by bit
|
||||||
// operations. We don't care if cofficients are positive or negative.
|
// operations. We don't care if coefficients are positive or negative.
|
||||||
static int calculateBCHCode(int value, int poly) {
|
static int calculateBCHCode(int value, int poly) {
|
||||||
if (poly == 0) {
|
if (poly == 0) {
|
||||||
throw new IllegalArgumentException("0 polynomial");
|
throw new IllegalArgumentException("0 polynomial");
|
||||||
|
@ -459,19 +459,15 @@ final class MatrixUtil {
|
||||||
}
|
}
|
||||||
int index = version.getVersionNumber() - 1;
|
int index = version.getVersionNumber() - 1;
|
||||||
int[] coordinates = POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[index];
|
int[] coordinates = POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[index];
|
||||||
int numCoordinates = POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[index].length;
|
for (int y : coordinates) {
|
||||||
for (int i = 0; i < numCoordinates; ++i) {
|
if (y >= 0) {
|
||||||
for (int j = 0; j < numCoordinates; ++j) {
|
for (int x : coordinates) {
|
||||||
int y = coordinates[i];
|
if (x >= 0 && isEmpty(matrix.get(x, y))) {
|
||||||
int x = coordinates[j];
|
// If the cell is unset, we embed the position adjustment pattern here.
|
||||||
if (x == -1 || y == -1) {
|
// -2 is necessary since the x/y coordinates point to the center of the pattern, not the
|
||||||
continue;
|
// left top corner.
|
||||||
}
|
embedPositionAdjustmentPattern(x - 2, y - 2, matrix);
|
||||||
// If the cell is unset, we embed the position adjustment pattern here.
|
}
|
||||||
if (isEmpty(matrix.get(x, y))) {
|
|
||||||
// -2 is necessary since the x/y coordinates point to the center of the pattern, not the
|
|
||||||
// left top corner.
|
|
||||||
embedPositionAdjustmentPattern(x - 2, y - 2, matrix);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,8 +231,8 @@ public final class CalendarParsedResultTestCase extends Assert {
|
||||||
assertEquals(summary, calResult.getSummary());
|
assertEquals(summary, calResult.getSummary());
|
||||||
assertEquals(location, calResult.getLocation());
|
assertEquals(location, calResult.getLocation());
|
||||||
DateFormat dateFormat = makeGMTFormat();
|
DateFormat dateFormat = makeGMTFormat();
|
||||||
assertEquals(startString, dateFormat.format(calResult.getStart()));
|
assertEquals(startString, dateFormat.format(calResult.getStartTimestamp()));
|
||||||
assertEquals(endString, calResult.getEnd() == null ? null : dateFormat.format(calResult.getEnd()));
|
assertEquals(endString, calResult.getEndTimestamp() < 0L ? null : dateFormat.format(calResult.getEndTimestamp()));
|
||||||
assertEquals(organizer, calResult.getOrganizer());
|
assertEquals(organizer, calResult.getOrganizer());
|
||||||
assertArrayEquals(attendees, calResult.getAttendees());
|
assertArrayEquals(attendees, calResult.getAttendees());
|
||||||
assertEqualOrNaN(latitude, calResult.getLatitude());
|
assertEqualOrNaN(latitude, calResult.getLatitude());
|
||||||
|
|
|
@ -141,7 +141,7 @@ public abstract class AbstractBlackBoxTestCase extends Assert {
|
||||||
int[] passedCounts = new int[testCount];
|
int[] passedCounts = new int[testCount];
|
||||||
int[] misreadCounts = new int[testCount];
|
int[] misreadCounts = new int[testCount];
|
||||||
int[] tryHarderCounts = new int[testCount];
|
int[] tryHarderCounts = new int[testCount];
|
||||||
int[] tryHaderMisreadCounts = new int[testCount];
|
int[] tryHarderMisreadCounts = new int[testCount];
|
||||||
|
|
||||||
for (Path testImage : imageFiles) {
|
for (Path testImage : imageFiles) {
|
||||||
log.info(String.format("Starting %s", testImage));
|
log.info(String.format("Starting %s", testImage));
|
||||||
|
@ -186,7 +186,7 @@ public abstract class AbstractBlackBoxTestCase extends Assert {
|
||||||
if (decode(bitmap, rotation, expectedText, expectedMetadata, true)) {
|
if (decode(bitmap, rotation, expectedText, expectedMetadata, true)) {
|
||||||
tryHarderCounts[x]++;
|
tryHarderCounts[x]++;
|
||||||
} else {
|
} else {
|
||||||
tryHaderMisreadCounts[x]++;
|
tryHarderMisreadCounts[x]++;
|
||||||
}
|
}
|
||||||
} catch (ReaderException ignored) {
|
} catch (ReaderException ignored) {
|
||||||
log.fine(String.format("could not read at rotation %f w/TH", rotation));
|
log.fine(String.format("could not read at rotation %f w/TH", rotation));
|
||||||
|
@ -212,10 +212,10 @@ public abstract class AbstractBlackBoxTestCase extends Assert {
|
||||||
tryHarderCounts[x], imageFiles.size(), testResult.getTryHarderCount()));
|
tryHarderCounts[x], imageFiles.size(), testResult.getTryHarderCount()));
|
||||||
failed = imageFiles.size() - tryHarderCounts[x];
|
failed = imageFiles.size() - tryHarderCounts[x];
|
||||||
log.info(String.format(" %d failed due to misreads, %d not detected",
|
log.info(String.format(" %d failed due to misreads, %d not detected",
|
||||||
tryHaderMisreadCounts[x], failed - tryHaderMisreadCounts[x]));
|
tryHarderMisreadCounts[x], failed - tryHarderMisreadCounts[x]));
|
||||||
totalFound += passedCounts[x] + tryHarderCounts[x];
|
totalFound += passedCounts[x] + tryHarderCounts[x];
|
||||||
totalMustPass += testResult.getMustPassCount() + testResult.getTryHarderCount();
|
totalMustPass += testResult.getMustPassCount() + testResult.getTryHarderCount();
|
||||||
totalMisread += misreadCounts[x] + tryHaderMisreadCounts[x];
|
totalMisread += misreadCounts[x] + tryHarderMisreadCounts[x];
|
||||||
totalMaxMisread += testResult.getMaxMisreads() + testResult.getMaxTryHarderMisreads();
|
totalMaxMisread += testResult.getMaxMisreads() + testResult.getMaxTryHarderMisreads();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,7 +247,7 @@ public abstract class AbstractBlackBoxTestCase extends Assert {
|
||||||
assertTrue(label,
|
assertTrue(label,
|
||||||
misreadCounts[x] <= testResult.getMaxMisreads());
|
misreadCounts[x] <= testResult.getMaxMisreads());
|
||||||
assertTrue("Try harder, " + label,
|
assertTrue("Try harder, " + label,
|
||||||
tryHaderMisreadCounts[x] <= testResult.getMaxTryHarderMisreads());
|
tryHarderMisreadCounts[x] <= testResult.getMaxTryHarderMisreads());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,7 +126,7 @@ public abstract class AbstractNegativeBlackBoxTestCase extends AbstractBlackBoxT
|
||||||
*
|
*
|
||||||
* @param image The image to test
|
* @param image The image to test
|
||||||
* @param rotationInDegrees The amount of rotation to apply
|
* @param rotationInDegrees The amount of rotation to apply
|
||||||
* @return true if nothing found, false if a non-existant barcode was detected
|
* @return true if nothing found, false if a non-existent barcode was detected
|
||||||
*/
|
*/
|
||||||
private boolean checkForFalsePositives(BufferedImage image, float rotationInDegrees) {
|
private boolean checkForFalsePositives(BufferedImage image, float rotationInDegrees) {
|
||||||
BufferedImage rotatedImage = rotateImage(image, rotationInDegrees);
|
BufferedImage rotatedImage = rotateImage(image, rotationInDegrees);
|
||||||
|
|
4
pom.xml
4
pom.xml
|
@ -250,7 +250,7 @@
|
||||||
<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>2.6</version>
|
<version>3.0.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
@ -428,7 +428,7 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-site-plugin</artifactId>
|
<artifactId>maven-site-plugin</artifactId>
|
||||||
<version>3.5.1</version>
|
<version>3.6</version>
|
||||||
<inherited>false</inherited>
|
<inherited>false</inherited>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.eclipse.jetty</groupId>
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
<artifactId>jetty-maven-plugin</artifactId>
|
<artifactId>jetty-maven-plugin</artifactId>
|
||||||
<version>9.4.0.RC1</version>
|
<version>9.4.0.RC2</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
Loading…
Reference in a new issue