Browse Source

Remove IImageInfo, IImage and use inheritance.

pull/2317/head
James Jackson-South 3 years ago
parent
commit
96a22c40ad
  1. 18
      src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
  2. 4
      src/ImageSharp/Formats/Gif/GifEncoderCore.cs
  3. 2
      src/ImageSharp/Formats/ImageDecoder.cs
  4. 2
      src/ImageSharp/Formats/Pbm/PbmEncoderCore.cs
  5. 2
      src/ImageSharp/Formats/Png/PngEncoderCore.cs
  6. 11
      src/ImageSharp/IImage.cs
  7. 34
      src/ImageSharp/IImageInfo.cs
  8. 32
      src/ImageSharp/Image.cs
  9. 56
      src/ImageSharp/ImageInfo.cs
  10. 24
      src/ImageSharp/ImageInfoExtensions.cs
  11. 2
      src/ImageSharp/Image{TPixel}.cs
  12. 2
      src/ImageSharp/Processing/DefaultImageProcessorContext{TPixel}.cs
  13. 2
      src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs
  14. 38
      src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor{TPixel}.cs
  15. 2
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs
  16. 4
      tests/ImageSharp.Benchmarks/Codecs/Png/DecodeFilteredPng.cs
  17. 17
      tests/ImageSharp.Benchmarks/Codecs/Png/DecodePng.cs
  18. 16
      tests/ImageSharp.Benchmarks/Codecs/Tiff/DecodeTiff.cs
  19. 8
      tests/ImageSharp.Benchmarks/Processing/Diffuse.cs
  20. 4
      tests/ImageSharp.Benchmarks/Processing/Rotate.cs
  21. 4
      tests/ImageSharp.Benchmarks/Processing/Skew.cs
  22. 12
      tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs
  23. 2
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Metadata.cs
  24. 12
      tests/ImageSharp.Tests/Image/ImageRotationTests.cs
  25. 10
      tests/ImageSharp.Tests/Image/ImageTests.Identify.cs
  26. 12
      tests/ImageSharp.Tests/Image/ImageTests.ImageLoadTestBase.cs
  27. 2
      tests/ImageSharp.Tests/Image/ImageTests.Load_FileSystemPath_UseDefaultConfiguration.cs
  28. 2
      tests/ImageSharp.Tests/Image/ImageTests.Load_FromBytes_UseGlobalConfiguration.cs
  29. 2
      tests/ImageSharp.Tests/Image/ImageTests.Load_FromStream_UseDefaultConfiguration.cs
  30. 24
      tests/ImageSharp.Tests/ImageInfoTests.cs
  31. 2
      tests/ImageSharp.Tests/Processing/BaseImageOperationsExtensionTest.cs
  32. 2
      tests/ImageSharp.Tests/Processing/FakeImageOperationsProvider.cs
  33. 33
      tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs
  34. 2
      tests/ImageSharp.Tests/Processing/Processors/Transforms/AffineTransformTests.cs
  35. 8
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs
  36. 2
      tests/ImageSharp.Tests/ProfilingBenchmarks/LoadResizeSaveProfilingBenchmarks.cs
  37. 8
      tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs

18
src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs

@ -215,15 +215,15 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals
BmpInfoHeader infoHeader = new(
headerSize: infoHeaderSize,
height: height,
width: width,
bitsPerPixel: bpp,
height: height,
planes: 1,
bitsPerPixel: bpp,
imageSize: height * bytesPerLine,
clrUsed: 0,
clrImportant: 0,
xPelsPerMeter: hResolution,
yPelsPerMeter: vResolution);
yPelsPerMeter: vResolution,
clrUsed: 0,
clrImportant: 0);
if ((this.infoHeaderType is BmpInfoHeaderType.WinVersion4 or BmpInfoHeaderType.WinVersion5) && this.bitsPerPixel == BmpBitsPerPixel.Pixel32)
{
@ -470,7 +470,7 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals
using IQuantizer<TPixel> frameQuantizer = this.quantizer.CreatePixelSpecificQuantizer<TPixel>(this.configuration);
frameQuantizer.BuildPalette(this.pixelSamplingStrategy, image);
using IndexedImageFrame<TPixel> quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds());
using IndexedImageFrame<TPixel> quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds);
ReadOnlySpan<TPixel> quantizedColorPalette = quantized.Palette.Span;
this.WriteColorPalette(stream, quantizedColorPalette, colorPalette);
@ -541,7 +541,7 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals
frameQuantizer.BuildPalette(this.pixelSamplingStrategy, image);
using IndexedImageFrame<TPixel> quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds());
using IndexedImageFrame<TPixel> quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds);
using IMemoryOwner<byte> colorPaletteBuffer = this.memoryAllocator.Allocate<byte>(ColorPaletteSize4Bit, AllocationOptions.Clean);
Span<byte> colorPalette = colorPaletteBuffer.GetSpan();
@ -588,7 +588,7 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals
frameQuantizer.BuildPalette(this.pixelSamplingStrategy, image);
using IndexedImageFrame<TPixel> quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds());
using IndexedImageFrame<TPixel> quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds);
using IMemoryOwner<byte> colorPaletteBuffer = this.memoryAllocator.Allocate<byte>(ColorPaletteSize2Bit, AllocationOptions.Clean);
Span<byte> colorPalette = colorPaletteBuffer.GetSpan();
@ -644,7 +644,7 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals
frameQuantizer.BuildPalette(this.pixelSamplingStrategy, image);
using IndexedImageFrame<TPixel> quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds());
using IndexedImageFrame<TPixel> quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds);
using IMemoryOwner<byte> colorPaletteBuffer = this.memoryAllocator.Allocate<byte>(ColorPaletteSize1Bit, AllocationOptions.Clean);
Span<byte> colorPalette = colorPaletteBuffer.GetSpan();

4
src/ImageSharp/Formats/Gif/GifEncoderCore.cs

@ -99,12 +99,12 @@ internal sealed class GifEncoderCore : IImageEncoderInternals
if (useGlobalTable)
{
frameQuantizer.BuildPalette(this.pixelSamplingStrategy, image);
quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds());
quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds);
}
else
{
frameQuantizer.BuildPalette(this.pixelSamplingStrategy, image.Frames.RootFrame);
quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds());
quantized = frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds);
}
}

2
src/ImageSharp/Formats/ImageDecoder.cs

@ -172,7 +172,7 @@ public abstract class ImageDecoder : IImageDecoder
}
Size targetSize = options.TargetSize.Value;
Size currentSize = image.Size();
Size currentSize = image.Size;
return currentSize.Width != targetSize.Width && currentSize.Height != targetSize.Height;
}

2
src/ImageSharp/Formats/Pbm/PbmEncoderCore.cs

@ -68,7 +68,7 @@ internal sealed class PbmEncoderCore : IImageEncoderInternals
this.SanitizeAndSetEncoderOptions(image);
byte signature = this.DeduceSignature();
this.WriteHeader(stream, signature, image.Size());
this.WriteHeader(stream, signature, image.Size);
this.WritePixels(stream, image.Frames.RootFrame);

2
src/ImageSharp/Formats/Png/PngEncoderCore.cs

@ -1300,7 +1300,7 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable
using IQuantizer<TPixel> frameQuantizer = quantizer.CreatePixelSpecificQuantizer<TPixel>(image.GetConfiguration());
frameQuantizer.BuildPalette(encoder.PixelSamplingStrategy, image);
return frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds());
return frameQuantizer.QuantizeFrame(image.Frames.RootFrame, image.Bounds);
}
/// <summary>

11
src/ImageSharp/IImage.cs

@ -1,11 +0,0 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp;
/// <summary>
/// Encapsulates the properties and methods that describe an image.
/// </summary>
public interface IImage : IImageInfo, IDisposable
{
}

34
src/ImageSharp/IImageInfo.cs

@ -1,34 +0,0 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Metadata;
namespace SixLabors.ImageSharp;
/// <summary>
/// Encapsulates properties that describe basic image information including dimensions, pixel type information
/// and additional metadata.
/// </summary>
public interface IImageInfo
{
/// <summary>
/// Gets information about the image pixels.
/// </summary>
PixelTypeInfo PixelType { get; }
/// <summary>
/// Gets the width.
/// </summary>
int Width { get; }
/// <summary>
/// Gets the height.
/// </summary>
int Height { get; }
/// <summary>
/// Gets the metadata of the image.
/// </summary>
ImageMetadata Metadata { get; }
}

32
src/ImageSharp/Image.cs

@ -14,11 +14,9 @@ namespace SixLabors.ImageSharp;
/// For the non-generic <see cref="Image"/> type, the pixel type is only known at runtime.
/// <see cref="Image"/> is always implemented by a pixel-specific <see cref="Image{TPixel}"/> instance.
/// </summary>
public abstract partial class Image : IImage, IConfigurationProvider
public abstract partial class Image : ImageInfo, IDisposable, IConfigurationProvider
{
private bool isDisposed;
private Size size;
private readonly Configuration configuration;
/// <summary>
@ -27,16 +25,12 @@ public abstract partial class Image : IImage, IConfigurationProvider
/// <param name="configuration">
/// The configuration which allows altering default behaviour or extending the library.
/// </param>
/// <param name="pixelType">The <see cref="PixelTypeInfo"/>.</param>
/// <param name="metadata">The <see cref="ImageMetadata"/>.</param>
/// <param name="size">The <see cref="size"/>.</param>
/// <param name="pixelType">The pixel type information.</param>
/// <param name="metadata">The image metadata.</param>
/// <param name="size">The size in px units.</param>
protected Image(Configuration configuration, PixelTypeInfo pixelType, ImageMetadata metadata, Size size)
{
this.configuration = configuration ?? Configuration.Default;
this.PixelType = pixelType;
this.size = size;
this.Metadata = metadata ?? new ImageMetadata();
}
: base(pixelType, size, metadata)
=> this.configuration = configuration ?? Configuration.Default;
/// <summary>
/// Initializes a new instance of the <see cref="Image"/> class.
@ -61,18 +55,6 @@ public abstract partial class Image : IImage, IConfigurationProvider
/// </summary>
protected abstract ImageFrameCollection NonGenericFrameCollection { get; }
/// <inheritdoc/>
public PixelTypeInfo PixelType { get; }
/// <inheritdoc />
public int Width => this.size.Width;
/// <inheritdoc />
public int Height => this.size.Height;
/// <inheritdoc/>
public ImageMetadata Metadata { get; }
/// <summary>
/// Gets the frames of the image as (non-generic) <see cref="ImageFrameCollection"/>.
/// </summary>
@ -148,7 +130,7 @@ public abstract partial class Image : IImage, IConfigurationProvider
/// Update the size of the image after mutation.
/// </summary>
/// <param name="size">The <see cref="Size"/>.</param>
protected void UpdateSize(Size size) => this.size = size;
protected void UpdateSize(Size size) => this.Size = size;
/// <summary>
/// Disposes the object and frees resources for the Garbage Collector.

56
src/ImageSharp/ImageInfo.cs

@ -9,32 +9,60 @@ namespace SixLabors.ImageSharp;
/// <summary>
/// Contains information about the image including dimensions, pixel type information and additional metadata
/// </summary>
public sealed class ImageInfo : IImageInfo
public class ImageInfo
{
/// <summary>
/// Initializes a new instance of the <see cref="ImageInfo"/> class.
/// </summary>
/// <param name="pixelType">The image pixel type information.</param>
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
/// <param name="metadata">The images metadata.</param>
/// <param name="pixelType">The pixel type information.</param>
/// <param name="width">The width of the image in px units.</param>
/// <param name="height">The height of the image in px units.</param>
/// <param name="metadata">The image metadata.</param>
public ImageInfo(PixelTypeInfo pixelType, int width, int height, ImageMetadata metadata)
: this(pixelType, new(width, height), metadata)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ImageInfo"/> class.
/// </summary>
/// <param name="pixelType">The pixel type information.</param>
/// <param name="size">The size of the image in px units.</param>
/// <param name="metadata">The image metadata.</param>
public ImageInfo(PixelTypeInfo pixelType, Size size, ImageMetadata metadata)
{
this.PixelType = pixelType;
this.Width = width;
this.Height = height;
this.Metadata = metadata;
this.Metadata = metadata ?? new ImageMetadata();
this.Size = size;
}
/// <inheritdoc />
/// <summary>
/// Gets information about the image pixels.
/// </summary>
public PixelTypeInfo PixelType { get; }
/// <inheritdoc />
public int Width { get; }
/// <summary>
/// Gets the image width in px units.
/// </summary>
public int Width => this.Size.Width;
/// <inheritdoc />
public int Height { get; }
/// <summary>
/// Gets the image height in px units.
/// </summary>
public int Height => this.Size.Height;
/// <inheritdoc />
/// <summary>
/// Gets any metadata associated wit The image.
/// </summary>
public ImageMetadata Metadata { get; }
/// <summary>
/// Gets the size of the image in px units.
/// </summary>
public Size Size { get; internal set; }
/// <summary>
/// Gets the bounds of the image.
/// </summary>
public Rectangle Bounds => new(0, 0, this.Width, this.Height);
}

24
src/ImageSharp/ImageInfoExtensions.cs

@ -1,24 +0,0 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp;
/// <summary>
/// Extension methods that allow the addition of geometry calculating methods to the <see cref="IImageInfo"/> type
/// </summary>
public static class ImageInfoExtensions
{
/// <summary>
/// Gets the bounds of the image.
/// </summary>
/// <param name="info">The image info</param>
/// <returns>The <see cref="Size"/></returns>
public static Size Size(this IImageInfo info) => new(info.Width, info.Height);
/// <summary>
/// Gets the bounds of the image.
/// </summary>
/// <param name="info">The image info</param>
/// <returns>The <see cref="Rectangle"/></returns>
public static Rectangle Bounds(this IImageInfo info) => new(0, 0, info.Width, info.Height);
}

2
src/ImageSharp/Image{TPixel}.cs

@ -411,7 +411,7 @@ public sealed class Image<TPixel> : Image
this.frames[i].SwapOrCopyPixelsBufferFrom(sourceFrames[i]);
}
this.UpdateSize(pixelSource.Size());
this.UpdateSize(pixelSource.Size);
}
private static Size ValidateFramesAndGetSize(IEnumerable<ImageFrame<TPixel>> frames)

2
src/ImageSharp/Processing/DefaultImageProcessorContext{TPixel}.cs

@ -95,5 +95,5 @@ internal class DefaultImageProcessorContext<TPixel> : IInternalImageProcessingCo
return this;
}
private Rectangle GetCurrentBounds() => this.destination?.Bounds() ?? this.source.Bounds();
private Rectangle GetCurrentBounds() => this.destination?.Bounds ?? this.source.Bounds;
}

2
src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs

@ -78,7 +78,7 @@ internal class DrawImageProcessor<TPixelBg, TPixelFg> : ImageProcessor<TPixelBg>
int locationY = this.Location.Y;
// Align start/end positions.
Rectangle bounds = targetImage.Bounds();
Rectangle bounds = targetImage.Bounds;
int minX = Math.Max(this.Location.X, sourceRectangle.X);
int maxX = Math.Min(this.Location.X + bounds.Width, sourceRectangle.Right);

38
src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor{TPixel}.cs

@ -27,9 +27,7 @@ internal class EntropyCropProcessor<TPixel> : ImageProcessor<TPixel>
/// <param name="sourceRectangle">The source area to process for the current processor instance.</param>
public EntropyCropProcessor(Configuration configuration, EntropyCropProcessor definition, Image<TPixel> source, Rectangle sourceRectangle)
: base(configuration, source, sourceRectangle)
{
this.definition = definition;
}
=> this.definition = definition;
/// <inheritdoc/>
protected override void BeforeImageApply()
@ -38,7 +36,7 @@ internal class EntropyCropProcessor<TPixel> : ImageProcessor<TPixel>
// TODO: This is clunky. We should add behavior enum to ExtractFrame.
// All frames have be the same size so we only need to calculate the correct dimensions for the first frame
using (var temp = new Image<TPixel>(this.Configuration, this.Source.Metadata.DeepClone(), new[] { this.Source.Frames.RootFrame.Clone() }))
using (Image<TPixel> temp = new(this.Configuration, this.Source.Metadata.DeepClone(), new[] { this.Source.Frames.RootFrame.Clone() }))
{
Configuration configuration = this.Source.GetConfiguration();
@ -52,7 +50,7 @@ internal class EntropyCropProcessor<TPixel> : ImageProcessor<TPixel>
rectangle = GetFilteredBoundingRectangle(temp.Frames.RootFrame, 0);
}
new CropProcessor(rectangle, this.Source.Size()).Execute(this.Configuration, this.Source, this.SourceRectangle);
new CropProcessor(rectangle, this.Source.Size).Execute(this.Configuration, this.Source, this.SourceRectangle);
base.BeforeImageApply();
}
@ -77,7 +75,7 @@ internal class EntropyCropProcessor<TPixel> : ImageProcessor<TPixel>
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Rectangle GetBoundingRectangle(Point topLeft, Point bottomRight)
=> new Rectangle(
=> new(
topLeft.X,
topLeft.Y,
bottomRight.X - topLeft.X,
@ -99,29 +97,13 @@ internal class EntropyCropProcessor<TPixel> : ImageProcessor<TPixel>
int height = bitmap.Height;
Point topLeft = default;
Point bottomRight = default;
Func<ImageFrame<TPixel>, int, int, float, bool> delegateFunc;
// Determine which channel to check against
switch (channel)
Func<ImageFrame<TPixel>, int, int, float, bool> delegateFunc = channel switch
{
case RgbaComponent.R:
delegateFunc = (pixels, x, y, b) => MathF.Abs(pixels[x, y].ToVector4().X - b) > Constants.Epsilon;
break;
case RgbaComponent.G:
delegateFunc = (pixels, x, y, b) => MathF.Abs(pixels[x, y].ToVector4().Y - b) > Constants.Epsilon;
break;
case RgbaComponent.B:
delegateFunc = (pixels, x, y, b) => MathF.Abs(pixels[x, y].ToVector4().Z - b) > Constants.Epsilon;
break;
default:
delegateFunc = (pixels, x, y, b) => MathF.Abs(pixels[x, y].ToVector4().W - b) > Constants.Epsilon;
break;
}
RgbaComponent.R => (pixels, x, y, b) => MathF.Abs(pixels[x, y].ToVector4().X - b) > Constants.Epsilon,
RgbaComponent.G => (pixels, x, y, b) => MathF.Abs(pixels[x, y].ToVector4().Y - b) > Constants.Epsilon,
RgbaComponent.B => (pixels, x, y, b) => MathF.Abs(pixels[x, y].ToVector4().Z - b) > Constants.Epsilon,
_ => (pixels, x, y, b) => MathF.Abs(pixels[x, y].ToVector4().W - b) > Constants.Epsilon,
};
int GetMinY(ImageFrame<TPixel> pixels)
{
for (int y = 0; y < height; y++)

2
src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs

@ -82,7 +82,7 @@ internal class ResizeProcessor<TPixel> : TransformProcessor<TPixel>, IResampling
return;
}
var interest = Rectangle.Intersect(destinationRectangle, destination.Bounds());
var interest = Rectangle.Intersect(destinationRectangle, destination.Bounds);
if (sampler is NearestNeighborResampler)
{

4
tests/ImageSharp.Benchmarks/Codecs/Png/DecodeFilteredPng.cs

@ -56,8 +56,8 @@ public class DecodeFilteredPng
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Size LoadPng(byte[] bytes)
{
using var image = Image.Load<Rgba32>(bytes);
return image.Size();
using Image<Rgba32> image = Image.Load<Rgba32>(bytes);
return image.Size;
}
private static string TestImageFullPath(string path)

17
tests/ImageSharp.Benchmarks/Codecs/Png/DecodePng.cs

@ -22,26 +22,21 @@ public class DecodePng
[GlobalSetup]
public void ReadImages()
{
if (this.pngBytes == null)
{
this.pngBytes = File.ReadAllBytes(this.TestImageFullPath);
}
}
=> this.pngBytes ??= File.ReadAllBytes(this.TestImageFullPath);
[Benchmark(Baseline = true, Description = "System.Drawing Png")]
public SDSize PngSystemDrawing()
{
using var memoryStream = new MemoryStream(this.pngBytes);
using var image = SDImage.FromStream(memoryStream);
using MemoryStream memoryStream = new(this.pngBytes);
using SDImage image = SDImage.FromStream(memoryStream);
return image.Size;
}
[Benchmark(Description = "ImageSharp Png")]
public Size PngImageSharp()
{
using var memoryStream = new MemoryStream(this.pngBytes);
using var image = Image.Load<Rgba32>(memoryStream);
return image.Size();
using MemoryStream memoryStream = new(this.pngBytes);
using Image<Rgba32> image = Image.Load<Rgba32>(memoryStream);
return image.Size;
}
}

16
tests/ImageSharp.Benchmarks/Codecs/Tiff/DecodeTiff.cs

@ -69,20 +69,16 @@ public class DecodeTiff
[Benchmark(Baseline = true, Description = "System.Drawing Tiff")]
public SDSize TiffSystemDrawing()
{
using (var memoryStream = new MemoryStream(this.data))
using (var image = SDImage.FromStream(memoryStream))
{
return image.Size;
}
using MemoryStream memoryStream = new(this.data);
using SDImage image = SDImage.FromStream(memoryStream);
return image.Size;
}
[Benchmark(Description = "ImageSharp Tiff")]
public Size TiffCore()
{
using (var ms = new MemoryStream(this.data))
using (var image = Image.Load<Rgba32>(ms))
{
return image.Size();
}
using MemoryStream ms = new(this.data);
using Image<Rgba32> image = Image.Load<Rgba32>(ms);
return image.Size;
}
}

8
tests/ImageSharp.Benchmarks/Processing/Diffuse.cs

@ -13,19 +13,19 @@ public class Diffuse
[Benchmark]
public Size DoDiffuse()
{
using var image = new Image<Rgba32>(Configuration.Default, 800, 800, Color.BlanchedAlmond);
using Image<Rgba32> image = new(Configuration.Default, 800, 800, Color.BlanchedAlmond);
image.Mutate(x => x.Dither(KnownDitherings.FloydSteinberg));
return image.Size();
return image.Size;
}
[Benchmark]
public Size DoDither()
{
using var image = new Image<Rgba32>(Configuration.Default, 800, 800, Color.BlanchedAlmond);
using Image<Rgba32> image = new(Configuration.Default, 800, 800, Color.BlanchedAlmond);
image.Mutate(x => x.Dither());
return image.Size();
return image.Size;
}
}

4
tests/ImageSharp.Benchmarks/Processing/Rotate.cs

@ -13,10 +13,10 @@ public class Rotate
[Benchmark]
public Size DoRotate()
{
using var image = new Image<Rgba32>(Configuration.Default, 400, 400, Color.BlanchedAlmond);
using Image<Rgba32> image = new(Configuration.Default, 400, 400, Color.BlanchedAlmond);
image.Mutate(x => x.Rotate(37.5F));
return image.Size();
return image.Size;
}
}

4
tests/ImageSharp.Benchmarks/Processing/Skew.cs

@ -13,10 +13,10 @@ public class Skew
[Benchmark]
public Size DoSkew()
{
using var image = new Image<Rgba32>(Configuration.Default, 400, 400, Color.BlanchedAlmond);
using Image<Rgba32> image = new(Configuration.Default, 400, 400, Color.BlanchedAlmond);
image.Mutate(x => x.Skew(20, 10));
return image.Size();
return image.Size;
}
}

12
tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs

@ -30,7 +30,7 @@ public class AdvancedImageExtensionsTests
IMemoryGroup<TPixel> memoryGroup = image.GetPixelMemoryGroup();
// Assert:
VerifyMemoryGroupDataMatchesTestPattern(provider, memoryGroup, image.Size());
VerifyMemoryGroupDataMatchesTestPattern(provider, memoryGroup, image.Size);
}
[Theory]
@ -57,23 +57,23 @@ public class AdvancedImageExtensionsTests
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image0 = provider.GetImage();
var targetBuffer = new TPixel[image0.Width * image0.Height];
TPixel[] targetBuffer = new TPixel[image0.Width * image0.Height];
Assert.True(image0.DangerousTryGetSinglePixelMemory(out Memory<TPixel> sourceBuffer));
sourceBuffer.CopyTo(targetBuffer);
var managerOfExternalMemory = new TestMemoryManager<TPixel>(targetBuffer);
TestMemoryManager<TPixel> managerOfExternalMemory = new(targetBuffer);
Memory<TPixel> externalMemory = managerOfExternalMemory.Memory;
using (var image1 = Image.WrapMemory(externalMemory, image0.Width, image0.Height))
using (Image<TPixel> image1 = Image.WrapMemory(externalMemory, image0.Width, image0.Height))
{
VerifyMemoryGroupDataMatchesTestPattern(provider, image1.GetPixelMemoryGroup(), image1.Size());
VerifyMemoryGroupDataMatchesTestPattern(provider, image1.GetPixelMemoryGroup(), image1.Size);
}
// Make sure externalMemory works after destruction:
VerifyMemoryGroupDataMatchesTestPattern(provider, image0.GetPixelMemoryGroup(), image0.Size());
VerifyMemoryGroupDataMatchesTestPattern(provider, image0.GetPixelMemoryGroup(), image0.Size);
}
private static void VerifyMemoryGroupDataMatchesTestPattern<TPixel>(

2
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Metadata.cs

@ -174,7 +174,7 @@ public partial class JpegDecoderTests
Assert.Equal(expectedColorType, meta.ColorType);
}
private static void TestImageInfo(string imagePath, IImageDecoder decoder, bool useIdentify, Action<IImageInfo> test)
private static void TestImageInfo(string imagePath, IImageDecoder decoder, bool useIdentify, Action<ImageInfo> test)
{
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);

12
tests/ImageSharp.Tests/Image/ImageRotationTests.cs

@ -45,12 +45,10 @@ public class ImageRotationTests
private static (Size Original, Size Rotated) Rotate(int angle)
{
var file = TestFile.Create(TestImages.Bmp.Car);
using (var image = Image.Load<Rgba32>(file.FullPath))
{
Size original = image.Size();
image.Mutate(x => x.Rotate(angle));
return (original, image.Size());
}
TestFile file = TestFile.Create(TestImages.Bmp.Car);
using Image<Rgba32> image = Image.Load<Rgba32>(file.FullPath);
Size original = image.Size;
image.Mutate(x => x.Rotate(angle));
return (original, image.Size);
}
}

10
tests/ImageSharp.Tests/Image/ImageTests.Identify.cs

@ -34,7 +34,7 @@ public partial class ImageTests
public void FromBytes_GlobalConfiguration()
{
ImageInfo info = Image.Identify(ActualImageBytes);
Assert.Equal(ExpectedImageSize, info.Size());
Assert.Equal(ExpectedImageSize, info.Size);
Assert.Equal(ExpectedGlobalFormat, info.Metadata.DecodedImageFormat);
}
@ -176,7 +176,7 @@ public partial class ImageTests
AsyncStreamWrapper asyncStream = new(stream, () => false);
ImageInfo info = await Image.IdentifyAsync(asyncStream);
Assert.Equal(ExpectedImageSize, info.Size());
Assert.Equal(ExpectedImageSize, info.Size);
Assert.Equal(ExpectedGlobalFormat, info.Metadata.DecodedImageFormat);
}
@ -201,7 +201,7 @@ public partial class ImageTests
AsyncStreamWrapper asyncStream = new(nonSeekableStream, () => false);
ImageInfo info = await Image.IdentifyAsync(asyncStream);
Assert.Equal(ExpectedImageSize, info.Size());
Assert.Equal(ExpectedImageSize, info.Size);
Assert.Equal(ExpectedGlobalFormat, info.Metadata.DecodedImageFormat);
}
@ -253,7 +253,7 @@ public partial class ImageTests
{
ImageInfo info = await Image.IdentifyAsync(ActualImagePath);
Assert.Equal(ExpectedImageSize, info.Size());
Assert.Equal(ExpectedImageSize, info.Size);
Assert.Equal(ExpectedGlobalFormat, info.Metadata.DecodedImageFormat);
}
@ -262,7 +262,7 @@ public partial class ImageTests
{
ImageInfo info = await Image.IdentifyAsync(ActualImagePath);
Assert.Equal(ExpectedImageSize, info.Size());
Assert.Equal(ExpectedImageSize, info.Size);
}
[Fact]

12
tests/ImageSharp.Tests/Image/ImageTests.ImageLoadTestBase.cs

@ -5,6 +5,7 @@ using Moq;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.IO;
using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests;
@ -25,8 +26,6 @@ public partial class ImageTests
protected Mock<IImageFormat> localImageFormatMock;
protected Mock<IImageInfo> localImageInfoMock;
protected readonly string MockFilePath = Guid.NewGuid().ToString();
internal readonly Mock<IFileSystem> LocalFileSystemMock = new();
@ -58,14 +57,7 @@ public partial class ImageTests
// TODO: Remove all this mocking. It's too complicated and we can now use fakes.
this.localStreamReturnImageRgba32 = new Image<Rgba32>(1, 1);
this.localStreamReturnImageAgnostic = new Image<Bgra4444>(1, 1);
this.localImageInfoMock = new Mock<IImageInfo>();
this.LocalImageInfo = new(
this.localImageInfoMock.Object.PixelType,
this.localImageInfoMock.Object.Width,
this.localImageInfoMock.Object.Height,
this.localImageInfoMock.Object.Metadata);
this.LocalImageInfo = new(new PixelTypeInfo(8), new(1, 1), new ImageMetadata());
this.localImageFormatMock = new Mock<IImageFormat>();

2
tests/ImageSharp.Tests/Image/ImageTests.Load_FileSystemPath_UseDefaultConfiguration.cs

@ -12,7 +12,7 @@ public partial class ImageTests
{
private string Path { get; } = TestFile.GetInputFileFullPath(TestImages.Bmp.Bit8);
private static void VerifyDecodedImage(Image img) => Assert.Equal(new Size(127, 64), img.Size());
private static void VerifyDecodedImage(Image img) => Assert.Equal(new Size(127, 64), img.Size);
[Fact]
public void Path_Specific()

2
tests/ImageSharp.Tests/Image/ImageTests.Load_FromBytes_UseGlobalConfiguration.cs

@ -14,7 +14,7 @@ public partial class ImageTests
private static Span<byte> ByteSpan => new(ByteArray);
private static void VerifyDecodedImage(Image img) => Assert.Equal(new Size(127, 64), img.Size());
private static void VerifyDecodedImage(Image img) => Assert.Equal(new Size(127, 64), img.Size);
[Fact]
public void Bytes_Specific()

2
tests/ImageSharp.Tests/Image/ImageTests.Load_FromStream_UseDefaultConfiguration.cs

@ -26,7 +26,7 @@ public partial class ImageTests
}
private static void VerifyDecodedImage(Image img)
=> Assert.Equal(new Size(127, 64), img.Size());
=> Assert.Equal(new Size(127, 64), img.Size);
[Fact]
public void Stream_Specific()

24
tests/ImageSharp.Tests/ImageInfoTests.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors.
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Formats;
@ -11,20 +11,20 @@ public class ImageInfoTests
[Fact]
public void ImageInfoInitializesCorrectly()
{
const int Width = 50;
const int Height = 60;
var size = new Size(Width, Height);
var rectangle = new Rectangle(0, 0, Width, Height);
var pixelType = new PixelTypeInfo(8);
var meta = new ImageMetadata();
const int width = 50;
const int height = 60;
Size size = new(width, height);
Rectangle rectangle = new(0, 0, width, height);
PixelTypeInfo pixelType = new(8);
ImageMetadata meta = new();
var info = new ImageInfo(pixelType, Width, Height, meta);
ImageInfo info = new(pixelType, width, height, meta);
Assert.Equal(pixelType, info.PixelType);
Assert.Equal(Width, info.Width);
Assert.Equal(Height, info.Height);
Assert.Equal(size, info.Size());
Assert.Equal(rectangle, info.Bounds());
Assert.Equal(width, info.Width);
Assert.Equal(height, info.Height);
Assert.Equal(size, info.Size);
Assert.Equal(rectangle, info.Bounds);
Assert.Equal(meta, info.Metadata);
}
}

2
tests/ImageSharp.Tests/Processing/BaseImageOperationsExtensionTest.cs

@ -15,7 +15,7 @@ public abstract class BaseImageOperationsExtensionTest : IDisposable
protected readonly GraphicsOptions options;
private readonly Image<Rgba32> source;
public Rectangle SourceBounds() => this.source.Bounds();
public Rectangle SourceBounds() => this.source.Bounds;
public BaseImageOperationsExtensionTest()
{

2
tests/ImageSharp.Tests/Processing/FakeImageOperationsProvider.cs

@ -64,7 +64,7 @@ internal class FakeImageOperationsProvider : IImageProcessingContextFactory
public Size GetCurrentSize()
{
return this.Source.Size();
return this.Source.Size;
}
public IImageProcessingContext ApplyProcessor(IImageProcessor processor, Rectangle rectangle)

33
tests/ImageSharp.Tests/Processing/Processors/Convolution/BokehBlurTest.cs

@ -48,7 +48,7 @@ public class BokehBlurTest
public void VerifyComplexComponents()
{
// Get the saved components
var components = new List<Complex64[]>();
List<Complex64[]> components = new();
foreach (Match match in Regex.Matches(Components10x2, @"\[\[(.*?)\]\]", RegexOptions.Singleline))
{
string[] values = match.Groups[1].Value.Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
@ -64,23 +64,20 @@ public class BokehBlurTest
}
// Make sure the kernel components are the same
using (var image = new Image<Rgb24>(1, 1))
using Image<Rgb24> image = new(1, 1);
Configuration configuration = image.GetConfiguration();
BokehBlurProcessor definition = new(10, BokehBlurProcessor.DefaultComponents, BokehBlurProcessor.DefaultGamma);
using BokehBlurProcessor<Rgb24> processor = (BokehBlurProcessor<Rgb24>)definition.CreatePixelSpecificProcessor(configuration, image, image.Bounds);
Assert.Equal(components.Count, processor.Kernels.Count);
foreach ((Complex64[] a, Complex64[] b) in components.Zip(processor.Kernels, (a, b) => (a, b)))
{
Configuration configuration = image.GetConfiguration();
var definition = new BokehBlurProcessor(10, BokehBlurProcessor.DefaultComponents, BokehBlurProcessor.DefaultGamma);
using (var processor = (BokehBlurProcessor<Rgb24>)definition.CreatePixelSpecificProcessor(configuration, image, image.Bounds()))
Span<Complex64> spanA = a.AsSpan(), spanB = b.AsSpan();
Assert.Equal(spanA.Length, spanB.Length);
for (int i = 0; i < spanA.Length; i++)
{
Assert.Equal(components.Count, processor.Kernels.Count);
foreach ((Complex64[] a, Complex64[] b) in components.Zip(processor.Kernels, (a, b) => (a, b)))
{
Span<Complex64> spanA = a.AsSpan(), spanB = b.AsSpan();
Assert.Equal(spanA.Length, spanB.Length);
for (int i = 0; i < spanA.Length; i++)
{
Assert.True(Math.Abs(Math.Abs(spanA[i].Real) - Math.Abs(spanB[i].Real)) < 0.0001f);
Assert.True(Math.Abs(Math.Abs(spanA[i].Imaginary) - Math.Abs(spanB[i].Imaginary)) < 0.0001f);
}
}
Assert.True(Math.Abs(Math.Abs(spanA[i].Real) - Math.Abs(spanB[i].Real)) < 0.0001f);
Assert.True(Math.Abs(Math.Abs(spanA[i].Imaginary) - Math.Abs(spanB[i].Imaginary)) < 0.0001f);
}
}
}
@ -110,7 +107,7 @@ public class BokehBlurTest
public override string ToString() => $"R{this.Radius}_C{this.Components}_G{this.Gamma}";
}
public static readonly TheoryData<BokehBlurInfo> BokehBlurValues = new TheoryData<BokehBlurInfo>
public static readonly TheoryData<BokehBlurInfo> BokehBlurValues = new()
{
new BokehBlurInfo { Radius = 8, Components = 1, Gamma = 1 },
new BokehBlurInfo { Radius = 16, Components = 1, Gamma = 3 },
@ -167,7 +164,7 @@ public class BokehBlurTest
x =>
{
Size size = x.GetCurrentSize();
var bounds = new Rectangle(10, 10, size.Width / 2, size.Height / 2);
Rectangle bounds = new(10, 10, size.Width / 2, size.Height / 2);
x.BokehBlur(value.Radius, value.Components, value.Gamma, bounds);
},
testOutputDetails: value.ToString(),

2
tests/ImageSharp.Tests/Processing/Processors/Transforms/AffineTransformTests.cs

@ -106,7 +106,7 @@ public class AffineTransformTests
.AppendScale(new SizeF(sx, sy))
.AppendTranslation(new PointF(tx, ty));
this.PrintMatrix(builder.BuildMatrix(image.Size()));
this.PrintMatrix(builder.BuildMatrix(image.Size));
image.Mutate(i => i.Transform(builder, KnownResamplers.Bicubic));

8
tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs

@ -39,7 +39,7 @@ public class ResizeTests
string filePath = TestFile.GetInputFileFullPath(TestImages.Jpeg.Baseline.Calliphora);
using Image image = Image.Load(filePath);
image.Mutate(x => x.Resize(image.Size() / 2));
image.Mutate(x => x.Resize(image.Size / 2));
string path = Path.Combine(
TestEnvironment.CreateOutputDirectory(nameof(ResizeTests)),
nameof(this.Resize_PixelAgnostic) + ".png");
@ -101,7 +101,7 @@ public class ResizeTests
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image0 = provider.GetImage();
Size destSize = image0.Size() / 4;
Size destSize = image0.Size / 4;
Configuration configuration = Configuration.CreateDefaultInstance();
@ -155,7 +155,7 @@ public class ResizeTests
{
using Image<TPixel> expected = provider.GetImage();
int width = expected.Width;
Size destSize = expected.Size() / 4;
Size destSize = expected.Size / 4;
expected.Mutate(c => c.Resize(destSize, KnownResamplers.Bicubic, false));
// Replace configuration:
@ -179,7 +179,7 @@ public class ResizeTests
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage();
image.Mutate(x => x.Resize(image.Size() / 2, true));
image.Mutate(x => x.Resize(image.Size / 2, true));
image.DebugSave(provider);
image.CompareToReferenceOutput(ValidatorComparer, provider);

2
tests/ImageSharp.Tests/ProfilingBenchmarks/LoadResizeSaveProfilingBenchmarks.cs

@ -35,7 +35,7 @@ public class LoadResizeSaveProfilingBenchmarks : MeasureFixture
{
using (var image = Image.Load(options, imageBytes))
{
image.Mutate(x => x.Resize(image.Size() / 4));
image.Mutate(x => x.Resize(image.Size / 4));
image.SaveAsJpeg(ms);
}

8
tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs

@ -76,9 +76,9 @@ public static class ImageComparerExtensions
where TPixelA : unmanaged, IPixel<TPixelA>
where TPixelB : unmanaged, IPixel<TPixelB>
{
if (expected.Size() != actual.Size())
if (expected.Size != actual.Size)
{
throw new ImageDimensionsMismatchException(expected.Size(), actual.Size());
throw new ImageDimensionsMismatchException(expected.Size, actual.Size);
}
if (expected.Frames.Count != actual.Frames.Count)
@ -101,9 +101,9 @@ public static class ImageComparerExtensions
where TPixelA : unmanaged, IPixel<TPixelA>
where TPixelB : unmanaged, IPixel<TPixelB>
{
if (expected.Size() != actual.Size())
if (expected.Size != actual.Size)
{
throw new ImageDimensionsMismatchException(expected.Size(), actual.Size());
throw new ImageDimensionsMismatchException(expected.Size, actual.Size);
}
if (expected.Frames.Count != actual.Frames.Count)

Loading…
Cancel
Save