Search in sources :

Example 36 with DecoderResult

use of com.google.zxing.common.DecoderResult in project weex-example by KalicyZhou.

the class AztecReader method decode.

@Override
public Result decode(BinaryBitmap image, Map<DecodeHintType, ?> hints) throws NotFoundException, FormatException {
    NotFoundException notFoundException = null;
    FormatException formatException = null;
    Detector detector = new Detector(image.getBlackMatrix());
    ResultPoint[] points = null;
    DecoderResult decoderResult = null;
    try {
        AztecDetectorResult detectorResult = detector.detect(false);
        points = detectorResult.getPoints();
        decoderResult = new Decoder().decode(detectorResult);
    } catch (NotFoundException e) {
        notFoundException = e;
    } catch (FormatException e) {
        formatException = e;
    }
    if (decoderResult == null) {
        try {
            AztecDetectorResult detectorResult = detector.detect(true);
            points = detectorResult.getPoints();
            decoderResult = new Decoder().decode(detectorResult);
        } catch (NotFoundException | FormatException e) {
            if (notFoundException != null) {
                throw notFoundException;
            }
            if (formatException != null) {
                throw formatException;
            }
            throw e;
        }
    }
    if (hints != null) {
        ResultPointCallback rpcb = (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
        if (rpcb != null) {
            for (ResultPoint point : points) {
                rpcb.foundPossibleResultPoint(point);
            }
        }
    }
    Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.AZTEC);
    List<byte[]> byteSegments = decoderResult.getByteSegments();
    if (byteSegments != null) {
        result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments);
    }
    String ecLevel = decoderResult.getECLevel();
    if (ecLevel != null) {
        result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
    }
    return result;
}
Also used : ResultPointCallback(com.google.zxing.ResultPointCallback) ResultPoint(com.google.zxing.ResultPoint) NotFoundException(com.google.zxing.NotFoundException) Decoder(com.google.zxing.aztec.decoder.Decoder) FormatException(com.google.zxing.FormatException) Result(com.google.zxing.Result) DecoderResult(com.google.zxing.common.DecoderResult) Detector(com.google.zxing.aztec.detector.Detector) DecoderResult(com.google.zxing.common.DecoderResult)

Example 37 with DecoderResult

use of com.google.zxing.common.DecoderResult in project weex-example by KalicyZhou.

the class Decoder method decode.

public DecoderResult decode(AztecDetectorResult detectorResult) throws FormatException {
    ddata = detectorResult;
    BitMatrix matrix = detectorResult.getBits();
    boolean[] rawbits = extractBits(matrix);
    boolean[] correctedBits = correctBits(rawbits);
    String result = getEncodedData(correctedBits);
    return new DecoderResult(null, result, null, null);
}
Also used : DecoderResult(com.google.zxing.common.DecoderResult) BitMatrix(com.google.zxing.common.BitMatrix)

Example 38 with DecoderResult

use of com.google.zxing.common.DecoderResult in project weex-example by KalicyZhou.

the class DecodedBitStreamParser method decode.

static DecoderResult decode(byte[] bytes, int mode) {
    StringBuilder result = new StringBuilder(144);
    switch(mode) {
        case 2:
        case 3:
            String postcode;
            if (mode == 2) {
                int pc = getPostCode2(bytes);
                NumberFormat df = new DecimalFormat("0000000000".substring(0, getPostCode2Length(bytes)));
                postcode = df.format(pc);
            } else {
                postcode = getPostCode3(bytes);
            }
            String country = THREE_DIGITS.format(getCountry(bytes));
            String service = THREE_DIGITS.format(getServiceClass(bytes));
            result.append(getMessage(bytes, 10, 84));
            if (result.toString().startsWith("[)>" + RS + "01" + GS)) {
                result.insert(9, postcode + GS + country + GS + service + GS);
            } else {
                result.insert(0, postcode + GS + country + GS + service + GS);
            }
            break;
        case 4:
            result.append(getMessage(bytes, 1, 93));
            break;
        case 5:
            result.append(getMessage(bytes, 1, 77));
            break;
    }
    return new DecoderResult(bytes, result.toString(), null, String.valueOf(mode));
}
Also used : DecimalFormat(java.text.DecimalFormat) DecoderResult(com.google.zxing.common.DecoderResult) NumberFormat(java.text.NumberFormat)

Example 39 with DecoderResult

use of com.google.zxing.common.DecoderResult in project weex-example by KalicyZhou.

the class QRCodeMultiReader method decodeMultiple.

@Override
public Result[] decodeMultiple(BinaryBitmap image, Map<DecodeHintType, ?> hints) throws NotFoundException {
    List<Result> results = new ArrayList<>();
    DetectorResult[] detectorResults = new MultiDetector(image.getBlackMatrix()).detectMulti(hints);
    for (DetectorResult detectorResult : detectorResults) {
        try {
            DecoderResult decoderResult = getDecoder().decode(detectorResult.getBits(), hints);
            ResultPoint[] points = detectorResult.getPoints();
            // If the code was mirrored: swap the bottom-left and the top-right points.
            if (decoderResult.getOther() instanceof QRCodeDecoderMetaData) {
                ((QRCodeDecoderMetaData) decoderResult.getOther()).applyMirroredCorrection(points);
            }
            Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.QR_CODE);
            List<byte[]> byteSegments = decoderResult.getByteSegments();
            if (byteSegments != null) {
                result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments);
            }
            String ecLevel = decoderResult.getECLevel();
            if (ecLevel != null) {
                result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
            }
            if (decoderResult.hasStructuredAppend()) {
                result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, decoderResult.getStructuredAppendSequenceNumber());
                result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_PARITY, decoderResult.getStructuredAppendParity());
            }
            results.add(result);
        } catch (ReaderException re) {
        // ignore and continue 
        }
    }
    if (results.isEmpty()) {
        return EMPTY_RESULT_ARRAY;
    } else {
        results = processStructuredAppend(results);
        return results.toArray(new Result[results.size()]);
    }
}
Also used : ResultPoint(com.google.zxing.ResultPoint) ArrayList(java.util.ArrayList) Result(com.google.zxing.Result) DetectorResult(com.google.zxing.common.DetectorResult) DecoderResult(com.google.zxing.common.DecoderResult) ReaderException(com.google.zxing.ReaderException) DecoderResult(com.google.zxing.common.DecoderResult) DetectorResult(com.google.zxing.common.DetectorResult) MultiDetector(com.google.zxing.multi.qrcode.detector.MultiDetector) QRCodeDecoderMetaData(com.google.zxing.qrcode.decoder.QRCodeDecoderMetaData)

Example 40 with DecoderResult

use of com.google.zxing.common.DecoderResult in project weex-example by KalicyZhou.

the class DataMatrixReader method decode.

@Override
public Result decode(BinaryBitmap image, Map<DecodeHintType, ?> hints) throws NotFoundException, ChecksumException, FormatException {
    DecoderResult decoderResult;
    ResultPoint[] points;
    if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {
        BitMatrix bits = extractPureBits(image.getBlackMatrix());
        decoderResult = decoder.decode(bits);
        points = NO_POINTS;
    } else {
        DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect();
        decoderResult = decoder.decode(detectorResult.getBits());
        points = detectorResult.getPoints();
    }
    Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.DATA_MATRIX);
    List<byte[]> byteSegments = decoderResult.getByteSegments();
    if (byteSegments != null) {
        result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments);
    }
    String ecLevel = decoderResult.getECLevel();
    if (ecLevel != null) {
        result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
    }
    return result;
}
Also used : ResultPoint(com.google.zxing.ResultPoint) Detector(com.google.zxing.datamatrix.detector.Detector) DecoderResult(com.google.zxing.common.DecoderResult) DetectorResult(com.google.zxing.common.DetectorResult) BitMatrix(com.google.zxing.common.BitMatrix) Result(com.google.zxing.Result) DetectorResult(com.google.zxing.common.DetectorResult) DecoderResult(com.google.zxing.common.DecoderResult)

Aggregations

DecoderResult (com.google.zxing.common.DecoderResult)57 ResultPoint (com.google.zxing.ResultPoint)27 Result (com.google.zxing.Result)24 BitMatrix (com.google.zxing.common.BitMatrix)21 ArrayList (java.util.ArrayList)16 DetectorResult (com.google.zxing.common.DetectorResult)13 FormatException (com.google.zxing.FormatException)9 BitSource (com.google.zxing.common.BitSource)8 CharacterSetECI (com.google.zxing.common.CharacterSetECI)8 QRCodeDecoderMetaData (com.google.zxing.qrcode.decoder.QRCodeDecoderMetaData)8 Decoder (com.google.zxing.aztec.decoder.Decoder)7 NotFoundException (com.google.zxing.NotFoundException)6 ChecksumException (com.google.zxing.ChecksumException)5 Detector (com.google.zxing.qrcode.detector.Detector)5 ReaderException (com.google.zxing.ReaderException)4 ResultPointCallback (com.google.zxing.ResultPointCallback)4 AztecDetectorResult (com.google.zxing.aztec.AztecDetectorResult)4 Detector (com.google.zxing.aztec.detector.Detector)4 Detector (com.google.zxing.datamatrix.detector.Detector)4 MultiDetector (com.google.zxing.multi.qrcode.detector.MultiDetector)4