@@ -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 ;
0 commit comments