diff --git a/.travis.yml b/.travis.yml index 5a146cea6e..2515ca82a9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ matrix: - os: linux # Ubuntu 14.04 dist: trusty sudo: required - dotnet: 2.1.300 + dotnet: 2.1.401 mono: latest # - os: osx # OSX 10.11 # osx_image: xcode7.3.1 diff --git a/ImageSharp.sln b/ImageSharp.sln index 3ff5b09d41..0291d9f93a 100644 --- a/ImageSharp.sln +++ b/ImageSharp.sln @@ -1,7 +1,6 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26730.3 VisualStudioVersion = 15.0.26730.12 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionItems", "{C317F1B1-D75E-4C6D-83EB-80367343E0D7}" @@ -19,6 +18,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt NuGet.config = NuGet.config .github\PULL_REQUEST_TEMPLATE.md = .github\PULL_REQUEST_TEMPLATE.md README.md = README.md + run-tests.ps1 = run-tests.ps1 EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{815C0625-CD3D-440F-9F80-2D83856AB7AE}" @@ -46,9 +46,6 @@ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp.Sandbox46", "tests\ImageSharp.Sandbox46\ImageSharp.Sandbox46.csproj", "{561B880A-D9EE-44EF-90F5-817C54A9D9AB}" EndProject Global - GlobalSection(Performance) = preSolution - HasPerformanceSessions = true - EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 @@ -133,4 +130,7 @@ Global GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {5F8B9D1F-CD8B-4CC5-8216-D531E25BD795} EndGlobalSection + GlobalSection(Performance) = preSolution + HasPerformanceSessions = true + EndGlobalSection EndGlobal diff --git a/README.md b/README.md index b54a9b2075..a420c07c8e 100644 --- a/README.md +++ b/README.md @@ -117,12 +117,9 @@ For more examples check out: If you prefer, you can compile ImageSharp yourself (please do and help!) -- Using [Visual Studio 2017 Preview](https://docs.microsoft.com/en-us/visualstudio/releasenotes/vs2017-preview-relnotes) +- Using [Visual Studio 2017](https://visualstudio.microsoft.com/vs/) - Make sure you have the latest version installed - - Make sure you have [the newest 2.1 RC1 SDK installed](https://www.microsoft.com/net/core#windows) - -- Using [Visual Studio 2017](https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes) - - If you are unable and/or don't want to build ImageSharp.Tests against 2.1 RC, remove the `netcoreapp2.1` target [from TargetFrameworks](https://github.com/SixLabors/ImageSharp/blob/master/tests/ImageSharp.Tests/ImageSharp.Tests.csproj#L3) locally + - Make sure you have [the .NET Core 2.1 SDK](https://www.microsoft.com/net/core#windows) installed Alternatively, you can work from command line and/or with a lightweight editor on **both Linux/Unix and Windows**: diff --git a/appveyor.yml b/appveyor.yml index 5d84e6cea3..fccac0c44d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -12,9 +12,6 @@ environment: - target_framework: netcoreapp2.1 is_32bit: True - - target_framework: netcoreapp2.0 - is_32bit: False - - target_framework: net471 is_32bit: False @@ -27,8 +24,6 @@ environment: - target_framework: net462 is_32bit: True - #- target_framework: netcoreapp2.0 # As far as I understand, 32 bit test execution is not supported by "dotnet xunit" - # is_32bit: True #- target_framework: mono # is_32bit: False #- target_framework: mono diff --git a/run-tests.ps1 b/run-tests.ps1 index 3218d9d679..4aeaa14908 100644 --- a/run-tests.ps1 +++ b/run-tests.ps1 @@ -41,8 +41,8 @@ function CheckSubmoduleStatus() { } -if ( ($targetFramework -eq "netcoreapp2.0") -and ($env:CI -eq "True") -and ($is32Bit -ne "True")) { - # We execute CodeCoverage.cmd only for one specific job on CI (netcoreapp2.0 + 64bit ) +if ( ($targetFramework -eq "netcoreapp2.1") -and ($env:CI -eq "True") -and ($is32Bit -ne "True")) { + # We execute CodeCoverage.cmd only for one specific job on CI (netcoreapp2.1 + 64bit ) $testRunnerCmd = ".\tests\CodeCoverage\CodeCoverage.cmd" } elseif ($targetFramework -eq "mono") { @@ -70,11 +70,6 @@ else { cd .\tests\ImageSharp.Tests $xunitArgs = "-nobuild -c Release -framework $targetFramework" - if ($targetFramework -eq "netcoreapp2.0") { - # There were issues matching the correct installed runtime if we do not specify it explicitly: - $xunitArgs += " --fx-version 2.0.0" - } - if ($targetFramework -eq "netcoreapp2.1") { # There were issues matching the correct installed runtime if we do not specify it explicitly: $xunitArgs += " --fx-version 2.1.0" diff --git a/src/ImageSharp.Drawing/Processing/BrushApplicator.cs b/src/ImageSharp.Drawing/Processing/BrushApplicator.cs index 41b47a822e..770d440656 100644 --- a/src/ImageSharp.Drawing/Processing/BrushApplicator.cs +++ b/src/ImageSharp.Drawing/Processing/BrushApplicator.cs @@ -28,7 +28,7 @@ namespace SixLabors.ImageSharp.Processing { this.Target = target; this.Options = options; - this.Blender = PixelOperations.Instance.GetPixelBlender(options.BlenderMode); + this.Blender = PixelOperations.Instance.GetPixelBlender(options); } /// diff --git a/src/ImageSharp.Drawing/Processing/DrawImageExtensions.cs b/src/ImageSharp.Drawing/Processing/DrawImageExtensions.cs index 7c9d7c280a..8ccbe22acb 100644 --- a/src/ImageSharp.Drawing/Processing/DrawImageExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/DrawImageExtensions.cs @@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.Processing /// The . public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, float opacity) where TPixel : struct, IPixel - => source.ApplyProcessor(new DrawImageProcessor(image, opacity)); + => source.ApplyProcessor(new DrawImageProcessor(image, Point.Empty, GraphicsOptions.Default.ColorBlendingMode, GraphicsOptions.Default.AlphaCompositionMode, opacity)); /// /// Draws the given image together with the current one by blending their pixels. @@ -30,63 +30,92 @@ namespace SixLabors.ImageSharp.Processing /// The pixel format. /// The image this method extends. /// The image to blend with the currently processing image. - /// The blending mode. + /// The blending mode. /// The opacity of the image to blend. Must be between 0 and 1. /// The . - public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, PixelBlenderMode blender, float opacity) + public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, PixelColorBlendingMode colorBlending, float opacity) where TPixel : struct, IPixel - => source.ApplyProcessor(new DrawImageProcessor(image, opacity, blender)); - + => source.ApplyProcessor(new DrawImageProcessor(image, Point.Empty, colorBlending, GraphicsOptions.Default.AlphaCompositionMode, opacity)); + /// /// Draws the given image together with the current one by blending their pixels. /// /// The pixel format. /// The image this method extends. - /// The options, including the blending type and blending amount. /// The image to blend with the currently processing image. + /// The color blending mode. + /// The alpha composition mode. + /// The opacity of the image to blend. Must be between 0 and 1. /// The . - public static IImageProcessingContext DrawImage(this IImageProcessingContext source, GraphicsOptions options, Image image) + public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, PixelColorBlendingMode colorBlending, PixelAlphaCompositionMode alphaComposition, float opacity) where TPixel : struct, IPixel - => source.ApplyProcessor(new DrawImageProcessor(image, options)); - + => source.ApplyProcessor(new DrawImageProcessor(image, Point.Empty, colorBlending, alphaComposition, opacity)); + /// /// Draws the given image together with the current one by blending their pixels. /// - /// The image this method extends. + /// The pixel format. + /// The image this method extends. /// The image to blend with the currently processing image. + /// The options, including the blending type and blending amount. + /// The . + public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, GraphicsOptions options) + where TPixel : struct, IPixel + => source.ApplyProcessor(new DrawImageProcessor(image, Point.Empty, options.ColorBlendingMode, options.AlphaCompositionMode, options.BlendPercentage)); + + /// + /// Draws the given image together with the current one by blending their pixels. + /// /// The pixel format. - /// The opacity of the image to blend. Must be between 0 and 1. + /// The image this method extends. + /// The image to blend with the currently processing image. /// The location to draw the blended image. + /// The opacity of the image to blend. Must be between 0 and 1. /// The . - public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, float opacity, Point location) + public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, Point location, float opacity) where TPixel : struct, IPixel - => source.ApplyProcessor(new DrawImageProcessor(image, location, opacity)); - + => source.ApplyProcessor(new DrawImageProcessor(image, location, GraphicsOptions.Default.ColorBlendingMode, GraphicsOptions.Default.AlphaCompositionMode, opacity)); + /// /// Draws the given image together with the current one by blending their pixels. - /// - /// The image this method extends. - /// The image to blend with the currently processing image. + /// /// The pixel format. - /// The type of bending to apply. - /// The opacity of the image to blend. Must be between 0 and 1. + /// The image this method extends. + /// The image to blend with the currently processing image. /// The location to draw the blended image. + /// The color blending to apply. + /// The opacity of the image to blend. Must be between 0 and 1. /// The . - public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, PixelBlenderMode blender, float opacity, Point location) + public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, Point location, PixelColorBlendingMode colorBlending, float opacity) where TPixel : struct, IPixel - => source.ApplyProcessor(new DrawImageProcessor(image, location, opacity, blender)); - + => source.ApplyProcessor(new DrawImageProcessor(image, location, colorBlending, GraphicsOptions.Default.AlphaCompositionMode, opacity)); + /// /// Draws the given image together with the current one by blending their pixels. - /// - /// The image this method extends. - /// The options containing the blend mode and opacity. - /// The image to blend with the currently processing image. + /// /// The pixel format. + /// The image this method extends. + /// The image to blend with the currently processing image. /// The location to draw the blended image. + /// The color blending to apply. + /// The alpha composition mode. + /// The opacity of the image to blend. Must be between 0 and 1. + /// The . + public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, Point location, PixelColorBlendingMode colorBlending, PixelAlphaCompositionMode alphaComposition, float opacity) + where TPixel : struct, IPixel + => source.ApplyProcessor(new DrawImageProcessor(image, location, colorBlending, alphaComposition, opacity)); + + /// + /// Draws the given image together with the current one by blending their pixels. + /// + /// The pixel format. + /// The image this method extends. + /// The image to blend with the currently processing image. + /// The location to draw the blended image. + /// The options containing the blend mode and opacity. /// The . - public static IImageProcessingContext DrawImage(this IImageProcessingContext source, GraphicsOptions options, Image image, Point location) + public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, Point location, GraphicsOptions options) where TPixel : struct, IPixel - => source.ApplyProcessor(new DrawImageProcessor(image, location, options)); + => source.ApplyProcessor(new DrawImageProcessor(image, location, options.ColorBlendingMode, options.AlphaCompositionMode, options.BlendPercentage)); } } \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs index faf3fe7115..324d25e097 100644 --- a/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs @@ -18,80 +18,22 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing /// The pixel format. internal class DrawImageProcessor : ImageProcessor where TPixel : struct, IPixel - { + { /// /// Initializes a new instance of the class. /// /// The image to blend with the currently processing image. + /// The location to draw the blended image. + /// The blending mode to use when drawing the image. + /// The Alpha blending mode to use when drawing the image. /// The opacity of the image to blend. Must be between 0 and 1. - public DrawImageProcessor(Image image, float opacity) - : this(image, Point.Empty, opacity) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The image to blend with the currently processing image. - /// - /// The options containing the opacity of the image to blend and blending mode. - /// Opacity must be between 0 and 1. - /// - public DrawImageProcessor(Image image, GraphicsOptions options) - : this(image, Point.Empty, options) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The image to blend with the currently processing image. - /// The location to draw the blended image. - /// The opacity of the image to blend. Must be between 0 and 1. - public DrawImageProcessor(Image image, Point location, float opacity) - : this(image, location, opacity, GraphicsOptions.Default.BlenderMode) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The image to blend with the currently processing image. - /// The location to draw the blended image. - /// - /// The options containing the opacity of the image to blend and blending mode. - /// Opacity must be between 0 and 1. - /// - public DrawImageProcessor(Image image, Point location, GraphicsOptions options) - : this(image, location, options.BlendPercentage, options.BlenderMode) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The image to blend with the currently processing image. - /// The opacity of the image to blend. Must be between 0 and 1. - /// The blending mode to use when drawing the image. - public DrawImageProcessor(Image image, float opacity, PixelBlenderMode blenderMode) - : this(image, Point.Empty, opacity, blenderMode) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The image to blend with the currently processing image. - /// The location to draw the blended image. - /// The opacity of the image to blend. Must be between 0 and 1. - /// The blending mode to use when drawing the image. - public DrawImageProcessor(Image image, Point location, float opacity, PixelBlenderMode blenderMode) + public DrawImageProcessor(Image image, Point location, PixelColorBlendingMode colorBlendingMode, PixelAlphaCompositionMode alphaCompositionMode, float opacity) { Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity)); this.Image = image; this.Opacity = opacity; - this.Blender = PixelOperations.Instance.GetPixelBlender(blenderMode); + this.Blender = PixelOperations.Instance.GetPixelBlender(colorBlendingMode, alphaCompositionMode); this.Location = location; } diff --git a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs index c9d6777ce6..3285e75a7b 100644 --- a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs @@ -102,14 +102,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing private bool IsSolidBrushWithoutBlending(out SolidBrush solidBrush) { - solidBrush = this.brush as SolidBrush; - - return solidBrush != null - && ((this.options.BlenderMode == PixelBlenderMode.Normal && this.options.BlendPercentage == 1f - && solidBrush.Color.ToVector4().W == 1f) - || (this.options.BlenderMode == PixelBlenderMode.Over && this.options.BlendPercentage == 1f - && solidBrush.Color.ToVector4().W == 1f) - || (this.options.BlenderMode == PixelBlenderMode.Src)); + solidBrush = this.brush as SolidBrush; + + if (solidBrush == null) + { + return false; + } + + return this.options.IsOpaqueColorWithoutBlending(solidBrush.Color); } } } \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs b/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs index 6da635c981..1095de325f 100644 --- a/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs @@ -37,9 +37,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Text { Guard.NotNull(text, nameof(text)); Guard.NotNull(font, nameof(font)); - if (brush == null && pen == null) + + if (brush is null && pen is null) { - throw new ArgumentNullException($"at least one of {nameof(brush)} or {nameof(pen)} must not be null"); + throw new ArgumentNullException($"Expected a {nameof(brush)} or {nameof(pen)}. Both were null"); } this.Options = options; diff --git a/src/ImageSharp.Drawing/Processing/TextGraphicsOptions.cs b/src/ImageSharp.Drawing/Processing/TextGraphicsOptions.cs index dfad06768e..3c682a761b 100644 --- a/src/ImageSharp.Drawing/Processing/TextGraphicsOptions.cs +++ b/src/ImageSharp.Drawing/Processing/TextGraphicsOptions.cs @@ -32,7 +32,9 @@ namespace SixLabors.ImageSharp.Processing private float? dpiY; - private PixelBlenderMode blenderMode; + private PixelColorBlendingMode colorBlendingMode; + + private PixelAlphaCompositionMode alphaCompositionMode; private float wrapTextWidth; @@ -53,7 +55,8 @@ namespace SixLabors.ImageSharp.Processing this.verticalAlignment = VerticalAlignment.Top; this.antialiasSubpixelDepth = 16; - this.blenderMode = PixelBlenderMode.Normal; + this.colorBlendingMode = PixelColorBlendingMode.Normal; + this.alphaCompositionMode = PixelAlphaCompositionMode.SrcOver; this.blendPercentage = 1; this.antialias = enableAntialiasing; this.dpiX = DefaultTextDpi; @@ -80,9 +83,14 @@ namespace SixLabors.ImageSharp.Processing // some API thought post V1. /// - /// Gets or sets a value indicating the blending percentage to apply to the drawing operation + /// Gets or sets a value indicating the color blending percentage to apply to the drawing operation + /// + public PixelColorBlendingMode ColorBlendingMode { get => this.colorBlendingMode; set => this.colorBlendingMode = value; } + + /// + /// Gets or sets a value indicating the color blending percentage to apply to the drawing operation /// - public PixelBlenderMode BlenderMode { get => this.blenderMode; set => this.blenderMode = value; } + public PixelAlphaCompositionMode AlphaCompositionMode { get => this.alphaCompositionMode; set => this.alphaCompositionMode = value; } /// /// Gets or sets a value indicating whether the text should be drawing with kerning enabled. @@ -135,7 +143,8 @@ namespace SixLabors.ImageSharp.Processing { AntialiasSubpixelDepth = options.AntialiasSubpixelDepth, blendPercentage = options.BlendPercentage, - blenderMode = options.BlenderMode + colorBlendingMode = options.ColorBlendingMode, + alphaCompositionMode = options.AlphaCompositionMode }; } @@ -151,7 +160,8 @@ namespace SixLabors.ImageSharp.Processing return new GraphicsOptions(options.Antialias) { AntialiasSubpixelDepth = options.AntialiasSubpixelDepth, - BlenderMode = options.BlenderMode, + ColorBlendingMode = options.ColorBlendingMode, + AlphaCompositionMode = options.AlphaCompositionMode, BlendPercentage = options.BlendPercentage }; } diff --git a/src/ImageSharp/Common/Helpers/DebugGuard.cs b/src/ImageSharp/Common/Helpers/DebugGuard.cs index 5a1d3a2e35..2cf18b2456 100644 --- a/src/ImageSharp/Common/Helpers/DebugGuard.cs +++ b/src/ImageSharp/Common/Helpers/DebugGuard.cs @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp public static void NotNull(T value, string parameterName) where T : class { - if (value == null) + if (value is null) { throw new ArgumentNullException(parameterName); } diff --git a/src/ImageSharp/Common/Helpers/Guard.cs b/src/ImageSharp/Common/Helpers/Guard.cs index 41e7c5d940..038d5c35c8 100644 --- a/src/ImageSharp/Common/Helpers/Guard.cs +++ b/src/ImageSharp/Common/Helpers/Guard.cs @@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp public static void NotNull(T value, string parameterName) where T : class { - if (value == null) + if (value is null) { throw new ArgumentNullException(parameterName); } @@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp /// is empty or contains only blanks. public static void NotNullOrWhiteSpace(string value, string parameterName) { - if (value == null) + if (value is null) { throw new ArgumentNullException(parameterName); } @@ -58,7 +58,7 @@ namespace SixLabors.ImageSharp /// is empty. public static void NotNullOrEmpty(ICollection value, string parameterName) { - if (value == null) + if (value is null) { throw new ArgumentNullException(parameterName); } diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs index d3cb50d6ba..3d079cf619 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoder.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoder.cs @@ -25,7 +25,6 @@ namespace SixLabors.ImageSharp.Formats.Bmp { /// public Image Decode(Configuration configuration, Stream stream) - where TPixel : struct, IPixel { Guard.NotNull(stream, nameof(stream)); diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs index 3832a30c68..2a4d981ebb 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs @@ -377,7 +377,7 @@ namespace SixLabors.ImageSharp.Formats.Gif ImageFrame currentFrame = null; ImageFrame imageFrame; - if (previousFrame == null) + if (previousFrame is null) { // This initializes the image to become fully transparent because the alpha channel is zero. image = new Image(this.configuration, imageWidth, imageHeight, this.metaData); @@ -485,7 +485,7 @@ namespace SixLabors.ImageSharp.Formats.Gif private void RestoreToBackground(ImageFrame frame) where TPixel : struct, IPixel { - if (this.restoreArea == null) + if (this.restoreArea is null) { return; } diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index 1fb706ae18..5532900355 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs @@ -159,7 +159,7 @@ namespace SixLabors.ImageSharp.Formats.Gif { foreach (ImageFrame frame in image.Frames) { - if (quantized == null) + if (quantized is null) { quantized = this.quantizer.CreateFrameQuantizer().QuantizeFrame(frame); } diff --git a/src/ImageSharp/Formats/Gif/LzwDecoder.cs b/src/ImageSharp/Formats/Gif/LzwDecoder.cs index 3c7b6a4af6..07594e81a1 100644 --- a/src/ImageSharp/Formats/Gif/LzwDecoder.cs +++ b/src/ImageSharp/Formats/Gif/LzwDecoder.cs @@ -56,9 +56,7 @@ namespace SixLabors.ImageSharp.Formats.Gif /// is null. public LzwDecoder(MemoryAllocator memoryAllocator, Stream stream) { - Guard.NotNull(stream, nameof(stream)); - - this.stream = stream; + this.stream = stream ?? throw new ArgumentNullException(nameof(stream)); this.prefix = memoryAllocator.Allocate(MaxStackSize, AllocationOptions.Clean); this.suffix = memoryAllocator.Allocate(MaxStackSize, AllocationOptions.Clean); diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs index 40b8d391a3..8aeb01d7f0 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs @@ -44,7 +44,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters public static JpegColorConverter GetConverter(JpegColorSpace colorSpace) { JpegColorConverter converter = Converters.FirstOrDefault(c => c.ColorSpace == colorSpace); - if (converter == null) + + if (converter is null) { throw new Exception($"Could not find any converter for JpegColorSpace {colorSpace}!"); } diff --git a/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs b/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs index c150242593..2e20da266b 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs @@ -58,13 +58,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components public void LoadAndStretchEdges(IPixelSource source, int sourceX, int sourceY) where TPixel : struct, IPixel { - var buffer = source.PixelBuffer as Buffer2D; - if (buffer == null) + if (source.PixelBuffer is Buffer2D buffer) + { + this.LoadAndStretchEdges(buffer, sourceX, sourceY); + } + else { throw new InvalidOperationException("LoadAndStretchEdges() is only valid for TPixel == T !"); } - - this.LoadAndStretchEdges(buffer, sourceX, sourceY); } /// diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs index 1eb4dad898..7561afa1ef 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs @@ -538,7 +538,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg if (ProfileResolver.IsProfile(profile, ProfileResolver.ExifMarker)) { this.isExif = true; - if (this.exifData == null) + if (this.exifData is null) { // The first 6 bytes (Exif00) will be skipped, because this is Jpeg specific this.exifData = profile.Skip(Exif00).ToArray(); @@ -575,7 +575,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg byte[] profile = new byte[remaining]; this.InputStream.Read(profile, 0, remaining); - if (this.iccData == null) + if (this.iccData is null) { this.iccData = profile; } diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs index 1a3bb77234..f7b6fe9967 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs @@ -550,7 +550,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg private void WriteDefineHuffmanTables(int componentCount) { // Table identifiers. - byte[] headers = { 0x00, 0x10, 0x01, 0x11 }; + Span headers = stackalloc byte[] { 0x00, 0x10, 0x01, 0x11 }; + int markerlen = 2; HuffmanSpec[] specs = HuffmanSpec.TheHuffmanSpecs; @@ -628,7 +629,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg byte[] data = exifProfile?.ToByteArray(); - if (data == null || data.Length == 0) + if (data is null || data.Length == 0) { return; } @@ -687,7 +688,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg /// private void WriteIccProfile(IccProfile iccProfile) { - if (iccProfile == null) + if (iccProfile is null) { return; } @@ -698,7 +699,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg byte[] data = iccProfile.ToByteArray(); - if (data == null || data.Length == 0) + if (data is null || data.Length == 0) { return; } diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index e1ec3c1d66..aa96b926ca 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -239,7 +239,7 @@ namespace SixLabors.ImageSharp.Formats.Png this.ReadPhysicalChunk(metadata, chunk.Data.GetSpan()); break; case PngChunkType.Data: - if (image == null) + if (image is null) { this.InitializeImage(metadata, out image); } @@ -283,7 +283,7 @@ namespace SixLabors.ImageSharp.Formats.Png } } - if (image == null) + if (image is null) { throw new ImageFormatException("PNG Image does not contain a data chunk"); } diff --git a/src/ImageSharp/Formats/Png/Zlib/ZlibInflateStream.cs b/src/ImageSharp/Formats/Png/Zlib/ZlibInflateStream.cs index fd9c4ac63e..55432d60b1 100644 --- a/src/ImageSharp/Formats/Png/Zlib/ZlibInflateStream.cs +++ b/src/ImageSharp/Formats/Png/Zlib/ZlibInflateStream.cs @@ -88,7 +88,7 @@ namespace SixLabors.ImageSharp.Formats.Png.Zlib public void AllocateNewBytes(int bytes) { this.currentDataRemaining = bytes; - if (this.compressedStream == null) + if (this.compressedStream is null) { this.InitializeInflateStream(); } diff --git a/src/ImageSharp/GraphicsOptions.cs b/src/ImageSharp/GraphicsOptions.cs index a094abacbe..2d20c17732 100644 --- a/src/ImageSharp/GraphicsOptions.cs +++ b/src/ImageSharp/GraphicsOptions.cs @@ -21,7 +21,9 @@ namespace SixLabors.ImageSharp private bool? antialias; - private PixelBlenderMode blenderMode; + private PixelColorBlendingMode colorBlendingMode; + + private PixelAlphaCompositionMode alphaCompositionMode; /// /// Initializes a new instance of the struct. @@ -29,10 +31,62 @@ namespace SixLabors.ImageSharp /// If set to true [enable antialiasing]. public GraphicsOptions(bool enableAntialiasing) { - this.blenderMode = PixelBlenderMode.Normal; + this.colorBlendingMode = PixelColorBlendingMode.Normal; + this.alphaCompositionMode = PixelAlphaCompositionMode.SrcOver; this.blendPercentage = 1; this.antialiasSubpixelDepth = 16; this.antialias = enableAntialiasing; + } + + /// + /// Initializes a new instance of the struct. + /// + /// If set to true [enable antialiasing]. + /// blending percentage to apply to the drawing operation + public GraphicsOptions(bool enableAntialiasing, float opacity) + { + Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity)); + + this.colorBlendingMode = PixelColorBlendingMode.Normal; + this.alphaCompositionMode = PixelAlphaCompositionMode.SrcOver; + this.blendPercentage = opacity; + this.antialiasSubpixelDepth = 16; + this.antialias = enableAntialiasing; + } + + /// + /// Initializes a new instance of the struct. + /// + /// If set to true [enable antialiasing]. + /// blending percentage to apply to the drawing operation + /// color blending mode to apply to the drawing operation + public GraphicsOptions(bool enableAntialiasing, PixelColorBlendingMode blending, float opacity) + { + Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity)); + + this.colorBlendingMode = blending; + this.alphaCompositionMode = PixelAlphaCompositionMode.SrcOver; + this.blendPercentage = opacity; + this.antialiasSubpixelDepth = 16; + this.antialias = enableAntialiasing; + } + + /// + /// Initializes a new instance of the struct. + /// + /// If set to true [enable antialiasing]. + /// blending percentage to apply to the drawing operation + /// color blending mode to apply to the drawing operation + /// alpha composition mode to apply to the drawing operation + public GraphicsOptions(bool enableAntialiasing, PixelColorBlendingMode blending, PixelAlphaCompositionMode composition, float opacity) + { + Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity)); + + this.colorBlendingMode = blending; + this.alphaCompositionMode = composition; + this.blendPercentage = opacity; + this.antialiasSubpixelDepth = 16; + this.antialias = enableAntialiasing; } /// @@ -67,12 +121,59 @@ namespace SixLabors.ImageSharp // some API thought post V1. /// - /// Gets or sets a value indicating the blending mode to apply to the drawing operation + /// Gets or sets a value indicating the color blending mode to apply to the drawing operation + /// + public PixelColorBlendingMode ColorBlendingMode + { + get => this.colorBlendingMode; + set => this.colorBlendingMode = value; + } + + /// + /// Gets or sets a value indicating the alpha composition mode to apply to the drawing operation /// - public PixelBlenderMode BlenderMode + public PixelAlphaCompositionMode AlphaCompositionMode { - get => this.blenderMode; - set => this.blenderMode = value; + get => this.alphaCompositionMode; + set => this.alphaCompositionMode = value; + } + + /// + /// Evaluates if a given SOURCE color can completely replace a BACKDROP color given the current blending and composition settings. + /// + /// The pixel format + /// the color + /// true if the color can be considered opaque + /// + /// Blending and composition is an expensive operation, in some cases, like + /// filling with a solid color, the blending can be avoided by a plain color replacement. + /// This method can be useful for such processors to select the fast path. + /// + internal bool IsOpaqueColorWithoutBlending(TPixel color) + where TPixel : struct, IPixel + { + if (this.ColorBlendingMode != PixelColorBlendingMode.Normal) + { + return false; + } + + if (this.AlphaCompositionMode != PixelAlphaCompositionMode.SrcOver && + this.AlphaCompositionMode != PixelAlphaCompositionMode.Src) + { + return false; + } + + if (this.BlendPercentage != 1f) + { + return false; + } + + if (color.ToVector4().W != 1f) + { + return false; + } + + return true; } } } \ No newline at end of file diff --git a/src/ImageSharp/Image.Decode.cs b/src/ImageSharp/Image.Decode.cs index 3b014e7bd6..894551e08f 100644 --- a/src/ImageSharp/Image.Decode.cs +++ b/src/ImageSharp/Image.Decode.cs @@ -70,7 +70,7 @@ namespace SixLabors.ImageSharp where TPixel : struct, IPixel { IImageDecoder decoder = DiscoverDecoder(stream, config, out IImageFormat format); - if (decoder == null) + if (decoder is null) { return (null, null); } diff --git a/src/ImageSharp/ImageExtensions.cs b/src/ImageSharp/ImageExtensions.cs index 9a46400fd5..bf312cb6f5 100644 --- a/src/ImageSharp/ImageExtensions.cs +++ b/src/ImageSharp/ImageExtensions.cs @@ -32,7 +32,7 @@ namespace SixLabors.ImageSharp string ext = Path.GetExtension(filePath); IImageFormat format = source.GetConfiguration().ImageFormatsManager.FindFormatByFileExtension(ext); - if (format == null) + if (format is null) { var sb = new StringBuilder(); sb.AppendLine($"Can't find a format that is associated with the file extention '{ext}'. Registered formats with there extensions include:"); @@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp IImageEncoder encoder = source.GetConfiguration().ImageFormatsManager.FindEncoder(format); - if (encoder == null) + if (encoder is null) { var sb = new StringBuilder(); sb.AppendLine($"Can't find encoder for file extention '{ext}' using image format '{format.Name}'. Registered encoders include:"); @@ -94,7 +94,7 @@ namespace SixLabors.ImageSharp Guard.NotNull(format, nameof(format)); IImageEncoder encoder = source.GetConfiguration().ImageFormatsManager.FindEncoder(format); - if (encoder == null) + if (encoder is null) { var sb = new StringBuilder(); sb.AppendLine("Can't find encoder for provided mime type. Available encoded:"); diff --git a/src/ImageSharp/ImageFrameCollection.cs b/src/ImageSharp/ImageFrameCollection.cs index 929dd7e36e..59571ce92e 100644 --- a/src/ImageSharp/ImageFrameCollection.cs +++ b/src/ImageSharp/ImageFrameCollection.cs @@ -7,7 +7,6 @@ using System.Collections.Generic; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.Memory; namespace SixLabors.ImageSharp { @@ -23,9 +22,7 @@ namespace SixLabors.ImageSharp internal ImageFrameCollection(Image parent, int width, int height, TPixel backgroundColor) { - Guard.NotNull(parent, nameof(parent)); - - this.parent = parent; + this.parent = parent ?? throw new ArgumentNullException(nameof(parent)); // Frames are already cloned within the caller this.frames.Add(new ImageFrame(parent.GetConfiguration(), width, height, backgroundColor)); @@ -33,9 +30,7 @@ namespace SixLabors.ImageSharp internal ImageFrameCollection(Image parent, int width, int height, MemorySource memorySource) { - Guard.NotNull(parent, nameof(parent)); - - this.parent = parent; + this.parent = parent ?? throw new ArgumentNullException(nameof(parent)); // Frames are already cloned within the caller this.frames.Add(new ImageFrame(parent.GetConfiguration(), width, height, memorySource)); diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs index 6f5af8ffcd..1dd8857217 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs @@ -128,7 +128,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif return null; } - if (this.data == null || this.data.Length < (this.thumbnailOffset + this.thumbnailLength)) + if (this.data is null || this.data.Length < (this.thumbnailOffset + this.thumbnailLength)) { return null; } @@ -235,7 +235,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif /// The public byte[] ToByteArray() { - if (this.values == null) + if (this.values is null) { return this.data; } @@ -262,7 +262,8 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif private void SyncResolution(ExifTag tag, double resolution) { ExifValue value = this.GetValue(tag); - if (value == null) + + if (value is null) { return; } @@ -283,7 +284,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif return; } - if (this.data == null) + if (this.data is null) { this.values = new List(); return; diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs index db1d0c6228..72db6305dd 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs @@ -76,7 +76,8 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif { var values = new List(); - if (this.ReadString(2) == "II") + // II == 0x4949 + if (this.ReadUInt16() == 0x4949) { this.endianness = Endianness.LittleEndian; } @@ -202,7 +203,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif private object ConvertValue(ExifDataType dataType, ReadOnlySpan buffer, uint numberOfComponents) { - if (buffer == null || buffer.Length == 0) + if (buffer.Length == 0) { return null; } diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifTagDescriptionAttribute.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifTagDescriptionAttribute.cs index 4021227f57..286fdbe57f 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifTagDescriptionAttribute.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifTagDescriptionAttribute.cs @@ -12,8 +12,8 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif [AttributeUsage(AttributeTargets.Field, AllowMultiple = true)] internal sealed class ExifTagDescriptionAttribute : Attribute { - private object value; - private string description; + private readonly object value; + private readonly string description; /// /// Initializes a new instance of the class. @@ -37,7 +37,8 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif public static string GetDescription(ExifTag tag, object value) { FieldInfo field = tag.GetType().GetTypeInfo().GetDeclaredField(tag.ToString()); - if (field == null) + + if (field is null) { return null; } diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs index 87e3e44949..e6da9b7d1e 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs @@ -80,7 +80,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif { get { - if (this.Value == null) + if (this.Value is null) { return false; } @@ -101,7 +101,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif { get { - if (this.Value == null) + if (this.Value is null) { return 4; } @@ -213,7 +213,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif /// public override string ToString() { - if (this.Value == null) + if (this.Value is null) { return null; } @@ -589,7 +589,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif type = type.GetElementType(); } - if (type == null || type == typeof(ushort)) + if (type is null || type == typeof(ushort)) { return new ExifValue(tag, ExifDataType.Short, value, isArray); } @@ -616,7 +616,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif /// private void CheckValue(object value) { - if (value == null) + if (value is null) { return; } diff --git a/src/ImageSharp/MetaData/Profiles/Exif/ExifWriter.cs b/src/ImageSharp/MetaData/Profiles/Exif/ExifWriter.cs index dc75697e29..ade373341e 100644 --- a/src/ImageSharp/MetaData/Profiles/Exif/ExifWriter.cs +++ b/src/ImageSharp/MetaData/Profiles/Exif/ExifWriter.cs @@ -20,9 +20,9 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif private ExifParts allowedParts; private IList values; private List dataOffsets; - private List ifdIndexes; - private List exifIndexes; - private List gpsIndexes; + private readonly List ifdIndexes; + private readonly List exifIndexes; + private readonly List gpsIndexes; /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccCurveSegment.cs b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccCurveSegment.cs index 157453f1b1..516887bcd6 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccCurveSegment.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccCurveSegment.cs @@ -27,7 +27,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public virtual bool Equals(IccCurveSegment other) { - if (other == null) + if (other is null) { return false; } @@ -40,4 +40,4 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc return this.Signature == other.Signature; } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccOneDimensionalCurve.cs b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccOneDimensionalCurve.cs index 2ad9079e13..7076e51447 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccOneDimensionalCurve.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccOneDimensionalCurve.cs @@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccOneDimensionalCurve other) { - if (other == null) + if (other is null) { return false; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccResponseCurve.cs b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccResponseCurve.cs index 6873c5f4d6..02ab301bd2 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccResponseCurve.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccResponseCurve.cs @@ -49,7 +49,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccResponseCurve other) { - if (other == null) + if (other is null) { return false; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs index 49b453a464..cc0f8f34dc 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System; using System.Text; namespace SixLabors.ImageSharp.MetaData.Profiles.Icc @@ -28,8 +29,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// The data to read public IccDataReader(byte[] data) { - Guard.NotNull(data, nameof(data)); - this.data = data; + this.data = data ?? throw new ArgumentNullException(nameof(data)); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs index bf39a08491..a58f62519c 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs @@ -199,7 +199,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc Guard.MustBeGreaterThan(length, 0, nameof(length)); - if (value == null) + if (value is null) { value = string.Empty; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs index 18280faaf5..51ea2d4e4a 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs @@ -901,7 +901,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc { int size, count = 0; - if (value.Ascii == null) + if (value.Ascii is null) { count += this.WriteUInt32(0); } @@ -914,7 +914,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc this.dataStream.Position += size; } - if (value.Unicode == null) + if (value.Unicode is null) { count += this.WriteUInt32(0); count += this.WriteUInt32(0); @@ -929,7 +929,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc this.dataStream.Position += size; } - if (value.ScriptCode == null) + if (value.ScriptCode is null) { count += this.WriteUInt16(0); count += this.WriteByte(0); diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs index 2b2fe1e4ec..dac56c608e 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs @@ -18,7 +18,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// /// The byte array to read the ICC profile from /// - private byte[] data; + private readonly byte[] data; /// /// The backing file for the property @@ -200,7 +200,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc return; } - if (this.data == null) + if (this.data is null) { this.header = new IccProfileHeader(); return; @@ -217,7 +217,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc return; } - if (this.data == null) + if (this.data is null) { this.entries = new List(); return; diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs index 231f3818ad..2687e10b66 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs @@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public virtual bool Equals(IccTagDataEntry other) { - if (other == null) + if (other is null) { return false; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccClutProcessElement.cs b/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccClutProcessElement.cs index 384ae850f3..6aba186326 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccClutProcessElement.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccClutProcessElement.cs @@ -17,8 +17,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc public IccClutProcessElement(IccClut clutValue) : base(IccMultiProcessElementSignature.Clut, clutValue?.InputChannelCount ?? 1, clutValue?.OutputChannelCount ?? 1) { - Guard.NotNull(clutValue, nameof(clutValue)); - this.ClutValue = clutValue; + this.ClutValue = clutValue ?? throw new ArgumentNullException(nameof(clutValue)); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccCurveSetProcessElement.cs b/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccCurveSetProcessElement.cs index 0aa0306845..7585fc2128 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccCurveSetProcessElement.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccCurveSetProcessElement.cs @@ -18,8 +18,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc public IccCurveSetProcessElement(IccOneDimensionalCurve[] curves) : base(IccMultiProcessElementSignature.CurveSet, curves?.Length ?? 1, curves?.Length ?? 1) { - Guard.NotNull(curves, nameof(curves)); - this.Curves = curves; + this.Curves = curves ?? throw new ArgumentNullException(nameof(curves)); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccMultiProcessElement.cs b/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccMultiProcessElement.cs index 3da482b1f4..db2d56cc3d 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccMultiProcessElement.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccMultiProcessElement.cs @@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public virtual bool Equals(IccMultiProcessElement other) { - if (other == null) + if (other is null) { return false; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccChromaticityTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccChromaticityTagDataEntry.cs index c008463eec..a87dae8c5d 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccChromaticityTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccChromaticityTagDataEntry.cs @@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc this.ChannelValues = channelValues; int channelLength = channelValues[0].Length; - bool channelsNotSame = channelValues.Any(t => t == null || t.Length != channelLength); + bool channelsNotSame = channelValues.Any(t => t is null || t.Length != channelLength); Guard.IsFalse(channelsNotSame, nameof(channelValues), "The number of values per channel is not the same for all channels"); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs index 6df2f556f0..54c2056151 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs @@ -48,7 +48,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccColorantOrderTagDataEntry other) { - if (other == null) + if (other is null) { return false; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantTableTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantTableTagDataEntry.cs index 90b1c304ba..dd99a2f9fb 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantTableTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantTableTagDataEntry.cs @@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccColorantTableTagDataEntry other) { - if (other == null) + if (other is null) { return false; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs index b2bbb7b566..cc1aea3192 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs @@ -94,7 +94,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccCrdInfoTagDataEntry other) { - if (other == null) + if (other is null) { return false; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs index 40666934f4..38a2f4522c 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs @@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccCurveTagDataEntry other) { - if (other == null) + if (other is null) { return false; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs index 7f034cebfe..9b24bffe85 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs @@ -42,8 +42,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc public IccDataTagDataEntry(byte[] data, bool isAscii, IccProfileTag tagSignature) : base(IccTypeSignature.Data, tagSignature) { - Guard.NotNull(data, nameof(data)); - this.Data = data; + this.Data = data ?? throw new ArgumentException(nameof(data)); this.IsAscii = isAscii; } @@ -72,7 +71,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccDataTagDataEntry other) { - if (other == null) + if (other is null) { return false; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDateTimeTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDateTimeTagDataEntry.cs index 004603a0e5..792c653f6c 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDateTimeTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDateTimeTagDataEntry.cs @@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccDateTimeTagDataEntry other) { - if (other == null) + if (other is null) { return false; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs index 8a7d068f98..a76310927b 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs @@ -27,8 +27,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc public IccFix16ArrayTagDataEntry(float[] data, IccProfileTag tagSignature) : base(IccTypeSignature.S15Fixed16Array, tagSignature) { - Guard.NotNull(data, nameof(data)); - this.Data = data; + this.Data = data ?? throw new ArgumentNullException(nameof(data)); } /// @@ -45,7 +44,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccFix16ArrayTagDataEntry other) { - if (other == null) + if (other is null) { return false; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs index f296a8b077..9a7f2123e2 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs @@ -117,7 +117,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccLut16TagDataEntry other) { - if (other == null) + if (other is null) { return false; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs index f94d500c39..bc0335cd8b 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs @@ -120,7 +120,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccLut8TagDataEntry other) { - if (other == null) + if (other is null) { return false; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs index c4f3f8a2a7..22d5f7b2f1 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs @@ -153,7 +153,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccLutAToBTagDataEntry other) { - if (other == null) + if (other is null) { return false; } @@ -200,8 +200,8 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc private bool EqualsCurve(IccTagDataEntry[] thisCurves, IccTagDataEntry[] entryCurves) { - bool thisNull = thisCurves == null; - bool entryNull = entryCurves == null; + bool thisNull = thisCurves is null; + bool entryNull = entryCurves is null; if (thisNull && entryNull) { @@ -271,7 +271,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc private Vector3? CreateMatrix3x1(float[] matrix) { - if (matrix == null) + if (matrix is null) { return null; } @@ -281,7 +281,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc private Matrix4x4? CreateMatrix3x3(float[,] matrix) { - if (matrix == null) + if (matrix is null) { return null; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs index 17bbf915ba..a739358b56 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs @@ -153,7 +153,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccLutBToATagDataEntry other) { - if (other == null) + if (other is null) { return false; } @@ -200,8 +200,8 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc private bool EqualsCurve(IccTagDataEntry[] thisCurves, IccTagDataEntry[] entryCurves) { - bool thisNull = thisCurves == null; - bool entryNull = entryCurves == null; + bool thisNull = thisCurves is null; + bool entryNull = entryCurves is null; if (thisNull && entryNull) { @@ -271,7 +271,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc private Vector3? CreateMatrix3x1(float[] matrix) { - if (matrix == null) + if (matrix is null) { return null; } @@ -281,7 +281,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc private Matrix4x4? CreateMatrix3x3(float[,] matrix) { - if (matrix == null) + if (matrix is null) { return null; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMeasurementTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMeasurementTagDataEntry.cs index f32e17714d..262129a380 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMeasurementTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMeasurementTagDataEntry.cs @@ -79,7 +79,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccMeasurementTagDataEntry other) { - if (other == null) + if (other is null) { return false; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiLocalizedUnicodeTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiLocalizedUnicodeTagDataEntry.cs index c006c95569..48ed048bf9 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiLocalizedUnicodeTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiLocalizedUnicodeTagDataEntry.cs @@ -29,8 +29,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc public IccMultiLocalizedUnicodeTagDataEntry(IccLocalizedString[] texts, IccProfileTag tagSignature) : base(IccTypeSignature.MultiLocalizedUnicode, tagSignature) { - Guard.NotNull(texts, nameof(texts)); - this.Texts = texts; + this.Texts = texts ?? throw new ArgumentNullException(nameof(texts)); } /// @@ -47,7 +46,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccMultiLocalizedUnicodeTagDataEntry other) { - if (other == null) + if (other is null) { return false; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiProcessElementsTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiProcessElementsTagDataEntry.cs index dcfe010aa1..1429a0a878 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiProcessElementsTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiProcessElementsTagDataEntry.cs @@ -65,7 +65,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccMultiProcessElementsTagDataEntry other) { - if (other == null) + if (other is null) { return false; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceDescTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceDescTagDataEntry.cs index c420046347..da6fcd7a2a 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceDescTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceDescTagDataEntry.cs @@ -30,8 +30,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc public IccProfileSequenceDescTagDataEntry(IccProfileDescription[] descriptions, IccProfileTag tagSignature) : base(IccTypeSignature.ProfileSequenceDesc, tagSignature) { - Guard.NotNull(descriptions, nameof(descriptions)); - this.Descriptions = descriptions; + this.Descriptions = descriptions ?? throw new ArgumentNullException(nameof(descriptions)); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs index 3336155242..51528a0736 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs @@ -28,8 +28,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc public IccProfileSequenceIdentifierTagDataEntry(IccProfileSequenceIdentifier[] data, IccProfileTag tagSignature) : base(IccTypeSignature.ProfileSequenceIdentifier, tagSignature) { - Guard.NotNull(data, nameof(data)); - this.Data = data; + this.Data = data ?? throw new ArgumentNullException(nameof(data)); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs index de6264824f..0bf8abfcac 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs @@ -30,10 +30,8 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc public IccScreeningTagDataEntry(IccScreeningFlag flags, IccScreeningChannel[] channels, IccProfileTag tagSignature) : base(IccTypeSignature.Screening, tagSignature) { - Guard.NotNull(channels, nameof(channels)); - this.Flags = flags; - this.Channels = channels; + this.Channels = channels ?? throw new ArgumentNullException(nameof(channels)); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccSignatureTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccSignatureTagDataEntry.cs index e469e7eab5..da557e644f 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccSignatureTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccSignatureTagDataEntry.cs @@ -28,12 +28,11 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc public IccSignatureTagDataEntry(string signatureData, IccProfileTag tagSignature) : base(IccTypeSignature.Signature, tagSignature) { - Guard.NotNull(signatureData, nameof(signatureData)); - this.SignatureData = signatureData; + this.SignatureData = signatureData ?? throw new ArgumentNullException(nameof(signatureData)); } /// - /// Gets the Signature + /// Gets the signature data /// public string SignatureData { get; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs index cc67dd1b16..ca1e4c4915 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs @@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// The converted entry public static explicit operator IccMultiLocalizedUnicodeTagDataEntry(IccTextDescriptionTagDataEntry textEntry) { - if (textEntry == null) + if (textEntry is null) { return null; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextTagDataEntry.cs index 1cf321893d..f10712d96c 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextTagDataEntry.cs @@ -27,8 +27,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc public IccTextTagDataEntry(string text, IccProfileTag tagSignature) : base(IccTypeSignature.Text, tagSignature) { - Guard.NotNull(text, nameof(text)); - this.Text = text; + this.Text = text ?? throw new ArgumentNullException(nameof(text)); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs index 4d9979a4fc..19430dc7b8 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs @@ -27,8 +27,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc public IccUFix16ArrayTagDataEntry(float[] data, IccProfileTag tagSignature) : base(IccTypeSignature.U16Fixed16Array, tagSignature) { - Guard.NotNull(data, nameof(data)); - this.Data = data; + this.Data = data ?? throw new ArgumentNullException(nameof(data)); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs index b0c225d85a..d9c093bda0 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs @@ -27,8 +27,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc public IccUInt16ArrayTagDataEntry(ushort[] data, IccProfileTag tagSignature) : base(IccTypeSignature.UInt16Array, tagSignature) { - Guard.NotNull(data, nameof(data)); - this.Data = data; + this.Data = data ?? throw new ArgumentNullException(nameof(data)); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs index c8b95d8354..8031919290 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs @@ -27,8 +27,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc public IccUInt32ArrayTagDataEntry(uint[] data, IccProfileTag tagSignature) : base(IccTypeSignature.UInt32Array, tagSignature) { - Guard.NotNull(data, nameof(data)); - this.Data = data; + this.Data = data ?? throw new ArgumentNullException(nameof(data)); } /// @@ -45,7 +44,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccUInt32ArrayTagDataEntry other) { - if (other == null) + if (other is null) { return false; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs index b780183df2..2973b9ae6b 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs @@ -28,8 +28,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc public IccUInt64ArrayTagDataEntry(ulong[] data, IccProfileTag tagSignature) : base(IccTypeSignature.UInt64Array, tagSignature) { - Guard.NotNull(data, nameof(data)); - this.Data = data; + this.Data = data ?? throw new ArgumentNullException(nameof(data)); } /// @@ -46,7 +45,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccUInt64ArrayTagDataEntry other) { - if (other == null) + if (other is null) { return false; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs index 920b9efc03..2391ce96a6 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs @@ -27,8 +27,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc public IccUInt8ArrayTagDataEntry(byte[] data, IccProfileTag tagSignature) : base(IccTypeSignature.UInt8Array, tagSignature) { - Guard.NotNull(data, nameof(data)); - this.Data = data; + this.Data = data ?? throw new ArgumentNullException(nameof(data)); } /// @@ -45,7 +44,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccUInt8ArrayTagDataEntry other) { - if (other == null) + if (other is null) { return false; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs index 28759a54cd..eed4f97d47 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs @@ -32,13 +32,9 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc public IccUcrBgTagDataEntry(ushort[] ucrCurve, ushort[] bgCurve, string description, IccProfileTag tagSignature) : base(IccTypeSignature.UcrBg, tagSignature) { - Guard.NotNull(ucrCurve, nameof(ucrCurve)); - Guard.NotNull(bgCurve, nameof(bgCurve)); - Guard.NotNull(description, nameof(description)); - - this.UcrCurve = ucrCurve; - this.BgCurve = bgCurve; - this.Description = description; + this.UcrCurve = ucrCurve ?? throw new ArgumentNullException(nameof(ucrCurve)); + this.BgCurve = bgCurve ?? throw new ArgumentNullException(nameof(bgCurve)); + this.Description = description ?? throw new ArgumentNullException(nameof(description)); } /// @@ -65,7 +61,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccUcrBgTagDataEntry other) { - if (other == null) + if (other is null) { return false; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs index 68a0ff2f43..da206a968b 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs @@ -27,8 +27,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc public IccUnknownTagDataEntry(byte[] data, IccProfileTag tagSignature) : base(IccTypeSignature.Unknown, tagSignature) { - Guard.NotNull(data, nameof(data)); - this.Data = data; + this.Data = data ?? throw new ArgumentNullException(nameof(data)); } /// @@ -45,7 +44,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccUnknownTagDataEntry other) { - if (other == null) + if (other is null) { return false; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccXyzTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccXyzTagDataEntry.cs index 1623923261..c1c14d8cbb 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccXyzTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccXyzTagDataEntry.cs @@ -28,8 +28,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc public IccXyzTagDataEntry(Vector3[] data, IccProfileTag tagSignature) : base(IccTypeSignature.Xyz, tagSignature) { - Guard.NotNull(data, nameof(data)); - this.Data = data; + this.Data = data ?? throw new ArgumentNullException(nameof(data)); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs index 3f9d865b77..4878d96e4b 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs @@ -116,7 +116,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// public bool Equals(IccClut other) { - if (other == null) + if (other is null) { return false; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccColorantTableEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccColorantTableEntry.cs index 22e4a05237..56aa8b335d 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccColorantTableEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccColorantTableEntry.cs @@ -28,9 +28,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// Third PCS value public IccColorantTableEntry(string name, ushort pcs1, ushort pcs2, ushort pcs3) { - Guard.NotNull(name, nameof(name)); - - this.Name = name; + this.Name = name ?? throw new ArgumentNullException(nameof(name)); this.Pcs1 = pcs1; this.Pcs2 = pcs2; this.Pcs3 = pcs3; diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccLocalizedString.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccLocalizedString.cs index 18e28e94c3..00ededca4d 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccLocalizedString.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccLocalizedString.cs @@ -29,11 +29,8 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// The text value of this string public IccLocalizedString(CultureInfo culture, string text) { - Guard.NotNull(culture, nameof(culture)); - Guard.NotNull(text, nameof(text)); - - this.Culture = culture; - this.Text = text; + this.Culture = culture ?? throw new ArgumentNullException(nameof(culture)); + this.Text = text ?? throw new ArgumentNullException(nameof(text)); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccLut.cs b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccLut.cs index a846311439..c46d6884b6 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Various/IccLut.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Various/IccLut.cs @@ -16,8 +16,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc /// The LUT values public IccLut(float[] values) { - Guard.NotNull(values, nameof(values)); - this.Values = values; + this.Values = values ?? throw new ArgumentNullException(nameof(values)); } /// diff --git a/src/ImageSharp/PixelFormats/ColorBuilder{TPixel}.cs b/src/ImageSharp/PixelFormats/ColorBuilder{TPixel}.cs index c2c0277f9e..cf66f5d5e8 100644 --- a/src/ImageSharp/PixelFormats/ColorBuilder{TPixel}.cs +++ b/src/ImageSharp/PixelFormats/ColorBuilder{TPixel}.cs @@ -28,7 +28,7 @@ namespace SixLabors.ImageSharp.PixelFormats hex = ToRgbaHex(hex); - if (hex == null || !uint.TryParse(hex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out uint packedValue)) + if (hex is null || !uint.TryParse(hex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out uint packedValue)) { throw new ArgumentException("Hexadecimal string is not in the correct format.", nameof(hex)); } diff --git a/src/ImageSharp/PixelFormats/PixelBlenderMode.cs b/src/ImageSharp/PixelFormats/PixelAlphaCompositionMode.cs similarity index 53% rename from src/ImageSharp/PixelFormats/PixelBlenderMode.cs rename to src/ImageSharp/PixelFormats/PixelAlphaCompositionMode.cs index 7a8ab6592a..2758a74808 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenderMode.cs +++ b/src/ImageSharp/PixelFormats/PixelAlphaCompositionMode.cs @@ -4,55 +4,15 @@ namespace SixLabors.ImageSharp.PixelFormats { /// - /// Enumerates the various blending modes. + /// Enumerates the various alpha composition modes. /// - public enum PixelBlenderMode - { + public enum PixelAlphaCompositionMode + { /// - /// Default blending mode, also known as "Normal" or "Alpha Blending" - /// - Normal = 0, - - /// - /// Blends the 2 values by multiplication. - /// - Multiply, - - /// - /// Blends the 2 values by addition. - /// - Add, - - /// - /// Blends the 2 values by subtraction. - /// - Subtract, - - /// - /// Multiplies the complements of the backdrop and source values, then complements the result. - /// - Screen, - - /// - /// Selects the minimum of the backdrop and source values. - /// - Darken, - - /// - /// Selects the max of the backdrop and source values. - /// - Lighten, - - /// - /// Multiplies or screens the values, depending on the backdrop vector values. - /// - Overlay, - - /// - /// Multiplies or screens the colors, depending on the source value. + /// returns the destination over the source. /// - HardLight, - + SrcOver = 0, + /// /// returns the source colors. /// @@ -61,22 +21,17 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// returns the source over the destination. /// - Atop, - - /// - /// returns the destination over the source. - /// - Over, + SrcAtop, /// /// The source where the destination and source overlap. /// - In, + SrcIn, /// /// The destination where the destination and source overlap. /// - Out, + SrcOut, /// /// The destination where the source does not overlap it. diff --git a/src/ImageSharp/PixelFormats/PixelColorBlendingMode.cs b/src/ImageSharp/PixelFormats/PixelColorBlendingMode.cs new file mode 100644 index 0000000000..a68f7d9492 --- /dev/null +++ b/src/ImageSharp/PixelFormats/PixelColorBlendingMode.cs @@ -0,0 +1,56 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Enumerates the various color blending modes. + /// + public enum PixelColorBlendingMode + { + /// + /// Default blending mode, also known as "Normal" or "Alpha Blending" + /// + Normal = 0, + + /// + /// Blends the 2 values by multiplication. + /// + Multiply, + + /// + /// Blends the 2 values by addition. + /// + Add, + + /// + /// Blends the 2 values by subtraction. + /// + Subtract, + + /// + /// Multiplies the complements of the backdrop and source values, then complements the result. + /// + Screen, + + /// + /// Selects the minimum of the backdrop and source values. + /// + Darken, + + /// + /// Selects the max of the backdrop and source values. + /// + Lighten, + + /// + /// Multiplies or screens the values, depending on the backdrop vector values. + /// + Overlay, + + /// + /// Multiplies or screens the colors, depending on the source value. + /// + HardLight, + } +} diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.PixelBenders.cs b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.PixelBenders.cs index ca6a28192d..dcddadb6a1 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.PixelBenders.cs +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.PixelBenders.cs @@ -1,50 +1,217 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using SixLabors.ImageSharp.PixelFormats.PixelBlenders; - -namespace SixLabors.ImageSharp.PixelFormats -{ - /// - /// Provides access to pixel blenders - /// - public partial class PixelOperations - where TPixel : struct, IPixel - { - /// - /// Find an instance of the pixel blender. - /// - /// The blending mode to apply - /// A . - internal virtual PixelBlender GetPixelBlender(PixelBlenderMode mode) - { - switch (mode) - { - case PixelBlenderMode.Multiply: return DefaultPixelBlenders.MultiplySrcOver.Instance; - case PixelBlenderMode.Add: return DefaultPixelBlenders.AddSrcOver.Instance; - case PixelBlenderMode.Subtract: return DefaultPixelBlenders.SubtractSrcOver.Instance; - case PixelBlenderMode.Screen: return DefaultPixelBlenders.ScreenSrcOver.Instance; - case PixelBlenderMode.Darken: return DefaultPixelBlenders.DarkenSrcOver.Instance; - case PixelBlenderMode.Lighten: return DefaultPixelBlenders.LightenSrcOver.Instance; - case PixelBlenderMode.Overlay: return DefaultPixelBlenders.OverlaySrcOver.Instance; - case PixelBlenderMode.HardLight: return DefaultPixelBlenders.HardLightSrcOver.Instance; - case PixelBlenderMode.Src: return DefaultPixelBlenders.NormalSrc.Instance; - case PixelBlenderMode.Atop: return DefaultPixelBlenders.NormalSrcAtop.Instance; - case PixelBlenderMode.Over: return DefaultPixelBlenders.NormalSrcOver.Instance; - case PixelBlenderMode.In: return DefaultPixelBlenders.NormalSrcIn.Instance; - case PixelBlenderMode.Out: return DefaultPixelBlenders.NormalSrcOut.Instance; - case PixelBlenderMode.Dest: return DefaultPixelBlenders.NormalDest.Instance; - case PixelBlenderMode.DestAtop: return DefaultPixelBlenders.NormalDestAtop.Instance; - case PixelBlenderMode.DestOver: return DefaultPixelBlenders.NormalDestOver.Instance; - case PixelBlenderMode.DestIn: return DefaultPixelBlenders.NormalDestIn.Instance; - case PixelBlenderMode.DestOut: return DefaultPixelBlenders.NormalDestOut.Instance; - case PixelBlenderMode.Clear: return DefaultPixelBlenders.NormalClear.Instance; - case PixelBlenderMode.Xor: return DefaultPixelBlenders.NormalXor.Instance; - - case PixelBlenderMode.Normal: - default: - return DefaultPixelBlenders.NormalSrcOver.Instance; - } - } - } +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats.PixelBlenders; + +namespace SixLabors.ImageSharp.PixelFormats +{ + /// + /// Provides access to pixel blenders + /// + public partial class PixelOperations + where TPixel : struct, IPixel + { + /// + /// Find an instance of the pixel blender. + /// + /// the blending and composition to apply + /// A . + internal PixelBlender GetPixelBlender(GraphicsOptions options) + { + return this.GetPixelBlender(options.ColorBlendingMode, options.AlphaCompositionMode); + } + + /// + /// Find an instance of the pixel blender. + /// + /// The color blending mode to apply + /// The alpha composition mode to apply + /// A . + internal virtual PixelBlender GetPixelBlender(PixelColorBlendingMode colorMode, PixelAlphaCompositionMode alphaMode) + { + switch (alphaMode) + { + case PixelAlphaCompositionMode.Clear: + switch (colorMode) + { + case PixelColorBlendingMode.Multiply: return DefaultPixelBlenders.MultiplyClear.Instance; + case PixelColorBlendingMode.Add: return DefaultPixelBlenders.AddClear.Instance; + case PixelColorBlendingMode.Subtract: return DefaultPixelBlenders.SubtractClear.Instance; + case PixelColorBlendingMode.Screen: return DefaultPixelBlenders.ScreenClear.Instance; + case PixelColorBlendingMode.Darken: return DefaultPixelBlenders.DarkenClear.Instance; + case PixelColorBlendingMode.Lighten: return DefaultPixelBlenders.LightenClear.Instance; + case PixelColorBlendingMode.Overlay: return DefaultPixelBlenders.OverlayClear.Instance; + case PixelColorBlendingMode.HardLight: return DefaultPixelBlenders.HardLightClear.Instance; + case PixelColorBlendingMode.Normal: + default: return DefaultPixelBlenders.NormalClear.Instance; + } + + case PixelAlphaCompositionMode.Xor: + switch (colorMode) + { + case PixelColorBlendingMode.Multiply: return DefaultPixelBlenders.MultiplyXor.Instance; + case PixelColorBlendingMode.Add: return DefaultPixelBlenders.AddXor.Instance; + case PixelColorBlendingMode.Subtract: return DefaultPixelBlenders.SubtractXor.Instance; + case PixelColorBlendingMode.Screen: return DefaultPixelBlenders.ScreenXor.Instance; + case PixelColorBlendingMode.Darken: return DefaultPixelBlenders.DarkenXor.Instance; + case PixelColorBlendingMode.Lighten: return DefaultPixelBlenders.LightenXor.Instance; + case PixelColorBlendingMode.Overlay: return DefaultPixelBlenders.OverlayXor.Instance; + case PixelColorBlendingMode.HardLight: return DefaultPixelBlenders.HardLightXor.Instance; + case PixelColorBlendingMode.Normal: + default: return DefaultPixelBlenders.NormalXor.Instance; + } + + case PixelAlphaCompositionMode.Src: + switch (colorMode) + { + case PixelColorBlendingMode.Multiply: return DefaultPixelBlenders.MultiplySrc.Instance; + case PixelColorBlendingMode.Add: return DefaultPixelBlenders.AddSrc.Instance; + case PixelColorBlendingMode.Subtract: return DefaultPixelBlenders.SubtractSrc.Instance; + case PixelColorBlendingMode.Screen: return DefaultPixelBlenders.ScreenSrc.Instance; + case PixelColorBlendingMode.Darken: return DefaultPixelBlenders.DarkenSrc.Instance; + case PixelColorBlendingMode.Lighten: return DefaultPixelBlenders.LightenSrc.Instance; + case PixelColorBlendingMode.Overlay: return DefaultPixelBlenders.OverlaySrc.Instance; + case PixelColorBlendingMode.HardLight: return DefaultPixelBlenders.HardLightSrc.Instance; + case PixelColorBlendingMode.Normal: + default: return DefaultPixelBlenders.NormalSrc.Instance; + } + + case PixelAlphaCompositionMode.SrcAtop: + switch (colorMode) + { + case PixelColorBlendingMode.Multiply: return DefaultPixelBlenders.MultiplySrcAtop.Instance; + case PixelColorBlendingMode.Add: return DefaultPixelBlenders.AddSrcAtop.Instance; + case PixelColorBlendingMode.Subtract: return DefaultPixelBlenders.SubtractSrcAtop.Instance; + case PixelColorBlendingMode.Screen: return DefaultPixelBlenders.ScreenSrcAtop.Instance; + case PixelColorBlendingMode.Darken: return DefaultPixelBlenders.DarkenSrcAtop.Instance; + case PixelColorBlendingMode.Lighten: return DefaultPixelBlenders.LightenSrcAtop.Instance; + case PixelColorBlendingMode.Overlay: return DefaultPixelBlenders.OverlaySrcAtop.Instance; + case PixelColorBlendingMode.HardLight: return DefaultPixelBlenders.HardLightSrcAtop.Instance; + case PixelColorBlendingMode.Normal: + default: return DefaultPixelBlenders.NormalSrcAtop.Instance; + } + + case PixelAlphaCompositionMode.SrcIn: + switch (colorMode) + { + case PixelColorBlendingMode.Multiply: return DefaultPixelBlenders.MultiplySrcIn.Instance; + case PixelColorBlendingMode.Add: return DefaultPixelBlenders.AddSrcIn.Instance; + case PixelColorBlendingMode.Subtract: return DefaultPixelBlenders.SubtractSrcIn.Instance; + case PixelColorBlendingMode.Screen: return DefaultPixelBlenders.ScreenSrcIn.Instance; + case PixelColorBlendingMode.Darken: return DefaultPixelBlenders.DarkenSrcIn.Instance; + case PixelColorBlendingMode.Lighten: return DefaultPixelBlenders.LightenSrcIn.Instance; + case PixelColorBlendingMode.Overlay: return DefaultPixelBlenders.OverlaySrcIn.Instance; + case PixelColorBlendingMode.HardLight: return DefaultPixelBlenders.HardLightSrcIn.Instance; + case PixelColorBlendingMode.Normal: + default: return DefaultPixelBlenders.NormalSrcIn.Instance; + } + + case PixelAlphaCompositionMode.SrcOut: + switch (colorMode) + { + case PixelColorBlendingMode.Multiply: return DefaultPixelBlenders.MultiplySrcOut.Instance; + case PixelColorBlendingMode.Add: return DefaultPixelBlenders.AddSrcOut.Instance; + case PixelColorBlendingMode.Subtract: return DefaultPixelBlenders.SubtractSrcOut.Instance; + case PixelColorBlendingMode.Screen: return DefaultPixelBlenders.ScreenSrcOut.Instance; + case PixelColorBlendingMode.Darken: return DefaultPixelBlenders.DarkenSrcOut.Instance; + case PixelColorBlendingMode.Lighten: return DefaultPixelBlenders.LightenSrcOut.Instance; + case PixelColorBlendingMode.Overlay: return DefaultPixelBlenders.OverlaySrcOut.Instance; + case PixelColorBlendingMode.HardLight: return DefaultPixelBlenders.HardLightSrcOut.Instance; + case PixelColorBlendingMode.Normal: + default: return DefaultPixelBlenders.NormalSrcOut.Instance; + } + + case PixelAlphaCompositionMode.Dest: + switch (colorMode) + { + case PixelColorBlendingMode.Multiply: return DefaultPixelBlenders.MultiplyDest.Instance; + case PixelColorBlendingMode.Add: return DefaultPixelBlenders.AddDest.Instance; + case PixelColorBlendingMode.Subtract: return DefaultPixelBlenders.SubtractDest.Instance; + case PixelColorBlendingMode.Screen: return DefaultPixelBlenders.ScreenDest.Instance; + case PixelColorBlendingMode.Darken: return DefaultPixelBlenders.DarkenDest.Instance; + case PixelColorBlendingMode.Lighten: return DefaultPixelBlenders.LightenDest.Instance; + case PixelColorBlendingMode.Overlay: return DefaultPixelBlenders.OverlayDest.Instance; + case PixelColorBlendingMode.HardLight: return DefaultPixelBlenders.HardLightDest.Instance; + case PixelColorBlendingMode.Normal: + default: return DefaultPixelBlenders.NormalDest.Instance; + } + + case PixelAlphaCompositionMode.DestAtop: + switch (colorMode) + { + case PixelColorBlendingMode.Multiply: return DefaultPixelBlenders.MultiplyDestAtop.Instance; + case PixelColorBlendingMode.Add: return DefaultPixelBlenders.AddDestAtop.Instance; + case PixelColorBlendingMode.Subtract: return DefaultPixelBlenders.SubtractDestAtop.Instance; + case PixelColorBlendingMode.Screen: return DefaultPixelBlenders.ScreenDestAtop.Instance; + case PixelColorBlendingMode.Darken: return DefaultPixelBlenders.DarkenDestAtop.Instance; + case PixelColorBlendingMode.Lighten: return DefaultPixelBlenders.LightenDestAtop.Instance; + case PixelColorBlendingMode.Overlay: return DefaultPixelBlenders.OverlayDestAtop.Instance; + case PixelColorBlendingMode.HardLight: return DefaultPixelBlenders.HardLightDestAtop.Instance; + case PixelColorBlendingMode.Normal: + default: return DefaultPixelBlenders.NormalDestAtop.Instance; + } + + case PixelAlphaCompositionMode.DestIn: + switch (colorMode) + { + case PixelColorBlendingMode.Multiply: return DefaultPixelBlenders.MultiplyDestIn.Instance; + case PixelColorBlendingMode.Add: return DefaultPixelBlenders.AddDestIn.Instance; + case PixelColorBlendingMode.Subtract: return DefaultPixelBlenders.SubtractDestIn.Instance; + case PixelColorBlendingMode.Screen: return DefaultPixelBlenders.ScreenDestIn.Instance; + case PixelColorBlendingMode.Darken: return DefaultPixelBlenders.DarkenDestIn.Instance; + case PixelColorBlendingMode.Lighten: return DefaultPixelBlenders.LightenDestIn.Instance; + case PixelColorBlendingMode.Overlay: return DefaultPixelBlenders.OverlayDestIn.Instance; + case PixelColorBlendingMode.HardLight: return DefaultPixelBlenders.HardLightDestIn.Instance; + case PixelColorBlendingMode.Normal: + default: return DefaultPixelBlenders.NormalDestIn.Instance; + } + + case PixelAlphaCompositionMode.DestOut: + switch (colorMode) + { + case PixelColorBlendingMode.Multiply: return DefaultPixelBlenders.MultiplyDestOut.Instance; + case PixelColorBlendingMode.Add: return DefaultPixelBlenders.AddDestOut.Instance; + case PixelColorBlendingMode.Subtract: return DefaultPixelBlenders.SubtractDestOut.Instance; + case PixelColorBlendingMode.Screen: return DefaultPixelBlenders.ScreenDestOut.Instance; + case PixelColorBlendingMode.Darken: return DefaultPixelBlenders.DarkenDestOut.Instance; + case PixelColorBlendingMode.Lighten: return DefaultPixelBlenders.LightenDestOut.Instance; + case PixelColorBlendingMode.Overlay: return DefaultPixelBlenders.OverlayDestOut.Instance; + case PixelColorBlendingMode.HardLight: return DefaultPixelBlenders.HardLightDestOut.Instance; + case PixelColorBlendingMode.Normal: + default: return DefaultPixelBlenders.NormalDestOut.Instance; + } + + case PixelAlphaCompositionMode.DestOver: + switch (colorMode) + { + case PixelColorBlendingMode.Multiply: return DefaultPixelBlenders.MultiplyDestOver.Instance; + case PixelColorBlendingMode.Add: return DefaultPixelBlenders.AddDestOver.Instance; + case PixelColorBlendingMode.Subtract: return DefaultPixelBlenders.SubtractDestOver.Instance; + case PixelColorBlendingMode.Screen: return DefaultPixelBlenders.ScreenDestOver.Instance; + case PixelColorBlendingMode.Darken: return DefaultPixelBlenders.DarkenDestOver.Instance; + case PixelColorBlendingMode.Lighten: return DefaultPixelBlenders.LightenDestOver.Instance; + case PixelColorBlendingMode.Overlay: return DefaultPixelBlenders.OverlayDestOver.Instance; + case PixelColorBlendingMode.HardLight: return DefaultPixelBlenders.HardLightDestOver.Instance; + case PixelColorBlendingMode.Normal: + default: return DefaultPixelBlenders.NormalDestOver.Instance; + } + + case PixelAlphaCompositionMode.SrcOver: + default: + switch (colorMode) + { + case PixelColorBlendingMode.Multiply: return DefaultPixelBlenders.MultiplySrcOver.Instance; + case PixelColorBlendingMode.Add: return DefaultPixelBlenders.AddSrcOver.Instance; + case PixelColorBlendingMode.Subtract: return DefaultPixelBlenders.SubtractSrcOver.Instance; + case PixelColorBlendingMode.Screen: return DefaultPixelBlenders.ScreenSrcOver.Instance; + case PixelColorBlendingMode.Darken: return DefaultPixelBlenders.DarkenSrcOver.Instance; + case PixelColorBlendingMode.Lighten: return DefaultPixelBlenders.LightenSrcOver.Instance; + case PixelColorBlendingMode.Overlay: return DefaultPixelBlenders.OverlaySrcOver.Instance; + case PixelColorBlendingMode.HardLight: return DefaultPixelBlenders.HardLightSrcOver.Instance; + case PixelColorBlendingMode.Normal: + default: return DefaultPixelBlenders.NormalSrcOver.Instance; + } + } + } + } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/DefaultInternalImageProcessorContext.cs b/src/ImageSharp/Processing/DefaultInternalImageProcessorContext.cs index a392b8d8e8..43ba259725 100644 --- a/src/ImageSharp/Processing/DefaultInternalImageProcessorContext.cs +++ b/src/ImageSharp/Processing/DefaultInternalImageProcessorContext.cs @@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Processing /// public Image Apply() { - if (!this.mutate && this.destination == null) + if (!this.mutate && this.destination is null) { // Ensure we have cloned it if we are not mutating as we might have failed to register any processors this.destination = this.source.Clone(); @@ -56,7 +56,7 @@ namespace SixLabors.ImageSharp.Processing /// public IImageProcessingContext ApplyProcessor(IImageProcessor processor, Rectangle rectangle) { - if (!this.mutate && this.destination == null) + if (!this.mutate && this.destination is null) { // This will only work if the first processor applied is the cloning one thus // realistically for this optimization to work the resize must the first processor diff --git a/src/ImageSharp/Processing/Processors/Binarization/BinaryOrderedDitherProcessor.cs b/src/ImageSharp/Processing/Processors/Binarization/BinaryOrderedDitherProcessor.cs index 95f4ef472e..048af82619 100644 --- a/src/ImageSharp/Processing/Processors/Binarization/BinaryOrderedDitherProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Binarization/BinaryOrderedDitherProcessor.cs @@ -33,9 +33,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization /// The color to use for pixels that are below the threshold. public BinaryOrderedDitherProcessor(IOrderedDither dither, TPixel upperColor, TPixel lowerColor) { - Guard.NotNull(dither, nameof(dither)); - - this.Dither = dither; + this.Dither = dither ?? throw new ArgumentNullException(nameof(dither)); this.UpperColor = upperColor; this.LowerColor = lowerColor; } diff --git a/src/ImageSharp/Processing/Processors/Dithering/OrderedDitherPaletteProcessor.cs b/src/ImageSharp/Processing/Processors/Dithering/OrderedDitherPaletteProcessor.cs index 4100fef8c2..b5e2eebc2b 100644 --- a/src/ImageSharp/Processing/Processors/Dithering/OrderedDitherPaletteProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/OrderedDitherPaletteProcessor.cs @@ -34,8 +34,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering public OrderedDitherPaletteProcessor(IOrderedDither dither, TPixel[] palette) : base(palette) { - Guard.NotNull(dither, nameof(dither)); - this.Dither = dither; + this.Dither = dither ?? throw new ArgumentNullException(nameof(dither)); } /// diff --git a/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessorBase.cs b/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessorBase.cs index e70c8acd29..a1bbe72733 100644 --- a/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessorBase.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessorBase.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System; using System.Collections.Generic; using System.Numerics; using System.Runtime.CompilerServices; @@ -28,8 +29,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering /// The palette to select substitute colors from. protected PaletteDitherProcessorBase(TPixel[] palette) { - Guard.NotNull(palette, nameof(palette)); - this.Palette = palette; + this.Palette = palette ?? throw new ArgumentNullException(nameof(palette)); this.paletteVector = new Vector4[this.Palette.Length]; PixelOperations.Instance.ToScaledVector4(this.Palette, this.paletteVector, this.Palette.Length); } diff --git a/src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor.cs index c7fa2ff19c..ecbeebeb06 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor.cs @@ -81,7 +81,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays amountSpan[i] = this.GraphicsOptions.BlendPercentage; } - PixelBlender blender = PixelOperations.Instance.GetPixelBlender(this.GraphicsOptions.BlenderMode); + PixelBlender blender = PixelOperations.Instance.GetPixelBlender(this.GraphicsOptions); ParallelFor.WithConfiguration( minY, maxY, diff --git a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs index 6042493310..eb91fec043 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs @@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays { this.GlowColor = color; this.Radius = radius; - this.blender = PixelOperations.Instance.GetPixelBlender(options.BlenderMode); + this.blender = PixelOperations.Instance.GetPixelBlender(options); this.GraphicsOptions = options; } diff --git a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs index b8bd6c5a53..63780df476 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs @@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays { this.VignetteColor = color; this.GraphicsOptions = options; - this.blender = PixelOperations.Instance.GetPixelBlender(options.BlenderMode); + this.blender = PixelOperations.Instance.GetPixelBlender(options); } /// @@ -56,7 +56,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays this.VignetteColor = color; this.RadiusX = radiusX; this.RadiusY = radiusY; - this.blender = PixelOperations.Instance.GetPixelBlender(options.BlenderMode); + this.blender = PixelOperations.Instance.GetPixelBlender(options); this.GraphicsOptions = options; } diff --git a/src/ImageSharp/Processing/Processors/Quantization/OctreeFrameQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/OctreeFrameQuantizer{TPixel}.cs index 0eb3db864c..3eac70eea5 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/OctreeFrameQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/OctreeFrameQuantizer{TPixel}.cs @@ -233,7 +233,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization { // If so, check if I have a previous node setup. This will only occur if the first color in the image // happens to be black, with an alpha component of zero. - if (this.previousNode == null) + if (this.previousNode is null) { this.previousColor = pixel; this.root.AddColor(ref pixel, this.maxColorBits, 0, this, ref rgba); @@ -309,7 +309,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization { // Find the deepest level containing at least one reducible node int index = this.maxColorBits - 1; - while ((index > 0) && (this.ReducibleNodes[index] == null)) + while ((index > 0) && (this.ReducibleNodes[index] is null)) { index--; } @@ -440,7 +440,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization | ((rgba.R & Mask[level]) >> shift); OctreeNode child = this.children[index]; - if (child == null) + if (child is null) { // Create a new child node and store it in the array child = new OctreeNode(level + 1, colorBits, octree); diff --git a/src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs index 619107f971..021dc62fbf 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs @@ -166,7 +166,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization /// protected override TPixel[] GetPalette() { - if (this.palette == null) + if (this.palette is null) { this.palette = new TPixel[this.colors]; for (int k = 0; k < this.colors; k++) diff --git a/src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor.cs index c077914ff6..a610ae5bb3 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor.cs @@ -73,13 +73,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// The private static OrientationMode GetExifOrientation(Image source) { - if (source.MetaData.ExifProfile == null) + if (source.MetaData.ExifProfile is null) { return OrientationMode.Unknown; } ExifValue value = source.MetaData.ExifProfile.GetValue(ExifTag.Orientation); - if (value == null) + if (value is null) { return OrientationMode.Unknown; } diff --git a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs index b18d882c24..93c847d598 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs @@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms protected override void AfterImageApply(Image source, Image destination, Rectangle sourceRectangle) { ExifProfile profile = destination.MetaData.ExifProfile; - if (profile == null) + if (profile is null) { return; } diff --git a/src/ImageSharp/Processing/Processors/Transforms/TransformHelpers.cs b/src/ImageSharp/Processing/Processors/Transforms/TransformHelpers.cs index 1b676139b3..b22fa64cfd 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/TransformHelpers.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/TransformHelpers.cs @@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms where TPixel : struct, IPixel { ExifProfile profile = image.MetaData.ExifProfile; - if (profile == null) + if (profile is null) { return; } diff --git a/tests/CodeCoverage/CodeCoverage.cmd b/tests/CodeCoverage/CodeCoverage.cmd index f0ed3da1bf..01e342b3d2 100644 --- a/tests/CodeCoverage/CodeCoverage.cmd +++ b/tests/CodeCoverage/CodeCoverage.cmd @@ -12,7 +12,7 @@ dotnet restore ImageSharp.sln rem Clean the solution to force a rebuild with /p:codecov=true dotnet clean ImageSharp.sln -c Release rem The -threshold options prevents this taking ages... -tests\CodeCoverage\OpenCover.4.6.519\tools\OpenCover.Console.exe -target:"dotnet.exe" -targetargs:"test tests\ImageSharp.Tests\ImageSharp.Tests.csproj -c Release -f netcoreapp2.0 /p:codecov=true" -register:user -threshold:10 -oldStyle -safemode:off -output:.\ImageSharp.Coverage.xml -hideskipped:All -returntargetcode -filter:"+[SixLabors.ImageSharp*]*" +tests\CodeCoverage\OpenCover.4.6.519\tools\OpenCover.Console.exe -target:"dotnet.exe" -targetargs:"test tests\ImageSharp.Tests\ImageSharp.Tests.csproj -c Release -f netcoreapp2.1 /p:codecov=true" -register:user -threshold:10 -oldStyle -safemode:off -output:.\ImageSharp.Coverage.xml -hideskipped:All -returntargetcode -filter:"+[SixLabors.ImageSharp*]*" if %errorlevel% neq 0 exit /b %errorlevel% diff --git a/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs b/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs index 40ad92adc2..740b30a8c3 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs @@ -25,30 +25,30 @@ namespace SixLabors.ImageSharp.Tests }; [Theory] - [WithFileCollection(nameof(TestFiles), PixelTypes, PixelBlenderMode.Normal)] - [WithFileCollection(nameof(TestFiles), PixelTypes, PixelBlenderMode.Multiply)] - [WithFileCollection(nameof(TestFiles), PixelTypes, PixelBlenderMode.Add)] - [WithFileCollection(nameof(TestFiles), PixelTypes, PixelBlenderMode.Subtract)] - [WithFileCollection(nameof(TestFiles), PixelTypes, PixelBlenderMode.Screen)] - [WithFileCollection(nameof(TestFiles), PixelTypes, PixelBlenderMode.Darken)] - [WithFileCollection(nameof(TestFiles), PixelTypes, PixelBlenderMode.Lighten)] - [WithFileCollection(nameof(TestFiles), PixelTypes, PixelBlenderMode.Overlay)] - [WithFileCollection(nameof(TestFiles), PixelTypes, PixelBlenderMode.HardLight)] - public void ImageShouldApplyDrawImage(TestImageProvider provider, PixelBlenderMode mode) + [WithFileCollection(nameof(TestFiles), PixelTypes, PixelColorBlendingMode.Normal)] + [WithFileCollection(nameof(TestFiles), PixelTypes, PixelColorBlendingMode.Multiply)] + [WithFileCollection(nameof(TestFiles), PixelTypes, PixelColorBlendingMode.Add)] + [WithFileCollection(nameof(TestFiles), PixelTypes, PixelColorBlendingMode.Subtract)] + [WithFileCollection(nameof(TestFiles), PixelTypes, PixelColorBlendingMode.Screen)] + [WithFileCollection(nameof(TestFiles), PixelTypes, PixelColorBlendingMode.Darken)] + [WithFileCollection(nameof(TestFiles), PixelTypes, PixelColorBlendingMode.Lighten)] + [WithFileCollection(nameof(TestFiles), PixelTypes, PixelColorBlendingMode.Overlay)] + [WithFileCollection(nameof(TestFiles), PixelTypes, PixelColorBlendingMode.HardLight)] + public void ImageShouldApplyDrawImage(TestImageProvider provider, PixelColorBlendingMode mode) where TPixel : struct, IPixel { using (Image image = provider.GetImage()) using (var blend = Image.Load(TestFile.Create(TestImages.Bmp.Car).Bytes)) { blend.Mutate(x => x.Resize(image.Width / 2, image.Height / 2)); - image.Mutate(x => x.DrawImage(blend, mode, .75f, new Point(image.Width / 4, image.Height / 4))); + image.Mutate(x => x.DrawImage(blend, new Point(image.Width / 4, image.Height / 4), mode, .75f) ); image.DebugSave(provider, new { mode }); } } [Theory] - [WithFileCollection(nameof(TestFiles), PixelTypes, PixelBlenderMode.Normal)] - public void ImageShouldDrawTransformedImage(TestImageProvider provider, PixelBlenderMode mode) + [WithFileCollection(nameof(TestFiles), PixelTypes, PixelColorBlendingMode.Normal)] + public void ImageShouldDrawTransformedImage(TestImageProvider provider, PixelColorBlendingMode mode) where TPixel : struct, IPixel { using (Image image = provider.GetImage()) @@ -70,7 +70,7 @@ namespace SixLabors.ImageSharp.Tests new Rectangle(0, 0, destBounds.Width, destBounds.Height))); var position = new Point((image.Width - blend.Width) / 2, (image.Height - blend.Height) / 2); - image.Mutate(x => x.DrawImage(blend, mode, .75F, position)); + image.Mutate(x => x.DrawImage(blend, position, mode, .75F)); image.DebugSave(provider, new[] { "Transformed" }); } } @@ -88,7 +88,7 @@ namespace SixLabors.ImageSharp.Tests Rgba32 backgroundPixel = background[0, 0]; Rgba32 overlayPixel = overlay[Math.Abs(xy) + 1, Math.Abs(xy) + 1]; - background.Mutate(x => x.DrawImage(overlay, PixelBlenderMode.Normal, 1F, new Point(xy, xy))); + background.Mutate(x => x.DrawImage(overlay, new Point(xy, xy), PixelColorBlendingMode.Normal, 1F)); Assert.Equal(Rgba32.White, backgroundPixel); Assert.Equal(overlayPixel, background[0, 0]); @@ -110,7 +110,7 @@ namespace SixLabors.ImageSharp.Tests Rgba32 backgroundPixel = background[xy - 1, xy - 1]; Rgba32 overlayPixel = overlay[0, 0]; - background.Mutate(x => x.DrawImage(overlay, PixelBlenderMode.Normal, 1F, new Point(xy, xy))); + background.Mutate(x => x.DrawImage(overlay, new Point(xy, xy), PixelColorBlendingMode.Normal, 1F)); Assert.Equal(Rgba32.White, backgroundPixel); Assert.Equal(overlayPixel, background[xy, xy]); diff --git a/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs b/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs index 45f1340be9..e86d41f574 100644 --- a/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs @@ -98,38 +98,38 @@ namespace SixLabors.ImageSharp.Tests.Drawing useReferenceOutputFrom: nameof(this.FillRegion)); } - public static readonly TheoryData BlendData = - new TheoryData() + public static readonly TheoryData BlendData = + new TheoryData() { - { false, "Blue", 0.5f, PixelBlenderMode.Normal, 1.0f }, - { false, "Blue", 1.0f, PixelBlenderMode.Normal, 0.5f }, - { false, "Green", 0.5f, PixelBlenderMode.Normal, 0.3f }, - { false, "HotPink", 0.8f, PixelBlenderMode.Normal, 0.8f }, - - { false, "Blue", 0.5f, PixelBlenderMode.Multiply, 1.0f }, - { false, "Blue", 1.0f, PixelBlenderMode.Multiply, 0.5f }, - { false, "Green", 0.5f, PixelBlenderMode.Multiply, 0.3f }, - { false, "HotPink", 0.8f, PixelBlenderMode.Multiply, 0.8f }, - - { false, "Blue", 0.5f, PixelBlenderMode.Add, 1.0f }, - { false, "Blue", 1.0f, PixelBlenderMode.Add, 0.5f }, - { false, "Green", 0.5f, PixelBlenderMode.Add, 0.3f }, - { false, "HotPink", 0.8f, PixelBlenderMode.Add, 0.8f }, - - { true, "Blue", 0.5f, PixelBlenderMode.Normal, 1.0f }, - { true, "Blue", 1.0f, PixelBlenderMode.Normal, 0.5f }, - { true, "Green", 0.5f, PixelBlenderMode.Normal, 0.3f }, - { true, "HotPink", 0.8f, PixelBlenderMode.Normal, 0.8f }, - - { true, "Blue", 0.5f, PixelBlenderMode.Multiply, 1.0f }, - { true, "Blue", 1.0f, PixelBlenderMode.Multiply, 0.5f }, - { true, "Green", 0.5f, PixelBlenderMode.Multiply, 0.3f }, - { true, "HotPink", 0.8f, PixelBlenderMode.Multiply, 0.8f }, - - { true, "Blue", 0.5f, PixelBlenderMode.Add, 1.0f }, - { true, "Blue", 1.0f, PixelBlenderMode.Add, 0.5f }, - { true, "Green", 0.5f, PixelBlenderMode.Add, 0.3f }, - { true, "HotPink", 0.8f, PixelBlenderMode.Add, 0.8f }, + { false, "Blue", 0.5f, PixelColorBlendingMode.Normal, 1.0f }, + { false, "Blue", 1.0f, PixelColorBlendingMode.Normal, 0.5f }, + { false, "Green", 0.5f, PixelColorBlendingMode.Normal, 0.3f }, + { false, "HotPink", 0.8f, PixelColorBlendingMode.Normal, 0.8f }, + + { false, "Blue", 0.5f, PixelColorBlendingMode.Multiply, 1.0f }, + { false, "Blue", 1.0f, PixelColorBlendingMode.Multiply, 0.5f }, + { false, "Green", 0.5f, PixelColorBlendingMode.Multiply, 0.3f }, + { false, "HotPink", 0.8f, PixelColorBlendingMode.Multiply, 0.8f }, + + { false, "Blue", 0.5f, PixelColorBlendingMode.Add, 1.0f }, + { false, "Blue", 1.0f, PixelColorBlendingMode.Add, 0.5f }, + { false, "Green", 0.5f, PixelColorBlendingMode.Add, 0.3f }, + { false, "HotPink", 0.8f, PixelColorBlendingMode.Add, 0.8f }, + + { true, "Blue", 0.5f, PixelColorBlendingMode.Normal, 1.0f }, + { true, "Blue", 1.0f, PixelColorBlendingMode.Normal, 0.5f }, + { true, "Green", 0.5f, PixelColorBlendingMode.Normal, 0.3f }, + { true, "HotPink", 0.8f, PixelColorBlendingMode.Normal, 0.8f }, + + { true, "Blue", 0.5f, PixelColorBlendingMode.Multiply, 1.0f }, + { true, "Blue", 1.0f, PixelColorBlendingMode.Multiply, 0.5f }, + { true, "Green", 0.5f, PixelColorBlendingMode.Multiply, 0.3f }, + { true, "HotPink", 0.8f, PixelColorBlendingMode.Multiply, 0.8f }, + + { true, "Blue", 0.5f, PixelColorBlendingMode.Add, 1.0f }, + { true, "Blue", 1.0f, PixelColorBlendingMode.Add, 0.5f }, + { true, "Green", 0.5f, PixelColorBlendingMode.Add, 0.3f }, + { true, "HotPink", 0.8f, PixelColorBlendingMode.Add, 0.8f }, }; [Theory] @@ -139,7 +139,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing bool triggerFillRegion, string newColorName, float alpha, - PixelBlenderMode blenderMode, + PixelColorBlendingMode blenderMode, float blendPercentage) where TPixel : struct, IPixel { @@ -155,7 +155,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing var options = new GraphicsOptions(false) { - BlenderMode = blenderMode, + ColorBlendingMode = blenderMode, BlendPercentage = blendPercentage }; @@ -185,7 +185,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing appendPixelTypeToFileName: false, appendSourceFileOrDescription: false); - PixelBlender blender = PixelOperations.Instance.GetPixelBlender(blenderMode); + PixelBlender blender = PixelOperations.Instance.GetPixelBlender(blenderMode, PixelAlphaCompositionMode.SrcOver); TPixel expectedPixel = blender.Blend(bgColor, fillColor, blendPercentage); image.ComparePixelBufferTo(expectedPixel); diff --git a/tests/ImageSharp.Tests/Drawing/SolidFillBlendedShapesTests.cs b/tests/ImageSharp.Tests/Drawing/SolidFillBlendedShapesTests.cs index b31a18ac45..a8fb187ced 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidFillBlendedShapesTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidFillBlendedShapesTests.cs @@ -15,14 +15,26 @@ namespace SixLabors.ImageSharp.Tests.Drawing [GroupOutput("Drawing")] public class SolidFillBlendedShapesTests { - public static IEnumerable modes = - ((PixelBlenderMode[])Enum.GetValues(typeof(PixelBlenderMode))).Select(x => new object[] { x }); + public static IEnumerable modes = GetAllModeCombinations(); + + private static IEnumerable GetAllModeCombinations() + { + foreach (var composition in Enum.GetValues(typeof(PixelAlphaCompositionMode))) + { + foreach (var blending in Enum.GetValues(typeof(PixelColorBlendingMode))) + { + yield return new object[] { blending, composition }; + } + } + } + [Theory] [WithBlankImages(nameof(modes), 250, 250, PixelTypes.Rgba32)] public void _1DarkBlueRect_2BlendHotPinkRect( TestImageProvider provider, - PixelBlenderMode mode) + PixelColorBlendingMode blending, + PixelAlphaCompositionMode composition) where TPixel : struct, IPixel { using (Image img = provider.GetImage()) @@ -34,12 +46,12 @@ namespace SixLabors.ImageSharp.Tests.Drawing NamedColors.DarkBlue, new Rectangle(0 * scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY) ) - .Fill(new GraphicsOptions(true) { BlenderMode = mode }, + .Fill(new GraphicsOptions(true) { ColorBlendingMode = blending, AlphaCompositionMode=composition }, NamedColors.HotPink, new Rectangle(20 * scaleX, 0 * scaleY, 30 * scaleX, 100 * scaleY)) ); - VerifyImage(provider, mode, img); + VerifyImage(provider, blending, composition, img); } } @@ -47,7 +59,8 @@ namespace SixLabors.ImageSharp.Tests.Drawing [WithBlankImages(nameof(modes), 250, 250, PixelTypes.Rgba32)] public void _1DarkBlueRect_2BlendHotPinkRect_3BlendTransparentEllipse( TestImageProvider provider, - PixelBlenderMode mode) + PixelColorBlendingMode blending, + PixelAlphaCompositionMode composition) where TPixel : struct, IPixel { using (Image img = provider.GetImage()) @@ -60,17 +73,17 @@ namespace SixLabors.ImageSharp.Tests.Drawing new Rectangle(0 * scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY))); img.Mutate( x => x.Fill( - new GraphicsOptions(true) { BlenderMode = mode }, + new GraphicsOptions(true) { ColorBlendingMode = blending, AlphaCompositionMode = composition }, NamedColors.HotPink, new Rectangle(20 * scaleX, 0 * scaleY, 30 * scaleX, 100 * scaleY))); img.Mutate( x => x.Fill( - new GraphicsOptions(true) { BlenderMode = mode }, + new GraphicsOptions(true) { ColorBlendingMode = blending, AlphaCompositionMode = composition }, NamedColors.Transparent, new Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY)) ); - VerifyImage(provider, mode, img); + VerifyImage(provider, blending, composition, img); } } @@ -78,7 +91,8 @@ namespace SixLabors.ImageSharp.Tests.Drawing [WithBlankImages(nameof(modes), 250, 250, PixelTypes.Rgba32)] public void _1DarkBlueRect_2BlendHotPinkRect_3BlendSemiTransparentRedEllipse( TestImageProvider provider, - PixelBlenderMode mode) + PixelColorBlendingMode blending, + PixelAlphaCompositionMode composition) where TPixel : struct, IPixel { using (Image img = provider.GetImage()) @@ -91,7 +105,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing new Rectangle(0 * scaleX, 40, 100 * scaleX, 20 * scaleY))); img.Mutate( x => x.Fill( - new GraphicsOptions(true) { BlenderMode = mode }, + new GraphicsOptions(true) { ColorBlendingMode = blending, AlphaCompositionMode = composition }, NamedColors.HotPink, new Rectangle(20 * scaleX, 0, 30 * scaleX, 100 * scaleY))); var c = NamedColors.Red.ToVector4(); @@ -101,18 +115,21 @@ namespace SixLabors.ImageSharp.Tests.Drawing img.Mutate( x => x.Fill( - new GraphicsOptions(true) { BlenderMode = mode }, + new GraphicsOptions(true) { ColorBlendingMode = blending, AlphaCompositionMode = composition }, pixel, new Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY)) ); - VerifyImage(provider, mode, img); ; + VerifyImage(provider, blending, composition, img); ; } } [Theory] [WithBlankImages(nameof(modes), 250, 250, PixelTypes.Rgba32)] - public void _1DarkBlueRect_2BlendBlackEllipse(TestImageProvider provider, PixelBlenderMode mode) + public void _1DarkBlueRect_2BlendBlackEllipse( + TestImageProvider provider, + PixelColorBlendingMode blending, + PixelAlphaCompositionMode composition) where TPixel : struct, IPixel { using(Image dstImg = provider.GetImage(), srcImg = provider.GetImage()) @@ -131,28 +148,32 @@ namespace SixLabors.ImageSharp.Tests.Drawing new Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY))); dstImg.Mutate( - x => x.DrawImage(new GraphicsOptions(true) { BlenderMode = mode }, srcImg) + x => x.DrawImage(srcImg, new GraphicsOptions(true) { ColorBlendingMode = blending, AlphaCompositionMode = composition }) ); - VerifyImage(provider, mode, dstImg); + VerifyImage(provider, blending, composition, dstImg); } } - private static void VerifyImage(TestImageProvider provider, PixelBlenderMode mode, Image img) + private static void VerifyImage( + TestImageProvider provider, + PixelColorBlendingMode blending, + PixelAlphaCompositionMode composition, + Image img) where TPixel : struct, IPixel { img.DebugSave( provider, - new { mode }, + new { composition, blending }, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false); - + var comparer = ImageComparer.TolerantPercentage(0.01f, 3); - img.CompareFirstFrameToReferenceOutput(comparer, + img.CompareFirstFrameToReferenceOutput(comparer, provider, - new { mode }, + new { composition, blending }, appendPixelTypeToFileName: false, - appendSourceFileOrDescription: false); + appendSourceFileOrDescription: false); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj index d153ecf50f..5ef8f0111f 100644 --- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj +++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj @@ -1,8 +1,8 @@  - net471;netcoreapp2.0;netcoreapp2.1;net47;net462 + net462;net471;netcoreapp2.1 True - 7.2 + 7.3 full portable True diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs index 120619fb5a..9c3ea90d53 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs @@ -1,47 +1,56 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders -{ - using SixLabors.ImageSharp.PixelFormats; - using SixLabors.ImageSharp.Processing; - - using Xunit; - - public class PorterDuffCompositorTests - { - // TODO: Add other modes to compare. - public static readonly TheoryData CompositingOperators = - new TheoryData - { - PixelBlenderMode.Src, - PixelBlenderMode.Atop, - PixelBlenderMode.Over, - PixelBlenderMode.In, - PixelBlenderMode.Out, - PixelBlenderMode.Dest, - PixelBlenderMode.DestAtop, - PixelBlenderMode.DestOver, - PixelBlenderMode.DestIn, - PixelBlenderMode.DestOut, - PixelBlenderMode.Clear, - PixelBlenderMode.Xor - }; - - [Theory] - [WithFile(TestImages.Png.PDDest, nameof(CompositingOperators), PixelTypes.Rgba32)] - public void PorterDuffOutputIsCorrect(TestImageProvider provider, PixelBlenderMode mode) - { - var srcFile = TestFile.Create(TestImages.Png.PDSrc); - using (Image src = srcFile.CreateImage()) - using (Image dest = provider.GetImage()) - { - using (Image res = dest.Clone(x => x.DrawImage(new GraphicsOptions { BlenderMode = mode }, src))) - { - res.DebugSave(provider, mode.ToString()); - res.CompareToReferenceOutput(provider, mode.ToString()); - } - } - } - } +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders +{ + using SixLabors.ImageSharp.PixelFormats; + using SixLabors.ImageSharp.Processing; + + using Xunit; + + public class PorterDuffCompositorTests + { + // TODO: Add other modes to compare. + public static readonly TheoryData CompositingOperators = + new TheoryData + { + PixelAlphaCompositionMode.Src, + PixelAlphaCompositionMode.SrcAtop, + PixelAlphaCompositionMode.SrcOver, + PixelAlphaCompositionMode.SrcIn, + PixelAlphaCompositionMode.SrcOut, + PixelAlphaCompositionMode.Dest, + PixelAlphaCompositionMode.DestAtop, + PixelAlphaCompositionMode.DestOver, + PixelAlphaCompositionMode.DestIn, + PixelAlphaCompositionMode.DestOut, + PixelAlphaCompositionMode.Clear, + PixelAlphaCompositionMode.Xor + }; + + [Theory] + [WithFile(TestImages.Png.PDDest, nameof(CompositingOperators), PixelTypes.Rgba32)] + public void PorterDuffOutputIsCorrect(TestImageProvider provider, PixelAlphaCompositionMode mode) + { + var srcFile = TestFile.Create(TestImages.Png.PDSrc); + using (Image src = srcFile.CreateImage()) + using (Image dest = provider.GetImage()) + { + GraphicsOptions options = new GraphicsOptions + { + AlphaCompositionMode = mode + }; + + using (Image res = dest.Clone(x => x.DrawImage(src, options))) + { + string combinedMode = mode.ToString(); + + if (combinedMode != "Src" && combinedMode.StartsWith("Src")) combinedMode = combinedMode.Substring(3); + + res.DebugSave(provider, combinedMode); + res.CompareToReferenceOutput(provider, combinedMode); + } + } + } + } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.Blender.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.Blender.cs index 3923a56752..8f574ca169 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.Blender.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.Blender.cs @@ -12,64 +12,36 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.PixelFormats { public class PixelBlenderTests - { - - - public static TheoryData BlenderMappings = new TheoryData() + { + public static TheoryData BlenderMappings = new TheoryData() { - { new TestPixel(), typeof(DefaultPixelBlenders.NormalSrcOver), PixelBlenderMode.Normal }, - { new TestPixel(), typeof(DefaultPixelBlenders.ScreenSrcOver), PixelBlenderMode.Screen }, - { new TestPixel(), typeof(DefaultPixelBlenders.HardLightSrcOver), PixelBlenderMode.HardLight }, - { new TestPixel(), typeof(DefaultPixelBlenders.OverlaySrcOver), PixelBlenderMode.Overlay }, - { new TestPixel(), typeof(DefaultPixelBlenders.DarkenSrcOver), PixelBlenderMode.Darken }, - { new TestPixel(), typeof(DefaultPixelBlenders.LightenSrcOver), PixelBlenderMode.Lighten }, - { new TestPixel(), typeof(DefaultPixelBlenders.AddSrcOver), PixelBlenderMode.Add }, - { new TestPixel(), typeof(DefaultPixelBlenders.SubtractSrcOver), PixelBlenderMode.Subtract }, - { new TestPixel(), typeof(DefaultPixelBlenders.MultiplySrcOver), PixelBlenderMode.Multiply }, - - { new TestPixel(), typeof(DefaultPixelBlenders.NormalSrc), PixelBlenderMode.Src }, - { new TestPixel(), typeof(DefaultPixelBlenders.NormalSrcAtop), PixelBlenderMode.Atop }, - { new TestPixel(), typeof(DefaultPixelBlenders.NormalSrcOver), PixelBlenderMode.Over }, - { new TestPixel(), typeof(DefaultPixelBlenders.NormalSrcIn), PixelBlenderMode.In }, - { new TestPixel(), typeof(DefaultPixelBlenders.NormalSrcOut), PixelBlenderMode.Out }, - { new TestPixel(), typeof(DefaultPixelBlenders.NormalDest), PixelBlenderMode.Dest }, - { new TestPixel(), typeof(DefaultPixelBlenders.NormalDestAtop), PixelBlenderMode.DestAtop }, - { new TestPixel(), typeof(DefaultPixelBlenders.NormalDestOver), PixelBlenderMode.DestOver }, - { new TestPixel(), typeof(DefaultPixelBlenders.NormalDestIn), PixelBlenderMode.DestIn }, - { new TestPixel(), typeof(DefaultPixelBlenders.NormalDestOut), PixelBlenderMode.DestOut }, - { new TestPixel(), typeof(DefaultPixelBlenders.NormalClear), PixelBlenderMode.Clear }, - { new TestPixel(), typeof(DefaultPixelBlenders.NormalXor), PixelBlenderMode.Xor }, - - { new TestPixel(), typeof(DefaultPixelBlenders.NormalSrcOver), PixelBlenderMode.Normal }, - { new TestPixel(), typeof(DefaultPixelBlenders.ScreenSrcOver), PixelBlenderMode.Screen }, - { new TestPixel(), typeof(DefaultPixelBlenders.HardLightSrcOver), PixelBlenderMode.HardLight }, - { new TestPixel(), typeof(DefaultPixelBlenders.OverlaySrcOver), PixelBlenderMode.Overlay }, - { new TestPixel(), typeof(DefaultPixelBlenders.DarkenSrcOver), PixelBlenderMode.Darken }, - { new TestPixel(), typeof(DefaultPixelBlenders.LightenSrcOver), PixelBlenderMode.Lighten }, - { new TestPixel(), typeof(DefaultPixelBlenders.AddSrcOver), PixelBlenderMode.Add }, - { new TestPixel(), typeof(DefaultPixelBlenders.SubtractSrcOver), PixelBlenderMode.Subtract }, - { new TestPixel(), typeof(DefaultPixelBlenders.MultiplySrcOver), PixelBlenderMode.Multiply }, - { new TestPixel(), typeof(DefaultPixelBlenders.NormalSrc), PixelBlenderMode.Src }, - { new TestPixel(), typeof(DefaultPixelBlenders.NormalSrcAtop), PixelBlenderMode.Atop }, - { new TestPixel(), typeof(DefaultPixelBlenders.NormalSrcOver), PixelBlenderMode.Over }, - { new TestPixel(), typeof(DefaultPixelBlenders.NormalSrcIn), PixelBlenderMode.In }, - { new TestPixel(), typeof(DefaultPixelBlenders.NormalSrcOut), PixelBlenderMode.Out }, - { new TestPixel(), typeof(DefaultPixelBlenders.NormalDest), PixelBlenderMode.Dest }, - { new TestPixel(), typeof(DefaultPixelBlenders.NormalDestAtop), PixelBlenderMode.DestAtop }, - { new TestPixel(), typeof(DefaultPixelBlenders.NormalDestOver), PixelBlenderMode.DestOver }, - { new TestPixel(), typeof(DefaultPixelBlenders.NormalDestIn), PixelBlenderMode.DestIn }, - { new TestPixel(), typeof(DefaultPixelBlenders.NormalDestOut), PixelBlenderMode.DestOut }, - { new TestPixel(), typeof(DefaultPixelBlenders.NormalClear), PixelBlenderMode.Clear }, - { new TestPixel(), typeof(DefaultPixelBlenders.NormalXor), PixelBlenderMode.Xor }, - + { new TestPixel(), typeof(DefaultPixelBlenders.NormalSrcOver), PixelColorBlendingMode.Normal }, + { new TestPixel(), typeof(DefaultPixelBlenders.ScreenSrcOver), PixelColorBlendingMode.Screen }, + { new TestPixel(), typeof(DefaultPixelBlenders.HardLightSrcOver), PixelColorBlendingMode.HardLight }, + { new TestPixel(), typeof(DefaultPixelBlenders.OverlaySrcOver), PixelColorBlendingMode.Overlay }, + { new TestPixel(), typeof(DefaultPixelBlenders.DarkenSrcOver), PixelColorBlendingMode.Darken }, + { new TestPixel(), typeof(DefaultPixelBlenders.LightenSrcOver), PixelColorBlendingMode.Lighten }, + { new TestPixel(), typeof(DefaultPixelBlenders.AddSrcOver), PixelColorBlendingMode.Add }, + { new TestPixel(), typeof(DefaultPixelBlenders.SubtractSrcOver), PixelColorBlendingMode.Subtract }, + { new TestPixel(), typeof(DefaultPixelBlenders.MultiplySrcOver), PixelColorBlendingMode.Multiply }, + + { new TestPixel(), typeof(DefaultPixelBlenders.NormalSrcOver), PixelColorBlendingMode.Normal }, + { new TestPixel(), typeof(DefaultPixelBlenders.ScreenSrcOver), PixelColorBlendingMode.Screen }, + { new TestPixel(), typeof(DefaultPixelBlenders.HardLightSrcOver), PixelColorBlendingMode.HardLight }, + { new TestPixel(), typeof(DefaultPixelBlenders.OverlaySrcOver), PixelColorBlendingMode.Overlay }, + { new TestPixel(), typeof(DefaultPixelBlenders.DarkenSrcOver), PixelColorBlendingMode.Darken }, + { new TestPixel(), typeof(DefaultPixelBlenders.LightenSrcOver), PixelColorBlendingMode.Lighten }, + { new TestPixel(), typeof(DefaultPixelBlenders.AddSrcOver), PixelColorBlendingMode.Add }, + { new TestPixel(), typeof(DefaultPixelBlenders.SubtractSrcOver), PixelColorBlendingMode.Subtract }, + { new TestPixel(), typeof(DefaultPixelBlenders.MultiplySrcOver), PixelColorBlendingMode.Multiply }, }; [Theory] [MemberData(nameof(BlenderMappings))] - public void ReturnsCorrectBlender(TestPixel pixel, Type type, PixelBlenderMode mode) + public void ReturnsCorrectBlender(TestPixel pixel, Type type, PixelColorBlendingMode mode) where TPixel : struct, IPixel { - PixelBlender blender = PixelOperations.Instance.GetPixelBlender(mode); + PixelBlender blender = PixelOperations.Instance.GetPixelBlender(mode, PixelAlphaCompositionMode.SrcOver); Assert.IsType(type, blender); } } diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs index e084379ba4..9e41fd94f3 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs @@ -88,6 +88,17 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats where TPixel : struct, IPixel { Assert.NotNull(PixelOperations.Instance); + } + + [Fact] + public void IsOpaqueColor() + { + Assert.True(new GraphicsOptions(true).IsOpaqueColorWithoutBlending(ImageSharp.PixelFormats.Rgba32.Red)); + + Assert.False(new GraphicsOptions(true, 0.5f).IsOpaqueColorWithoutBlending(ImageSharp.PixelFormats.Rgba32.Red)); + Assert.False(new GraphicsOptions(true).IsOpaqueColorWithoutBlending(ImageSharp.PixelFormats.Rgba32.Transparent)); + Assert.False(new GraphicsOptions(true, PixelColorBlendingMode.Lighten, 1).IsOpaqueColorWithoutBlending(ImageSharp.PixelFormats.Rgba32.Red)); + Assert.False(new GraphicsOptions(true, PixelColorBlendingMode.Normal,PixelAlphaCompositionMode.DestOver, 1).IsOpaqueColorWithoutBlending(ImageSharp.PixelFormats.Rgba32.Red)); } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs index ae2b12e87d..d1d2ea0771 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs @@ -73,9 +73,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { PropertyInfo property = typeof(KnownResamplers).GetTypeInfo().GetProperty(name); - if (property == null) + if (property is null) { - throw new Exception("Invalid property name!"); + throw new Exception($"No resampler named '{name}"); } return (IResampler)property.GetValue(null); diff --git a/tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs index 8ec8409add..edc6994e7a 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/AffineTransformTests.cs @@ -228,9 +228,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms { PropertyInfo property = typeof(KnownResamplers).GetTypeInfo().GetProperty(name); - if (property == null) + if (property is null) { - throw new Exception("Invalid property name!"); + throw new Exception($"No resampler named {name}"); } return (IResampler)property.GetValue(null); diff --git a/tests/ImageSharp.Tests/Processing/Transforms/ProjectiveTransformTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/ProjectiveTransformTests.cs index f0a924d270..8cf9dd62f5 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/ProjectiveTransformTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/ProjectiveTransformTests.cs @@ -124,9 +124,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms { PropertyInfo property = typeof(KnownResamplers).GetTypeInfo().GetProperty(name); - if (property == null) + if (property is null) { - throw new Exception("Invalid property name!"); + throw new Exception($"No resampler named {name}"); } return (IResampler)property.GetValue(null); diff --git a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs index 6880486635..a935873670 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs @@ -365,7 +365,7 @@ namespace SixLabors.ImageSharp.Tests if (!File.Exists(referenceOutputFile)) { - throw new Exception("Reference output file missing: " + referenceOutputFile); + throw new System.IO.FileNotFoundException("Reference output file missing: " + referenceOutputFile, referenceOutputFile); } IImageDecoder decoder = TestEnvironment.GetReferenceDecoder(referenceOutputFile); diff --git a/tests/Images/External b/tests/Images/External index 825220cdc4..6a43d335f2 160000 --- a/tests/Images/External +++ b/tests/Images/External @@ -1 +1 @@ -Subproject commit 825220cdc4e9d1b4b3b474c63139e18e1cdb800e +Subproject commit 6a43d335f216d6325a6a9fd8d35942ade12b7c7b