From 4a6b51bc288f13978adcc59f618615216c5db956 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Thu, 1 Aug 2024 15:25:41 +1000 Subject: [PATCH] Rename --- src/ImageSharp/Formats/DecoderOptions.cs | 2 +- src/ImageSharp/Formats/Png/PngChunk.cs | 8 ++++---- src/ImageSharp/Formats/Png/PngDecoderCore.cs | 12 ++++++------ ...tErrorHandling.cs => SegmentIntegrityHandling.cs} | 2 +- .../ImageSharp.Tests/Formats/Png/PngDecoderTests.cs | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) rename src/ImageSharp/Formats/{SegmentErrorHandling.cs => SegmentIntegrityHandling.cs} (94%) diff --git a/src/ImageSharp/Formats/DecoderOptions.cs b/src/ImageSharp/Formats/DecoderOptions.cs index be906d7d93..3b16159b7e 100644 --- a/src/ImageSharp/Formats/DecoderOptions.cs +++ b/src/ImageSharp/Formats/DecoderOptions.cs @@ -58,7 +58,7 @@ public sealed class DecoderOptions /// /// Gets the segment error handling strategy to use during decoding. /// - public SegmentErrorHandling SegmentErrorHandling { get; init; } = SegmentErrorHandling.IgnoreNonCritical; + public SegmentIntegrityHandling SegmentIntegrityHandling { get; init; } = SegmentIntegrityHandling.IgnoreNonCritical; internal void SetConfiguration(Configuration configuration) => this.configuration = configuration; } diff --git a/src/ImageSharp/Formats/Png/PngChunk.cs b/src/ImageSharp/Formats/Png/PngChunk.cs index 666f51daad..3883986d06 100644 --- a/src/ImageSharp/Formats/Png/PngChunk.cs +++ b/src/ImageSharp/Formats/Png/PngChunk.cs @@ -42,12 +42,12 @@ internal readonly struct PngChunk /// Gets a value indicating whether the given chunk is critical to decoding /// /// The segment handling behavior. - public bool IsCritical(SegmentErrorHandling handling) + public bool IsCritical(SegmentIntegrityHandling handling) => handling switch { - SegmentErrorHandling.IgnoreNone => true, - SegmentErrorHandling.IgnoreNonCritical => this.Type is PngChunkType.Header or PngChunkType.Palette or PngChunkType.Data or PngChunkType.FrameData, - SegmentErrorHandling.IgnoreData => this.Type is PngChunkType.Header or PngChunkType.Palette, + SegmentIntegrityHandling.IgnoreNone => true, + SegmentIntegrityHandling.IgnoreNonCritical => this.Type is PngChunkType.Header or PngChunkType.Palette or PngChunkType.Data or PngChunkType.FrameData, + SegmentIntegrityHandling.IgnoreData => this.Type is PngChunkType.Header or PngChunkType.Palette, _ => false, }; } diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index 080c35c0d1..484241d52f 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -119,7 +119,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore /// /// How to handle CRC errors. /// - private readonly SegmentErrorHandling segmentErrorHandling; + private readonly SegmentIntegrityHandling segmentIntegrityHandling; /// /// A reusable Crc32 hashing instance. @@ -142,7 +142,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore this.maxFrames = options.GeneralOptions.MaxFrames; this.skipMetadata = options.GeneralOptions.SkipMetadata; this.memoryAllocator = this.configuration.MemoryAllocator; - this.segmentErrorHandling = options.GeneralOptions.SegmentErrorHandling; + this.segmentIntegrityHandling = options.GeneralOptions.SegmentIntegrityHandling; this.maxUncompressedLength = options.MaxUncompressedAncillaryChunkSizeBytes; } @@ -154,7 +154,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore this.skipMetadata = true; this.configuration = options.GeneralOptions.Configuration; this.memoryAllocator = this.configuration.MemoryAllocator; - this.segmentErrorHandling = options.GeneralOptions.SegmentErrorHandling; + this.segmentIntegrityHandling = options.GeneralOptions.SegmentIntegrityHandling; this.maxUncompressedLength = options.MaxUncompressedAncillaryChunkSizeBytes; } @@ -833,7 +833,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore break; default: - if (this.segmentErrorHandling is SegmentErrorHandling.IgnoreData or SegmentErrorHandling.IgnoreAll) + if (this.segmentIntegrityHandling is SegmentIntegrityHandling.IgnoreData or SegmentIntegrityHandling.IgnoreAll) { goto EXIT; } @@ -939,7 +939,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore break; default: - if (this.segmentErrorHandling is SegmentErrorHandling.IgnoreData or SegmentErrorHandling.IgnoreAll) + if (this.segmentIntegrityHandling is SegmentIntegrityHandling.IgnoreData or SegmentIntegrityHandling.IgnoreAll) { goto EXIT; } @@ -1927,7 +1927,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore private void ValidateChunk(in PngChunk chunk, Span buffer) { uint inputCrc = this.ReadChunkCrc(buffer); - if (chunk.IsCritical(this.segmentErrorHandling)) + if (chunk.IsCritical(this.segmentIntegrityHandling)) { Span chunkType = stackalloc byte[4]; BinaryPrimitives.WriteUInt32BigEndian(chunkType, (uint)chunk.Type); diff --git a/src/ImageSharp/Formats/SegmentErrorHandling.cs b/src/ImageSharp/Formats/SegmentIntegrityHandling.cs similarity index 94% rename from src/ImageSharp/Formats/SegmentErrorHandling.cs rename to src/ImageSharp/Formats/SegmentIntegrityHandling.cs index 7b28de5895..977aee4ad5 100644 --- a/src/ImageSharp/Formats/SegmentErrorHandling.cs +++ b/src/ImageSharp/Formats/SegmentIntegrityHandling.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Formats; /// /// Specifies how to handle validation of errors in different segments of encoded image files. /// -public enum SegmentErrorHandling +public enum SegmentIntegrityHandling { /// /// Do not ignore any errors. diff --git a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs index c3a6b11f5a..9f3c5f6828 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs @@ -389,7 +389,7 @@ public partial class PngDecoderTests TestFile testFile = TestFile.Create(imagePath); using MemoryStream stream = new(testFile.Bytes, false); - ImageInfo imageInfo = Image.Identify(new DecoderOptions() { SegmentErrorHandling = SegmentErrorHandling.IgnoreData }, stream); + ImageInfo imageInfo = Image.Identify(new DecoderOptions() { SegmentIntegrityHandling = SegmentIntegrityHandling.IgnoreData }, stream); Assert.NotNull(imageInfo); Assert.Equal(expectedPixelSize, imageInfo.PixelType.BitsPerPixel); @@ -493,7 +493,7 @@ public partial class PngDecoderTests public void Decode_InvalidDataChunkCrc_IgnoreCrcErrors(TestImageProvider provider, bool compare) where TPixel : unmanaged, IPixel { - using Image image = provider.GetImage(PngDecoder.Instance, new DecoderOptions() { SegmentErrorHandling = SegmentErrorHandling.IgnoreData }); + using Image image = provider.GetImage(PngDecoder.Instance, new DecoderOptions() { SegmentIntegrityHandling = SegmentIntegrityHandling.IgnoreData }); image.DebugSave(provider); if (compare) @@ -674,7 +674,7 @@ public partial class PngDecoderTests public void Binary_PrematureEof() { PngDecoder decoder = PngDecoder.Instance; - PngDecoderOptions options = new() { GeneralOptions = new() { SegmentErrorHandling = SegmentErrorHandling.IgnoreData } }; + PngDecoderOptions options = new() { GeneralOptions = new() { SegmentIntegrityHandling = SegmentIntegrityHandling.IgnoreData } }; using EofHitCounter eofHitCounter = EofHitCounter.RunDecoder(TestImages.Png.Bad.FlagOfGermany0000016446, decoder, options); // TODO: Try to reduce this to 1.