Skip to content

Commit

Permalink
Merge pull request #2770 from SixLabors/af/backport-2759-2.1.x
Browse files Browse the repository at this point in the history
Backport 2759 to 2.1.x
  • Loading branch information
JimBobSquarePants authored Jul 15, 2024
2 parents a1f2879 + b33d666 commit 9816ca4
Show file tree
Hide file tree
Showing 15 changed files with 564 additions and 278 deletions.
5 changes: 5 additions & 0 deletions src/ImageSharp/Formats/Gif/GifDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public sealed class GifDecoder : IImageDecoder, IGifDecoderOptions, IImageInfoDe
/// </summary>
public FrameDecodingMode DecodingMode { get; set; } = FrameDecodingMode.All;

/// <summary>
/// Gets or sets the maximum number of gif frames.
/// </summary>
public uint MaxFrames { get; set; } = uint.MaxValue;

/// <inheritdoc/>
public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel<TPixel>
Expand Down
465 changes: 284 additions & 181 deletions src/ImageSharp/Formats/Gif/GifDecoderCore.cs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/ImageSharp/Formats/Gif/GifThrowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0.

using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace SixLabors.ImageSharp.Formats.Gif
Expand All @@ -24,5 +25,11 @@ public static void ThrowInvalidImageContentException(string errorMessage)
/// if no inner exception is specified.</param>
[MethodImpl(InliningOptions.ColdPath)]
public static void ThrowInvalidImageContentException(string errorMessage, Exception innerException) => throw new InvalidImageContentException(errorMessage, innerException);

[MethodImpl(InliningOptions.ColdPath)]
public static void ThrowNoHeader() => throw new InvalidImageContentException("Gif image does not contain a Logical Screen Descriptor.");

[MethodImpl(InliningOptions.ColdPath)]
public static void ThrowNoData() => throw new InvalidImageContentException("Unable to read Gif image data");
}
}
5 changes: 5 additions & 0 deletions src/ImageSharp/Formats/Gif/IGifDecoderOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@ internal interface IGifDecoderOptions
/// Gets the decoding mode for multi-frame images.
/// </summary>
FrameDecodingMode DecodingMode { get; }

/// <summary>
/// Gets or sets the maximum number of gif frames.
/// </summary>
uint MaxFrames { get; set; }
}
}
Loading

0 comments on commit 9816ca4

Please sign in to comment.