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

The following examples show how to use com.google.zxing.common.reedsolomon.GenericGF. 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 barcodescanner-lib-aar with MIT License 6 votes vote down vote up
private static GenericGF getGF(int wordSize) {
  switch (wordSize) {
    case 4:
      return GenericGF.AZTEC_PARAM;
    case 6:
      return GenericGF.AZTEC_DATA_6;
    case 8:
      return GenericGF.AZTEC_DATA_8;
    case 10:
      return GenericGF.AZTEC_DATA_10;
    case 12:
      return GenericGF.AZTEC_DATA_12;
    default:
      throw new IllegalArgumentException("Unsupported word size " + wordSize);
  }
}
 
Example #3
Source File: Encoder.java    From ZXing-Orient with Apache License 2.0 6 votes vote down vote up
private static GenericGF getGF(int wordSize) {
  switch (wordSize) {
    case 4:
      return GenericGF.AZTEC_PARAM;
    case 6:
      return GenericGF.AZTEC_DATA_6;
    case 8:
      return GenericGF.AZTEC_DATA_8;
    case 10:
      return GenericGF.AZTEC_DATA_10;
    case 12:
      return GenericGF.AZTEC_DATA_12;
    default:
      return null;
  }
}
 
Example #4
Source File: Encoder.java    From weex with Apache License 2.0 6 votes vote down vote up
private static GenericGF getGF(int wordSize) {
  switch (wordSize) {
    case 4:
      return GenericGF.AZTEC_PARAM;
    case 6:
      return GenericGF.AZTEC_DATA_6;
    case 8:
      return GenericGF.AZTEC_DATA_8;
    case 10:
      return GenericGF.AZTEC_DATA_10;
    case 12:
      return GenericGF.AZTEC_DATA_12;
    default:
      throw new IllegalArgumentException("Unsupported word size " + wordSize);
  }
}
 
Example #5
Source File: Encoder.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
private static GenericGF getGF(int wordSize) {
  switch (wordSize) {
    case 4:
      return GenericGF.AZTEC_PARAM;
    case 6:
      return GenericGF.AZTEC_DATA_6;
    case 8:
      return GenericGF.AZTEC_DATA_8;
    case 10:
      return GenericGF.AZTEC_DATA_10;
    case 12:
      return GenericGF.AZTEC_DATA_12;
    default:
      throw new IllegalArgumentException("Unsupported word size " + wordSize);
  }
}
 
Example #6
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 #7
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 #8
Source File: Detector.java    From barcodescanner-lib-aar with MIT License 5 votes vote down vote up
/**
 * Corrects the parameter bits using Reed-Solomon algorithm.
 *
 * @param parameterData parameter bits
 * @param compact true if this is a compact Aztec code
 * @throws NotFoundException if the array contains too many errors
 */
private static int getCorrectedParameterData(long parameterData, boolean compact) throws NotFoundException {
  int numCodewords;
  int numDataCodewords;

  if (compact) {
    numCodewords = 7;
    numDataCodewords = 2;
  } else {
    numCodewords = 10;
    numDataCodewords = 4;
  }

  int numECCodewords = numCodewords - numDataCodewords;
  int[] parameterWords = new int[numCodewords];
  for (int i = numCodewords - 1; i >= 0; --i) {
    parameterWords[i] = (int) parameterData & 0xF;
    parameterData >>= 4;
  }
  try {
    ReedSolomonDecoder rsDecoder = new ReedSolomonDecoder(GenericGF.AZTEC_PARAM);
    rsDecoder.decode(parameterWords, numECCodewords);
  } catch (ReedSolomonException ignored) {
    throw NotFoundException.getNotFoundInstance();
  }
  // Toss the error correction.  Just return the data as an integer
  int result = 0;
  for (int i = 0; i < numDataCodewords; i++) {
    result = (result << 4) + parameterWords[i];
  }
  return result;
}
 
Example #9
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 #10
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 #11
Source File: Detector.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Corrects the parameter bits using Reed-Solomon algorithm.
 *
 * @param parameterData parameter bits
 * @param compact true if this is a compact Aztec code
 * @throws NotFoundException if the array contains too many errors
 */
private static int getCorrectedParameterData(long parameterData, boolean compact) throws NotFoundException {
  int numCodewords;
  int numDataCodewords;

  if (compact) {
    numCodewords = 7;
    numDataCodewords = 2;
  } else {
    numCodewords = 10;
    numDataCodewords = 4;
  }

  int numECCodewords = numCodewords - numDataCodewords;
  int[] parameterWords = new int[numCodewords];
  for (int i = numCodewords - 1; i >= 0; --i) {
    parameterWords[i] = (int) parameterData & 0xF;
    parameterData >>= 4;
  }
  try {
    ReedSolomonDecoder rsDecoder = new ReedSolomonDecoder(GenericGF.AZTEC_PARAM);
    rsDecoder.decode(parameterWords, numECCodewords);
  } catch (ReedSolomonException ignored) {
    throw NotFoundException.getNotFoundInstance();
  }
  // Toss the error correction.  Just return the data as an integer
  int result = 0;
  for (int i = 0; i < numDataCodewords; i++) {
    result = (result << 4) + parameterWords[i];
  }
  return result;
}
 
Example #12
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 #13
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 #14
Source File: Detector.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
/**
 * Corrects the parameter bits using Reed-Solomon algorithm.
 *
 * @param parameterData parameter bits
 * @param compact true if this is a compact Aztec code
 * @throws NotFoundException if the array contains too many errors
 */
private static int getCorrectedParameterData(long parameterData, boolean compact) throws NotFoundException {
  int numCodewords;
  int numDataCodewords;

  if (compact) {
    numCodewords = 7;
    numDataCodewords = 2;
  } else {
    numCodewords = 10;
    numDataCodewords = 4;
  }

  int numECCodewords = numCodewords - numDataCodewords;
  int[] parameterWords = new int[numCodewords];
  for (int i = numCodewords - 1; i >= 0; --i) {
    parameterWords[i] = (int) parameterData & 0xF;
    parameterData >>= 4;
  }
  try {
    ReedSolomonDecoder rsDecoder = new ReedSolomonDecoder(GenericGF.AZTEC_PARAM);
    rsDecoder.decode(parameterWords, numECCodewords);
  } catch (ReedSolomonException ignored) {
    throw NotFoundException.getNotFoundInstance();
  }
  // Toss the error correction.  Just return the data as an integer
  int result = 0;
  for (int i = 0; i < numDataCodewords; i++) {
    result = (result << 4) + parameterWords[i];
  }
  return result;
}
 
Example #15
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 #16
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 #17
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 #18
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 #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 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 #21
Source File: Detector.java    From ZXing-Orient with Apache License 2.0 5 votes vote down vote up
/**
 * Corrects the parameter bits using Reed-Solomon algorithm.
 *
 * @param parameterData parameter bits
 * @param compact true if this is a compact Aztec code
 * @throws NotFoundException if the array contains too many errors
 */
private static int getCorrectedParameterData(long parameterData, boolean compact) throws NotFoundException {
  int numCodewords;
  int numDataCodewords;

  if (compact) {
    numCodewords = 7;
    numDataCodewords = 2;
  } else {
    numCodewords = 10;
    numDataCodewords = 4;
  }

  int numECCodewords = numCodewords - numDataCodewords;
  int[] parameterWords = new int[numCodewords];
  for (int i = numCodewords - 1; i >= 0; --i) {
    parameterWords[i] = (int) parameterData & 0xF;
    parameterData >>= 4;
  }
  try {
    ReedSolomonDecoder rsDecoder = new ReedSolomonDecoder(GenericGF.AZTEC_PARAM);
    rsDecoder.decode(parameterWords, numECCodewords);
  } catch (ReedSolomonException ignored) {
    throw NotFoundException.getNotFoundInstance();
  }
  // Toss the error correction.  Just return the data as an integer
  int result = 0;
  for (int i = 0; i < numDataCodewords; i++) {
    result = (result << 4) + parameterWords[i];
  }
  return result;
}
 
Example #22
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 #23
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 #24
Source File: Decoder.java    From RipplePower with Apache License 2.0 4 votes vote down vote up
public Decoder() {
	rsDecoder = new ReedSolomonDecoder(GenericGF.DATA_MATRIX_FIELD_256);
}
 
Example #25
Source File: Decoder.java    From barterli_android with Apache License 2.0 4 votes vote down vote up
public Decoder() {
    rsDecoder = new ReedSolomonDecoder(GenericGF.QR_CODE_FIELD_256);
}
 
Example #26
Source File: Decoder.java    From RipplePower with Apache License 2.0 4 votes vote down vote up
public Decoder() {
	rsDecoder = new ReedSolomonDecoder(GenericGF.QR_CODE_FIELD_256);
}
 
Example #27
Source File: Decoder.java    From RipplePower with Apache License 2.0 4 votes vote down vote up
public Decoder() {
	rsDecoder = new ReedSolomonDecoder(GenericGF.MAXICODE_FIELD_64);
}
 
Example #28
Source File: Decoder.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
public Decoder()
{
    d = new ReedSolomonDecoder(GenericGF.MAXICODE_FIELD_64);
}
 
Example #29
Source File: Decoder.java    From android-quick-response-code with Apache License 2.0 4 votes vote down vote up
public Decoder() {
    rsDecoder = new ReedSolomonDecoder(GenericGF.QR_CODE_FIELD_256);
}
 
Example #30
Source File: Decoder.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
public Decoder()
{
    a = new ReedSolomonDecoder(GenericGF.DATA_MATRIX_FIELD_256);
}