Exemplo n.º 1
0
        /// <summary>
        /// Creates an FDAT Chunk from an IDAT Chunk.
        /// </summary>
        /// <returns>The FDAT chunk.</returns>
        /// <param name="idatChunk">IDAT chunk.</param>
        /// <param name="sequenceNumber">Sequence number.</param>
        public static fdATChunk FromIDATChunk(IDATChunk idatChunk, uint sequenceNumber)
        {
            uint newCrc;

            byte[]    frameData;
            fdATChunk fdat = null;

            using (var msCrc = new MemoryStream())
            {
                msCrc.WriteBytes(new[] { (byte)'f', (byte)'d', (byte)'A', (byte)'T' });
                byte[] seqNum = BitConverter.GetBytes(Helper.ConvertEndian(sequenceNumber));
                frameData = new byte[seqNum.Length + idatChunk.ChunkData.Length];
                Buffer.BlockCopy(seqNum, 0, frameData, 0, seqNum.Length);
                Buffer.BlockCopy(idatChunk.ChunkData, 0, frameData, seqNum.Length, idatChunk.ChunkData.Length);
                msCrc.WriteBytes(frameData);

                newCrc = CrcHelper.Calculate(msCrc.ToArray());
            }

            using (var ms = new MemoryStream())
            {
                ms.WriteUInt32((uint)Helper.ConvertEndian(idatChunk.ChunkData.Length + 4));
                ms.WriteBytes(new[] { (byte)'f', (byte)'d', (byte)'A', (byte)'T' });
                ms.WriteBytes(frameData);
                ms.WriteUInt32(Helper.ConvertEndian(newCrc));
                ms.Position = 0;

                fdat = new fdATChunk(ms);
            }

            return(fdat);
        }
Exemplo n.º 2
0
 /// <summary>
 ///     Add an IDAT Chunk to end end of existing list.
 /// </summary>
 internal void AddIDATChunk(IDATChunk chunk)
 {
     idatChunks.Add(chunk);
 }