Browse Source

Minor cleanup

pull/2353/head
James Jackson-South 3 years ago
parent
commit
a04526ff88
  1. 9
      src/ImageSharp/ImageFrame{TPixel}.cs
  2. 4
      src/ImageSharp/IndexedImageFrame{TPixel}.cs
  3. 12
      src/ImageSharp/Processing/Extensions/ProcessingExtensions.cs
  4. 4
      src/ImageSharp/Processing/ProjectiveTransformBuilder.cs

9
src/ImageSharp/ImageFrame{TPixel}.cs

@ -144,7 +144,7 @@ public sealed class ImageFrame<TPixel> : ImageFrame, IPixelSource<TPixel>
}
/// <inheritdoc/>
public Buffer2D<TPixel> PixelBuffer { get; private set; }
public Buffer2D<TPixel> PixelBuffer { get; }
/// <summary>
/// Gets or sets the pixel at the specified position.
@ -309,6 +309,7 @@ public sealed class ImageFrame<TPixel> : ImageFrame, IPixelSource<TPixel>
/// Copies the pixels to a <see cref="Buffer2D{TPixel}"/> of the same size.
/// </summary>
/// <param name="target">The target pixel buffer accessor.</param>
/// <exception cref="ArgumentException">ImageFrame{TPixel}.CopyTo(): target must be of the same size!</exception>
internal void CopyTo(Buffer2D<TPixel> target)
{
if (this.Size() != target.Size())
@ -445,14 +446,12 @@ public sealed class ImageFrame<TPixel> : ImageFrame, IPixelSource<TPixel>
}
[MethodImpl(InliningOptions.ColdPath)]
private static void ThrowArgumentOutOfRangeException(string paramName)
{
throw new ArgumentOutOfRangeException(paramName);
}
private static void ThrowArgumentOutOfRangeException(string paramName) => throw new ArgumentOutOfRangeException(paramName);
/// <summary>
/// A <see langword="struct"/> implementing the clone logic for <see cref="ImageFrame{TPixel}"/>.
/// </summary>
/// <typeparam name="TPixel2">The type of the target pixel format.</typeparam>
private readonly struct RowIntervalOperation<TPixel2> : IRowIntervalOperation
where TPixel2 : unmanaged, IPixel<TPixel2>
{

4
src/ImageSharp/IndexedImageFrame{TPixel}.cs

@ -17,8 +17,8 @@ namespace SixLabors.ImageSharp;
public sealed class IndexedImageFrame<TPixel> : IPixelSource, IDisposable
where TPixel : unmanaged, IPixel<TPixel>
{
private Buffer2D<byte> pixelBuffer;
private IMemoryOwner<TPixel> paletteOwner;
private readonly Buffer2D<byte> pixelBuffer;
private readonly IMemoryOwner<TPixel> paletteOwner;
private bool isDisposed;
/// <summary>

12
src/ImageSharp/Processing/Extensions/ProcessingExtensions.cs

@ -134,7 +134,7 @@ public static partial class ProcessingExtensions
/// <exception cref="ArgumentNullException">The operation is null.</exception>
/// <exception cref="ObjectDisposedException">The source has been disposed.</exception>
/// <exception cref="ImageProcessingException">The processing operation failed.</exception>
public static Image? Clone(this Image source, Action<IImageProcessingContext> operation)
public static Image Clone(this Image source, Action<IImageProcessingContext> operation)
=> Clone(source, source.GetConfiguration(), operation);
/// <summary>
@ -149,7 +149,7 @@ public static partial class ProcessingExtensions
/// <exception cref="ObjectDisposedException">The source has been disposed.</exception>
/// <exception cref="ImageProcessingException">The processing operation failed.</exception>
/// <returns>The new <see cref="Image"/>.</returns>
public static Image? Clone(this Image source, Configuration configuration, Action<IImageProcessingContext> operation)
public static Image Clone(this Image source, Configuration configuration, Action<IImageProcessingContext> operation)
{
Guard.NotNull(configuration, nameof(configuration));
Guard.NotNull(source, nameof(source));
@ -158,7 +158,7 @@ public static partial class ProcessingExtensions
ProcessingVisitor visitor = new(configuration, operation, false);
source.AcceptVisitor(visitor);
return visitor.ResultImage;
return visitor.GetResultImage();
}
/// <summary>
@ -274,6 +274,8 @@ public static partial class ProcessingExtensions
private readonly bool mutate;
private Image? resultImage;
public ProcessingVisitor(Configuration configuration, Action<IImageProcessingContext> operation, bool mutate)
{
this.configuration = configuration;
@ -281,7 +283,7 @@ public static partial class ProcessingExtensions
this.mutate = mutate;
}
public Image? ResultImage { get; private set; }
public Image GetResultImage() => this.resultImage!;
public void Visit<TPixel>(Image<TPixel> image)
where TPixel : unmanaged, IPixel<TPixel>
@ -290,7 +292,7 @@ public static partial class ProcessingExtensions
this.configuration.ImageOperationsProvider.CreateImageProcessingContext(this.configuration, image, this.mutate);
this.operation(operationsRunner);
this.ResultImage = operationsRunner.GetResultImage();
this.resultImage = operationsRunner.GetResultImage();
}
}
}

4
src/ImageSharp/Processing/ProjectiveTransformBuilder.cs

@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Processing;
/// </summary>
public class ProjectiveTransformBuilder
{
private readonly List<Func<Size, Matrix4x4>> matrixFactories = new List<Func<Size, Matrix4x4>>();
private readonly List<Func<Size, Matrix4x4>> matrixFactories = new();
/// <summary>
/// Prepends a matrix that performs a tapering projective transform.
@ -313,7 +313,7 @@ public class ProjectiveTransformBuilder
Guard.MustBeGreaterThan(sourceRectangle.Height, 0, nameof(sourceRectangle));
// Translate the origin matrix to cater for source rectangle offsets.
var matrix = Matrix4x4.CreateTranslation(new Vector3(-sourceRectangle.Location, 0));
Matrix4x4 matrix = Matrix4x4.CreateTranslation(new Vector3(-sourceRectangle.Location, 0));
Size size = sourceRectangle.Size;

Loading…
Cancel
Save