Java Code Examples for com.google.zxing.common.DecoderResult

The following examples show how to use com.google.zxing.common.DecoderResult. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: RipplePower   Source File: MaxiCodeReader.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Result decode(BinaryBitmap image, Map<DecodeHintType, ?> hints)
		throws NotFoundException, ChecksumException, FormatException {
	DecoderResult decoderResult;
	if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {
		BitMatrix bits = extractPureBits(image.getBlackMatrix());
		decoderResult = decoder.decode(bits, hints);
	} else {
		throw NotFoundException.getNotFoundInstance();
	}

	ResultPoint[] points = NO_POINTS;
	Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points,
			BarcodeFormat.MAXICODE);

	String ecLevel = decoderResult.getECLevel();
	if (ecLevel != null) {
		result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
	}
	return result;
}
 
Example 2
Source Project: MiBandDecompiled   Source File: MaxiCodeReader.java    License: Apache License 2.0 6 votes vote down vote up
public Result decode(BinaryBitmap binarybitmap, Map map)
{
    if (map != null && map.containsKey(DecodeHintType.PURE_BARCODE))
    {
        BitMatrix bitmatrix = a(binarybitmap.getBlackMatrix());
        DecoderResult decoderresult = d.decode(bitmatrix, map);
        ResultPoint aresultpoint[] = a;
        Result result = new Result(decoderresult.getText(), decoderresult.getRawBytes(), aresultpoint, BarcodeFormat.MAXICODE);
        String s = decoderresult.getECLevel();
        if (s != null)
        {
            result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, s);
        }
        return result;
    } else
    {
        throw NotFoundException.getNotFoundInstance();
    }
}
 
Example 3
Source Project: barcodescanner-lib-aar   Source File: PDF417Reader.java    License: MIT License 6 votes vote down vote up
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()]);
}
 
Example 4
Source Project: MiBandDecompiled   Source File: Decoder.java    License: Apache License 2.0 6 votes vote down vote up
public DecoderResult decode(boolean aflag[][], Map map)
{
    int i = aflag.length;
    BitMatrix bitmatrix = new BitMatrix(i);
    for (int j = 0; j < i; j++)
    {
        for (int k = 0; k < i; k++)
        {
            if (aflag[j][k])
            {
                bitmatrix.set(k, j);
            }
        }

    }

    return decode(bitmatrix, map);
}
 
Example 5
Source Project: RipplePower   Source File: DataMatrixReader.java    License: Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 6
Source Project: barterli_android   Source File: QRCodeReader.java    License: Apache License 2.0 6 votes vote down vote up
@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, hints);
        points = NO_POINTS;
    } else {
        DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect(hints);
        decoderResult = decoder.decode(detectorResult.getBits(), hints);
        points = detectorResult.getPoints();
    }

    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);
    }
    return result;
}
 
Example 7
Source Project: barcodescanner-lib-aar   Source File: PDF417ScanningDecoder.java    License: MIT License 6 votes vote down vote up
private static DecoderResult decodeCodewords(int[] codewords, int ecLevel, int[] erasures) throws FormatException,
    ChecksumException {
  if (codewords.length == 0) {
    throw FormatException.getFormatInstance();
  }

  int numECCodewords = 1 << (ecLevel + 1);
  int correctedErrorsCount = correctErrors(codewords, erasures, numECCodewords);
  verifyCodewordCount(codewords, numECCodewords);

  // Decode the codewords
  DecoderResult decoderResult = DecodedBitStreamParser.decode(codewords, String.valueOf(ecLevel));
  decoderResult.setErrorsCorrected(correctedErrorsCount);
  decoderResult.setErasures(erasures.length);
  return decoderResult;
}
 
Example 8
Source Project: android-quick-response-code   Source File: QRCodeReader.java    License: Apache License 2.0 6 votes vote down vote up
@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, hints);
        points = NO_POINTS;
    } else {
        DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect(hints);
        decoderResult = decoder.decode(detectorResult.getBits(), hints);
        points = detectorResult.getPoints();
    }

    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);
    }
    return result;
}
 
Example 9
Source Project: ZXing-Orient   Source File: DataMatrixReader.java    License: Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 10
Source Project: reacteu-app   Source File: PDF417Reader.java    License: MIT License 6 votes vote down vote up
@Override
public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
    throws NotFoundException, FormatException, ChecksumException {
  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).detect();
    decoderResult = decoder.decode(detectorResult.getBits());
    points = detectorResult.getPoints();
  }
  return new Result(decoderResult.getText(), decoderResult.getRawBytes(), points,
      BarcodeFormat.PDF_417);
}
 
Example 11
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()]);
}
 
Example 12
private static DecoderResult decodeCodewords(int[] codewords, int ecLevel, int[] erasures) throws FormatException,
    ChecksumException {
  if (codewords.length == 0) {
    throw FormatException.getFormatInstance();
  }

  int numECCodewords = 1 << (ecLevel + 1);
  int correctedErrorsCount = correctErrors(codewords, erasures, numECCodewords);
  verifyCodewordCount(codewords, numECCodewords);

  // Decode the codewords
  DecoderResult decoderResult = DecodedBitStreamParser.decode(codewords, String.valueOf(ecLevel));
  decoderResult.setErrorsCorrected(correctedErrorsCount);
  decoderResult.setErasures(erasures.length);
  return decoderResult;
}
 
Example 13
@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;
}
 
Example 14
Source Project: reacteu-app   Source File: QRCodeReader.java    License: MIT License 6 votes vote down vote up
@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, hints);
    points = NO_POINTS;
  } else {
    DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect(hints);
    decoderResult = decoder.decode(detectorResult.getBits(), hints);
    points = detectorResult.getPoints();
  }

  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);
  }
  return result;
}
 
Example 15
Source Project: weex   Source File: PDF417Reader.java    License: Apache License 2.0 6 votes vote down vote up
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()]);
}
 
Example 16
Source Project: MiBandDecompiled   Source File: Decoder.java    License: Apache License 2.0 6 votes vote down vote up
public DecoderResult decode(boolean aflag[][])
{
    int i = aflag.length;
    BitMatrix bitmatrix = new BitMatrix(i);
    for (int j = 0; j < i; j++)
    {
        for (int k = 0; k < i; k++)
        {
            if (aflag[j][k])
            {
                bitmatrix.set(k, j);
            }
        }

    }

    return decode(bitmatrix);
}
 
Example 17
Source Project: weex   Source File: PDF417ScanningDecoder.java    License: Apache License 2.0 6 votes vote down vote up
private static DecoderResult decodeCodewords(int[] codewords, int ecLevel, int[] erasures) throws FormatException,
    ChecksumException {
  if (codewords.length == 0) {
    throw FormatException.getFormatInstance();
  }

  int numECCodewords = 1 << (ecLevel + 1);
  int correctedErrorsCount = correctErrors(codewords, erasures, numECCodewords);
  verifyCodewordCount(codewords, numECCodewords);

  // Decode the codewords
  DecoderResult decoderResult = DecodedBitStreamParser.decode(codewords, String.valueOf(ecLevel));
  decoderResult.setErrorsCorrected(correctedErrorsCount);
  decoderResult.setErasures(erasures.length);
  return decoderResult;
}
 
Example 18
Source Project: reacteu-app   Source File: DataMatrixReader.java    License: MIT License 6 votes vote down vote up
@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;
}
 
Example 19
Source Project: weex   Source File: MaxiCodeReader.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
    throws NotFoundException, ChecksumException, FormatException {
  DecoderResult decoderResult;
  if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {
    BitMatrix bits = extractPureBits(image.getBlackMatrix());
    decoderResult = decoder.decode(bits, hints);
  } else {
    throw NotFoundException.getNotFoundInstance();
  }

  ResultPoint[] points = NO_POINTS;
  Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.MAXICODE);

  String ecLevel = decoderResult.getECLevel();
  if (ecLevel != null) {
    result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
  }
  return result;
}
 
Example 20
Source Project: reacteu-app   Source File: Decoder.java    License: MIT License 5 votes vote down vote up
public DecoderResult decode(BitMatrix bits,
                            Map<DecodeHintType,?> hints) throws FormatException, ChecksumException {
  BitMatrixParser parser = new BitMatrixParser(bits);
  byte[] codewords = parser.readCodewords();

  correctErrors(codewords, 0, 10, 10, ALL);
  int mode = codewords[0] & 0x0F;
  byte[] datawords;
  switch (mode) {
    case 2:
    case 3:
    case 4:
      correctErrors(codewords, 20, 84, 40, EVEN);
      correctErrors(codewords, 20, 84, 40, ODD);
      datawords = new byte[94];
      break;
    case 5:
      correctErrors(codewords, 20, 68, 56, EVEN);
      correctErrors(codewords, 20, 68, 56, ODD);
      datawords = new byte[78];
      break;
    default:
      throw FormatException.getFormatInstance();
  }

  System.arraycopy(codewords, 0, datawords, 0, 10);
  System.arraycopy(codewords, 20, datawords, 10, datawords.length - 10);

  return DecodedBitStreamParser.decode(datawords, mode);
}
 
Example 21
Source Project: barcodescanner-lib-aar   Source File: PDF417ScanningDecoder.java    License: MIT License 5 votes vote down vote up
/**
 * This method deals with the fact, that the decoding process doesn't always yield a single most likely value. The
 * current error correction implementation doesn't deal with erasures very well, so it's better to provide a value
 * for these ambiguous codewords instead of treating it as an erasure. The problem is that we don't know which of
 * the ambiguous values to choose. We try decode using the first value, and if that fails, we use another of the
 * ambiguous values and try to decode again. This usually only happens on very hard to read and decode barcodes,
 * so decoding the normal barcodes is not affected by this. 
 *
 * @param erasureArray contains the indexes of erasures
 * @param ambiguousIndexes array with the indexes that have more than one most likely value
 * @param ambiguousIndexValues two dimensional array that contains the ambiguous values. The first dimension must
 * be the same length as the ambiguousIndexes array
 */
private static DecoderResult createDecoderResultFromAmbiguousValues(int ecLevel,
                                                                    int[] codewords,
                                                                    int[] erasureArray,
                                                                    int[] ambiguousIndexes,
                                                                    int[][] ambiguousIndexValues)
    throws FormatException, ChecksumException {
  int[] ambiguousIndexCount = new int[ambiguousIndexes.length];

  int tries = 100;
  while (tries-- > 0) {
    for (int i = 0; i < ambiguousIndexCount.length; i++) {
      codewords[ambiguousIndexes[i]] = ambiguousIndexValues[i][ambiguousIndexCount[i]];
    }
    try {
      return decodeCodewords(codewords, ecLevel, erasureArray);
    } catch (ChecksumException ignored) {
      //
    }
    if (ambiguousIndexCount.length == 0) {
      throw ChecksumException.getChecksumInstance();
    }
    for (int i = 0; i < ambiguousIndexCount.length; i++) {
      if (ambiguousIndexCount[i] < ambiguousIndexValues[i].length - 1) {
        ambiguousIndexCount[i]++;
        break;
      } else {
        ambiguousIndexCount[i] = 0;
        if (i == ambiguousIndexCount.length - 1) {
          throw ChecksumException.getChecksumInstance();
        }
      }
    }
  }
  throw ChecksumException.getChecksumInstance();
}
 
Example 22
Source Project: Tesseract-OCR-Scanner   Source File: QRCodeMultiReader.java    License: Apache License 2.0 5 votes vote down vote up
@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()]);
  }
}
 
Example 23
Source Project: QrCodeScanner   Source File: QRCodeReader.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public final 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, hints);
    points = NO_POINTS;
  } else {
    DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect(hints);
    decoderResult = decoder.decode(detectorResult.getBits(), hints);
    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());
  }
  return result;
}
 
Example 24
Source Project: reacteu-app   Source File: Decoder.java    License: MIT License 5 votes vote down vote up
/**
 * <p>Convenience method that can decode a PDF417 Code represented as a 2D array of booleans.
 * "true" is taken to mean a black module.</p>
 *
 * @param image booleans representing white/black PDF417 modules
 * @return text and bytes encoded within the PDF417 Code
 */
public DecoderResult decode(boolean[][] image) throws FormatException, ChecksumException {
  int dimension = image.length;
  BitMatrix bits = new BitMatrix(dimension);
  for (int i = 0; i < dimension; i++) {
    for (int j = 0; j < dimension; j++) {
      if (image[j][i]) {
        bits.set(j, i);
      }
    }
  }
  return decode(bits);
}
 
Example 25
Source Project: weex   Source File: QRCodeMultiReader.java    License: Apache License 2.0 5 votes vote down vote up
@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()]);
  }
}
 
Example 26
Source Project: reacteu-app   Source File: AztecReader.java    License: MIT License 5 votes vote down vote up
@Override
public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
    throws NotFoundException, FormatException {

  AztecDetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect();
  ResultPoint[] points = detectorResult.getPoints();

  if (hints != null) {
    ResultPointCallback rpcb = (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
    if (rpcb != null) {
      for (ResultPoint point : points) {
        rpcb.foundPossibleResultPoint(point);
      }
    }
  }

  DecoderResult decoderResult = new Decoder().decode(detectorResult);

  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;
}
 
Example 27
@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()]);
  }
}
 
Example 28
Source Project: ZXing-Orient   Source File: PDF417ScanningDecoder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This method deals with the fact, that the decoding process doesn't always yield a single most likely value. The
 * current error correction implementation doesn't deal with erasures very well, so it's better to provide a value
 * for these ambiguous codewords instead of treating it as an erasure. The problem is that we don't know which of
 * the ambiguous values to choose. We try decode using the first value, and if that fails, we use another of the
 * ambiguous values and try to decode again. This usually only happens on very hard to read and decode barcodes,
 * so decoding the normal barcodes is not affected by this. 
 *
 * @param erasureArray contains the indexes of erasures
 * @param ambiguousIndexes array with the indexes that have more than one most likely value
 * @param ambiguousIndexValues two dimensional array that contains the ambiguous values. The first dimension must
 * be the same length as the ambiguousIndexes array
 */
private static DecoderResult createDecoderResultFromAmbiguousValues(int ecLevel,
                                                                    int[] codewords,
                                                                    int[] erasureArray,
                                                                    int[] ambiguousIndexes,
                                                                    int[][] ambiguousIndexValues)
    throws FormatException, ChecksumException {
  int[] ambiguousIndexCount = new int[ambiguousIndexes.length];

  int tries = 100;
  while (tries-- > 0) {
    for (int i = 0; i < ambiguousIndexCount.length; i++) {
      codewords[ambiguousIndexes[i]] = ambiguousIndexValues[i][ambiguousIndexCount[i]];
    }
    try {
      return decodeCodewords(codewords, ecLevel, erasureArray);
    } catch (ChecksumException ignored) {
      //
    }
    if (ambiguousIndexCount.length == 0) {
      throw ChecksumException.getChecksumInstance();
    }
    for (int i = 0; i < ambiguousIndexCount.length; i++) {
      if (ambiguousIndexCount[i] < ambiguousIndexValues[i].length - 1) {
        ambiguousIndexCount[i]++;
        break;
      } else {
        ambiguousIndexCount[i] = 0;
        if (i == ambiguousIndexCount.length - 1) {
          throw ChecksumException.getChecksumInstance();
        }
      }
    }
  }
  throw ChecksumException.getChecksumInstance();
}
 
Example 29
Source Project: barcodescanner-lib-aar   Source File: DecodedBitStreamParser.java    License: MIT License 5 votes vote down vote up
static DecoderResult decode(byte[] bytes) throws FormatException {
  BitSource bits = new BitSource(bytes);
  StringBuilder result = new StringBuilder(100);
  StringBuilder resultTrailer = new StringBuilder(0);
  List<byte[]> byteSegments = new ArrayList<>(1);
  Mode mode = Mode.ASCII_ENCODE;
  do {
    if (mode == Mode.ASCII_ENCODE) {
      mode = decodeAsciiSegment(bits, result, resultTrailer);
    } else {
      switch (mode) {
        case C40_ENCODE:
          decodeC40Segment(bits, result);
          break;
        case TEXT_ENCODE:
          decodeTextSegment(bits, result);
          break;
        case ANSIX12_ENCODE:
          decodeAnsiX12Segment(bits, result);
          break;
        case EDIFACT_ENCODE:
          decodeEdifactSegment(bits, result);
          break;
        case BASE256_ENCODE:
          decodeBase256Segment(bits, result, byteSegments);
          break;
        default:
          throw FormatException.getFormatInstance();
      }
      mode = Mode.ASCII_ENCODE;
    }
  } while (mode != Mode.PAD_ENCODE && bits.available() > 0);
  if (resultTrailer.length() > 0) {
    result.append(resultTrailer);
  }
  return new DecoderResult(bytes, result.toString(), byteSegments.isEmpty() ? null : byteSegments, null);
}
 
Example 30
Source Project: MiBandDecompiled   Source File: Decoder.java    License: Apache License 2.0 5 votes vote down vote up
public DecoderResult decode(BitMatrix bitmatrix, Map map)
    {
        byte abyte0[];
        int i;
        abyte0 = (new a(bitmatrix)).a();
        a(abyte0, 0, 10, 10, 0);
        i = 0xf & abyte0[0];
        i;
        JVM INSTR tableswitch 2 5: default 64
    //                   2 68
    //                   3 68
    //                   4 68
    //                   5 132;
           goto _L1 _L2 _L2 _L2 _L3
_L1:
        throw FormatException.getFormatInstance();
_L2:
        byte abyte1[];
        a(abyte0, 20, 84, 40, 1);
        a(abyte0, 20, 84, 40, 2);
        abyte1 = new byte[94];
_L5:
        System.arraycopy(abyte0, 0, abyte1, 0, 10);
        System.arraycopy(abyte0, 20, abyte1, 10, -10 + abyte1.length);
        return com.google.zxing.maxicode.decoder.b.a(abyte1, i);
_L3:
        a(abyte0, 20, 68, 56, 1);
        a(abyte0, 20, 68, 56, 2);
        abyte1 = new byte[78];
        if (true) goto _L5; else goto _L4
_L4:
    }