Skip to content

Commit a42f6b6

Browse files
Enable dedup for png
1 parent 958c9c9 commit a42f6b6

5 files changed

Lines changed: 97 additions & 89 deletions

File tree

src/ImageSharp/Formats/AnimationUtilities.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ public static (bool Difference, Rectangle Bounds) DeDuplicatePixels<TPixel>(
8585
int m = Avx2.MoveMask(neq.AsByte());
8686
if (m != 0)
8787
{
88-
// If is diff is found, the left side is marked by the min of previously found left side and the diff position.
89-
// The right is the max of the previously found right side and the diff position + 1.
90-
int diff = (int)(i + (uint)(BitOperations.TrailingZeroCount(m) / size));
91-
left = Math.Min(left, diff);
92-
right = Math.Max(right, diff + 1);
88+
// If is diff is found, the left side is marked by the min of previously found left side and the start position.
89+
// The right is the max of the previously found right side and the end position.
90+
int start = i + (BitOperations.TrailingZeroCount(m) / size);
91+
int end = i + (2 - (BitOperations.LeadingZeroCount((uint)m) / size));
92+
left = Math.Min(left, start);
93+
right = Math.Max(right, end);
9394
hasRowDiff = true;
9495
hasDiff = true;
9596
}

src/ImageSharp/Formats/Gif/GifDecoderCore.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,8 @@ private void ReadLogicalScreenDescriptorAndGlobalColorTable(BufferedReadStream s
797797
this.gifMetadata.GlobalColorTable = colorTable;
798798
}
799799
}
800+
801+
this.gifMetadata.BackgroundColorIndex = this.logicalScreenDescriptor.BackgroundColorIndex;
800802
}
801803

802804
private unsafe struct ScratchBuffer

src/ImageSharp/Formats/Gif/GifEncoderCore.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,6 @@ private void EncodeAdditionalFrames<TPixel>(
245245
ImageFrame<TPixel> previousFrame = image.Frames.RootFrame;
246246

247247
// This frame is reused to store de-duplicated pixel buffers.
248-
// This is more expensive memory-wise than de-duplicating indexed buffer but allows us to deduplicate
249-
// frames using both local and global palettes.
250248
using ImageFrame<TPixel> encodingFrame = new(previousFrame.Configuration, previousFrame.Size());
251249

252250
for (int i = 1; i < image.Frames.Count; i++)

src/ImageSharp/Formats/Gif/MetadataExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ internal static AnimatedImageFrameMetadata ToAnimatedImageFrameMetadata(this Gif
8383
ColorTableMode = source.ColorTableMode == GifColorTableMode.Global ? FrameColorTableMode.Global : FrameColorTableMode.Local,
8484
Duration = TimeSpan.FromMilliseconds(source.FrameDelay * 10),
8585
DisposalMode = GetMode(source.DisposalMethod),
86-
BlendMode = FrameBlendMode.Source,
86+
BlendMode = FrameBlendMode.Over,
8787
};
8888

8989
private static FrameDisposalMode GetMode(GifDisposalMethod method) => method switch

0 commit comments

Comments
 (0)