use of com.google.zxing.NotFoundException in project android-zxing by PearceXu.
the class RSSExpandedReader method retrieveNextPair.
// not private for testing
ExpandedPair retrieveNextPair(BitArray row, List<ExpandedPair> previousPairs, int rowNumber) throws NotFoundException {
boolean isOddPattern = previousPairs.size() % 2 == 0;
if (startFromEven) {
isOddPattern = !isOddPattern;
}
FinderPattern pattern;
boolean keepFinding = true;
int forcedOffset = -1;
do {
this.findNextPair(row, previousPairs, forcedOffset);
pattern = parseFoundFinderPattern(row, rowNumber, isOddPattern);
if (pattern == null) {
forcedOffset = getNextSecondBar(row, this.startEnd[0]);
} else {
keepFinding = false;
}
} while (keepFinding);
// When stacked symbol is split over multiple rows, there's no way to guess if this pair can be last or not.
// boolean mayBeLast = checkPairSequence(previousPairs, pattern);
DataCharacter leftChar = this.decodeDataCharacter(row, pattern, isOddPattern, true);
if (!previousPairs.isEmpty() && previousPairs.get(previousPairs.size() - 1).mustBeLast()) {
throw NotFoundException.getNotFoundInstance();
}
DataCharacter rightChar;
try {
rightChar = this.decodeDataCharacter(row, pattern, isOddPattern, false);
} catch (NotFoundException ignored) {
rightChar = null;
}
return new ExpandedPair(leftChar, rightChar, pattern, true);
}
use of com.google.zxing.NotFoundException in project weex-example by KalicyZhou.
the class OneDReader method doDecode.
/**
* We're going to examine rows from the middle outward, searching alternately above and below the
* middle, and farther out each time. rowStep is the number of rows between each successive
* attempt above and below the middle. So we'd scan row middle, then middle - rowStep, then
* middle + rowStep, then middle - (2 * rowStep), etc.
* rowStep is bigger as the image is taller, but is always at least 1. We've somewhat arbitrarily
* decided that moving up and down by about 1/16 of the image is pretty good; we try more of the
* image if "trying harder".
*
* @param image The image to decode
* @param hints Any hints that were requested
* @return The contents of the decoded barcode
* @throws NotFoundException Any spontaneous errors which occur
*/
private Result doDecode(BinaryBitmap image, Map<DecodeHintType, ?> hints) throws NotFoundException {
int width = image.getWidth();
int height = image.getHeight();
BitArray row = new BitArray(width);
int middle = height >> 1;
boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);
int rowStep = Math.max(1, height >> (tryHarder ? 8 : 5));
int maxLines;
if (tryHarder) {
// Look at the whole image, not just the center
maxLines = height;
} else {
// 15 rows spaced 1/32 apart is roughly the middle half of the image
maxLines = 15;
}
for (int x = 0; x < maxLines; x++) {
// Scanning from the middle out. Determine which row we're looking at next:
int rowStepsAboveOrBelow = (x + 1) / 2;
// i.e. is x even?
boolean isAbove = (x & 0x01) == 0;
int rowNumber = middle + rowStep * (isAbove ? rowStepsAboveOrBelow : -rowStepsAboveOrBelow);
if (rowNumber < 0 || rowNumber >= height) {
// Oops, if we run off the top or bottom, stop
break;
}
// Estimate black point for this row and load it:
try {
row = image.getBlackRow(rowNumber, row);
} catch (NotFoundException ignored) {
continue;
}
// handle decoding upside down barcodes.
for (int attempt = 0; attempt < 2; attempt++) {
if (attempt == 1) {
// trying again?
// reverse the row and continue
row.reverse();
// that start on the center line.
if (hints != null && hints.containsKey(DecodeHintType.NEED_RESULT_POINT_CALLBACK)) {
Map<DecodeHintType, Object> newHints = new EnumMap<>(DecodeHintType.class);
newHints.putAll(hints);
newHints.remove(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
hints = newHints;
}
}
try {
// Look for a barcode
Result result = decodeRow(rowNumber, row, hints);
// We found our barcode
if (attempt == 1) {
// But it was upside down, so note that
result.putMetadata(ResultMetadataType.ORIENTATION, 180);
// And remember to flip the result points horizontally.
ResultPoint[] points = result.getResultPoints();
if (points != null) {
points[0] = new ResultPoint(width - points[0].getX() - 1, points[0].getY());
points[1] = new ResultPoint(width - points[1].getX() - 1, points[1].getY());
}
}
return result;
} catch (ReaderException re) {
// continue -- just couldn't decode this row
}
}
}
throw NotFoundException.getNotFoundInstance();
}
use of com.google.zxing.NotFoundException in project weex-example by KalicyZhou.
the class RSSExpandedReader method parseFoundFinderPattern.
private FinderPattern parseFoundFinderPattern(BitArray row, int rowNumber, boolean oddPattern) {
// Actually we found elements 2-5.
int firstCounter;
int start;
int end;
if (oddPattern) {
// If pattern number is odd, we need to locate element 1 *before* the current block.
int firstElementStart = this.startEnd[0] - 1;
// Locate element 1
while (firstElementStart >= 0 && !row.get(firstElementStart)) {
firstElementStart--;
}
firstElementStart++;
firstCounter = this.startEnd[0] - firstElementStart;
start = firstElementStart;
end = this.startEnd[1];
} else {
// If pattern number is even, the pattern is reversed, so we need to locate element 1 *after* the current block.
start = this.startEnd[0];
end = row.getNextUnset(this.startEnd[1] + 1);
firstCounter = end - this.startEnd[1];
}
// Make 'counters' hold 1-4
int[] counters = this.getDecodeFinderCounters();
System.arraycopy(counters, 0, counters, 1, counters.length - 1);
counters[0] = firstCounter;
int value;
try {
value = parseFinderValue(counters, FINDER_PATTERNS);
} catch (NotFoundException ignored) {
return null;
}
return new FinderPattern(value, new int[] { start, end }, start, end, rowNumber);
}
use of com.google.zxing.NotFoundException in project elastic-core-maven by OrdinaryDude.
the class DecodeQRCode method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest request) throws NxtException {
String qrCodeBase64 = Convert.nullToEmpty(request.getParameter("qrCodeBase64"));
JSONObject response = new JSONObject();
try {
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(new ByteArrayInputStream(Base64.getDecoder().decode(qrCodeBase64))))));
Map hints = new HashMap();
hints.put(DecodeHintType.POSSIBLE_FORMATS, EnumSet.of(BarcodeFormat.QR_CODE));
hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
Result qrCodeData = new MultiFormatReader().decode(binaryBitmap, hints);
response.put("qrCodeData", qrCodeData.getText());
} catch (IOException ex) {
String errorMessage = "Error reading base64 byte stream";
Logger.logErrorMessage(errorMessage, ex);
JSONData.putException(response, ex, errorMessage);
} catch (NullPointerException ex) {
String errorMessage = "Invalid base64 image";
Logger.logErrorMessage(errorMessage, ex);
JSONData.putException(response, ex, errorMessage);
} catch (NotFoundException ex) {
response.put("qrCodeData", "");
}
return response;
}
use of com.google.zxing.NotFoundException in project react-native-camera by react-native-community.
the class BarCodeScannerAsyncTask method doInBackground.
@Override
protected Result doInBackground(Void... ignored) {
if (isCancelled() || mDelegate == null) {
return null;
}
Result result = null;
try {
BinaryBitmap bitmap = generateBitmapFromImageData(mImageData, mWidth, mHeight);
result = mMultiFormatReader.decodeWithState(bitmap);
} catch (NotFoundException e) {
// No barcode found, result is already null.
} catch (Throwable t) {
t.printStackTrace();
}
return result;
}
Aggregations