com.google.zxing.qrcode.decoder.Version Java Examples
The following examples show how to use
com.google.zxing.qrcode.decoder.Version.
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: MatrixUtil.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
static void maybeEmbedVersionInfo(Version version, ByteMatrix matrix) throws WriterException { if (version.getVersionNumber() < 7) { // Version info is necessary if version >= 7. return; // Don't need version info. } BitArray versionInfoBits = new BitArray(); makeVersionInfoBits(version, versionInfoBits); int bitIndex = 6 * 3 - 1; // It will decrease from 17 to 0. for (int i = 0; i < 6; ++i) { for (int j = 0; j < 3; ++j) { // Place bits in LSB (least significant bit) to MSB order. boolean bit = versionInfoBits.get(bitIndex); bitIndex--; // Left bottom corner. matrix.set(i, matrix.getHeight() - 11 + j, bit); // Right bottom corner. matrix.set(matrix.getHeight() - 11 + j, i, bit); } } }
Example #2
Source File: MatrixUtil.java From weex with Apache License 2.0 | 6 votes |
static void maybeEmbedVersionInfo(Version version, ByteMatrix matrix) throws WriterException { if (version.getVersionNumber() < 7) { // Version info is necessary if version >= 7. return; // Don't need version info. } BitArray versionInfoBits = new BitArray(); makeVersionInfoBits(version, versionInfoBits); int bitIndex = 6 * 3 - 1; // It will decrease from 17 to 0. for (int i = 0; i < 6; ++i) { for (int j = 0; j < 3; ++j) { // Place bits in LSB (least significant bit) to MSB order. boolean bit = versionInfoBits.get(bitIndex); bitIndex--; // Left bottom corner. matrix.set(i, matrix.getHeight() - 11 + j, bit); // Right bottom corner. matrix.set(matrix.getHeight() - 11 + j, i, bit); } } }
Example #3
Source File: Encoder.java From barcodescanner-lib-aar with MIT License | 6 votes |
private static int chooseMaskPattern(BitArray bits, ErrorCorrectionLevel ecLevel, Version version, ByteMatrix matrix) throws WriterException { int minPenalty = Integer.MAX_VALUE; // Lower penalty is better. int bestMaskPattern = -1; // We try all mask patterns to choose the best one. for (int maskPattern = 0; maskPattern < QRCode.NUM_MASK_PATTERNS; maskPattern++) { MatrixUtil.buildMatrix(bits, ecLevel, version, maskPattern, matrix); int penalty = calculateMaskPenalty(matrix); if (penalty < minPenalty) { minPenalty = penalty; bestMaskPattern = maskPattern; } } return bestMaskPattern; }
Example #4
Source File: Encoder.java From MiBandDecompiled with Apache License 2.0 | 6 votes |
private static void a(int i, ErrorCorrectionLevel errorcorrectionlevel, Mode mode, QRCode qrcode) { qrcode.setECLevel(errorcorrectionlevel); qrcode.setMode(mode); for (int j = 1; j <= 40; j++) { Version version = Version.getVersionForNumber(j); int k = version.getTotalCodewords(); com.google.zxing.qrcode.decoder.Version.ECBlocks ecblocks = version.getECBlocksForLevel(errorcorrectionlevel); int l = ecblocks.getTotalECCodewords(); int i1 = ecblocks.getNumBlocks(); int j1 = k - l; if (j1 >= a(i, version, mode)) { qrcode.setVersion(j); qrcode.setNumTotalBytes(k); qrcode.setNumDataBytes(j1); qrcode.setNumRSBlocks(i1); qrcode.setNumECBytes(l); qrcode.setMatrixWidth(version.getDimensionForVersion()); return; } } throw new WriterException("Cannot find proper rs block info (input data too big?)"); }
Example #5
Source File: Encoder.java From ScreenCapture with MIT License | 6 votes |
private static int chooseMaskPattern(BitArray bits, ErrorCorrectionLevel ecLevel, Version version, ByteMatrix matrix) throws WriterException { int minPenalty = Integer.MAX_VALUE; // Lower penalty is better. int bestMaskPattern = -1; // We try all mask patterns to choose the best one. for (int maskPattern = 0; maskPattern < QRCode.NUM_MASK_PATTERNS; maskPattern++) { MatrixUtil.buildMatrix(bits, ecLevel, version, maskPattern, matrix); int penalty = calculateMaskPenalty(matrix); if (penalty < minPenalty) { minPenalty = penalty; bestMaskPattern = maskPattern; } } return bestMaskPattern; }
Example #6
Source File: MatrixUtil.java From ScreenCapture with MIT License | 6 votes |
static void maybeEmbedVersionInfo(Version version, ByteMatrix matrix) throws WriterException { if (version.getVersionNumber() < 7) { // Version info is necessary if version >= 7. return; // Don't need version info. } BitArray versionInfoBits = new BitArray(); makeVersionInfoBits(version, versionInfoBits); int bitIndex = 6 * 3 - 1; // It will decrease from 17 to 0. for (int i = 0; i < 6; ++i) { for (int j = 0; j < 3; ++j) { // Place bits in LSB (least significant bit) to MSB order. boolean bit = versionInfoBits.get(bitIndex); bitIndex--; // Left bottom corner. matrix.set(i, matrix.getHeight() - 11 + j, bit); // Right bottom corner. matrix.set(matrix.getHeight() - 11 + j, i, bit); } } }
Example #7
Source File: MatrixUtil.java From weex with Apache License 2.0 | 6 votes |
private static void maybeEmbedPositionAdjustmentPatterns(Version version, ByteMatrix matrix) { if (version.getVersionNumber() < 2) { // The patterns appear if version >= 2 return; } int index = version.getVersionNumber() - 1; int[] coordinates = POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[index]; int numCoordinates = POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[index].length; for (int i = 0; i < numCoordinates; ++i) { for (int j = 0; j < numCoordinates; ++j) { int y = coordinates[i]; int x = coordinates[j]; if (x == -1 || y == -1) { continue; } // If the cell is unset, we embed the position adjustment pattern here. if (isEmpty(matrix.get(x, y))) { // -2 is necessary since the x/y coordinates point to the center of the pattern, not the // left top corner. embedPositionAdjustmentPattern(x - 2, y - 2, matrix); } } } }
Example #8
Source File: Encoder.java From weex with Apache License 2.0 | 6 votes |
private static Version chooseVersion(int numInputBits, ErrorCorrectionLevel ecLevel) throws WriterException { // In the following comments, we use numbers of Version 7-H. for (int versionNum = 1; versionNum <= 40; versionNum++) { Version version = Version.getVersionForNumber(versionNum); // 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; if (numDataBytes >= totalInputBytes) { return version; } } throw new WriterException("Data too big"); }
Example #9
Source File: Encoder.java From weex with Apache License 2.0 | 6 votes |
private static int chooseMaskPattern(BitArray bits, ErrorCorrectionLevel ecLevel, Version version, ByteMatrix matrix) throws WriterException { int minPenalty = Integer.MAX_VALUE; // Lower penalty is better. int bestMaskPattern = -1; // We try all mask patterns to choose the best one. for (int maskPattern = 0; maskPattern < QRCode.NUM_MASK_PATTERNS; maskPattern++) { MatrixUtil.buildMatrix(bits, ecLevel, version, maskPattern, matrix); int penalty = calculateMaskPenalty(matrix); if (penalty < minPenalty) { minPenalty = penalty; bestMaskPattern = maskPattern; } } return bestMaskPattern; }
Example #10
Source File: Qr.java From bither-android with Apache License 2.0 | 6 votes |
public static void printQrContentSize() { for (int versionNum = 1; versionNum <= 40; versionNum++) { Version version = Version.getVersionForNumber(versionNum); // numBytes = 196 int numBytes = version.getTotalCodewords(); // getNumECBytes = 130 Version.ECBlocks ecBlocks = version.getECBlocksForLevel(ErrorCorrectionLevel.L); int numEcBytes = ecBlocks.getTotalECCodewords(); // getNumDataBytes = 196 - 130 = 66 int numDataBytes = numBytes - numEcBytes; int numInputBytes = numDataBytes * 8 - 7; int length = (numInputBytes - 10) / 11 * 2; LogUtil.d("Qr", "Version: " + versionNum + " numData bytes: " + numDataBytes + " " + "input: " + numInputBytes + " string length: " + length); } }
Example #11
Source File: MatrixUtil.java From Telegram with GNU General Public License v2.0 | 6 votes |
private static void maybeEmbedPositionAdjustmentPatterns(Version version, ByteMatrix matrix) { if (version.getVersionNumber() < 2) { // The patterns appear if version >= 2 return; } int index = version.getVersionNumber() - 1; int[] coordinates = POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[index]; for (int y : coordinates) { if (y >= 0) { for (int x : coordinates) { if (x >= 0 && isEmpty(matrix.get(x, y))) { // If the cell is unset, we embed the position adjustment pattern here. // -2 is necessary since the x/y coordinates point to the center of the pattern, not the // left top corner. embedPositionAdjustmentPattern(x - 2, y - 2, matrix); } } } } }
Example #12
Source File: Encoder.java From analyzer-of-android-for-Apache-Weex with Apache License 2.0 | 6 votes |
private static Version chooseVersion(int numInputBits, ErrorCorrectionLevel ecLevel) throws WriterException { // In the following comments, we use numbers of Version 7-H. for (int versionNum = 1; versionNum <= 40; versionNum++) { Version version = Version.getVersionForNumber(versionNum); // 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; if (numDataBytes >= totalInputBytes) { return version; } } throw new WriterException("Data too big"); }
Example #13
Source File: Encoder.java From RipplePower with Apache License 2.0 | 6 votes |
private static Version chooseVersion(int numInputBits, ErrorCorrectionLevel ecLevel) throws WriterException { // In the following comments, we use numbers of Version 7-H. for (int versionNum = 1; versionNum <= 40; versionNum++) { Version version = Version.getVersionForNumber(versionNum); // 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; if (numDataBytes >= totalInputBytes) { return version; } } throw new WriterException("Data too big"); }
Example #14
Source File: MatrixUtil.java From ZXing-Orient with Apache License 2.0 | 6 votes |
private static void maybeEmbedPositionAdjustmentPatterns(Version version, ByteMatrix matrix) { if (version.getVersionNumber() < 2) { // The patterns appear if version >= 2 return; } int index = version.getVersionNumber() - 1; int[] coordinates = POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[index]; int numCoordinates = POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[index].length; for (int i = 0; i < numCoordinates; ++i) { for (int j = 0; j < numCoordinates; ++j) { int y = coordinates[i]; int x = coordinates[j]; if (x == -1 || y == -1) { continue; } // If the cell is unset, we embed the position adjustment pattern here. if (isEmpty(matrix.get(x, y))) { // -2 is necessary since the x/y coordinates point to the center of the pattern, not the // left top corner. embedPositionAdjustmentPattern(x - 2, y - 2, matrix); } } } }
Example #15
Source File: MatrixUtil.java From ZXing-Orient with Apache License 2.0 | 6 votes |
static void maybeEmbedVersionInfo(Version version, ByteMatrix matrix) throws WriterException { if (version.getVersionNumber() < 7) { // Version info is necessary if version >= 7. return; // Don't need version info. } BitArray versionInfoBits = new BitArray(); makeVersionInfoBits(version, versionInfoBits); int bitIndex = 6 * 3 - 1; // It will decrease from 17 to 0. for (int i = 0; i < 6; ++i) { for (int j = 0; j < 3; ++j) { // Place bits in LSB (least significant bit) to MSB order. boolean bit = versionInfoBits.get(bitIndex); bitIndex--; // Left bottom corner. matrix.set(i, matrix.getHeight() - 11 + j, bit); // Right bottom corner. matrix.set(matrix.getHeight() - 11 + j, i, bit); } } }
Example #16
Source File: Encoder.java From reacteu-app with MIT License | 6 votes |
private static int chooseMaskPattern(BitArray bits, ErrorCorrectionLevel ecLevel, Version version, ByteMatrix matrix) throws WriterException { int minPenalty = Integer.MAX_VALUE; // Lower penalty is better. int bestMaskPattern = -1; // We try all mask patterns to choose the best one. for (int maskPattern = 0; maskPattern < QRCode.NUM_MASK_PATTERNS; maskPattern++) { MatrixUtil.buildMatrix(bits, ecLevel, version, maskPattern, matrix); int penalty = calculateMaskPenalty(matrix); if (penalty < minPenalty) { minPenalty = penalty; bestMaskPattern = maskPattern; } } return bestMaskPattern; }
Example #17
Source File: Encoder.java From ZXing-Orient with Apache License 2.0 | 6 votes |
private static Version chooseVersion(int numInputBits, ErrorCorrectionLevel ecLevel) throws WriterException { // In the following comments, we use numbers of Version 7-H. for (int versionNum = 1; versionNum <= 40; versionNum++) { Version version = Version.getVersionForNumber(versionNum); // 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; if (numDataBytes >= totalInputBytes) { return version; } } throw new WriterException("Data too big"); }
Example #18
Source File: Encoder.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
private static int chooseMaskPattern(BitArray bits, ErrorCorrectionLevel ecLevel, Version version, ByteMatrix matrix) throws WriterException { int minPenalty = Integer.MAX_VALUE; // Lower penalty is better. int bestMaskPattern = -1; // We try all mask patterns to choose the best one. for (int maskPattern = 0; maskPattern < QRCode.NUM_MASK_PATTERNS; maskPattern++) { MatrixUtil.buildMatrix(bits, ecLevel, version, maskPattern, matrix); int penalty = calculateMaskPenalty(matrix); if (penalty < minPenalty) { minPenalty = penalty; bestMaskPattern = maskPattern; } } return bestMaskPattern; }
Example #19
Source File: MatrixUtil.java From QrCodeScanner with GNU General Public License v3.0 | 6 votes |
private static void maybeEmbedPositionAdjustmentPatterns(Version version, ByteMatrix matrix) { if (version.getVersionNumber() < 2) { // The patterns appear if version >= 2 return; } int index = version.getVersionNumber() - 1; int[] coordinates = POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[index]; for (int y : coordinates) { if (y >= 0) { for (int x : coordinates) { if (x >= 0 && isEmpty(matrix.get(x, y))) { // If the cell is unset, we embed the position adjustment pattern here. // -2 is necessary since the x/y coordinates point to the center of the pattern, not the // left top corner. embedPositionAdjustmentPattern(x - 2, y - 2, matrix); } } } } }
Example #20
Source File: MatrixUtil.java From barcodescanner-lib-aar with MIT License | 6 votes |
private static void maybeEmbedPositionAdjustmentPatterns(Version version, ByteMatrix matrix) { if (version.getVersionNumber() < 2) { // The patterns appear if version >= 2 return; } int index = version.getVersionNumber() - 1; int[] coordinates = POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[index]; int numCoordinates = POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[index].length; for (int i = 0; i < numCoordinates; ++i) { for (int j = 0; j < numCoordinates; ++j) { int y = coordinates[i]; int x = coordinates[j]; if (x == -1 || y == -1) { continue; } // If the cell is unset, we embed the position adjustment pattern here. if (isEmpty(matrix.get(x, y))) { // -2 is necessary since the x/y coordinates point to the center of the pattern, not the // left top corner. embedPositionAdjustmentPattern(x - 2, y - 2, matrix); } } } }
Example #21
Source File: Encoder.java From reacteu-app with MIT License | 6 votes |
private static Version chooseVersion(int numInputBits, ErrorCorrectionLevel ecLevel) throws WriterException { // In the following comments, we use numbers of Version 7-H. for (int versionNum = 1; versionNum <= 40; versionNum++) { Version version = Version.getVersionForNumber(versionNum); // 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; if (numDataBytes >= totalInputBytes) { return version; } } throw new WriterException("Data too big"); }
Example #22
Source File: MatrixUtil.java From analyzer-of-android-for-Apache-Weex with Apache License 2.0 | 5 votes |
static void embedBasicPatterns(Version version, ByteMatrix matrix) throws WriterException { // Let's get started with embedding big squares at corners. embedPositionDetectionPatternsAndSeparators(matrix); // Then, embed the dark dot at the left bottom corner. embedDarkDotAtLeftBottomCorner(matrix); // Position adjustment patterns appear if version >= 2. maybeEmbedPositionAdjustmentPatterns(version, matrix); // Timing patterns should be embedded after position adj. patterns. embedTimingPatterns(matrix); }
Example #23
Source File: Encoder.java From analyzer-of-android-for-Apache-Weex with Apache License 2.0 | 5 votes |
/** * Append length info. On success, store the result in "bits". */ 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); }
Example #24
Source File: MatrixUtil.java From analyzer-of-android-for-Apache-Weex with Apache License 2.0 | 5 votes |
static void makeVersionInfoBits(Version version, BitArray bits) throws WriterException { bits.appendBits(version.getVersionNumber(), 6); int bchCode = calculateBCHCode(version.getVersionNumber(), VERSION_INFO_POLY); bits.appendBits(bchCode, 12); if (bits.getSize() != 18) { // Just in case. throw new WriterException("should not happen but we got: " + bits.getSize()); } }
Example #25
Source File: Encoder.java From ZXing-Orient with Apache License 2.0 | 5 votes |
/** * Append length info. On success, store the result in "bits". */ 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); }
Example #26
Source File: Encoder.java From Telegram with GNU General Public License v2.0 | 5 votes |
/** * @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; }
Example #27
Source File: Encoder.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
private static Version chooseVersion(int numInputBits, ErrorCorrectionLevel ecLevel) throws WriterException { for (int versionNum = 1; versionNum <= 40; versionNum++) { Version version = Version.getVersionForNumber(versionNum); if (willFit(numInputBits, version, ecLevel)) { return version; } } throw new WriterException("Data too big"); }
Example #28
Source File: MatrixUtil.java From QrCodeScanner with GNU General Public License v3.0 | 5 votes |
static void makeVersionInfoBits(Version version, BitArray bits) throws WriterException { bits.appendBits(version.getVersionNumber(), 6); int bchCode = calculateBCHCode(version.getVersionNumber(), VERSION_INFO_POLY); bits.appendBits(bchCode, 12); if (bits.getSize() != 18) { // Just in case. throw new WriterException("should not happen but we got: " + bits.getSize()); } }
Example #29
Source File: MatrixUtil.java From QrCodeScanner with GNU General Public License v3.0 | 5 votes |
static void embedBasicPatterns(Version version, ByteMatrix matrix) throws WriterException { // Let's get started with embedding big squares at corners. embedPositionDetectionPatternsAndSeparators(matrix); // Then, embed the dark dot at the left bottom corner. embedDarkDotAtLeftBottomCorner(matrix); // Position adjustment patterns appear if version >= 2. maybeEmbedPositionAdjustmentPatterns(version, matrix); // Timing patterns should be embedded after position adj. patterns. embedTimingPatterns(matrix); }
Example #30
Source File: MatrixUtil.java From QrCodeScanner with GNU General Public License v3.0 | 5 votes |
static void buildMatrix(BitArray dataBits, ErrorCorrectionLevel ecLevel, Version version, int maskPattern, ByteMatrix matrix) throws WriterException { clearMatrix(matrix); embedBasicPatterns(version, matrix); // Type information appear with any version. embedTypeInfo(ecLevel, maskPattern, matrix); // Version info appear if version >= 7. maybeEmbedVersionInfo(version, matrix); // Data should be embedded at end. embedDataBits(dataBits, maskPattern, matrix); }