Skip to content

Commit b56633e

Browse files
Review fixes
1 parent c17eacf commit b56633e

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/ImageSharp/Formats/Gif/GifDecoderCore.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -710,10 +710,10 @@ private void SetFrameMetadata(ImageFrameMetadata metadata)
710710
gifMeta.ColorTableMode = GifColorTableMode.Local;
711711

712712
Color[] colorTable = new Color[this.imageDescriptor.LocalColorTableSize];
713-
ref Rgb24 localBase = ref MemoryMarshal.GetReference(MemoryMarshal.Cast<byte, Rgb24>(this.currentLocalColorTable!.GetSpan()[..this.currentLocalColorTableSize]));
713+
ReadOnlySpan<Rgb24> rgbTable = MemoryMarshal.Cast<byte, Rgb24>(this.currentLocalColorTable!.GetSpan()[..this.currentLocalColorTableSize]);
714714
for (int i = 0; i < colorTable.Length; i++)
715715
{
716-
colorTable[i] = new Color(Unsafe.Add(ref localBase, (uint)i));
716+
colorTable[i] = new Color(rgbTable[i]);
717717
}
718718

719719
gifMeta.LocalColorTable = colorTable;
@@ -784,13 +784,14 @@ private void ReadLogicalScreenDescriptorAndGlobalColorTable(BufferedReadStream s
784784
this.globalColorTable = this.memoryAllocator.Allocate<byte>(globalColorTableLength, AllocationOptions.Clean);
785785

786786
// Read the global color table data from the stream and preserve it in the gif metadata
787-
stream.Read(this.globalColorTable.GetSpan());
787+
Span<byte> globalColorTableSpan = this.globalColorTable.GetSpan();
788+
stream.Read(globalColorTableSpan);
788789

789790
Color[] colorTable = new Color[this.logicalScreenDescriptor.GlobalColorTableSize];
790-
ref Rgb24 globalBase = ref MemoryMarshal.GetReference(MemoryMarshal.Cast<byte, Rgb24>(this.globalColorTable.GetSpan()));
791+
ReadOnlySpan<Rgb24> rgbTable = MemoryMarshal.Cast<byte, Rgb24>(globalColorTableSpan);
791792
for (int i = 0; i < colorTable.Length; i++)
792793
{
793-
colorTable[i] = new Color(Unsafe.Add(ref globalBase, (uint)i));
794+
colorTable[i] = new Color(rgbTable[i]);
794795
}
795796

796797
this.gifMetadata.GlobalColorTable = colorTable;

src/ImageSharp/Formats/Gif/GifFrameMetadata.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4+
using SixLabors.ImageSharp.PixelFormats;
5+
46
namespace SixLabors.ImageSharp.Formats.Gif;
57

68
/// <summary>
@@ -41,6 +43,7 @@ private GifFrameMetadata(GifFrameMetadata other)
4143

4244
/// <summary>
4345
/// Gets or sets the local color table, if any.
46+
/// The underlying pixel format is represented by <see cref="Rgb24"/>.
4447
/// </summary>
4548
public ReadOnlyMemory<Color>? LocalColorTable { get; set; }
4649

src/ImageSharp/Formats/Gif/GifMetadata.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4+
using SixLabors.ImageSharp.PixelFormats;
5+
46
namespace SixLabors.ImageSharp.Formats.Gif;
57

68
/// <summary>
@@ -51,6 +53,7 @@ private GifMetadata(GifMetadata other)
5153

5254
/// <summary>
5355
/// Gets or sets the global color table, if any.
56+
/// The underlying pixel format is represented by <see cref="Rgb24"/>.
5457
/// </summary>
5558
public ReadOnlyMemory<Color>? GlobalColorTable { get; set; }
5659

0 commit comments

Comments
 (0)