From 69516e110befcb677946021aa128fcfb0efdd59f Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Thu, 15 Mar 2018 00:36:51 +1100 Subject: [PATCH 1/5] Use non-generic IQuantizer for image formats --- src/ImageSharp/Common/Helpers/Guard.cs | 10 +- src/ImageSharp/Formats/Gif/GifEncoder.cs | 15 +- src/ImageSharp/Formats/Gif/GifEncoderCore.cs | 49 ++---- .../Formats/Gif/IGifEncoderOptions.cs | 10 -- .../Formats/Png/IPngEncoderOptions.cs | 10 -- src/ImageSharp/Formats/Png/PngEncoder.cs | 15 +- src/ImageSharp/Formats/Png/PngEncoderCore.cs | 148 ++++++------------ src/ImageSharp/Processing/Quantization/Box.cs | 56 ------- .../FrameQuantizerBase{TPixel}.cs} | 27 ++-- .../IFrameQuantizer{TPixel}.cs | 35 +++++ .../OctreeFrameQuantizer{TPixel}.cs} | 32 ++-- .../PaletteFrameQuantizer{TPixel}.cs} | 34 +--- .../WuFrameQuantizer{TPixel}.cs} | 74 +++++++-- .../Processing/Quantization/IQuantizer.cs | 33 ++++ .../Quantization/IQuantizer{TPixel}.cs | 42 ----- .../Quantization/OctreeQuantizer.cs | 75 +++++++++ .../Quantization/PaletteQuantizer.cs | 68 ++++++++ .../Processors/QuantizeProcessor.cs | 53 +++---- .../Quantization/QuantizationMode.cs | 16 +- .../Quantization/QuantizeExtensions.cs | 31 +--- .../Processing/Quantization/WuQuantizer.cs | 75 +++++++++ .../Image/EncodeIndexedPng.cs | 53 ++++--- .../ImageSharp.Benchmarks/Image/EncodePng.cs | 10 +- .../Formats/Png/PngEncoderTests.cs | 64 ++++---- .../Image/ImageFramesCollectionTests.cs | 2 +- .../Quantization/QuantizedImageTests.cs | 18 +-- 26 files changed, 571 insertions(+), 484 deletions(-) delete mode 100644 src/ImageSharp/Processing/Quantization/Box.cs rename src/ImageSharp/Processing/Quantization/{QuantizerBase{TPixel}.cs => FrameQuantizers/FrameQuantizerBase{TPixel}.cs} (82%) create mode 100644 src/ImageSharp/Processing/Quantization/FrameQuantizers/IFrameQuantizer{TPixel}.cs rename src/ImageSharp/Processing/Quantization/{OctreeQuantizer{TPixel}.cs => FrameQuantizers/OctreeFrameQuantizer{TPixel}.cs} (96%) rename src/ImageSharp/Processing/Quantization/{PaletteQuantizer{TPixel}.cs => FrameQuantizers/PaletteFrameQuantizer{TPixel}.cs} (76%) rename src/ImageSharp/Processing/Quantization/{WuQuantizer{TPixel}.cs => FrameQuantizers/WuFrameQuantizer{TPixel}.cs} (94%) create mode 100644 src/ImageSharp/Processing/Quantization/IQuantizer.cs delete mode 100644 src/ImageSharp/Processing/Quantization/IQuantizer{TPixel}.cs create mode 100644 src/ImageSharp/Processing/Quantization/OctreeQuantizer.cs create mode 100644 src/ImageSharp/Processing/Quantization/PaletteQuantizer.cs create mode 100644 src/ImageSharp/Processing/Quantization/WuQuantizer.cs diff --git a/src/ImageSharp/Common/Helpers/Guard.cs b/src/ImageSharp/Common/Helpers/Guard.cs index b0546bf9a9..0db5cb7c1d 100644 --- a/src/ImageSharp/Common/Helpers/Guard.cs +++ b/src/ImageSharp/Common/Helpers/Guard.cs @@ -100,7 +100,7 @@ namespace SixLabors.ImageSharp { if (value.CompareTo(max) >= 0) { - throw new ArgumentOutOfRangeException(parameterName, $"Value must be less than {max}."); + throw new ArgumentOutOfRangeException(parameterName, $"Value {value} must be less than {max}."); } } @@ -120,7 +120,7 @@ namespace SixLabors.ImageSharp { if (value.CompareTo(max) > 0) { - throw new ArgumentOutOfRangeException(parameterName, $"Value must be less than or equal to {max}."); + throw new ArgumentOutOfRangeException(parameterName, $"Value {value} must be less than or equal to {max}."); } } @@ -142,7 +142,7 @@ namespace SixLabors.ImageSharp { throw new ArgumentOutOfRangeException( parameterName, - $"Value must be greater than {min}."); + $"Value {value} must be greater than {min}."); } } @@ -162,7 +162,7 @@ namespace SixLabors.ImageSharp { if (value.CompareTo(min) < 0) { - throw new ArgumentOutOfRangeException(parameterName, $"Value must be greater than or equal to {min}."); + throw new ArgumentOutOfRangeException(parameterName, $"Value {value} must be greater than or equal to {min}."); } } @@ -183,7 +183,7 @@ namespace SixLabors.ImageSharp { if (value.CompareTo(min) < 0 || value.CompareTo(max) > 0) { - throw new ArgumentOutOfRangeException(parameterName, $"Value must be greater than or equal to {min} and less than or equal to {max}."); + throw new ArgumentOutOfRangeException(parameterName, $"Value {value} must be greater than or equal to {min} and less than or equal to {max}."); } } diff --git a/src/ImageSharp/Formats/Gif/GifEncoder.cs b/src/ImageSharp/Formats/Gif/GifEncoder.cs index ad3e85f92f..fb072bcb7a 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoder.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoder.cs @@ -24,20 +24,11 @@ namespace SixLabors.ImageSharp.Formats.Gif /// public Encoding TextEncoding { get; set; } = GifConstants.DefaultEncoding; - /// - /// Gets or sets the size of the color palette to use. For gifs the value ranges from 1 to 256. Leave as zero for default size. - /// - public int PaletteSize { get; set; } = 0; - - /// - /// Gets or sets the transparency threshold. - /// - public byte Threshold { get; set; } = 128; - /// /// Gets or sets the quantizer for reducing the color count. + /// Defaults to the /// - public IQuantizer Quantizer { get; set; } + public IQuantizer Quantizer { get; set; } = new OctreeQuantizer(); /// public void Encode(Image image, Stream stream) @@ -47,4 +38,4 @@ namespace SixLabors.ImageSharp.Formats.Gif encoder.Encode(image, stream); } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index bdb228f520..57bb3d09a7 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs @@ -25,40 +25,30 @@ namespace SixLabors.ImageSharp.Formats.Gif /// private readonly byte[] buffer = new byte[16]; - /// - /// The number of bits requires to store the image palette. - /// - private int bitDepth; - - /// - /// Whether the current image has multiple frames. - /// - private bool hasFrames; - /// /// Gets the TextEncoding /// - private Encoding textEncoding; + private readonly Encoding textEncoding; /// /// Gets or sets the quantizer for reducing the color count. /// - private IQuantizer quantizer; + private readonly IQuantizer quantizer; /// - /// Gets or sets the threshold. + /// Gets or sets a value indicating whether the metadata should be ignored when the image is being decoded. /// - private byte threshold; + private readonly bool ignoreMetadata; /// - /// Gets or sets the size of the color palette to use. + /// The number of bits requires to store the image palette. /// - private int paletteSize; + private int bitDepth; /// - /// Gets or sets a value indicating whether the metadata should be ignored when the image is being decoded. + /// Whether the current image has multiple frames. /// - private bool ignoreMetadata; + private bool hasFrames; /// /// Initializes a new instance of the class. @@ -69,10 +59,7 @@ namespace SixLabors.ImageSharp.Formats.Gif { this.memoryManager = memoryManager; this.textEncoding = options.TextEncoding ?? GifConstants.DefaultEncoding; - this.quantizer = options.Quantizer; - this.threshold = options.Threshold; - this.paletteSize = options.PaletteSize; this.ignoreMetadata = options.IgnoreMetadata; } @@ -88,24 +75,16 @@ namespace SixLabors.ImageSharp.Formats.Gif Guard.NotNull(image, nameof(image)); Guard.NotNull(stream, nameof(stream)); - this.quantizer = this.quantizer ?? new OctreeQuantizer(); - // Do not use IDisposable pattern here as we want to preserve the stream. var writer = new EndianBinaryWriter(Endianness.LittleEndian, stream); - // Ensure that pallete size can be set but has a fallback. - int size = this.paletteSize; - size = size > 0 ? size.Clamp(1, 256) : 256; - - // Get the number of bits. - this.bitDepth = ImageMaths.GetBitsNeededForColorDepth(size); - this.hasFrames = image.Frames.Count > 1; - var pixelQuantizer = (IQuantizer)this.quantizer; - // Quantize the image returning a palette. - QuantizedFrame quantized = pixelQuantizer.Quantize(image.Frames.RootFrame, size); + QuantizedFrame quantized = this.quantizer.CreateFrameQuantizer().QuantizeFrame(image.Frames.RootFrame); + + // Get the number of bits. + this.bitDepth = ImageMaths.GetBitsNeededForColorDepth(quantized.Palette.Length).Clamp(1, 8); int index = this.GetTransparentIndex(quantized); @@ -128,7 +107,7 @@ namespace SixLabors.ImageSharp.Formats.Gif { if (quantized == null) { - quantized = pixelQuantizer.Quantize(frame, size); + quantized = this.quantizer.CreateFrameQuantizer().QuantizeFrame(frame); } this.WriteGraphicalControlExtension(frame.MetaData, writer, this.GetTransparentIndex(quantized)); @@ -136,7 +115,7 @@ namespace SixLabors.ImageSharp.Formats.Gif this.WriteColorTable(quantized, writer); this.WriteImageData(quantized, writer); - quantized = null; // so next frame can regenerate it + quantized = null; // So next frame can regenerate it } // TODO: Write extension etc diff --git a/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs b/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs index a709b2b9d8..1f1875789b 100644 --- a/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs +++ b/src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs @@ -21,16 +21,6 @@ namespace SixLabors.ImageSharp.Formats.Gif /// Encoding TextEncoding { get; } - /// - /// Gets the size of the color palette to use. For gifs the value ranges from 1 to 256. Leave as zero for default size. - /// - int PaletteSize { get; } - - /// - /// Gets the transparency threshold. - /// - byte Threshold { get; } - /// /// Gets the quantizer for reducing the color count. /// diff --git a/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs b/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs index 28020f2600..1bfa4b0631 100644 --- a/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs +++ b/src/ImageSharp/Formats/Png/IPngEncoderOptions.cs @@ -10,16 +10,6 @@ namespace SixLabors.ImageSharp.Formats.Png /// internal interface IPngEncoderOptions { - /// - /// Gets a value indicating whether the metadata should be ignored when the image is being encoded. - /// - bool IgnoreMetadata { get; } - - /// - /// Gets the size of the color palette to use. Set to zero to leav png encoding to use pixel data. - /// - int PaletteSize { get; } - /// /// Gets the png color type /// diff --git a/src/ImageSharp/Formats/Png/PngEncoder.cs b/src/ImageSharp/Formats/Png/PngEncoder.cs index 2cff18410d..993dc6586b 100644 --- a/src/ImageSharp/Formats/Png/PngEncoder.cs +++ b/src/ImageSharp/Formats/Png/PngEncoder.cs @@ -13,16 +13,6 @@ namespace SixLabors.ImageSharp.Formats.Png /// public sealed class PngEncoder : IImageEncoder, IPngEncoderOptions { - /// - /// Gets or sets a value indicating whether the metadata should be ignored when the image is being encoded. - /// - public bool IgnoreMetadata { get; set; } - - /// - /// Gets or sets the size of the color palette to use. Set to zero to leave png encoding to use pixel data. - /// - public int PaletteSize { get; set; } = 0; - /// /// Gets or sets the png color type /// @@ -44,8 +34,9 @@ namespace SixLabors.ImageSharp.Formats.Png /// /// Gets or sets quantizer for reducing the color count. + /// Defaults to the /// - public IQuantizer Quantizer { get; set; } + public IQuantizer Quantizer { get; set; } = new WuQuantizer(); /// /// Gets or sets the transparency threshold. @@ -73,4 +64,4 @@ namespace SixLabors.ImageSharp.Formats.Png } } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 29c9d2a142..2735164996 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -40,6 +40,36 @@ namespace SixLabors.ImageSharp.Formats.Png /// private readonly Crc32 crc = new Crc32(); + /// + /// The png color type. + /// + private readonly PngColorType pngColorType; + + /// + /// The quantizer for reducing the color count. + /// + private readonly IQuantizer quantizer; + + /// + /// Gets or sets the CompressionLevel value + /// + private readonly int compressionLevel; + + /// + /// Gets or sets the Gamma value + /// + private readonly float gamma; + + /// + /// Gets or sets the Threshold value + /// + private readonly byte threshold; + + /// + /// Gets or sets a value indicating whether to Write Gamma + /// + private readonly bool writeGamma; + /// /// Contains the raw pixel data from an indexed image. /// @@ -101,50 +131,10 @@ namespace SixLabors.ImageSharp.Formats.Png private IManagedByteBuffer average; /// - /// The buffer for the paeth filter + /// The buffer for the Paeth filter /// private IManagedByteBuffer paeth; - /// - /// The png color type. - /// - private PngColorType pngColorType; - - /// - /// The quantizer for reducing the color count. - /// - private IQuantizer quantizer; - - /// - /// Gets or sets a value indicating whether to ignore metadata - /// - private bool ignoreMetadata; - - /// - /// Gets or sets the Quality value - /// - private int paletteSize; - - /// - /// Gets or sets the CompressionLevel value - /// - private int compressionLevel; - - /// - /// Gets or sets the Gamma value - /// - private float gamma; - - /// - /// Gets or sets the Threshold value - /// - private byte threshold; - - /// - /// Gets or sets a value indicating whether to Write Gamma - /// - private bool writeGamma; - /// /// Initializes a new instance of the class. /// @@ -153,8 +143,6 @@ namespace SixLabors.ImageSharp.Formats.Png public PngEncoderCore(MemoryManager memoryManager, IPngEncoderOptions options) { this.memoryManager = memoryManager; - this.ignoreMetadata = options.IgnoreMetadata; - this.paletteSize = options.PaletteSize > 0 ? options.PaletteSize.Clamp(1, int.MaxValue) : int.MaxValue; this.pngColorType = options.PngColorType; this.compressionLevel = options.CompressionLevel; this.gamma = options.Gamma; @@ -190,28 +178,27 @@ namespace SixLabors.ImageSharp.Formats.Png stream.Write(this.chunkDataBuffer, 0, 8); - // Set correct color type if the color count is 256 or less. - if (this.paletteSize <= 256) - { - this.pngColorType = PngColorType.Palette; - } - - if (this.pngColorType == PngColorType.Palette && this.paletteSize > 256) + QuantizedFrame quantized = null; + if (this.pngColorType == PngColorType.Palette) { - this.paletteSize = 256; - } + // Create quantized frame returning the palette and set the bit depth. + quantized = this.quantizer.CreateFrameQuantizer().QuantizeFrame(image.Frames.RootFrame); + this.palettePixelData = quantized.Pixels; + byte bits = (byte)ImageMaths.GetBitsNeededForColorDepth(quantized.Palette.Length).Clamp(1, 8); - // Set correct bit depth. - this.bitDepth = this.paletteSize <= 256 - ? (byte)ImageMaths.GetBitsNeededForColorDepth(this.paletteSize).Clamp(1, 8) - : (byte)8; + // Png only supports in four pixel depths: 1, 2, 4, and 8 bits when using the PLTE chunk + if (bits == 3) + { + bits = 4; + } + else if (bits >= 5 || bits <= 7) + { + bits = 8; + } - // Png only supports in four pixel depths: 1, 2, 4, and 8 bits when using the PLTE chunk - if (this.bitDepth == 3) - { - this.bitDepth = 4; + this.bitDepth = bits; } - else if (this.bitDepth >= 5 || this.bitDepth <= 7) + else { this.bitDepth = 8; } @@ -232,9 +219,9 @@ namespace SixLabors.ImageSharp.Formats.Png this.WriteHeaderChunk(stream, header); // Collect the indexed pixel data - if (this.pngColorType == PngColorType.Palette) + if (quantized != null) { - this.CollectIndexedBytes(image.Frames.RootFrame, stream, header); + this.WritePaletteChunk(stream, header, quantized); } this.WritePhysicalChunk(stream, image); @@ -296,21 +283,6 @@ namespace SixLabors.ImageSharp.Formats.Png stream.Write(buffer, 0, 4); } - /// - /// Collects the indexed pixel data. - /// - /// The pixel format. - /// The image to encode. - /// The containing image data. - /// The . - private void CollectIndexedBytes(ImageFrame image, Stream stream, PngHeader header) - where TPixel : struct, IPixel - { - // Quantize the image and get the pixels. - QuantizedFrame quantized = this.WritePaletteChunk(stream, header, image); - this.palettePixelData = quantized.Pixels; - } - /// /// Collects a row of grayscale pixels. /// @@ -496,24 +468,10 @@ namespace SixLabors.ImageSharp.Formats.Png /// The pixel format. /// The containing image data. /// The . - /// The image to encode. - /// The - private QuantizedFrame WritePaletteChunk(Stream stream, PngHeader header, ImageFrame image) + /// The quantized frame. + private void WritePaletteChunk(Stream stream, PngHeader header, QuantizedFrame quantized) where TPixel : struct, IPixel { - if (this.paletteSize > 256) - { - return null; - } - - if (this.quantizer == null) - { - this.quantizer = new WuQuantizer(); - } - - // Quantize the image returning a palette. This boxing is icky. - QuantizedFrame quantized = ((IQuantizer)this.quantizer).Quantize(image, this.paletteSize); - // Grab the palette and write it to the stream. TPixel[] palette = quantized.Palette; byte pixelCount = palette.Length.ToByte(); @@ -560,8 +518,6 @@ namespace SixLabors.ImageSharp.Formats.Png this.WriteChunk(stream, PngChunkTypes.PaletteAlpha, alphaTable.Array, 0, pixelCount); } } - - return quantized; } /// diff --git a/src/ImageSharp/Processing/Quantization/Box.cs b/src/ImageSharp/Processing/Quantization/Box.cs deleted file mode 100644 index e6e1166f88..0000000000 --- a/src/ImageSharp/Processing/Quantization/Box.cs +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -namespace SixLabors.ImageSharp.Processing.Quantization -{ - /// - /// Represents a box color cube. - /// - internal struct Box - { - /// - /// Gets or sets the min red value, exclusive. - /// - public int R0 { get; set; } - - /// - /// Gets or sets the max red value, inclusive. - /// - public int R1 { get; set; } - - /// - /// Gets or sets the min green value, exclusive. - /// - public int G0 { get; set; } - - /// - /// Gets or sets the max green value, inclusive. - /// - public int G1 { get; set; } - - /// - /// Gets or sets the min blue value, exclusive. - /// - public int B0 { get; set; } - - /// - /// Gets or sets the max blue value, inclusive. - /// - public int B1 { get; set; } - - /// - /// Gets or sets the min alpha value, exclusive. - /// - public int A0 { get; set; } - - /// - /// Gets or sets the max alpha value, inclusive. - /// - public int A1 { get; set; } - - /// - /// Gets or sets the volume. - /// - public int Volume { get; set; } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Quantization/QuantizerBase{TPixel}.cs b/src/ImageSharp/Processing/Quantization/FrameQuantizers/FrameQuantizerBase{TPixel}.cs similarity index 82% rename from src/ImageSharp/Processing/Quantization/QuantizerBase{TPixel}.cs rename to src/ImageSharp/Processing/Quantization/FrameQuantizers/FrameQuantizerBase{TPixel}.cs index 96763195d2..5f0510627c 100644 --- a/src/ImageSharp/Processing/Quantization/QuantizerBase{TPixel}.cs +++ b/src/ImageSharp/Processing/Quantization/FrameQuantizers/FrameQuantizerBase{TPixel}.cs @@ -6,16 +6,15 @@ using System.Collections.Generic; using System.Numerics; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Dithering; using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; -namespace SixLabors.ImageSharp.Processing.Quantization +namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers { /// - /// Encapsulates methods to calculate the color palette of an image. + /// The base class for all implementations /// /// The pixel format. - public abstract class QuantizerBase : IQuantizer + public abstract class FrameQuantizerBase : IFrameQuantizer where TPixel : struct, IPixel { /// @@ -24,29 +23,35 @@ namespace SixLabors.ImageSharp.Processing.Quantization private readonly bool singlePass; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// + /// The quantizer /// - /// If true, the quantization only needs to loop through the source pixels once + /// If true, the quantization process only needs to loop through the source pixels once /// /// /// If you construct this class with a true value for singlePass, then the code will, when quantizing your image, - /// only call the 'QuantizeImage' function. If two passes are required, the code will call 'InitialQuantizeImage' + /// only call the methods. + /// If two passes are required, the code will also call /// and then 'QuantizeImage'. /// - protected QuantizerBase(bool singlePass) + protected FrameQuantizerBase(IQuantizer quantizer, bool singlePass) { + Guard.NotNull(quantizer, nameof(quantizer)); + + this.Dither = quantizer.Dither; + this.DitherType = quantizer.DitherType; this.singlePass = singlePass; } /// - public bool Dither { get; set; } = true; + public bool Dither { get; } /// - public IErrorDiffuser DitherType { get; set; } = DiffuseMode.FloydSteinberg; + public IErrorDiffuser DitherType { get; } /// - public virtual QuantizedFrame Quantize(ImageFrame image, int maxColors) + public virtual QuantizedFrame QuantizeFrame(ImageFrame image) { Guard.NotNull(image, nameof(image)); diff --git a/src/ImageSharp/Processing/Quantization/FrameQuantizers/IFrameQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Quantization/FrameQuantizers/IFrameQuantizer{TPixel}.cs new file mode 100644 index 0000000000..0972a636a3 --- /dev/null +++ b/src/ImageSharp/Processing/Quantization/FrameQuantizers/IFrameQuantizer{TPixel}.cs @@ -0,0 +1,35 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; + +namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers +{ + /// + /// Provides methods to allow the execution of the quantization process on an image frame. + /// + /// The pixel format. + public interface IFrameQuantizer + where TPixel : struct, IPixel + { + /// + /// Gets a value indicating whether to apply dithering to the output image. + /// + bool Dither { get; } + + /// + /// Gets the dithering algorithm to apply to the output image. + /// + IErrorDiffuser DitherType { get; } + + /// + /// Quantize an image frame and return the resulting output pixels. + /// + /// The image to quantize. + /// + /// A representing a quantized version of the image pixels. + /// + QuantizedFrame QuantizeFrame(ImageFrame image); + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Quantization/OctreeQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Quantization/FrameQuantizers/OctreeFrameQuantizer{TPixel}.cs similarity index 96% rename from src/ImageSharp/Processing/Quantization/OctreeQuantizer{TPixel}.cs rename to src/ImageSharp/Processing/Quantization/FrameQuantizers/OctreeFrameQuantizer{TPixel}.cs index 5d81049371..56a6c7240a 100644 --- a/src/ImageSharp/Processing/Quantization/OctreeQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Quantization/FrameQuantizers/OctreeFrameQuantizer{TPixel}.cs @@ -8,14 +8,14 @@ using System.Runtime.InteropServices; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Quantization +namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers { /// /// Encapsulates methods to calculate the color palette if an image using an Octree pattern. /// /// /// The pixel format. - public sealed class OctreeQuantizer : QuantizerBase + internal sealed class OctreeFrameQuantizer : FrameQuantizerBase where TPixel : struct, IPixel { /// @@ -24,14 +24,14 @@ namespace SixLabors.ImageSharp.Processing.Quantization private readonly Dictionary colorMap = new Dictionary(); /// - /// Stores the tree + /// Maximum allowed color depth /// - private Octree octree; + private readonly byte colors; /// - /// Maximum allowed color depth + /// Stores the tree /// - private byte colors; + private readonly Octree octree; /// /// The reduced image palette @@ -44,26 +44,18 @@ namespace SixLabors.ImageSharp.Processing.Quantization private byte transparentIndex; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// + /// The octree quantizer /// /// The Octree quantizer is a two pass algorithm. The initial pass sets up the Octree, /// the second pass quantizes a color based on the nodes in the tree /// - public OctreeQuantizer() - : base(false) + public OctreeFrameQuantizer(OctreeQuantizer quantizer) + : base(quantizer, false) { - } - - /// - public override QuantizedFrame Quantize(ImageFrame image, int maxColors) - { - this.colors = (byte)maxColors.Clamp(1, 255); + this.colors = (byte)quantizer.MaxColors; this.octree = new Octree(this.GetBitsNeededForColorDepth(this.colors)); - this.palette = null; - this.colorMap.Clear(); - - return base.Quantize(image, this.colors); } /// @@ -322,7 +314,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization } // Now palletize the nodes - TPixel[] palette = new TPixel[colorCount + 1]; + var palette = new TPixel[colorCount + 1]; int paletteIndex = 0; this.root.ConstructPalette(palette, ref paletteIndex); diff --git a/src/ImageSharp/Processing/Quantization/PaletteQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Quantization/FrameQuantizers/PaletteFrameQuantizer{TPixel}.cs similarity index 76% rename from src/ImageSharp/Processing/Quantization/PaletteQuantizer{TPixel}.cs rename to src/ImageSharp/Processing/Quantization/FrameQuantizers/PaletteFrameQuantizer{TPixel}.cs index 8955e14dd4..141c1afa05 100644 --- a/src/ImageSharp/Processing/Quantization/PaletteQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Quantization/FrameQuantizers/PaletteFrameQuantizer{TPixel}.cs @@ -7,15 +7,14 @@ using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Quantization +namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers { /// /// Encapsulates methods to create a quantized image based upon the given palette. - /// If no palette is given this will default to the web safe colors defined in the CSS Color Module Level 4. /// /// /// The pixel format. - public sealed class PaletteQuantizer : QuantizerBase + internal sealed class PaletteFrameQuantizer : FrameQuantizerBase where TPixel : struct, IPixel { /// @@ -26,33 +25,16 @@ namespace SixLabors.ImageSharp.Processing.Quantization /// /// List of all colors in the palette /// - private TPixel[] colors; + private readonly TPixel[] colors; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public PaletteQuantizer() - : this(NamedColors.WebSafePalette) + /// The palette quantizer + public PaletteFrameQuantizer(PaletteQuantizer quantizer) + : base(quantizer, true) { - } - - /// - /// Initializes a new instance of the class. - /// - /// The palette to select substitute colors from. - public PaletteQuantizer(TPixel[] palette = null) - : base(true) - { - Guard.NotNull(palette, nameof(palette)); - this.colors = palette; - } - - /// - public override QuantizedFrame Quantize(ImageFrame image, int maxColors) - { - Array.Resize(ref this.colors, maxColors.Clamp(1, 255)); - this.colorMap.Clear(); - return base.Quantize(image, maxColors); + this.colors = quantizer.GetPalette(); } /// diff --git a/src/ImageSharp/Processing/Quantization/WuQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs similarity index 94% rename from src/ImageSharp/Processing/Quantization/WuQuantizer{TPixel}.cs rename to src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs index 0c2371cf39..6adb38d2ee 100644 --- a/src/ImageSharp/Processing/Quantization/WuQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs @@ -10,7 +10,7 @@ using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; -namespace SixLabors.ImageSharp.Processing.Quantization +namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers { /// /// An implementation of Wu's color quantizer with alpha channel. @@ -32,10 +32,10 @@ namespace SixLabors.ImageSharp.Processing.Quantization /// /// /// The pixel format. - public class WuQuantizer : QuantizerBase + internal sealed class WuFrameQuantizer : FrameQuantizerBase where TPixel : struct, IPixel { - // TODO: The WuQuantizer code is rising several questions: + // TODO: The WuFrameQuantizer code is rising several questions: // - Do we really need to ALWAYS allocate the whole table of size TableLength? (~ 2471625 * sizeof(long) * 5 bytes ) // - Isn't an AOS ("array of structures") layout more efficient & more readable than SOA ("structure of arrays") for this particular use case? // (T, R, G, B, A, M2) could be grouped together! @@ -124,26 +124,23 @@ namespace SixLabors.ImageSharp.Processing.Quantization private Box[] colorCube; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// + /// The wu quantizer /// /// The Wu quantizer is a two pass algorithm. The initial pass sets up the 3-D color histogram, /// the second pass quantizes a color based on the position in the histogram. /// - public WuQuantizer() - : base(false) + public WuFrameQuantizer(WuQuantizer quantizer) + : base(quantizer, false) { + this.colors = quantizer.MaxColors; } /// - public override QuantizedFrame Quantize(ImageFrame image, int maxColors) + public override QuantizedFrame QuantizeFrame(ImageFrame image) { Guard.NotNull(image, nameof(image)); - - this.colors = maxColors.Clamp(1, 255); - this.palette = null; - this.colorMap.Clear(); - MemoryManager memoryManager = image.MemoryManager; try @@ -156,7 +153,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization this.m2 = memoryManager.AllocateClean(TableLength); this.tag = memoryManager.AllocateClean(TableLength); - return base.Quantize(image, this.colors); + return base.QuantizeFrame(image); } finally { @@ -873,5 +870,56 @@ namespace SixLabors.ImageSharp.Processing.Quantization return tagSpan[GetPaletteIndex(r + 1, g + 1, b + 1, a + 1)]; } + + /// + /// Represents a box color cube. + /// + private struct Box + { + /// + /// Gets or sets the min red value, exclusive. + /// + public int R0; + + /// + /// Gets or sets the max red value, inclusive. + /// + public int R1; + + /// + /// Gets or sets the min green value, exclusive. + /// + public int G0; + + /// + /// Gets or sets the max green value, inclusive. + /// + public int G1; + + /// + /// Gets or sets the min blue value, exclusive. + /// + public int B0; + + /// + /// Gets or sets the max blue value, inclusive. + /// + public int B1; + + /// + /// Gets or sets the min alpha value, exclusive. + /// + public int A0; + + /// + /// Gets or sets the max alpha value, inclusive. + /// + public int A1; + + /// + /// Gets or sets the volume. + /// + public int Volume; + } } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Quantization/IQuantizer.cs b/src/ImageSharp/Processing/Quantization/IQuantizer.cs new file mode 100644 index 0000000000..2eb872a4f0 --- /dev/null +++ b/src/ImageSharp/Processing/Quantization/IQuantizer.cs @@ -0,0 +1,33 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; +using SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers; + +namespace SixLabors.ImageSharp.Processing.Quantization +{ + /// + /// Provides methods for allowing quantization of images pixels with configurable dithering. + /// + public interface IQuantizer + { + /// + /// Gets a value indicating whether to apply dithering to the output image. + /// + bool Dither { get; } + + /// + /// Gets the dithering algorithm to apply to the output image. + /// + IErrorDiffuser DitherType { get; } + + /// + /// Creates the generic frame quantizer + /// + /// The pixel format. + /// The + IFrameQuantizer CreateFrameQuantizer() + where TPixel : struct, IPixel; + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Quantization/IQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Quantization/IQuantizer{TPixel}.cs deleted file mode 100644 index 841b84496b..0000000000 --- a/src/ImageSharp/Processing/Quantization/IQuantizer{TPixel}.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; - -namespace SixLabors.ImageSharp.Processing.Quantization -{ - /// - /// Provides methods for for allowing quantization of images pixels with configurable dithering. - /// - /// The pixel format. - public interface IQuantizer : IQuantizer - where TPixel : struct, IPixel - { - /// - /// Quantize an image and return the resulting output pixels. - /// - /// The image to quantize. - /// The maximum number of colors to return. - /// - /// A representing a quantized version of the image pixels. - /// - QuantizedFrame Quantize(ImageFrame image, int maxColors); - } - - /// - /// Provides methods for allowing quantization of images pixels with configurable dithering. - /// - public interface IQuantizer - { - /// - /// Gets or sets a value indicating whether to apply dithering to the output image. - /// - bool Dither { get; set; } - - /// - /// Gets or sets the dithering algorithm to apply to the output image. - /// - IErrorDiffuser DitherType { get; set; } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Quantization/OctreeQuantizer.cs b/src/ImageSharp/Processing/Quantization/OctreeQuantizer.cs new file mode 100644 index 0000000000..acc5943c30 --- /dev/null +++ b/src/ImageSharp/Processing/Quantization/OctreeQuantizer.cs @@ -0,0 +1,75 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Dithering; +using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; +using SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers; + +namespace SixLabors.ImageSharp.Processing.Quantization +{ + /// + /// Allows the quantization of images pixels using Octrees. + /// + /// + public class OctreeQuantizer : IQuantizer + { + /// + /// Initializes a new instance of the class. + /// + public OctreeQuantizer() + : this(255) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Whether to apply dithering to the output image + public OctreeQuantizer(bool dither) + : this(dither, DiffuseMode.FloydSteinberg, 255) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The maximum number of colors to hold in the color palette + public OctreeQuantizer(int maxColors) + : this(true, DiffuseMode.FloydSteinberg, maxColors) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Whether to apply dithering to the output image + /// The dithering algorithm to apply to the output image + /// The maximum number of colors to hold in the color palette + public OctreeQuantizer(bool dither, IErrorDiffuser ditherType, int maxColors) + { + Guard.NotNull(ditherType, nameof(ditherType)); + Guard.MustBeBetweenOrEqualTo(maxColors, 1, 255, nameof(maxColors)); + + this.Dither = dither; + this.DitherType = ditherType; + this.MaxColors = maxColors; + } + + /// + public bool Dither { get; } + + /// + public IErrorDiffuser DitherType { get; } + + /// + /// Gets the maximum number of colors to hold in the color palette. + /// + public int MaxColors { get; } + + /// + public IFrameQuantizer CreateFrameQuantizer() + where TPixel : struct, IPixel + => new OctreeFrameQuantizer(this); + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Quantization/PaletteQuantizer.cs b/src/ImageSharp/Processing/Quantization/PaletteQuantizer.cs new file mode 100644 index 0000000000..ccdfae9a1e --- /dev/null +++ b/src/ImageSharp/Processing/Quantization/PaletteQuantizer.cs @@ -0,0 +1,68 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Dithering; +using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; +using SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers; + +namespace SixLabors.ImageSharp.Processing.Quantization +{ + /// + /// Allows the quantization of images pixels using web safe colors defined in the CSS Color Module Level 4. + /// + /// Override this class to provide your own palette. + /// + public class PaletteQuantizer : IQuantizer + { + /// + /// Initializes a new instance of the class. + /// + public PaletteQuantizer() + : this(true, DiffuseMode.FloydSteinberg) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Whether to apply dithering to the output image + public PaletteQuantizer(bool dither) + : this(dither, DiffuseMode.FloydSteinberg) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Whether to apply dithering to the output image + /// The dithering algorithm to apply to the output image + public PaletteQuantizer(bool dither, IErrorDiffuser ditherType) + { + Guard.NotNull(ditherType, nameof(ditherType)); + + this.Dither = dither; + this.DitherType = ditherType; + } + + /// + public bool Dither { get; } + + /// + public IErrorDiffuser DitherType { get; } + + /// + /// Gets the palette to use to quantize the image. + /// + /// The pixel format. + /// The + public virtual TPixel[] GetPalette() + where TPixel : struct, IPixel + => NamedColors.WebSafePalette; + + /// + public IFrameQuantizer CreateFrameQuantizer() + where TPixel : struct, IPixel + => new PaletteFrameQuantizer(this); + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Quantization/Processors/QuantizeProcessor.cs b/src/ImageSharp/Processing/Quantization/Processors/QuantizeProcessor.cs index e6b1099937..951e471273 100644 --- a/src/ImageSharp/Processing/Quantization/Processors/QuantizeProcessor.cs +++ b/src/ImageSharp/Processing/Quantization/Processors/QuantizeProcessor.cs @@ -2,16 +2,16 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Threading.Tasks; -using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Processing.Quantization.Processors { /// - /// Enables the quantization of images to remove the number of colors used in the image palette. + /// Enables the quantization of images to reduce the number of colors used in the image palette. /// /// The pixel format. internal class QuantizeProcessor : ImageProcessor @@ -21,51 +21,38 @@ namespace SixLabors.ImageSharp.Processing.Quantization.Processors /// Initializes a new instance of the class. /// /// The quantizer used to reduce the color palette - /// The maximum number of colors to reduce the palette to - public QuantizeProcessor(IQuantizer quantizer, int maxColors) + public QuantizeProcessor(IQuantizer quantizer) { Guard.NotNull(quantizer, nameof(quantizer)); - Guard.MustBeGreaterThan(maxColors, 0, nameof(maxColors)); - this.Quantizer = quantizer; - this.MaxColors = maxColors; } /// /// Gets the quantizer /// - public IQuantizer Quantizer { get; } - - /// - /// Gets the maximum number of palette colors - /// - public int MaxColors { get; } + public IQuantizer Quantizer { get; } /// protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { - QuantizedFrame quantized = this.Quantizer.Quantize(source, this.MaxColors); + IFrameQuantizer executor = this.Quantizer.CreateFrameQuantizer(); + QuantizedFrame quantized = executor.QuantizeFrame(source); int paletteCount = quantized.Palette.Length - 1; - using (Buffer2D pixels = source.MemoryManager.Allocate2D(quantized.Width, quantized.Height)) + // Not parallel to remove "quantized" closure allocation. + // We can operate directly on the source here as we've already read it to get the + // quantized result + for (int y = 0; y < source.Height; y++) { - Parallel.For( - 0, - pixels.Height, - configuration.ParallelOptions, - y => - { - Span row = pixels.GetRowSpan(y); - int yy = y * pixels.Width; - for (int x = 0; x < pixels.Width; x++) - { - int i = x + yy; - TPixel color = quantized.Palette[Math.Min(paletteCount, quantized.Pixels[i])]; - row[x] = color; - } - }); - - Buffer2D.SwapContents(source.PixelBuffer, pixels); + Span row = source.GetPixelRowSpan(y); + int yy = y * source.Width; + + for (int x = 0; x < source.Width; x++) + { + int i = x + yy; + TPixel color = quantized.Palette[Math.Min(paletteCount, quantized.Pixels[i])]; + row[x] = color; + } } } } diff --git a/src/ImageSharp/Processing/Quantization/QuantizationMode.cs b/src/ImageSharp/Processing/Quantization/QuantizationMode.cs index 69857b3844..45a085c01f 100644 --- a/src/ImageSharp/Processing/Quantization/QuantizationMode.cs +++ b/src/ImageSharp/Processing/Quantization/QuantizationMode.cs @@ -4,26 +4,26 @@ namespace SixLabors.ImageSharp.Processing.Quantization { /// - /// Provides enumeration over how an image should be quantized. + /// Contains reusable static instances of known quantizing algorithms /// - public enum QuantizationMode + public static class QuantizationMode { /// - /// An adaptive Octree quantizer. Fast with good quality. + /// Gets the adaptive Octree quantizer. Fast with good quality. /// The quantizer only supports a single alpha value. /// - Octree, + public static IQuantizer Octree { get; } = new OctreeQuantizer(); /// - /// Xiaolin Wu's Color Quantizer which generates high quality output. + /// Gets the Xiaolin Wu's Color Quantizer which generates high quality output. /// The quantizer supports multiple alpha values. /// - Wu, + public static IQuantizer Wu { get; } = new WuQuantizer(); /// - /// Palette based, Uses the collection of web-safe colors by default. + /// Gets the palette based, Using the collection of web-safe colors. /// The quantizer supports multiple alpha values. /// - Palette + public static IQuantizer Palette { get; } = new PaletteQuantizer(); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Quantization/QuantizeExtensions.cs b/src/ImageSharp/Processing/Quantization/QuantizeExtensions.cs index 2b367ffe95..0583c176b0 100644 --- a/src/ImageSharp/Processing/Quantization/QuantizeExtensions.cs +++ b/src/ImageSharp/Processing/Quantization/QuantizeExtensions.cs @@ -12,34 +12,14 @@ namespace SixLabors.ImageSharp.Processing.Quantization public static class QuantizeExtensions { /// - /// Applies quantization to the image. + /// Applies quantization to the image using the . /// /// The pixel format. /// The image this method extends. - /// The quantization mode to apply to perform the operation. - /// The maximum number of colors to return. Defaults to 256. /// The . - public static IImageProcessingContext Quantize(this IImageProcessingContext source, QuantizationMode mode = QuantizationMode.Octree, int maxColors = 256) + public static IImageProcessingContext Quantize(this IImageProcessingContext source) where TPixel : struct, IPixel - { - IQuantizer quantizer; - switch (mode) - { - case QuantizationMode.Wu: - quantizer = new WuQuantizer(); - break; - - case QuantizationMode.Palette: - quantizer = new PaletteQuantizer(); - break; - - default: - quantizer = new OctreeQuantizer(); - break; - } - - return Quantize(source, quantizer, maxColors); - } + => Quantize(source, QuantizationMode.Octree); /// /// Applies quantization to the image. @@ -47,10 +27,9 @@ namespace SixLabors.ImageSharp.Processing.Quantization /// The pixel format. /// The image this method extends. /// The quantizer to apply to perform the operation. - /// The maximum number of colors to return. /// The . - public static IImageProcessingContext Quantize(this IImageProcessingContext source, IQuantizer quantizer, int maxColors) + public static IImageProcessingContext Quantize(this IImageProcessingContext source, IQuantizer quantizer) where TPixel : struct, IPixel - => source.ApplyProcessor(new QuantizeProcessor(quantizer, maxColors)); + => source.ApplyProcessor(new QuantizeProcessor(quantizer)); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Quantization/WuQuantizer.cs b/src/ImageSharp/Processing/Quantization/WuQuantizer.cs new file mode 100644 index 0000000000..0d306107e9 --- /dev/null +++ b/src/ImageSharp/Processing/Quantization/WuQuantizer.cs @@ -0,0 +1,75 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Dithering; +using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion; +using SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers; + +namespace SixLabors.ImageSharp.Processing.Quantization +{ + /// + /// Allows the quantization of images pixels using Xiaolin Wu's Color Quantizer. + /// + /// + public class WuQuantizer : IQuantizer + { + /// + /// Initializes a new instance of the class. + /// + public WuQuantizer() + : this(255) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Whether to apply dithering to the output image + public WuQuantizer(bool dither) + : this(dither, DiffuseMode.FloydSteinberg, 255) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The maximum number of colors to hold in the color palette + public WuQuantizer(int maxColors) + : this(true, DiffuseMode.FloydSteinberg, maxColors) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Whether to apply dithering to the output image + /// The dithering algorithm to apply to the output image + /// The maximum number of colors to hold in the color palette + public WuQuantizer(bool dither, IErrorDiffuser ditherType, int maxColors) + { + Guard.NotNull(ditherType, nameof(ditherType)); + Guard.MustBeBetweenOrEqualTo(maxColors, 1, 255, nameof(maxColors)); + + this.Dither = dither; + this.DitherType = ditherType; + this.MaxColors = maxColors; + } + + /// + public bool Dither { get; } + + /// + public IErrorDiffuser DitherType { get; } + + /// + /// Gets the maximum number of colors to hold in the color palette. + /// + public int MaxColors { get; } + + /// + public IFrameQuantizer CreateFrameQuantizer() + where TPixel : struct, IPixel + => new WuFrameQuantizer(this); + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs b/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs index a4cc06e25f..bed826c10a 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs @@ -3,20 +3,15 @@ // Licensed under the Apache License, Version 2.0. // +using System.IO; +using BenchmarkDotNet.Attributes; +using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Quantization; +using CoreImage = SixLabors.ImageSharp.Image; namespace SixLabors.ImageSharp.Benchmarks.Image { - using System.IO; - - using BenchmarkDotNet.Attributes; - - using SixLabors.ImageSharp; - using SixLabors.ImageSharp.Formats.Png; - using SixLabors.ImageSharp.Processing.Quantization; - - using CoreImage = ImageSharp.Image; - /// /// Benchmarks saving png files using different quantizers. System.Drawing cannot save indexed png files so we cannot compare. /// @@ -35,8 +30,9 @@ namespace SixLabors.ImageSharp.Benchmarks.Image if (this.bmpStream == null) { string path = this.LargeImage - ? "../ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg420exif.jpg" - : "../ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp"; + ? "../ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg420exif.jpg" + : "../ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp"; + this.bmpStream = File.OpenRead(path); this.bmpCore = CoreImage.Load(this.bmpStream); this.bmpStream.Position = 0; @@ -53,20 +49,20 @@ namespace SixLabors.ImageSharp.Benchmarks.Image [Benchmark(Baseline = true, Description = "ImageSharp Octree Png")] public void PngCoreOctree() { - using (MemoryStream memoryStream = new MemoryStream()) + using (var memoryStream = new MemoryStream()) { - PngEncoder encoder = new PngEncoder() { Quantizer = new OctreeQuantizer(), PaletteSize = 256 }; + var encoder = new PngEncoder { Quantizer = new OctreeQuantizer() }; this.bmpCore.SaveAsPng(memoryStream, encoder); } } [Benchmark(Description = "ImageSharp Octree NoDither Png")] - public void PngCoreOctreeNoDIther() + public void PngCoreOctreeNoDither() { - using (MemoryStream memoryStream = new MemoryStream()) + using (var memoryStream = new MemoryStream()) { - PngEncoder options = new PngEncoder() { Quantizer = new OctreeQuantizer { Dither = false }, PaletteSize = 256 }; + var options = new PngEncoder { Quantizer = new OctreeQuantizer(false) }; this.bmpCore.SaveAsPng(memoryStream, options); } @@ -75,9 +71,9 @@ namespace SixLabors.ImageSharp.Benchmarks.Image [Benchmark(Description = "ImageSharp Palette Png")] public void PngCorePalette() { - using (MemoryStream memoryStream = new MemoryStream()) + using (var memoryStream = new MemoryStream()) { - PngEncoder options = new PngEncoder() { Quantizer = new PaletteQuantizer(), PaletteSize = 256 }; + var options = new PngEncoder { Quantizer = new PaletteQuantizer() }; this.bmpCore.SaveAsPng(memoryStream, options); } @@ -86,9 +82,9 @@ namespace SixLabors.ImageSharp.Benchmarks.Image [Benchmark(Description = "ImageSharp Palette NoDither Png")] public void PngCorePaletteNoDither() { - using (MemoryStream memoryStream = new MemoryStream()) + using (var memoryStream = new MemoryStream()) { - PngEncoder options = new PngEncoder() { Quantizer = new PaletteQuantizer { Dither = false }, PaletteSize = 256 }; + var options = new PngEncoder { Quantizer = new PaletteQuantizer(false) }; this.bmpCore.SaveAsPng(memoryStream, options); } @@ -97,9 +93,20 @@ namespace SixLabors.ImageSharp.Benchmarks.Image [Benchmark(Description = "ImageSharp Wu Png")] public void PngCoreWu() { - using (MemoryStream memoryStream = new MemoryStream()) + using (var memoryStream = new MemoryStream()) + { + var options = new PngEncoder { Quantizer = new WuQuantizer() }; + + this.bmpCore.SaveAsPng(memoryStream, options); + } + } + + [Benchmark(Description = "ImageSharp Wu NoDither Png")] + public void PngCoreWuNoDither() + { + using (var memoryStream = new MemoryStream()) { - PngEncoder options = new PngEncoder() { Quantizer = new WuQuantizer(), PaletteSize = 256 }; + var options = new PngEncoder { Quantizer = new WuQuantizer(false) }; this.bmpCore.SaveAsPng(memoryStream, options); } diff --git a/tests/ImageSharp.Benchmarks/Image/EncodePng.cs b/tests/ImageSharp.Benchmarks/Image/EncodePng.cs index ffd810f289..4fc84ba618 100644 --- a/tests/ImageSharp.Benchmarks/Image/EncodePng.cs +++ b/tests/ImageSharp.Benchmarks/Image/EncodePng.cs @@ -70,12 +70,12 @@ namespace SixLabors.ImageSharp.Benchmarks.Image { using (var memoryStream = new MemoryStream()) { - QuantizerBase quantizer = this.UseOctreeQuantizer - ? (QuantizerBase) - new OctreeQuantizer() - : new PaletteQuantizer(); + IQuantizer quantizer = this.UseOctreeQuantizer + ? + (IQuantizer)new OctreeQuantizer() + : new PaletteQuantizer(); - var options = new PngEncoder() { Quantizer = quantizer }; + var options = new PngEncoder { Quantizer = quantizer }; this.bmpCore.SaveAsPng(memoryStream, options); } } diff --git a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs index 7f983e1e42..9a7b9413e7 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs @@ -7,6 +7,8 @@ using System.Linq; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing.Quantization; + using Xunit; // ReSharper disable InconsistentNaming @@ -22,31 +24,31 @@ namespace SixLabors.ImageSharp.Tests /// /// All types except Palette /// - public static readonly TheoryData PngColorTypes = new TheoryData() - { - PngColorType.RgbWithAlpha, - PngColorType.Rgb, - PngColorType.Grayscale, - PngColorType.GrayscaleWithAlpha, - }; + public static readonly TheoryData PngColorTypes = new TheoryData + { + PngColorType.RgbWithAlpha, + PngColorType.Rgb, + PngColorType.Grayscale, + PngColorType.GrayscaleWithAlpha, + }; /// /// All types except Palette /// - public static readonly TheoryData CompressionLevels = new TheoryData() - { - 1, 2, 3, 4, 5, 6, 7, 8, 9 - }; + public static readonly TheoryData CompressionLevels = new TheoryData + { + 1, 2, 3, 4, 5, 6, 7, 8, 9 + }; - public static readonly TheoryData PaletteSizes = new TheoryData() + public static readonly TheoryData PaletteSizes = new TheoryData { - 30, 55, 100, 201, 255 - }; + 30, 55, 100, 201, 255 + }; - public static readonly TheoryData PaletteLargeOnly = new TheoryData() - { - 80, 100, 120, 230 - }; + public static readonly TheoryData PaletteLargeOnly = new TheoryData + { + 80, 100, 120, 230 + }; [Theory] [WithFile(TestImages.Png.Palette8Bpp, nameof(PngColorTypes), PixelTypes.Rgba32)] @@ -60,7 +62,7 @@ namespace SixLabors.ImageSharp.Tests { TestPngEncoderCore(provider, pngColorType, appendPngColorType: true); } - + [Theory] [WithTestPatternImages(nameof(PngColorTypes), 24, 24, PixelTypes.Rgba32 | PixelTypes.Bgra32 | PixelTypes.Rgb24)] public void IsNotBoundToSinglePixelType(TestImageProvider provider, PngColorType pngColorType) @@ -76,7 +78,7 @@ namespace SixLabors.ImageSharp.Tests { TestPngEncoderCore(provider, PngColorType.RgbWithAlpha, compressionLevel, appendCompressionLevel: true); } - + [Theory] [WithFile(TestImages.Png.Palette8Bpp, nameof(PaletteLargeOnly), PixelTypes.Rgba32)] public void PaletteColorType_WuQuantizer(TestImageProvider provider, int paletteSize) @@ -92,7 +94,7 @@ namespace SixLabors.ImageSharp.Tests TestImageProvider provider, PngColorType pngColorType, int compressionLevel = 6, - int paletteSize = 0, + int paletteSize = 255, bool appendPngColorType = false, bool appendPixelType = false, bool appendCompressionLevel = false, @@ -107,11 +109,11 @@ namespace SixLabors.ImageSharp.Tests } var encoder = new PngEncoder - { - PngColorType = pngColorType, - CompressionLevel = compressionLevel, - PaletteSize = paletteSize - }; + { + PngColorType = pngColorType, + CompressionLevel = compressionLevel, + Quantizer = new WuQuantizer(paletteSize) + }; string pngColorTypeInfo = appendPngColorType ? pngColorType.ToString() : ""; string compressionLevelInfo = appendCompressionLevel ? $"_C{compressionLevel}" : ""; @@ -121,10 +123,10 @@ namespace SixLabors.ImageSharp.Tests // Does DebugSave & load reference CompareToReferenceInput(): string actualOutputFile = ((ITestImageProvider)provider).Utility.SaveTestOutputFile(image, "png", encoder, debugInfo, appendPixelType); - + IImageDecoder referenceDecoder = TestEnvironment.GetReferenceDecoder(actualOutputFile); string referenceOutputFile = ((ITestImageProvider)provider).Utility.GetReferenceOutputFileName("png", debugInfo, appendPixelType); - + using (var actualImage = Image.Load(actualOutputFile, referenceDecoder)) using (var referenceImage = Image.Load(referenceOutputFile, referenceDecoder)) { @@ -136,7 +138,7 @@ namespace SixLabors.ImageSharp.Tests } } } - + [Theory] [WithBlankImages(1, 1, PixelTypes.Rgba32)] public void WritesFileMarker(TestImageProvider provider) @@ -146,8 +148,8 @@ namespace SixLabors.ImageSharp.Tests using (var ms = new MemoryStream()) { image.Save(ms, new PngEncoder()); - - byte[] data = ms.ToArray().Take(8).ToArray(); + + byte[] data = ms.ToArray().Take(8).ToArray(); byte[] expected = { 0x89, // Set the high bit. 0x50, // P diff --git a/tests/ImageSharp.Tests/Image/ImageFramesCollectionTests.cs b/tests/ImageSharp.Tests/Image/ImageFramesCollectionTests.cs index 1f2137070f..987805ca15 100644 --- a/tests/ImageSharp.Tests/Image/ImageFramesCollectionTests.cs +++ b/tests/ImageSharp.Tests/Image/ImageFramesCollectionTests.cs @@ -69,7 +69,7 @@ namespace SixLabors.ImageSharp.Tests this.collection.AddFrame(new Rgba32[0]); }); - Assert.StartsWith("Value must be greater than or equal to 100.", ex.Message); + Assert.StartsWith("Value 0 must be greater than or equal to 100.", ex.Message); } [Fact] diff --git a/tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs b/tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs index 8ca04ac23c..15d2bf51f7 100644 --- a/tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs +++ b/tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs @@ -10,9 +10,9 @@ [Fact] public void QuantizersDitherByDefault() { - var palette = new PaletteQuantizer(); - var octree = new OctreeQuantizer(); - var wu = new WuQuantizer(); + var palette = new PaletteQuantizer(); + var octree = new OctreeQuantizer(); + var wu = new WuQuantizer(); Assert.True(palette.Dither); Assert.True(octree.Dither); @@ -29,11 +29,11 @@ { Assert.True(image[0, 0].Equals(default(TPixel))); - IQuantizer quantizer = new PaletteQuantizer { Dither = dither }; + var quantizer = new PaletteQuantizer(dither); foreach (ImageFrame frame in image.Frames) { - QuantizedFrame quantized = quantizer.Quantize(frame, 256); + QuantizedFrame quantized = quantizer.CreateFrameQuantizer().QuantizeFrame(frame); int index = this.GetTransparentIndex(quantized); Assert.Equal(index, quantized.Pixels[0]); @@ -51,11 +51,11 @@ { Assert.True(image[0, 0].Equals(default(TPixel))); - IQuantizer quantizer = new OctreeQuantizer { Dither = dither }; + var quantizer = new OctreeQuantizer(dither); foreach (ImageFrame frame in image.Frames) { - QuantizedFrame quantized = quantizer.Quantize(frame, 256); + QuantizedFrame quantized = quantizer.CreateFrameQuantizer().QuantizeFrame(frame); int index = this.GetTransparentIndex(quantized); Assert.Equal(index, quantized.Pixels[0]); @@ -73,11 +73,11 @@ { Assert.True(image[0, 0].Equals(default(TPixel))); - IQuantizer quantizer = new WuQuantizer() { Dither = dither }; + var quantizer = new WuQuantizer(dither); foreach (ImageFrame frame in image.Frames) { - QuantizedFrame quantized = quantizer.Quantize(frame, 256); + QuantizedFrame quantized = quantizer.CreateFrameQuantizer().QuantizeFrame(frame); int index = this.GetTransparentIndex(quantized); Assert.Equal(index, quantized.Pixels[0]); From a7f2bd97925a04b213923c18f782b182282c6957 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Thu, 15 Mar 2018 11:16:47 +1100 Subject: [PATCH 2/5] Drop Dither property from interface, rename diffuser. --- .../FrameQuantizerBase{TPixel}.cs | 6 ++-- .../IFrameQuantizer{TPixel}.cs | 4 +-- .../OctreeFrameQuantizer{TPixel}.cs | 2 +- .../PaletteFrameQuantizer{TPixel}.cs | 2 +- .../WuFrameQuantizer{TPixel}.cs | 2 +- .../Processing/Quantization/IQuantizer.cs | 9 ++--- .../Quantization/OctreeQuantizer.cs | 35 +++++++++++-------- .../Quantization/PaletteQuantizer.cs | 21 +++++------ .../Processing/Quantization/WuQuantizer.cs | 35 +++++++++++-------- .../Quantization/QuantizedImageTests.cs | 10 ++++-- 10 files changed, 65 insertions(+), 61 deletions(-) diff --git a/src/ImageSharp/Processing/Quantization/FrameQuantizers/FrameQuantizerBase{TPixel}.cs b/src/ImageSharp/Processing/Quantization/FrameQuantizers/FrameQuantizerBase{TPixel}.cs index 5f0510627c..bf0d80b07c 100644 --- a/src/ImageSharp/Processing/Quantization/FrameQuantizers/FrameQuantizerBase{TPixel}.cs +++ b/src/ImageSharp/Processing/Quantization/FrameQuantizers/FrameQuantizerBase{TPixel}.cs @@ -39,8 +39,8 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers { Guard.NotNull(quantizer, nameof(quantizer)); - this.Dither = quantizer.Dither; - this.DitherType = quantizer.DitherType; + this.Diffuser = quantizer.Diffuser; + this.Dither = this.Diffuser != null; this.singlePass = singlePass; } @@ -48,7 +48,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers public bool Dither { get; } /// - public IErrorDiffuser DitherType { get; } + public IErrorDiffuser Diffuser { get; } /// public virtual QuantizedFrame QuantizeFrame(ImageFrame image) diff --git a/src/ImageSharp/Processing/Quantization/FrameQuantizers/IFrameQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Quantization/FrameQuantizers/IFrameQuantizer{TPixel}.cs index 0972a636a3..435302bd3e 100644 --- a/src/ImageSharp/Processing/Quantization/FrameQuantizers/IFrameQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Quantization/FrameQuantizers/IFrameQuantizer{TPixel}.cs @@ -19,9 +19,9 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers bool Dither { get; } /// - /// Gets the dithering algorithm to apply to the output image. + /// Gets the error diffusion algorithm to apply to the output image. /// - IErrorDiffuser DitherType { get; } + IErrorDiffuser Diffuser { get; } /// /// Quantize an image frame and return the resulting output pixels. diff --git a/src/ImageSharp/Processing/Quantization/FrameQuantizers/OctreeFrameQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Quantization/FrameQuantizers/OctreeFrameQuantizer{TPixel}.cs index 56a6c7240a..431064f220 100644 --- a/src/ImageSharp/Processing/Quantization/FrameQuantizers/OctreeFrameQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Quantization/FrameQuantizers/OctreeFrameQuantizer{TPixel}.cs @@ -121,7 +121,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers if (this.Dither) { // Apply the dithering matrix. We have to reapply the value now as the original has changed. - this.DitherType.Dither(source, sourcePixel, transformedPixel, x, y, 0, 0, width, height); + this.Diffuser.Dither(source, sourcePixel, transformedPixel, x, y, 0, 0, width, height); } output[(y * source.Width) + x] = pixelValue; diff --git a/src/ImageSharp/Processing/Quantization/FrameQuantizers/PaletteFrameQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Quantization/FrameQuantizers/PaletteFrameQuantizer{TPixel}.cs index 141c1afa05..b3a3eee634 100644 --- a/src/ImageSharp/Processing/Quantization/FrameQuantizers/PaletteFrameQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Quantization/FrameQuantizers/PaletteFrameQuantizer{TPixel}.cs @@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers if (this.Dither) { // Apply the dithering matrix. We have to reapply the value now as the original has changed. - this.DitherType.Dither(source, sourcePixel, transformedPixel, x, y, 0, 0, width, height); + this.Diffuser.Dither(source, sourcePixel, transformedPixel, x, y, 0, 0, width, height); } output[(y * source.Width) + x] = pixelValue; diff --git a/src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs index 6adb38d2ee..fbc40dc8a1 100644 --- a/src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs @@ -290,7 +290,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers if (this.Dither) { // Apply the dithering matrix. We have to reapply the value now as the original has changed. - this.DitherType.Dither(source, sourcePixel, transformedPixel, x, y, 0, 0, width, height); + this.Diffuser.Dither(source, sourcePixel, transformedPixel, x, y, 0, 0, width, height); } output[(y * source.Width) + x] = pixelValue; diff --git a/src/ImageSharp/Processing/Quantization/IQuantizer.cs b/src/ImageSharp/Processing/Quantization/IQuantizer.cs index 2eb872a4f0..e00b865ac5 100644 --- a/src/ImageSharp/Processing/Quantization/IQuantizer.cs +++ b/src/ImageSharp/Processing/Quantization/IQuantizer.cs @@ -13,14 +13,9 @@ namespace SixLabors.ImageSharp.Processing.Quantization public interface IQuantizer { /// - /// Gets a value indicating whether to apply dithering to the output image. + /// Gets the error diffusion algorithm to apply to the output image. /// - bool Dither { get; } - - /// - /// Gets the dithering algorithm to apply to the output image. - /// - IErrorDiffuser DitherType { get; } + IErrorDiffuser Diffuser { get; } /// /// Creates the generic frame quantizer diff --git a/src/ImageSharp/Processing/Quantization/OctreeQuantizer.cs b/src/ImageSharp/Processing/Quantization/OctreeQuantizer.cs index acc5943c30..9d27970b14 100644 --- a/src/ImageSharp/Processing/Quantization/OctreeQuantizer.cs +++ b/src/ImageSharp/Processing/Quantization/OctreeQuantizer.cs @@ -18,7 +18,16 @@ namespace SixLabors.ImageSharp.Processing.Quantization /// Initializes a new instance of the class. /// public OctreeQuantizer() - : this(255) + : this(true) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The maximum number of colors to hold in the color palette + public OctreeQuantizer(int maxColors) + : this(GetDiffuser(true), maxColors) { } @@ -27,40 +36,34 @@ namespace SixLabors.ImageSharp.Processing.Quantization /// /// Whether to apply dithering to the output image public OctreeQuantizer(bool dither) - : this(dither, DiffuseMode.FloydSteinberg, 255) + : this(GetDiffuser(dither), 255) { } /// /// Initializes a new instance of the class. /// - /// The maximum number of colors to hold in the color palette - public OctreeQuantizer(int maxColors) - : this(true, DiffuseMode.FloydSteinberg, maxColors) + /// The error diffusion algorithm, if any, to apply to the output image + public OctreeQuantizer(IErrorDiffuser diffuser) + : this(diffuser, 255) { } /// /// Initializes a new instance of the class. /// - /// Whether to apply dithering to the output image - /// The dithering algorithm to apply to the output image + /// The error diffusion algorithm, if any, to apply to the output image /// The maximum number of colors to hold in the color palette - public OctreeQuantizer(bool dither, IErrorDiffuser ditherType, int maxColors) + public OctreeQuantizer(IErrorDiffuser diffuser, int maxColors) { - Guard.NotNull(ditherType, nameof(ditherType)); Guard.MustBeBetweenOrEqualTo(maxColors, 1, 255, nameof(maxColors)); - this.Dither = dither; - this.DitherType = ditherType; + this.Diffuser = diffuser; this.MaxColors = maxColors; } /// - public bool Dither { get; } - - /// - public IErrorDiffuser DitherType { get; } + public IErrorDiffuser Diffuser { get; } /// /// Gets the maximum number of colors to hold in the color palette. @@ -71,5 +74,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization public IFrameQuantizer CreateFrameQuantizer() where TPixel : struct, IPixel => new OctreeFrameQuantizer(this); + + private static IErrorDiffuser GetDiffuser(bool dither) => dither ? DiffuseMode.FloydSteinberg : null; } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Quantization/PaletteQuantizer.cs b/src/ImageSharp/Processing/Quantization/PaletteQuantizer.cs index ccdfae9a1e..f25b6537a7 100644 --- a/src/ImageSharp/Processing/Quantization/PaletteQuantizer.cs +++ b/src/ImageSharp/Processing/Quantization/PaletteQuantizer.cs @@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization /// Initializes a new instance of the class. /// public PaletteQuantizer() - : this(true, DiffuseMode.FloydSteinberg) + : this(true) { } @@ -28,28 +28,21 @@ namespace SixLabors.ImageSharp.Processing.Quantization /// /// Whether to apply dithering to the output image public PaletteQuantizer(bool dither) - : this(dither, DiffuseMode.FloydSteinberg) + : this(GetDiffuser(dither)) { } /// /// Initializes a new instance of the class. /// - /// Whether to apply dithering to the output image - /// The dithering algorithm to apply to the output image - public PaletteQuantizer(bool dither, IErrorDiffuser ditherType) + /// The error diffusion algorithm, if any, to apply to the output image + public PaletteQuantizer(IErrorDiffuser diffuser) { - Guard.NotNull(ditherType, nameof(ditherType)); - - this.Dither = dither; - this.DitherType = ditherType; + this.Diffuser = diffuser; } /// - public bool Dither { get; } - - /// - public IErrorDiffuser DitherType { get; } + public IErrorDiffuser Diffuser { get; } /// /// Gets the palette to use to quantize the image. @@ -64,5 +57,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization public IFrameQuantizer CreateFrameQuantizer() where TPixel : struct, IPixel => new PaletteFrameQuantizer(this); + + private static IErrorDiffuser GetDiffuser(bool dither) => dither ? DiffuseMode.FloydSteinberg : null; } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Quantization/WuQuantizer.cs b/src/ImageSharp/Processing/Quantization/WuQuantizer.cs index 0d306107e9..9cfb554126 100644 --- a/src/ImageSharp/Processing/Quantization/WuQuantizer.cs +++ b/src/ImageSharp/Processing/Quantization/WuQuantizer.cs @@ -18,7 +18,16 @@ namespace SixLabors.ImageSharp.Processing.Quantization /// Initializes a new instance of the class. /// public WuQuantizer() - : this(255) + : this(true) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The maximum number of colors to hold in the color palette + public WuQuantizer(int maxColors) + : this(GetDiffuser(true), maxColors) { } @@ -27,40 +36,34 @@ namespace SixLabors.ImageSharp.Processing.Quantization /// /// Whether to apply dithering to the output image public WuQuantizer(bool dither) - : this(dither, DiffuseMode.FloydSteinberg, 255) + : this(GetDiffuser(dither), 255) { } /// /// Initializes a new instance of the class. /// - /// The maximum number of colors to hold in the color palette - public WuQuantizer(int maxColors) - : this(true, DiffuseMode.FloydSteinberg, maxColors) + /// The error diffusion algorithm, if any, to apply to the output image + public WuQuantizer(IErrorDiffuser diffuser) + : this(diffuser, 255) { } /// /// Initializes a new instance of the class. /// - /// Whether to apply dithering to the output image - /// The dithering algorithm to apply to the output image + /// The error diffusion algorithm, if any, to apply to the output image /// The maximum number of colors to hold in the color palette - public WuQuantizer(bool dither, IErrorDiffuser ditherType, int maxColors) + public WuQuantizer(IErrorDiffuser diffuser, int maxColors) { - Guard.NotNull(ditherType, nameof(ditherType)); Guard.MustBeBetweenOrEqualTo(maxColors, 1, 255, nameof(maxColors)); - this.Dither = dither; - this.DitherType = ditherType; + this.Diffuser = diffuser; this.MaxColors = maxColors; } /// - public bool Dither { get; } - - /// - public IErrorDiffuser DitherType { get; } + public IErrorDiffuser Diffuser { get; } /// /// Gets the maximum number of colors to hold in the color palette. @@ -71,5 +74,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization public IFrameQuantizer CreateFrameQuantizer() where TPixel : struct, IPixel => new WuFrameQuantizer(this); + + private static IErrorDiffuser GetDiffuser(bool dither) => dither ? DiffuseMode.FloydSteinberg : null; } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs b/tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs index 15d2bf51f7..8965904a5a 100644 --- a/tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs +++ b/tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs @@ -14,9 +14,13 @@ var octree = new OctreeQuantizer(); var wu = new WuQuantizer(); - Assert.True(palette.Dither); - Assert.True(octree.Dither); - Assert.True(wu.Dither); + Assert.NotNull(palette.Diffuser); + Assert.NotNull(octree.Diffuser); + Assert.NotNull(wu.Diffuser); + + Assert.True(palette.CreateFrameQuantizer().Dither); + Assert.True(octree.CreateFrameQuantizer().Dither); + Assert.True(wu.CreateFrameQuantizer().Dither); } [Theory] From 9f078c818c0adf6104e4609ed7d6a802f404c9d3 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Thu, 15 Mar 2018 17:41:04 +1100 Subject: [PATCH 3/5] Establish naming convention + move missed primitives - `KnownXXX`. Any open-ended collection of algorithms e.g. `KnownQuantizers`, `KnownResamplers` - `XXXMode`. Any closed operation enumeration e.g `AnchorPositionMode`, `FlipMode` - `XXXType`. Any enumeration of a data type e.g `ExifDataType`. --- .../Jpeg/GolangPort/OrigJpegDecoderCore.cs | 2 +- .../Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs | 1 + .../MetaData/Profiles/Exif/ExifProfile.cs | 1 + .../MetaData/Profiles/Exif/ExifReader.cs | 2 + .../MetaData/Profiles/Exif/ExifValue.cs | 1 + .../MetaData/Profiles/Exif/ExifWriter.cs | 1 + .../Exif => Primitives}/LongRational.cs | 2 +- .../Profiles/Exif => Primitives}/Rational.cs | 2 +- .../Exif => Primitives}/SignedRational.cs | 2 +- .../Processing/Dithering/DiffuseExtensions.cs | 4 +- .../Processing/Dithering/DitherExtensions.cs | 2 +- .../{DiffuseMode.cs => KnownDiffusers.cs} | 2 +- .../{DitherMode.cs => KnownDitherMatrices.cs} | 2 +- .../Filters/ColorBlindnessExtensions.cs | 24 +++---- ...olorBlindness.cs => ColorBlindnessMode.cs} | 2 +- ...MatrixFilters.cs => KnownMatrixFilters.cs} | 2 +- .../Processors/AchromatomalyProcessor.cs | 2 +- .../Processors/AchromatopsiaProcessor.cs | 2 +- .../Filters/Processors/BlackWhiteProcessor.cs | 2 +- .../Filters/Processors/BrightnessProcessor.cs | 2 +- .../Filters/Processors/ContrastProcessor.cs | 2 +- .../Processors/DeuteranomalyProcessor.cs | 2 +- .../Processors/DeuteranopiaProcessor.cs | 2 +- .../Processors/GrayscaleBt601Processor.cs | 2 +- .../Processors/GrayscaleBt709Processor.cs | 2 +- .../Filters/Processors/HueProcessor.cs | 2 +- .../Filters/Processors/InvertProcessor.cs | 2 +- .../Filters/Processors/KodachromeProcessor.cs | 2 +- .../Filters/Processors/LomographProcessor.cs | 2 +- .../Filters/Processors/OpacityProcessor.cs | 2 +- .../Filters/Processors/PolaroidProcessor.cs | 2 +- .../Processors/ProtanomalyProcessor.cs | 2 +- .../Filters/Processors/ProtanopiaProcessor.cs | 2 +- .../Filters/Processors/SaturateProcessor.cs | 2 +- .../Filters/Processors/SepiaProcessor.cs | 2 +- .../Processors/TritanomalyProcessor.cs | 2 +- .../Filters/Processors/TritanopiaProcessor.cs | 2 +- ...QuantizationMode.cs => KnownQuantizers.cs} | 2 +- .../Quantization/OctreeQuantizer.cs | 2 +- .../Quantization/PaletteQuantizer.cs | 2 +- .../Quantization/QuantizeExtensions.cs | 2 +- .../Processing/Quantization/WuQuantizer.cs | 2 +- ...nchorPosition.cs => AnchorPositionMode.cs} | 2 +- .../Processing/Transforms/FlipExtensions.cs | 6 +- .../Transforms/{FlipType.cs => FlipMode.cs} | 2 +- .../{ResampleMode.cs => KnownResamplers.cs} | 2 +- ...{OrientationType.cs => OrientationMode.cs} | 2 +- .../Processing/Transforms/PadExtensions.cs | 2 +- .../Processors/AutoOrientProcessor.cs | 54 ++++++++-------- .../Transforms/Processors/FlipProcessor.cs | 16 ++--- .../Transforms/Processors/RotateProcessor.cs | 2 +- .../Transforms/Processors/SkewProcessor.cs | 2 +- .../Processing/Transforms/ResizeExtensions.cs | 8 +-- .../Processing/Transforms/ResizeHelper.cs | 64 +++++++++---------- .../Processing/Transforms/ResizeMode.cs | 2 +- .../Processing/Transforms/ResizeOptions.cs | 4 +- .../Processing/Transforms/RotateExtensions.cs | 8 +-- .../Transforms/RotateFlipExtensions.cs | 8 +-- .../{RotateType.cs => RotateMode.cs} | 2 +- .../Processing/Transforms/SkewExtensions.cs | 2 +- .../Transforms/TransformExtensions.cs | 4 +- .../ImageSharp.Tests/Drawing/DrawImageTest.cs | 2 +- .../Formats/GeneralFormatTests.cs | 6 +- .../MetaData/ImageMetaDataTests.cs | 2 + .../Profiles/Exif/ExifProfileTests.cs | 2 + .../Numerics/RationalTests.cs | 2 + .../Numerics/SignedRationalTests.cs | 2 + .../Binarization/BinaryDitherTest.cs | 4 +- .../Processing/Dithering/DitherTest.cs | 4 +- .../Processing/Filters/ColorBlindnessTest.cs | 20 +++--- .../Processing/Filters/FilterTest.cs | 4 +- .../Binarization/BinaryDitherTests.cs | 30 ++++----- .../Processors/Dithering/DitherTests.cs | 30 ++++----- .../Processors/Filters/ColorBlindnessTest.cs | 22 +++---- .../Processors/Filters/FilterTest.cs | 6 +- .../Processors/Transforms/AutoOrientTests.cs | 24 +++---- .../Processors/Transforms/FlipTests.cs | 12 ++-- .../Transforms/ResizeProfilingBenchmarks.cs | 2 +- .../Processors/Transforms/ResizeTests.cs | 38 +++++------ .../Processors/Transforms/RotateFlipTests.cs | 16 ++--- .../Processors/Transforms/RotateTests.cs | 14 ++-- .../Processors/Transforms/SkewTest.cs | 32 +++++----- .../Transforms/AffineTransformTests.cs | 48 +++++++------- .../Processing/Transforms/FlipTests.cs | 10 +-- .../Processing/Transforms/PadTest.cs | 2 +- .../Processing/Transforms/ResizeTests.cs | 6 +- .../Processing/Transforms/RotateFlipTests.cs | 28 ++++---- .../Processing/Transforms/RotateTests.cs | 10 +-- 88 files changed, 344 insertions(+), 330 deletions(-) rename src/ImageSharp/{MetaData/Profiles/Exif => Primitives}/LongRational.cs (99%) rename src/ImageSharp/{MetaData/Profiles/Exif => Primitives}/Rational.cs (99%) rename src/ImageSharp/{MetaData/Profiles/Exif => Primitives}/SignedRational.cs (99%) rename src/ImageSharp/Processing/Dithering/{DiffuseMode.cs => KnownDiffusers.cs} (98%) rename src/ImageSharp/Processing/Dithering/{DitherMode.cs => KnownDitherMatrices.cs} (96%) rename src/ImageSharp/Processing/Filters/{ColorBlindness.cs => ColorBlindnessMode.cs} (96%) rename src/ImageSharp/Processing/Filters/{MatrixFilters.cs => KnownMatrixFilters.cs} (99%) rename src/ImageSharp/Processing/Quantization/{QuantizationMode.cs => KnownQuantizers.cs} (96%) rename src/ImageSharp/Processing/Transforms/{AnchorPosition.cs => AnchorPositionMode.cs} (97%) rename src/ImageSharp/Processing/Transforms/{FlipType.cs => FlipMode.cs} (95%) rename src/ImageSharp/Processing/Transforms/{ResampleMode.cs => KnownResamplers.cs} (99%) rename src/ImageSharp/Processing/Transforms/{OrientationType.cs => OrientationMode.cs} (97%) rename src/ImageSharp/Processing/Transforms/{RotateType.cs => RotateMode.cs} (96%) diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs index d3d1efe7fd..0125d2703b 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.IO; - using SixLabors.ImageSharp.Formats.Jpeg.Common; using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder; @@ -11,6 +10,7 @@ using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.MetaData.Profiles.Exif; using SixLabors.ImageSharp.MetaData.Profiles.Icc; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; using SixLabors.Primitives; namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs index 54e2833b11..a600658b02 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs @@ -12,6 +12,7 @@ using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.MetaData.Profiles.Exif; using SixLabors.ImageSharp.MetaData.Profiles.Icc; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort { diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs index f72753cc27..7cd2d002d7 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; namespace SixLabors.ImageSharp.MetaData.Profiles.Exif { diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs index e247527a6e..8a7b1f7d7e 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs @@ -1,10 +1,12 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. + using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; +using SixLabors.ImageSharp.Primitives; namespace SixLabors.ImageSharp.MetaData.Profiles.Exif { diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs index 7ffe9d48fe..3c2b23f37f 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs @@ -4,6 +4,7 @@ using System; using System.Globalization; using System.Text; +using SixLabors.ImageSharp.Primitives; namespace SixLabors.ImageSharp.MetaData.Profiles.Exif { diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifWriter.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifWriter.cs index 7f4123225e..a4cfc7e13e 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifWriter.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifWriter.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Text; +using SixLabors.ImageSharp.Primitives; namespace SixLabors.ImageSharp.MetaData.Profiles.Exif { diff --git a/src/ImageSharp/MetaData/Profiles/Exif/LongRational.cs b/src/ImageSharp/Primitives/LongRational.cs similarity index 99% rename from src/ImageSharp/MetaData/Profiles/Exif/LongRational.cs rename to src/ImageSharp/Primitives/LongRational.cs index f9c16d57d4..641a1e5e53 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/LongRational.cs +++ b/src/ImageSharp/Primitives/LongRational.cs @@ -5,7 +5,7 @@ using System; using System.Globalization; using System.Text; -namespace SixLabors.ImageSharp.MetaData.Profiles.Exif +namespace SixLabors.ImageSharp.Primitives { /// /// Represents a number that can be expressed as a fraction diff --git a/src/ImageSharp/MetaData/Profiles/Exif/Rational.cs b/src/ImageSharp/Primitives/Rational.cs similarity index 99% rename from src/ImageSharp/MetaData/Profiles/Exif/Rational.cs rename to src/ImageSharp/Primitives/Rational.cs index 0f47870d24..6678eb9540 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/Rational.cs +++ b/src/ImageSharp/Primitives/Rational.cs @@ -4,7 +4,7 @@ using System; using System.Globalization; -namespace SixLabors.ImageSharp.MetaData.Profiles.Exif +namespace SixLabors.ImageSharp.Primitives { /// /// Represents a number that can be expressed as a fraction. diff --git a/src/ImageSharp/MetaData/Profiles/Exif/SignedRational.cs b/src/ImageSharp/Primitives/SignedRational.cs similarity index 99% rename from src/ImageSharp/MetaData/Profiles/Exif/SignedRational.cs rename to src/ImageSharp/Primitives/SignedRational.cs index 17f1b568b3..c2a7b3e234 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/SignedRational.cs +++ b/src/ImageSharp/Primitives/SignedRational.cs @@ -4,7 +4,7 @@ using System; using System.Globalization; -namespace SixLabors.ImageSharp.MetaData.Profiles.Exif +namespace SixLabors.ImageSharp.Primitives { /// /// Represents a number that can be expressed as a fraction. diff --git a/src/ImageSharp/Processing/Dithering/DiffuseExtensions.cs b/src/ImageSharp/Processing/Dithering/DiffuseExtensions.cs index 7ae8ec01ef..adb678ee49 100644 --- a/src/ImageSharp/Processing/Dithering/DiffuseExtensions.cs +++ b/src/ImageSharp/Processing/Dithering/DiffuseExtensions.cs @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Dithering /// The . public static IImageProcessingContext Diffuse(this IImageProcessingContext source) where TPixel : struct, IPixel - => Diffuse(source, DiffuseMode.FloydSteinberg, .5F); + => Diffuse(source, KnownDiffusers.FloydSteinberg, .5F); /// /// Dithers the image reducing it to a web-safe palette using error diffusion. @@ -32,7 +32,7 @@ namespace SixLabors.ImageSharp.Processing.Dithering /// The . public static IImageProcessingContext Diffuse(this IImageProcessingContext source, float threshold) where TPixel : struct, IPixel - => Diffuse(source, DiffuseMode.FloydSteinberg, threshold); + => Diffuse(source, KnownDiffusers.FloydSteinberg, threshold); /// /// Dithers the image reducing it to a web-safe palette using error diffusion. diff --git a/src/ImageSharp/Processing/Dithering/DitherExtensions.cs b/src/ImageSharp/Processing/Dithering/DitherExtensions.cs index 31ef12a0ac..9058138550 100644 --- a/src/ImageSharp/Processing/Dithering/DitherExtensions.cs +++ b/src/ImageSharp/Processing/Dithering/DitherExtensions.cs @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Dithering /// The . public static IImageProcessingContext Dither(this IImageProcessingContext source) where TPixel : struct, IPixel - => Dither(source, DitherMode.BayerDither4x4); + => Dither(source, KnownDitherMatrices.BayerDither4x4); /// /// Dithers the image reducing it to a web-safe palette using ordered dithering. diff --git a/src/ImageSharp/Processing/Dithering/DiffuseMode.cs b/src/ImageSharp/Processing/Dithering/KnownDiffusers.cs similarity index 98% rename from src/ImageSharp/Processing/Dithering/DiffuseMode.cs rename to src/ImageSharp/Processing/Dithering/KnownDiffusers.cs index cc74f1230f..250a543ec9 100644 --- a/src/ImageSharp/Processing/Dithering/DiffuseMode.cs +++ b/src/ImageSharp/Processing/Dithering/KnownDiffusers.cs @@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Processing.Dithering /// /// Contains reusable static instances of known error diffusion algorithms /// - public static class DiffuseMode + public static class KnownDiffusers { /// /// Gets the error diffuser that implements the Atkinson algorithm. diff --git a/src/ImageSharp/Processing/Dithering/DitherMode.cs b/src/ImageSharp/Processing/Dithering/KnownDitherMatrices.cs similarity index 96% rename from src/ImageSharp/Processing/Dithering/DitherMode.cs rename to src/ImageSharp/Processing/Dithering/KnownDitherMatrices.cs index f5122608c1..8e32584798 100644 --- a/src/ImageSharp/Processing/Dithering/DitherMode.cs +++ b/src/ImageSharp/Processing/Dithering/KnownDitherMatrices.cs @@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Processing.Dithering /// /// Contains reusable static instances of known ordered dither matrices /// - public class DitherMode + public class KnownDitherMatrices { /// /// Gets the order ditherer using the 2x2 Bayer dithering matrix diff --git a/src/ImageSharp/Processing/Filters/ColorBlindnessExtensions.cs b/src/ImageSharp/Processing/Filters/ColorBlindnessExtensions.cs index b7dc871503..d70064097d 100644 --- a/src/ImageSharp/Processing/Filters/ColorBlindnessExtensions.cs +++ b/src/ImageSharp/Processing/Filters/ColorBlindnessExtensions.cs @@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.Processing.Filters /// The image this method extends. /// The type of color blindness simulator to apply. /// The . - public static IImageProcessingContext ColorBlindness(this IImageProcessingContext source, ColorBlindness colorBlindness) + public static IImageProcessingContext ColorBlindness(this IImageProcessingContext source, ColorBlindnessMode colorBlindness) where TPixel : struct, IPixel => source.ApplyProcessor(GetProcessor(colorBlindness)); @@ -29,33 +29,33 @@ namespace SixLabors.ImageSharp.Processing.Filters /// /// The pixel format. /// The image this method extends. - /// The type of color blindness simulator to apply. + /// The type of color blindness simulator to apply. /// /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessingContext ColorBlindness(this IImageProcessingContext source, ColorBlindness colorBlindness, Rectangle rectangle) + public static IImageProcessingContext ColorBlindness(this IImageProcessingContext source, ColorBlindnessMode colorBlindnessMode, Rectangle rectangle) where TPixel : struct, IPixel - => source.ApplyProcessor(GetProcessor(colorBlindness), rectangle); + => source.ApplyProcessor(GetProcessor(colorBlindnessMode), rectangle); - private static IImageProcessor GetProcessor(ColorBlindness colorBlindness) + private static IImageProcessor GetProcessor(ColorBlindnessMode colorBlindness) where TPixel : struct, IPixel { switch (colorBlindness) { - case Filters.ColorBlindness.Achromatomaly: + case ColorBlindnessMode.Achromatomaly: return new AchromatomalyProcessor(); - case Filters.ColorBlindness.Achromatopsia: + case ColorBlindnessMode.Achromatopsia: return new AchromatopsiaProcessor(); - case Filters.ColorBlindness.Deuteranomaly: + case ColorBlindnessMode.Deuteranomaly: return new DeuteranomalyProcessor(); - case Filters.ColorBlindness.Deuteranopia: + case ColorBlindnessMode.Deuteranopia: return new DeuteranopiaProcessor(); - case Filters.ColorBlindness.Protanomaly: + case ColorBlindnessMode.Protanomaly: return new ProtanomalyProcessor(); - case Filters.ColorBlindness.Protanopia: + case ColorBlindnessMode.Protanopia: return new ProtanopiaProcessor(); - case Filters.ColorBlindness.Tritanomaly: + case ColorBlindnessMode.Tritanomaly: return new TritanomalyProcessor(); default: return new TritanopiaProcessor(); diff --git a/src/ImageSharp/Processing/Filters/ColorBlindness.cs b/src/ImageSharp/Processing/Filters/ColorBlindnessMode.cs similarity index 96% rename from src/ImageSharp/Processing/Filters/ColorBlindness.cs rename to src/ImageSharp/Processing/Filters/ColorBlindnessMode.cs index 41d468f340..584c9fa08a 100644 --- a/src/ImageSharp/Processing/Filters/ColorBlindness.cs +++ b/src/ImageSharp/Processing/Filters/ColorBlindnessMode.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Processing.Filters /// /// Enumerates the various types of defined color blindness filters. /// - public enum ColorBlindness + public enum ColorBlindnessMode { /// /// Partial color desensitivity. diff --git a/src/ImageSharp/Processing/Filters/MatrixFilters.cs b/src/ImageSharp/Processing/Filters/KnownMatrixFilters.cs similarity index 99% rename from src/ImageSharp/Processing/Filters/MatrixFilters.cs rename to src/ImageSharp/Processing/Filters/KnownMatrixFilters.cs index 2f5883fc9c..2b3c0a9a39 100644 --- a/src/ImageSharp/Processing/Filters/MatrixFilters.cs +++ b/src/ImageSharp/Processing/Filters/KnownMatrixFilters.cs @@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Processing.Filters /// /// A collection of known values for composing filters /// - public static class MatrixFilters + public static class KnownMatrixFilters { /// /// Gets a filter recreating Achromatomaly (Color desensitivity) color blindness diff --git a/src/ImageSharp/Processing/Filters/Processors/AchromatomalyProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/AchromatomalyProcessor.cs index 55c6220308..e1f11c094f 100644 --- a/src/ImageSharp/Processing/Filters/Processors/AchromatomalyProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/AchromatomalyProcessor.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// Initializes a new instance of the class. /// public AchromatomalyProcessor() - : base(MatrixFilters.AchromatomalyFilter) + : base(KnownMatrixFilters.AchromatomalyFilter) { } } diff --git a/src/ImageSharp/Processing/Filters/Processors/AchromatopsiaProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/AchromatopsiaProcessor.cs index 95f9e893be..e9ff6177c7 100644 --- a/src/ImageSharp/Processing/Filters/Processors/AchromatopsiaProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/AchromatopsiaProcessor.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// Initializes a new instance of the class. /// public AchromatopsiaProcessor() - : base(MatrixFilters.AchromatopsiaFilter) + : base(KnownMatrixFilters.AchromatopsiaFilter) { } } diff --git a/src/ImageSharp/Processing/Filters/Processors/BlackWhiteProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/BlackWhiteProcessor.cs index f6a420257e..0b1f4dab5c 100644 --- a/src/ImageSharp/Processing/Filters/Processors/BlackWhiteProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/BlackWhiteProcessor.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// Initializes a new instance of the class. /// public BlackWhiteProcessor() - : base(MatrixFilters.BlackWhiteFilter) + : base(KnownMatrixFilters.BlackWhiteFilter) { } } diff --git a/src/ImageSharp/Processing/Filters/Processors/BrightnessProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/BrightnessProcessor.cs index c6f758634d..d4a51ed04a 100644 --- a/src/ImageSharp/Processing/Filters/Processors/BrightnessProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/BrightnessProcessor.cs @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// /// The proportion of the conversion. Must be greater than or equal to 0. public BrightnessProcessor(float amount) - : base(MatrixFilters.CreateBrightnessFilter(amount)) + : base(KnownMatrixFilters.CreateBrightnessFilter(amount)) { this.Amount = amount; } diff --git a/src/ImageSharp/Processing/Filters/Processors/ContrastProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/ContrastProcessor.cs index 3a8022703c..9c8e717f2f 100644 --- a/src/ImageSharp/Processing/Filters/Processors/ContrastProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/ContrastProcessor.cs @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// /// The proportion of the conversion. Must be greater than or equal to 0. public ContrastProcessor(float amount) - : base(MatrixFilters.CreateContrastFilter(amount)) + : base(KnownMatrixFilters.CreateContrastFilter(amount)) { this.Amount = amount; } diff --git a/src/ImageSharp/Processing/Filters/Processors/DeuteranomalyProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/DeuteranomalyProcessor.cs index 31ea79afe2..afb5bbd531 100644 --- a/src/ImageSharp/Processing/Filters/Processors/DeuteranomalyProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/DeuteranomalyProcessor.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// Initializes a new instance of the class. /// public DeuteranomalyProcessor() - : base(MatrixFilters.DeuteranomalyFilter) + : base(KnownMatrixFilters.DeuteranomalyFilter) { } } diff --git a/src/ImageSharp/Processing/Filters/Processors/DeuteranopiaProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/DeuteranopiaProcessor.cs index 5ed7e85408..2cbfcf4674 100644 --- a/src/ImageSharp/Processing/Filters/Processors/DeuteranopiaProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/DeuteranopiaProcessor.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// Initializes a new instance of the class. /// public DeuteranopiaProcessor() - : base(MatrixFilters.DeuteranopiaFilter) + : base(KnownMatrixFilters.DeuteranopiaFilter) { } } diff --git a/src/ImageSharp/Processing/Filters/Processors/GrayscaleBt601Processor.cs b/src/ImageSharp/Processing/Filters/Processors/GrayscaleBt601Processor.cs index fa483752c5..2fe4bf31b6 100644 --- a/src/ImageSharp/Processing/Filters/Processors/GrayscaleBt601Processor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/GrayscaleBt601Processor.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// /// The proportion of the conversion. Must be between 0 and 1. public GrayscaleBt601Processor(float amount) - : base(MatrixFilters.CreateGrayscaleBt601Filter(amount)) + : base(KnownMatrixFilters.CreateGrayscaleBt601Filter(amount)) { this.Amount = amount; } diff --git a/src/ImageSharp/Processing/Filters/Processors/GrayscaleBt709Processor.cs b/src/ImageSharp/Processing/Filters/Processors/GrayscaleBt709Processor.cs index 396ad7d903..5e26849984 100644 --- a/src/ImageSharp/Processing/Filters/Processors/GrayscaleBt709Processor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/GrayscaleBt709Processor.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// /// The proportion of the conversion. Must be between 0 and 1. public GrayscaleBt709Processor(float amount) - : base(MatrixFilters.CreateGrayscaleBt709Filter(amount)) + : base(KnownMatrixFilters.CreateGrayscaleBt709Filter(amount)) { this.Amount = amount; } diff --git a/src/ImageSharp/Processing/Filters/Processors/HueProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/HueProcessor.cs index 31adf21259..8bd7d3278a 100644 --- a/src/ImageSharp/Processing/Filters/Processors/HueProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/HueProcessor.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// /// The angle of rotation in degrees public HueProcessor(float degrees) - : base(MatrixFilters.CreateHueFilter(degrees)) + : base(KnownMatrixFilters.CreateHueFilter(degrees)) { this.Degrees = degrees; } diff --git a/src/ImageSharp/Processing/Filters/Processors/InvertProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/InvertProcessor.cs index e5175ca69b..fc408912d0 100644 --- a/src/ImageSharp/Processing/Filters/Processors/InvertProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/InvertProcessor.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// /// The proportion of the conversion. Must be between 0 and 1. public InvertProcessor(float amount) - : base(MatrixFilters.CreateInvertFilter(amount)) + : base(KnownMatrixFilters.CreateInvertFilter(amount)) { this.Amount = amount; } diff --git a/src/ImageSharp/Processing/Filters/Processors/KodachromeProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/KodachromeProcessor.cs index 19f55507c4..ea9b86d1b7 100644 --- a/src/ImageSharp/Processing/Filters/Processors/KodachromeProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/KodachromeProcessor.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// Initializes a new instance of the class. /// public KodachromeProcessor() - : base(MatrixFilters.KodachromeFilter) + : base(KnownMatrixFilters.KodachromeFilter) { } } diff --git a/src/ImageSharp/Processing/Filters/Processors/LomographProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/LomographProcessor.cs index 5e3d73fd19..7196bc2dde 100644 --- a/src/ImageSharp/Processing/Filters/Processors/LomographProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/LomographProcessor.cs @@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// Initializes a new instance of the class. /// public LomographProcessor() - : base(MatrixFilters.LomographFilter) + : base(KnownMatrixFilters.LomographFilter) { } diff --git a/src/ImageSharp/Processing/Filters/Processors/OpacityProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/OpacityProcessor.cs index db9af9546c..9e2e549b2c 100644 --- a/src/ImageSharp/Processing/Filters/Processors/OpacityProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/OpacityProcessor.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// /// The proportion of the conversion. Must be between 0 and 1. public OpacityProcessor(float amount) - : base(MatrixFilters.CreateOpacityFilter(amount)) + : base(KnownMatrixFilters.CreateOpacityFilter(amount)) { this.Amount = amount; } diff --git a/src/ImageSharp/Processing/Filters/Processors/PolaroidProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/PolaroidProcessor.cs index 0e90efc7ec..b9c555c9f6 100644 --- a/src/ImageSharp/Processing/Filters/Processors/PolaroidProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/PolaroidProcessor.cs @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// Initializes a new instance of the class. /// public PolaroidProcessor() - : base(MatrixFilters.PolaroidFilter) + : base(KnownMatrixFilters.PolaroidFilter) { } diff --git a/src/ImageSharp/Processing/Filters/Processors/ProtanomalyProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/ProtanomalyProcessor.cs index 4801391227..24cdd75c25 100644 --- a/src/ImageSharp/Processing/Filters/Processors/ProtanomalyProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/ProtanomalyProcessor.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// Initializes a new instance of the class. /// public ProtanomalyProcessor() - : base(MatrixFilters.ProtanomalyFilter) + : base(KnownMatrixFilters.ProtanomalyFilter) { } } diff --git a/src/ImageSharp/Processing/Filters/Processors/ProtanopiaProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/ProtanopiaProcessor.cs index 43f1c14ea8..441d083107 100644 --- a/src/ImageSharp/Processing/Filters/Processors/ProtanopiaProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/ProtanopiaProcessor.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// Initializes a new instance of the class. /// public ProtanopiaProcessor() - : base(MatrixFilters.ProtanopiaFilter) + : base(KnownMatrixFilters.ProtanopiaFilter) { } } diff --git a/src/ImageSharp/Processing/Filters/Processors/SaturateProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/SaturateProcessor.cs index 9a48cb2b51..645052eab5 100644 --- a/src/ImageSharp/Processing/Filters/Processors/SaturateProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/SaturateProcessor.cs @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// /// The proportion of the conversion. Must be greater than or equal to 0. public SaturateProcessor(float amount) - : base(MatrixFilters.CreateSaturateFilter(amount)) + : base(KnownMatrixFilters.CreateSaturateFilter(amount)) { this.Amount = amount; } diff --git a/src/ImageSharp/Processing/Filters/Processors/SepiaProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/SepiaProcessor.cs index 2b3bf105bf..641540f61a 100644 --- a/src/ImageSharp/Processing/Filters/Processors/SepiaProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/SepiaProcessor.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// /// The proportion of the conversion. Must be between 0 and 1. public SepiaProcessor(float amount) - : base(MatrixFilters.CreateSepiaFilter(amount)) + : base(KnownMatrixFilters.CreateSepiaFilter(amount)) { this.Amount = amount; } diff --git a/src/ImageSharp/Processing/Filters/Processors/TritanomalyProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/TritanomalyProcessor.cs index cd2e382178..2da3fd5fbd 100644 --- a/src/ImageSharp/Processing/Filters/Processors/TritanomalyProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/TritanomalyProcessor.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// Initializes a new instance of the class. /// public TritanomalyProcessor() - : base(MatrixFilters.TritanomalyFilter) + : base(KnownMatrixFilters.TritanomalyFilter) { } } diff --git a/src/ImageSharp/Processing/Filters/Processors/TritanopiaProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/TritanopiaProcessor.cs index ce4a079a27..a496f6f62c 100644 --- a/src/ImageSharp/Processing/Filters/Processors/TritanopiaProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/TritanopiaProcessor.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// Initializes a new instance of the class. /// public TritanopiaProcessor() - : base(MatrixFilters.TritanopiaFilter) + : base(KnownMatrixFilters.TritanopiaFilter) { } } diff --git a/src/ImageSharp/Processing/Quantization/QuantizationMode.cs b/src/ImageSharp/Processing/Quantization/KnownQuantizers.cs similarity index 96% rename from src/ImageSharp/Processing/Quantization/QuantizationMode.cs rename to src/ImageSharp/Processing/Quantization/KnownQuantizers.cs index 45a085c01f..357cd5676a 100644 --- a/src/ImageSharp/Processing/Quantization/QuantizationMode.cs +++ b/src/ImageSharp/Processing/Quantization/KnownQuantizers.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization /// /// Contains reusable static instances of known quantizing algorithms /// - public static class QuantizationMode + public static class KnownQuantizers { /// /// Gets the adaptive Octree quantizer. Fast with good quality. diff --git a/src/ImageSharp/Processing/Quantization/OctreeQuantizer.cs b/src/ImageSharp/Processing/Quantization/OctreeQuantizer.cs index 9d27970b14..89fa7a90ec 100644 --- a/src/ImageSharp/Processing/Quantization/OctreeQuantizer.cs +++ b/src/ImageSharp/Processing/Quantization/OctreeQuantizer.cs @@ -75,6 +75,6 @@ namespace SixLabors.ImageSharp.Processing.Quantization where TPixel : struct, IPixel => new OctreeFrameQuantizer(this); - private static IErrorDiffuser GetDiffuser(bool dither) => dither ? DiffuseMode.FloydSteinberg : null; + private static IErrorDiffuser GetDiffuser(bool dither) => dither ? KnownDiffusers.FloydSteinberg : null; } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Quantization/PaletteQuantizer.cs b/src/ImageSharp/Processing/Quantization/PaletteQuantizer.cs index f25b6537a7..06c5a99183 100644 --- a/src/ImageSharp/Processing/Quantization/PaletteQuantizer.cs +++ b/src/ImageSharp/Processing/Quantization/PaletteQuantizer.cs @@ -58,6 +58,6 @@ namespace SixLabors.ImageSharp.Processing.Quantization where TPixel : struct, IPixel => new PaletteFrameQuantizer(this); - private static IErrorDiffuser GetDiffuser(bool dither) => dither ? DiffuseMode.FloydSteinberg : null; + private static IErrorDiffuser GetDiffuser(bool dither) => dither ? KnownDiffusers.FloydSteinberg : null; } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Quantization/QuantizeExtensions.cs b/src/ImageSharp/Processing/Quantization/QuantizeExtensions.cs index 0583c176b0..bf49c765ac 100644 --- a/src/ImageSharp/Processing/Quantization/QuantizeExtensions.cs +++ b/src/ImageSharp/Processing/Quantization/QuantizeExtensions.cs @@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization /// The . public static IImageProcessingContext Quantize(this IImageProcessingContext source) where TPixel : struct, IPixel - => Quantize(source, QuantizationMode.Octree); + => Quantize(source, KnownQuantizers.Octree); /// /// Applies quantization to the image. diff --git a/src/ImageSharp/Processing/Quantization/WuQuantizer.cs b/src/ImageSharp/Processing/Quantization/WuQuantizer.cs index 9cfb554126..6b1287b465 100644 --- a/src/ImageSharp/Processing/Quantization/WuQuantizer.cs +++ b/src/ImageSharp/Processing/Quantization/WuQuantizer.cs @@ -75,6 +75,6 @@ namespace SixLabors.ImageSharp.Processing.Quantization where TPixel : struct, IPixel => new WuFrameQuantizer(this); - private static IErrorDiffuser GetDiffuser(bool dither) => dither ? DiffuseMode.FloydSteinberg : null; + private static IErrorDiffuser GetDiffuser(bool dither) => dither ? KnownDiffusers.FloydSteinberg : null; } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/AnchorPosition.cs b/src/ImageSharp/Processing/Transforms/AnchorPositionMode.cs similarity index 97% rename from src/ImageSharp/Processing/Transforms/AnchorPosition.cs rename to src/ImageSharp/Processing/Transforms/AnchorPositionMode.cs index 4519f90f94..793fc0dfca 100644 --- a/src/ImageSharp/Processing/Transforms/AnchorPosition.cs +++ b/src/ImageSharp/Processing/Transforms/AnchorPositionMode.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms /// /// Enumerated anchor positions to apply to resized images. /// - public enum AnchorPosition + public enum AnchorPositionMode { /// /// Anchors the position of the image to the center of it's bounding container. diff --git a/src/ImageSharp/Processing/Transforms/FlipExtensions.cs b/src/ImageSharp/Processing/Transforms/FlipExtensions.cs index e88074c137..0cbbdd95f5 100644 --- a/src/ImageSharp/Processing/Transforms/FlipExtensions.cs +++ b/src/ImageSharp/Processing/Transforms/FlipExtensions.cs @@ -16,10 +16,10 @@ namespace SixLabors.ImageSharp.Processing.Transforms /// /// The pixel format. /// The image to rotate, flip, or both. - /// The to perform the flip. + /// The to perform the flip. /// The - public static IImageProcessingContext Flip(this IImageProcessingContext source, FlipType flipType) + public static IImageProcessingContext Flip(this IImageProcessingContext source, FlipMode flipMode) where TPixel : struct, IPixel - => source.ApplyProcessor(new FlipProcessor(flipType)); + => source.ApplyProcessor(new FlipProcessor(flipMode)); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/FlipType.cs b/src/ImageSharp/Processing/Transforms/FlipMode.cs similarity index 95% rename from src/ImageSharp/Processing/Transforms/FlipType.cs rename to src/ImageSharp/Processing/Transforms/FlipMode.cs index 71a4e6fc8f..32c910c803 100644 --- a/src/ImageSharp/Processing/Transforms/FlipType.cs +++ b/src/ImageSharp/Processing/Transforms/FlipMode.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms /// /// Provides enumeration over how a image should be flipped. /// - public enum FlipType + public enum FlipMode { /// /// Don't flip the image. diff --git a/src/ImageSharp/Processing/Transforms/ResampleMode.cs b/src/ImageSharp/Processing/Transforms/KnownResamplers.cs similarity index 99% rename from src/ImageSharp/Processing/Transforms/ResampleMode.cs rename to src/ImageSharp/Processing/Transforms/KnownResamplers.cs index bbbdc3b265..2b589d4612 100644 --- a/src/ImageSharp/Processing/Transforms/ResampleMode.cs +++ b/src/ImageSharp/Processing/Transforms/KnownResamplers.cs @@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms /// /// Contains reusable static instances of known resampling algorithms /// - public static class ResampleMode + public static class KnownResamplers { /// /// Gets the Bicubic sampler that implements the bicubic kernel algorithm W(x) diff --git a/src/ImageSharp/Processing/Transforms/OrientationType.cs b/src/ImageSharp/Processing/Transforms/OrientationMode.cs similarity index 97% rename from src/ImageSharp/Processing/Transforms/OrientationType.cs rename to src/ImageSharp/Processing/Transforms/OrientationMode.cs index 752ac9fe68..c6f05380bd 100644 --- a/src/ImageSharp/Processing/Transforms/OrientationType.cs +++ b/src/ImageSharp/Processing/Transforms/OrientationMode.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms /// /// Enumerates the available orientation values supplied by EXIF metadata. /// - internal enum OrientationType : ushort + internal enum OrientationMode : ushort { /// /// Unknown rotation. diff --git a/src/ImageSharp/Processing/Transforms/PadExtensions.cs b/src/ImageSharp/Processing/Transforms/PadExtensions.cs index 23e9d5d27e..a231088dd7 100644 --- a/src/ImageSharp/Processing/Transforms/PadExtensions.cs +++ b/src/ImageSharp/Processing/Transforms/PadExtensions.cs @@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms { Size = new Size(width, height), Mode = ResizeMode.BoxPad, - Sampler = ResampleMode.NearestNeighbor + Sampler = KnownResamplers.NearestNeighbor }; return source.Resize(options); diff --git a/src/ImageSharp/Processing/Transforms/Processors/AutoOrientProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/AutoOrientProcessor.cs index fdb58918af..68dc7f0ad3 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/AutoOrientProcessor.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/AutoOrientProcessor.cs @@ -19,42 +19,42 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors /// protected override void BeforeImageApply(Image source, Rectangle sourceRectangle) { - OrientationType orientation = GetExifOrientation(source); + OrientationMode orientation = GetExifOrientation(source); Size size = sourceRectangle.Size; switch (orientation) { - case OrientationType.TopRight: - new FlipProcessor(FlipType.Horizontal).Apply(source, sourceRectangle); + case OrientationMode.TopRight: + new FlipProcessor(FlipMode.Horizontal).Apply(source, sourceRectangle); break; - case OrientationType.BottomRight: - new RotateProcessor((int)RotateType.Rotate180, size).Apply(source, sourceRectangle); + case OrientationMode.BottomRight: + new RotateProcessor((int)RotateMode.Rotate180, size).Apply(source, sourceRectangle); break; - case OrientationType.BottomLeft: - new FlipProcessor(FlipType.Vertical).Apply(source, sourceRectangle); + case OrientationMode.BottomLeft: + new FlipProcessor(FlipMode.Vertical).Apply(source, sourceRectangle); break; - case OrientationType.LeftTop: - new RotateProcessor((int)RotateType.Rotate90, size).Apply(source, sourceRectangle); - new FlipProcessor(FlipType.Horizontal).Apply(source, sourceRectangle); + case OrientationMode.LeftTop: + new RotateProcessor((int)RotateMode.Rotate90, size).Apply(source, sourceRectangle); + new FlipProcessor(FlipMode.Horizontal).Apply(source, sourceRectangle); break; - case OrientationType.RightTop: - new RotateProcessor((int)RotateType.Rotate90, size).Apply(source, sourceRectangle); + case OrientationMode.RightTop: + new RotateProcessor((int)RotateMode.Rotate90, size).Apply(source, sourceRectangle); break; - case OrientationType.RightBottom: - new FlipProcessor(FlipType.Vertical).Apply(source, sourceRectangle); - new RotateProcessor((int)RotateType.Rotate270, size).Apply(source, sourceRectangle); + case OrientationMode.RightBottom: + new FlipProcessor(FlipMode.Vertical).Apply(source, sourceRectangle); + new RotateProcessor((int)RotateMode.Rotate270, size).Apply(source, sourceRectangle); break; - case OrientationType.LeftBottom: - new RotateProcessor((int)RotateType.Rotate270, size).Apply(source, sourceRectangle); + case OrientationMode.LeftBottom: + new RotateProcessor((int)RotateMode.Rotate270, size).Apply(source, sourceRectangle); break; - case OrientationType.Unknown: - case OrientationType.TopLeft: + case OrientationMode.Unknown: + case OrientationMode.TopLeft: default: break; } @@ -70,32 +70,32 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors /// Returns the current EXIF orientation /// /// The image to auto rotate. - /// The - private static OrientationType GetExifOrientation(Image source) + /// The + private static OrientationMode GetExifOrientation(Image source) { if (source.MetaData.ExifProfile == null) { - return OrientationType.Unknown; + return OrientationMode.Unknown; } ExifValue value = source.MetaData.ExifProfile.GetValue(ExifTag.Orientation); if (value == null) { - return OrientationType.Unknown; + return OrientationMode.Unknown; } - OrientationType orientation; + OrientationMode orientation; if (value.DataType == ExifDataType.Short) { - orientation = (OrientationType)value.Value; + orientation = (OrientationMode)value.Value; } else { - orientation = (OrientationType)Convert.ToUInt16(value.Value); + orientation = (OrientationMode)Convert.ToUInt16(value.Value); source.MetaData.ExifProfile.RemoveValue(ExifTag.Orientation); } - source.MetaData.ExifProfile.SetValue(ExifTag.Orientation, (ushort)OrientationType.TopLeft); + source.MetaData.ExifProfile.SetValue(ExifTag.Orientation, (ushort)OrientationMode.TopLeft); return orientation; } diff --git a/src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs index 4c6cb166bf..cf5ebf418a 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/FlipProcessor.cs @@ -21,27 +21,27 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors /// /// Initializes a new instance of the class. /// - /// The used to perform flipping. - public FlipProcessor(FlipType flipType) + /// The used to perform flipping. + public FlipProcessor(FlipMode flipMode) { - this.FlipType = flipType; + this.FlipMode = flipMode; } /// - /// Gets the used to perform flipping. + /// Gets the used to perform flipping. /// - public FlipType FlipType { get; } + public FlipMode FlipMode { get; } /// protected override void OnFrameApply(ImageFrame source, Rectangle sourceRectangle, Configuration configuration) { - switch (this.FlipType) + switch (this.FlipMode) { // No default needed as we have already set the pixels. - case FlipType.Vertical: + case FlipMode.Vertical: this.FlipX(source, configuration); break; - case FlipType.Horizontal: + case FlipMode.Horizontal: this.FlipY(source, configuration); break; } diff --git a/src/ImageSharp/Processing/Transforms/Processors/RotateProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/RotateProcessor.cs index 0cf42cbb72..62c3e476b5 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/RotateProcessor.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/RotateProcessor.cs @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors /// The angle of rotation in degrees. /// The source image size public RotateProcessor(float degrees, Size sourceSize) - : this(degrees, ResampleMode.Bicubic, sourceSize) + : this(degrees, KnownResamplers.Bicubic, sourceSize) { } diff --git a/src/ImageSharp/Processing/Transforms/Processors/SkewProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/SkewProcessor.cs index cc3d901d6c..61e8b12686 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/SkewProcessor.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/SkewProcessor.cs @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors /// The angle in degrees to perform the skew along the y-axis. /// The source image size public SkewProcessor(float degreesX, float degreesY, Size sourceSize) - : this(degreesX, degreesY, ResampleMode.Bicubic, sourceSize) + : this(degreesX, degreesY, KnownResamplers.Bicubic, sourceSize) { } diff --git a/src/ImageSharp/Processing/Transforms/ResizeExtensions.cs b/src/ImageSharp/Processing/Transforms/ResizeExtensions.cs index 4101d3cff4..4317c1fc1f 100644 --- a/src/ImageSharp/Processing/Transforms/ResizeExtensions.cs +++ b/src/ImageSharp/Processing/Transforms/ResizeExtensions.cs @@ -35,7 +35,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image public static IImageProcessingContext Resize(this IImageProcessingContext source, Size size) where TPixel : struct, IPixel - => Resize(source, size.Width, size.Height, ResampleMode.Bicubic, false); + => Resize(source, size.Width, size.Height, KnownResamplers.Bicubic, false); /// /// Resizes an image to the given . @@ -48,7 +48,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image public static IImageProcessingContext Resize(this IImageProcessingContext source, Size size, bool compand) where TPixel : struct, IPixel - => Resize(source, size.Width, size.Height, ResampleMode.Bicubic, compand); + => Resize(source, size.Width, size.Height, KnownResamplers.Bicubic, compand); /// /// Resizes an image to the given width and height. @@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image public static IImageProcessingContext Resize(this IImageProcessingContext source, int width, int height) where TPixel : struct, IPixel - => Resize(source, width, height, ResampleMode.Bicubic, false); + => Resize(source, width, height, KnownResamplers.Bicubic, false); /// /// Resizes an image to the given width and height. @@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image public static IImageProcessingContext Resize(this IImageProcessingContext source, int width, int height, bool compand) where TPixel : struct, IPixel - => Resize(source, width, height, ResampleMode.Bicubic, compand); + => Resize(source, width, height, KnownResamplers.Bicubic, compand); /// /// Resizes an image to the given width and height with the given sampler. diff --git a/src/ImageSharp/Processing/Transforms/ResizeHelper.cs b/src/ImageSharp/Processing/Transforms/ResizeHelper.cs index 0d500b1bce..aca9d97d3f 100644 --- a/src/ImageSharp/Processing/Transforms/ResizeHelper.cs +++ b/src/ImageSharp/Processing/Transforms/ResizeHelper.cs @@ -87,14 +87,14 @@ namespace SixLabors.ImageSharp.Processing.Transforms { switch (options.Position) { - case AnchorPosition.Top: - case AnchorPosition.TopLeft: - case AnchorPosition.TopRight: + case AnchorPositionMode.Top: + case AnchorPositionMode.TopLeft: + case AnchorPositionMode.TopRight: destinationY = 0; break; - case AnchorPosition.Bottom: - case AnchorPosition.BottomLeft: - case AnchorPosition.BottomRight: + case AnchorPositionMode.Bottom: + case AnchorPositionMode.BottomLeft: + case AnchorPositionMode.BottomRight: destinationY = (int)MathF.Round(height - (sourceHeight * ratio)); break; default: @@ -128,14 +128,14 @@ namespace SixLabors.ImageSharp.Processing.Transforms { switch (options.Position) { - case AnchorPosition.Left: - case AnchorPosition.TopLeft: - case AnchorPosition.BottomLeft: + case AnchorPositionMode.Left: + case AnchorPositionMode.TopLeft: + case AnchorPositionMode.BottomLeft: destinationX = 0; break; - case AnchorPosition.Right: - case AnchorPosition.TopRight: - case AnchorPosition.BottomRight: + case AnchorPositionMode.Right: + case AnchorPositionMode.TopRight: + case AnchorPositionMode.BottomRight: destinationX = (int)MathF.Round(width - (sourceWidth * ratio)); break; default: @@ -177,14 +177,14 @@ namespace SixLabors.ImageSharp.Processing.Transforms switch (options.Position) { - case AnchorPosition.Left: - case AnchorPosition.TopLeft: - case AnchorPosition.BottomLeft: + case AnchorPositionMode.Left: + case AnchorPositionMode.TopLeft: + case AnchorPositionMode.BottomLeft: destinationX = 0; break; - case AnchorPosition.Right: - case AnchorPosition.TopRight: - case AnchorPosition.BottomRight: + case AnchorPositionMode.Right: + case AnchorPositionMode.TopRight: + case AnchorPositionMode.BottomRight: destinationX = (int)MathF.Round(width - (sourceWidth * ratio)); break; default: @@ -199,14 +199,14 @@ namespace SixLabors.ImageSharp.Processing.Transforms switch (options.Position) { - case AnchorPosition.Top: - case AnchorPosition.TopLeft: - case AnchorPosition.TopRight: + case AnchorPositionMode.Top: + case AnchorPositionMode.TopLeft: + case AnchorPositionMode.TopRight: destinationY = 0; break; - case AnchorPosition.Bottom: - case AnchorPosition.BottomLeft: - case AnchorPosition.BottomRight: + case AnchorPositionMode.Bottom: + case AnchorPositionMode.BottomLeft: + case AnchorPositionMode.BottomRight: destinationY = (int)MathF.Round(height - (sourceHeight * ratio)); break; default: @@ -247,35 +247,35 @@ namespace SixLabors.ImageSharp.Processing.Transforms switch (options.Position) { - case AnchorPosition.Left: + case AnchorPositionMode.Left: destinationY = (height - sourceHeight) / 2; destinationX = 0; break; - case AnchorPosition.Right: + case AnchorPositionMode.Right: destinationY = (height - sourceHeight) / 2; destinationX = width - sourceWidth; break; - case AnchorPosition.TopRight: + case AnchorPositionMode.TopRight: destinationY = 0; destinationX = width - sourceWidth; break; - case AnchorPosition.Top: + case AnchorPositionMode.Top: destinationY = 0; destinationX = (width - sourceWidth) / 2; break; - case AnchorPosition.TopLeft: + case AnchorPositionMode.TopLeft: destinationY = 0; destinationX = 0; break; - case AnchorPosition.BottomRight: + case AnchorPositionMode.BottomRight: destinationY = height - sourceHeight; destinationX = width - sourceWidth; break; - case AnchorPosition.Bottom: + case AnchorPositionMode.Bottom: destinationY = height - sourceHeight; destinationX = (width - sourceWidth) / 2; break; - case AnchorPosition.BottomLeft: + case AnchorPositionMode.BottomLeft: destinationY = height - sourceHeight; destinationX = 0; break; diff --git a/src/ImageSharp/Processing/Transforms/ResizeMode.cs b/src/ImageSharp/Processing/Transforms/ResizeMode.cs index d81691cd37..2707b11b3d 100644 --- a/src/ImageSharp/Processing/Transforms/ResizeMode.cs +++ b/src/ImageSharp/Processing/Transforms/ResizeMode.cs @@ -4,7 +4,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms { /// - /// Enumerated resize modes to apply to images. + /// Provides enumeration over how the image should be resized. /// public enum ResizeMode { diff --git a/src/ImageSharp/Processing/Transforms/ResizeOptions.cs b/src/ImageSharp/Processing/Transforms/ResizeOptions.cs index 8d63847485..c14abe2a87 100644 --- a/src/ImageSharp/Processing/Transforms/ResizeOptions.cs +++ b/src/ImageSharp/Processing/Transforms/ResizeOptions.cs @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms /// /// Gets or sets the anchor position. /// - public AnchorPosition Position { get; set; } = AnchorPosition.Center; + public AnchorPositionMode Position { get; set; } = AnchorPositionMode.Center; /// /// Gets or sets the center coordinates. @@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms /// /// Gets or sets the sampler to perform the resize operation. /// - public IResampler Sampler { get; set; } = ResampleMode.Bicubic; + public IResampler Sampler { get; set; } = KnownResamplers.Bicubic; /// /// Gets or sets a value indicating whether to compress diff --git a/src/ImageSharp/Processing/Transforms/RotateExtensions.cs b/src/ImageSharp/Processing/Transforms/RotateExtensions.cs index e4a233ba45..28819099e9 100644 --- a/src/ImageSharp/Processing/Transforms/RotateExtensions.cs +++ b/src/ImageSharp/Processing/Transforms/RotateExtensions.cs @@ -17,11 +17,11 @@ namespace SixLabors.ImageSharp.Processing.Transforms /// /// The pixel format. /// The image to rotate. - /// The to perform the rotation. + /// The to perform the rotation. /// The - public static IImageProcessingContext Rotate(this IImageProcessingContext source, RotateType rotateType) + public static IImageProcessingContext Rotate(this IImageProcessingContext source, RotateMode rotateMode) where TPixel : struct, IPixel - => Rotate(source, (float)rotateType); + => Rotate(source, (float)rotateMode); /// /// Rotates an image by the given angle in degrees. @@ -32,7 +32,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms /// The public static IImageProcessingContext Rotate(this IImageProcessingContext source, float degrees) where TPixel : struct, IPixel - => Rotate(source, degrees, ResampleMode.Bicubic); + => Rotate(source, degrees, KnownResamplers.Bicubic); /// /// Rotates an image by the given angle in degrees using the specified sampling algorithm. diff --git a/src/ImageSharp/Processing/Transforms/RotateFlipExtensions.cs b/src/ImageSharp/Processing/Transforms/RotateFlipExtensions.cs index 693c0d8ad7..66bb27b365 100644 --- a/src/ImageSharp/Processing/Transforms/RotateFlipExtensions.cs +++ b/src/ImageSharp/Processing/Transforms/RotateFlipExtensions.cs @@ -15,11 +15,11 @@ namespace SixLabors.ImageSharp.Processing.Transforms /// /// The pixel format. /// The image to rotate, flip, or both. - /// The to perform the rotation. - /// The to perform the flip. + /// The to perform the rotation. + /// The to perform the flip. /// The - public static IImageProcessingContext RotateFlip(this IImageProcessingContext source, RotateType rotateType, FlipType flipType) + public static IImageProcessingContext RotateFlip(this IImageProcessingContext source, RotateMode rotateMode, FlipMode flipMode) where TPixel : struct, IPixel - => source.Rotate(rotateType).Flip(flipType); + => source.Rotate(rotateMode).Flip(flipMode); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/RotateType.cs b/src/ImageSharp/Processing/Transforms/RotateMode.cs similarity index 96% rename from src/ImageSharp/Processing/Transforms/RotateType.cs rename to src/ImageSharp/Processing/Transforms/RotateMode.cs index 498ad4149a..6f66d0c09e 100644 --- a/src/ImageSharp/Processing/Transforms/RotateType.cs +++ b/src/ImageSharp/Processing/Transforms/RotateMode.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms /// /// Provides enumeration over how the image should be rotated. /// - public enum RotateType + public enum RotateMode { /// /// Do not rotate the image. diff --git a/src/ImageSharp/Processing/Transforms/SkewExtensions.cs b/src/ImageSharp/Processing/Transforms/SkewExtensions.cs index 686f2c87c8..cbb4148889 100644 --- a/src/ImageSharp/Processing/Transforms/SkewExtensions.cs +++ b/src/ImageSharp/Processing/Transforms/SkewExtensions.cs @@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms /// The public static IImageProcessingContext Skew(this IImageProcessingContext source, float degreesX, float degreesY) where TPixel : struct, IPixel - => Skew(source, degreesX, degreesY, ResampleMode.Bicubic); + => Skew(source, degreesX, degreesY, KnownResamplers.Bicubic); /// /// Skews an image by the given angles in degrees using the specified sampling algorithm. diff --git a/src/ImageSharp/Processing/Transforms/TransformExtensions.cs b/src/ImageSharp/Processing/Transforms/TransformExtensions.cs index 865511b26d..585288d8a8 100644 --- a/src/ImageSharp/Processing/Transforms/TransformExtensions.cs +++ b/src/ImageSharp/Processing/Transforms/TransformExtensions.cs @@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms /// The public static IImageProcessingContext Transform(this IImageProcessingContext source, Matrix3x2 matrix) where TPixel : struct, IPixel - => Transform(source, matrix, ResampleMode.Bicubic); + => Transform(source, matrix, KnownResamplers.Bicubic); /// /// Transforms an image by the given matrix using the specified sampling algorithm. @@ -88,7 +88,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms /// The internal static IImageProcessingContext Transform(this IImageProcessingContext source, Matrix4x4 matrix) where TPixel : struct, IPixel - => Transform(source, matrix, ResampleMode.Bicubic); + => Transform(source, matrix, KnownResamplers.Bicubic); /// /// Applies a projective transform to the image by the given matrix using the specified sampling algorithm. diff --git a/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs b/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs index cf65833ea6..3e7f3648fb 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs @@ -66,7 +66,7 @@ namespace SixLabors.ImageSharp.Tests // We pass a new rectangle here based on the dest bounds since we've offset the matrix blend.Mutate(x => x.Transform( centeredMatrix, - ResampleMode.Bicubic, + KnownResamplers.Bicubic, new Rectangle(0, 0, destBounds.Width, destBounds.Height))); var position = new Point((image.Width - blend.Width) / 2, (image.Height - blend.Height) / 2); diff --git a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs index b78a8083e2..26b5dca271 100644 --- a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs +++ b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs @@ -74,7 +74,7 @@ namespace SixLabors.ImageSharp.Tests { using (FileStream output = File.OpenWrite($"{path}/Octree-{file.FileName}")) { - image.Mutate(x => x.Quantize(QuantizationMode.Octree)); + image.Mutate(x => x.Quantize(KnownQuantizers.Octree)); image.Save(output, mimeType); } @@ -84,7 +84,7 @@ namespace SixLabors.ImageSharp.Tests { using (FileStream output = File.OpenWrite($"{path}/Wu-{file.FileName}")) { - image.Mutate(x => x.Quantize(QuantizationMode.Wu)); + image.Mutate(x => x.Quantize(KnownQuantizers.Wu)); image.Save(output, mimeType); } } @@ -93,7 +93,7 @@ namespace SixLabors.ImageSharp.Tests { using (FileStream output = File.OpenWrite($"{path}/Palette-{file.FileName}")) { - image.Mutate(x => x.Quantize(QuantizationMode.Palette)); + image.Mutate(x => x.Quantize(KnownQuantizers.Palette)); image.Save(output, mimeType); } } diff --git a/tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs b/tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs index 1cb35596c5..43c53570a1 100644 --- a/tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs +++ b/tests/ImageSharp.Tests/MetaData/ImageMetaDataTests.cs @@ -6,6 +6,8 @@ using SixLabors.ImageSharp.Formats.Gif; using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.MetaData.Profiles.Exif; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; + using Xunit; namespace SixLabors.ImageSharp.Tests diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs index 5e7e9e3a79..65a469b6f1 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs +++ b/tests/ImageSharp.Tests/MetaData/Profiles/Exif/ExifProfileTests.cs @@ -9,6 +9,8 @@ using System.Text; using SixLabors.ImageSharp.MetaData; using SixLabors.ImageSharp.MetaData.Profiles.Exif; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; + using Xunit; namespace SixLabors.ImageSharp.Tests diff --git a/tests/ImageSharp.Tests/Numerics/RationalTests.cs b/tests/ImageSharp.Tests/Numerics/RationalTests.cs index 61eeed01f5..71bf71fa0e 100644 --- a/tests/ImageSharp.Tests/Numerics/RationalTests.cs +++ b/tests/ImageSharp.Tests/Numerics/RationalTests.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.MetaData.Profiles.Exif; +using SixLabors.ImageSharp.Primitives; + using Xunit; namespace SixLabors.ImageSharp.Tests diff --git a/tests/ImageSharp.Tests/Numerics/SignedRationalTests.cs b/tests/ImageSharp.Tests/Numerics/SignedRationalTests.cs index af5388d1cf..b22e84f3c6 100644 --- a/tests/ImageSharp.Tests/Numerics/SignedRationalTests.cs +++ b/tests/ImageSharp.Tests/Numerics/SignedRationalTests.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.MetaData.Profiles.Exif; +using SixLabors.ImageSharp.Primitives; + using Xunit; namespace SixLabors.ImageSharp.Tests diff --git a/tests/ImageSharp.Tests/Processing/Binarization/BinaryDitherTest.cs b/tests/ImageSharp.Tests/Processing/Binarization/BinaryDitherTest.cs index a742171b19..d88491638d 100644 --- a/tests/ImageSharp.Tests/Processing/Binarization/BinaryDitherTest.cs +++ b/tests/ImageSharp.Tests/Processing/Binarization/BinaryDitherTest.cs @@ -20,8 +20,8 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization public BinaryDitherTest() { - this.orderedDither = DitherMode.BayerDither4x4; - this.errorDiffuser = DiffuseMode.FloydSteinberg; + this.orderedDither = KnownDitherMatrices.BayerDither4x4; + this.errorDiffuser = KnownDiffusers.FloydSteinberg; } [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Dithering/DitherTest.cs b/tests/ImageSharp.Tests/Processing/Dithering/DitherTest.cs index 69aee9bc81..1526644bbe 100644 --- a/tests/ImageSharp.Tests/Processing/Dithering/DitherTest.cs +++ b/tests/ImageSharp.Tests/Processing/Dithering/DitherTest.cs @@ -25,8 +25,8 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization public DitherTest() { - this.orderedDither = DitherMode.BayerDither4x4; - this.errorDiffuser = DiffuseMode.FloydSteinberg; + this.orderedDither = KnownDitherMatrices.BayerDither4x4; + this.errorDiffuser = KnownDiffusers.FloydSteinberg; } [Fact] diff --git a/tests/ImageSharp.Tests/Processing/Filters/ColorBlindnessTest.cs b/tests/ImageSharp.Tests/Processing/Filters/ColorBlindnessTest.cs index 29d18897fb..04b916b6e2 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/ColorBlindnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/ColorBlindnessTest.cs @@ -17,19 +17,19 @@ namespace SixLabors.ImageSharp.Tests.Processing.Filters public class ColorBlindnessTest : BaseImageOperationsExtensionTest { public static IEnumerable TheoryData = new[] { - new object[]{ new TestType>(), ColorBlindness.Achromatomaly }, - new object[]{ new TestType>(), ColorBlindness.Achromatopsia }, - new object[]{ new TestType>(), ColorBlindness.Deuteranomaly }, - new object[]{ new TestType>(), ColorBlindness.Deuteranopia }, - new object[]{ new TestType>(), ColorBlindness.Protanomaly }, - new object[]{ new TestType>(), ColorBlindness.Protanopia }, - new object[]{ new TestType>(), ColorBlindness.Tritanomaly }, - new object[]{ new TestType>(), ColorBlindness.Tritanopia } + new object[]{ new TestType>(), ColorBlindnessMode.Achromatomaly }, + new object[]{ new TestType>(), ColorBlindnessMode.Achromatopsia }, + new object[]{ new TestType>(), ColorBlindnessMode.Deuteranomaly }, + new object[]{ new TestType>(), ColorBlindnessMode.Deuteranopia }, + new object[]{ new TestType>(), ColorBlindnessMode.Protanomaly }, + new object[]{ new TestType>(), ColorBlindnessMode.Protanopia }, + new object[]{ new TestType>(), ColorBlindnessMode.Tritanomaly }, + new object[]{ new TestType>(), ColorBlindnessMode.Tritanopia } }; [Theory] [MemberData(nameof(TheoryData))] - public void ColorBlindness_CorrectProcessor(TestType testType, ColorBlindness colorBlindness) + public void ColorBlindness_CorrectProcessor(TestType testType, ColorBlindnessMode colorBlindness) where T : IImageProcessor { this.operations.ColorBlindness(colorBlindness); @@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Filters } [Theory] [MemberData(nameof(TheoryData))] - public void ColorBlindness_rect_CorrectProcessor(TestType testType, ColorBlindness colorBlindness) + public void ColorBlindness_rect_CorrectProcessor(TestType testType, ColorBlindnessMode colorBlindness) where T : IImageProcessor { this.operations.ColorBlindness(colorBlindness, this.rect); diff --git a/tests/ImageSharp.Tests/Processing/Filters/FilterTest.cs b/tests/ImageSharp.Tests/Processing/Filters/FilterTest.cs index 77325b24cc..eb6d7c38c5 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/FilterTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/FilterTest.cs @@ -16,14 +16,14 @@ namespace SixLabors.ImageSharp.Tests.Processing.Filters [Fact] public void Filter_CorrectProcessor() { - this.operations.Filter(MatrixFilters.AchromatomalyFilter * MatrixFilters.CreateHueFilter(90F)); + this.operations.Filter(KnownMatrixFilters.AchromatomalyFilter * KnownMatrixFilters.CreateHueFilter(90F)); FilterProcessor p = this.Verify>(); } [Fact] public void Filter_rect_CorrectProcessor() { - this.operations.Filter(MatrixFilters.AchromatomalyFilter * MatrixFilters.CreateHueFilter(90F), this.rect); + this.operations.Filter(KnownMatrixFilters.AchromatomalyFilter * KnownMatrixFilters.CreateHueFilter(90F), this.rect); FilterProcessor p = this.Verify>(this.rect); } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryDitherTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryDitherTests.cs index 2937573395..b75087bc4a 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryDitherTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryDitherTests.cs @@ -25,29 +25,29 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization public static readonly TheoryData OrderedDitherers = new TheoryData { - { "Bayer8x8", DitherMode.BayerDither8x8 }, - { "Bayer4x4", DitherMode.BayerDither4x4 }, - { "Ordered3x3", DitherMode.OrderedDither3x3 }, - { "Bayer2x2", DitherMode.BayerDither2x2 } + { "Bayer8x8", KnownDitherMatrices.BayerDither8x8 }, + { "Bayer4x4", KnownDitherMatrices.BayerDither4x4 }, + { "Ordered3x3", KnownDitherMatrices.OrderedDither3x3 }, + { "Bayer2x2", KnownDitherMatrices.BayerDither2x2 } }; public static readonly TheoryData ErrorDiffusers = new TheoryData { - { "Atkinson", DiffuseMode.Atkinson }, - { "Burks", DiffuseMode.Burks }, - { "FloydSteinberg", DiffuseMode.FloydSteinberg }, - { "JarvisJudiceNinke", DiffuseMode.JarvisJudiceNinke }, - { "Sierra2", DiffuseMode.Sierra2 }, - { "Sierra3", DiffuseMode.Sierra3 }, - { "SierraLite", DiffuseMode.SierraLite }, - { "StevensonArce", DiffuseMode.StevensonArce }, - { "Stucki", DiffuseMode.Stucki }, + { "Atkinson", KnownDiffusers.Atkinson }, + { "Burks", KnownDiffusers.Burks }, + { "FloydSteinberg", KnownDiffusers.FloydSteinberg }, + { "JarvisJudiceNinke", KnownDiffusers.JarvisJudiceNinke }, + { "Sierra2", KnownDiffusers.Sierra2 }, + { "Sierra3", KnownDiffusers.Sierra3 }, + { "SierraLite", KnownDiffusers.SierraLite }, + { "StevensonArce", KnownDiffusers.StevensonArce }, + { "Stucki", KnownDiffusers.Stucki }, }; - private static IOrderedDither DefaultDitherer => DitherMode.BayerDither4x4; + private static IOrderedDither DefaultDitherer => KnownDitherMatrices.BayerDither4x4; - private static IErrorDiffuser DefaultErrorDiffuser => DiffuseMode.Atkinson; + private static IErrorDiffuser DefaultErrorDiffuser => KnownDiffusers.Atkinson; [Theory] [WithFileCollection(nameof(CommonTestImages), nameof(OrderedDitherers), DefaultPixelType)] diff --git a/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs index 3bb3aedfcf..64e62fb2a4 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs @@ -24,29 +24,29 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization public static readonly TheoryData OrderedDitherers = new TheoryData { - { "Bayer8x8", DitherMode.BayerDither8x8 }, - { "Bayer4x4", DitherMode.BayerDither4x4 }, - { "Ordered3x3", DitherMode.OrderedDither3x3 }, - { "Bayer2x2", DitherMode.BayerDither2x2 } + { "Bayer8x8", KnownDitherMatrices.BayerDither8x8 }, + { "Bayer4x4", KnownDitherMatrices.BayerDither4x4 }, + { "Ordered3x3", KnownDitherMatrices.OrderedDither3x3 }, + { "Bayer2x2", KnownDitherMatrices.BayerDither2x2 } }; public static readonly TheoryData ErrorDiffusers = new TheoryData { - { "Atkinson", DiffuseMode.Atkinson }, - { "Burks", DiffuseMode.Burks }, - { "FloydSteinberg", DiffuseMode.FloydSteinberg }, - { "JarvisJudiceNinke", DiffuseMode.JarvisJudiceNinke }, - { "Sierra2", DiffuseMode.Sierra2 }, - { "Sierra3", DiffuseMode.Sierra3 }, - { "SierraLite", DiffuseMode.SierraLite }, - { "StevensonArce", DiffuseMode.StevensonArce }, - { "Stucki", DiffuseMode.Stucki }, + { "Atkinson", KnownDiffusers.Atkinson }, + { "Burks", KnownDiffusers.Burks }, + { "FloydSteinberg", KnownDiffusers.FloydSteinberg }, + { "JarvisJudiceNinke", KnownDiffusers.JarvisJudiceNinke }, + { "Sierra2", KnownDiffusers.Sierra2 }, + { "Sierra3", KnownDiffusers.Sierra3 }, + { "SierraLite", KnownDiffusers.SierraLite }, + { "StevensonArce", KnownDiffusers.StevensonArce }, + { "Stucki", KnownDiffusers.Stucki }, }; - private static IOrderedDither DefaultDitherer => DitherMode.BayerDither4x4; + private static IOrderedDither DefaultDitherer => KnownDitherMatrices.BayerDither4x4; - private static IErrorDiffuser DefaultErrorDiffuser => DiffuseMode.Atkinson; + private static IErrorDiffuser DefaultErrorDiffuser => KnownDiffusers.Atkinson; [Theory] [WithFileCollection(nameof(CommonTestImages), nameof(OrderedDitherers), DefaultPixelType)] diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/ColorBlindnessTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/ColorBlindnessTest.cs index b0dcbd726b..fd77245313 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/ColorBlindnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/ColorBlindnessTest.cs @@ -13,22 +13,22 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters [GroupOutput("Filters")] public class ColorBlindnessTest { - public static readonly TheoryData ColorBlindnessFilters - = new TheoryData + public static readonly TheoryData ColorBlindnessFilters + = new TheoryData { - ColorBlindness.Achromatomaly, - ColorBlindness.Achromatopsia, - ColorBlindness.Deuteranomaly, - ColorBlindness.Deuteranopia, - ColorBlindness.Protanomaly, - ColorBlindness.Protanopia, - ColorBlindness.Tritanomaly, - ColorBlindness.Tritanopia + ColorBlindnessMode.Achromatomaly, + ColorBlindnessMode.Achromatopsia, + ColorBlindnessMode.Deuteranomaly, + ColorBlindnessMode.Deuteranopia, + ColorBlindnessMode.Protanomaly, + ColorBlindnessMode.Protanopia, + ColorBlindnessMode.Tritanomaly, + ColorBlindnessMode.Tritanopia }; [Theory] [WithTestPatternImages(nameof(ColorBlindnessFilters), 48, 48, PixelTypes.Rgba32)] - public void ApplyColorBlindnessFilter(TestImageProvider provider, ColorBlindness colorBlindness) + public void ApplyColorBlindnessFilter(TestImageProvider provider, ColorBlindnessMode colorBlindness) where TPixel : struct, IPixel { provider.RunValidatingProcessorTest(x => x.ColorBlindness(colorBlindness), colorBlindness.ToString()); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/FilterTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/FilterTest.cs index 077073b4c7..226ebd6732 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/FilterTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/FilterTest.cs @@ -40,9 +40,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters private static Matrix4x4 CreateCombinedTestFilterMatrix() { - Matrix4x4 brightness = MatrixFilters.CreateBrightnessFilter(0.9F); - Matrix4x4 hue = MatrixFilters.CreateHueFilter(180F); - Matrix4x4 saturation = MatrixFilters.CreateSaturateFilter(1.5F); + Matrix4x4 brightness = KnownMatrixFilters.CreateBrightnessFilter(0.9F); + Matrix4x4 hue = KnownMatrixFilters.CreateHueFilter(180F); + Matrix4x4 saturation = KnownMatrixFilters.CreateSaturateFilter(1.5F); Matrix4x4 m = brightness * hue * saturation; return m; } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs index fb1a7f0a38..d421a5936e 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs @@ -15,18 +15,18 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { public static readonly string[] FlipFiles = { TestImages.Bmp.F }; - public static readonly TheoryData OrientationValues - = new TheoryData + public static readonly TheoryData OrientationValues + = new TheoryData { - { RotateType.None, FlipType.None, 0 }, - { RotateType.None, FlipType.None, 1 }, - { RotateType.None, FlipType.Horizontal, 2 }, - { RotateType.Rotate180, FlipType.None, 3 }, - { RotateType.Rotate180, FlipType.Horizontal, 4 }, - { RotateType.Rotate90, FlipType.Horizontal, 5 }, - { RotateType.Rotate270, FlipType.None, 6 }, - { RotateType.Rotate90, FlipType.Vertical, 7 }, - { RotateType.Rotate90, FlipType.None, 8 }, + { RotateMode.None, FlipMode.None, 0 }, + { RotateMode.None, FlipMode.None, 1 }, + { RotateMode.None, FlipMode.Horizontal, 2 }, + { RotateMode.Rotate180, FlipMode.None, 3 }, + { RotateMode.Rotate180, FlipMode.Horizontal, 4 }, + { RotateMode.Rotate90, FlipMode.Horizontal, 5 }, + { RotateMode.Rotate270, FlipMode.None, 6 }, + { RotateMode.Rotate90, FlipMode.Vertical, 7 }, + { RotateMode.Rotate90, FlipMode.None, 8 }, }; public static readonly TheoryData InvalidOrientationValues @@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms [Theory] [WithFileCollection(nameof(FlipFiles), nameof(OrientationValues), DefaultPixelType)] - public void ImageShouldAutoRotate(TestImageProvider provider, RotateType rotateType, FlipType flipType, ushort orientation) + public void ImageShouldAutoRotate(TestImageProvider provider, RotateMode rotateType, FlipMode flipType, ushort orientation) where TPixel : struct, IPixel { using (Image image = provider.GetImage()) diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs index 7a4743e449..b1ce7ae1f1 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs @@ -13,17 +13,17 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { public static readonly string[] FlipFiles = { TestImages.Bmp.F }; - public static readonly TheoryData FlipValues - = new TheoryData + public static readonly TheoryData FlipValues + = new TheoryData { - { FlipType.None }, - { FlipType.Vertical }, - { FlipType.Horizontal }, + { FlipMode.None }, + { FlipMode.Vertical }, + { FlipMode.Horizontal }, }; [Theory] [WithFileCollection(nameof(FlipFiles), nameof(FlipValues), DefaultPixelType)] - public void ImageShouldFlip(TestImageProvider provider, FlipType flipType) + public void ImageShouldFlip(TestImageProvider provider, FlipMode flipType) where TPixel : struct, IPixel { using (Image image = provider.GetImage()) diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs index bbb0b1db96..cf070ccbb1 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs @@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms public void PrintWeightsData() { var size = new Size(500, 500); - var proc = new ResizeProcessor(ResampleMode.Bicubic, 200, 200, size); + var proc = new ResizeProcessor(KnownResamplers.Bicubic, 200, 200, size); WeightsBuffer weights = proc.PrecomputeWeights(Configuration.Default.MemoryManager, proc.Width, size.Width); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs index 46e7b119e2..ae763d65c9 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs @@ -20,20 +20,20 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms public static readonly TheoryData AllReSamplers = new TheoryData { - { "Bicubic", ResampleMode.Bicubic }, - { "Triangle", ResampleMode.Triangle}, - { "NearestNeighbor", ResampleMode.NearestNeighbor }, - { "Box", ResampleMode.Box }, + { "Bicubic", KnownResamplers.Bicubic }, + { "Triangle", KnownResamplers.Triangle}, + { "NearestNeighbor", KnownResamplers.NearestNeighbor }, + { "Box", KnownResamplers.Box }, // { "Lanczos2", KnownResamplers.Lanczos2 }, TODO: Add expected file - { "Lanczos3", ResampleMode.Lanczos3 }, - { "Lanczos5", ResampleMode.Lanczos5 }, - { "MitchellNetravali", ResampleMode.MitchellNetravali }, - { "Lanczos8", ResampleMode.Lanczos8 }, - { "Hermite", ResampleMode.Hermite }, - { "Spline", ResampleMode.Spline }, - { "Robidoux", ResampleMode.Robidoux }, - { "RobidouxSharp", ResampleMode.RobidouxSharp }, - { "Welch", ResampleMode.Welch } + { "Lanczos3", KnownResamplers.Lanczos3 }, + { "Lanczos5", KnownResamplers.Lanczos5 }, + { "MitchellNetravali", KnownResamplers.MitchellNetravali }, + { "Lanczos8", KnownResamplers.Lanczos8 }, + { "Hermite", KnownResamplers.Hermite }, + { "Spline", KnownResamplers.Spline }, + { "Robidoux", KnownResamplers.Robidoux }, + { "RobidouxSharp", KnownResamplers.RobidouxSharp }, + { "Welch", KnownResamplers.Welch } }; [Theory] @@ -102,7 +102,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { using (Image image = provider.GetImage()) { - image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2, ResampleMode.NearestNeighbor)); + image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2, KnownResamplers.NearestNeighbor)); // Comparer fights decoder with gif-s. Could not use CompareToReferenceOutput here :( image.DebugSave(provider, extension: Extensions.Gif); @@ -119,7 +119,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms var sourceRectangle = new Rectangle(image.Width / 8, image.Height / 8, image.Width / 4, image.Height / 4); var destRectangle = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); - image.Mutate(x => x.Resize(image.Width, image.Height, ResampleMode.Bicubic, sourceRectangle, destRectangle, false)); + image.Mutate(x => x.Resize(image.Width, image.Height, KnownResamplers.Bicubic, sourceRectangle, destRectangle, false)); image.DebugSave(provider); image.CompareToReferenceOutput(provider); @@ -300,7 +300,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms [InlineData(2, 0)] public static void BicubicWindowOscillatesCorrectly(float x, float expected) { - var sampler = ResampleMode.Bicubic; + var sampler = KnownResamplers.Bicubic; float result = sampler.GetValue(x); Assert.Equal(result, expected); @@ -314,7 +314,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms [InlineData(2, 0)] public static void TriangleWindowOscillatesCorrectly(float x, float expected) { - var sampler = ResampleMode.Triangle; + var sampler = KnownResamplers.Triangle; float result = sampler.GetValue(x); Assert.Equal(result, expected); @@ -328,7 +328,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms [InlineData(2, 0)] public static void Lanczos3WindowOscillatesCorrectly(float x, float expected) { - var sampler = ResampleMode.Lanczos3; + var sampler = KnownResamplers.Lanczos3; float result = sampler.GetValue(x); Assert.Equal(result, expected); @@ -342,7 +342,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms [InlineData(4, 0)] public static void Lanczos5WindowOscillatesCorrectly(float x, float expected) { - var sampler = ResampleMode.Lanczos5; + var sampler = KnownResamplers.Lanczos5; float result = sampler.GetValue(x); Assert.Equal(result, expected); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs index f15ed3cc7e..b2865d9da5 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs @@ -13,20 +13,20 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { public static readonly string[] FlipFiles = { TestImages.Bmp.F }; - public static readonly TheoryData RotateFlipValues - = new TheoryData + public static readonly TheoryData RotateFlipValues + = new TheoryData { - { RotateType.None, FlipType.Vertical }, - { RotateType.None, FlipType.Horizontal }, - { RotateType.Rotate90, FlipType.None }, - { RotateType.Rotate180, FlipType.None }, - { RotateType.Rotate270, FlipType.None }, + { RotateMode.None, FlipMode.Vertical }, + { RotateMode.None, FlipMode.Horizontal }, + { RotateMode.Rotate90, FlipMode.None }, + { RotateMode.Rotate180, FlipMode.None }, + { RotateMode.Rotate270, FlipMode.None }, }; [Theory] [WithTestPatternImages(nameof(RotateFlipValues), 100, 50, DefaultPixelType)] [WithTestPatternImages(nameof(RotateFlipValues), 50, 100, DefaultPixelType)] - public void RotateFlip(TestImageProvider provider, RotateType rotateType, FlipType flipType) + public void RotateFlip(TestImageProvider provider, RotateMode rotateType, FlipMode flipType) where TPixel : struct, IPixel { using (Image image = provider.GetImage()) diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs index 54e2a4a185..f9c2d83c88 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs @@ -21,13 +21,13 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms 50, -50, 170, -170 }; - public static readonly TheoryData RotateEnumValues - = new TheoryData + public static readonly TheoryData RotateEnumValues + = new TheoryData { - RotateType.None, - RotateType.Rotate90, - RotateType.Rotate180, - RotateType.Rotate270 + RotateMode.None, + RotateMode.Rotate90, + RotateMode.Rotate180, + RotateMode.Rotate270 }; [Theory] @@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms [Theory] [WithTestPatternImages(nameof(RotateEnumValues), 100, 50, DefaultPixelType)] [WithTestPatternImages(nameof(RotateEnumValues), 50, 100, DefaultPixelType)] - public void Rotate_WithRotateTypeEnum(TestImageProvider provider, RotateType value) + public void Rotate_WithRotateTypeEnum(TestImageProvider provider, RotateMode value) where TPixel : struct, IPixel { using (Image image = provider.GetImage()) diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs index 174aadf602..30c9e682de 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs @@ -26,21 +26,21 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms public static readonly List ResamplerNames = new List { - nameof(ResampleMode.Bicubic), - nameof(ResampleMode.Box), - nameof(ResampleMode.CatmullRom), - nameof(ResampleMode.Hermite), - nameof(ResampleMode.Lanczos2), - nameof(ResampleMode.Lanczos3), - nameof(ResampleMode.Lanczos5), - nameof(ResampleMode.Lanczos8), - nameof(ResampleMode.MitchellNetravali), - nameof(ResampleMode.NearestNeighbor), - nameof(ResampleMode.Robidoux), - nameof(ResampleMode.RobidouxSharp), - nameof(ResampleMode.Spline), - nameof(ResampleMode.Triangle), - nameof(ResampleMode.Welch), + nameof(KnownResamplers.Bicubic), + nameof(KnownResamplers.Box), + nameof(KnownResamplers.CatmullRom), + nameof(KnownResamplers.Hermite), + nameof(KnownResamplers.Lanczos2), + nameof(KnownResamplers.Lanczos3), + nameof(KnownResamplers.Lanczos5), + nameof(KnownResamplers.Lanczos8), + nameof(KnownResamplers.MitchellNetravali), + nameof(KnownResamplers.NearestNeighbor), + nameof(KnownResamplers.Robidoux), + nameof(KnownResamplers.RobidouxSharp), + nameof(KnownResamplers.Spline), + nameof(KnownResamplers.Triangle), + nameof(KnownResamplers.Welch), }; [Theory] @@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms private static IResampler GetResampler(string name) { - PropertyInfo property = typeof(ResampleMode).GetTypeInfo().GetProperty(name); + PropertyInfo property = typeof(KnownResamplers).GetTypeInfo().GetProperty(name); if (property == null) { diff --git a/tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs index 02144e0735..605f4075a3 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs @@ -38,30 +38,30 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms public static readonly TheoryData ResamplerNames = new TheoryData { - nameof(ResampleMode.Bicubic), - nameof(ResampleMode.Box), - nameof(ResampleMode.CatmullRom), - nameof(ResampleMode.Hermite), - nameof(ResampleMode.Lanczos2), - nameof(ResampleMode.Lanczos3), - nameof(ResampleMode.Lanczos5), - nameof(ResampleMode.Lanczos8), - nameof(ResampleMode.MitchellNetravali), - nameof(ResampleMode.NearestNeighbor), - nameof(ResampleMode.Robidoux), - nameof(ResampleMode.RobidouxSharp), - nameof(ResampleMode.Spline), - nameof(ResampleMode.Triangle), - nameof(ResampleMode.Welch), + nameof(KnownResamplers.Bicubic), + nameof(KnownResamplers.Box), + nameof(KnownResamplers.CatmullRom), + nameof(KnownResamplers.Hermite), + nameof(KnownResamplers.Lanczos2), + nameof(KnownResamplers.Lanczos3), + nameof(KnownResamplers.Lanczos5), + nameof(KnownResamplers.Lanczos8), + nameof(KnownResamplers.MitchellNetravali), + nameof(KnownResamplers.NearestNeighbor), + nameof(KnownResamplers.Robidoux), + nameof(KnownResamplers.RobidouxSharp), + nameof(KnownResamplers.Spline), + nameof(KnownResamplers.Triangle), + nameof(KnownResamplers.Welch), }; public static readonly TheoryData Transform_DoesNotCreateEdgeArtifacts_ResamplerNames = new TheoryData { - nameof(ResampleMode.NearestNeighbor), - nameof(ResampleMode.Triangle), - nameof(ResampleMode.Bicubic), - nameof(ResampleMode.Lanczos8), + nameof(KnownResamplers.NearestNeighbor), + nameof(KnownResamplers.Triangle), + nameof(KnownResamplers.Bicubic), + nameof(KnownResamplers.Lanczos8), }; public AffineTransformTests(ITestOutputHelper output) @@ -113,7 +113,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms this.PrintMatrix(m); - image.Mutate(i => i.Transform(m, ResampleMode.Bicubic)); + image.Mutate(i => i.Transform(m, KnownResamplers.Bicubic)); string testOutputDetails = $"R({angleDeg})_S({sx},{sy})_T({tx},{ty})"; image.DebugSave(provider, testOutputDetails); @@ -130,7 +130,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms { Matrix3x2 m = this.MakeManuallyCenteredMatrix(angleDeg, s, image); - image.Mutate(i => i.Transform(m, ResampleMode.Bicubic)); + image.Mutate(i => i.Transform(m, KnownResamplers.Bicubic)); string testOutputDetails = $"R({angleDeg})_S({s})"; image.DebugSave(provider, testOutputDetails); @@ -163,7 +163,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms { var m = Matrix3x2.CreateScale(2.0F, 1.5F); - image.Mutate(i => i.Transform(m, ResampleMode.Spline, rectangle)); + image.Mutate(i => i.Transform(m, KnownResamplers.Spline, rectangle)); image.DebugSave(provider); image.CompareToReferenceOutput(provider); @@ -181,7 +181,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms { var m = Matrix3x2.CreateScale(1.0F, 2.0F); - image.Mutate(i => i.Transform(m, ResampleMode.Spline, rectangle)); + image.Mutate(i => i.Transform(m, KnownResamplers.Spline, rectangle)); image.DebugSave(provider); image.CompareToReferenceOutput(provider); @@ -225,7 +225,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms private static IResampler GetResampler(string name) { - PropertyInfo property = typeof(ResampleMode).GetTypeInfo().GetProperty(name); + PropertyInfo property = typeof(KnownResamplers).GetTypeInfo().GetProperty(name); if (property == null) { diff --git a/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs index 0ab9978d1b..41aeb1ad56 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs @@ -16,15 +16,15 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms { [Theory] - [InlineData(FlipType.None)] - [InlineData(FlipType.Horizontal)] - [InlineData(FlipType.Vertical)] - public void Flip_degreesFloat_RotateProcessorWithAnglesSetAndExpandTrue(FlipType flip) + [InlineData(FlipMode.None)] + [InlineData(FlipMode.Horizontal)] + [InlineData(FlipMode.Vertical)] + public void Flip_degreesFloat_RotateProcessorWithAnglesSetAndExpandTrue(FlipMode flip) { this.operations.Flip(flip); FlipProcessor flipProcessor = this.Verify>(); - Assert.Equal(flip, flipProcessor.FlipType); + Assert.Equal(flip, flipProcessor.FlipMode); } } } diff --git a/tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs index 6d7816f59d..dd4c314589 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms { int width = 500; int height = 565; - IResampler sampler = ResampleMode.NearestNeighbor; + IResampler sampler = KnownResamplers.NearestNeighbor; this.operations.Pad(width, height); ResizeProcessor resizeProcessor = this.Verify>(); diff --git a/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs index 853f4b3e65..ee72f361bb 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs @@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms { int width = 50; int height = 100; - IResampler sampler = ResampleMode.Lanczos3; + IResampler sampler = KnownResamplers.Lanczos3; this.operations.Resize(width, height, sampler); ResizeProcessor resizeProcessor = this.Verify>(); @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms { int width = 50; int height = 100; - IResampler sampler = ResampleMode.Lanczos3; + IResampler sampler = KnownResamplers.Lanczos3; bool compand = true; // ReSharper disable once ConditionIsAlwaysTrueOrFalse @@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms { int width = 50; int height = 100; - IResampler sampler = ResampleMode.Lanczos3; + IResampler sampler = KnownResamplers.Lanczos3; bool compand = true; ResizeMode mode = ResizeMode.Stretch; diff --git a/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs index 3d443b70c3..9a396e8714 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs @@ -11,26 +11,26 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms public class RotateFlipTests : BaseImageOperationsExtensionTest { [Theory] - [InlineData(RotateType.None, FlipType.None, 0)] - [InlineData(RotateType.Rotate90, FlipType.None, 90)] - [InlineData(RotateType.Rotate180, FlipType.None, 180)] - [InlineData(RotateType.Rotate270, FlipType.None, 270)] - [InlineData(RotateType.None, FlipType.Horizontal, 0)] - [InlineData(RotateType.Rotate90, FlipType.Horizontal, 90)] - [InlineData(RotateType.Rotate180, FlipType.Horizontal, 180)] - [InlineData(RotateType.Rotate270, FlipType.Horizontal, 270)] - [InlineData(RotateType.None, FlipType.Vertical, 0)] - [InlineData(RotateType.Rotate90, FlipType.Vertical, 90)] - [InlineData(RotateType.Rotate180, FlipType.Vertical, 180)] - [InlineData(RotateType.Rotate270, FlipType.Vertical, 270)] - public void RotateDegreesFloatRotateProcessorWithAnglesSet(RotateType angle, FlipType flip, float expectedAngle) + [InlineData(RotateMode.None, FlipMode.None, 0)] + [InlineData(RotateMode.Rotate90, FlipMode.None, 90)] + [InlineData(RotateMode.Rotate180, FlipMode.None, 180)] + [InlineData(RotateMode.Rotate270, FlipMode.None, 270)] + [InlineData(RotateMode.None, FlipMode.Horizontal, 0)] + [InlineData(RotateMode.Rotate90, FlipMode.Horizontal, 90)] + [InlineData(RotateMode.Rotate180, FlipMode.Horizontal, 180)] + [InlineData(RotateMode.Rotate270, FlipMode.Horizontal, 270)] + [InlineData(RotateMode.None, FlipMode.Vertical, 0)] + [InlineData(RotateMode.Rotate90, FlipMode.Vertical, 90)] + [InlineData(RotateMode.Rotate180, FlipMode.Vertical, 180)] + [InlineData(RotateMode.Rotate270, FlipMode.Vertical, 270)] + public void RotateDegreesFloatRotateProcessorWithAnglesSet(RotateMode angle, FlipMode flip, float expectedAngle) { this.operations.RotateFlip(angle, flip); RotateProcessor rotateProcessor = this.Verify>(0); FlipProcessor flipProcessor = this.Verify>(1); Assert.Equal(expectedAngle, rotateProcessor.Degrees); - Assert.Equal(flip, flipProcessor.FlipType); + Assert.Equal(flip, flipProcessor.FlipMode); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs index 742f633c08..e81cf83050 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs @@ -25,11 +25,11 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms } [Theory] - [InlineData(RotateType.None, 0)] - [InlineData(RotateType.Rotate90, 90)] - [InlineData(RotateType.Rotate180, 180)] - [InlineData(RotateType.Rotate270, 270)] - public void RotateRotateTypeRotateProcessorWithAnglesConvertedFromEnum(RotateType angle, float expectedAngle) + [InlineData(RotateMode.None, 0)] + [InlineData(RotateMode.Rotate90, 90)] + [InlineData(RotateMode.Rotate180, 180)] + [InlineData(RotateMode.Rotate270, 270)] + public void RotateRotateTypeRotateProcessorWithAnglesConvertedFromEnum(RotateMode angle, float expectedAngle) { this.operations.Rotate(angle); // is this api needed ??? RotateProcessor processor = this.Verify>(); From 0e11ffa3d96c6824875ce7cf9d977ecfeea9069d Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Thu, 15 Mar 2018 22:46:32 +1100 Subject: [PATCH 4/5] Add moar xml doc details. --- src/ImageSharp/Processing/Quantization/OctreeQuantizer.cs | 5 ++++- src/ImageSharp/Processing/Quantization/PaletteQuantizer.cs | 6 ++++-- src/ImageSharp/Processing/Quantization/WuQuantizer.cs | 6 ++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/ImageSharp/Processing/Quantization/OctreeQuantizer.cs b/src/ImageSharp/Processing/Quantization/OctreeQuantizer.cs index 89fa7a90ec..385ddceec2 100644 --- a/src/ImageSharp/Processing/Quantization/OctreeQuantizer.cs +++ b/src/ImageSharp/Processing/Quantization/OctreeQuantizer.cs @@ -11,6 +11,9 @@ namespace SixLabors.ImageSharp.Processing.Quantization /// /// Allows the quantization of images pixels using Octrees. /// + /// + /// By default the quantizer uses dithering and a color palette of a maximum length of 255 + /// /// public class OctreeQuantizer : IQuantizer { @@ -45,7 +48,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization /// /// The error diffusion algorithm, if any, to apply to the output image public OctreeQuantizer(IErrorDiffuser diffuser) - : this(diffuser, 255) + : this(diffuser, 255) { } diff --git a/src/ImageSharp/Processing/Quantization/PaletteQuantizer.cs b/src/ImageSharp/Processing/Quantization/PaletteQuantizer.cs index 06c5a99183..8f790dfc91 100644 --- a/src/ImageSharp/Processing/Quantization/PaletteQuantizer.cs +++ b/src/ImageSharp/Processing/Quantization/PaletteQuantizer.cs @@ -10,8 +10,10 @@ namespace SixLabors.ImageSharp.Processing.Quantization { /// /// Allows the quantization of images pixels using web safe colors defined in the CSS Color Module Level 4. - /// - /// Override this class to provide your own palette. + /// Override this class to provide your own palette. + /// + /// By default the quantizer uses dithering and the + /// /// public class PaletteQuantizer : IQuantizer { diff --git a/src/ImageSharp/Processing/Quantization/WuQuantizer.cs b/src/ImageSharp/Processing/Quantization/WuQuantizer.cs index 6b1287b465..f46cddfe6f 100644 --- a/src/ImageSharp/Processing/Quantization/WuQuantizer.cs +++ b/src/ImageSharp/Processing/Quantization/WuQuantizer.cs @@ -9,8 +9,10 @@ using SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers; namespace SixLabors.ImageSharp.Processing.Quantization { /// - /// Allows the quantization of images pixels using Xiaolin Wu's Color Quantizer. - /// + /// Allows the quantization of images pixels using Xiaolin Wu's Color Quantizer + /// + /// By default the quantizer uses dithering and a color palette of a maximum length of 255 + /// /// public class WuQuantizer : IQuantizer { From dccdc1d1810509ce7a9b1be23467759d3004e7bf Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Fri, 16 Mar 2018 10:54:48 +1100 Subject: [PATCH 5/5] Rename types --- .../Processing/Dithering/DitherExtensions.cs | 2 +- .../{KnownDitherMatrices.cs => KnownDitherers.cs} | 2 +- .../{KnownMatrixFilters.cs => KnownFilterMatrices.cs} | 2 +- .../Filters/Processors/AchromatomalyProcessor.cs | 2 +- .../Filters/Processors/AchromatopsiaProcessor.cs | 2 +- .../Filters/Processors/BlackWhiteProcessor.cs | 2 +- .../Filters/Processors/BrightnessProcessor.cs | 2 +- .../Processing/Filters/Processors/ContrastProcessor.cs | 2 +- .../Filters/Processors/DeuteranomalyProcessor.cs | 2 +- .../Filters/Processors/DeuteranopiaProcessor.cs | 2 +- .../Filters/Processors/GrayscaleBt601Processor.cs | 2 +- .../Filters/Processors/GrayscaleBt709Processor.cs | 2 +- .../Processing/Filters/Processors/HueProcessor.cs | 2 +- .../Processing/Filters/Processors/InvertProcessor.cs | 2 +- .../Filters/Processors/KodachromeProcessor.cs | 2 +- .../Filters/Processors/LomographProcessor.cs | 2 +- .../Processing/Filters/Processors/OpacityProcessor.cs | 2 +- .../Processing/Filters/Processors/PolaroidProcessor.cs | 2 +- .../Filters/Processors/ProtanomalyProcessor.cs | 2 +- .../Filters/Processors/ProtanopiaProcessor.cs | 2 +- .../Processing/Filters/Processors/SaturateProcessor.cs | 2 +- .../Processing/Filters/Processors/SepiaProcessor.cs | 2 +- .../Filters/Processors/TritanomalyProcessor.cs | 2 +- .../Filters/Processors/TritanopiaProcessor.cs | 2 +- .../Processing/Binarization/BinaryDitherTest.cs | 2 +- .../Processing/Dithering/DitherTest.cs | 2 +- .../ImageSharp.Tests/Processing/Filters/FilterTest.cs | 4 ++-- .../Processors/Binarization/BinaryDitherTests.cs | 10 +++++----- .../Processing/Processors/Dithering/DitherTests.cs | 10 +++++----- .../Processing/Processors/Filters/FilterTest.cs | 6 +++--- 30 files changed, 41 insertions(+), 41 deletions(-) rename src/ImageSharp/Processing/Dithering/{KnownDitherMatrices.cs => KnownDitherers.cs} (96%) rename src/ImageSharp/Processing/Filters/{KnownMatrixFilters.cs => KnownFilterMatrices.cs} (99%) diff --git a/src/ImageSharp/Processing/Dithering/DitherExtensions.cs b/src/ImageSharp/Processing/Dithering/DitherExtensions.cs index 9058138550..48dd87a3b3 100644 --- a/src/ImageSharp/Processing/Dithering/DitherExtensions.cs +++ b/src/ImageSharp/Processing/Dithering/DitherExtensions.cs @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Dithering /// The . public static IImageProcessingContext Dither(this IImageProcessingContext source) where TPixel : struct, IPixel - => Dither(source, KnownDitherMatrices.BayerDither4x4); + => Dither(source, KnownDitherers.BayerDither4x4); /// /// Dithers the image reducing it to a web-safe palette using ordered dithering. diff --git a/src/ImageSharp/Processing/Dithering/KnownDitherMatrices.cs b/src/ImageSharp/Processing/Dithering/KnownDitherers.cs similarity index 96% rename from src/ImageSharp/Processing/Dithering/KnownDitherMatrices.cs rename to src/ImageSharp/Processing/Dithering/KnownDitherers.cs index 8e32584798..b268ae12c0 100644 --- a/src/ImageSharp/Processing/Dithering/KnownDitherMatrices.cs +++ b/src/ImageSharp/Processing/Dithering/KnownDitherers.cs @@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Processing.Dithering /// /// Contains reusable static instances of known ordered dither matrices /// - public class KnownDitherMatrices + public class KnownDitherers { /// /// Gets the order ditherer using the 2x2 Bayer dithering matrix diff --git a/src/ImageSharp/Processing/Filters/KnownMatrixFilters.cs b/src/ImageSharp/Processing/Filters/KnownFilterMatrices.cs similarity index 99% rename from src/ImageSharp/Processing/Filters/KnownMatrixFilters.cs rename to src/ImageSharp/Processing/Filters/KnownFilterMatrices.cs index 2b3c0a9a39..9da4aaa65f 100644 --- a/src/ImageSharp/Processing/Filters/KnownMatrixFilters.cs +++ b/src/ImageSharp/Processing/Filters/KnownFilterMatrices.cs @@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Processing.Filters /// /// A collection of known values for composing filters /// - public static class KnownMatrixFilters + public static class KnownFilterMatrices { /// /// Gets a filter recreating Achromatomaly (Color desensitivity) color blindness diff --git a/src/ImageSharp/Processing/Filters/Processors/AchromatomalyProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/AchromatomalyProcessor.cs index e1f11c094f..e7238c68c8 100644 --- a/src/ImageSharp/Processing/Filters/Processors/AchromatomalyProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/AchromatomalyProcessor.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// Initializes a new instance of the class. /// public AchromatomalyProcessor() - : base(KnownMatrixFilters.AchromatomalyFilter) + : base(KnownFilterMatrices.AchromatomalyFilter) { } } diff --git a/src/ImageSharp/Processing/Filters/Processors/AchromatopsiaProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/AchromatopsiaProcessor.cs index e9ff6177c7..b581f8925f 100644 --- a/src/ImageSharp/Processing/Filters/Processors/AchromatopsiaProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/AchromatopsiaProcessor.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// Initializes a new instance of the class. /// public AchromatopsiaProcessor() - : base(KnownMatrixFilters.AchromatopsiaFilter) + : base(KnownFilterMatrices.AchromatopsiaFilter) { } } diff --git a/src/ImageSharp/Processing/Filters/Processors/BlackWhiteProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/BlackWhiteProcessor.cs index 0b1f4dab5c..428b9d4dda 100644 --- a/src/ImageSharp/Processing/Filters/Processors/BlackWhiteProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/BlackWhiteProcessor.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// Initializes a new instance of the class. /// public BlackWhiteProcessor() - : base(KnownMatrixFilters.BlackWhiteFilter) + : base(KnownFilterMatrices.BlackWhiteFilter) { } } diff --git a/src/ImageSharp/Processing/Filters/Processors/BrightnessProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/BrightnessProcessor.cs index d4a51ed04a..e5c43bd8a1 100644 --- a/src/ImageSharp/Processing/Filters/Processors/BrightnessProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/BrightnessProcessor.cs @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// /// The proportion of the conversion. Must be greater than or equal to 0. public BrightnessProcessor(float amount) - : base(KnownMatrixFilters.CreateBrightnessFilter(amount)) + : base(KnownFilterMatrices.CreateBrightnessFilter(amount)) { this.Amount = amount; } diff --git a/src/ImageSharp/Processing/Filters/Processors/ContrastProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/ContrastProcessor.cs index 9c8e717f2f..51f8ba6b16 100644 --- a/src/ImageSharp/Processing/Filters/Processors/ContrastProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/ContrastProcessor.cs @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// /// The proportion of the conversion. Must be greater than or equal to 0. public ContrastProcessor(float amount) - : base(KnownMatrixFilters.CreateContrastFilter(amount)) + : base(KnownFilterMatrices.CreateContrastFilter(amount)) { this.Amount = amount; } diff --git a/src/ImageSharp/Processing/Filters/Processors/DeuteranomalyProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/DeuteranomalyProcessor.cs index afb5bbd531..d93068c8cd 100644 --- a/src/ImageSharp/Processing/Filters/Processors/DeuteranomalyProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/DeuteranomalyProcessor.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// Initializes a new instance of the class. /// public DeuteranomalyProcessor() - : base(KnownMatrixFilters.DeuteranomalyFilter) + : base(KnownFilterMatrices.DeuteranomalyFilter) { } } diff --git a/src/ImageSharp/Processing/Filters/Processors/DeuteranopiaProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/DeuteranopiaProcessor.cs index 2cbfcf4674..4b57a1fa46 100644 --- a/src/ImageSharp/Processing/Filters/Processors/DeuteranopiaProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/DeuteranopiaProcessor.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// Initializes a new instance of the class. /// public DeuteranopiaProcessor() - : base(KnownMatrixFilters.DeuteranopiaFilter) + : base(KnownFilterMatrices.DeuteranopiaFilter) { } } diff --git a/src/ImageSharp/Processing/Filters/Processors/GrayscaleBt601Processor.cs b/src/ImageSharp/Processing/Filters/Processors/GrayscaleBt601Processor.cs index 2fe4bf31b6..b4ea8ac6bd 100644 --- a/src/ImageSharp/Processing/Filters/Processors/GrayscaleBt601Processor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/GrayscaleBt601Processor.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// /// The proportion of the conversion. Must be between 0 and 1. public GrayscaleBt601Processor(float amount) - : base(KnownMatrixFilters.CreateGrayscaleBt601Filter(amount)) + : base(KnownFilterMatrices.CreateGrayscaleBt601Filter(amount)) { this.Amount = amount; } diff --git a/src/ImageSharp/Processing/Filters/Processors/GrayscaleBt709Processor.cs b/src/ImageSharp/Processing/Filters/Processors/GrayscaleBt709Processor.cs index 5e26849984..480b134d3f 100644 --- a/src/ImageSharp/Processing/Filters/Processors/GrayscaleBt709Processor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/GrayscaleBt709Processor.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// /// The proportion of the conversion. Must be between 0 and 1. public GrayscaleBt709Processor(float amount) - : base(KnownMatrixFilters.CreateGrayscaleBt709Filter(amount)) + : base(KnownFilterMatrices.CreateGrayscaleBt709Filter(amount)) { this.Amount = amount; } diff --git a/src/ImageSharp/Processing/Filters/Processors/HueProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/HueProcessor.cs index 8bd7d3278a..95ae98e784 100644 --- a/src/ImageSharp/Processing/Filters/Processors/HueProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/HueProcessor.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// /// The angle of rotation in degrees public HueProcessor(float degrees) - : base(KnownMatrixFilters.CreateHueFilter(degrees)) + : base(KnownFilterMatrices.CreateHueFilter(degrees)) { this.Degrees = degrees; } diff --git a/src/ImageSharp/Processing/Filters/Processors/InvertProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/InvertProcessor.cs index fc408912d0..7b8ed2a036 100644 --- a/src/ImageSharp/Processing/Filters/Processors/InvertProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/InvertProcessor.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// /// The proportion of the conversion. Must be between 0 and 1. public InvertProcessor(float amount) - : base(KnownMatrixFilters.CreateInvertFilter(amount)) + : base(KnownFilterMatrices.CreateInvertFilter(amount)) { this.Amount = amount; } diff --git a/src/ImageSharp/Processing/Filters/Processors/KodachromeProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/KodachromeProcessor.cs index ea9b86d1b7..cc3fa42f66 100644 --- a/src/ImageSharp/Processing/Filters/Processors/KodachromeProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/KodachromeProcessor.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// Initializes a new instance of the class. /// public KodachromeProcessor() - : base(KnownMatrixFilters.KodachromeFilter) + : base(KnownFilterMatrices.KodachromeFilter) { } } diff --git a/src/ImageSharp/Processing/Filters/Processors/LomographProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/LomographProcessor.cs index 7196bc2dde..d97bf57dda 100644 --- a/src/ImageSharp/Processing/Filters/Processors/LomographProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/LomographProcessor.cs @@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// Initializes a new instance of the class. /// public LomographProcessor() - : base(KnownMatrixFilters.LomographFilter) + : base(KnownFilterMatrices.LomographFilter) { } diff --git a/src/ImageSharp/Processing/Filters/Processors/OpacityProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/OpacityProcessor.cs index 9e2e549b2c..f50d27ae09 100644 --- a/src/ImageSharp/Processing/Filters/Processors/OpacityProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/OpacityProcessor.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// /// The proportion of the conversion. Must be between 0 and 1. public OpacityProcessor(float amount) - : base(KnownMatrixFilters.CreateOpacityFilter(amount)) + : base(KnownFilterMatrices.CreateOpacityFilter(amount)) { this.Amount = amount; } diff --git a/src/ImageSharp/Processing/Filters/Processors/PolaroidProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/PolaroidProcessor.cs index b9c555c9f6..b6aa562231 100644 --- a/src/ImageSharp/Processing/Filters/Processors/PolaroidProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/PolaroidProcessor.cs @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// Initializes a new instance of the class. /// public PolaroidProcessor() - : base(KnownMatrixFilters.PolaroidFilter) + : base(KnownFilterMatrices.PolaroidFilter) { } diff --git a/src/ImageSharp/Processing/Filters/Processors/ProtanomalyProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/ProtanomalyProcessor.cs index 24cdd75c25..88e2ee3c3f 100644 --- a/src/ImageSharp/Processing/Filters/Processors/ProtanomalyProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/ProtanomalyProcessor.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// Initializes a new instance of the class. /// public ProtanomalyProcessor() - : base(KnownMatrixFilters.ProtanomalyFilter) + : base(KnownFilterMatrices.ProtanomalyFilter) { } } diff --git a/src/ImageSharp/Processing/Filters/Processors/ProtanopiaProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/ProtanopiaProcessor.cs index 441d083107..17020bbe24 100644 --- a/src/ImageSharp/Processing/Filters/Processors/ProtanopiaProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/ProtanopiaProcessor.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// Initializes a new instance of the class. /// public ProtanopiaProcessor() - : base(KnownMatrixFilters.ProtanopiaFilter) + : base(KnownFilterMatrices.ProtanopiaFilter) { } } diff --git a/src/ImageSharp/Processing/Filters/Processors/SaturateProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/SaturateProcessor.cs index 645052eab5..d4b28a8945 100644 --- a/src/ImageSharp/Processing/Filters/Processors/SaturateProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/SaturateProcessor.cs @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// /// The proportion of the conversion. Must be greater than or equal to 0. public SaturateProcessor(float amount) - : base(KnownMatrixFilters.CreateSaturateFilter(amount)) + : base(KnownFilterMatrices.CreateSaturateFilter(amount)) { this.Amount = amount; } diff --git a/src/ImageSharp/Processing/Filters/Processors/SepiaProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/SepiaProcessor.cs index 641540f61a..7295cee99b 100644 --- a/src/ImageSharp/Processing/Filters/Processors/SepiaProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/SepiaProcessor.cs @@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// /// The proportion of the conversion. Must be between 0 and 1. public SepiaProcessor(float amount) - : base(KnownMatrixFilters.CreateSepiaFilter(amount)) + : base(KnownFilterMatrices.CreateSepiaFilter(amount)) { this.Amount = amount; } diff --git a/src/ImageSharp/Processing/Filters/Processors/TritanomalyProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/TritanomalyProcessor.cs index 2da3fd5fbd..6991506e6e 100644 --- a/src/ImageSharp/Processing/Filters/Processors/TritanomalyProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/TritanomalyProcessor.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// Initializes a new instance of the class. /// public TritanomalyProcessor() - : base(KnownMatrixFilters.TritanomalyFilter) + : base(KnownFilterMatrices.TritanomalyFilter) { } } diff --git a/src/ImageSharp/Processing/Filters/Processors/TritanopiaProcessor.cs b/src/ImageSharp/Processing/Filters/Processors/TritanopiaProcessor.cs index a496f6f62c..95c6cb5427 100644 --- a/src/ImageSharp/Processing/Filters/Processors/TritanopiaProcessor.cs +++ b/src/ImageSharp/Processing/Filters/Processors/TritanopiaProcessor.cs @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Filters.Processors /// Initializes a new instance of the class. /// public TritanopiaProcessor() - : base(KnownMatrixFilters.TritanopiaFilter) + : base(KnownFilterMatrices.TritanopiaFilter) { } } diff --git a/tests/ImageSharp.Tests/Processing/Binarization/BinaryDitherTest.cs b/tests/ImageSharp.Tests/Processing/Binarization/BinaryDitherTest.cs index d88491638d..324225a064 100644 --- a/tests/ImageSharp.Tests/Processing/Binarization/BinaryDitherTest.cs +++ b/tests/ImageSharp.Tests/Processing/Binarization/BinaryDitherTest.cs @@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization public BinaryDitherTest() { - this.orderedDither = KnownDitherMatrices.BayerDither4x4; + this.orderedDither = KnownDitherers.BayerDither4x4; this.errorDiffuser = KnownDiffusers.FloydSteinberg; } diff --git a/tests/ImageSharp.Tests/Processing/Dithering/DitherTest.cs b/tests/ImageSharp.Tests/Processing/Dithering/DitherTest.cs index 1526644bbe..a29fc28c96 100644 --- a/tests/ImageSharp.Tests/Processing/Dithering/DitherTest.cs +++ b/tests/ImageSharp.Tests/Processing/Dithering/DitherTest.cs @@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Binarization public DitherTest() { - this.orderedDither = KnownDitherMatrices.BayerDither4x4; + this.orderedDither = KnownDitherers.BayerDither4x4; this.errorDiffuser = KnownDiffusers.FloydSteinberg; } diff --git a/tests/ImageSharp.Tests/Processing/Filters/FilterTest.cs b/tests/ImageSharp.Tests/Processing/Filters/FilterTest.cs index eb6d7c38c5..cac1d7057c 100644 --- a/tests/ImageSharp.Tests/Processing/Filters/FilterTest.cs +++ b/tests/ImageSharp.Tests/Processing/Filters/FilterTest.cs @@ -16,14 +16,14 @@ namespace SixLabors.ImageSharp.Tests.Processing.Filters [Fact] public void Filter_CorrectProcessor() { - this.operations.Filter(KnownMatrixFilters.AchromatomalyFilter * KnownMatrixFilters.CreateHueFilter(90F)); + this.operations.Filter(KnownFilterMatrices.AchromatomalyFilter * KnownFilterMatrices.CreateHueFilter(90F)); FilterProcessor p = this.Verify>(); } [Fact] public void Filter_rect_CorrectProcessor() { - this.operations.Filter(KnownMatrixFilters.AchromatomalyFilter * KnownMatrixFilters.CreateHueFilter(90F), this.rect); + this.operations.Filter(KnownFilterMatrices.AchromatomalyFilter * KnownFilterMatrices.CreateHueFilter(90F), this.rect); FilterProcessor p = this.Verify>(this.rect); } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryDitherTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryDitherTests.cs index b75087bc4a..f99fe0c2a8 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryDitherTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryDitherTests.cs @@ -25,10 +25,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization public static readonly TheoryData OrderedDitherers = new TheoryData { - { "Bayer8x8", KnownDitherMatrices.BayerDither8x8 }, - { "Bayer4x4", KnownDitherMatrices.BayerDither4x4 }, - { "Ordered3x3", KnownDitherMatrices.OrderedDither3x3 }, - { "Bayer2x2", KnownDitherMatrices.BayerDither2x2 } + { "Bayer8x8", KnownDitherers.BayerDither8x8 }, + { "Bayer4x4", KnownDitherers.BayerDither4x4 }, + { "Ordered3x3", KnownDitherers.OrderedDither3x3 }, + { "Bayer2x2", KnownDitherers.BayerDither2x2 } }; public static readonly TheoryData ErrorDiffusers = new TheoryData @@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization }; - private static IOrderedDither DefaultDitherer => KnownDitherMatrices.BayerDither4x4; + private static IOrderedDither DefaultDitherer => KnownDitherers.BayerDither4x4; private static IErrorDiffuser DefaultErrorDiffuser => KnownDiffusers.Atkinson; diff --git a/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs index 64e62fb2a4..de2eff2eed 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs @@ -24,10 +24,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization public static readonly TheoryData OrderedDitherers = new TheoryData { - { "Bayer8x8", KnownDitherMatrices.BayerDither8x8 }, - { "Bayer4x4", KnownDitherMatrices.BayerDither4x4 }, - { "Ordered3x3", KnownDitherMatrices.OrderedDither3x3 }, - { "Bayer2x2", KnownDitherMatrices.BayerDither2x2 } + { "Bayer8x8", KnownDitherers.BayerDither8x8 }, + { "Bayer4x4", KnownDitherers.BayerDither4x4 }, + { "Ordered3x3", KnownDitherers.OrderedDither3x3 }, + { "Bayer2x2", KnownDitherers.BayerDither2x2 } }; public static readonly TheoryData ErrorDiffusers = new TheoryData @@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization }; - private static IOrderedDither DefaultDitherer => KnownDitherMatrices.BayerDither4x4; + private static IOrderedDither DefaultDitherer => KnownDitherers.BayerDither4x4; private static IErrorDiffuser DefaultErrorDiffuser => KnownDiffusers.Atkinson; diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/FilterTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/FilterTest.cs index 226ebd6732..190e117b3a 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/FilterTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/FilterTest.cs @@ -40,9 +40,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters private static Matrix4x4 CreateCombinedTestFilterMatrix() { - Matrix4x4 brightness = KnownMatrixFilters.CreateBrightnessFilter(0.9F); - Matrix4x4 hue = KnownMatrixFilters.CreateHueFilter(180F); - Matrix4x4 saturation = KnownMatrixFilters.CreateSaturateFilter(1.5F); + Matrix4x4 brightness = KnownFilterMatrices.CreateBrightnessFilter(0.9F); + Matrix4x4 hue = KnownFilterMatrices.CreateHueFilter(180F); + Matrix4x4 saturation = KnownFilterMatrices.CreateSaturateFilter(1.5F); Matrix4x4 m = brightness * hue * saturation; return m; }