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/> /// <inheritdoc/>
public Buffer2D<TPixel> PixelBuffer { get; private set; } public Buffer2D<TPixel> PixelBuffer { get; }
/// <summary> /// <summary>
/// Gets or sets the pixel at the specified position. /// 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. /// Copies the pixels to a <see cref="Buffer2D{TPixel}"/> of the same size.
/// </summary> /// </summary>
/// <param name="target">The target pixel buffer accessor.</param> /// <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) internal void CopyTo(Buffer2D<TPixel> target)
{ {
if (this.Size() != target.Size()) if (this.Size() != target.Size())
@ -445,14 +446,12 @@ public sealed class ImageFrame<TPixel> : ImageFrame, IPixelSource<TPixel>
} }
[MethodImpl(InliningOptions.ColdPath)] [MethodImpl(InliningOptions.ColdPath)]
private static void ThrowArgumentOutOfRangeException(string paramName) private static void ThrowArgumentOutOfRangeException(string paramName) => throw new ArgumentOutOfRangeException(paramName);
{
throw new ArgumentOutOfRangeException(paramName);
}
/// <summary> /// <summary>
/// A <see langword="struct"/> implementing the clone logic for <see cref="ImageFrame{TPixel}"/>. /// A <see langword="struct"/> implementing the clone logic for <see cref="ImageFrame{TPixel}"/>.
/// </summary> /// </summary>
/// <typeparam name="TPixel2">The type of the target pixel format.</typeparam>
private readonly struct RowIntervalOperation<TPixel2> : IRowIntervalOperation private readonly struct RowIntervalOperation<TPixel2> : IRowIntervalOperation
where TPixel2 : unmanaged, IPixel<TPixel2> 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 public sealed class IndexedImageFrame<TPixel> : IPixelSource, IDisposable
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
private Buffer2D<byte> pixelBuffer; private readonly Buffer2D<byte> pixelBuffer;
private IMemoryOwner<TPixel> paletteOwner; private readonly IMemoryOwner<TPixel> paletteOwner;
private bool isDisposed; private bool isDisposed;
/// <summary> /// <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="ArgumentNullException">The operation is null.</exception>
/// <exception cref="ObjectDisposedException">The source has been disposed.</exception> /// <exception cref="ObjectDisposedException">The source has been disposed.</exception>
/// <exception cref="ImageProcessingException">The processing operation failed.</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); => Clone(source, source.GetConfiguration(), operation);
/// <summary> /// <summary>
@ -149,7 +149,7 @@ public static partial class ProcessingExtensions
/// <exception cref="ObjectDisposedException">The source has been disposed.</exception> /// <exception cref="ObjectDisposedException">The source has been disposed.</exception>
/// <exception cref="ImageProcessingException">The processing operation failed.</exception> /// <exception cref="ImageProcessingException">The processing operation failed.</exception>
/// <returns>The new <see cref="Image"/>.</returns> /// <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(configuration, nameof(configuration));
Guard.NotNull(source, nameof(source)); Guard.NotNull(source, nameof(source));
@ -158,7 +158,7 @@ public static partial class ProcessingExtensions
ProcessingVisitor visitor = new(configuration, operation, false); ProcessingVisitor visitor = new(configuration, operation, false);
source.AcceptVisitor(visitor); source.AcceptVisitor(visitor);
return visitor.ResultImage; return visitor.GetResultImage();
} }
/// <summary> /// <summary>
@ -274,6 +274,8 @@ public static partial class ProcessingExtensions
private readonly bool mutate; private readonly bool mutate;
private Image? resultImage;
public ProcessingVisitor(Configuration configuration, Action<IImageProcessingContext> operation, bool mutate) public ProcessingVisitor(Configuration configuration, Action<IImageProcessingContext> operation, bool mutate)
{ {
this.configuration = configuration; this.configuration = configuration;
@ -281,7 +283,7 @@ public static partial class ProcessingExtensions
this.mutate = mutate; this.mutate = mutate;
} }
public Image? ResultImage { get; private set; } public Image GetResultImage() => this.resultImage!;
public void Visit<TPixel>(Image<TPixel> image) public void Visit<TPixel>(Image<TPixel> image)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
@ -290,7 +292,7 @@ public static partial class ProcessingExtensions
this.configuration.ImageOperationsProvider.CreateImageProcessingContext(this.configuration, image, this.mutate); this.configuration.ImageOperationsProvider.CreateImageProcessingContext(this.configuration, image, this.mutate);
this.operation(operationsRunner); 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> /// </summary>
public class ProjectiveTransformBuilder public class ProjectiveTransformBuilder
{ {
private readonly List<Func<Size, Matrix4x4>> matrixFactories = new List<Func<Size, Matrix4x4>>(); private readonly List<Func<Size, Matrix4x4>> matrixFactories = new();
/// <summary> /// <summary>
/// Prepends a matrix that performs a tapering projective transform. /// Prepends a matrix that performs a tapering projective transform.
@ -313,7 +313,7 @@ public class ProjectiveTransformBuilder
Guard.MustBeGreaterThan(sourceRectangle.Height, 0, nameof(sourceRectangle)); Guard.MustBeGreaterThan(sourceRectangle.Height, 0, nameof(sourceRectangle));
// Translate the origin matrix to cater for source rectangle offsets. // 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; Size size = sourceRectangle.Size;

Loading…
Cancel
Save