/// <summary> Append length info. On success, store the result in "bits".</summary> internal static void appendLengthInfo(int numLetters, int version, Mode mode, BitVector bits) { int numBits = mode.getCharacterCountBits(Version.getVersionForNumber(version)); if (numLetters > ((1 << numBits) - 1)) { throw new WriterException(numLetters + "is bigger than" + ((1 << numBits) - 1)); } bits.appendBits(numLetters, numBits); }
private static string ECBlocksToString(VersionZX.ECBlocks ecBlocks) { VersionZX.ECB[] ecBlock = ecBlocks.getECBlocks(); string returnValue = ""; foreach(VersionZX.ECB ecb in ecBlock) { returnValue = string.Join(s_Separator, returnValue, ecb.Count, ecb.DataCodewords); } return returnValue; }
/// <summary> Initialize "QRCodeInternal" according to "numInputBytes", "m_EcLevelInternal", and "mode". On success, /// modify "QRCodeInternal". /// </summary> internal static void initQRCode(int numInputBytes, ErrorCorrectionLevelInternal m_EcLevelInternal, Mode mode, QRCodeInternal qrCodeInternal) { qrCodeInternal.EcLevelInternal = m_EcLevelInternal; qrCodeInternal.Mode = mode; // 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.TotalCodewords; // getNumECBytes = 130 Version.ECBlocks ecBlocks = version.getECBlocksForLevel(m_EcLevelInternal); int numEcBytes = ecBlocks.TotalECCodewords; // getNumRSBlocks = 5 int numRSBlocks = ecBlocks.NumBlocks; // getNumDataBytes = 196 - 130 = 66 int numDataBytes = numBytes - numEcBytes; // We want to choose the smallest version which can contain data of "numInputBytes" + some // extra bits for the header (mode info and length info). The header can be three bytes // (precisely 4 + 16 bits) at most. Hence we do +3 here. if (numDataBytes >= numInputBytes + 3) { // Yay, we found the proper rs block info! qrCodeInternal.Version = versionNum; qrCodeInternal.NumTotalBytes = numBytes; qrCodeInternal.NumDataBytes = numDataBytes; qrCodeInternal.NumRSBlocks = numRSBlocks; // getNumECBytes = 196 - 66 = 130 qrCodeInternal.NumECBytes = numEcBytes; // matrix width = 21 + 6 * 4 = 45 qrCodeInternal.MatrixWidth = version.DimensionForVersion; return; } } throw new WriterException("Cannot find proper rs block info (input data too big?)"); }
/** * <p>Reads version information from one of its two locations within the QR Code.</p> * * @return {@link Version} encapsulating the QR Code's version * @throws ReaderException if both version information locations cannot be parsed as * the valid encoding of version information */ public Version readVersion(){ if (parsedVersion != null) { return parsedVersion; } int dimension = bitMatrix.getDimension(); int provisionalVersion = (dimension - 17) >> 2; if (provisionalVersion <= 6) { return Version.getVersionForNumber(provisionalVersion); } // Read top-right version info: 3 wide by 6 tall int versionBits = 0; for (int i = 5; i >= 0; i--) { int jMin = dimension - 11; for (int j = dimension - 9; j >= jMin; j--) { versionBits = copyBit(i, j, versionBits); } } parsedVersion = Version.decodeVersionInformation(versionBits); if (parsedVersion != null) { return parsedVersion; } // Hmm, failed. Try bottom left: 6 wide by 3 tall versionBits = 0; for (int j = 5; j >= 0; j--) { int iMin = dimension - 11; for (int i = dimension - 11; i >= iMin; i--) { versionBits = copyBit(i, j, versionBits); } } parsedVersion = Version.decodeVersionInformation(versionBits); if (parsedVersion != null) { return parsedVersion; } throw new ReaderException(); }
/// <summary> /// <p>Reads version information from one of its two locations within the QR Code.</p> /// </summary> /// <returns> <seealso cref="Version"/> encapsulating the QR Code's version </returns> /// <exception cref="FormatException"> if both version information locations cannot be parsed as /// the valid encoding of version information </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: Version readVersion() throws com.google.zxing.FormatException internal Version readVersion() { if (parsedVersion != null) { return parsedVersion; } int dimension = bitMatrix.Height; int provisionalVersion = (dimension - 17) >> 2; if (provisionalVersion <= 6) { return Version.getVersionForNumber(provisionalVersion); } // Read top-right version info: 3 wide by 6 tall int versionBits = 0; int ijMin = dimension - 11; for (int j = 5; j >= 0; j--) { for (int i = dimension - 9; i >= ijMin; i--) { versionBits = copyBit(i, j, versionBits); } } Version theParsedVersion = Version.decodeVersionInformation(versionBits); if (theParsedVersion != null && theParsedVersion.DimensionForVersion == dimension) { parsedVersion = theParsedVersion; return theParsedVersion; } // Hmm, failed. Try bottom left: 6 wide by 3 tall versionBits = 0; for (int i = 5; i >= 0; i--) { for (int j = dimension - 9; j >= ijMin; j--) { versionBits = copyBit(i, j, versionBits); } } theParsedVersion = Version.decodeVersionInformation(versionBits); if (theParsedVersion != null && theParsedVersion.DimensionForVersion == dimension) { parsedVersion = theParsedVersion; return theParsedVersion; } throw FormatException.FormatInstance; }