com.google.zxing.common.reedsolomon.ReedSolomonEncoder Java Examples

The following examples show how to use com.google.zxing.common.reedsolomon.ReedSolomonEncoder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Encoder.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
static byte[] a(byte abyte0[], int i)
{
    int j = 0;
    int k = abyte0.length;
    int ai[] = new int[k + i];
    for (int l = 0; l < k; l++)
    {
        ai[l] = 0xff & abyte0[l];
    }

    (new ReedSolomonEncoder(GenericGF.QR_CODE_FIELD_256)).encode(ai, i);
    byte abyte1[] = new byte[i];
    for (; j < i; j++)
    {
        abyte1[j] = (byte)ai[k + j];
    }

    return abyte1;
}
 
Example #2
Source File: Encoder.java    From weex with Apache License 2.0 5 votes vote down vote up
static byte[] generateECBytes(byte[] dataBytes, int numEcBytesInBlock) {
  int numDataBytes = dataBytes.length;
  int[] toEncode = new int[numDataBytes + numEcBytesInBlock];
  for (int i = 0; i < numDataBytes; i++) {
    toEncode[i] = dataBytes[i] & 0xFF;
  }
  new ReedSolomonEncoder(GenericGF.QR_CODE_FIELD_256).encode(toEncode, numEcBytesInBlock);

  byte[] ecBytes = new byte[numEcBytesInBlock];
  for (int i = 0; i < numEcBytesInBlock; i++) {
    ecBytes[i] = (byte) toEncode[numDataBytes + i];
  }
  return ecBytes;
}
 
Example #3
Source File: Encoder.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
static byte[] generateECBytes(byte[] dataBytes, int numEcBytesInBlock) {
  int numDataBytes = dataBytes.length;
  int[] toEncode = new int[numDataBytes + numEcBytesInBlock];
  for (int i = 0; i < numDataBytes; i++) {
    toEncode[i] = dataBytes[i] & 0xFF;
  }
  new ReedSolomonEncoder(GenericGF.QR_CODE_FIELD_256).encode(toEncode, numEcBytesInBlock);

  byte[] ecBytes = new byte[numEcBytesInBlock];
  for (int i = 0; i < numEcBytesInBlock; i++) {
    ecBytes[i] = (byte) toEncode[numDataBytes + i];
  }
  return ecBytes;
}
 
Example #4
Source File: Encoder.java    From android-quick-response-code with Apache License 2.0 5 votes vote down vote up
static byte[] generateECBytes(byte[] dataBytes, int numEcBytesInBlock) {
    int numDataBytes = dataBytes.length;
    int[] toEncode = new int[numDataBytes + numEcBytesInBlock];
    for (int i = 0; i < numDataBytes; i++) {
        toEncode[i] = dataBytes[i] & 0xFF;
    }
    new ReedSolomonEncoder(GenericGF.QR_CODE_FIELD_256).encode(toEncode, numEcBytesInBlock);

    byte[] ecBytes = new byte[numEcBytesInBlock];
    for (int i = 0; i < numEcBytesInBlock; i++) {
        ecBytes[i] = (byte) toEncode[numDataBytes + i];
    }
    return ecBytes;
}
 
Example #5
Source File: Encoder.java    From barterli_android with Apache License 2.0 5 votes vote down vote up
static byte[] generateECBytes(byte[] dataBytes, int numEcBytesInBlock) {
    int numDataBytes = dataBytes.length;
    int[] toEncode = new int[numDataBytes + numEcBytesInBlock];
    for (int i = 0; i < numDataBytes; i++) {
        toEncode[i] = dataBytes[i] & 0xFF;
    }
    new ReedSolomonEncoder(GenericGF.QR_CODE_FIELD_256).encode(toEncode, numEcBytesInBlock);

    byte[] ecBytes = new byte[numEcBytesInBlock];
    for (int i = 0; i < numEcBytesInBlock; i++) {
        ecBytes[i] = (byte) toEncode[numDataBytes + i];
    }
    return ecBytes;
}
 
Example #6
Source File: Encoder.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
static byte[] generateECBytes(byte[] dataBytes, int numEcBytesInBlock) {
  int numDataBytes = dataBytes.length;
  int[] toEncode = new int[numDataBytes + numEcBytesInBlock];
  for (int i = 0; i < numDataBytes; i++) {
    toEncode[i] = dataBytes[i] & 0xFF;
  }
  new ReedSolomonEncoder(GenericGF.QR_CODE_FIELD_256).encode(toEncode, numEcBytesInBlock);

  byte[] ecBytes = new byte[numEcBytesInBlock];
  for (int i = 0; i < numEcBytesInBlock; i++) {
    ecBytes[i] = (byte) toEncode[numDataBytes + i];
  }
  return ecBytes;
}
 
Example #7
Source File: Encoder.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
static byte[] generateECBytes(byte[] dataBytes, int numEcBytesInBlock) {
	int numDataBytes = dataBytes.length;
	int[] toEncode = new int[numDataBytes + numEcBytesInBlock];
	for (int i = 0; i < numDataBytes; i++) {
		toEncode[i] = dataBytes[i] & 0xFF;
	}
	new ReedSolomonEncoder(GenericGF.QR_CODE_FIELD_256).encode(toEncode, numEcBytesInBlock);

	byte[] ecBytes = new byte[numEcBytesInBlock];
	for (int i = 0; i < numEcBytesInBlock; i++) {
		ecBytes[i] = (byte) toEncode[numDataBytes + i];
	}
	return ecBytes;
}
 
Example #8
Source File: Encoder.java    From reacteu-app with MIT License 5 votes vote down vote up
static byte[] generateECBytes(byte[] dataBytes, int numEcBytesInBlock) {
  int numDataBytes = dataBytes.length;
  int[] toEncode = new int[numDataBytes + numEcBytesInBlock];
  for (int i = 0; i < numDataBytes; i++) {
    toEncode[i] = dataBytes[i] & 0xFF;
  }
  new ReedSolomonEncoder(GenericGF.QR_CODE_FIELD_256).encode(toEncode, numEcBytesInBlock);

  byte[] ecBytes = new byte[numEcBytesInBlock];
  for (int i = 0; i < numEcBytesInBlock; i++) {
    ecBytes[i] = (byte) toEncode[numDataBytes + i];
  }
  return ecBytes;
}
 
Example #9
Source File: Encoder.java    From barcodescanner-lib-aar with MIT License 5 votes vote down vote up
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;
}
 
Example #10
Source File: Encoder.java    From barcodescanner-lib-aar with MIT License 5 votes vote down vote up
static byte[] generateECBytes(byte[] dataBytes, int numEcBytesInBlock) {
  int numDataBytes = dataBytes.length;
  int[] toEncode = new int[numDataBytes + numEcBytesInBlock];
  for (int i = 0; i < numDataBytes; i++) {
    toEncode[i] = dataBytes[i] & 0xFF;
  }
  new ReedSolomonEncoder(GenericGF.QR_CODE_FIELD_256).encode(toEncode, numEcBytesInBlock);

  byte[] ecBytes = new byte[numEcBytesInBlock];
  for (int i = 0; i < numEcBytesInBlock; i++) {
    ecBytes[i] = (byte) toEncode[numDataBytes + i];
  }
  return ecBytes;
}
 
Example #11
Source File: Encoder.java    From weex with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #12
Source File: Encoder.java    From ScreenCapture with MIT License 5 votes vote down vote up
static byte[] generateECBytes(byte[] dataBytes, int numEcBytesInBlock) {
  int numDataBytes = dataBytes.length;
  int[] toEncode = new int[numDataBytes + numEcBytesInBlock];
  for (int i = 0; i < numDataBytes; i++) {
    toEncode[i] = dataBytes[i] & 0xFF;
  }
  new ReedSolomonEncoder(GenericGF.QR_CODE_FIELD_256).encode(toEncode, numEcBytesInBlock);

  byte[] ecBytes = new byte[numEcBytesInBlock];
  for (int i = 0; i < numEcBytesInBlock; i++) {
    ecBytes[i] = (byte) toEncode[numDataBytes + i];
  }
  return ecBytes;
}
 
Example #13
Source File: Encoder.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #14
Source File: Encoder.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
static byte[] generateECBytes(byte[] dataBytes, int numEcBytesInBlock) {
  int numDataBytes = dataBytes.length;
  int[] toEncode = new int[numDataBytes + numEcBytesInBlock];
  for (int i = 0; i < numDataBytes; i++) {
    toEncode[i] = dataBytes[i] & 0xFF;
  }
  new ReedSolomonEncoder(GenericGF.QR_CODE_FIELD_256).encode(toEncode, numEcBytesInBlock);

  byte[] ecBytes = new byte[numEcBytesInBlock];
  for (int i = 0; i < numEcBytesInBlock; i++) {
    ecBytes[i] = (byte) toEncode[numDataBytes + i];
  }
  return ecBytes;
}
 
Example #15
Source File: Bits.java    From qart4j with GNU General Public License v3.0 5 votes vote down vote up
public void addCheckBytes(Version version, Level level) throws QArtException {
    int numberOfDataBytes = version.dataBytes(level);
    if (this.size < numberOfDataBytes*8) {
        pad(numberOfDataBytes*8 - this.size);
    }

    if (this.size != numberOfDataBytes*8) {
        throw new IllegalArgumentException("qr: too much data");
    }

    Version.VersionInfo versionInfo = Version.VERSION_INFOS[version.getVersion()];
    Version.VersionLevelInfo levelInfo = versionInfo.levelInfos[level.ordinal()];
    int numberOfDataBytesPerBlock = numberOfDataBytes / levelInfo.numberOfBlocks;
    int numberOfExtraBytes = numberOfDataBytes % levelInfo.numberOfBlocks;
    ReedSolomonEncoder reedSolomonEncoder = new ReedSolomonEncoder(GenericGF.QR_CODE_FIELD_256);

    int dataIndex = 0;
    for(int i = 0;i < levelInfo.numberOfBlocks;i++){
        if(i == levelInfo.numberOfBlocks - numberOfExtraBytes) {
            numberOfDataBytesPerBlock++;
        }

        byte[] checkBytes = ReedSolomonUtil.generateECBytes(reedSolomonEncoder, this.bits, dataIndex, numberOfDataBytesPerBlock, levelInfo.numberOfCheckBytesPerBlock);
        dataIndex += numberOfDataBytesPerBlock;

        this.append(new Bits(checkBytes, levelInfo.numberOfCheckBytesPerBlock * 8));
    }

    if(this.size/8 != versionInfo.bytes) {
        throw new QArtException("qr: internal error");
    }

}
 
Example #16
Source File: ReedSolomonUtil.java    From qart4j with GNU General Public License v3.0 5 votes vote down vote up
public static byte[] generateECBytes(ReedSolomonEncoder encoder, byte[] dataBytes, int position, int length, int numEcBytesInBlock) {
    int numDataBytes = length;
    int[] toEncode = new int[numDataBytes + numEcBytesInBlock];
    for (int i = 0; i < numDataBytes; i++) {
        toEncode[i] = dataBytes[position + i] & 0xFF;
    }
    encoder.encode(toEncode, numEcBytesInBlock);

    byte[] ecBytes = new byte[numEcBytesInBlock];
    for (int i = 0; i < numEcBytesInBlock; i++) {
        ecBytes[i] = (byte) toEncode[numDataBytes + i];
    }
    return ecBytes;
}
 
Example #17
Source File: BitBlock.java    From qart4j with GNU General Public License v3.0 5 votes vote down vote up
public BitBlock(int numberOfDataBytes, int numberOfCheckBytes, ReedSolomonEncoder encoder, byte[] primaryDataBytes, int primaryDataIndex, byte[] primaryCheckBytes, int primaryCheckIndex) throws QArtException {
    this.numberOfDataBytes = numberOfDataBytes;
    this.numberOfCheckBytes = numberOfCheckBytes;
    this.encoder = encoder;
    this.blockBytes = new byte[numberOfDataBytes + numberOfCheckBytes];
    this.primaryDataBytes = primaryDataBytes;
    this.primaryDataIndex = primaryDataIndex;
    this.primaryCheckBytes = primaryCheckBytes;
    this.primaryCheckIndex = primaryCheckIndex;

    System.arraycopy(primaryDataBytes, primaryDataIndex, blockBytes, 0, numberOfDataBytes);
    byte[] checkBytes = ReedSolomonUtil.generateECBytes(encoder, blockBytes, 0, numberOfDataBytes, numberOfCheckBytes);
    System.arraycopy(checkBytes, 0, blockBytes, numberOfDataBytes, numberOfCheckBytes);

    byte[] expectCheckBytes = new byte[numberOfCheckBytes];
    System.arraycopy(primaryCheckBytes, primaryCheckIndex, expectCheckBytes, 0, numberOfCheckBytes);
    if(!Arrays.equals(expectCheckBytes, checkBytes)) {
        throw new QArtException("check data not match");
    }

    this.maskMatrix = new byte[numberOfDataBytes*8][numberOfDataBytes + numberOfCheckBytes];
    this.maskIndex = this.maskMatrix.length;
    for(int i = 0;i < numberOfDataBytes*8;i++) {
        for(int j = 0;j < numberOfDataBytes + numberOfCheckBytes;j++) {
            maskMatrix[i][j] = 0;
        }

        maskMatrix[i][i/8] = (byte) (1 << (7 - i%8));
        checkBytes = ReedSolomonUtil.generateECBytes(encoder, maskMatrix[i], 0, numberOfDataBytes, numberOfCheckBytes);
        System.arraycopy(checkBytes, 0, maskMatrix[i], numberOfDataBytes, numberOfCheckBytes);
    }
}
 
Example #18
Source File: Encoder.java    From ZXing-Orient with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #19
Source File: Encoder.java    From ZXing-Orient with Apache License 2.0 5 votes vote down vote up
static byte[] generateECBytes(byte[] dataBytes, int numEcBytesInBlock) {
  int numDataBytes = dataBytes.length;
  int[] toEncode = new int[numDataBytes + numEcBytesInBlock];
  for (int i = 0; i < numDataBytes; i++) {
    toEncode[i] = dataBytes[i] & 0xFF;
  }
  new ReedSolomonEncoder(GenericGF.QR_CODE_FIELD_256).encode(toEncode, numEcBytesInBlock);

  byte[] ecBytes = new byte[numEcBytesInBlock];
  for (int i = 0; i < numEcBytesInBlock; i++) {
    ecBytes[i] = (byte) toEncode[numDataBytes + i];
  }
  return ecBytes;
}
 
Example #20
Source File: Encoder.java    From QrCodeScanner with GNU General Public License v3.0 5 votes vote down vote up
static byte[] generateECBytes(byte[] dataBytes, int numEcBytesInBlock) {
  int numDataBytes = dataBytes.length;
  int[] toEncode = new int[numDataBytes + numEcBytesInBlock];
  for (int i = 0; i < numDataBytes; i++) {
    toEncode[i] = dataBytes[i] & 0xFF;
  }
  new ReedSolomonEncoder(GenericGF.QR_CODE_FIELD_256).encode(toEncode, numEcBytesInBlock);

  byte[] ecBytes = new byte[numEcBytesInBlock];
  for (int i = 0; i < numEcBytesInBlock; i++) {
    ecBytes[i] = (byte) toEncode[numDataBytes + i];
  }
  return ecBytes;
}
 
Example #21
Source File: Encoder.java    From Tesseract-OCR-Scanner with Apache License 2.0 5 votes vote down vote up
static byte[] generateECBytes(byte[] dataBytes, int numEcBytesInBlock) {
  int numDataBytes = dataBytes.length;
  int[] toEncode = new int[numDataBytes + numEcBytesInBlock];
  for (int i = 0; i < numDataBytes; i++) {
    toEncode[i] = dataBytes[i] & 0xFF;
  }
  new ReedSolomonEncoder(GenericGF.QR_CODE_FIELD_256).encode(toEncode, numEcBytesInBlock);

  byte[] ecBytes = new byte[numEcBytesInBlock];
  for (int i = 0; i < numEcBytesInBlock; i++) {
    ecBytes[i] = (byte) toEncode[numDataBytes + i];
  }
  return ecBytes;
}
 
Example #22
Source File: EncoderDecoder.java    From pied-piper with MIT License 4 votes vote down vote up
public EncoderDecoder(){
	decoder = new ReedSolomonDecoder(GenericGF.QR_CODE_FIELD_256);
	encoder = new ReedSolomonEncoder(GenericGF.QR_CODE_FIELD_256);
}
 
Example #23
Source File: MainActivity.java    From OpenChirp with Apache License 2.0 4 votes vote down vote up
private final ReedSolomonEncoder getReedSolomonEncoder() {
    return this.mReedSolomonEncoder;
}