- public Result decode(MonochromeBitmapSource image, Hashtable hints) throws ReaderException {
-
- Vector possibleFormats = hints == null ? null : (Vector) hints.get(DecodeHintType.POSSIBLE_FORMATS);
- Vector readers = new Vector();
- if (possibleFormats != null) {
- if (possibleFormats.contains(BarcodeFormat.UPC_A) ||
- possibleFormats.contains(BarcodeFormat.UPC_E) ||
- possibleFormats.contains(BarcodeFormat.EAN_13) ||
- possibleFormats.contains(BarcodeFormat.EAN_8) ||
- possibleFormats.contains(BarcodeFormat.CODE_39) ||
- possibleFormats.contains(BarcodeFormat.CODE_128)) {
- readers.addElement(new MultiFormatOneDReader());
+ /**
+ * Decode an image using the state set up by calling setHints() previously. Continuous scan
+ * clients will get a <b>large</b> speed increase by using this instead of decode().
+ *
+ * @param image The pixel data to decode
+ * @return The contents of the image
+ * @throws NotFoundException Any errors which occurred
+ */
+ public Result decodeWithState(BinaryBitmap image) throws NotFoundException {
+ // Make sure to set up the default state so we don't crash
+ if (readers == null) {
+ setHints(null);
+ }
+ return decodeInternal(image);
+ }
+
+ /**
+ * 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.CODABAR) ||
+ 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));