Exemplo n.º 1
0
 /// <summary>
 ///     The make image end chunk.
 /// </summary>
 private void MakeImageEndChunk()
 {
     this.m_iendChunk = new PngChunk(PngChunkIend);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PngStream"/> class.
 ///     Builds a PNG stream around a set of chunks.
 /// </summary>
 /// <param name="chunks">
 /// The chunks that make up this PNG image.
 /// </param>
 /// <remarks>
 /// See http://www.w3.org/TR/PNG/ for more detail on all
 ///     this stuff.
 /// </remarks>
 public PngStream(PngChunk[] chunks)
 {
     this.m_chunks = chunks;
 }
Exemplo n.º 3
0
 /// <summary>
 ///     The make image end chunk.
 /// </summary>
 private void MakeImageEndChunk()
 {
     this.m_iendChunk = new PngChunk(PngChunkIend);
 }
Exemplo n.º 4
0
 /// <summary>
 ///     The make image header chunk.
 /// </summary>
 private void MakeImageHeaderChunk()
 {
     this.m_ihdrChunk = new PngChunk(PngChunkIhdr);
     var ihdrData = new byte[13];
     NetworkOrderBitConverter.GetBytes((uint)this.m_imageWidth, ihdrData, 0);
     NetworkOrderBitConverter.GetBytes((uint)this.m_imageHeight, ihdrData, 4);
     ihdrData[8] = 8; // Bits per channel
     ihdrData[9] = 2; // Colour model - RGB
     this.m_ihdrChunk.SetData(ihdrData);
 }
Exemplo n.º 5
0
        /// <summary>
        ///     The make image data chunk.
        /// </summary>
        private void MakeImageDataChunk()
        {
            this.m_idatChunk = new PngChunk(PngChunkIdat);

            int preDeflateImageDataSize = (this.m_imageWidth * 3 + 1) * this.m_imageHeight;
            int pngDataSize = MapPixelDataOffset(preDeflateImageDataSize);
            this.pngPixelData = new byte[pngDataSize + 4]; // Extra 4 bytes for ADLER-32
            this.pngPixelData[0] = 0x78;
            this.pngPixelData[1] = 1;

            // Block headers are all 0 except for last one, which is 1.
            for (int blockStart = 0; blockStart < preDeflateImageDataSize - 0xffff; blockStart += 0xffff)
            {
                int blockOffset = MapPixelDataOffset(blockStart);
                this.pngPixelData[blockOffset - 4] = 0xff;
                this.pngPixelData[blockOffset - 3] = 0xff;

                // Next two bytes two's complement - already initialized to 0
            }

            int lastBlock = MapPixelDataOffset((preDeflateImageDataSize / 0xffff) * 0xffff);
            int lastBlockSize = preDeflateImageDataSize % 0xffff;
            this.pngPixelData[lastBlock - 5] = 1;
            this.pngPixelData[lastBlock - 4] = (byte)(lastBlockSize & 0xff);
            this.pngPixelData[lastBlock - 3] = (byte)((lastBlockSize >> 8) & 0xff);
            lastBlockSize = ~lastBlockSize;
            this.pngPixelData[lastBlock - 2] = (byte)(lastBlockSize & 0xff);
            this.pngPixelData[lastBlock - 1] = (byte)((lastBlockSize >> 8) & 0xff);
        }