Пример #1
0
        /// <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);
        }
Пример #2
0
        /// <summary> Initialize "qrCode" according to "numInputBytes", "ecLevel", and "mode". On success,
        /// modify "qrCode".
        /// </summary>
        private static void initQRCode(int numInputBytes, ErrorCorrectionLevel ecLevel, Mode mode, MicroQRCode qrCode, int versionNum)
        {
            qrCode.ECLevel = ecLevel;
            qrCode.Mode    = mode;

            // In the following comments, we use numbers of Version 7-H.

            Version version = Version.getVersionForNumber(versionNum);
            // numBytes = 196
            int numBytes = version.TotalCodewords;

            // getNumECBytes = 130
            Version.ECBlocks ecBlocks = version.getECBlocksForLevel(ecLevel);
            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)
            {
                // Yay, we found the proper rs block info!
                qrCode.Version       = versionNum;
                qrCode.NumTotalBytes = numBytes;
                qrCode.NumDataBytes  = numDataBytes;
                qrCode.NumRSBlocks   = numRSBlocks;
                // getNumECBytes = 196 - 66 = 130
                qrCode.NumECBytes = numEcBytes;
                // matrix width = 21 + 6 * 4 = 45
                qrCode.MatrixWidth = version.DimensionForVersion;
                return;
            }
            throw new WriterException("Cannot find proper rs block info (input data too big?)");
        }
Пример #3
0
        protected internal virtual DetectorResult processFinderPatternInfo(FinderPatternInfo info)
        {
            FinderPattern topLeft    = info.TopLeft;
            FinderPattern topRight   = info.TopRight;
            FinderPattern bottomLeft = info.BottomLeft;

            float moduleSize = calculateModuleSize(topLeft, topRight, bottomLeft);

            if (moduleSize < 1.0f)
            {
                throw ReaderException.Instance;
            }
            int     dimension               = computeDimension(topLeft, topRight, bottomLeft, moduleSize);
            Version provisionalVersion      = Version.getProvisionalVersionForDimension(dimension);
            int     modulesBetweenFPCenters = provisionalVersion.DimensionForVersion - 7;

            PerspectiveTransform transform = createTransform(topLeft, topRight, bottomLeft, dimension);

            BitMatrix bits = sampleGrid(image, transform, dimension);

            ResultPoint[] points;
            points = new ResultPoint[] { bottomLeft, topLeft, topRight };
            return(new DetectorResult(bits, points));
        }