类com.google.zxing.pdf417.PDF417Common源码实例Demo

下面列出了怎么用com.google.zxing.pdf417.PDF417Common的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: ZXing-Orient   文件: PDF417CodewordDecoder.java
private static int[] sampleBitCounts(int[] moduleBitCount) {
  float bitCountSum = PDF417Common.getBitCountSum(moduleBitCount);
  int[] result = new int[PDF417Common.BARS_IN_MODULE];
  int bitCountIndex = 0;
  int sumPreviousBits = 0;
  for (int i = 0; i < PDF417Common.MODULES_IN_CODEWORD; i++) {
    float sampleIndex = 
        bitCountSum / (2 * PDF417Common.MODULES_IN_CODEWORD) + 
        (i * bitCountSum) / PDF417Common.MODULES_IN_CODEWORD;
    if (sumPreviousBits + moduleBitCount[bitCountIndex] <= sampleIndex) {
      sumPreviousBits += moduleBitCount[bitCountIndex];
      bitCountIndex++;
    }
    result[bitCountIndex]++;
  }
  return result;
}
 
源代码2 项目: ZXing-Orient   文件: PDF417CodewordDecoder.java
private static int getClosestDecodedValue(int[] moduleBitCount) {
  int bitCountSum = PDF417Common.getBitCountSum(moduleBitCount);
  float[] bitCountRatios = new float[PDF417Common.BARS_IN_MODULE];
  for (int i = 0; i < bitCountRatios.length; i++) {
    bitCountRatios[i] = moduleBitCount[i] / (float) bitCountSum;
  }
  float bestMatchError = Float.MAX_VALUE;
  int bestMatch = -1;
  for (int j = 0; j < RATIOS_TABLE.length; j++) {
    float error = 0.0f;
    float[] ratioTableRow = RATIOS_TABLE[j];
    for (int k = 0; k < PDF417Common.BARS_IN_MODULE; k++) {
      float diff = ratioTableRow[k] - bitCountRatios[k];
      error += diff * diff;
      if (error >= bestMatchError) {
        break;
      }
    }
    if (error < bestMatchError) {
      bestMatchError = error;
      bestMatch = PDF417Common.SYMBOL_TABLE[j];
    }
  }
  return bestMatch;
}
 
源代码3 项目: ZXing-Orient   文件: PDF417ScanningDecoder.java
private static void adjustCodewordCount(DetectionResult detectionResult, BarcodeValue[][] barcodeMatrix)
    throws NotFoundException {
  int[] numberOfCodewords = barcodeMatrix[0][1].getValue();
  int calculatedNumberOfCodewords = detectionResult.getBarcodeColumnCount() *
      detectionResult.getBarcodeRowCount() -
      getNumberOfECCodeWords(detectionResult.getBarcodeECLevel());
  if (numberOfCodewords.length == 0) {
    if (calculatedNumberOfCodewords < 1 || calculatedNumberOfCodewords > PDF417Common.MAX_CODEWORDS_IN_BARCODE) {
      throw NotFoundException.getNotFoundInstance();
    }
    barcodeMatrix[0][1].setValue(calculatedNumberOfCodewords);
  } else if (numberOfCodewords[0] != calculatedNumberOfCodewords) {
    // The calculated one is more reliable as it is derived from the row indicator columns
    barcodeMatrix[0][1].setValue(calculatedNumberOfCodewords);
  }
}
 
private static int[] sampleBitCounts(int[] moduleBitCount) {
  float bitCountSum = PDF417Common.getBitCountSum(moduleBitCount);
  int[] result = new int[PDF417Common.BARS_IN_MODULE];
  int bitCountIndex = 0;
  int sumPreviousBits = 0;
  for (int i = 0; i < PDF417Common.MODULES_IN_CODEWORD; i++) {
    float sampleIndex = 
        bitCountSum / (2 * PDF417Common.MODULES_IN_CODEWORD) + 
        (i * bitCountSum) / PDF417Common.MODULES_IN_CODEWORD;
    if (sumPreviousBits + moduleBitCount[bitCountIndex] <= sampleIndex) {
      sumPreviousBits += moduleBitCount[bitCountIndex];
      bitCountIndex++;
    }
    result[bitCountIndex]++;
  }
  return result;
}
 
private static int getClosestDecodedValue(int[] moduleBitCount) {
  int bitCountSum = PDF417Common.getBitCountSum(moduleBitCount);
  float[] bitCountRatios = new float[PDF417Common.BARS_IN_MODULE];
  for (int i = 0; i < bitCountRatios.length; i++) {
    bitCountRatios[i] = moduleBitCount[i] / (float) bitCountSum;
  }
  float bestMatchError = Float.MAX_VALUE;
  int bestMatch = -1;
  for (int j = 0; j < RATIOS_TABLE.length; j++) {
    float error = 0.0f;
    float[] ratioTableRow = RATIOS_TABLE[j];
    for (int k = 0; k < PDF417Common.BARS_IN_MODULE; k++) {
      float diff = ratioTableRow[k] - bitCountRatios[k];
      error += diff * diff;
      if (error >= bestMatchError) {
        break;
      }
    }
    if (error < bestMatchError) {
      bestMatchError = error;
      bestMatch = PDF417Common.SYMBOL_TABLE[j];
    }
  }
  return bestMatch;
}
 
private static void adjustCodewordCount(DetectionResult detectionResult, BarcodeValue[][] barcodeMatrix)
    throws NotFoundException {
  int[] numberOfCodewords = barcodeMatrix[0][1].getValue();
  int calculatedNumberOfCodewords = detectionResult.getBarcodeColumnCount() *
      detectionResult.getBarcodeRowCount() -
      getNumberOfECCodeWords(detectionResult.getBarcodeECLevel());
  if (numberOfCodewords.length == 0) {
    if (calculatedNumberOfCodewords < 1 || calculatedNumberOfCodewords > PDF417Common.MAX_CODEWORDS_IN_BARCODE) {
      throw NotFoundException.getNotFoundInstance();
    }
    barcodeMatrix[0][1].setValue(calculatedNumberOfCodewords);
  } else if (numberOfCodewords[0] != calculatedNumberOfCodewords) {
    // The calculated one is more reliable as it is derived from the row indicator columns
    barcodeMatrix[0][1].setValue(calculatedNumberOfCodewords);
  }
}
 
源代码7 项目: weex   文件: PDF417CodewordDecoder.java
private static int[] sampleBitCounts(int[] moduleBitCount) {
  float bitCountSum = PDF417Common.getBitCountSum(moduleBitCount);
  int[] result = new int[PDF417Common.BARS_IN_MODULE];
  int bitCountIndex = 0;
  int sumPreviousBits = 0;
  for (int i = 0; i < PDF417Common.MODULES_IN_CODEWORD; i++) {
    float sampleIndex = 
        bitCountSum / (2 * PDF417Common.MODULES_IN_CODEWORD) + 
        (i * bitCountSum) / PDF417Common.MODULES_IN_CODEWORD;
    if (sumPreviousBits + moduleBitCount[bitCountIndex] <= sampleIndex) {
      sumPreviousBits += moduleBitCount[bitCountIndex];
      bitCountIndex++;
    }
    result[bitCountIndex]++;
  }
  return result;
}
 
源代码8 项目: weex   文件: PDF417CodewordDecoder.java
private static int getClosestDecodedValue(int[] moduleBitCount) {
  int bitCountSum = PDF417Common.getBitCountSum(moduleBitCount);
  float[] bitCountRatios = new float[PDF417Common.BARS_IN_MODULE];
  for (int i = 0; i < bitCountRatios.length; i++) {
    bitCountRatios[i] = moduleBitCount[i] / (float) bitCountSum;
  }
  float bestMatchError = Float.MAX_VALUE;
  int bestMatch = -1;
  for (int j = 0; j < RATIOS_TABLE.length; j++) {
    float error = 0.0f;
    float[] ratioTableRow = RATIOS_TABLE[j];
    for (int k = 0; k < PDF417Common.BARS_IN_MODULE; k++) {
      float diff = ratioTableRow[k] - bitCountRatios[k];
      error += diff * diff;
      if (error >= bestMatchError) {
        break;
      }
    }
    if (error < bestMatchError) {
      bestMatchError = error;
      bestMatch = PDF417Common.SYMBOL_TABLE[j];
    }
  }
  return bestMatch;
}
 
源代码9 项目: weex   文件: PDF417ScanningDecoder.java
private static void adjustCodewordCount(DetectionResult detectionResult, BarcodeValue[][] barcodeMatrix)
    throws NotFoundException {
  int[] numberOfCodewords = barcodeMatrix[0][1].getValue();
  int calculatedNumberOfCodewords = detectionResult.getBarcodeColumnCount() *
      detectionResult.getBarcodeRowCount() -
      getNumberOfECCodeWords(detectionResult.getBarcodeECLevel());
  if (numberOfCodewords.length == 0) {
    if (calculatedNumberOfCodewords < 1 || calculatedNumberOfCodewords > PDF417Common.MAX_CODEWORDS_IN_BARCODE) {
      throw NotFoundException.getNotFoundInstance();
    }
    barcodeMatrix[0][1].setValue(calculatedNumberOfCodewords);
  } else if (numberOfCodewords[0] != calculatedNumberOfCodewords) {
    // The calculated one is more reliable as it is derived from the row indicator columns
    barcodeMatrix[0][1].setValue(calculatedNumberOfCodewords);
  }
}
 
private static int[] sampleBitCounts(int[] moduleBitCount) {
  float bitCountSum = MathUtils.sum(moduleBitCount);
  int[] result = new int[PDF417Common.BARS_IN_MODULE];
  int bitCountIndex = 0;
  int sumPreviousBits = 0;
  for (int i = 0; i < PDF417Common.MODULES_IN_CODEWORD; i++) {
    float sampleIndex = 
        bitCountSum / (2 * PDF417Common.MODULES_IN_CODEWORD) + 
        (i * bitCountSum) / PDF417Common.MODULES_IN_CODEWORD;
    if (sumPreviousBits + moduleBitCount[bitCountIndex] <= sampleIndex) {
      sumPreviousBits += moduleBitCount[bitCountIndex];
      bitCountIndex++;
    }
    result[bitCountIndex]++;
  }
  return result;
}
 
private static int getClosestDecodedValue(int[] moduleBitCount) {
  int bitCountSum = MathUtils.sum(moduleBitCount);
  float[] bitCountRatios = new float[PDF417Common.BARS_IN_MODULE];
  for (int i = 0; i < bitCountRatios.length; i++) {
    bitCountRatios[i] = moduleBitCount[i] / (float) bitCountSum;
  }
  float bestMatchError = Float.MAX_VALUE;
  int bestMatch = -1;
  for (int j = 0; j < RATIOS_TABLE.length; j++) {
    float error = 0.0f;
    float[] ratioTableRow = RATIOS_TABLE[j];
    for (int k = 0; k < PDF417Common.BARS_IN_MODULE; k++) {
      float diff = ratioTableRow[k] - bitCountRatios[k];
      error += diff * diff;
      if (error >= bestMatchError) {
        break;
      }
    }
    if (error < bestMatchError) {
      bestMatchError = error;
      bestMatch = PDF417Common.SYMBOL_TABLE[j];
    }
  }
  return bestMatch;
}
 
private static void adjustCodewordCount(DetectionResult detectionResult, BarcodeValue[][] barcodeMatrix)
    throws NotFoundException {
  int[] numberOfCodewords = barcodeMatrix[0][1].getValue();
  int calculatedNumberOfCodewords = detectionResult.getBarcodeColumnCount() *
      detectionResult.getBarcodeRowCount() -
      getNumberOfECCodeWords(detectionResult.getBarcodeECLevel());
  if (numberOfCodewords.length == 0) {
    if (calculatedNumberOfCodewords < 1 || calculatedNumberOfCodewords > PDF417Common.MAX_CODEWORDS_IN_BARCODE) {
      throw NotFoundException.getNotFoundInstance();
    }
    barcodeMatrix[0][1].setValue(calculatedNumberOfCodewords);
  } else if (numberOfCodewords[0] != calculatedNumberOfCodewords) {
    // The calculated one is more reliable as it is derived from the row indicator columns
    barcodeMatrix[0][1].setValue(calculatedNumberOfCodewords);
  }
}
 
源代码13 项目: ZXing-Orient   文件: PDF417ScanningDecoder.java
private static DecoderResult createDecoderResult(DetectionResult detectionResult) throws FormatException,
    ChecksumException, NotFoundException {
  BarcodeValue[][] barcodeMatrix = createBarcodeMatrix(detectionResult);
  adjustCodewordCount(detectionResult, barcodeMatrix);
  Collection<Integer> erasures = new ArrayList<>();
  int[] codewords = new int[detectionResult.getBarcodeRowCount() * detectionResult.getBarcodeColumnCount()];
  List<int[]> ambiguousIndexValuesList = new ArrayList<>();
  List<Integer> ambiguousIndexesList = new ArrayList<>();
  for (int row = 0; row < detectionResult.getBarcodeRowCount(); row++) {
    for (int column = 0; column < detectionResult.getBarcodeColumnCount(); column++) {
      int[] values = barcodeMatrix[row][column + 1].getValue();
      int codewordIndex = row * detectionResult.getBarcodeColumnCount() + column;
      if (values.length == 0) {
        erasures.add(codewordIndex);
      } else if (values.length == 1) {
        codewords[codewordIndex] = values[0];
      } else {
        ambiguousIndexesList.add(codewordIndex);
        ambiguousIndexValuesList.add(values);
      }
    }
  }
  int[][] ambiguousIndexValues = new int[ambiguousIndexValuesList.size()][];
  for (int i = 0; i < ambiguousIndexValues.length; i++) {
    ambiguousIndexValues[i] = ambiguousIndexValuesList.get(i);
  }
  return createDecoderResultFromAmbiguousValues(detectionResult.getBarcodeECLevel(), codewords,
      PDF417Common.toIntArray(erasures), PDF417Common.toIntArray(ambiguousIndexesList), ambiguousIndexValues);
}
 
源代码14 项目: ZXing-Orient   文件: BarcodeValue.java
/**
 * Determines the maximum occurrence of a set value and returns all values which were set with this occurrence. 
 * @return an array of int, containing the values with the highest occurrence, or null, if no value was set
 */
int[] getValue() {
  int maxConfidence = -1;
  Collection<Integer> result = new ArrayList<>();
  for (Entry<Integer,Integer> entry : values.entrySet()) {
    if (entry.getValue() > maxConfidence) {
      maxConfidence = entry.getValue();
      result.clear();
      result.add(entry.getKey());
    } else if (entry.getValue() == maxConfidence) {
      result.add(entry.getKey());
    }
  }
  return PDF417Common.toIntArray(result);
}
 
源代码15 项目: ZXing-Orient   文件: DetectionResult.java
DetectionResultColumn[] getDetectionResultColumns() {
  adjustIndicatorColumnRowNumbers(detectionResultColumns[0]);
  adjustIndicatorColumnRowNumbers(detectionResultColumns[barcodeColumnCount + 1]);
  int unadjustedCodewordCount = PDF417Common.MAX_CODEWORDS_IN_BARCODE;
  int previousUnadjustedCount;
  do {
    previousUnadjustedCount = unadjustedCodewordCount;
    unadjustedCodewordCount = adjustRowNumbers();
  } while (unadjustedCodewordCount > 0 && unadjustedCodewordCount < previousUnadjustedCount);
  return detectionResultColumns;
}
 
private static DecoderResult createDecoderResult(DetectionResult detectionResult) throws FormatException,
    ChecksumException, NotFoundException {
  BarcodeValue[][] barcodeMatrix = createBarcodeMatrix(detectionResult);
  adjustCodewordCount(detectionResult, barcodeMatrix);
  Collection<Integer> erasures = new ArrayList<>();
  int[] codewords = new int[detectionResult.getBarcodeRowCount() * detectionResult.getBarcodeColumnCount()];
  List<int[]> ambiguousIndexValuesList = new ArrayList<>();
  List<Integer> ambiguousIndexesList = new ArrayList<>();
  for (int row = 0; row < detectionResult.getBarcodeRowCount(); row++) {
    for (int column = 0; column < detectionResult.getBarcodeColumnCount(); column++) {
      int[] values = barcodeMatrix[row][column + 1].getValue();
      int codewordIndex = row * detectionResult.getBarcodeColumnCount() + column;
      if (values.length == 0) {
        erasures.add(codewordIndex);
      } else if (values.length == 1) {
        codewords[codewordIndex] = values[0];
      } else {
        ambiguousIndexesList.add(codewordIndex);
        ambiguousIndexValuesList.add(values);
      }
    }
  }
  int[][] ambiguousIndexValues = new int[ambiguousIndexValuesList.size()][];
  for (int i = 0; i < ambiguousIndexValues.length; i++) {
    ambiguousIndexValues[i] = ambiguousIndexValuesList.get(i);
  }
  return createDecoderResultFromAmbiguousValues(detectionResult.getBarcodeECLevel(), codewords,
      PDF417Common.toIntArray(erasures), PDF417Common.toIntArray(ambiguousIndexesList), ambiguousIndexValues);
}
 
/**
 * Determines the maximum occurrence of a set value and returns all values which were set with this occurrence. 
 * @return an array of int, containing the values with the highest occurrence, or null, if no value was set
 */
int[] getValue() {
  int maxConfidence = -1;
  Collection<Integer> result = new ArrayList<>();
  for (Entry<Integer,Integer> entry : values.entrySet()) {
    if (entry.getValue() > maxConfidence) {
      maxConfidence = entry.getValue();
      result.clear();
      result.add(entry.getKey());
    } else if (entry.getValue() == maxConfidence) {
      result.add(entry.getKey());
    }
  }
  return PDF417Common.toIntArray(result);
}
 
DetectionResultColumn[] getDetectionResultColumns() {
  adjustIndicatorColumnRowNumbers(detectionResultColumns[0]);
  adjustIndicatorColumnRowNumbers(detectionResultColumns[barcodeColumnCount + 1]);
  int unadjustedCodewordCount = PDF417Common.MAX_CODEWORDS_IN_BARCODE;
  int previousUnadjustedCount;
  do {
    previousUnadjustedCount = unadjustedCodewordCount;
    unadjustedCodewordCount = adjustRowNumbers();
  } while (unadjustedCodewordCount > 0 && unadjustedCodewordCount < previousUnadjustedCount);
  return detectionResultColumns;
}
 
源代码19 项目: weex   文件: PDF417ScanningDecoder.java
private static DecoderResult createDecoderResult(DetectionResult detectionResult) throws FormatException,
    ChecksumException, NotFoundException {
  BarcodeValue[][] barcodeMatrix = createBarcodeMatrix(detectionResult);
  adjustCodewordCount(detectionResult, barcodeMatrix);
  Collection<Integer> erasures = new ArrayList<>();
  int[] codewords = new int[detectionResult.getBarcodeRowCount() * detectionResult.getBarcodeColumnCount()];
  List<int[]> ambiguousIndexValuesList = new ArrayList<>();
  List<Integer> ambiguousIndexesList = new ArrayList<>();
  for (int row = 0; row < detectionResult.getBarcodeRowCount(); row++) {
    for (int column = 0; column < detectionResult.getBarcodeColumnCount(); column++) {
      int[] values = barcodeMatrix[row][column + 1].getValue();
      int codewordIndex = row * detectionResult.getBarcodeColumnCount() + column;
      if (values.length == 0) {
        erasures.add(codewordIndex);
      } else if (values.length == 1) {
        codewords[codewordIndex] = values[0];
      } else {
        ambiguousIndexesList.add(codewordIndex);
        ambiguousIndexValuesList.add(values);
      }
    }
  }
  int[][] ambiguousIndexValues = new int[ambiguousIndexValuesList.size()][];
  for (int i = 0; i < ambiguousIndexValues.length; i++) {
    ambiguousIndexValues[i] = ambiguousIndexValuesList.get(i);
  }
  return createDecoderResultFromAmbiguousValues(detectionResult.getBarcodeECLevel(), codewords,
      PDF417Common.toIntArray(erasures), PDF417Common.toIntArray(ambiguousIndexesList), ambiguousIndexValues);
}
 
源代码20 项目: weex   文件: BarcodeValue.java
/**
 * Determines the maximum occurrence of a set value and returns all values which were set with this occurrence. 
 * @return an array of int, containing the values with the highest occurrence, or null, if no value was set
 */
int[] getValue() {
  int maxConfidence = -1;
  Collection<Integer> result = new ArrayList<>();
  for (Entry<Integer,Integer> entry : values.entrySet()) {
    if (entry.getValue() > maxConfidence) {
      maxConfidence = entry.getValue();
      result.clear();
      result.add(entry.getKey());
    } else if (entry.getValue() == maxConfidence) {
      result.add(entry.getKey());
    }
  }
  return PDF417Common.toIntArray(result);
}
 
源代码21 项目: weex   文件: DetectionResult.java
DetectionResultColumn[] getDetectionResultColumns() {
  adjustIndicatorColumnRowNumbers(detectionResultColumns[0]);
  adjustIndicatorColumnRowNumbers(detectionResultColumns[barcodeColumnCount + 1]);
  int unadjustedCodewordCount = PDF417Common.MAX_CODEWORDS_IN_BARCODE;
  int previousUnadjustedCount;
  do {
    previousUnadjustedCount = unadjustedCodewordCount;
    unadjustedCodewordCount = adjustRowNumbers();
  } while (unadjustedCodewordCount > 0 && unadjustedCodewordCount < previousUnadjustedCount);
  return detectionResultColumns;
}
 
private static DecoderResult createDecoderResult(DetectionResult detectionResult) throws FormatException,
    ChecksumException, NotFoundException {
  BarcodeValue[][] barcodeMatrix = createBarcodeMatrix(detectionResult);
  adjustCodewordCount(detectionResult, barcodeMatrix);
  Collection<Integer> erasures = new ArrayList<>();
  int[] codewords = new int[detectionResult.getBarcodeRowCount() * detectionResult.getBarcodeColumnCount()];
  List<int[]> ambiguousIndexValuesList = new ArrayList<>();
  List<Integer> ambiguousIndexesList = new ArrayList<>();
  for (int row = 0; row < detectionResult.getBarcodeRowCount(); row++) {
    for (int column = 0; column < detectionResult.getBarcodeColumnCount(); column++) {
      int[] values = barcodeMatrix[row][column + 1].getValue();
      int codewordIndex = row * detectionResult.getBarcodeColumnCount() + column;
      if (values.length == 0) {
        erasures.add(codewordIndex);
      } else if (values.length == 1) {
        codewords[codewordIndex] = values[0];
      } else {
        ambiguousIndexesList.add(codewordIndex);
        ambiguousIndexValuesList.add(values);
      }
    }
  }
  int[][] ambiguousIndexValues = new int[ambiguousIndexValuesList.size()][];
  for (int i = 0; i < ambiguousIndexValues.length; i++) {
    ambiguousIndexValues[i] = ambiguousIndexValuesList.get(i);
  }
  return createDecoderResultFromAmbiguousValues(detectionResult.getBarcodeECLevel(), codewords,
      PDF417Common.toIntArray(erasures), PDF417Common.toIntArray(ambiguousIndexesList), ambiguousIndexValues);
}
 
源代码23 项目: barcodescanner-lib-aar   文件: BarcodeValue.java
/**
 * Determines the maximum occurrence of a set value and returns all values which were set with this occurrence. 
 * @return an array of int, containing the values with the highest occurrence, or null, if no value was set
 */
int[] getValue() {
  int maxConfidence = -1;
  Collection<Integer> result = new ArrayList<>();
  for (Entry<Integer,Integer> entry : values.entrySet()) {
    if (entry.getValue() > maxConfidence) {
      maxConfidence = entry.getValue();
      result.clear();
      result.add(entry.getKey());
    } else if (entry.getValue() == maxConfidence) {
      result.add(entry.getKey());
    }
  }
  return PDF417Common.toIntArray(result);
}
 
源代码24 项目: barcodescanner-lib-aar   文件: DetectionResult.java
DetectionResultColumn[] getDetectionResultColumns() {
  adjustIndicatorColumnRowNumbers(detectionResultColumns[0]);
  adjustIndicatorColumnRowNumbers(detectionResultColumns[barcodeColumnCount + 1]);
  int unadjustedCodewordCount = PDF417Common.MAX_CODEWORDS_IN_BARCODE;
  int previousUnadjustedCount;
  do {
    previousUnadjustedCount = unadjustedCodewordCount;
    unadjustedCodewordCount = adjustRowNumbers();
  } while (unadjustedCodewordCount > 0 && unadjustedCodewordCount < previousUnadjustedCount);
  return detectionResultColumns;
}
 
源代码25 项目: ZXing-Orient   文件: PDF417CodewordDecoder.java
private static int getDecodedCodewordValue(int[] moduleBitCount) {
  int decodedValue = getBitValue(moduleBitCount);
  return PDF417Common.getCodeword(decodedValue) == -1 ? -1 : decodedValue;
}
 
BarcodeMetadata getBarcodeMetadata() {
  Codeword[] codewords = getCodewords();
  BarcodeValue barcodeColumnCount = new BarcodeValue();
  BarcodeValue barcodeRowCountUpperPart = new BarcodeValue();
  BarcodeValue barcodeRowCountLowerPart = new BarcodeValue();
  BarcodeValue barcodeECLevel = new BarcodeValue();
  for (Codeword codeword : codewords) {
    if (codeword == null) {
      continue;
    }
    codeword.setRowNumberAsRowIndicatorColumn();
    int rowIndicatorValue = codeword.getValue() % 30;
    int codewordRowNumber = codeword.getRowNumber();
    if (!isLeft) {
      codewordRowNumber += 2;
    }
    switch (codewordRowNumber % 3) {
      case 0:
        barcodeRowCountUpperPart.setValue(rowIndicatorValue * 3 + 1);
        break;
      case 1:
        barcodeECLevel.setValue(rowIndicatorValue / 3);
        barcodeRowCountLowerPart.setValue(rowIndicatorValue % 3);
        break;
      case 2:
        barcodeColumnCount.setValue(rowIndicatorValue + 1);
        break;
    }
  }
  // Maybe we should check if we have ambiguous values?
  if ((barcodeColumnCount.getValue().length == 0) ||
      (barcodeRowCountUpperPart.getValue().length == 0) ||
      (barcodeRowCountLowerPart.getValue().length == 0) ||
      (barcodeECLevel.getValue().length == 0) ||
      barcodeColumnCount.getValue()[0] < 1 ||
      barcodeRowCountUpperPart.getValue()[0] + barcodeRowCountLowerPart.getValue()[0] < PDF417Common.MIN_ROWS_IN_BARCODE ||
      barcodeRowCountUpperPart.getValue()[0] + barcodeRowCountLowerPart.getValue()[0] > PDF417Common.MAX_ROWS_IN_BARCODE) {
    return null;
  }
  BarcodeMetadata barcodeMetadata = new BarcodeMetadata(barcodeColumnCount.getValue()[0],
      barcodeRowCountUpperPart.getValue()[0], barcodeRowCountLowerPart.getValue()[0], barcodeECLevel.getValue()[0]);
  removeIncorrectCodewords(codewords, barcodeMetadata);
  return barcodeMetadata;
}
 
源代码27 项目: ZXing-Orient   文件: PDF417ScanningDecoder.java
private static Codeword detectCodeword(BitMatrix image,
                                       int minColumn,
                                       int maxColumn,
                                       boolean leftToRight,
                                       int startColumn,
                                       int imageRow,
                                       int minCodewordWidth,
                                       int maxCodewordWidth) {
  startColumn = adjustCodewordStartColumn(image, minColumn, maxColumn, leftToRight, startColumn, imageRow);
  // we usually know fairly exact now how long a codeword is. We should provide minimum and maximum expected length
  // and try to adjust the read pixels, e.g. remove single pixel errors or try to cut off exceeding pixels.
  // min and maxCodewordWidth should not be used as they are calculated for the whole barcode an can be inaccurate
  // for the current position
  int[] moduleBitCount = getModuleBitCount(image, minColumn, maxColumn, leftToRight, startColumn, imageRow);
  if (moduleBitCount == null) {
    return null;
  }
  int endColumn;
  int codewordBitCount = PDF417Common.getBitCountSum(moduleBitCount);
  if (leftToRight) {
    endColumn = startColumn + codewordBitCount;
  } else {
    for (int i = 0; i < moduleBitCount.length / 2; i++) {
      int tmpCount = moduleBitCount[i];
      moduleBitCount[i] = moduleBitCount[moduleBitCount.length - 1 - i];
      moduleBitCount[moduleBitCount.length - 1 - i] = tmpCount;
    }
    endColumn = startColumn;
    startColumn = endColumn - codewordBitCount;
  }
  // TODO implement check for width and correction of black and white bars
  // use start (and maybe stop pattern) to determine if blackbars are wider than white bars. If so, adjust.
  // should probably done only for codewords with a lot more than 17 bits. 
  // The following fixes 10-1.png, which has wide black bars and small white bars
  //    for (int i = 0; i < moduleBitCount.length; i++) {
  //      if (i % 2 == 0) {
  //        moduleBitCount[i]--;
  //      } else {
  //        moduleBitCount[i]++;
  //      }
  //    }

  // We could also use the width of surrounding codewords for more accurate results, but this seems
  // sufficient for now
  if (!checkCodewordSkew(codewordBitCount, minCodewordWidth, maxCodewordWidth)) {
    // We could try to use the startX and endX position of the codeword in the same column in the previous row,
    // create the bit count from it and normalize it to 8. This would help with single pixel errors.
    return null;
  }

  int decodedValue = PDF417CodewordDecoder.getDecodedValue(moduleBitCount);
  int codeword = PDF417Common.getCodeword(decodedValue);
  if (codeword == -1) {
    return null;
  }
  return new Codeword(startColumn, endColumn, getCodewordBucketNumber(decodedValue), codeword);
}
 
private static int getDecodedCodewordValue(int[] moduleBitCount) {
  int decodedValue = getBitValue(moduleBitCount);
  return PDF417Common.getCodeword(decodedValue) == -1 ? -1 : decodedValue;
}
 
BarcodeMetadata getBarcodeMetadata() {
  Codeword[] codewords = getCodewords();
  BarcodeValue barcodeColumnCount = new BarcodeValue();
  BarcodeValue barcodeRowCountUpperPart = new BarcodeValue();
  BarcodeValue barcodeRowCountLowerPart = new BarcodeValue();
  BarcodeValue barcodeECLevel = new BarcodeValue();
  for (Codeword codeword : codewords) {
    if (codeword == null) {
      continue;
    }
    codeword.setRowNumberAsRowIndicatorColumn();
    int rowIndicatorValue = codeword.getValue() % 30;
    int codewordRowNumber = codeword.getRowNumber();
    if (!isLeft) {
      codewordRowNumber += 2;
    }
    switch (codewordRowNumber % 3) {
      case 0:
        barcodeRowCountUpperPart.setValue(rowIndicatorValue * 3 + 1);
        break;
      case 1:
        barcodeECLevel.setValue(rowIndicatorValue / 3);
        barcodeRowCountLowerPart.setValue(rowIndicatorValue % 3);
        break;
      case 2:
        barcodeColumnCount.setValue(rowIndicatorValue + 1);
        break;
    }
  }
  // Maybe we should check if we have ambiguous values?
  if ((barcodeColumnCount.getValue().length == 0) ||
      (barcodeRowCountUpperPart.getValue().length == 0) ||
      (barcodeRowCountLowerPart.getValue().length == 0) ||
      (barcodeECLevel.getValue().length == 0) ||
      barcodeColumnCount.getValue()[0] < 1 ||
      barcodeRowCountUpperPart.getValue()[0] + barcodeRowCountLowerPart.getValue()[0] < PDF417Common.MIN_ROWS_IN_BARCODE ||
      barcodeRowCountUpperPart.getValue()[0] + barcodeRowCountLowerPart.getValue()[0] > PDF417Common.MAX_ROWS_IN_BARCODE) {
    return null;
  }
  BarcodeMetadata barcodeMetadata = new BarcodeMetadata(barcodeColumnCount.getValue()[0],
      barcodeRowCountUpperPart.getValue()[0], barcodeRowCountLowerPart.getValue()[0], barcodeECLevel.getValue()[0]);
  removeIncorrectCodewords(codewords, barcodeMetadata);
  return barcodeMetadata;
}
 
private static Codeword detectCodeword(BitMatrix image,
                                       int minColumn,
                                       int maxColumn,
                                       boolean leftToRight,
                                       int startColumn,
                                       int imageRow,
                                       int minCodewordWidth,
                                       int maxCodewordWidth) {
  startColumn = adjustCodewordStartColumn(image, minColumn, maxColumn, leftToRight, startColumn, imageRow);
  // we usually know fairly exact now how long a codeword is. We should provide minimum and maximum expected length
  // and try to adjust the read pixels, e.g. remove single pixel errors or try to cut off exceeding pixels.
  // min and maxCodewordWidth should not be used as they are calculated for the whole barcode an can be inaccurate
  // for the current position
  int[] moduleBitCount = getModuleBitCount(image, minColumn, maxColumn, leftToRight, startColumn, imageRow);
  if (moduleBitCount == null) {
    return null;
  }
  int endColumn;
  int codewordBitCount = PDF417Common.getBitCountSum(moduleBitCount);
  if (leftToRight) {
    endColumn = startColumn + codewordBitCount;
  } else {
    for (int i = 0; i < moduleBitCount.length / 2; i++) {
      int tmpCount = moduleBitCount[i];
      moduleBitCount[i] = moduleBitCount[moduleBitCount.length - 1 - i];
      moduleBitCount[moduleBitCount.length - 1 - i] = tmpCount;
    }
    endColumn = startColumn;
    startColumn = endColumn - codewordBitCount;
  }
  // TODO implement check for width and correction of black and white bars
  // use start (and maybe stop pattern) to determine if blackbars are wider than white bars. If so, adjust.
  // should probably done only for codewords with a lot more than 17 bits. 
  // The following fixes 10-1.png, which has wide black bars and small white bars
  //    for (int i = 0; i < moduleBitCount.length; i++) {
  //      if (i % 2 == 0) {
  //        moduleBitCount[i]--;
  //      } else {
  //        moduleBitCount[i]++;
  //      }
  //    }

  // We could also use the width of surrounding codewords for more accurate results, but this seems
  // sufficient for now
  if (!checkCodewordSkew(codewordBitCount, minCodewordWidth, maxCodewordWidth)) {
    // We could try to use the startX and endX position of the codeword in the same column in the previous row,
    // create the bit count from it and normalize it to 8. This would help with single pixel errors.
    return null;
  }

  int decodedValue = PDF417CodewordDecoder.getDecodedValue(moduleBitCount);
  int codeword = PDF417Common.getCodeword(decodedValue);
  if (codeword == -1) {
    return null;
  }
  return new Codeword(startColumn, endColumn, getCodewordBucketNumber(decodedValue), codeword);
}
 
 类所在包
 同包方法