diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs index f2821b288e..742189ec3a 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs @@ -461,6 +461,7 @@ internal sealed class BmpEncoderCore : IImageEncoderInternals private void Write8BitColor(Stream stream, ImageFrame image, Span colorPalette) where TPixel : unmanaged, IPixel { + // TODO: Should we use the pixel sampling strategy here? using IQuantizer frameQuantizer = this.quantizer.CreatePixelSpecificQuantizer(this.configuration); using IndexedImageFrame quantized = frameQuantizer.BuildPaletteAndQuantizeFrame(image, image.Bounds()); diff --git a/src/ImageSharp/ImageFrameCollection.cs b/src/ImageSharp/ImageFrameCollection.cs index 1632134260..cc2b430ff1 100644 --- a/src/ImageSharp/ImageFrameCollection.cs +++ b/src/ImageSharp/ImageFrameCollection.cs @@ -180,7 +180,7 @@ public abstract class ImageFrameCollection : IDisposable, IEnumerable - public IEnumerator GetEnumerator() + IEnumerator IEnumerable.GetEnumerator() { this.EnsureNotDisposed(); @@ -188,7 +188,7 @@ public abstract class ImageFrameCollection : IDisposable, IEnumerable - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)this).GetEnumerator(); /// /// Throws if the image frame is disposed. @@ -208,7 +208,7 @@ public abstract class ImageFrameCollection : IDisposable, IEnumerable - /// Implements . + /// Implements . /// /// The enumerator. protected abstract IEnumerator NonGenericGetEnumerator(); diff --git a/src/ImageSharp/ImageFrameCollection{TPixel}.cs b/src/ImageSharp/ImageFrameCollection{TPixel}.cs index 60b5c6d6ad..d366ff7a76 100644 --- a/src/ImageSharp/ImageFrameCollection{TPixel}.cs +++ b/src/ImageSharp/ImageFrameCollection{TPixel}.cs @@ -168,7 +168,7 @@ public sealed class ImageFrameCollection : ImageFrameCollection, IEnumer { this.EnsureNotDisposed(); - var frame = ImageFrame.LoadPixelData( + ImageFrame frame = ImageFrame.LoadPixelData( this.parent.GetConfiguration(), source, this.RootFrame.Width, @@ -298,7 +298,7 @@ public sealed class ImageFrameCollection : ImageFrameCollection, IEnumer { this.EnsureNotDisposed(); - var frame = new ImageFrame( + ImageFrame frame = new( this.parent.GetConfiguration(), this.RootFrame.Width, this.RootFrame.Height); @@ -364,7 +364,7 @@ public sealed class ImageFrameCollection : ImageFrameCollection, IEnumer /// public ImageFrame CreateFrame(TPixel backgroundColor) { - var frame = new ImageFrame( + ImageFrame frame = new( this.parent.GetConfiguration(), this.RootFrame.Width, this.RootFrame.Height, @@ -374,7 +374,7 @@ public sealed class ImageFrameCollection : ImageFrameCollection, IEnumer } /// - IEnumerator> IEnumerable>.GetEnumerator() => this.frames.GetEnumerator(); + public IEnumerator> GetEnumerator() => this.frames.GetEnumerator(); /// IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)this.frames).GetEnumerator(); @@ -408,7 +408,7 @@ public sealed class ImageFrameCollection : ImageFrameCollection, IEnumer private ImageFrame CopyNonCompatibleFrame(ImageFrame source) { - var result = new ImageFrame( + ImageFrame result = new( this.parent.GetConfiguration(), source.Size(), source.Metadata.DeepClone()); diff --git a/src/ImageSharp/Image{TPixel}.cs b/src/ImageSharp/Image{TPixel}.cs index 814843013e..4dab82a024 100644 --- a/src/ImageSharp/Image{TPixel}.cs +++ b/src/ImageSharp/Image{TPixel}.cs @@ -80,9 +80,7 @@ public sealed class Image : Image /// The images metadata. internal Image(Configuration configuration, int width, int height, ImageMetadata metadata) : base(configuration, PixelTypeInfo.Create(), metadata, width, height) - { - this.frames = new ImageFrameCollection(this, width, height, default(TPixel)); - } + => this.frames = new ImageFrameCollection(this, width, height, default(TPixel)); /// /// Initializes a new instance of the class @@ -115,9 +113,7 @@ public sealed class Image : Image int height, ImageMetadata metadata) : base(configuration, PixelTypeInfo.Create(), metadata, width, height) - { - this.frames = new ImageFrameCollection(this, width, height, memoryGroup); - } + => this.frames = new ImageFrameCollection(this, width, height, memoryGroup); /// /// Initializes a new instance of the class @@ -135,9 +131,7 @@ public sealed class Image : Image TPixel backgroundColor, ImageMetadata metadata) : base(configuration, PixelTypeInfo.Create(), metadata, width, height) - { - this.frames = new ImageFrameCollection(this, width, height, backgroundColor); - } + => this.frames = new ImageFrameCollection(this, width, height, backgroundColor); /// /// Initializes a new instance of the class @@ -148,9 +142,7 @@ public sealed class Image : Image /// The frames that will be owned by this image instance. internal Image(Configuration configuration, ImageMetadata metadata, IEnumerable> frames) : base(configuration, PixelTypeInfo.Create(), metadata, ValidateFramesAndGetSize(frames)) - { - this.frames = new ImageFrameCollection(this, frames); - } + => this.frames = new ImageFrameCollection(this, frames); /// protected override ImageFrameCollection NonGenericFrameCollection => this.Frames; @@ -181,7 +173,7 @@ public sealed class Image : Image /// Thrown when the provided (x,y) coordinates are outside the image boundary. public TPixel this[int x, int y] { - [MethodImpl(InliningOptions.ShortMethod)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { this.EnsureNotDisposed(); @@ -190,7 +182,7 @@ public sealed class Image : Image return this.PixelSourceUnsafe.PixelBuffer.GetElementUnsafe(x, y); } - [MethodImpl(InliningOptions.ShortMethod)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] set { this.EnsureNotDisposed(); @@ -212,7 +204,7 @@ public sealed class Image : Image try { - var accessor = new PixelAccessor(buffer); + PixelAccessor accessor = new(buffer); processPixels(accessor); } finally @@ -243,8 +235,8 @@ public sealed class Image : Image try { - var accessor1 = new PixelAccessor(buffer1); - var accessor2 = new PixelAccessor(buffer2); + PixelAccessor accessor1 = new(buffer1); + PixelAccessor accessor2 = new(buffer2); processPixels(accessor1, accessor2); } finally @@ -283,9 +275,9 @@ public sealed class Image : Image try { - var accessor1 = new PixelAccessor(buffer1); - var accessor2 = new PixelAccessor(buffer2); - var accessor3 = new PixelAccessor(buffer3); + PixelAccessor accessor1 = new(buffer1); + PixelAccessor accessor2 = new(buffer2); + PixelAccessor accessor3 = new(buffer3); processPixels(accessor1, accessor2, accessor3); } finally @@ -348,7 +340,7 @@ public sealed class Image : Image { this.EnsureNotDisposed(); - var clonedFrames = new ImageFrame[this.frames.Count]; + ImageFrame[] clonedFrames = new ImageFrame[this.frames.Count]; for (int i = 0; i < clonedFrames.Length; i++) { clonedFrames[i] = this.frames[i].Clone(configuration); @@ -367,7 +359,7 @@ public sealed class Image : Image { this.EnsureNotDisposed(); - var clonedFrames = new ImageFrame[this.frames.Count]; + ImageFrame[] clonedFrames = new ImageFrame[this.frames.Count]; for (int i = 0; i < clonedFrames.Length; i++) { clonedFrames[i] = this.frames[i].CloneAs(configuration); @@ -444,7 +436,7 @@ public sealed class Image : Image return rootSize; } - [MethodImpl(InliningOptions.ShortMethod)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] private void VerifyCoords(int x, int y) { if ((uint)x >= (uint)this.Width) @@ -458,9 +450,6 @@ public sealed class Image : Image } } - [MethodImpl(InliningOptions.ColdPath)] private static void ThrowArgumentOutOfRangeException(string paramName) - { - throw new ArgumentOutOfRangeException(paramName); - } + => throw new ArgumentOutOfRangeException(paramName); } diff --git a/src/ImageSharp/Processing/Processors/Quantization/DefaultPixelSamplingStrategy.cs b/src/ImageSharp/Processing/Processors/Quantization/DefaultPixelSamplingStrategy.cs index 9da1d98e3b..de36d1592a 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/DefaultPixelSamplingStrategy.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/DefaultPixelSamplingStrategy.cs @@ -79,7 +79,7 @@ public class DefaultPixelSamplingStrategy : IPixelSamplingStrategy r = Math.Max(this.MinimumScanRatio, r); // always visit the minimum defined portion of the image. - var ratio = new Rational(r); + Rational ratio = new(r); int denom = (int)ratio.Denominator; int num = (int)ratio.Numerator; diff --git a/src/ImageSharp/Processing/Processors/Quantization/QuantizerUtilities.cs b/src/ImageSharp/Processing/Processors/Quantization/QuantizerUtilities.cs index 04e8124037..63094287c7 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/QuantizerUtilities.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/QuantizerUtilities.cs @@ -50,7 +50,7 @@ public static class QuantizerUtilities Guard.NotNull(quantizer, nameof(quantizer)); Guard.NotNull(source, nameof(source)); - var interest = Rectangle.Intersect(source.Bounds(), bounds); + Rectangle interest = Rectangle.Intersect(source.Bounds(), bounds); Buffer2DRegion region = source.PixelBuffer.GetRegion(interest); // Collect the palette. Required before the second pass runs. @@ -77,9 +77,9 @@ public static class QuantizerUtilities where TPixel : unmanaged, IPixel { Guard.NotNull(source, nameof(source)); - var interest = Rectangle.Intersect(source.Bounds(), bounds); + Rectangle interest = Rectangle.Intersect(source.Bounds(), bounds); - var destination = new IndexedImageFrame( + IndexedImageFrame destination = new( quantizer.Configuration, interest.Width, interest.Height,