+ /**
+ * This method adds state to the MultiFormatReader. By setting the hints once, subsequent calls
+ * to decodeWithState(image) can reuse the same set of readers without reallocating memory. This
+ * is important for performance in continuous scan clients.
+ *
+ * @param hints The set of hints to use for subsequent calls to decode(image)
+ */
+ public void setHints(Hashtable hints) {
+ this.hints = hints;
+
+ boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);
+ Vector formats = hints == null ? null : (Vector) hints.get(DecodeHintType.POSSIBLE_FORMATS);
+ readers = new Vector();
+ if (formats != null) {
+ boolean addOneDReader =
+ formats.contains(BarcodeFormat.UPC_A) ||
+ formats.contains(BarcodeFormat.UPC_E) ||
+ formats.contains(BarcodeFormat.EAN_13) ||
+ formats.contains(BarcodeFormat.EAN_8) ||
+ formats.contains(BarcodeFormat.CODE_39) ||
+ formats.contains(BarcodeFormat.CODE_93) ||
+ formats.contains(BarcodeFormat.CODE_128) ||
+ formats.contains(BarcodeFormat.ITF) ||
+ formats.contains(BarcodeFormat.RSS14) ||
+ formats.contains(BarcodeFormat.RSS_EXPANDED);
+ // Put 1D readers upfront in "normal" mode
+ if (addOneDReader && !tryHarder) {
+ readers.addElement(new MultiFormatOneDReader(hints));
+ }
+ if (formats.contains(BarcodeFormat.QR_CODE)) {
+ readers.addElement(new QRCodeReader());
+ }
+ if (formats.contains(BarcodeFormat.DATAMATRIX)) {
+ readers.addElement(new DataMatrixReader());
+ }
+ if (formats.contains(BarcodeFormat.PDF417)) {
+ readers.addElement(new PDF417Reader());
+ }
+ // At end in "try harder" mode
+ if (addOneDReader && tryHarder) {
+ readers.addElement(new MultiFormatOneDReader(hints));
+ }
+ }
+ if (readers.isEmpty()) {
+ if (!tryHarder) {
+ readers.addElement(new MultiFormatOneDReader(hints));
+ }
+ readers.addElement(new QRCodeReader());
+
+ // TODO re-enable once Data Matrix is ready
+ // readers.addElement(new DataMatrixReader());
+
+ // TODO: Enable once PDF417 has passed QA
+ //readers.addElement(new PDF417Reader());
+
+ if (tryHarder) {
+ readers.addElement(new MultiFormatOneDReader(hints));