Example #1
0
        private void readChunk()
        {
            ulong len = readInt();
            String type = readType();
            byte[] buffer = new byte[len];
            _stream.Read(buffer, 0, (int)len);
            ulong crc = readInt();

            if (crc != CalcCRC(type, buffer))
            {
                Console.WriteLine("CRC Don't match! {0} {1:X}:{2:X}", type, crc, CalcCRC(type, buffer));
            }

            PNGChunk pc = new PNGChunk() { Type = type, Data = buffer, CRC = crc };
            _chunks.Add(pc.Type, pc);

            _chunkOrder.Add(pc.Type);
        }
Example #2
0
        public void Save(Stream Stream)
        {
            Stream.Write(_header, 0, 8);

            foreach (String type in _chunkOrder)
            {
                PNGChunk chunk = _chunks[type];

                WriteLong(Stream, (ulong)chunk.Data.Length);
                Stream.WriteByte((byte)type[0]);
                Stream.WriteByte((byte)type[1]);
                Stream.WriteByte((byte)type[2]);
                Stream.WriteByte((byte)type[3]);

                Stream.Write(chunk.Data, 0, chunk.Data.Length);

                WriteLong(Stream, chunk.CRC);
            }

            Stream.Close();
        }
Example #3
0
        private void readChunk()
        {
            ulong  len  = readInt();
            String type = readType();

            byte[] buffer = new byte[len];
            _stream.Read(buffer, 0, (int)len);
            ulong crc = readInt();

            if (crc != CalcCRC(type, buffer))
            {
                Console.WriteLine("CRC Don't match! {0} {1:X}:{2:X}", type, crc, CalcCRC(type, buffer));
            }

            PNGChunk pc = new PNGChunk()
            {
                Type = type, Data = buffer, CRC = crc
            };

            _chunks.Add(pc.Type, pc);

            _chunkOrder.Add(pc.Type);
        }