|
|
|
@ -376,7 +376,17 @@ namespace SixLabors.ImageSharp.Formats.Gif |
|
|
|
indices = this.Configuration.MemoryAllocator.Allocate2D<byte>(this.imageDescriptor.Width, this.imageDescriptor.Height, AllocationOptions.Clean); |
|
|
|
|
|
|
|
this.ReadFrameIndices(indices); |
|
|
|
ReadOnlySpan<Rgb24> colorTable = MemoryMarshal.Cast<byte, Rgb24>((localColorTable ?? this.globalColorTable).GetSpan()); |
|
|
|
Span<byte> rawColorTable = default; |
|
|
|
if (localColorTable != null) |
|
|
|
{ |
|
|
|
rawColorTable = localColorTable.GetSpan(); |
|
|
|
} |
|
|
|
else if (this.globalColorTable != null) |
|
|
|
{ |
|
|
|
rawColorTable = this.globalColorTable.GetSpan(); |
|
|
|
} |
|
|
|
|
|
|
|
ReadOnlySpan<Rgb24> colorTable = MemoryMarshal.Cast<byte, Rgb24>(rawColorTable); |
|
|
|
this.ReadFrameColors(ref image, ref previousFrame, indices, colorTable, this.imageDescriptor); |
|
|
|
|
|
|
|
// Skip any remaining blocks
|
|
|
|
@ -415,6 +425,7 @@ namespace SixLabors.ImageSharp.Formats.Gif |
|
|
|
{ |
|
|
|
int imageWidth = this.logicalScreenDescriptor.Width; |
|
|
|
int imageHeight = this.logicalScreenDescriptor.Height; |
|
|
|
bool transFlag = this.graphicsControlExtension.TransparencyFlag; |
|
|
|
|
|
|
|
ImageFrame<TPixel> prevFrame = null; |
|
|
|
ImageFrame<TPixel> currentFrame = null; |
|
|
|
@ -422,8 +433,15 @@ namespace SixLabors.ImageSharp.Formats.Gif |
|
|
|
|
|
|
|
if (previousFrame is null) |
|
|
|
{ |
|
|
|
// This initializes the image to become fully transparent because the alpha channel is zero.
|
|
|
|
image = new Image<TPixel>(this.Configuration, imageWidth, imageHeight, this.metadata); |
|
|
|
if (!transFlag) |
|
|
|
{ |
|
|
|
image = new Image<TPixel>(this.Configuration, imageWidth, imageHeight, Color.Black.ToPixel<TPixel>(), this.metadata); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// This initializes the image to become fully transparent because the alpha channel is zero.
|
|
|
|
image = new Image<TPixel>(this.Configuration, imageWidth, imageHeight, this.metadata); |
|
|
|
} |
|
|
|
|
|
|
|
this.SetFrameMetadata(image.Frames.RootFrame.Metadata); |
|
|
|
|
|
|
|
@ -445,6 +463,11 @@ namespace SixLabors.ImageSharp.Formats.Gif |
|
|
|
this.RestoreToBackground(imageFrame); |
|
|
|
} |
|
|
|
|
|
|
|
if (colorTable.Length == 0) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
int interlacePass = 0; // The interlace pass
|
|
|
|
int interlaceIncrement = 8; // The interlacing line increment
|
|
|
|
int interlaceY = 0; // The current interlaced line
|
|
|
|
@ -452,7 +475,6 @@ namespace SixLabors.ImageSharp.Formats.Gif |
|
|
|
int descriptorBottom = descriptorTop + descriptor.Height; |
|
|
|
int descriptorLeft = descriptor.Left; |
|
|
|
int descriptorRight = descriptorLeft + descriptor.Width; |
|
|
|
bool transFlag = this.graphicsControlExtension.TransparencyFlag; |
|
|
|
byte transIndex = this.graphicsControlExtension.TransparencyIndex; |
|
|
|
int colorTableMaxIdx = colorTable.Length - 1; |
|
|
|
|
|
|
|
@ -635,10 +657,13 @@ namespace SixLabors.ImageSharp.Formats.Gif |
|
|
|
int globalColorTableLength = this.logicalScreenDescriptor.GlobalColorTableSize * 3; |
|
|
|
this.gifMetadata.GlobalColorTableLength = globalColorTableLength; |
|
|
|
|
|
|
|
this.globalColorTable = this.MemoryAllocator.Allocate<byte>(globalColorTableLength, AllocationOptions.Clean); |
|
|
|
if (globalColorTableLength > 0) |
|
|
|
{ |
|
|
|
this.globalColorTable = this.MemoryAllocator.Allocate<byte>(globalColorTableLength, AllocationOptions.Clean); |
|
|
|
|
|
|
|
// Read the global color table data from the stream
|
|
|
|
stream.Read(this.globalColorTable.GetSpan()); |
|
|
|
// Read the global color table data from the stream
|
|
|
|
stream.Read(this.globalColorTable.GetSpan()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|