/// <summary> /// Creates a new chunk with the specified type. /// </summary> /// <param name="type">The type of chunk.</param> /// <param name="image">The parent image.</param> public Chunk(string type, PNGImage image) { if (image == null) { throw new ArgumentNullException("The image must not be null."); } _image = image; this.AssertChunkType(type); _type = type; }
public IHDRChunk(byte[] data, PNGImage image) : base(data, image) { this.AssertDataLength(data, 13); this.Width = Utils.BytesToUInt(data, 4, Utils.Endianness.Big); this.Height = Utils.BytesToUInt(data, 8, Utils.Endianness.Big); this.ColorType = (ColorType)data[13]; this.BitDepth = data[12]; this.CompressionMethod = (CompressionMethod)data[14]; this.FilterMethod = (FilterMethod)data[15]; this.InterlaceMethod = (InterlaceMethod)data[16]; }
public tIMEChunk(byte[] data, PNGImage image) : base(data, image) { this.AssertDataLength(data, 7); _time = new DateTime( Utils.BytesToUShort(data, 4, Utils.Endianness.Big), data[6], data[7], data[8], data[9], data[10]); }
public tEXtChunk(byte[] data, PNGImage image) : base(data, image) { int i = 0; while (data[i + 4] != 0) { i++; } this.Keyword = ASCIIEncoding.ASCII.GetString(data, 4, i); this.Text = ASCIIEncoding.ASCII.GetString(data, i + 5, data.Length - 4 - i - 1); }
public cHRMChunk(byte[] data, PNGImage image) : base(data, image) { this.AssertDataLength(data, 32); _whiteX = ((float)Utils.BytesToUInt(data, 4, Utils.Endianness.Big)) / 100000; _whiteY = ((float)Utils.BytesToUInt(data, 8, Utils.Endianness.Big)) / 100000; _redX = ((float)Utils.BytesToUInt(data, 12, Utils.Endianness.Big)) / 100000; _redY = ((float)Utils.BytesToUInt(data, 16, Utils.Endianness.Big)) / 100000; _greenX = ((float)Utils.BytesToUInt(data, 20, Utils.Endianness.Big)) / 100000; _greenY = ((float)Utils.BytesToUInt(data, 24, Utils.Endianness.Big)) / 100000; _blueX = ((float)Utils.BytesToUInt(data, 28, Utils.Endianness.Big)) / 100000; _blueY = ((float)Utils.BytesToUInt(data, 32, Utils.Endianness.Big)) / 100000; }
public hISTChunk(byte[] data, PNGImage image) : base(data, image) { if (data.Length - 4 != this.GetAssertPLTEChunk().Entries.Length * 2) { throw new InvalidChunkLengthException("Chunk length must equal to the number of palette entries times 2."); } _histogram = new ushort[(data.Length - 4) / 2]; for (int i = 0; i < (data.Length - 4) / 2; i++) { _histogram[i] = Utils.BytesToUShort(data, i * 2 + 4, Utils.Endianness.Big); } }
public tRNSChunk(byte[] data, PNGImage image) : base(data, image) { IHDRChunk hdr = this.GetAssertIHDRChunk(); switch (hdr.ColorType) { case ColorType.Grayscale: this.AssertDataLength(data, 2); _grayValue = Utils.BytesToUShort(data, 4, Utils.Endianness.Big); break; case ColorType.GrayscaleWithAlpha: throw new InvalidChunkDataException("The tRNS chunk cannot appear for the grayscale with alpha color type."); case ColorType.Truecolor: this.AssertDataLength(data, 6); _redValue = Utils.BytesToUShort(data, 4, Utils.Endianness.Big); _greenValue = Utils.BytesToUShort(data, 6, Utils.Endianness.Big); _blueValue = Utils.BytesToUShort(data, 8, Utils.Endianness.Big); break; case ColorType.TruecolorWithAlpha: throw new InvalidChunkDataException("The tRNS chunk cannot appear for the truecolor with alpha color type."); case ColorType.IndexedColor: if (data.Length - 4 > this.GetAssertPLTEChunk().Entries.Length) { throw new InvalidChunkLengthException("tRNS chunk must contain the same amount of entries as the palette chunk or less."); } _paletteAlpha = new byte[data.Length - 4]; for (int i = 0; i < data.Length - 4; i++) { _paletteAlpha[i] = data[i + 4]; } break; default: throw new InvalidChunkDataException("Invalid color type."); } }
/// <summary> /// Creates a new chunk with the specified data (which must include the chunk type in /// the first four bytes). /// </summary> /// <param name="data">The chunk data.</param> /// <param name="image">The parent image.</param> public Chunk(byte[] data, PNGImage image) { if (image == null) { throw new ArgumentNullException("The image must not be null."); } _image = image; ByteStreamReader bs = new ByteStreamReader(data); _type = Utils.ReadString(bs, 4); this.AssertChunkType(_type); if (!image.Classes.ContainsKey(_type)) { _data = data; } }
public zTXtChunk(byte[] data, PNGImage image) : base(data, image) { int i = 0; while (data[i + 4] != 0) { i++; } this.Keyword = ASCIIEncoding.ASCII.GetString(data, 4, i); this.CompressionMethod = (CompressionMethod)data[i + 5]; ByteStreamReader bs = new ByteStreamReader(data); bs.Seek(i + 6, SeekOrigin.Begin); InflaterInputStream iis = new InflaterInputStream(bs, new Inflater(), data.Length - 4 - i - 2); StringBuilder sb = new StringBuilder(); while (iis.Available == 1) { int b = iis.ReadByte(); if (b == -1) { break; } sb.Append(System.Text.ASCIIEncoding.ASCII.GetChars(new byte[] { (byte)b })[0]); } this.Text = sb.ToString(); iis.Close(); bs.Close(); }
public PLTEChunk(byte[] data, PNGImage image) : base(data, image) { if (data.Length - 4 < 3) { throw new InvalidChunkLengthException("There must be at least one palette entry."); } if ((data.Length - 4) % 3 != 0) { throw new InvalidChunkLengthException("Chunk length must be divisible by 3."); } if ((data.Length - 4) > 3 * 256) { throw new InvalidChunkLengthException("There must be 256 or less palette entries."); } _entries = new Color[(data.Length - 4) / 3]; for (int i = 0; i < (data.Length - 4) / 3; i++) { _entries[i] = Color.FromArgb( data[i * 3 + 4], data[i * 3 + 5], data[i * 3 + 6]); } }
public bKGDChunk(PNGImage image) : base("bKGD", image) { _backgroundColor = new BackgroundColor(); }
public hISTChunk(PNGImage image) : base("hIST", image) { _histogram = new ushort[this.GetAssertPLTEChunk().Entries.Length]; }
public zTXtChunk(PNGImage image) : base("zTXt", image) { }
public cHRMChunk(PNGImage image) : base("cHRM", image) { }
public sRGBChunk(PNGImage image) : base("sRGB", image) { _ri = RenderingIntent.Perceptual; }
public gAMAChunk(PNGImage image) : base("gAMA", image) { _gamma = 1; }
/// <summary> /// Reads a PNG file from the specified stream. /// </summary> /// <param name="s">The stream to read from.</param> public PNGBitmap(Stream s) { _image = new PNGImage(s); this.Read(this.Decompress()); }
public pHYsChunk(PNGImage image) : base("pHYs", image) { }
public IENDChunk(PNGImage image) : base("IEND", image) { }
public tRNSChunk(PNGImage image) : base("tRNS", image) { _paletteAlpha = new byte[0]; }
public IDATChunk(byte[] data, PNGImage image) : base(data, image) { _data = new byte[data.Length - 4]; Array.Copy(data, 4, _data, 0, data.Length - 4); }
public IDATChunk(PNGImage image) : base("IDAT", image) { }
public tEXtChunk(PNGImage image) : base("tEXt", image) { }
public sBITChunk(PNGImage image) : base("sBIT", image) { _sb = new SignificantBits(); }
public tIMEChunk(PNGImage image) : base("tIME", image) { }
public IENDChunk(byte[] data, PNGImage image) : base(data, image) { this.AssertDataLength(data, 0); }
public PLTEChunk(PNGImage image) : base("PLTE", image) { _entries = new Color[0]; }