use of com.google.zxing.ReaderException in project samourai-wallet-android by Samourai-Wallet.
the class BarcodeUtils method decodeYuv.
/**
* Decode barcode from YUV pixels array
*
* @param pixels YUV image data
* @param width Image width
* @param height Image height
* @param rotation Degrees to rotate image before decoding (only 0, 90, 180 or 270 are allowed)
* @param reverseHorizontal Reverse image horizontally before decoding
* @param hints Decoder hints
* @return Decode result, if barcode was decoded successfully, {@code null} otherwise
* @see DecodeHintType
*/
@Nullable
@SuppressWarnings("SuspiciousNameCombination")
public static Result decodeYuv(@NonNull final byte[] pixels, final int width, final int height, @Rotation final int rotation, final boolean reverseHorizontal, @Nullable final Map<DecodeHintType, ?> hints) {
Objects.requireNonNull(pixels);
final byte[] rotatedPixels = Utils.rotateYuv(pixels, width, height, rotation);
final int rotatedWidth;
final int rotatedHeight;
if (rotation == ROTATION_90 || rotation == ROTATION_270) {
rotatedWidth = height;
rotatedHeight = width;
} else {
rotatedWidth = width;
rotatedHeight = height;
}
final MultiFormatReader reader = createReader(hints);
try {
return Utils.decodeLuminanceSource(reader, new PlanarYUVLuminanceSource(rotatedPixels, rotatedWidth, rotatedHeight, 0, 0, rotatedWidth, rotatedHeight, reverseHorizontal));
} catch (final ReaderException e) {
return null;
}
}
Aggregations