Пример #1
0
        private void ParseEncodingMessage(IBitIterator it, MessageMode mode)
        {
            if (!it.EndReached)
            {
                this.charCountIndicatorSymbolCode = CodeSymbolCode <CharCountIndicatorSymbol> .BuildInstance(it, new CharCountIndicatorSymbolFactory(mode));

                this.characterCount = charCountIndicatorSymbolCode.GetSymbolAt(0).GetCharacterCount();

                if (!it.EndReached)
                {
                    switch (mode.Mode)
                    {
                    case MessageMode.EncodingMode.Byte:
                        this.Message = CodeSymbolCode <ByteEncodingSymbol> .BuildInstance(it, new ByteEncodingSymbolFactory(characterCount));

                        break;

                    case MessageMode.EncodingMode.Alphanumeric:
                        this.Message = CodeSymbolCode <AlphaNumericEncodingSymbol> .BuildInstance(it, new AlphaNumericEncodingSymbolFactory(characterCount));

                        break;

                    case MessageMode.EncodingMode.Numeric:
                        this.Message = CodeSymbolCode <NumericEncodingSymbol> .BuildInstance(it, new NumericEncodingSymbolFactory(characterCount));

                        break;

                    default:
                        throw new NotImplementedException($"{mode.Mode} decoding not implemented");
                    }
                }
            }
        }
Пример #2
0
        private void RepairBlock()
        {
            int[] dataWithECC = new int[this.preRepairData.SymbolCount + this.preRepairECC.SymbolCount];
            ECCBlock.ConvertToIntArray(preRepairData).CopyTo(dataWithECC, 0);
            ECCBlock.ConvertToIntArray(preRepairECC).CopyTo(dataWithECC, this.preRepairData.SymbolCount);

            var rsDecoder = new ReedSolomonDecoder(GenericGF.QR_CODE_FIELD_256);

            this.RepairSuccess = rsDecoder.decode(dataWithECC, this.preRepairECC.SymbolCount);


            if (dataWithECC.All(x => x == 0))   // TODO determine better way to detect zeroing out of block
            {
                this.RepairSuccess = false;
            }


            if (this.RepairSuccess)
            {
                var dataArr = new int[this.preRepairData.SymbolCount];
                var eccArr  = new int[this.preRepairECC.SymbolCount];
                Array.Copy(dataWithECC, 0, dataArr, 0, dataArr.Length);
                Array.Copy(dataWithECC, dataArr.Length, eccArr, 0, eccArr.Length);
                var dataIt  = new OverrideByteSymbolCodeValuesBitIterator <RawCodeByte>(this.preRepairData, dataArr);
                var eccIt   = new OverrideByteSymbolCodeValuesBitIterator <RawCodeByte>(this.preRepairECC, eccArr);
                var factory = new RawCodeByteFactory();
                this.postRepairData = CodeSymbolCode <RawCodeByte> .BuildInstance(dataIt, factory);

                this.postRepairECC = CodeSymbolCode <RawCodeByte> .BuildInstance(eccIt, factory);
            }
            else
            {
                this.postRepairData = this.preRepairData;
                this.postRepairECC  = this.preRepairECC;
            }
        }