return Version.getVersionForNumber(provisionalVersion); parsedVersion = Version.decodeVersionInformation(versionBits); if (parsedVersion != null && parsedVersion.getDimensionForVersion() == dimension) { return parsedVersion; parsedVersion = Version.decodeVersionInformation(versionBits); if (parsedVersion != null && parsedVersion.getDimensionForVersion() == dimension) { return parsedVersion;
try { qrCode = Encoder.encode(contentsToEncode, level, hints); patternCenters = qrCode.getVersion().getAlignmentPatternCenters();
/** * @return true if the number of input bits will fit in a code with the specified version and * error correction level. */ private static boolean willFit(int numInputBits, Version version, ErrorCorrectionLevel ecLevel) { // In the following comments, we use numbers of Version 7-H. // numBytes = 196 int numBytes = version.getTotalCodewords(); // getNumECBytes = 130 Version.ECBlocks ecBlocks = version.getECBlocksForLevel(ecLevel); int numEcBytes = ecBlocks.getTotalECCodewords(); // getNumDataBytes = 196 - 130 = 66 int numDataBytes = numBytes - numEcBytes; int totalInputBytes = (numInputBits + 7) / 8; return numDataBytes >= totalInputBytes; }
Version version = Version.getVersionForNumber(versionNum); int numBytes = version.getTotalCodewords(); Version.ECBlocks ecBlocks = version.getECBlocksForLevel(ecLevel); int numEcBytes = ecBlocks.getTotalECCodewords(); qrCode.setMatrixWidth(version.getDimensionForVersion()); return;
Version provisionalVersion = Version.getProvisionalVersionForDimension(dimension); int modulesBetweenFPCenters = provisionalVersion.getDimensionForVersion() - 7; if (provisionalVersion.getAlignmentPatternCenters().length > 0) {
dataMask.unmaskBitMatrix(bitMatrix, dimension); BitMatrix functionPattern = version.buildFunctionPattern(); byte[] result = new byte[version.getTotalCodewords()]; int resultOffset = 0; int currentByte = 0; if (resultOffset != version.getTotalCodewords()) { throw FormatException.getFormatInstance();
static Version decodeVersionInformation(int versionBits) { int bestDifference = Integer.MAX_VALUE; int bestVersion = 0; for (int i = 0; i < VERSION_DECODE_INFO.length; i++) { int targetVersion = VERSION_DECODE_INFO[i]; // Do the version info bits match exactly? done. if (targetVersion == versionBits) { return getVersionForNumber(i + 7); } // Otherwise see if this is the closest to a real version info bit string // we have seen so far int bitsDifference = FormatInformation.numBitsDiffering(versionBits, targetVersion); if (bitsDifference < bestDifference) { bestVersion = i + 7; bestDifference = bitsDifference; } } // We can tolerate up to 3 bits of error since no two version info codewords will // differ in less than 8 bits. if (bestDifference <= 3) { return getVersionForNumber(bestVersion); } // If we didn't find a close enough match, fail return null; }
/** * @param version version in question * @return number of bits used, in this QR Code symbol {@link Version}, to encode the * count of characters that will follow encoded in this Mode */ public int getCharacterCountBits(Version version) { int number = version.getVersionNumber(); int offset; if (number <= 9) { offset = 0; } else if (number <= 26) { offset = 1; } else { offset = 2; } return characterCountBitsForVersions[offset]; }
int dimension = getDimensionForVersion(); BitMatrix bitMatrix = new BitMatrix(dimension);
new Version(1, new int[]{}, new ECBlocks(7, new ECB(1, 19)), new ECBlocks(10, new ECB(1, 16)), new ECBlocks(13, new ECB(1, 13)), new ECBlocks(17, new ECB(1, 9))), new Version(2, new int[]{6, 18}, new ECBlocks(10, new ECB(1, 34)), new ECBlocks(16, new ECB(1, 28)), new ECBlocks(22, new ECB(1, 22)), new ECBlocks(28, new ECB(1, 16))), new Version(3, new int[]{6, 22}, new ECBlocks(15, new ECB(1, 55)), new ECBlocks(26, new ECB(1, 44)), new ECBlocks(18, new ECB(2, 17)), new ECBlocks(22, new ECB(2, 13))), new Version(4, new int[]{6, 26}, new ECBlocks(20, new ECB(1, 80)), new ECBlocks(18, new ECB(2, 32)), new ECBlocks(26, new ECB(2, 24)), new ECBlocks(16, new ECB(4, 9))), new Version(5, new int[]{6, 30}, new ECBlocks(26, new ECB(1, 108)), new ECBlocks(24, new ECB(2, 43)), new ECBlocks(22, new ECB(2, 11), new ECB(2, 12))), new Version(6, new int[]{6, 34}, new ECBlocks(18, new ECB(2, 68)), new ECBlocks(16, new ECB(4, 27)),
Version version = Version.getVersionForNumber(versionNum); int numBytes = version.getTotalCodewords(); Version.ECBlocks ecBlocks = version.getECBlocksForLevel(ecLevel); int numEcBytes = ecBlocks.getTotalECCodewords(); qrCode.setMatrixWidth(version.getDimensionForVersion()); return;
Version provisionalVersion = Version.getProvisionalVersionForDimension(dimension); int modulesBetweenFPCenters = provisionalVersion.getDimensionForVersion() - 7; if (provisionalVersion.getAlignmentPatternCenters().length > 0) {
dataMask.unmaskBitMatrix(bitMatrix, dimension); BitMatrix functionPattern = version.buildFunctionPattern(); byte[] result = new byte[version.getTotalCodewords()]; int resultOffset = 0; int currentByte = 0; if (resultOffset != version.getTotalCodewords()) { throw FormatException.getFormatInstance();
static Version decodeVersionInformation(int versionBits) { int bestDifference = Integer.MAX_VALUE; int bestVersion = 0; for (int i = 0; i < VERSION_DECODE_INFO.length; i++) { int targetVersion = VERSION_DECODE_INFO[i]; // Do the version info bits match exactly? done. if (targetVersion == versionBits) { return getVersionForNumber(i + 7); } // Otherwise see if this is the closest to a real version info bit string // we have seen so far int bitsDifference = FormatInformation.numBitsDiffering(versionBits, targetVersion); if (bitsDifference < bestDifference) { bestVersion = i + 7; bestDifference = bitsDifference; } } // We can tolerate up to 3 bits of error since no two version info codewords will // differ in less than 8 bits. if (bestDifference <= 3) { return getVersionForNumber(bestVersion); } // If we didn't find a close enough match, fail return null; }
/** * @param version version in question * @return number of bits used, in this QR Code symbol {@link Version}, to encode the * count of characters that will follow encoded in this Mode */ public int getCharacterCountBits(Version version) { int number = version.getVersionNumber(); int offset; if (number <= 9) { offset = 0; } else if (number <= 26) { offset = 1; } else { offset = 2; } return characterCountBitsForVersions[offset]; }
int dimension = getDimensionForVersion(); BitMatrix bitMatrix = new BitMatrix(dimension);
new Version(1, new int[]{}, new ECBlocks(7, new ECB(1, 19)), new ECBlocks(10, new ECB(1, 16)), new ECBlocks(13, new ECB(1, 13)), new ECBlocks(17, new ECB(1, 9))), new Version(2, new int[]{6, 18}, new ECBlocks(10, new ECB(1, 34)), new ECBlocks(16, new ECB(1, 28)), new ECBlocks(22, new ECB(1, 22)), new ECBlocks(28, new ECB(1, 16))), new Version(3, new int[]{6, 22}, new ECBlocks(15, new ECB(1, 55)), new ECBlocks(26, new ECB(1, 44)), new ECBlocks(18, new ECB(2, 17)), new ECBlocks(22, new ECB(2, 13))), new Version(4, new int[]{6, 26}, new ECBlocks(20, new ECB(1, 80)), new ECBlocks(18, new ECB(2, 32)), new ECBlocks(26, new ECB(2, 24)), new ECBlocks(16, new ECB(4, 9))), new Version(5, new int[]{6, 30}, new ECBlocks(26, new ECB(1, 108)), new ECBlocks(24, new ECB(2, 43)), new ECBlocks(22, new ECB(2, 11), new ECB(2, 12))), new Version(6, new int[]{6, 34}, new ECBlocks(18, new ECB(2, 68)), new ECBlocks(16, new ECB(4, 27)),
if (hints != null && hints.containsKey(EncodeHintType.QR_VERSION)) { int versionNumber = Integer.parseInt(hints.get(EncodeHintType.QR_VERSION).toString()); version = Version.getVersionForNumber(versionNumber); int bitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, version); if (!willFit(bitsNeeded, version, ecLevel)) { Version.ECBlocks ecBlocks = version.getECBlocksForLevel(ecLevel); int numDataBytes = version.getTotalCodewords() - ecBlocks.getTotalECCodewords(); version.getTotalCodewords(), numDataBytes, ecBlocks.getNumBlocks()); int dimension = version.getDimensionForVersion(); ByteMatrix matrix = new ByteMatrix(dimension, dimension); int maskPattern = chooseMaskPattern(finalBits, ecLevel, version, matrix);
return Version.getVersionForNumber(provisionalVersion); Version theParsedVersion = Version.decodeVersionInformation(versionBits); if (theParsedVersion != null && theParsedVersion.getDimensionForVersion() == dimension) { parsedVersion = theParsedVersion; return theParsedVersion; theParsedVersion = Version.decodeVersionInformation(versionBits); if (theParsedVersion != null && theParsedVersion.getDimensionForVersion() == dimension) { parsedVersion = theParsedVersion; return theParsedVersion;
/** * @return true if the number of input bits will fit in a code with the specified version and * error correction level. */ private static boolean willFit(int numInputBits, Version version, ErrorCorrectionLevel ecLevel) { // In the following comments, we use numbers of Version 7-H. // numBytes = 196 int numBytes = version.getTotalCodewords(); // getNumECBytes = 130 Version.ECBlocks ecBlocks = version.getECBlocksForLevel(ecLevel); int numEcBytes = ecBlocks.getTotalECCodewords(); // getNumDataBytes = 196 - 130 = 66 int numDataBytes = numBytes - numEcBytes; int totalInputBytes = (numInputBits + 7) / 8; return numDataBytes >= totalInputBytes; }