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) });
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) });