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); } }
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; } }
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; } }
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; }
/** * Generate the Error correction codewords thanks to the Zxing external library. * * @todo auto convert int array to byte string * * @param dataBytes * @param numEcBytesInBlock * @return ecInt */ public int[] 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); int[] ecInt = new int[numEcBytesInBlock]; for (int i = 0; i < numEcBytesInBlock; i++) { ecInt[i] = (int) ((byte) toEncode[numDataBytes + i] & 0xFF) ; } return ecInt; }
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; }
/** * 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; }
static byte[] generateECBytes(byte[] dataBytes, int numEcBytesInBlock) { int i; int numDataBytes = dataBytes.length; int[] toEncode = new int[(numDataBytes + numEcBytesInBlock)]; for (i = 0; i < numDataBytes; i++) { toEncode[i] = dataBytes[i] & 255; } new ReedSolomonEncoder(GenericGF.QR_CODE_FIELD_256).encode(toEncode, numEcBytesInBlock); byte[] ecBytes = new byte[numEcBytesInBlock]; for (i = 0; i < numEcBytesInBlock; i++) { ecBytes[i] = (byte) toEncode[numDataBytes + i]; } return ecBytes; }
private static int getCorrectedParameterData(long parameterData, boolean compact) throws NotFoundException { int numCodewords; int numDataCodewords; int i; if (compact) { numCodewords = 7; numDataCodewords = 2; } else { numCodewords = 10; numDataCodewords = 4; } int numECCodewords = numCodewords - numDataCodewords; int[] parameterWords = new int[numCodewords]; for (i = numCodewords - 1; i >= 0; i--) { parameterWords[i] = ((int) parameterData) & 15; parameterData >>= 4; } try { new ReedSolomonDecoder(GenericGF.AZTEC_PARAM).decode(parameterWords, numECCodewords); int result = 0; for (i = 0; i < numDataCodewords; i++) { result = (result << 4) + parameterWords[i]; } return result; } catch (ReedSolomonException e) { throw NotFoundException.getNotFoundInstance(); } }
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"); } }