当前位置: 首页>>代码示例>>Java>>正文


Java BitArray类代码示例

本文整理汇总了Java中com.google.zxing.common.BitArray的典型用法代码示例。如果您正苦于以下问题:Java BitArray类的具体用法?Java BitArray怎么用?Java BitArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BitArray类属于com.google.zxing.common包,在下文中一共展示了BitArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: decodeRow

import com.google.zxing.common.BitArray; //导入依赖的package包/类
Result decodeRow(int rowNumber, BitArray row, int[] extensionStartRange) throws NotFoundException {

    StringBuilder result = decodeRowStringBuffer;
    result.setLength(0);
    int end = decodeMiddle(row, extensionStartRange, result);

    String resultString = result.toString();
    Map<ResultMetadataType,Object> extensionData = parseExtensionString(resultString);

    Result extensionResult =
        new Result(resultString,
                   null,
                   new ResultPoint[] {
                       new ResultPoint((extensionStartRange[0] + extensionStartRange[1]) / 2.0f, rowNumber),
                       new ResultPoint(end, rowNumber),
                   },
                   BarcodeFormat.UPC_EAN_EXTENSION);
    if (extensionData != null) {
      extensionResult.putAllMetadata(extensionData);
    }
    return extensionResult;
  }
 
开发者ID:10045125,项目名称:QrCode,代码行数:23,代码来源:UPCEANExtension2Support.java

示例2: appendBytes

import com.google.zxing.common.BitArray; //导入依赖的package包/类
/**
 * Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".
 */
static void appendBytes(String content,
                        Mode mode,
                        BitArray bits,
                        String encoding) throws WriterException {
  switch (mode) {
    case NUMERIC:
      appendNumericBytes(content, bits);
      break;
    case ALPHANUMERIC:
      appendAlphanumericBytes(content, bits);
      break;
    case BYTE:
      append8BitBytes(content, bits, encoding);
      break;
    case KANJI:
      appendKanjiBytes(content, bits);
      break;
    default:
      throw new WriterException("Invalid mode: " + mode);
  }
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:25,代码来源:Encoder.java

示例3: appendAlphanumericBytes

import com.google.zxing.common.BitArray; //导入依赖的package包/类
static void appendAlphanumericBytes(CharSequence content, BitArray bits) throws WriterException {
  int length = content.length();
  int i = 0;
  while (i < length) {
    int code1 = getAlphanumericCode(content.charAt(i));
    if (code1 == -1) {
      throw new WriterException();
    }
    if (i + 1 < length) {
      int code2 = getAlphanumericCode(content.charAt(i + 1));
      if (code2 == -1) {
        throw new WriterException();
      }
      // Encode two alphanumeric letters in 11 bits.
      bits.appendBits(code1 * 45 + code2, 11);
      i += 2;
    } else {
      // Encode one alphanumeric letter in six bits.
      bits.appendBits(code1, 6);
      i++;
    }
  }
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:24,代码来源:Encoder.java

示例4: decodePair

import com.google.zxing.common.BitArray; //导入依赖的package包/类
private Pair decodePair(BitArray row, boolean right, int rowNumber, Map<DecodeHintType,?> hints) {
  try {
    int[] startEnd = findFinderPattern(row, right);
    FinderPattern pattern = parseFoundFinderPattern(row, rowNumber, right, startEnd);

    ResultPointCallback resultPointCallback = hints == null ? null :
      (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);

    if (resultPointCallback != null) {
      float center = (startEnd[0] + startEnd[1]) / 2.0f;
      if (right) {
        // row is actually reversed
        center = row.getSize() - 1 - center;
      }
      resultPointCallback.foundPossibleResultPoint(new ResultPoint(center, rowNumber));
    }

    DataCharacter outside = decodeDataCharacter(row, pattern, true);
    DataCharacter inside = decodeDataCharacter(row, pattern, false);
    return new Pair(1597 * outside.getValue() + inside.getValue(),
                    outside.getChecksumPortion() + 4 * inside.getChecksumPortion(),
                    pattern);
  } catch (NotFoundException ignored) {
    return null;
  }
}
 
开发者ID:simplezhli,项目名称:Tesseract-OCR-Scanner,代码行数:27,代码来源:RSS14Reader.java

示例5: appendKanjiBytes

import com.google.zxing.common.BitArray; //导入依赖的package包/类
static void appendKanjiBytes(String content, BitArray bits) throws WriterException {
  byte[] bytes;
  try {
    bytes = content.getBytes("Shift_JIS");
  } catch (UnsupportedEncodingException uee) {
    throw new WriterException(uee);
  }
  int length = bytes.length;
  for (int i = 0; i < length; i += 2) {
    int byte1 = bytes[i] & 0xFF;
    int byte2 = bytes[i + 1] & 0xFF;
    int code = (byte1 << 8) | byte2;
    int subtracted = -1;
    if (code >= 0x8140 && code <= 0x9ffc) {
      subtracted = code - 0x8140;
    } else if (code >= 0xe040 && code <= 0xebbf) {
      subtracted = code - 0xc140;
    }
    if (subtracted == -1) {
      throw new WriterException("Invalid byte sequence");
    }
    int encoded = ((subtracted >> 8) * 0xc0) + (subtracted & 0xff);
    bits.appendBits(encoded, 13);
  }
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:26,代码来源:Encoder.java

示例6: validateQuietZone

import com.google.zxing.common.BitArray; //导入依赖的package包/类
/**
 * The start & end patterns must be pre/post fixed by a quiet zone. This
 * zone must be at least 10 times the width of a narrow line.  Scan back until
 * we either get to the start of the barcode or match the necessary number of
 * quiet zone pixels.
 *
 * Note: Its assumed the row is reversed when using this method to find
 * quiet zone after the end pattern.
 *
 * ref: http://www.barcode-1.net/i25code.html
 *
 * @param row bit array representing the scanned barcode.
 * @param startPattern index into row of the start or end pattern.
 * @throws NotFoundException if the quiet zone cannot be found
 */
private void validateQuietZone(BitArray row, int startPattern) throws NotFoundException {

  int quietCount = this.narrowLineWidth * 10;  // expect to find this many pixels of quiet zone

  // if there are not so many pixel at all let's try as many as possible
  quietCount = quietCount < startPattern ? quietCount : startPattern;

  for (int i = startPattern - 1; quietCount > 0 && i >= 0; i--) {
    if (row.get(i)) {
      break;
    }
    quietCount--;
  }
  if (quietCount != 0) {
    // Unable to find the necessary number of quiet zone pixels.
    throw NotFoundException.getNotFoundInstance();
  }
}
 
开发者ID:simplezhli,项目名称:Tesseract-OCR-Scanner,代码行数:34,代码来源:ITFReader.java

示例7: maybeEmbedVersionInfo

import com.google.zxing.common.BitArray; //导入依赖的package包/类
static void maybeEmbedVersionInfo(Version version, ByteMatrix matrix) throws WriterException {
  if (version.getVersionNumber() < 7) {  // Version info is necessary if version >= 7.
    return;  // Don't need version info.
  }
  BitArray versionInfoBits = new BitArray();
  makeVersionInfoBits(version, versionInfoBits);

  int bitIndex = 6 * 3 - 1;  // It will decrease from 17 to 0.
  for (int i = 0; i < 6; ++i) {
    for (int j = 0; j < 3; ++j) {
      // Place bits in LSB (least significant bit) to MSB order.
      boolean bit = versionInfoBits.get(bitIndex);
      bitIndex--;
      // Left bottom corner.
      matrix.set(i, matrix.getHeight() - 11 + j, bit);
      // Right bottom corner.
      matrix.set(matrix.getHeight() - 11 + j, i, bit);
    }
  }
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:21,代码来源:MatrixUtil.java

示例8: decodeMiddle

import com.google.zxing.common.BitArray; //导入依赖的package包/类
protected int decodeMiddle(BitArray row, int[] startRange, StringBuilder result) throws
        NotFoundException {
    int[] counters = this.decodeMiddleCounters;
    counters[0] = 0;
    counters[1] = 0;
    counters[2] = 0;
    counters[3] = 0;
    int end = row.getSize();
    int rowOffset = startRange[1];
    int lgPatternFound = 0;
    for (int x = 0; x < 6 && rowOffset < end; x++) {
        int bestMatch = UPCEANReader.decodeDigit(row, counters, rowOffset, L_AND_G_PATTERNS);
        result.append((char) ((bestMatch % 10) + 48));
        for (int counter : counters) {
            rowOffset += counter;
        }
        if (bestMatch >= 10) {
            lgPatternFound |= 1 << (5 - x);
        }
    }
    determineNumSysAndCheckDigit(result, lgPatternFound);
    return rowOffset;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:24,代码来源:UPCEReader.java

示例9: makeTypeInfoBits

import com.google.zxing.common.BitArray; //导入依赖的package包/类
static void makeTypeInfoBits(ErrorCorrectionLevel ecLevel, int maskPattern, BitArray bits)
    throws WriterException {
  if (!QRCode.isValidMaskPattern(maskPattern)) {
    throw new WriterException("Invalid mask pattern");
  }
  int typeInfo = (ecLevel.getBits() << 3) | maskPattern;
  bits.appendBits(typeInfo, 5);

  int bchCode = calculateBCHCode(typeInfo, TYPE_INFO_POLY);
  bits.appendBits(bchCode, 10);

  BitArray maskBits = new BitArray();
  maskBits.appendBits(TYPE_INFO_MASK_PATTERN, 15);
  bits.xor(maskBits);

  if (bits.getSize() != 15) {  // Just in case.
    throw new WriterException("should not happen but we got: " + bits.getSize());
  }
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:20,代码来源:MatrixUtil.java

示例10: decodeDigit

import com.google.zxing.common.BitArray; //导入依赖的package包/类
/**
 * Attempts to decode a single UPC/EAN-encoded digit.
 *
 * @param row row of black/white values to decode
 * @param counters the counts of runs of observed black/white/black/... values
 * @param rowOffset horizontal offset to start decoding from
 * @param patterns the set of patterns to use to decode -- sometimes different encodings
 * for the digits 0-9 are used, and this indicates the encodings for 0 to 9 that should
 * be used
 * @return horizontal offset of first pixel beyond the decoded digit
 * @throws NotFoundException if digit cannot be decoded
 */
static int decodeDigit(BitArray row, int[] counters, int rowOffset, int[][] patterns)
    throws NotFoundException {
  recordPattern(row, rowOffset, counters);
  float bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept
  int bestMatch = -1;
  int max = patterns.length;
  for (int i = 0; i < max; i++) {
    int[] pattern = patterns[i];
    float variance = patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE);
    if (variance < bestVariance) {
      bestVariance = variance;
      bestMatch = i;
    }
  }
  if (bestMatch >= 0) {
    return bestMatch;
  } else {
    throw NotFoundException.getNotFoundInstance();
  }
}
 
开发者ID:simplezhli,项目名称:Tesseract-OCR-Scanner,代码行数:33,代码来源:UPCEANReader.java

示例11: validateQuietZone

import com.google.zxing.common.BitArray; //导入依赖的package包/类
/**
 * The start & end patterns must be pre/post fixed by a quiet zone. This
 * zone must be at least 10 times the width of a narrow line.  Scan back until
 * we either get to the start of the barcode or match the necessary number of
 * quiet zone pixels.
 *
 * Note: Its assumed the row is reversed when using this method to find
 * quiet zone after the end pattern.
 *
 * ref: http://www.barcode-1.net/i25code.html
 *
 * @param row bit array representing the scanned barcode.
 * @param startPattern index into row of the start or end pattern.
 * @throws NotFoundException if the quiet zone cannot be found, a ReaderException is thrown.
 */
private void validateQuietZone(BitArray row, int startPattern) throws NotFoundException {

  int quietCount = this.narrowLineWidth * 10;  // expect to find this many pixels of quiet zone

  // if there are not so many pixel at all let's try as many as possible
  quietCount = quietCount < startPattern ? quietCount : startPattern;

  for (int i = startPattern - 1; quietCount > 0 && i >= 0; i--) {
    if (row.get(i)) {
      break;
    }
    quietCount--;
  }
  if (quietCount != 0) {
    // Unable to find the necessary number of quiet zone pixels.
    throw NotFoundException.getNotFoundInstance();
  }
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:34,代码来源:ITFReader.java

示例12: decodeCode

import com.google.zxing.common.BitArray; //导入依赖的package包/类
private static int decodeCode(BitArray row, int[] counters, int rowOffset)
    throws NotFoundException {
  recordPattern(row, rowOffset, counters);
  float bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept
  int bestMatch = -1;
  for (int d = 0; d < CODE_PATTERNS.length; d++) {
    int[] pattern = CODE_PATTERNS[d];
    float variance = patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE);
    if (variance < bestVariance) {
      bestVariance = variance;
      bestMatch = d;
    }
  }
  // TODO We're overlooking the fact that the STOP pattern has 7 values, not 6.
  if (bestMatch >= 0) {
    return bestMatch;
  } else {
    throw NotFoundException.getNotFoundInstance();
  }
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:21,代码来源:Code128Reader.java

示例13: appendNumericBytes

import com.google.zxing.common.BitArray; //导入依赖的package包/类
static void appendNumericBytes(CharSequence content, BitArray bits) {
    int length = content.length();
    int i = 0;
    while (i < length) {
        int num1 = content.charAt(i) - 48;
        if (i + 2 < length) {
            int num3 = content.charAt(i + 2) - 48;
            bits.appendBits(((num1 * 100) + ((content.charAt(i + 1) - 48) * 10)) + num3, 10);
            i += 3;
        } else if (i + 1 < length) {
            bits.appendBits((num1 * 10) + (content.charAt(i + 1) - 48), 7);
            i += 2;
        } else {
            bits.appendBits(num1, 4);
            i++;
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:19,代码来源:Encoder.java

示例14: decodePair

import com.google.zxing.common.BitArray; //导入依赖的package包/类
private Pair decodePair(BitArray row, boolean right, int rowNumber, Map<DecodeHintType,?> hints) {
  try {
    int[] startEnd = findFinderPattern(row, 0, right);
    FinderPattern pattern = parseFoundFinderPattern(row, rowNumber, right, startEnd);

    ResultPointCallback resultPointCallback = hints == null ? null :
      (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);

    if (resultPointCallback != null) {
      float center = (startEnd[0] + startEnd[1]) / 2.0f;
      if (right) {
        // row is actually reversed
        center = row.getSize() - 1 - center;
      }
      resultPointCallback.foundPossibleResultPoint(new ResultPoint(center, rowNumber));
    }

    DataCharacter outside = decodeDataCharacter(row, pattern, true);
    DataCharacter inside = decodeDataCharacter(row, pattern, false);
    return new Pair(1597 * outside.getValue() + inside.getValue(),
                    outside.getChecksumPortion() + 4 * inside.getChecksumPortion(),
                    pattern);
  } catch (NotFoundException ignored) {
    return null;
  }
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:27,代码来源:RSS14Reader.java

示例15: appendKanjiBytes

import com.google.zxing.common.BitArray; //导入依赖的package包/类
static void appendKanjiBytes(String content, BitArray bits) throws WriterException {
    try {
        byte[] bytes = content.getBytes("Shift_JIS");
        int length = bytes.length;
        for (int i = 0; i < length; i += 2) {
            int byte2 = bytes[i + 1] & 255;
            int code = ((bytes[i] & 255) << 8) | byte2;
            int subtracted = -1;
            if (code >= 33088 && code <= 40956) {
                subtracted = code - 33088;
            } else if (code >= 57408 && code <= 60351) {
                subtracted = code - 49472;
            }
            if (subtracted == -1) {
                throw new WriterException("Invalid byte sequence");
            }
            bits.appendBits(((subtracted >> 8) * 192) + (subtracted & 255), 13);
        }
    } catch (UnsupportedEncodingException uee) {
        throw new WriterException(uee);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:23,代码来源:Encoder.java


注:本文中的com.google.zxing.common.BitArray类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。