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); if (dataBytes != null) { Text = Encoding.ASCII.GetString(dataBytes); } Extensions = controlExtensions.ToList().AsReadOnly(); }
private void Read(Stream stream) { // Note: at this point, the label (0xFE) has already been read var bytes = GifHelpers.ReadDataBlocks(stream, false); if (bytes != null) { Text = Encoding.ASCII.GetString(bytes); } }
private void Read(Stream stream, IEnumerable <GifExtension> controlExtensions, bool metadataOnly) { // Note: at this point, the Image Separator (0x2C) has already been read Descriptor = GifImageDescriptor.ReadImageDescriptor(stream); if (Descriptor.HasLocalColorTable) { LocalColorTable = GifHelpers.ReadColorTable(stream, Descriptor.LocalColorTableSize); } ImageData = GifImageData.ReadImageData(stream, metadataOnly); Extensions = controlExtensions.ToList().AsReadOnly(); }
private void Read(Stream stream) { Signature = GifHelpers.ReadString(stream, 3); if (Signature != "GIF") { throw GifHelpers.InvalidSignatureException(Signature); } Version = GifHelpers.ReadString(stream, 3); if (Version != "87a" && Version != "89a") { throw GifHelpers.UnsupportedVersionException(Version); } LogicalScreenDescriptor = GifLogicalScreenDescriptor.ReadLogicalScreenDescriptor(stream); }
internal static GifBlock ReadBlock(Stream stream, IEnumerable <GifExtension> controlExtensions, bool metadataOnly) { var blockId = stream.ReadByte(); if (blockId < 0) { throw GifHelpers.UnexpectedEndOfStreamException(); } return(blockId switch { GifExtension.ExtensionIntroducer => (GifBlock)GifExtension.ReadExtension(stream, controlExtensions, metadataOnly), GifFrame.ImageSeparator => GifFrame.ReadFrame(stream, controlExtensions, metadataOnly), GifTrailer.TrailerByte => GifTrailer.ReadTrailer(), _ => throw GifHelpers.UnknownBlockTypeException(blockId) });
private void Read(Stream stream, bool metadataOnly) { Header = GifHeader.ReadHeader(stream); if (Header.LogicalScreenDescriptor?.HasGlobalColorTable == true) { GlobalColorTable = GifHelpers.ReadColorTable(stream, Header.LogicalScreenDescriptor.GlobalColorTableSize); } ReadFrames(stream, metadataOnly); var netscapeExtension = Extensions .OfType <GifApplicationExtension>() .FirstOrDefault(GifHelpers.IsNetscapeExtension); RepeatCount = netscapeExtension != null?GifHelpers.GetRepeatCount(netscapeExtension) : (ushort)1; }
internal static GifExtension ReadExtension(Stream stream, IEnumerable <GifExtension> controlExtensions, bool metadataOnly) { // Note: at this point, the Extension Introducer (0x21) has already been read var label = stream.ReadByte(); if (label < 0) { throw GifHelpers.UnexpectedEndOfStreamException(); } return(label switch { GifGraphicControlExtension.ExtensionLabel => (GifExtension)GifGraphicControlExtension.ReadGraphicsControl(stream), GifCommentExtension.ExtensionLabel => GifCommentExtension.ReadComment(stream), GifPlainTextExtension.ExtensionLabel => GifPlainTextExtension.ReadPlainText(stream, controlExtensions, metadataOnly), GifApplicationExtension.ExtensionLabel => GifApplicationExtension.ReadApplication(stream), _ => throw GifHelpers.UnknownExtensionTypeException(label) });
private void Read(Stream stream) { // Note: at this point, the label (0xFF) has already been read var 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); var 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 var 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); } var 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, bool metadataOnly) { LzwMinimumCodeSize = (byte)stream.ReadByte(); CompressedData = GifHelpers.ReadDataBlocks(stream, metadataOnly); }