Browse Source

Review fixes

pull/2455/head
James Jackson-South 3 years ago
parent
commit
b56633e2f0
  1. 11
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs
  2. 3
      src/ImageSharp/Formats/Gif/GifFrameMetadata.cs
  3. 3
      src/ImageSharp/Formats/Gif/GifMetadata.cs

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

@ -710,10 +710,10 @@ internal sealed class GifDecoderCore : IImageDecoderInternals
gifMeta.ColorTableMode = GifColorTableMode.Local;
Color[] colorTable = new Color[this.imageDescriptor.LocalColorTableSize];
ref Rgb24 localBase = ref MemoryMarshal.GetReference(MemoryMarshal.Cast<byte, Rgb24>(this.currentLocalColorTable!.GetSpan()[..this.currentLocalColorTableSize]));
ReadOnlySpan<Rgb24> rgbTable = MemoryMarshal.Cast<byte, Rgb24>(this.currentLocalColorTable!.GetSpan()[..this.currentLocalColorTableSize]);
for (int i = 0; i < colorTable.Length; i++)
{
colorTable[i] = new Color(Unsafe.Add(ref localBase, (uint)i));
colorTable[i] = new Color(rgbTable[i]);
}
gifMeta.LocalColorTable = colorTable;
@ -784,13 +784,14 @@ internal sealed class GifDecoderCore : IImageDecoderInternals
this.globalColorTable = this.memoryAllocator.Allocate<byte>(globalColorTableLength, AllocationOptions.Clean);
// Read the global color table data from the stream and preserve it in the gif metadata
stream.Read(this.globalColorTable.GetSpan());
Span<byte> globalColorTableSpan = this.globalColorTable.GetSpan();
stream.Read(globalColorTableSpan);
Color[] colorTable = new Color[this.logicalScreenDescriptor.GlobalColorTableSize];
ref Rgb24 globalBase = ref MemoryMarshal.GetReference(MemoryMarshal.Cast<byte, Rgb24>(this.globalColorTable.GetSpan()));
ReadOnlySpan<Rgb24> rgbTable = MemoryMarshal.Cast<byte, Rgb24>(globalColorTableSpan);
for (int i = 0; i < colorTable.Length; i++)
{
colorTable[i] = new Color(Unsafe.Add(ref globalBase, (uint)i));
colorTable[i] = new Color(rgbTable[i]);
}
this.gifMetadata.GlobalColorTable = colorTable;

3
src/ImageSharp/Formats/Gif/GifFrameMetadata.cs

@ -1,6 +1,8 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Gif;
/// <summary>
@ -41,6 +43,7 @@ public class GifFrameMetadata : IDeepCloneable
/// <summary>
/// Gets or sets the local color table, if any.
/// The underlying pixel format is represented by <see cref="Rgb24"/>.
/// </summary>
public ReadOnlyMemory<Color>? LocalColorTable { get; set; }

3
src/ImageSharp/Formats/Gif/GifMetadata.cs

@ -1,6 +1,8 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Gif;
/// <summary>
@ -51,6 +53,7 @@ public class GifMetadata : IDeepCloneable
/// <summary>
/// Gets or sets the global color table, if any.
/// The underlying pixel format is represented by <see cref="Rgb24"/>.
/// </summary>
public ReadOnlyMemory<Color>? GlobalColorTable { get; set; }

Loading…
Cancel
Save