コード例 #1
0
ファイル: PngEncoder.cs プロジェクト: brezza92/PixelFarm
        private void WriteChunk(string type, byte[] data, int offset, int length)
        {
            WriteInteger(_stream, length);

            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 (data != null)
            {
                _stream.Write(data, offset, length);
            }



            //Crc32 crc32 = new Crc32();
            //crc32.Update(typeArray);
            CRC32Calculator crc32Cal = new CRC32Calculator();

            crc32Cal.Reset();
            crc32Cal.SlurpBlock(typeArray, 0, typeArray.Length);

            if (data != null)
            {
                // crc32.Update(data, offset, length);
                crc32Cal.SlurpBlock(data, offset, length);
            }

            //WriteInteger(_stream, (uint)crc32.Value);
            WriteInteger(_stream, (uint)crc32Cal.Crc32Result);
        }
コード例 #2
0
ファイル: PngDecoder.cs プロジェクト: brezza92/PixelFarm
        private void ReadChunkCrc(PngChunk chunk, byte[] typeBuffer)
        {
            byte[] crcBuffer = new byte[4];

            int numBytes = _stream.Read(crcBuffer, 0, 4);

            //if (numBytes.IsBetween(1, 3))
            if (numBytes >= 1 && numBytes <= 3)
            {
                throw new ImageFormatException("Image stream is not valid!");
            }

            Array.Reverse(crcBuffer);

            chunk.Crc = BitConverter.ToUInt32(crcBuffer, 0);

            //Crc32 crc = new Crc32();
            //crc.Update(typeBuffer);
            //crc.Update(chunk.Data);
            CRC32Calculator crc32Cal = new CRC32Calculator();

            crc32Cal.Reset();
            crc32Cal.SlurpBlock(typeBuffer);
            crc32Cal.SlurpBlock(chunk.Data);
            //if (crc.Value != chunk.Crc)
            if ((uint)crc32Cal.Crc32Result != chunk.Crc)
            {
                throw new ImageFormatException("CRC Error. PNG Image chunk is corrupt!");
            }
        }
コード例 #3
0
ファイル: PngEncoder.cs プロジェクト: prepare/HTML-Renderer
        private void WriteChunk(string type, byte[] data, int offset, int length)
        {
            WriteInteger(_stream, length);

            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 (data != null)
            {
                _stream.Write(data, offset, length);
            }



            //Crc32 crc32 = new Crc32();
            //crc32.Update(typeArray);
            CRC32Calculator crc32Cal = new CRC32Calculator();
            crc32Cal.SlurpBlock(typeArray, 0, typeArray.Length);

            if (data != null)
            {
                // crc32.Update(data, offset, length);
                crc32Cal.SlurpBlock(data, offset, length);
            }

            //WriteInteger(_stream, (uint)crc32.Value);
            WriteInteger(_stream, (uint)crc32Cal.Crc32Result);
        }
コード例 #4
0
ファイル: PngDecoder.cs プロジェクト: prepare/HTML-Renderer
        private void ReadChunkCrc(PngChunk chunk, byte[] typeBuffer)
        {
            byte[] crcBuffer = new byte[4];

            int numBytes = _stream.Read(crcBuffer, 0, 4);
            //if (numBytes.IsBetween(1, 3))
            if (numBytes >= 1 && numBytes <= 3)
            {
                throw new ImageFormatException("Image stream is not valid!");
            }

            Array.Reverse(crcBuffer);

            chunk.Crc = BitConverter.ToUInt32(crcBuffer, 0);

            //Crc32 crc = new Crc32();
            //crc.Update(typeBuffer);
            //crc.Update(chunk.Data);
            CRC32Calculator crc32Cal = new CRC32Calculator();
            crc32Cal.SlurpBlock(typeBuffer);
            crc32Cal.SlurpBlock(chunk.Data);
            //if (crc.Value != chunk.Crc)
            if ((uint)crc32Cal.Crc32Result != chunk.Crc)
            {
                throw new ImageFormatException("CRC Error. PNG Image chunk is corrupt!");
            }
        }