Java 类com.google.zxing.FormatException 实例源码

项目:boohee_v5.6    文件:PDF417ScanningDecoder.java   
private static void verifyCodewordCount(int[] codewords, int numECCodewords) throws
        FormatException {
    if (codewords.length < 4) {
        throw FormatException.getFormatInstance();
    }
    int numberOfCodewords = codewords[0];
    if (numberOfCodewords > codewords.length) {
        throw FormatException.getFormatInstance();
    } else if (numberOfCodewords != 0) {
    } else {
        if (numECCodewords < codewords.length) {
            codewords[0] = codewords.length - numECCodewords;
            return;
        }
        throw FormatException.getFormatInstance();
    }
}
项目:Tesseract-OCR-Scanner    文件:RSSExpandedReader.java   
@Override
public Result decodeRow(int rowNumber,
                        BitArray row,
                        Map<DecodeHintType,?> hints) throws NotFoundException, FormatException {
  // Rows can start with even pattern in case in prev rows there where odd number of patters.
  // So lets try twice
  this.pairs.clear();
  this.startFromEven = false;
  try {
    return constructResult(decodeRow2pairs(rowNumber, row));
  } catch (NotFoundException e) {
    // OK
  }

  this.pairs.clear();
  this.startFromEven = true;
  return constructResult(decodeRow2pairs(rowNumber, row));
}
项目:Tesseract-OCR-Scanner    文件:RSSExpandedReader.java   
static Result constructResult(List<ExpandedPair> pairs) throws NotFoundException, FormatException {
  BitArray binary = BitArrayBuilder.buildBitArray(pairs);

  AbstractExpandedDecoder decoder = AbstractExpandedDecoder.createDecoder(binary);
  String resultingString = decoder.parseInformation();

  ResultPoint[] firstPoints = pairs.get(0).getFinderPattern().getResultPoints();
  ResultPoint[] lastPoints  = pairs.get(pairs.size() - 1).getFinderPattern().getResultPoints();

  return new Result(
        resultingString,
        null,
        new ResultPoint[]{firstPoints[0], firstPoints[1], lastPoints[0], lastPoints[1]},
        BarcodeFormat.RSS_EXPANDED
    );
}
项目:boohee_v5.6    文件:AI01393xDecoder.java   
public String parseInformation() throws NotFoundException, FormatException {
    if (getInformation().getSize() < 48) {
        throw NotFoundException.getNotFoundInstance();
    }
    StringBuilder buf = new StringBuilder();
    encodeCompressedGtin(buf, 8);
    int lastAIdigit = getGeneralDecoder().extractNumericValueFromBitArray(48, 2);
    buf.append("(393");
    buf.append(lastAIdigit);
    buf.append(')');
    int firstThreeDigits = getGeneralDecoder().extractNumericValueFromBitArray(50, 10);
    if (firstThreeDigits / 100 == 0) {
        buf.append('0');
    }
    if (firstThreeDigits / 10 == 0) {
        buf.append('0');
    }
    buf.append(firstThreeDigits);
    buf.append(getGeneralDecoder().decodeGeneralPurposeField(60, null).getNewString());
    return buf.toString();
}
项目:boohee_v5.6    文件:PDF417Reader.java   
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 (Result[]) results.toArray(new Result[results.size()]);
}
项目:QrCode    文件:AI01392xDecoder.java   
@Override
public String parseInformation() throws NotFoundException, FormatException {
  if (this.getInformation().getSize() < HEADER_SIZE + GTIN_SIZE) {
    throw NotFoundException.getNotFoundInstance();
  }

  StringBuilder buf = new StringBuilder();

  encodeCompressedGtin(buf, HEADER_SIZE);

  int lastAIdigit =
      this.getGeneralDecoder().extractNumericValueFromBitArray(HEADER_SIZE + GTIN_SIZE, LAST_DIGIT_SIZE);
  buf.append("(392");
  buf.append(lastAIdigit);
  buf.append(')');

  DecodedInformation decodedInformation =
      this.getGeneralDecoder().decodeGeneralPurposeField(HEADER_SIZE + GTIN_SIZE + LAST_DIGIT_SIZE, null);
  buf.append(decodedInformation.getNewString());

  return buf.toString();
}
项目:Tesseract-OCR-Scanner    文件:DecodedBitStreamParser.java   
private static int parseECIValue(BitSource bits) throws FormatException {
  int firstByte = bits.readBits(8);
  if ((firstByte & 0x80) == 0) {
    // just one byte
    return firstByte & 0x7F;
  }
  if ((firstByte & 0xC0) == 0x80) {
    // two bytes
    int secondByte = bits.readBits(8);
    return ((firstByte & 0x3F) << 8) | secondByte;
  }
  if ((firstByte & 0xE0) == 0xC0) {
    // three bytes
    int secondThirdBytes = bits.readBits(16);
    return ((firstByte & 0x1F) << 16) | secondThirdBytes;
  }
  throw FormatException.getFormatInstance();
}
项目:weex-3d-map    文件:GeneralAppIdDecoder.java   
String decodeAllCodes(StringBuilder buff, int initialPosition) throws NotFoundException, FormatException {
  int currentPosition = initialPosition;
  String remaining = null;
  do{
    DecodedInformation info = this.decodeGeneralPurposeField(currentPosition, remaining);
    String parsedFields = FieldParser.parseFieldsInGeneralPurpose(info.getNewString());
    if (parsedFields != null) {
      buff.append(parsedFields);
    }
    if(info.isRemaining()) {
      remaining = String.valueOf(info.getRemainingValue());
    } else {
      remaining = null;
    }

    if(currentPosition == info.getNewPosition()) {// No step forward!
      break;
    }
    currentPosition = info.getNewPosition();
  }while(true);

  return buff.toString();
}
项目:boohee_v5.6    文件:PDF417ScanningDecoder.java   
private static DetectionResult merge(DetectionResultRowIndicatorColumn
                                             leftRowIndicatorColumn,
                                     DetectionResultRowIndicatorColumn
                                             rightRowIndicatorColumn) throws
        NotFoundException, FormatException {
    if (leftRowIndicatorColumn == null && rightRowIndicatorColumn == null) {
        return null;
    }
    BarcodeMetadata barcodeMetadata = getBarcodeMetadata(leftRowIndicatorColumn,
            rightRowIndicatorColumn);
    if (barcodeMetadata != null) {
        return new DetectionResult(barcodeMetadata, BoundingBox.merge(adjustBoundingBox
                (leftRowIndicatorColumn), adjustBoundingBox(rightRowIndicatorColumn)));
    }
    return null;
}
项目:weex-3d-map    文件:OneDReader.java   
@Override
public Result decode(BinaryBitmap image,
                     Map<DecodeHintType,?> hints) throws NotFoundException, FormatException {
  try {
    return doDecode(image, hints);
  } catch (NotFoundException nfe) {
    boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);
    if (tryHarder && image.isRotateSupported()) {
      BinaryBitmap rotatedImage = image.rotateCounterClockwise();
      Result result = doDecode(rotatedImage, hints);
      // Record that we found it rotated 90 degrees CCW / 270 degrees CW
      Map<ResultMetadataType,?> metadata = result.getResultMetadata();
      int orientation = 270;
      if (metadata != null && metadata.containsKey(ResultMetadataType.ORIENTATION)) {
        // But if we found it reversed in doDecode(), add in that result here:
        orientation = (orientation +
            (Integer) metadata.get(ResultMetadataType.ORIENTATION)) % 360;
      }
      result.putMetadata(ResultMetadataType.ORIENTATION, orientation);
      // Update result points
      ResultPoint[] points = result.getResultPoints();
      if (points != null) {
        int height = rotatedImage.getHeight();
        for (int i = 0; i < points.length; i++) {
          points[i] = new ResultPoint(height - points[i].getY() - 1, points[i].getX());
        }
      }
      return result;
    } else {
      throw nfe;
    }
  }
}
项目:boohee_v5.6    文件:GeneralAppIdDecoder.java   
String decodeAllCodes(StringBuilder buff, int initialPosition) throws NotFoundException,
        FormatException {
    int currentPosition = initialPosition;
    String remaining = null;
    while (true) {
        DecodedInformation info = decodeGeneralPurposeField(currentPosition, remaining);
        String parsedFields = FieldParser.parseFieldsInGeneralPurpose(info.getNewString());
        if (parsedFields != null) {
            buff.append(parsedFields);
        }
        if (info.isRemaining()) {
            remaining = String.valueOf(info.getRemainingValue());
        } else {
            remaining = null;
        }
        if (currentPosition == info.getNewPosition()) {
            return buff.toString();
        }
        currentPosition = info.getNewPosition();
    }
}
项目:weex-3d-map    文件:MaxiCodeReader.java   
@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;
}
项目:weex-3d-map    文件:PDF417Reader.java   
@Override
public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints) throws NotFoundException, FormatException,
    ChecksumException {
  Result[] result = decode(image, hints, false);
  if (result == null || result.length == 0 || result[0] == null) {
    throw NotFoundException.getNotFoundInstance();
  }
  return result[0];
}
项目:Tesseract-OCR-Scanner    文件:DecodedNumeric.java   
DecodedNumeric(int newPosition, int firstDigit, int secondDigit) throws FormatException {
  super(newPosition);

  if (firstDigit < 0 || firstDigit > 10 || secondDigit < 0 || secondDigit > 10) {
    throw FormatException.getFormatInstance();
  }

  this.firstDigit  = firstDigit;
  this.secondDigit = secondDigit;
}
项目:boohee_v5.6    文件:Decoder.java   
private DecoderResult decode(BitMatrixParser parser, Map<DecodeHintType, ?> hints) throws
        FormatException, ChecksumException {
    Version version = parser.readVersion();
    ErrorCorrectionLevel ecLevel = parser.readFormatInformation().getErrorCorrectionLevel();
    DataBlock[] dataBlocks = DataBlock.getDataBlocks(parser.readCodewords(), version, ecLevel);
    int totalBytes = 0;
    for (DataBlock dataBlock : dataBlocks) {
        DataBlock dataBlock2;
        totalBytes += dataBlock2.getNumDataCodewords();
    }
    byte[] resultBytes = new byte[totalBytes];
    int resultOffset = 0;
    int length = dataBlocks.length;
    int i = 0;
    while (i < length) {
        dataBlock2 = dataBlocks[i];
        byte[] codewordBytes = dataBlock2.getCodewords();
        int numDataCodewords = dataBlock2.getNumDataCodewords();
        correctErrors(codewordBytes, numDataCodewords);
        int i2 = 0;
        int resultOffset2 = resultOffset;
        while (i2 < numDataCodewords) {
            resultOffset = resultOffset2 + 1;
            resultBytes[resultOffset2] = codewordBytes[i2];
            i2++;
            resultOffset2 = resultOffset;
        }
        i++;
        resultOffset = resultOffset2;
    }
    return DecodedBitStreamParser.decode(resultBytes, version, ecLevel, hints);
}
项目:boohee_v5.6    文件:UPCAReader.java   
private static Result maybeReturnResult(Result result) throws FormatException {
    String text = result.getText();
    if (text.charAt(0) == '0') {
        return new Result(text.substring(1), null, result.getResultPoints(), BarcodeFormat
                .UPC_A);
    }
    throw FormatException.getFormatInstance();
}
项目:boohee_v5.6    文件:RSSExpandedReader.java   
public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType, ?> map) throws
        NotFoundException, FormatException {
    this.pairs.clear();
    this.startFromEven = false;
    try {
        return constructResult(decodeRow2pairs(rowNumber, row));
    } catch (NotFoundException e) {
        this.pairs.clear();
        this.startFromEven = true;
        return constructResult(decodeRow2pairs(rowNumber, row));
    }
}
项目:weex-3d-map    文件:PDF417ScanningDecoder.java   
private static BoundingBox adjustBoundingBox(DetectionResultRowIndicatorColumn rowIndicatorColumn)
    throws NotFoundException, FormatException {
  if (rowIndicatorColumn == null) {
    return null;
  }
  int[] rowHeights = rowIndicatorColumn.getRowHeights();
  if (rowHeights == null) {
    return null;
  }
  int maxRowHeight = getMax(rowHeights);
  int missingStartRows = 0;
  for (int rowHeight : rowHeights) {
    missingStartRows += maxRowHeight - rowHeight;
    if (rowHeight > 0) {
      break;
    }
  }
  Codeword[] codewords = rowIndicatorColumn.getCodewords();
  for (int row = 0; missingStartRows > 0 && codewords[row] == null; row++) {
    missingStartRows--;
  }
  int missingEndRows = 0;
  for (int row = rowHeights.length - 1; row >= 0; row--) {
    missingEndRows += maxRowHeight - rowHeights[row];
    if (rowHeights[row] > 0) {
      break;
    }
  }
  for (int row = codewords.length - 1; missingEndRows > 0 && codewords[row] == null; row--) {
    missingEndRows--;
  }
  return rowIndicatorColumn.getBoundingBox().addMissingRows(missingStartRows, missingEndRows,
      rowIndicatorColumn.isLeft());
}
项目:boohee_v5.6    文件:RSSExpandedReader.java   
static Result constructResult(List<ExpandedPair> pairs) throws NotFoundException,
        FormatException {
    String resultingString = AbstractExpandedDecoder.createDecoder(BitArrayBuilder
            .buildBitArray(pairs)).parseInformation();
    ResultPoint[] firstPoints = ((ExpandedPair) pairs.get(0)).getFinderPattern()
            .getResultPoints();
    ResultPoint[] lastPoints = ((ExpandedPair) pairs.get(pairs.size() - 1)).getFinderPattern
            ().getResultPoints();
    return new Result(resultingString, null, new ResultPoint[]{firstPoints[0],
            firstPoints[1], lastPoints[0], lastPoints[1]}, BarcodeFormat.RSS_EXPANDED);
}
项目:boohee_v5.6    文件:Version.java   
public static Version getProvisionalVersionForDimension(int dimension) throws FormatException {
    if (dimension % 4 != 1) {
        throw FormatException.getFormatInstance();
    }
    try {
        return getVersionForNumber((dimension - 17) / 4);
    } catch (IllegalArgumentException e) {
        throw FormatException.getFormatInstance();
    }
}
项目:weex-3d-map    文件:QRCodeReader.java   
@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;
}
项目:weex-3d-map    文件:DecodedBitStreamParser.java   
private static void decodeByteSegment(BitSource bits,
                                      StringBuilder result,
                                      int count,
                                      CharacterSetECI currentCharacterSetECI,
                                      Collection<byte[]> byteSegments,
                                      Map<DecodeHintType,?> hints) throws FormatException {
  // Don't crash trying to read more bits than we have available.
  if (8 * count > bits.available()) {
    throw FormatException.getFormatInstance();
  }

  byte[] readBytes = new byte[count];
  for (int i = 0; i < count; i++) {
    readBytes[i] = (byte) bits.readBits(8);
  }
  String encoding;
  if (currentCharacterSetECI == null) {
    // The spec isn't clear on this mode; see
    // section 6.4.5: t does not say which encoding to assuming
    // upon decoding. I have seen ISO-8859-1 used as well as
    // Shift_JIS -- without anything like an ECI designator to
    // give a hint.
    encoding = StringUtils.guessEncoding(readBytes, hints);
  } else {
    encoding = currentCharacterSetECI.name();
  }
  try {
    result.append(new String(readBytes, encoding));
  } catch (UnsupportedEncodingException ignored) {
    throw FormatException.getFormatInstance();
  }
  byteSegments.add(readBytes);
}
项目:boohee_v5.6    文件:DecodedBitStreamParser.java   
private static int numericCompaction(int[] codewords, int codeIndex, StringBuilder result)
        throws FormatException {
    int count = 0;
    boolean end = false;
    int[] numericCodewords = new int[15];
    while (codeIndex < codewords[0] && !end) {
        int codeIndex2 = codeIndex + 1;
        int code = codewords[codeIndex];
        if (codeIndex2 == codewords[0]) {
            end = true;
        }
        if (code < TEXT_COMPACTION_MODE_LATCH) {
            numericCodewords[count] = code;
            count++;
            codeIndex = codeIndex2;
        } else if (code == TEXT_COMPACTION_MODE_LATCH || code == BYTE_COMPACTION_MODE_LATCH
                || code == BYTE_COMPACTION_MODE_LATCH_6 || code == 928 || code ==
                BEGIN_MACRO_PDF417_OPTIONAL_FIELD || code == MACRO_PDF417_TERMINATOR) {
            codeIndex = codeIndex2 - 1;
            end = true;
        } else {
            codeIndex = codeIndex2;
        }
        if ((count % 15 == 0 || code == NUMERIC_COMPACTION_MODE_LATCH || end) && count > 0) {
            result.append(decodeBase900toBase10(numericCodewords, count));
            count = 0;
        }
    }
    return codeIndex;
}
项目:weex-3d-map    文件:DecodedBitStreamParser.java   
private static void decodeAlphanumericSegment(BitSource bits,
                                              StringBuilder result,
                                              int count,
                                              boolean fc1InEffect) throws FormatException {
  // Read two characters at a time
  int start = result.length();
  while (count > 1) {
    if (bits.available() < 11) {
      throw FormatException.getFormatInstance();
    }
    int nextTwoCharsBits = bits.readBits(11);
    result.append(toAlphaNumericChar(nextTwoCharsBits / 45));
    result.append(toAlphaNumericChar(nextTwoCharsBits % 45));
    count -= 2;
  }
  if (count == 1) {
    // special case: one character left
    if (bits.available() < 6) {
      throw FormatException.getFormatInstance();
    }
    result.append(toAlphaNumericChar(bits.readBits(6)));
  }
  // See section 6.4.8.1, 6.4.8.2
  if (fc1InEffect) {
    // We need to massage the result a bit if in an FNC1 mode:
    for (int i = start; i < result.length(); i++) {
      if (result.charAt(i) == '%') {
        if (i < result.length() - 1 && result.charAt(i + 1) == '%') {
          // %% is rendered as %
          result.deleteCharAt(i + 1);
        } else {
          // In alpha mode, % should be converted to FNC1 separator 0x1D
          result.setCharAt(i, (char) 0x1D);
        }
      }
    }
  }
}
项目:boohee_v5.6    文件:QRCodeReader.java   
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)) {
        DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect(hints);
        decoderResult = this.decoder.decode(detectorResult.getBits(), (Map) hints);
        points = detectorResult.getPoints();
    } else {
        decoderResult = this.decoder.decode(extractPureBits(image.getBlackMatrix()), (Map)
                hints);
        points = NO_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, Integer.valueOf
                (decoderResult.getStructuredAppendSequenceNumber()));
        result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_PARITY, Integer.valueOf
                (decoderResult.getStructuredAppendParity()));
    }
    return result;
}
项目:boohee_v5.6    文件:Decoder.java   
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[i][j]) {
                bits.set(j, i);
            }
        }
    }
    return decode(bits);
}
项目:boohee_v5.6    文件:AI01AndOtherAIs.java   
public String parseInformation() throws NotFoundException, FormatException {
    StringBuilder buff = new StringBuilder();
    buff.append("(01)");
    int initialGtinPosition = buff.length();
    buff.append(getGeneralDecoder().extractNumericValueFromBitArray(4, 4));
    encodeCompressedGtinWithoutAI(buff, 8, initialGtinPosition);
    return getGeneralDecoder().decodeAllCodes(buff, 48);
}
项目:boohee_v5.6    文件:MaxiCodeReader.java   
public Result decode(BinaryBitmap image, Map<DecodeHintType, ?> hints) throws
        NotFoundException, ChecksumException, FormatException {
    if (hints == null || !hints.containsKey(DecodeHintType.PURE_BARCODE)) {
        throw NotFoundException.getNotFoundInstance();
    }
    DecoderResult decoderResult = this.decoder.decode(extractPureBits(image.getBlackMatrix())
            , hints);
    Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(),
            NO_POINTS, BarcodeFormat.MAXICODE);
    String ecLevel = decoderResult.getECLevel();
    if (ecLevel != null) {
        result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
    }
    return result;
}
项目:weex-3d-map    文件:UPCAReader.java   
@Override
public Result decodeRow(int rowNumber,
                        BitArray row,
                        int[] startGuardRange,
                        Map<DecodeHintType,?> hints)
    throws NotFoundException, FormatException, ChecksumException {
  return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, startGuardRange, hints));
}
项目:QrCode    文件:UPCEANReader.java   
/**
 * Computes the UPC/EAN checksum on a string of digits, and reports
 * whether the checksum is correct or not.
 *
 * @param s string of digits to check
 * @return true iff string of digits passes the UPC/EAN checksum algorithm
 * @throws FormatException if the string does not contain only digits
 */
static boolean checkStandardUPCEANChecksum(CharSequence s) throws FormatException {
  int length = s.length();
  if (length == 0) {
    return false;
  }
  int check = Character.digit(s.charAt(length - 1), 10);
  return getStandardUPCEANChecksum(s.subSequence(0, length - 1)) == check;
}
项目:Tesseract-OCR-Scanner    文件:DecodedBitStreamParser.java   
private static void decodeKanjiSegment(BitSource bits,
                                       StringBuilder result,
                                       int count) throws FormatException {
  // Don't crash trying to read more bits than we have available.
  if (count * 13 > bits.available()) {
    throw FormatException.getFormatInstance();
  }

  // Each character will require 2 bytes. Read the characters as 2-byte pairs
  // and decode as Shift_JIS afterwards
  byte[] buffer = new byte[2 * count];
  int offset = 0;
  while (count > 0) {
    // Each 13 bits encodes a 2-byte character
    int twoBytes = bits.readBits(13);
    int assembledTwoBytes = ((twoBytes / 0x0C0) << 8) | (twoBytes % 0x0C0);
    if (assembledTwoBytes < 0x01F00) {
      // In the 0x8140 to 0x9FFC range
      assembledTwoBytes += 0x08140;
    } else {
      // In the 0xE040 to 0xEBBF range
      assembledTwoBytes += 0x0C140;
    }
    buffer[offset] = (byte) (assembledTwoBytes >> 8);
    buffer[offset + 1] = (byte) assembledTwoBytes;
    offset += 2;
    count--;
  }
  // Shift_JIS may not be supported in some environments:
  try {
    result.append(new String(buffer, StringUtils.SHIFT_JIS));
  } catch (UnsupportedEncodingException ignored) {
    throw FormatException.getFormatInstance();
  }
}
项目:boohee_v5.6    文件:Decoder.java   
public DecoderResult decode(boolean[][] image, Map<DecodeHintType, ?> hints) throws
        ChecksumException, FormatException {
    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[i][j]) {
                bits.set(j, i);
            }
        }
    }
    return decode(bits, (Map) hints);
}
项目:QrCode    文件:DecodedNumeric.java   
DecodedNumeric(int newPosition, int firstDigit, int secondDigit) throws FormatException {
  super(newPosition);

  if (firstDigit < 0 || firstDigit > 10 || secondDigit < 0 || secondDigit > 10) {
    throw FormatException.getFormatInstance();
  }

  this.firstDigit  = firstDigit;
  this.secondDigit = secondDigit;
}
项目:weex-3d-map    文件:DecodedNumeric.java   
DecodedNumeric(int newPosition, int firstDigit, int secondDigit) throws FormatException {
  super(newPosition);

  if (firstDigit < 0 || firstDigit > 10 || secondDigit < 0 || secondDigit > 10) {
    throw FormatException.getFormatInstance();
  }

  this.firstDigit  = firstDigit;
  this.secondDigit = secondDigit;
}
项目:boohee_v5.6    文件:DecodedNumeric.java   
DecodedNumeric(int newPosition, int firstDigit, int secondDigit) throws FormatException {
    super(newPosition);
    if (firstDigit < 0 || firstDigit > 10 || secondDigit < 0 || secondDigit > 10) {
        throw FormatException.getFormatInstance();
    }
    this.firstDigit = firstDigit;
    this.secondDigit = secondDigit;
}
项目:boohee_v5.6    文件:UPCEANReader.java   
static boolean checkStandardUPCEANChecksum(CharSequence s) throws FormatException {
    int length = s.length();
    if (length == 0) {
        return false;
    }
    int i;
    int sum = 0;
    for (i = length - 2; i >= 0; i -= 2) {
        int digit = s.charAt(i) - 48;
        if (digit < 0 || digit > 9) {
            throw FormatException.getFormatInstance();
        }
        sum += digit;
    }
    sum *= 3;
    for (i = length - 1; i >= 0; i -= 2) {
        digit = s.charAt(i) - 48;
        if (digit < 0 || digit > 9) {
            throw FormatException.getFormatInstance();
        }
        sum += digit;
    }
    if (sum % 10 == 0) {
        return true;
    }
    return false;
}
项目:QrCode    文件:UPCAReader.java   
@Override
public Result decodeRow(int rowNumber,
                        BitArray row,
                        int[] startGuardRange,
                        Map<DecodeHintType,?> hints)
    throws NotFoundException, FormatException, ChecksumException {
  return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, startGuardRange, hints));
}
项目:boohee_v5.6    文件:PDF417ScanningDecoder.java   
private static BoundingBox adjustBoundingBox(DetectionResultRowIndicatorColumn
                                                     rowIndicatorColumn) throws
        NotFoundException, FormatException {
    if (rowIndicatorColumn == null) {
        return null;
    }
    int[] rowHeights = rowIndicatorColumn.getRowHeights();
    if (rowHeights == null) {
        return null;
    }
    int maxRowHeight = getMax(rowHeights);
    int missingStartRows = 0;
    for (int rowHeight : rowHeights) {
        missingStartRows += maxRowHeight - rowHeight;
        if (rowHeight > 0) {
            break;
        }
    }
    Codeword[] codewords = rowIndicatorColumn.getCodewords();
    int row = 0;
    while (missingStartRows > 0 && codewords[row] == null) {
        missingStartRows--;
        row++;
    }
    int missingEndRows = 0;
    for (row = rowHeights.length - 1; row >= 0; row--) {
        missingEndRows += maxRowHeight - rowHeights[row];
        if (rowHeights[row] > 0) {
            break;
        }
    }
    row = codewords.length - 1;
    while (missingEndRows > 0 && codewords[row] == null) {
        missingEndRows--;
        row--;
    }
    return rowIndicatorColumn.getBoundingBox().addMissingRows(missingStartRows,
            missingEndRows, rowIndicatorColumn.isLeft());
}
项目:QrCode    文件:GeneralAppIdDecoder.java   
DecodedInformation decodeGeneralPurposeField(int pos, String remaining) throws FormatException {
  this.buffer.setLength(0);

  if (remaining != null) {
    this.buffer.append(remaining);
  }

  this.current.setPosition(pos);

  DecodedInformation lastDecoded = parseBlocks();
  if (lastDecoded != null && lastDecoded.isRemaining()) {
    return new DecodedInformation(this.current.getPosition(), this.buffer.toString(), lastDecoded.getRemainingValue());
  }
  return new DecodedInformation(this.current.getPosition(), this.buffer.toString());
}
项目:Tesseract-OCR-Scanner    文件:DecodedBitStreamParser.java   
private static void decodeByteSegment(BitSource bits,
                                      StringBuilder result,
                                      int count,
                                      CharacterSetECI currentCharacterSetECI,
                                      Collection<byte[]> byteSegments,
                                      Map<DecodeHintType,?> hints) throws FormatException {
  // Don't crash trying to read more bits than we have available.
  if (8 * count > bits.available()) {
    throw FormatException.getFormatInstance();
  }

  byte[] readBytes = new byte[count];
  for (int i = 0; i < count; i++) {
    readBytes[i] = (byte) bits.readBits(8);
  }
  String encoding;
  if (currentCharacterSetECI == null) {
    // The spec isn't clear on this mode; see
    // section 6.4.5: t does not say which encoding to assuming
    // upon decoding. I have seen ISO-8859-1 used as well as
    // Shift_JIS -- without anything like an ECI designator to
    // give a hint.
    encoding = StringUtils.guessEncoding(readBytes, hints);
  } else {
    encoding = currentCharacterSetECI.name();
  }
  try {
    result.append(new String(readBytes, encoding));
  } catch (UnsupportedEncodingException ignored) {
    throw FormatException.getFormatInstance();
  }
  byteSegments.add(readBytes);
}