import com.google.zxing.ReaderException;
import com.google.zxing.Result;
import com.google.zxing.ResultPoint;
+import com.google.zxing.ResultMetadataType;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.DecoderResult;
import com.google.zxing.common.DetectorResult;
*
* @author Sean Owen
*/
-public final class QRCodeReader implements Reader {
+public class QRCodeReader implements Reader {
private static final ResultPoint[] NO_POINTS = new ResultPoint[0];
private final Decoder decoder = new Decoder();
+ protected Decoder getDecoder() {
+ return decoder;
+ }
+
/**
* Locates and decodes a QR code in an image.
*
decoderResult = decoder.decode(bits);
points = NO_POINTS;
} else {
- DetectorResult result = new Detector(image).detect(hints);
- decoderResult = decoder.decode(result.getBits());
- points = result.getPoints();
+ DetectorResult detectorResult = new Detector(image).detect(hints);
+ decoderResult = decoder.decode(detectorResult.getBits());
+ points = detectorResult.getPoints();
+ }
+
+ Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.QR_CODE);
+ if (decoderResult.getByteSegments() != null) {
+ result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.getByteSegments());
}
- return new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.QR_CODE);
+ return result;
}
/**
borderWidth++;
}
if (borderWidth == minDimension) {
- throw new ReaderException("No black pixels found along diagonal");
+ throw ReaderException.getInstance();
}
// And then keep tracking across the top-left black module to determine module size
moduleEnd++;
}
if (moduleEnd == minDimension) {
- throw new ReaderException("No end to black pixels found along diagonal");
+ throw ReaderException.getInstance();
}
int moduleSize = moduleEnd - borderWidth;
rowEndOfSymbol--;
}
if (rowEndOfSymbol < 0) {
- throw new ReaderException("Can't find end of rightmost black module");
+ throw ReaderException.getInstance();
}
rowEndOfSymbol++;
// Make sure width of barcode is a multiple of module size
if ((rowEndOfSymbol - borderWidth) % moduleSize != 0) {
- throw new ReaderException("Bad module size / width: " + moduleSize +
- " / " + (rowEndOfSymbol - borderWidth));
+ throw ReaderException.getInstance();
}
int dimension = (rowEndOfSymbol - borderWidth) / moduleSize;
int sampleDimension = borderWidth + (dimension - 1) * moduleSize;
if (sampleDimension >= width || sampleDimension >= height) {
- throw new ReaderException("Estimated pure image size is beyond image boundaries");
+ throw ReaderException.getInstance();
}
// Now just read off the bits