Search in sources :

Example 66 with ReaderException

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;
    }
}
Also used : MultiFormatReader(com.google.zxing.MultiFormatReader) PlanarYUVLuminanceSource(com.google.zxing.PlanarYUVLuminanceSource) ReaderException(com.google.zxing.ReaderException) Nullable(androidx.annotation.Nullable)

Aggregations

ReaderException (com.google.zxing.ReaderException)66 Result (com.google.zxing.Result)58 BinaryBitmap (com.google.zxing.BinaryBitmap)39 HybridBinarizer (com.google.zxing.common.HybridBinarizer)34 Message (android.os.Message)25 Bundle (android.os.Bundle)24 PlanarYUVLuminanceSource (com.google.zxing.PlanarYUVLuminanceSource)16 ResultPoint (com.google.zxing.ResultPoint)16 Handler (android.os.Handler)14 ArrayList (java.util.ArrayList)10 BarcodeFormat (com.google.zxing.BarcodeFormat)8 ResultPointCallback (com.google.zxing.ResultPointCallback)8 DetectorResult (com.google.zxing.common.DetectorResult)8 BufferedImage (java.awt.image.BufferedImage)8 LuminanceSource (com.google.zxing.LuminanceSource)7 MultiFormatReader (com.google.zxing.MultiFormatReader)7 BitArray (com.google.zxing.common.BitArray)7 BufferedImageLuminanceSource (com.google.zxing.BufferedImageLuminanceSource)6 DecodeHintType (com.google.zxing.DecodeHintType)6 NotFoundException (com.google.zxing.NotFoundException)5