Example #1
0
        private void WriteChunk(string type, byte[] data, int offset, int length)
        {
            // Write out the length to the PNG.
            WriteInteger(_stream, length);

            // Write the chunck type out to the PNG.
            byte[] typeArray = new byte[4];
            typeArray[0] = (byte)type[0];
            typeArray[1] = (byte)type[1];
            typeArray[2] = (byte)type[2];
            typeArray[3] = (byte)type[3];

            _stream.Write(typeArray, 0, 4);

            // If we have some data to write out (some chunk types don't), the do so.
            if (data != null)
            {
                _stream.Write(data, offset, length);
            }

            // All chunk types need to have a CRC32 value at their end to make sure they haven't been currupted.
            CRC32 crcCode = new CRC32();

            crcCode.Add(typeArray, 4);

            if (data != null)
            {
                crcCode.Add(data, length, (uint)offset);
            }

            WriteInteger(_stream, crcCode.CurrentValue);
        }
Example #2
0
        /// <summary>
        /// Computes CRC32 for byte array
        /// </summary>
        public static uint ForBytes(byte[] buff)
        {
            var crc = new CRC32();

            crc.Add(buff);
            return(crc.m_CRC);
        }
Example #3
0
        /// <summary>
        /// Computes CRC32 for binary string representation (in-memory)
        /// </summary>
        public static uint ForString(string text)
        {
            if (text.IsNullOrWhiteSpace())
            {
                return(0);
            }

            var crc = new CRC32();

            for (var i = 0; i < text.Length; i++)
            {
                crc.Add(text[i]);
            }

            return(crc.m_CRC);
        }
 //hash the TOC
 static void AddAsBytesTo(CRC32 crc32, int i)
 => crc32.Add(BitConverter.GetBytes(i));
Example #5
0
        private void WriteChunk( string type, byte[] data, int offset, int length )
        {
            // Write out the length to the PNG.
            WriteInteger( _stream, length );

            // Write the chunck type out to the PNG.
            byte[] typeArray = new byte[4];
            typeArray[0] = (byte) type[0];
            typeArray[1] = (byte) type[1];
            typeArray[2] = (byte) type[2];
            typeArray[3] = (byte) type[3];

            _stream.Write( typeArray, 0, 4 );

            // If we have some data to write out (some chunk types don't), the do so.
            if ( data != null )
            {
                _stream.Write( data, offset, length );
            }

            // All chunk types need to have a CRC32 value at their end to make sure they haven't been currupted.
            CRC32 crcCode = new CRC32();
            crcCode.Add( typeArray, 4 );

            if ( data != null )
            {
                crcCode.Add( data, length, (uint) offset );
            }

            WriteInteger( _stream, crcCode.CurrentValue );
        }