本文整理汇总了Java中com.google.zxing.common.BitArray.appendBits方法的典型用法代码示例。如果您正苦于以下问题:Java BitArray.appendBits方法的具体用法?Java BitArray.appendBits怎么用?Java BitArray.appendBits使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.zxing.common.BitArray
的用法示例。
在下文中一共展示了BitArray.appendBits方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
} else if (i + 1 < length) {
int code2 = getAlphanumericCode(content.charAt(i + 1));
if (code2 == -1) {
throw new WriterException();
}
bits.appendBits((code1 * 45) + code2, 11);
i += 2;
} else {
bits.appendBits(code1, 6);
i++;
}
}
}
示例2: 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++;
}
}
}
示例3: generateCheckWords
import com.google.zxing.common.BitArray; //导入方法依赖的package包/类
private static BitArray generateCheckWords(BitArray bitArray, int totalBits, int wordSize) {
int i = 0;
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);
int length = messageWords.length;
while (i < length) {
messageBits.appendBits(messageWords[i], wordSize);
i++;
}
return messageBits;
}
示例4: 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);
}
}
示例5: 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());
}
}
示例6: 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);
}
}
示例7: stuffBits
import com.google.zxing.common.BitArray; //导入方法依赖的package包/类
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;
}
示例8: makeTypeInfoBits
import com.google.zxing.common.BitArray; //导入方法依赖的package包/类
static void makeTypeInfoBits(ErrorCorrectionLevel ecLevel, int maskPattern, BitArray bits)
throws WriterException {
if (QRCode.isValidMaskPattern(maskPattern)) {
int typeInfo = (ecLevel.getBits() << 3) | maskPattern;
bits.appendBits(typeInfo, 5);
bits.appendBits(calculateBCHCode(typeInfo, TYPE_INFO_POLY), 10);
BitArray maskBits = new BitArray();
maskBits.appendBits(TYPE_INFO_MASK_PATTERN, 15);
bits.xor(maskBits);
if (bits.getSize() != 15) {
throw new WriterException("should not happen but we got: " + bits.getSize());
}
return;
}
throw new WriterException("Invalid mask pattern");
}
示例9: terminateBits
import com.google.zxing.common.BitArray; //导入方法依赖的package包/类
/**
* 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");
}
}
示例10: generateModeMessage
import com.google.zxing.common.BitArray; //导入方法依赖的package包/类
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;
}
示例11: generateCheckWords
import com.google.zxing.common.BitArray; //导入方法依赖的package包/类
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;
}
示例12: appendLengthInfo
import com.google.zxing.common.BitArray; //导入方法依赖的package包/类
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: append8BitBytes
import com.google.zxing.common.BitArray; //导入方法依赖的package包/类
static void append8BitBytes(String content, BitArray bits, String encoding) throws
WriterException {
try {
for (byte b : content.getBytes(encoding)) {
bits.appendBits(b, 8);
}
} catch (UnsupportedEncodingException uee) {
throw new WriterException(uee);
}
}
示例14: append8BitBytes
import com.google.zxing.common.BitArray; //导入方法依赖的package包/类
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);
}
}
示例15: appendModeInfo
import com.google.zxing.common.BitArray; //导入方法依赖的package包/类
static void appendModeInfo(Mode mode, BitArray bits) {
bits.appendBits(mode.getBits(), 4);
}