コード例 #1
0
        /// <summary>
        /// decode the bits
        /// </summary>
        /// <param name="bits"></param>
        /// <param name="hints"></param>
        /// <returns></returns>
        public DecoderResult decode(BitMatrix bits,
                                    IDictionary <DecodeHintType, object> hints)
        {
            BitMatrixParser parser = new BitMatrixParser(bits);

            byte[] codewords = parser.readCodewords();

            if (!correctErrors(codewords, 0, 10, 10, ALL))
            {
                return(null);
            }

            int mode = codewords[0] & 0x0F;

            byte[] datawords;
            switch (mode)
            {
            case 2:
            case 3:
            case 4:
                if (!correctErrors(codewords, 20, 84, 40, EVEN))
                {
                    return(null);
                }
                if (!correctErrors(codewords, 20, 84, 40, ODD))
                {
                    return(null);
                }
                datawords = new byte[94];
                break;

            case 5:
                if (!correctErrors(codewords, 20, 68, 56, EVEN))
                {
                    return(null);
                }
                if (!correctErrors(codewords, 20, 68, 56, ODD))
                {
                    return(null);
                }
                datawords = new byte[78];
                break;

            default:
                return(null);
            }

            Array.Copy(codewords, 0, datawords, 0, 10);
            Array.Copy(codewords, 20, datawords, 10, datawords.Length - 10);

            return(DecodedBitStreamParser.decode(datawords, mode));
        }
コード例 #2
0
ファイル: Decoder.cs プロジェクト: hydrayu/imobile-src
        /// <summary>
        /// decode()
        /// </summary>
        /// <param name="bits"></param>
        /// <param name="hints"></param>
        /// <returns>DecoderResult</returns>
        public DecoderResult decode(BitMatrix bits,
                                    IDictionary<DecodeHintType, object> hints)
        {
            BitMatrixParser parser = new BitMatrixParser(bits);
            byte[] codewords = parser.readCodewords();

            if (!correctErrors(codewords, 0, 10, 10, ALL))
                return null;

            int mode = codewords[0] & 0x0F;
            byte[] datawords;
            switch (mode)
            {
                case 2:
                case 3:
                case 4:
                    if (!correctErrors(codewords, 20, 84, 40, EVEN))
                        return null;
                    if (!correctErrors(codewords, 20, 84, 40, ODD))
                        return null;
                    datawords = new byte[94];
                    break;
                case 5:
                    if (!correctErrors(codewords, 20, 68, 56, EVEN))
                        return null;
                    if (!correctErrors(codewords, 20, 68, 56, ODD))
                        return null;
                    datawords = new byte[78];
                    break;
                default:
                    return null;
            }

            Array.Copy(codewords, 0, datawords, 0, 10);
            Array.Copy(codewords, 20, datawords, 10, datawords.Length - 10);

            return DecodedBitStreamParser.decode(datawords, mode);
        }