コード例 #1
0
ファイル: PngDecoderCore.cs プロジェクト: ITTalk/2016_Krakow
        /// <summary>
        /// Identifies the chunk type from the chunk.
        /// </summary>
        /// <param name="chunk">The chunk.</param>
        /// <returns>
        /// The <see cref="T:byte[]"/> containing identifying information.
        /// </returns>
        /// <exception cref="ImageFormatException">
        /// Thrown if the input stream is not valid.
        /// </exception>
        private byte[] ReadChunkType(PngChunk chunk)
        {
            byte[] typeBuffer = new byte[4];

            int numBytes = this.currentStream.Read(typeBuffer, 0, 4);

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

            char[] chars = new char[4];
            chars[0] = (char)typeBuffer[0];
            chars[1] = (char)typeBuffer[1];
            chars[2] = (char)typeBuffer[2];
            chars[3] = (char)typeBuffer[3];

            chunk.Type = new string(chars);

            return(typeBuffer);
        }
コード例 #2
0
ファイル: PngDecoderCore.cs プロジェクト: ITTalk/2016_Krakow
        /// <summary>
        /// Reads a chunk from the stream.
        /// </summary>
        /// <returns>
        /// The <see cref="PngChunk"/>.
        /// </returns>
        private PngChunk ReadChunk()
        {
            PngChunk chunk = new PngChunk();

            if (this.ReadChunkLength(chunk) == 0)
            {
                return(null);
            }

            if (chunk.Length <= 0)
            {
                return(null);
            }

            byte[] typeBuffer = this.ReadChunkType(chunk);

            this.ReadChunkData(chunk);
            this.ReadChunkCrc(chunk, typeBuffer);

            return(chunk);
        }
コード例 #3
0
ファイル: PngDecoderCore.cs プロジェクト: ITTalk/2016_Krakow
 /// <summary>
 /// Reads the chunk data from the stream.
 /// </summary>
 /// <param name="chunk">The chunk.</param>
 private void ReadChunkData(PngChunk chunk)
 {
     chunk.Data = new byte[chunk.Length];
     this.currentStream.Read(chunk.Data, 0, chunk.Length);
 }