Browse Source

Rename GifGraphicControlExtension extension to match spec

pull/536/head
Jason Nelson 8 years ago
parent
commit
083cf9f754
  1. 4
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs
  2. 4
      src/ImageSharp/Formats/Gif/GifEncoderCore.cs
  3. 16
      src/ImageSharp/Formats/Gif/Sections/GifGraphicControlExtension.cs

4
src/ImageSharp/Formats/Gif/GifDecoderCore.cs

@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// <summary> /// <summary>
/// The graphics control extension. /// The graphics control extension.
/// </summary> /// </summary>
private GifGraphicsControlExtension graphicsControlExtension; private GifGraphicControlExtension graphicsControlExtension;
/// <summary> /// <summary>
/// The metadata /// The metadata
@ -238,7 +238,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
{ {
this.stream.Read(this.buffer, 0, 6); this.stream.Read(this.buffer, 0, 6);
this.graphicsControlExtension = GifGraphicsControlExtension.Parse(this.buffer); this.graphicsControlExtension = GifGraphicControlExtension.Parse(this.buffer);
} }
/// <summary> /// <summary>

4
src/ImageSharp/Formats/Gif/GifEncoderCore.cs

@ -248,11 +248,11 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// <param name="transparencyIndex">The index of the color in the color palette to make transparent.</param> /// <param name="transparencyIndex">The index of the color in the color palette to make transparent.</param>
private void WriteGraphicalControlExtension(ImageFrameMetaData metaData, Stream stream, int transparencyIndex) private void WriteGraphicalControlExtension(ImageFrameMetaData metaData, Stream stream, int transparencyIndex)
{ {
byte packedValue = GifGraphicsControlExtension.GetPackedValue( byte packedValue = GifGraphicControlExtension.GetPackedValue(
disposalMethod: metaData.DisposalMethod, disposalMethod: metaData.DisposalMethod,
transparencyFlag: transparencyIndex > -1); transparencyFlag: transparencyIndex > -1);
var extension = new GifGraphicsControlExtension( var extension = new GifGraphicControlExtension(
packed: packedValue, packed: packedValue,
transparencyIndex: unchecked((byte)transparencyIndex), transparencyIndex: unchecked((byte)transparencyIndex),
delayTime: (ushort)metaData.FrameDelay); delayTime: (ushort)metaData.FrameDelay);

16
src/ImageSharp/Formats/Gif/Sections/GifGraphicsControlExtension.cs → src/ImageSharp/Formats/Gif/Sections/GifGraphicControlExtension.cs

@ -12,9 +12,9 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// processing a graphic rendering block. /// processing a graphic rendering block.
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
internal readonly struct GifGraphicsControlExtension : IGifExtension internal readonly struct GifGraphicControlExtension : IGifExtension
{ {
public GifGraphicsControlExtension( public GifGraphicControlExtension(
byte packed, byte packed,
ushort delayTime, ushort delayTime,
byte transparencyIndex) byte transparencyIndex)
@ -36,9 +36,8 @@ namespace SixLabors.ImageSharp.Formats.Gif
public byte Packed { get; } public byte Packed { get; }
/// <summary> /// <summary>
/// Gets the delay time. /// Gets the delay time in of hundredths (1/100) of a second
/// If not 0, this field specifies the number of hundredths (1/100) of a second to /// to wait before continuing with the processing of the Data Stream.
/// wait before continuing with the processing of the Data Stream.
/// The clock starts ticking immediately after the graphic is rendered. /// The clock starts ticking immediately after the graphic is rendered.
/// </summary> /// </summary>
public ushort DelayTime { get; } public ushort DelayTime { get; }
@ -59,7 +58,6 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// <summary> /// <summary>
/// Gets a value indicating whether transparency flag is to be set. /// Gets a value indicating whether transparency flag is to be set.
/// This indicates whether a transparency index is given in the Transparent Index field. /// This indicates whether a transparency index is given in the Transparent Index field.
/// (This field is the least significant bit of the byte.)
/// </summary> /// </summary>
public bool TransparencyFlag => (this.Packed & 0x01) == 1; public bool TransparencyFlag => (this.Packed & 0x01) == 1;
@ -67,16 +65,16 @@ namespace SixLabors.ImageSharp.Formats.Gif
public int WriteTo(Span<byte> buffer) public int WriteTo(Span<byte> buffer)
{ {
ref GifGraphicsControlExtension dest = ref Unsafe.As<byte, GifGraphicsControlExtension>(ref MemoryMarshal.GetReference(buffer)); ref GifGraphicControlExtension dest = ref Unsafe.As<byte, GifGraphicControlExtension>(ref MemoryMarshal.GetReference(buffer));
dest = this; dest = this;
return 5; return 5;
} }
public static GifGraphicsControlExtension Parse(ReadOnlySpan<byte> buffer) public static GifGraphicControlExtension Parse(ReadOnlySpan<byte> buffer)
{ {
return MemoryMarshal.Cast<byte, GifGraphicsControlExtension>(buffer)[0]; return MemoryMarshal.Cast<byte, GifGraphicControlExtension>(buffer)[0];
} }
public static byte GetPackedValue(DisposalMethod disposalMethod, bool userInputFlag = false, bool transparencyFlag = false) public static byte GetPackedValue(DisposalMethod disposalMethod, bool userInputFlag = false, bool transparencyFlag = false)
Loading…
Cancel
Save