Esempio n. 1
0
        /**
         * <p>Reads format information from one of its two locations within the QR Code.</p>
         *
         * @return {@link FormatInformation} encapsulating the QR Code's format info
         * @throws ReaderException if both format information locations cannot be parsed as
         * the valid encoding of format information
         */
        public FormatInformation readFormatInformation()
        {
            if (parsedFormatInfo != null)
            {
                return(parsedFormatInfo);
            }

            // Read top-left format info bits
            int formatInfoBits = 0;

            for (int j = 0; j < 6; j++)
            {
                formatInfoBits = copyBit(8, j, formatInfoBits);
            }
            // .. and skip a bit in the timing pattern ...
            formatInfoBits = copyBit(8, 7, formatInfoBits);
            formatInfoBits = copyBit(8, 8, formatInfoBits);
            formatInfoBits = copyBit(7, 8, formatInfoBits);
            // .. and skip a bit in the timing pattern ...
            for (int i = 5; i >= 0; i--)
            {
                formatInfoBits = copyBit(i, 8, formatInfoBits);
            }

            parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits);
            if (parsedFormatInfo != null)
            {
                return(parsedFormatInfo);
            }

            // Hmm, failed. Try the top-right/bottom-left pattern
            int dimension = bitMatrix.getDimension();

            formatInfoBits = 0;
            int iMin = dimension - 8;

            for (int i = dimension - 1; i >= iMin; i--)
            {
                formatInfoBits = copyBit(i, 8, formatInfoBits);
            }
            for (int j = dimension - 7; j < dimension; j++)
            {
                formatInfoBits = copyBit(8, j, formatInfoBits);
            }

            parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits);
            if (parsedFormatInfo != null)
            {
                return(parsedFormatInfo);
            }
            throw new ReaderException();
        }
Esempio n. 2
0
        /// <summary>
        /// <p>Reads format information from one of its two locations within the QR Code.</p>
        /// </summary>
        /// <returns> <seealso cref="FormatInformation"/> encapsulating the QR Code's format info </returns>
        /// <exception cref="FormatException"> if both format information locations cannot be parsed as
        /// the valid encoding of format information </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: FormatInformation readFormatInformation() throws com.google.zxing.FormatException
        internal FormatInformation readFormatInformation()
        {
            if (parsedFormatInfo != null)
            {
                return(parsedFormatInfo);
            }

            // Read top-left format info bits
            int formatInfoBits1 = 0;

            for (int i = 0; i < 6; i++)
            {
                formatInfoBits1 = copyBit(i, 8, formatInfoBits1);
            }
            // .. and skip a bit in the timing pattern ...
            formatInfoBits1 = copyBit(7, 8, formatInfoBits1);
            formatInfoBits1 = copyBit(8, 8, formatInfoBits1);
            formatInfoBits1 = copyBit(8, 7, formatInfoBits1);
            // .. and skip a bit in the timing pattern ...
            for (int j = 5; j >= 0; j--)
            {
                formatInfoBits1 = copyBit(8, j, formatInfoBits1);
            }

            // Read the top-right/bottom-left pattern too
            int dimension       = bitMatrix.Height;
            int formatInfoBits2 = 0;
            int jMin            = dimension - 7;

            for (int j = dimension - 1; j >= jMin; j--)
            {
                formatInfoBits2 = copyBit(8, j, formatInfoBits2);
            }
            for (int i = dimension - 8; i < dimension; i++)
            {
                formatInfoBits2 = copyBit(i, 8, formatInfoBits2);
            }

            parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits1, formatInfoBits2);
            if (parsedFormatInfo != null)
            {
                return(parsedFormatInfo);
            }
            throw FormatException.FormatInstance;
        }