コード例 #1
0
        /// <summary>
        /// Creates a new instance of the <see cref="GifFrame"/> class from the byte representation
        /// starting from the current position in the <see cref="Stream"/>.
        /// </summary>
        /// <param name="stream">The <see cref="Stream"/> containing the byte representation of a <see cref="GifFrame"/>.</param>
        /// <param name="globalColorTable">The global color table of the Gif.</param>
        internal GifFrame(Stream stream, GifColorTable globalColorTable)
        {
            if (GifExtension.IsUpcoming(stream))
            {
                Extension = GifExtension.FromStream(stream);
            }

            Descriptor = new GifFrameDescriptor(stream);
            ColorTable = Descriptor.HasLocalColorTable ? new GifColorTable(stream, Descriptor.SizeOfColorTable) : globalColorTable;
            ColorData  = GifLZW.Decode(stream);
        }
コード例 #2
0
        /// <summary>
        /// Writes the byte representation of this <see cref="GifFrame"/> to the given <see cref="Stream"/>.
        /// </summary>
        /// <param name="stream">The <see cref="Stream"/> to write to.</param>
        internal void WriteToStream(Stream stream)
        {
            if (Extension != null)
            {
                Extension.WriteToStream(stream);
            }

            Descriptor.WriteToStream(stream);

            if (Descriptor.HasLocalColorTable)
            {
                ColorTable.WriteToStream(stream);
            }

            GifLZW.Encode(stream, ColorData, GifColorTable.GetNumberOfEntries(ColorTable.ScreenDescriptorSize));
        }
コード例 #3
0
ファイル: Gif.cs プロジェクト: Banane9/SharpGif
        /// <summary>
        /// Creates a new instance of the <see cref="Gif"/> class from the byte representation
        /// starting from the current position in the <see cref="Stream"/>.
        /// </summary>
        /// <param name="stream">The <see cref="Stream"/> containing the byte representation of a <see cref="Gif"/>.</param>
        public Gif(Stream stream)
        {
            Header = GifHeader.GetFromStream(stream);

            LogicalScreenDescriptor = new GifLogicalScreenDescriptor(stream);

            if (LogicalScreenDescriptor.HasGlobalColorTable)
            {
                GlobalColorTable = new GifColorTable(stream, LogicalScreenDescriptor.SizeOfColorTable);
            }

            Frames = new List <GifFrame>();
            while (stream.PeakByte() != trailer)
            {
                Frames.Add(new GifFrame(stream, GlobalColorTable));
            }
        }