diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
index 93d0bcaf18..5bec460cc7 100644
--- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
+++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
@@ -8,6 +8,7 @@ namespace ImageSharp.Formats
using System;
using System.Buffers;
using System.IO;
+ using System.Runtime.CompilerServices;
using System.Text;
using ImageSharp.PixelFormats;
@@ -332,6 +333,7 @@ namespace ImageSharp.Formats
///
/// The .
/// The pixel array to write to.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ReadFrameIndices(GifImageDescriptor imageDescriptor, byte[] indices)
{
int dataSize = this.currentStream.ReadByte();
@@ -366,7 +368,7 @@ namespace ImageSharp.Formats
// This initializes the image to become fully transparent because the alpha channel is zero.
this.image = Image.Create(imageWidth, imageHeight, this.metaData, this.configuration);
- this.SetFrameDelay(this.metaData);
+ this.SetFrameMetaData(this.metaData);
image = this.image;
}
@@ -380,7 +382,7 @@ namespace ImageSharp.Formats
currentFrame = this.previousFrame.Clone();
- this.SetFrameDelay(currentFrame.MetaData);
+ this.SetFrameMetaData(currentFrame.MetaData);
image = currentFrame;
@@ -506,14 +508,20 @@ namespace ImageSharp.Formats
}
///
- /// Sets the frame delay in the metadata.
+ /// Sets the frames metadata.
///
/// The meta data.
- private void SetFrameDelay(IMetaData metaData)
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private void SetFrameMetaData(IMetaData metaData)
{
if (this.graphicsControlExtension != null && this.graphicsControlExtension.DelayTime > 0)
{
- metaData.FrameDelay = this.graphicsControlExtension.DelayTime;
+ if (this.graphicsControlExtension.DelayTime > 0)
+ {
+ metaData.FrameDelay = this.graphicsControlExtension.DelayTime;
+ }
+
+ metaData.DisposalMethod = this.graphicsControlExtension.DisposalMethod;
}
}
}
diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs
index 3546b56628..becb56eabf 100644
--- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs
+++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs
@@ -191,7 +191,7 @@ namespace ImageSharp.Formats
{
Width = (short)image.Width,
Height = (short)image.Height,
- GlobalColorTableFlag = false, // Always false for now.
+ GlobalColorTableFlag = false, // TODO: Always false for now.
GlobalColorTableSize = this.bitDepth - 1,
BackgroundColorIndex = (byte)tranparencyIndex
};
@@ -312,16 +312,10 @@ namespace ImageSharp.Formats
private void WriteGraphicalControlExtension(ImageBase image, IMetaData metaData, EndianBinaryWriter writer, int transparencyIndex)
where TPixel : struct, IPixel
{
- // TODO: Check transparency logic.
- bool hasTransparent = transparencyIndex < 255;
- DisposalMethod disposalMethod = hasTransparent
- ? DisposalMethod.RestoreToBackground
- : DisposalMethod.Unspecified;
-
GifGraphicsControlExtension extension = new GifGraphicsControlExtension()
{
- DisposalMethod = disposalMethod,
- TransparencyFlag = hasTransparent,
+ DisposalMethod = metaData.DisposalMethod,
+ TransparencyFlag = transparencyIndex < 255,
TransparencyIndex = transparencyIndex,
DelayTime = metaData.FrameDelay
};
diff --git a/src/ImageSharp/MetaData/IMetaData.cs b/src/ImageSharp/MetaData/IMetaData.cs
index 38fd313493..6daa04dd63 100644
--- a/src/ImageSharp/MetaData/IMetaData.cs
+++ b/src/ImageSharp/MetaData/IMetaData.cs
@@ -5,6 +5,8 @@
namespace ImageSharp
{
+ using ImageSharp.Formats;
+
///
/// Encapsulates the metadata of an image frame.
///
@@ -12,10 +14,17 @@ namespace ImageSharp
{
///
/// Gets or sets the frame delay for animated images.
- /// If not 0, this field specifies the number of hundredths (1/100) of a second to
+ /// If not 0, when utilized in Gif animation, this field specifies the number of hundredths (1/100) of a second to
/// wait before continuing with the processing of the Data Stream.
/// The clock starts ticking immediately after the graphic is rendered.
///
int FrameDelay { get; set; }
+
+ ///
+ /// Gets or sets the disposal method for animated images.
+ /// Primarily used in Gif animation, this field indicates the way in which the graphic is to
+ /// be treated after being displayed.
+ ///
+ DisposalMethod DisposalMethod { get; set; }
}
}
diff --git a/src/ImageSharp/MetaData/ImageFrameMetaData.cs b/src/ImageSharp/MetaData/ImageFrameMetaData.cs
index 50119096e9..b55bfd1ad1 100644
--- a/src/ImageSharp/MetaData/ImageFrameMetaData.cs
+++ b/src/ImageSharp/MetaData/ImageFrameMetaData.cs
@@ -5,6 +5,8 @@
namespace ImageSharp
{
+ using ImageSharp.Formats;
+
///
/// Encapsulates the metadata of an image frame.
///
@@ -29,14 +31,13 @@ namespace ImageSharp
DebugGuard.NotNull(other, nameof(other));
this.FrameDelay = other.FrameDelay;
+ this.DisposalMethod = other.DisposalMethod;
}
- ///
- /// Gets or sets the frame delay for animated images.
- /// If not 0, this field specifies the number of hundredths (1/100) of a second to
- /// wait before continuing with the processing of the Data Stream.
- /// The clock starts ticking immediately after the graphic is rendered.
- ///
+ ///
public int FrameDelay { get; set; }
+
+ ///
+ public DisposalMethod DisposalMethod { get; set; }
}
}
diff --git a/src/ImageSharp/MetaData/ImageMetaData.cs b/src/ImageSharp/MetaData/ImageMetaData.cs
index aed6efa2cb..127ae720f2 100644
--- a/src/ImageSharp/MetaData/ImageMetaData.cs
+++ b/src/ImageSharp/MetaData/ImageMetaData.cs
@@ -7,6 +7,7 @@ namespace ImageSharp
{
using System;
using System.Collections.Generic;
+ using ImageSharp.Formats;
///
/// Encapsulates the metadata of an image.
@@ -52,6 +53,7 @@ namespace ImageSharp
this.VerticalResolution = other.VerticalResolution;
this.Quality = other.Quality;
this.FrameDelay = other.FrameDelay;
+ this.DisposalMethod = other.DisposalMethod;
this.RepeatCount = other.RepeatCount;
foreach (ImageProperty property in other.Properties)
@@ -83,10 +85,10 @@ namespace ImageSharp
set
{
- if (value > 0)
- {
- this.horizontalResolution = value;
- }
+ if (value > 0)
+ {
+ this.horizontalResolution = value;
+ }
}
}
@@ -116,14 +118,12 @@ namespace ImageSharp
///
public ExifProfile ExifProfile { get; set; }
- ///
- /// Gets or sets the frame delay for animated images.
- /// If not 0, this field specifies the number of hundredths (1/100) of a second to
- /// wait before continuing with the processing of the Data Stream.
- /// The clock starts ticking immediately after the graphic is rendered.
- ///
+ ///
public int FrameDelay { get; set; }
+ ///
+ public DisposalMethod DisposalMethod { get; set; }
+
///
/// Gets the list of properties for storing meta information about this image.
///