Handle dedup of local palette of 256 length - Main by JimBobSquarePants · Pull Request #2607 · SixLabors/ImageSharp · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions src/ImageSharp/Formats/Gif/GifEncoderCore.cs
10 changes: 8 additions & 2 deletions src/ImageSharp/Formats/Gif/MetadataExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,20 @@ internal static AnimatedImageMetadata ToAnimatedImageMetadata(this GifMetadata s
}

internal static AnimatedImageFrameMetadata ToAnimatedImageFrameMetadata(this GifFrameMetadata source)
=> new()
{
// For most scenarios we would consider the blend method to be 'Over' however if a frame has a disposal method of 'RestoreToBackground' or
// has a local palette with 256 colors and is not transparent we should use 'Source'.
bool blendSource = source.DisposalMethod == GifDisposalMethod.RestoreToBackground || (source.LocalColorTable?.Length == 256 && !source.HasTransparency);

return new()
{
ColorTable = source.LocalColorTable,
ColorTableMode = source.ColorTableMode == GifColorTableMode.Global ? FrameColorTableMode.Global : FrameColorTableMode.Local,
Duration = TimeSpan.FromMilliseconds(source.FrameDelay * 10),
DisposalMode = GetMode(source.DisposalMethod),
BlendMode = source.DisposalMethod == GifDisposalMethod.RestoreToBackground ? FrameBlendMode.Source : FrameBlendMode.Over,
BlendMode = blendSource ? FrameBlendMode.Source : FrameBlendMode.Over,
};
}

private static FrameDisposalMode GetMode(GifDisposalMethod method) => method switch
{
Expand Down
4 changes: 2 additions & 2 deletions src/ImageSharp/Formats/Webp/BitReader/Vp8LBitReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public Vp8LBitReader(IMemoryOwner<byte> data)
this.Eos = false;

ulong currentValue = 0;
System.Span<byte> dataSpan = this.Data.Memory.Span;
Span<byte> dataSpan = this.Data.Memory.Span;
for (int i = 0; i < 8; i++)
{
currentValue |= (ulong)dataSpan[i] << (8 * i);
Expand Down Expand Up @@ -103,7 +103,7 @@ public Vp8LBitReader(Stream inputStream, uint imageDataSize, MemoryAllocator mem
}

ulong currentValue = 0;
System.Span<byte> dataSpan = this.Data.Memory.Span;
Span<byte> dataSpan = this.Data.Memory.Span;
for (int i = 0; i < length; i++)
{
currentValue |= (ulong)dataSpan[i] << (8 * i);
Expand Down
4 changes: 3 additions & 1 deletion tests/ImageSharp.Tests/TestImages.cs
3 changes: 3 additions & 0 deletions tests/Images/Input/Gif/18-bit_RGB_Cube.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.