From b56633e2f07a81f92d17c79c42990519035d6743 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 11 Sep 2023 20:51:39 +1000 Subject: [PATCH] Review fixes --- src/ImageSharp/Formats/Gif/GifDecoderCore.cs | 11 ++++++----- src/ImageSharp/Formats/Gif/GifFrameMetadata.cs | 3 +++ src/ImageSharp/Formats/Gif/GifMetadata.cs | 3 +++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs index 776cb0e3c2..bc41c89dcf 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs +++ b/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(this.currentLocalColorTable!.GetSpan()[..this.currentLocalColorTableSize])); + ReadOnlySpan rgbTable = MemoryMarshal.Cast(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(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 globalColorTableSpan = this.globalColorTable.GetSpan(); + stream.Read(globalColorTableSpan); Color[] colorTable = new Color[this.logicalScreenDescriptor.GlobalColorTableSize]; - ref Rgb24 globalBase = ref MemoryMarshal.GetReference(MemoryMarshal.Cast(this.globalColorTable.GetSpan())); + ReadOnlySpan rgbTable = MemoryMarshal.Cast(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; diff --git a/src/ImageSharp/Formats/Gif/GifFrameMetadata.cs b/src/ImageSharp/Formats/Gif/GifFrameMetadata.cs index f7959ac12b..faabf7dfa8 100644 --- a/src/ImageSharp/Formats/Gif/GifFrameMetadata.cs +++ b/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; /// @@ -41,6 +43,7 @@ public class GifFrameMetadata : IDeepCloneable /// /// Gets or sets the local color table, if any. + /// The underlying pixel format is represented by . /// public ReadOnlyMemory? LocalColorTable { get; set; } diff --git a/src/ImageSharp/Formats/Gif/GifMetadata.cs b/src/ImageSharp/Formats/Gif/GifMetadata.cs index 0172344ff9..d25e2a5cc2 100644 --- a/src/ImageSharp/Formats/Gif/GifMetadata.cs +++ b/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; /// @@ -51,6 +53,7 @@ public class GifMetadata : IDeepCloneable /// /// Gets or sets the global color table, if any. + /// The underlying pixel format is represented by . /// public ReadOnlyMemory? GlobalColorTable { get; set; }