예제 #1
0
        internal static GifExtension ReadExtension(Stream stream, IEnumerable <GifExtension> controlExtensions, bool metadataOnly)
        {
            // Note: at this point, the Extension Introducer (0x21) has already been read

            int label = stream.ReadByte();

            if (label < 0)
            {
                throw GifHelpers.UnexpectedEndOfStreamException();
            }
            switch (label)
            {
            case GifGraphicControlExtension.ExtensionLabel:
                return(GifGraphicControlExtension.ReadGraphicsControl(stream));

            case GifCommentExtension.ExtensionLabel:
                return(GifCommentExtension.ReadComment(stream));

            case GifPlainTextExtension.ExtensionLabel:
                return(GifPlainTextExtension.ReadPlainText(stream, controlExtensions, metadataOnly));

            case GifApplicationExtension.ExtensionLabel:
                return(GifApplicationExtension.ReadApplication(stream));

            default:
                throw GifHelpers.UnknownExtensionTypeException(label);
            }
        }
예제 #2
0
        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();
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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();
        }
예제 #5
0
 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);
 }
예제 #6
0
        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);
        }
예제 #7
0
        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];
        }
예제 #8
0
        internal static GifBlock ReadBlock(Stream stream, IEnumerable <GifExtension> controlExtensions, bool metadataOnly)
        {
            int blockId = stream.ReadByte();

            if (blockId < 0)
            {
                throw GifHelpers.UnexpectedEndOfStreamException();
            }
            switch (blockId)
            {
            case GifExtension.ExtensionIntroducer:
                return(GifExtension.ReadExtension(stream, controlExtensions, metadataOnly));

            case GifFrame.ImageSeparator:
                return(GifFrame.ReadFrame(stream, controlExtensions, metadataOnly));

            case GifTrailer.TrailerByte:
                return(GifTrailer.ReadTrailer());

            default:
                throw GifHelpers.UnknownBlockTypeException(blockId);
            }
        }
예제 #9
0
        private void Read(Stream stream, bool metadataOnly)
        {
            Header = GifHeader.ReadHeader(stream);

            if (Header.LogicalScreenDescriptor.HasGlobalColorTable)
            {
                GlobalColorTable = GifHelpers.ReadColorTable(stream, Header.LogicalScreenDescriptor.GlobalColorTableSize);
            }
            ReadFrames(stream, metadataOnly);

            var netscapeExtension =
                Extensions
                .OfType <GifApplicationExtension>()
                .FirstOrDefault(GifHelpers.IsNetscapeExtension);

            if (netscapeExtension != null)
            {
                RepeatCount = GifHelpers.GetRepeatCount(netscapeExtension);
            }
            else
            {
                RepeatCount = 1;
            }
        }
예제 #10
0
 private void Read(Stream stream, bool metadataOnly)
 {
     LzwMinimumCodeSize = (byte)stream.ReadByte();
     CompressedData     = GifHelpers.ReadDataBlocks(stream, metadataOnly);
 }