Search in sources :

Example 1 with PDF417ResultMetadata

use of com.google.zxing.pdf417.PDF417ResultMetadata in project weex-example by KalicyZhou.

the class DecodedBitStreamParser method decode.

static DecoderResult decode(int[] codewords, String ecLevel) throws FormatException {
    StringBuilder result = new StringBuilder(codewords.length * 2);
    Charset encoding = DEFAULT_ENCODING;
    // Get compaction mode
    int codeIndex = 1;
    int code = codewords[codeIndex++];
    PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
    while (codeIndex < codewords[0]) {
        switch(code) {
            case TEXT_COMPACTION_MODE_LATCH:
                codeIndex = textCompaction(codewords, codeIndex, result);
                break;
            case BYTE_COMPACTION_MODE_LATCH:
            case BYTE_COMPACTION_MODE_LATCH_6:
                codeIndex = byteCompaction(code, codewords, encoding, codeIndex, result);
                break;
            case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
                result.append((char) codewords[codeIndex++]);
                break;
            case NUMERIC_COMPACTION_MODE_LATCH:
                codeIndex = numericCompaction(codewords, codeIndex, result);
                break;
            case ECI_CHARSET:
                CharacterSetECI charsetECI = CharacterSetECI.getCharacterSetECIByValue(codewords[codeIndex++]);
                encoding = Charset.forName(charsetECI.name());
                break;
            case ECI_GENERAL_PURPOSE:
                // Can't do anything with generic ECI; skip its 2 characters
                codeIndex += 2;
                break;
            case ECI_USER_DEFINED:
                // Can't do anything with user ECI; skip its 1 character
                codeIndex++;
                break;
            case BEGIN_MACRO_PDF417_CONTROL_BLOCK:
                codeIndex = decodeMacroBlock(codewords, codeIndex, resultMetadata);
                break;
            case BEGIN_MACRO_PDF417_OPTIONAL_FIELD:
            case MACRO_PDF417_TERMINATOR:
                // Should not see these outside a macro block
                throw FormatException.getFormatInstance();
            default:
                // Default to text compaction. During testing numerous barcodes
                // appeared to be missing the starting mode. In these cases defaulting
                // to text compaction seems to work.
                codeIndex--;
                codeIndex = textCompaction(codewords, codeIndex, result);
                break;
        }
        if (codeIndex < codewords.length) {
            code = codewords[codeIndex++];
        } else {
            throw FormatException.getFormatInstance();
        }
    }
    if (result.length() == 0) {
        throw FormatException.getFormatInstance();
    }
    DecoderResult decoderResult = new DecoderResult(null, result.toString(), null, ecLevel);
    decoderResult.setOther(resultMetadata);
    return decoderResult;
}
Also used : Charset(java.nio.charset.Charset) DecoderResult(com.google.zxing.common.DecoderResult) PDF417ResultMetadata(com.google.zxing.pdf417.PDF417ResultMetadata) CharacterSetECI(com.google.zxing.common.CharacterSetECI)

Example 2 with PDF417ResultMetadata

use of com.google.zxing.pdf417.PDF417ResultMetadata in project zxing by zxing.

the class DecodedBitStreamParser method decode.

static DecoderResult decode(int[] codewords, String ecLevel) throws FormatException {
    StringBuilder result = new StringBuilder(codewords.length * 2);
    Charset encoding = DEFAULT_ENCODING;
    // Get compaction mode
    int codeIndex = 1;
    int code = codewords[codeIndex++];
    PDF417ResultMetadata resultMetadata = new PDF417ResultMetadata();
    while (codeIndex < codewords[0]) {
        switch(code) {
            case TEXT_COMPACTION_MODE_LATCH:
                codeIndex = textCompaction(codewords, codeIndex, result);
                break;
            case BYTE_COMPACTION_MODE_LATCH:
            case BYTE_COMPACTION_MODE_LATCH_6:
                codeIndex = byteCompaction(code, codewords, encoding, codeIndex, result);
                break;
            case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
                result.append((char) codewords[codeIndex++]);
                break;
            case NUMERIC_COMPACTION_MODE_LATCH:
                codeIndex = numericCompaction(codewords, codeIndex, result);
                break;
            case ECI_CHARSET:
                CharacterSetECI charsetECI = CharacterSetECI.getCharacterSetECIByValue(codewords[codeIndex++]);
                encoding = Charset.forName(charsetECI.name());
                break;
            case ECI_GENERAL_PURPOSE:
                // Can't do anything with generic ECI; skip its 2 characters
                codeIndex += 2;
                break;
            case ECI_USER_DEFINED:
                // Can't do anything with user ECI; skip its 1 character
                codeIndex++;
                break;
            case BEGIN_MACRO_PDF417_CONTROL_BLOCK:
                codeIndex = decodeMacroBlock(codewords, codeIndex, resultMetadata);
                break;
            case BEGIN_MACRO_PDF417_OPTIONAL_FIELD:
            case MACRO_PDF417_TERMINATOR:
                // Should not see these outside a macro block
                throw FormatException.getFormatInstance();
            default:
                // Default to text compaction. During testing numerous barcodes
                // appeared to be missing the starting mode. In these cases defaulting
                // to text compaction seems to work.
                codeIndex--;
                codeIndex = textCompaction(codewords, codeIndex, result);
                break;
        }
        if (codeIndex < codewords.length) {
            code = codewords[codeIndex++];
        } else {
            throw FormatException.getFormatInstance();
        }
    }
    if (result.length() == 0) {
        throw FormatException.getFormatInstance();
    }
    DecoderResult decoderResult = new DecoderResult(null, result.toString(), null, ecLevel);
    decoderResult.setOther(resultMetadata);
    return decoderResult;
}
Also used : Charset(java.nio.charset.Charset) DecoderResult(com.google.zxing.common.DecoderResult) PDF417ResultMetadata(com.google.zxing.pdf417.PDF417ResultMetadata) CharacterSetECI(com.google.zxing.common.CharacterSetECI)

Example 3 with PDF417ResultMetadata

use of com.google.zxing.pdf417.PDF417ResultMetadata in project weex-example by KalicyZhou.

the class PDF417Reader method decode.

private static Result[] decode(BinaryBitmap image, Map<DecodeHintType, ?> hints, boolean multiple) throws NotFoundException, FormatException, ChecksumException {
    List<Result> results = new ArrayList<>();
    PDF417DetectorResult detectorResult = Detector.detect(image, hints, multiple);
    for (ResultPoint[] points : detectorResult.getPoints()) {
        DecoderResult decoderResult = PDF417ScanningDecoder.decode(detectorResult.getBits(), points[4], points[5], points[6], points[7], getMinCodewordWidth(points), getMaxCodewordWidth(points));
        Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.PDF_417);
        result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.getECLevel());
        PDF417ResultMetadata pdf417ResultMetadata = (PDF417ResultMetadata) decoderResult.getOther();
        if (pdf417ResultMetadata != null) {
            result.putMetadata(ResultMetadataType.PDF417_EXTRA_METADATA, pdf417ResultMetadata);
        }
        results.add(result);
    }
    return results.toArray(new Result[results.size()]);
}
Also used : ResultPoint(com.google.zxing.ResultPoint) ArrayList(java.util.ArrayList) PDF417DetectorResult(com.google.zxing.pdf417.detector.PDF417DetectorResult) DecoderResult(com.google.zxing.common.DecoderResult) Result(com.google.zxing.Result) DecoderResult(com.google.zxing.common.DecoderResult) PDF417DetectorResult(com.google.zxing.pdf417.detector.PDF417DetectorResult)

Example 4 with PDF417ResultMetadata

use of com.google.zxing.pdf417.PDF417ResultMetadata in project zxing by zxing.

the class PDF417Reader method decode.

private static Result[] decode(BinaryBitmap image, Map<DecodeHintType, ?> hints, boolean multiple) throws NotFoundException, FormatException, ChecksumException {
    List<Result> results = new ArrayList<>();
    PDF417DetectorResult detectorResult = Detector.detect(image, hints, multiple);
    for (ResultPoint[] points : detectorResult.getPoints()) {
        DecoderResult decoderResult = PDF417ScanningDecoder.decode(detectorResult.getBits(), points[4], points[5], points[6], points[7], getMinCodewordWidth(points), getMaxCodewordWidth(points));
        Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.PDF_417);
        result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.getECLevel());
        PDF417ResultMetadata pdf417ResultMetadata = (PDF417ResultMetadata) decoderResult.getOther();
        if (pdf417ResultMetadata != null) {
            result.putMetadata(ResultMetadataType.PDF417_EXTRA_METADATA, pdf417ResultMetadata);
        }
        results.add(result);
    }
    return results.toArray(new Result[results.size()]);
}
Also used : ResultPoint(com.google.zxing.ResultPoint) ArrayList(java.util.ArrayList) PDF417DetectorResult(com.google.zxing.pdf417.detector.PDF417DetectorResult) DecoderResult(com.google.zxing.common.DecoderResult) Result(com.google.zxing.Result) DecoderResult(com.google.zxing.common.DecoderResult) PDF417DetectorResult(com.google.zxing.pdf417.detector.PDF417DetectorResult)

Aggregations

DecoderResult (com.google.zxing.common.DecoderResult)4 Result (com.google.zxing.Result)2 ResultPoint (com.google.zxing.ResultPoint)2 CharacterSetECI (com.google.zxing.common.CharacterSetECI)2 PDF417ResultMetadata (com.google.zxing.pdf417.PDF417ResultMetadata)2 PDF417DetectorResult (com.google.zxing.pdf417.detector.PDF417DetectorResult)2 Charset (java.nio.charset.Charset)2 ArrayList (java.util.ArrayList)2