Set() public method

public Set ( byte source, int offset, int count ) : void
source byte
offset int
count int
return void
Ejemplo n.º 1
0
        private static ByteArray GenerateECBytes(ByteArray dataBytes, int numEcBytesInBlock)
        {
            var numDataBytes = dataBytes.Size();
            var toEncode     = new int[numDataBytes + numEcBytesInBlock];

            for (var i = 0; i < numDataBytes; i++)
            {
                toEncode[i] = dataBytes.At(i);
            }
            new ReedSolomonEncoder(GF256.QR_CODE_FIELD).Encode(toEncode, numEcBytesInBlock);

            var ecBytes = new ByteArray(numEcBytesInBlock);

            for (var i = 0; i < numEcBytesInBlock; i++)
            {
                ecBytes.Set(i, toEncode[numDataBytes + i]);
            }
            return(ecBytes);
        }
Ejemplo n.º 2
0
        static ByteArray GenerateECBytes(ByteArray dataBytes, int numEcBytesInBlock) {
            int numDataBytes = dataBytes.Size();
            int[] toEncode = new int[numDataBytes + numEcBytesInBlock];
            for (int i = 0; i < numDataBytes; i++) {
                toEncode[i] = dataBytes.At(i);
            }
            new ReedSolomonEncoder(GF256.QR_CODE_FIELD).Encode(toEncode, numEcBytesInBlock);

            ByteArray ecBytes = new ByteArray(numEcBytesInBlock);
            for (int i = 0; i < numEcBytesInBlock; i++) {
                ecBytes.Set(i, toEncode[numDataBytes + i]);
            }
            return ecBytes;
        }
Ejemplo n.º 3
0
        /**
         * Interleave "bits" with corresponding error correction bytes. On success, store the result in
         * "result". The interleave rule is complicated. See 8.6 of JISX0510:2004 (p.37) for details.
         */
        private static void InterleaveWithECBytes(BitVector bits, int numTotalBytes,
                                                  int numDataBytes, int numRSBlocks, BitVector result)
        {
            // "bits" must have "getNumDataBytes" bytes of data.
            if (bits.SizeInBytes() != numDataBytes)
            {
                throw new WriterException("Number of bits and data bytes does not match");
            }

            // Step 1.  Divide data bytes into blocks and generate error correction bytes for them. We'll
            // store the divided data bytes blocks and error correction bytes blocks into "blocks".
            var dataBytesOffset = 0;
            var maxNumDataBytes = 0;
            var maxNumEcBytes   = 0;

            // Since, we know the number of reedsolmon blocks, we can initialize the vector with the number.
            var blocks = new List <BlockPair>(numRSBlocks);

            for (var i = 0; i < numRSBlocks; ++i)
            {
                var numDataBytesInBlock = new int[1];
                var numEcBytesInBlock   = new int[1];
                GetNumDataBytesAndNumECBytesForBlockID(
                    numTotalBytes, numDataBytes, numRSBlocks, i,
                    numDataBytesInBlock, numEcBytesInBlock);

                var dataBytes = new ByteArray();
                dataBytes.Set(bits.GetArray(), dataBytesOffset, numDataBytesInBlock[0]);
                var ecBytes = GenerateECBytes(dataBytes, numEcBytesInBlock[0]);
                blocks.Add(new BlockPair(dataBytes, ecBytes));

                maxNumDataBytes  = Math.Max(maxNumDataBytes, dataBytes.Size());
                maxNumEcBytes    = Math.Max(maxNumEcBytes, ecBytes.Size());
                dataBytesOffset += numDataBytesInBlock[0];
            }
            if (numDataBytes != dataBytesOffset)
            {
                throw new WriterException("Data bytes does not match offset");
            }

            // First, place data blocks.
            for (var i = 0; i < maxNumDataBytes; ++i)
            {
                for (var j = 0; j < blocks.Count; ++j)
                {
                    var dataBytes = blocks[j].GetDataBytes();
                    if (i < dataBytes.Size())
                    {
                        result.AppendBits(dataBytes.At(i), 8);
                    }
                }
            }
            // Then, place error correction blocks.
            for (var i = 0; i < maxNumEcBytes; ++i)
            {
                for (var j = 0; j < blocks.Count; ++j)
                {
                    var ecBytes = blocks[j].GetErrorCorrectionBytes();
                    if (i < ecBytes.Size())
                    {
                        result.AppendBits(ecBytes.At(i), 8);
                    }
                }
            }
            if (numTotalBytes != result.SizeInBytes())
            {  // Should be same.
                throw new WriterException("Interleaving error: " + numTotalBytes + " and " +
                                          result.SizeInBytes() + " differ.");
            }
        }
Ejemplo n.º 4
0
        /**
         * Interleave "bits" with corresponding error correction bytes. On success, store the result in
         * "result". The interleave rule is complicated. See 8.6 of JISX0510:2004 (p.37) for details.
         */
        static void InterleaveWithECBytes(BitVector bits, int numTotalBytes,
            int numDataBytes, int numRSBlocks, BitVector result) {

            // "bits" must have "getNumDataBytes" bytes of data.
            if (bits.SizeInBytes() != numDataBytes) {
                throw new WriterException("Number of bits and data bytes does not match");
            }

            // Step 1.  Divide data bytes into blocks and generate error correction bytes for them. We'll
            // store the divided data bytes blocks and error correction bytes blocks into "blocks".
            int dataBytesOffset = 0;
            int maxNumDataBytes = 0;
            int maxNumEcBytes = 0;

            // Since, we know the number of reedsolmon blocks, we can initialize the vector with the number.
            List<BlockPair> blocks = new List<BlockPair>(numRSBlocks);

            for (int i = 0; i < numRSBlocks; ++i) {
                int[] numDataBytesInBlock = new int[1];
                int[] numEcBytesInBlock = new int[1];
                GetNumDataBytesAndNumECBytesForBlockID(
                    numTotalBytes, numDataBytes, numRSBlocks, i,
                    numDataBytesInBlock, numEcBytesInBlock);

                ByteArray dataBytes = new ByteArray();
                dataBytes.Set(bits.GetArray(), dataBytesOffset, numDataBytesInBlock[0]);
                ByteArray ecBytes = GenerateECBytes(dataBytes, numEcBytesInBlock[0]);
                blocks.Add(new BlockPair(dataBytes, ecBytes));

                maxNumDataBytes = Math.Max(maxNumDataBytes, dataBytes.Size());
                maxNumEcBytes = Math.Max(maxNumEcBytes, ecBytes.Size());
                dataBytesOffset += numDataBytesInBlock[0];
            }
            if (numDataBytes != dataBytesOffset) {
                throw new WriterException("Data bytes does not match offset");
            }

            // First, place data blocks.
            for (int i = 0; i < maxNumDataBytes; ++i) {
                for (int j = 0; j < blocks.Count; ++j) {
                    ByteArray dataBytes = blocks[j].GetDataBytes();
                    if (i < dataBytes.Size()) {
                        result.AppendBits(dataBytes.At(i), 8);
                    }
                }
            }
            // Then, place error correction blocks.
            for (int i = 0; i < maxNumEcBytes; ++i) {
                for (int j = 0; j < blocks.Count; ++j) {
                    ByteArray ecBytes = blocks[j].GetErrorCorrectionBytes();
                    if (i < ecBytes.Size()) {
                        result.AppendBits(ecBytes.At(i), 8);
                    }
                }
            }
            if (numTotalBytes != result.SizeInBytes()) {  // Should be same.
                throw new WriterException("Interleaving error: " + numTotalBytes + " and " +
                    result.SizeInBytes() + " differ.");
            }
        }