Beispiel #1
0
		/// <summary> <p>Decodes a Data Matrix Code represented as a {@link BitMatrix}. A 1 or "true" is taken
		/// to mean a black module.</p>
		/// 
		/// </summary>
		/// <param name="bits">booleans representing white/black Data Matrix Code modules
		/// </param>
		/// <returns> text and bytes encoded within the Data Matrix Code
		/// </returns>
		/// <throws>  ReaderException if the Data Matrix Code cannot be decoded </throws>
		public DecoderResult decode(BitMatrix bits)
		{
			
			// Construct a parser and read version, error-correction level
			BitMatrixParser parser = new BitMatrixParser(bits);
			Version version = parser.readVersion(bits);
			
			// Read codewords
			sbyte[] codewords = parser.readCodewords();
			// Separate into data blocks
			DataBlock[] dataBlocks = DataBlock.getDataBlocks(codewords, version);
			
			// Count total number of data bytes
			int totalBytes = 0;
			for (int i = 0; i < dataBlocks.Length; i++)
			{
				totalBytes += dataBlocks[i].NumDataCodewords;
			}
			sbyte[] resultBytes = new sbyte[totalBytes];
			int resultOffset = 0;
			
			// Error-correct and copy data blocks together into a stream of bytes
			for (int j = 0; j < dataBlocks.Length; j++)
			{
				DataBlock dataBlock = dataBlocks[j];
				sbyte[] codewordBytes = dataBlock.Codewords;
				int numDataCodewords = dataBlock.NumDataCodewords;
				correctErrors(codewordBytes, numDataCodewords);
				for (int i = 0; i < numDataCodewords; i++)
				{
					resultBytes[resultOffset++] = codewordBytes[i];
				}
			}
			
			// Decode the contents of that stream of bytes
			return DecodedBitStreamParser.decode(resultBytes);
		}
Beispiel #2
0
        /// <summary> <p>Decodes a Data Matrix Code represented as a {@link BitMatrix}. A 1 or "true" is taken
        /// to mean a black module.</p>
        ///
        /// </summary>
        /// <param name="bits">booleans representing white/black Data Matrix Code modules
        /// </param>
        /// <returns> text and bytes encoded within the Data Matrix Code
        /// </returns>
        /// <throws>  ReaderException if the Data Matrix Code cannot be decoded </throws>
        public DecoderResult decode(BitMatrix bits)
        {
            // Construct a parser and read version, error-correction level
            BitMatrixParser parser  = new BitMatrixParser(bits);
            Version         version = parser.readVersion(bits);

            // Read codewords
            sbyte[] codewords = parser.readCodewords();
            // Separate into data blocks
            DataBlock[] dataBlocks = DataBlock.getDataBlocks(codewords, version);

            // Count total number of data bytes
            int totalBytes = 0;

            for (int i = 0; i < dataBlocks.Length; i++)
            {
                totalBytes += dataBlocks[i].NumDataCodewords;
            }
            sbyte[] resultBytes  = new sbyte[totalBytes];
            int     resultOffset = 0;

            // Error-correct and copy data blocks together into a stream of bytes
            for (int j = 0; j < dataBlocks.Length; j++)
            {
                DataBlock dataBlock        = dataBlocks[j];
                sbyte[]   codewordBytes    = dataBlock.Codewords;
                int       numDataCodewords = dataBlock.NumDataCodewords;
                correctErrors(codewordBytes, numDataCodewords);
                for (int i = 0; i < numDataCodewords; i++)
                {
                    resultBytes[resultOffset++] = codewordBytes[i];
                }
            }

            // Decode the contents of that stream of bytes
            return(DecodedBitStreamParser.decode(resultBytes));
        }