private void Read(Stream stream, IEnumerable <GifExtension> controlExtensions, bool metadataOnly) { // Note: at this point, the label (0x01) has already been read byte[] bytes = new byte[13]; stream.ReadAll(bytes, 0, bytes.Length); BlockSize = bytes[0]; if (BlockSize != 12) { throw GifHelpers.InvalidBlockSizeException("Plain Text Extension", 12, BlockSize); } Left = BitConverter.ToUInt16(bytes, 1); Top = BitConverter.ToUInt16(bytes, 3); Width = BitConverter.ToUInt16(bytes, 5); Height = BitConverter.ToUInt16(bytes, 7); CellWidth = bytes[9]; CellHeight = bytes[10]; ForegroundColorIndex = bytes[11]; BackgroundColorIndex = bytes[12]; var dataBytes = GifHelpers.ReadDataBlocks(stream, metadataOnly); Text = Encoding.ASCII.GetString(dataBytes); Extensions = controlExtensions.ToList().AsReadOnly(); }
private void Read(Stream stream) { byte[] buffer = new byte[12]; stream.ReadAll(buffer, 0, buffer.Length); this.BlockSize = buffer[0]; if (this.BlockSize != 11) { throw GifHelpers.InvalidBlockSizeException("Application Extension", 11, this.BlockSize); } this.ApplicationIdentifier = Encoding.ASCII.GetString(buffer, 1, 8); byte[] destinationArray = new byte[3]; Array.Copy(buffer, 9, destinationArray, 0, 3); this.AuthenticationCode = destinationArray; this.Data = GifHelpers.ReadDataBlocks(stream, false); }
private void Read(Stream stream) { byte[] buffer = new byte[6]; stream.ReadAll(buffer, 0, buffer.Length); this.BlockSize = buffer[0]; if (this.BlockSize != 4) { throw GifHelpers.InvalidBlockSizeException("Graphic Control Extension", 4, this.BlockSize); } byte num = buffer[1]; this.DisposalMethod = (num & 0x1c) >> 2; this.UserInput = (num & 2) != 0; this.HasTransparency = (num & 1) != 0; this.Delay = BitConverter.ToUInt16(buffer, 2) * 10; this.TransparencyIndex = buffer[4]; }
private void Read(Stream stream) { // Note: at this point, the label (0xFF) has already been read byte[] bytes = new byte[12]; stream.ReadAll(bytes, 0, bytes.Length); BlockSize = bytes[0]; // should always be 11 if (BlockSize != 11) { throw GifHelpers.InvalidBlockSizeException("Application Extension", 11, BlockSize); } ApplicationIdentifier = Encoding.ASCII.GetString(bytes, 1, 8); byte[] authCode = new byte[3]; Array.Copy(bytes, 9, authCode, 0, 3); AuthenticationCode = authCode; Data = GifHelpers.ReadDataBlocks(stream, false); }
private void Read(Stream stream) { // Note: at this point, the label (0xF9) has already been read byte[] bytes = new byte[6]; stream.ReadAll(bytes, 0, bytes.Length); BlockSize = bytes[0]; // should always be 4 if (BlockSize != 4) { throw GifHelpers.InvalidBlockSizeException("Graphic Control Extension", 4, BlockSize); } byte packedFields = bytes[1]; DisposalMethod = (packedFields & 0x1C) >> 2; UserInput = (packedFields & 0x02) != 0; HasTransparency = (packedFields & 0x01) != 0; Delay = BitConverter.ToUInt16(bytes, 2) * 10; // milliseconds TransparencyIndex = bytes[4]; }
private void Read(Stream stream, IEnumerable <GifExtension> controlExtensions, bool metadataOnly) { byte[] buffer = new byte[13]; stream.ReadAll(buffer, 0, buffer.Length); this.BlockSize = buffer[0]; if (this.BlockSize != 12) { throw GifHelpers.InvalidBlockSizeException("Plain Text Extension", 12, this.BlockSize); } this.Left = BitConverter.ToUInt16(buffer, 1); this.Top = BitConverter.ToUInt16(buffer, 3); this.Width = BitConverter.ToUInt16(buffer, 5); this.Height = BitConverter.ToUInt16(buffer, 7); this.CellWidth = buffer[9]; this.CellHeight = buffer[10]; this.ForegroundColorIndex = buffer[11]; this.BackgroundColorIndex = buffer[12]; byte[] bytes = GifHelpers.ReadDataBlocks(stream, metadataOnly); this.Text = Encoding.ASCII.GetString(bytes); this.Extensions = controlExtensions.ToList <GifExtension>().AsReadOnly(); }