com.google.zxing.common.BitArray#appendBits ( )源码实例Demo

下面列出了com.google.zxing.common.BitArray#appendBits ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: barcodescanner-lib-aar   文件: Encoder.java
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++;
    }
  }
}
 
static BitArray stuffBits(BitArray bits, int wordSize) {
  BitArray out = new BitArray();

  int n = bits.getSize();
  int mask = (1 << wordSize) - 2;
  for (int i = 0; i < n; i += wordSize) {
    int word = 0;
    for (int j = 0; j < wordSize; j++) {
      if (i + j >= n || bits.get(i + j)) {
        word |= 1 << (wordSize - 1 - j);
      }
    }
    if ((word & mask) == mask) {
      out.appendBits(word & mask, wordSize);
      i--;
    } else if ((word & mask) == 0) {
      out.appendBits(word | 1, wordSize);
      i--;
    } else {
      out.appendBits(word, wordSize);
    }
  }
  return out;
}
 
源代码3 项目: ScreenCapture   文件: MatrixUtil.java
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());
  }
}
 
源代码4 项目: barterli_android   文件: MatrixUtil.java
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());
    }
}
 
源代码5 项目: Tesseract-OCR-Scanner   文件: Encoder.java
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);
  }
}
 
源代码6 项目: QrCodeScanner   文件: MatrixUtil.java
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());
  }
}
 
源代码7 项目: ZXing-Orient   文件: MatrixUtil.java
static void makeVersionInfoBits(Version version, BitArray bits) throws WriterException {
  bits.appendBits(version.getVersionNumber(), 6);
  int bchCode = calculateBCHCode(version.getVersionNumber(), VERSION_INFO_POLY);
  bits.appendBits(bchCode, 12);

  if (bits.getSize() != 18) {  // Just in case.
    throw new WriterException("should not happen but we got: " + bits.getSize());
  }
}
 
源代码8 项目: QrCodeScanner   文件: Encoder.java
static void append8BitBytes(String content, BitArray bits, String encoding)
    throws WriterException {
  byte[] bytes;
  try {
    bytes = content.getBytes(encoding);
  } catch (UnsupportedEncodingException uee) {
    throw new WriterException(uee);
  }
  for (byte b : bytes) {
    bits.appendBits(b, 8);
  }
}
 
源代码9 项目: MiBandDecompiled   文件: d.java
static void a(int j, BitArray bitarray)
{
    bitarray.appendBits(j, 6);
    bitarray.appendBits(a(j, 7973), 12);
    if (bitarray.getSize() != 18)
    {
        throw new WriterException((new StringBuilder()).append("should not happen but we got: ").append(bitarray.getSize()).toString());
    } else
    {
        return;
    }
}
 
源代码10 项目: barcodescanner-lib-aar   文件: Encoder.java
/**
 * Append length info. On success, store the result in "bits".
 */
static void appendLengthInfo(int numLetters, Version version, Mode mode, BitArray bits) throws WriterException {
  int numBits = mode.getCharacterCountBits(version);
  if (numLetters >= (1 << numBits)) {
    throw new WriterException(numLetters + " is bigger than " + ((1 << numBits) - 1));
  }
  bits.appendBits(numLetters, numBits);
}
 
源代码11 项目: Tesseract-OCR-Scanner   文件: Encoder.java
/**
 * Terminate bits as described in 8.4.8 and 8.4.9 of JISX0510:2004 (p.24).
 */
static void terminateBits(int numDataBytes, BitArray bits) throws WriterException {
  int capacity = numDataBytes * 8;
  if (bits.getSize() > capacity) {
    throw new WriterException("data bits cannot fit in the QR Code" + bits.getSize() + " > " +
        capacity);
  }
  for (int i = 0; i < 4 && bits.getSize() < capacity; ++i) {
    bits.appendBit(false);
  }
  // Append termination bits. See 8.4.8 of JISX0510:2004 (p.24) for details.
  // If the last byte isn't 8-bit aligned, we'll add padding bits.
  int numBitsInLastByte = bits.getSize() & 0x07;    
  if (numBitsInLastByte > 0) {
    for (int i = numBitsInLastByte; i < 8; i++) {
      bits.appendBit(false);
    }
  }
  // If we have more space, we'll fill the space with padding patterns defined in 8.4.9 (p.24).
  int numPaddingBytes = numDataBytes - bits.getSizeInBytes();
  for (int i = 0; i < numPaddingBytes; ++i) {
    bits.appendBits((i & 0x01) == 0 ? 0xEC : 0x11, 8);
  }
  if (bits.getSize() != capacity) {
    throw new WriterException("Bits size does not equal capacity");
  }
}
 
源代码12 项目: reacteu-app   文件: Encoder.java
/**
 * Append length info. On success, store the result in "bits".
 */
static void appendLengthInfo(int numLetters, Version version, Mode mode, BitArray bits) throws WriterException {
  int numBits = mode.getCharacterCountBits(version);
  if (numLetters >= (1 << numBits)) {
    throw new WriterException(numLetters + " is bigger than " + ((1 << numBits) - 1));
  }
  bits.appendBits(numLetters, numBits);
}
 
源代码13 项目: weex   文件: Encoder.java
static BitArray generateModeMessage(boolean compact, int layers, int messageSizeInWords) {
  BitArray modeMessage = new BitArray();
  if (compact) {
    modeMessage.appendBits(layers - 1, 2);
    modeMessage.appendBits(messageSizeInWords - 1, 6);
    modeMessage = generateCheckWords(modeMessage, 28, 4);
  } else {
    modeMessage.appendBits(layers - 1, 5);
    modeMessage.appendBits(messageSizeInWords - 1, 11);
    modeMessage = generateCheckWords(modeMessage, 40, 4);
  }
  return modeMessage;
}
 
源代码14 项目: MiBandDecompiled   文件: Encoder.java
static void a(int i, int j, Mode mode, BitArray bitarray)
{
    int k = mode.getCharacterCountBits(Version.getVersionForNumber(j));
    if (i > -1 + (1 << k))
    {
        throw new WriterException((new StringBuilder()).append(i).append("is bigger than").append(-1 + (1 << k)).toString());
    } else
    {
        bitarray.appendBits(i, k);
        return;
    }
}
 
源代码15 项目: weex   文件: Encoder.java
private static BitArray generateCheckWords(BitArray bitArray, int totalBits, int wordSize) {
  // bitArray is guaranteed to be a multiple of the wordSize, so no padding needed
  int messageSizeInWords = bitArray.getSize() / wordSize;
  ReedSolomonEncoder rs = new ReedSolomonEncoder(getGF(wordSize));
  int totalWords = totalBits / wordSize;
  int[] messageWords = bitsToWords(bitArray, wordSize, totalWords);
  rs.encode(messageWords, totalWords - messageSizeInWords);
  int startPad = totalBits % wordSize;
  BitArray messageBits = new BitArray();
  messageBits.appendBits(0, startPad);
  for (int messageWord : messageWords) {
    messageBits.appendBits(messageWord, wordSize);
  }
  return messageBits;
}
 
源代码16 项目: reacteu-app   文件: MatrixUtil.java
static void makeVersionInfoBits(Version version, BitArray bits) throws WriterException {
  bits.appendBits(version.getVersionNumber(), 6);
  int bchCode = calculateBCHCode(version.getVersionNumber(), VERSION_INFO_POLY);
  bits.appendBits(bchCode, 12);

  if (bits.getSize() != 18) {  // Just in case.
    throw new WriterException("should not happen but we got: " + bits.getSize());
  }
}
 
源代码17 项目: barcodescanner-lib-aar   文件: Encoder.java
private static void appendECI(CharacterSetECI eci, BitArray bits) {
  bits.appendBits(Mode.ECI.getBits(), 4);
  // This is correct for values up to 127, which is all we need now.
  bits.appendBits(eci.getValue(), 8);
}
 
private static void appendECI(CharacterSetECI eci, BitArray bits) {
  bits.appendBits(Mode.ECI.getBits(), 4);
  // This is correct for values up to 127, which is all we need now.
  bits.appendBits(eci.getValue(), 8);
}
 
源代码19 项目: Tesseract-OCR-Scanner   文件: Encoder.java
/**
 * Append mode info. On success, store the result in "bits".
 */
static void appendModeInfo(Mode mode, BitArray bits) {
  bits.appendBits(mode.getBits(), 4);
}
 
源代码20 项目: RipplePower   文件: Encoder.java
private static void appendECI(CharacterSetECI eci, BitArray bits) {
	bits.appendBits(Mode.ECI.getBits(), 4);
	// This is correct for values up to 127, which is all we need now.
	bits.appendBits(eci.getValue(), 8);
}