Browse Source

Rename

pull/2786/head
James Jackson-South 2 years ago
parent
commit
4a6b51bc28
  1. 2
      src/ImageSharp/Formats/DecoderOptions.cs
  2. 8
      src/ImageSharp/Formats/Png/PngChunk.cs
  3. 12
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  4. 2
      src/ImageSharp/Formats/SegmentIntegrityHandling.cs
  5. 6
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs

2
src/ImageSharp/Formats/DecoderOptions.cs

@ -58,7 +58,7 @@ public sealed class DecoderOptions
/// <summary>
/// Gets the segment error handling strategy to use during decoding.
/// </summary>
public SegmentErrorHandling SegmentErrorHandling { get; init; } = SegmentErrorHandling.IgnoreNonCritical;
public SegmentIntegrityHandling SegmentIntegrityHandling { get; init; } = SegmentIntegrityHandling.IgnoreNonCritical;
internal void SetConfiguration(Configuration configuration) => this.configuration = configuration;
}

8
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
/// </summary>
/// <param name="handling">The segment handling behavior.</param>
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,
};
}

12
src/ImageSharp/Formats/Png/PngDecoderCore.cs

@ -119,7 +119,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore
/// <summary>
/// How to handle CRC errors.
/// </summary>
private readonly SegmentErrorHandling segmentErrorHandling;
private readonly SegmentIntegrityHandling segmentIntegrityHandling;
/// <summary>
/// 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<byte> buffer)
{
uint inputCrc = this.ReadChunkCrc(buffer);
if (chunk.IsCritical(this.segmentErrorHandling))
if (chunk.IsCritical(this.segmentIntegrityHandling))
{
Span<byte> chunkType = stackalloc byte[4];
BinaryPrimitives.WriteUInt32BigEndian(chunkType, (uint)chunk.Type);

2
src/ImageSharp/Formats/SegmentErrorHandling.cs → src/ImageSharp/Formats/SegmentIntegrityHandling.cs

@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Formats;
/// <summary>
/// Specifies how to handle validation of errors in different segments of encoded image files.
/// </summary>
public enum SegmentErrorHandling
public enum SegmentIntegrityHandling
{
/// <summary>
/// Do not ignore any errors.

6
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<TPixel>(TestImageProvider<TPixel> provider, bool compare)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance, new DecoderOptions() { SegmentErrorHandling = SegmentErrorHandling.IgnoreData });
using Image<TPixel> 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.

Loading…
Cancel
Save