コード例 #1
0
ファイル: Version.cs プロジェクト: smart-make/zxing
        public static Version decodeVersionInformation(int versionBits)
        {
            int bestDifference = int.MaxValue;
            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);
        }
コード例 #2
0
        public override bool Equals(System.Object o)
        {
            if (!(o is FormatInformation))
            {
                return(false);
            }
            FormatInformation other = (FormatInformation)o;

            return(this.errorCorrectionLevel == other.errorCorrectionLevel && this.dataMask == other.dataMask);
        }
コード例 #3
0
        public bool equals(Object o)
        {
            if (!(o.GetType() == typeof(FormatInformation)))
            {
                return(false);
            }
            FormatInformation other = (FormatInformation)o;

            return(this.errorCorrectionLevel == other.errorCorrectionLevel &&
                   this.dataMask == other.dataMask);
        }
コード例 #4
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();
        }
コード例 #5
0
        /// <param name="maskedFormatInfo">format info indicator, with mask still applied
        /// </param>
        /// <returns> information about the format it specifies, or <code>null</code>
        /// if doesn't seem to match any known pattern
        /// </returns>
        internal static FormatInformation decodeFormatInformation(int maskedFormatInfo)
        {
            FormatInformation formatInfo = doDecodeFormatInformation(maskedFormatInfo);

            if (formatInfo != null)
            {
                return(formatInfo);
            }
            // Should return null, but, some QR codes apparently
            // do not mask this info. Try again by actually masking the pattern
            // first
            return(doDecodeFormatInformation(maskedFormatInfo ^ FORMAT_INFO_MASK_QR));
        }
コード例 #6
0
		/// <summary> <p>Reads format information from one of its two locations within the QR Code.</p>
		/// 
		/// </summary>
		/// <returns> {@link FormatInformation} encapsulating the QR Code's format info
		/// </returns>
		/// <throws>  ReaderException if both format information locations cannot be parsed as </throws>
		/// <summary> the valid encoding of format information
		/// </summary>
		internal FormatInformation readFormatInformation()
		{
			
			if (parsedFormatInfo != null)
			{
				return parsedFormatInfo;
			}
			
			// Read top-left format info bits
			int formatInfoBits = 0;
			for (int i = 0; i < 6; i++)
			{
				formatInfoBits = copyBit(i, 8, formatInfoBits);
			}
			// .. and skip a bit in the timing pattern ...
			formatInfoBits = copyBit(7, 8, formatInfoBits);
			formatInfoBits = copyBit(8, 8, formatInfoBits);
			formatInfoBits = copyBit(8, 7, formatInfoBits);
			// .. and skip a bit in the timing pattern ...
			for (int j = 5; j >= 0; j--)
			{
				formatInfoBits = copyBit(8, j, formatInfoBits);
			}
			
			parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits);
			if (parsedFormatInfo != null)
			{
				return parsedFormatInfo;
			}
			
			// Hmm, failed. Try the top-right/bottom-left pattern
			int dimension = bitMatrix.Dimension;
			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 ReaderException.Instance;
		}
コード例 #7
0
 /**
  * @param rawFormatInfo
  * @return
  */
 public static FormatInformation decodeFormatInformation(int rawFormatInfo)
 {
     try{
         FormatInformation formatInfo = doDecodeFormatInformation(rawFormatInfo);
         if (formatInfo != null)
         {
             return(formatInfo);
         }
         // Should return null, but, some QR codes apparently
         // do not mask this info. Try again, first masking the raw bits so
         // the function will unmask
         return(doDecodeFormatInformation(rawFormatInfo ^ FORMAT_INFO_MASK_QR));
     }catch (Exception e) {
         throw new ReaderException(e.Message);
     }
 }
コード例 #8
0
ファイル: BitMatrixParser.cs プロジェクト: smart-make/zxing
        /// <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;
        }
コード例 #9
0
        /**
         * <p>Reads the bits in the {@link BitMatrix} representing the finder pattern in the
         * correct order in order to reconstitute the codewords bytes contained within the
         * QR Code.</p>
         *
         * @return bytes encoded within the QR Code
         * @throws ReaderException if the exact number of bytes expected is not read
         */
        public sbyte[] readCodewords()
        {
            FormatInformation formatInfo = readFormatInformation();
            Version           version    = readVersion();

            // Get the data mask for the format used in this QR Code. This will exclude
            // some bits from reading as we wind through the bit matrix.
            DataMask dataMask  = DataMask.forReference((int)formatInfo.getDataMask());
            int      dimension = bitMatrix.getDimension();

            dataMask.unmaskBitMatrix(bitMatrix.getBits(), dimension);

            BitMatrix functionPattern = version.buildFunctionPattern();

            bool readingUp = true;

            sbyte[] result       = new sbyte[version.getTotalCodewords()];
            int     resultOffset = 0;
            int     currentByte  = 0;
            int     bitsRead     = 0;

            // Read columns in pairs, from right to left
            for (int j = dimension - 1; j > 0; j -= 2)
            {
                if (j == 6)
                {
                    // Skip whole column with vertical alignment pattern;
                    // saves time and makes the other code proceed more cleanly
                    j--;
                }
                // Read alternatingly from bottom to top then top to bottom
                for (int count = 0; count < dimension; count++)
                {
                    int i = readingUp ? dimension - 1 - count : count;
                    for (int col = 0; col < 2; col++)
                    {
                        // Ignore bits covered by the function pattern
                        if (!functionPattern.get(i, j - col))
                        {
                            // Read a bit
                            bitsRead++;
                            currentByte <<= 1;
                            if (bitMatrix.get(i, j - col))
                            {
                                currentByte |= 1;
                            }
                            // If we've made a whole byte, save it off
                            if (bitsRead == 8)
                            {
                                result[resultOffset++] = (sbyte)currentByte;
                                bitsRead    = 0;
                                currentByte = 0;
                            }
                        }
                    }
                }
                readingUp = !readingUp; // switch directions
            }
            if (resultOffset != version.getTotalCodewords())
            {
                throw new ReaderException();
            }
            return(result);
        }
コード例 #10
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;
        }