Browse Source

Make decoder options init only (except Configuration cos tests)

pull/2301/head
James Jackson-South 4 years ago
parent
commit
5726089a7c
  1. 6
      src/ImageSharp/Formats/Bmp/BmpDecoderOptions.cs
  2. 20
      src/ImageSharp/Formats/DecoderOptions.cs
  3. 4
      src/ImageSharp/Formats/ISpecializedDecoderOptions.cs
  4. 10
      src/ImageSharp/Formats/Jpeg/JpegDecoderOptions.cs
  5. 3
      tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpegParseStreamOnly.cs
  6. 2
      tests/ImageSharp.Tests/TestFormat.cs
  7. 8
      tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs

6
src/ImageSharp/Formats/Bmp/BmpDecoderOptions.cs

@ -9,11 +9,11 @@ namespace SixLabors.ImageSharp.Formats.Bmp;
public sealed class BmpDecoderOptions : ISpecializedDecoderOptions public sealed class BmpDecoderOptions : ISpecializedDecoderOptions
{ {
/// <inheritdoc/> /// <inheritdoc/>
public DecoderOptions GeneralOptions { get; set; } = new(); public DecoderOptions GeneralOptions { get; init; } = DecoderOptions.Default;
/// <summary> /// <summary>
/// Gets or sets the value indicating how to deal with skipped pixels, /// Gets the value indicating how to deal with skipped pixels,
/// which can occur during decoding run length encoded bitmaps. /// which can occur during decoding run length encoded bitmaps.
/// </summary> /// </summary>
public RleSkippedPixelHandling RleSkippedPixelHandling { get; set; } public RleSkippedPixelHandling RleSkippedPixelHandling { get; init; }
} }

20
src/ImageSharp/Formats/DecoderOptions.cs

@ -21,27 +21,27 @@ public sealed class DecoderOptions
internal static DecoderOptions Default { get; } = LazyOptions.Value; internal static DecoderOptions Default { get; } = LazyOptions.Value;
/// <summary> /// <summary>
/// Gets or sets a custom Configuration instance to be used by the image processing pipeline. /// Gets a custom configuration instance to be used by the image processing pipeline.
/// </summary> /// </summary>
public Configuration Configuration { get; set; } = Configuration.Default; public Configuration Configuration { get; internal set; } = Configuration.Default;
/// <summary> /// <summary>
/// Gets or sets the target size to decode the image into. /// Gets the target size to decode the image into.
/// </summary> /// </summary>
public Size? TargetSize { get; set; } public Size? TargetSize { get; init; }
/// <summary> /// <summary>
/// Gets or sets the sampler to use when resizing during decoding. /// Gets the sampler to use when resizing during decoding.
/// </summary> /// </summary>
public IResampler Sampler { get; set; } = KnownResamplers.Box; public IResampler Sampler { get; init; } = KnownResamplers.Box;
/// <summary> /// <summary>
/// Gets or sets a value indicating whether to ignore encoded metadata when decoding. /// Gets a value indicating whether to ignore encoded metadata when decoding.
/// </summary> /// </summary>
public bool SkipMetadata { get; set; } public bool SkipMetadata { get; init; }
/// <summary> /// <summary>
/// Gets or sets the maximum number of image frames to decode, inclusive. /// Gets the maximum number of image frames to decode, inclusive.
/// </summary> /// </summary>
public uint MaxFrames { get => this.maxFrames; set => this.maxFrames = Math.Clamp(value, 1, int.MaxValue); } public uint MaxFrames { get => this.maxFrames; init => this.maxFrames = Math.Clamp(value, 1, int.MaxValue); }
} }

4
src/ImageSharp/Formats/ISpecializedDecoderOptions.cs

@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Formats;
public interface ISpecializedDecoderOptions public interface ISpecializedDecoderOptions
{ {
/// <summary> /// <summary>
/// Gets or sets the general decoder options. /// Gets the general decoder options.
/// </summary> /// </summary>
DecoderOptions GeneralOptions { get; set; } DecoderOptions GeneralOptions { get; init; }
} }

10
src/ImageSharp/Formats/Jpeg/JpegDecoderOptions.cs

@ -8,11 +8,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg;
/// </summary> /// </summary>
public sealed class JpegDecoderOptions : ISpecializedDecoderOptions public sealed class JpegDecoderOptions : ISpecializedDecoderOptions
{ {
/// <inheritdoc/>
public DecoderOptions GeneralOptions { get; init; } = DecoderOptions.Default;
/// <summary> /// <summary>
/// Gets or sets the resize mode. /// Gets the resize mode.
/// </summary> /// </summary>
public JpegDecoderResizeMode ResizeMode { get; set; } public JpegDecoderResizeMode ResizeMode { get; init; }
/// <inheritdoc/>
public DecoderOptions GeneralOptions { get; set; } = new();
} }

3
tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpegParseStreamOnly.cs

@ -37,8 +37,7 @@ public class DecodeJpegParseStreamOnly
{ {
using var memoryStream = new MemoryStream(this.jpegBytes); using var memoryStream = new MemoryStream(this.jpegBytes);
using var bufferedStream = new BufferedReadStream(Configuration.Default, memoryStream); using var bufferedStream = new BufferedReadStream(Configuration.Default, memoryStream);
var options = new JpegDecoderOptions(); var options = new JpegDecoderOptions() { GeneralOptions = new() { SkipMetadata = true } };
options.GeneralOptions.SkipMetadata = true;
using var decoder = new JpegDecoderCore(options); using var decoder = new JpegDecoderCore(options);
var spectralConverter = new NoopSpectralConverter(); var spectralConverter = new NoopSpectralConverter();

2
tests/ImageSharp.Tests/TestFormat.cs

@ -230,7 +230,7 @@ public class TestFormat : IConfigurationModule, IImageFormat
public class TestDecoderOptions : ISpecializedDecoderOptions public class TestDecoderOptions : ISpecializedDecoderOptions
{ {
public DecoderOptions GeneralOptions { get; set; } = new(); public DecoderOptions GeneralOptions { get; init; } = DecoderOptions.Default;
} }
public class TestEncoder : ImageEncoder public class TestEncoder : ImageEncoder

8
tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs

@ -429,15 +429,15 @@ public class TestImageProviderTests
private class TestDecoderOptions : ISpecializedDecoderOptions private class TestDecoderOptions : ISpecializedDecoderOptions
{ {
public DecoderOptions GeneralOptions { get; set; } = new(); public DecoderOptions GeneralOptions { get; init; } = DecoderOptions.Default;
} }
private class TestDecoderWithParametersOptions : ISpecializedDecoderOptions private class TestDecoderWithParametersOptions : ISpecializedDecoderOptions
{ {
public string Param1 { get; set; } public string Param1 { get; init; }
public int Param2 { get; set; } public int Param2 { get; init; }
public DecoderOptions GeneralOptions { get; set; } = new(); public DecoderOptions GeneralOptions { get; init; } = DecoderOptions.Default;
} }
} }

Loading…
Cancel
Save