--possibleFormats arg added to command line

git-svn-id: https://zxing.googlecode.com/svn/trunk@2638 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen@gmail.com 2013-04-08 14:10:36 +00:00
parent ae6e2e0bd3
commit f4866452a4
3 changed files with 46 additions and 19 deletions

View file

@ -38,6 +38,7 @@ evansepdx
Erik Barbara Erik Barbara
Fred Lin (Anobiit) Fred Lin (Anobiit)
gcstang gcstang
Guenther Grau
Guillaume Le Biller Guillaume Le Biller
Hannes Erven Hannes Erven
Hartmut Neubauer (Schweers Informationstechnologie GmbH) Hartmut Neubauer (Schweers Informationstechnologie GmbH)

View file

@ -43,6 +43,7 @@ import java.util.regex.Pattern;
*/ */
public final class CommandLineRunner { public final class CommandLineRunner {
private static final String POSSIBLE_FORMATS_ARG = "--possibleFormats=";
private static final Pattern COMMA = Pattern.compile(","); private static final Pattern COMMA = Pattern.compile(",");
private CommandLineRunner() { private CommandLineRunner() {
@ -80,6 +81,8 @@ public final class CommandLineRunner {
crop[i] = Integer.parseInt(tokens[i]); crop[i] = Integer.parseInt(tokens[i]);
} }
config.setCrop(crop); config.setCrop(crop);
} else if (arg.startsWith(POSSIBLE_FORMATS_ARG)) {
config.setPossibleFormats(COMMA.split(arg.substring(POSSIBLE_FORMATS_ARG.length())));
} else if (arg.startsWith("-")) { } else if (arg.startsWith("-")) {
System.err.println("Unknown command line option " + arg); System.err.println("Unknown command line option " + arg);
printUsage(); printUsage();
@ -153,27 +156,34 @@ public final class CommandLineRunner {
// Manually turn on all formats, even those not yet considered production quality. // Manually turn on all formats, even those not yet considered production quality.
private static Map<DecodeHintType,?> buildHints(Config config) { private static Map<DecodeHintType,?> buildHints(Config config) {
Collection<BarcodeFormat> vector = new ArrayList<BarcodeFormat>(8); Collection<BarcodeFormat> possibleFormats = new ArrayList<BarcodeFormat>();
vector.add(BarcodeFormat.UPC_A); String[] possibleFormatsNames = config.getPossibleFormats();
vector.add(BarcodeFormat.UPC_E); if (possibleFormatsNames != null && possibleFormatsNames.length > 0) {
vector.add(BarcodeFormat.EAN_13); for (String format : possibleFormatsNames) {
vector.add(BarcodeFormat.EAN_8); possibleFormats.add(BarcodeFormat.valueOf(format));
vector.add(BarcodeFormat.RSS_14); }
vector.add(BarcodeFormat.RSS_EXPANDED); } else {
possibleFormats.add(BarcodeFormat.UPC_A);
possibleFormats.add(BarcodeFormat.UPC_E);
possibleFormats.add(BarcodeFormat.EAN_13);
possibleFormats.add(BarcodeFormat.EAN_8);
possibleFormats.add(BarcodeFormat.RSS_14);
possibleFormats.add(BarcodeFormat.RSS_EXPANDED);
if (!config.isProductsOnly()) { if (!config.isProductsOnly()) {
vector.add(BarcodeFormat.CODE_39); possibleFormats.add(BarcodeFormat.CODE_39);
vector.add(BarcodeFormat.CODE_93); possibleFormats.add(BarcodeFormat.CODE_93);
vector.add(BarcodeFormat.CODE_128); possibleFormats.add(BarcodeFormat.CODE_128);
vector.add(BarcodeFormat.ITF); possibleFormats.add(BarcodeFormat.ITF);
vector.add(BarcodeFormat.QR_CODE); possibleFormats.add(BarcodeFormat.QR_CODE);
vector.add(BarcodeFormat.DATA_MATRIX); possibleFormats.add(BarcodeFormat.DATA_MATRIX);
vector.add(BarcodeFormat.AZTEC); possibleFormats.add(BarcodeFormat.AZTEC);
vector.add(BarcodeFormat.PDF_417); possibleFormats.add(BarcodeFormat.PDF_417);
vector.add(BarcodeFormat.CODABAR); possibleFormats.add(BarcodeFormat.CODABAR);
vector.add(BarcodeFormat.MAXICODE); possibleFormats.add(BarcodeFormat.MAXICODE);
}
} }
Map<DecodeHintType, Object> hints = new EnumMap<DecodeHintType, Object>(DecodeHintType.class); Map<DecodeHintType, Object> hints = new EnumMap<DecodeHintType, Object>(DecodeHintType.class);
hints.put(DecodeHintType.POSSIBLE_FORMATS, vector); hints.put(DecodeHintType.POSSIBLE_FORMATS, possibleFormats);
if (config.isTryHarder()) { if (config.isTryHarder()) {
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE); hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
} }
@ -196,6 +206,13 @@ public final class CommandLineRunner {
System.err.println(" --brief: Only output one line per file, omitting the contents"); System.err.println(" --brief: Only output one line per file, omitting the contents");
System.err.println(" --recursive: Descend into subdirectories"); System.err.println(" --recursive: Descend into subdirectories");
System.err.println(" --crop=left,top,width,height: Only examine cropped region of input image(s)"); System.err.println(" --crop=left,top,width,height: Only examine cropped region of input image(s)");
StringBuilder builder = new StringBuilder(
" " + POSSIBLE_FORMATS_ARG + "barcodeFormat[,barcodeFormat2...] where barcodeFormat is any of: ");
for (BarcodeFormat format : BarcodeFormat.values()) {
builder.append(format).append(',');
}
builder.setLength(builder.length() - 1);
System.err.println(builder);
} }
} }

View file

@ -32,6 +32,7 @@ final class Config {
private boolean brief; private boolean brief;
private boolean recursive; private boolean recursive;
private int[] crop; private int[] crop;
private String[] possibleFormats;
Map<DecodeHintType,?> getHints() { Map<DecodeHintType,?> getHints() {
return hints; return hints;
@ -113,4 +114,12 @@ final class Config {
this.crop = crop; this.crop = crop;
} }
String[] getPossibleFormats() {
return possibleFormats;
}
void setPossibleFormats(String[] possibleFormats) {
this.possibleFormats = possibleFormats;
}
} }