Browse Source

Merge branch 'master' into colorspace-transforms

af/merge-core
James Jackson-South 8 years ago
committed by GitHub
parent
commit
655eaeb118
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .travis.yml
  2. 8
      ImageSharp.sln
  3. 7
      README.md
  4. 5
      appveyor.yml
  5. 9
      run-tests.ps1
  6. 2
      src/ImageSharp.Drawing/Processing/BrushApplicator.cs
  7. 85
      src/ImageSharp.Drawing/Processing/DrawImageExtensions.cs
  8. 70
      src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs
  9. 16
      src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs
  10. 5
      src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs
  11. 22
      src/ImageSharp.Drawing/Processing/TextGraphicsOptions.cs
  12. 2
      src/ImageSharp/Common/Helpers/DebugGuard.cs
  13. 6
      src/ImageSharp/Common/Helpers/Guard.cs
  14. 1
      src/ImageSharp/Formats/Bmp/BmpDecoder.cs
  15. 4
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs
  16. 2
      src/ImageSharp/Formats/Gif/GifEncoderCore.cs
  17. 4
      src/ImageSharp/Formats/Gif/LzwDecoder.cs
  18. 3
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs
  19. 9
      src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs
  20. 4
      src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
  21. 9
      src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs
  22. 4
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  23. 2
      src/ImageSharp/Formats/Png/Zlib/ZlibInflateStream.cs
  24. 113
      src/ImageSharp/GraphicsOptions.cs
  25. 2
      src/ImageSharp/Image.Decode.cs
  26. 6
      src/ImageSharp/ImageExtensions.cs
  27. 9
      src/ImageSharp/ImageFrameCollection.cs
  28. 9
      src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs
  29. 5
      src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs
  30. 7
      src/ImageSharp/MetaData/Profiles/Exif/ExifTagDescriptionAttribute.cs
  31. 10
      src/ImageSharp/MetaData/Profiles/Exif/ExifValue.cs
  32. 6
      src/ImageSharp/MetaData/Profiles/Exif/ExifWriter.cs
  33. 4
      src/ImageSharp/MetaData/Profiles/ICC/Curves/IccCurveSegment.cs
  34. 2
      src/ImageSharp/MetaData/Profiles/ICC/Curves/IccOneDimensionalCurve.cs
  35. 2
      src/ImageSharp/MetaData/Profiles/ICC/Curves/IccResponseCurve.cs
  36. 4
      src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs
  37. 2
      src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs
  38. 6
      src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs
  39. 6
      src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs
  40. 2
      src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs
  41. 3
      src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccClutProcessElement.cs
  42. 3
      src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccCurveSetProcessElement.cs
  43. 2
      src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccMultiProcessElement.cs
  44. 2
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccChromaticityTagDataEntry.cs
  45. 2
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs
  46. 2
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantTableTagDataEntry.cs
  47. 2
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs
  48. 2
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs
  49. 5
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDataTagDataEntry.cs
  50. 2
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDateTimeTagDataEntry.cs
  51. 5
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccFix16ArrayTagDataEntry.cs
  52. 2
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs
  53. 2
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs
  54. 10
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs
  55. 10
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs
  56. 2
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMeasurementTagDataEntry.cs
  57. 5
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiLocalizedUnicodeTagDataEntry.cs
  58. 2
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiProcessElementsTagDataEntry.cs
  59. 3
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceDescTagDataEntry.cs
  60. 3
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccProfileSequenceIdentifierTagDataEntry.cs
  61. 4
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccScreeningTagDataEntry.cs
  62. 5
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccSignatureTagDataEntry.cs
  63. 2
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs
  64. 3
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextTagDataEntry.cs
  65. 3
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUFix16ArrayTagDataEntry.cs
  66. 3
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt16ArrayTagDataEntry.cs
  67. 5
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt32ArrayTagDataEntry.cs
  68. 5
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt64ArrayTagDataEntry.cs
  69. 5
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUInt8ArrayTagDataEntry.cs
  70. 12
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUcrBgTagDataEntry.cs
  71. 5
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccUnknownTagDataEntry.cs
  72. 3
      src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccXyzTagDataEntry.cs
  73. 2
      src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs
  74. 4
      src/ImageSharp/MetaData/Profiles/ICC/Various/IccColorantTableEntry.cs
  75. 7
      src/ImageSharp/MetaData/Profiles/ICC/Various/IccLocalizedString.cs
  76. 3
      src/ImageSharp/MetaData/Profiles/ICC/Various/IccLut.cs
  77. 2
      src/ImageSharp/PixelFormats/ColorBuilder{TPixel}.cs
  78. 63
      src/ImageSharp/PixelFormats/PixelAlphaCompositionMode.cs
  79. 56
      src/ImageSharp/PixelFormats/PixelColorBlendingMode.cs
  80. 265
      src/ImageSharp/PixelFormats/PixelOperations{TPixel}.PixelBenders.cs
  81. 4
      src/ImageSharp/Processing/DefaultInternalImageProcessorContext.cs
  82. 4
      src/ImageSharp/Processing/Processors/Binarization/BinaryOrderedDitherProcessor.cs
  83. 3
      src/ImageSharp/Processing/Processors/Dithering/OrderedDitherPaletteProcessor.cs
  84. 4
      src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessorBase.cs
  85. 2
      src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor.cs
  86. 2
      src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs
  87. 4
      src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs
  88. 6
      src/ImageSharp/Processing/Processors/Quantization/OctreeFrameQuantizer{TPixel}.cs
  89. 2
      src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs
  90. 4
      src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor.cs
  91. 2
      src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs
  92. 2
      src/ImageSharp/Processing/Processors/Transforms/TransformHelpers.cs
  93. 2
      tests/CodeCoverage/CodeCoverage.cmd
  94. 32
      tests/ImageSharp.Tests/Drawing/DrawImageTest.cs
  95. 68
      tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs
  96. 65
      tests/ImageSharp.Tests/Drawing/SolidFillBlendedShapesTests.cs
  97. 4
      tests/ImageSharp.Tests/ImageSharp.Tests.csproj
  98. 101
      tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs
  99. 74
      tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.Blender.cs
  100. 11
      tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs

2
.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

8
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

7
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**:

5
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

9
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"

2
src/ImageSharp.Drawing/Processing/BrushApplicator.cs

@ -28,7 +28,7 @@ namespace SixLabors.ImageSharp.Processing
{
this.Target = target;
this.Options = options;
this.Blender = PixelOperations<TPixel>.Instance.GetPixelBlender(options.BlenderMode);
this.Blender = PixelOperations<TPixel>.Instance.GetPixelBlender(options);
}
/// <summary>

85
src/ImageSharp.Drawing/Processing/DrawImageExtensions.cs

@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.Processing
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, float opacity)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, opacity));
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, Point.Empty, GraphicsOptions.Default.ColorBlendingMode, GraphicsOptions.Default.AlphaCompositionMode, opacity));
/// <summary>
/// Draws the given image together with the current one by blending their pixels.
@ -30,63 +30,92 @@ namespace SixLabors.ImageSharp.Processing
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="blender">The blending mode.</param>
/// <param name="colorBlending">The blending mode.</param>
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, PixelBlenderMode blender, float opacity)
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, PixelColorBlendingMode colorBlending, float opacity)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, opacity, blender));
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, Point.Empty, colorBlending, GraphicsOptions.Default.AlphaCompositionMode, opacity));
/// <summary>
/// Draws the given image together with the current one by blending their pixels.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="options">The options, including the blending type and blending amount.</param>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="colorBlending">The color blending mode.</param>
/// <param name="alphaComposition">The alpha composition mode.</param>
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, Image<TPixel> image)
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, PixelColorBlendingMode colorBlending, PixelAlphaCompositionMode alphaComposition, float opacity)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, options));
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, Point.Empty, colorBlending, alphaComposition, opacity));
/// <summary>
/// Draws the given image together with the current one by blending their pixels.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="options">The options, including the blending type and blending amount.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, Point.Empty, options.ColorBlendingMode, options.AlphaCompositionMode, options.BlendPercentage));
/// <summary>
/// Draws the given image together with the current one by blending their pixels.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
/// <param name="source">The image this method extends.</param>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="location">The location to draw the blended image.</param>
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, float opacity, Point location)
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, Point location, float opacity)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, location, opacity));
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, location, GraphicsOptions.Default.ColorBlendingMode, GraphicsOptions.Default.AlphaCompositionMode, opacity));
/// <summary>
/// Draws the given image together with the current one by blending their pixels.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="image">The image to blend with the currently processing image.</param>
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="blender">The type of bending to apply.</param>
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
/// <param name="source">The image this method extends.</param>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="location">The location to draw the blended image.</param>
/// <param name="colorBlending">The color blending to apply.</param>
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, PixelBlenderMode blender, float opacity, Point location)
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, Point location, PixelColorBlendingMode colorBlending, float opacity)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, location, opacity, blender));
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, location, colorBlending, GraphicsOptions.Default.AlphaCompositionMode, opacity));
/// <summary>
/// Draws the given image together with the current one by blending their pixels.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="options">The options containing the blend mode and opacity.</param>
/// <param name="image">The image to blend with the currently processing image.</param>
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="location">The location to draw the blended image.</param>
/// <param name="colorBlending">The color blending to apply.</param>
/// <param name="alphaComposition">The alpha composition mode.</param>
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, Point location, PixelColorBlendingMode colorBlending, PixelAlphaCompositionMode alphaComposition, float opacity)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, location, colorBlending, alphaComposition, opacity));
/// <summary>
/// Draws the given image together with the current one by blending their pixels.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="location">The location to draw the blended image.</param>
/// <param name="options">The options containing the blend mode and opacity.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, Image<TPixel> image, Point location)
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, Point location, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, location, options));
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, location, options.ColorBlendingMode, options.AlphaCompositionMode, options.BlendPercentage));
}
}

70
src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs

@ -18,80 +18,22 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class DrawImageProcessor<TPixel> : ImageProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
{
/// <summary>
/// Initializes a new instance of the <see cref="DrawImageProcessor{TPixel}"/> class.
/// </summary>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="location">The location to draw the blended image.</param>
/// <param name="colorBlendingMode">The blending mode to use when drawing the image.</param>
/// <param name="alphaCompositionMode">The Alpha blending mode to use when drawing the image.</param>
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
public DrawImageProcessor(Image<TPixel> image, float opacity)
: this(image, Point.Empty, opacity)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DrawImageProcessor{TPixel}"/> class.
/// </summary>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="options">
/// The options containing the opacity of the image to blend and blending mode.
/// Opacity must be between 0 and 1.
/// </param>
public DrawImageProcessor(Image<TPixel> image, GraphicsOptions options)
: this(image, Point.Empty, options)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DrawImageProcessor{TPixel}"/> class.
/// </summary>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="location">The location to draw the blended image.</param>
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
public DrawImageProcessor(Image<TPixel> image, Point location, float opacity)
: this(image, location, opacity, GraphicsOptions.Default.BlenderMode)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DrawImageProcessor{TPixel}"/> class.
/// </summary>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="location">The location to draw the blended image.</param>
/// <param name="options">
/// The options containing the opacity of the image to blend and blending mode.
/// Opacity must be between 0 and 1.
/// </param>
public DrawImageProcessor(Image<TPixel> image, Point location, GraphicsOptions options)
: this(image, location, options.BlendPercentage, options.BlenderMode)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DrawImageProcessor{TPixel}"/> class.
/// </summary>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
/// <param name="blenderMode">The blending mode to use when drawing the image.</param>
public DrawImageProcessor(Image<TPixel> image, float opacity, PixelBlenderMode blenderMode)
: this(image, Point.Empty, opacity, blenderMode)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DrawImageProcessor{TPixel}"/> class.
/// </summary>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="location">The location to draw the blended image.</param>
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
/// <param name="blenderMode">The blending mode to use when drawing the image.</param>
public DrawImageProcessor(Image<TPixel> image, Point location, float opacity, PixelBlenderMode blenderMode)
public DrawImageProcessor(Image<TPixel> 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<TPixel>.Instance.GetPixelBlender(blenderMode);
this.Blender = PixelOperations<TPixel>.Instance.GetPixelBlender(colorBlendingMode, alphaCompositionMode);
this.Location = location;
}

16
src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs

@ -102,14 +102,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
private bool IsSolidBrushWithoutBlending(out SolidBrush<TPixel> solidBrush)
{
solidBrush = this.brush as SolidBrush<TPixel>;
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<TPixel>;
if (solidBrush == null)
{
return false;
}
return this.options.IsOpaqueColorWithoutBlending(solidBrush.Color);
}
}
}

5
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;

22
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.
/// <summary>
/// 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
/// </summary>
public PixelColorBlendingMode ColorBlendingMode { get => this.colorBlendingMode; set => this.colorBlendingMode = value; }
/// <summary>
/// Gets or sets a value indicating the color blending percentage to apply to the drawing operation
/// </summary>
public PixelBlenderMode BlenderMode { get => this.blenderMode; set => this.blenderMode = value; }
public PixelAlphaCompositionMode AlphaCompositionMode { get => this.alphaCompositionMode; set => this.alphaCompositionMode = value; }
/// <summary>
/// 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
};
}

2
src/ImageSharp/Common/Helpers/DebugGuard.cs

@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp
public static void NotNull<T>(T value, string parameterName)
where T : class
{
if (value == null)
if (value is null)
{
throw new ArgumentNullException(parameterName);
}

6
src/ImageSharp/Common/Helpers/Guard.cs

@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp
public static void NotNull<T>(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
/// <exception cref="ArgumentException"><paramref name="value"/> is empty or contains only blanks.</exception>
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
/// <exception cref="ArgumentException"><paramref name="value"/> is empty.</exception>
public static void NotNullOrEmpty<T>(ICollection<T> value, string parameterName)
{
if (value == null)
if (value is null)
{
throw new ArgumentNullException(parameterName);
}

1
src/ImageSharp/Formats/Bmp/BmpDecoder.cs

@ -25,7 +25,6 @@ namespace SixLabors.ImageSharp.Formats.Bmp
{
/// <inheritdoc/>
public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream)
where TPixel : struct, IPixel<TPixel>
{
Guard.NotNull(stream, nameof(stream));

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

@ -377,7 +377,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
ImageFrame<TPixel> currentFrame = null;
ImageFrame<TPixel> 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<TPixel>(this.configuration, imageWidth, imageHeight, this.metaData);
@ -485,7 +485,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
private void RestoreToBackground<TPixel>(ImageFrame<TPixel> frame)
where TPixel : struct, IPixel<TPixel>
{
if (this.restoreArea == null)
if (this.restoreArea is null)
{
return;
}

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

@ -159,7 +159,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
{
foreach (ImageFrame<TPixel> frame in image.Frames)
{
if (quantized == null)
if (quantized is null)
{
quantized = this.quantizer.CreateFrameQuantizer<TPixel>().QuantizeFrame(frame);
}

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

@ -56,9 +56,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// <exception cref="System.ArgumentNullException"><paramref name="stream"/> is null.</exception>
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<int>(MaxStackSize, AllocationOptions.Clean);
this.suffix = memoryAllocator.Allocate<int>(MaxStackSize, AllocationOptions.Clean);

3
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}!");
}

9
src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs

@ -58,13 +58,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
public void LoadAndStretchEdges<TPixel>(IPixelSource<TPixel> source, int sourceX, int sourceY)
where TPixel : struct, IPixel<TPixel>
{
var buffer = source.PixelBuffer as Buffer2D<T>;
if (buffer == null)
if (source.PixelBuffer is Buffer2D<T> buffer)
{
this.LoadAndStretchEdges(buffer, sourceX, sourceY);
}
else
{
throw new InvalidOperationException("LoadAndStretchEdges<TPixels>() is only valid for TPixel == T !");
}
this.LoadAndStretchEdges(buffer, sourceX, sourceY);
}
/// <summary>

4
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;
}

9
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<byte> 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
/// </exception>
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;
}

4
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");
}

2
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();
}

113
src/ImageSharp/GraphicsOptions.cs

@ -21,7 +21,9 @@ namespace SixLabors.ImageSharp
private bool? antialias;
private PixelBlenderMode blenderMode;
private PixelColorBlendingMode colorBlendingMode;
private PixelAlphaCompositionMode alphaCompositionMode;
/// <summary>
/// Initializes a new instance of the <see cref="GraphicsOptions"/> struct.
@ -29,10 +31,62 @@ namespace SixLabors.ImageSharp
/// <param name="enableAntialiasing">If set to <c>true</c> [enable antialiasing].</param>
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;
}
/// <summary>
/// Initializes a new instance of the <see cref="GraphicsOptions"/> struct.
/// </summary>
/// <param name="enableAntialiasing">If set to <c>true</c> [enable antialiasing].</param>
/// <param name="opacity">blending percentage to apply to the drawing operation</param>
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;
}
/// <summary>
/// Initializes a new instance of the <see cref="GraphicsOptions"/> struct.
/// </summary>
/// <param name="enableAntialiasing">If set to <c>true</c> [enable antialiasing].</param>
/// <param name="opacity">blending percentage to apply to the drawing operation</param>
/// <param name="blending">color blending mode to apply to the drawing operation</param>
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;
}
/// <summary>
/// Initializes a new instance of the <see cref="GraphicsOptions"/> struct.
/// </summary>
/// <param name="enableAntialiasing">If set to <c>true</c> [enable antialiasing].</param>
/// <param name="opacity">blending percentage to apply to the drawing operation</param>
/// <param name="blending">color blending mode to apply to the drawing operation</param>
/// <param name="composition">alpha composition mode to apply to the drawing operation</param>
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;
}
/// <summary>
@ -67,12 +121,59 @@ namespace SixLabors.ImageSharp
// some API thought post V1.
/// <summary>
/// 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
/// </summary>
public PixelColorBlendingMode ColorBlendingMode
{
get => this.colorBlendingMode;
set => this.colorBlendingMode = value;
}
/// <summary>
/// Gets or sets a value indicating the alpha composition mode to apply to the drawing operation
/// </summary>
public PixelBlenderMode BlenderMode
public PixelAlphaCompositionMode AlphaCompositionMode
{
get => this.blenderMode;
set => this.blenderMode = value;
get => this.alphaCompositionMode;
set => this.alphaCompositionMode = value;
}
/// <summary>
/// Evaluates if a given SOURCE color can completely replace a BACKDROP color given the current blending and composition settings.
/// </summary>
/// <typeparam name="TPixel">The pixel format</typeparam>
/// <param name="color">the color</param>
/// <returns>true if the color can be considered opaque</returns>
/// <remarks>
/// 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.
/// </remarks>
internal bool IsOpaqueColorWithoutBlending<TPixel>(TPixel color)
where TPixel : struct, IPixel<TPixel>
{
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;
}
}
}

2
src/ImageSharp/Image.Decode.cs

@ -70,7 +70,7 @@ namespace SixLabors.ImageSharp
where TPixel : struct, IPixel<TPixel>
{
IImageDecoder decoder = DiscoverDecoder(stream, config, out IImageFormat format);
if (decoder == null)
if (decoder is null)
{
return (null, null);
}

6
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:");

9
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<TPixel> 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<TPixel>(parent.GetConfiguration(), width, height, backgroundColor));
@ -33,9 +30,7 @@ namespace SixLabors.ImageSharp
internal ImageFrameCollection(Image<TPixel> parent, int width, int height, MemorySource<TPixel> 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<TPixel>(parent.GetConfiguration(), width, height, memorySource));

9
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
/// <returns>The <see cref="T:byte[]"/></returns>
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<ExifValue>();
return;

5
src/ImageSharp/MetaData/Profiles/Exif/ExifReader.cs

@ -76,7 +76,8 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
{
var values = new List<ExifValue>();
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<byte> buffer, uint numberOfComponents)
{
if (buffer == null || buffer.Length == 0)
if (buffer.Length == 0)
{
return null;
}

7
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;
/// <summary>
/// Initializes a new instance of the <see cref="ExifTagDescriptionAttribute"/> 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;
}

10
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
/// <inheritdoc/>
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
/// </exception>
private void CheckValue(object value)
{
if (value == null)
if (value is null)
{
return;
}

6
src/ImageSharp/MetaData/Profiles/Exif/ExifWriter.cs

@ -20,9 +20,9 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Exif
private ExifParts allowedParts;
private IList<ExifValue> values;
private List<int> dataOffsets;
private List<int> ifdIndexes;
private List<int> exifIndexes;
private List<int> gpsIndexes;
private readonly List<int> ifdIndexes;
private readonly List<int> exifIndexes;
private readonly List<int> gpsIndexes;
/// <summary>
/// Initializes a new instance of the <see cref="ExifWriter"/> class.

4
src/ImageSharp/MetaData/Profiles/ICC/Curves/IccCurveSegment.cs

@ -27,7 +27,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/>
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;
}
}
}
}

2
src/ImageSharp/MetaData/Profiles/ICC/Curves/IccOneDimensionalCurve.cs

@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc />
public bool Equals(IccOneDimensionalCurve other)
{
if (other == null)
if (other is null)
{
return false;
}

2
src/ImageSharp/MetaData/Profiles/ICC/Curves/IccResponseCurve.cs

@ -49,7 +49,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/>
public bool Equals(IccResponseCurve other)
{
if (other == null)
if (other is null)
{
return false;
}

4
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
/// <param name="data">The data to read</param>
public IccDataReader(byte[] data)
{
Guard.NotNull(data, nameof(data));
this.data = data;
this.data = data ?? throw new ArgumentNullException(nameof(data));
}
/// <summary>

2
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;
}

6
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);

6
src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs

@ -18,7 +18,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <summary>
/// The byte array to read the ICC profile from
/// </summary>
private byte[] data;
private readonly byte[] data;
/// <summary>
/// The backing file for the <see cref="Entries"/> 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<IccTagDataEntry>();
return;

2
src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs

@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/>
public virtual bool Equals(IccTagDataEntry other)
{
if (other == null)
if (other is null)
{
return false;
}

3
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));
}
/// <summary>

3
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));
}
/// <summary>

2
src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccMultiProcessElement.cs

@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/>
public virtual bool Equals(IccMultiProcessElement other)
{
if (other == null)
if (other is null)
{
return false;
}

2
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");
}

2
src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantOrderTagDataEntry.cs

@ -48,7 +48,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/>
public bool Equals(IccColorantOrderTagDataEntry other)
{
if (other == null)
if (other is null)
{
return false;
}

2
src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccColorantTableTagDataEntry.cs

@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/>
public bool Equals(IccColorantTableTagDataEntry other)
{
if (other == null)
if (other is null)
{
return false;
}

2
src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCrdInfoTagDataEntry.cs

@ -94,7 +94,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/>
public bool Equals(IccCrdInfoTagDataEntry other)
{
if (other == null)
if (other is null)
{
return false;
}

2
src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccCurveTagDataEntry.cs

@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/>
public bool Equals(IccCurveTagDataEntry other)
{
if (other == null)
if (other is null)
{
return false;
}

5
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
/// <inheritdoc/>
public bool Equals(IccDataTagDataEntry other)
{
if (other == null)
if (other is null)
{
return false;
}

2
src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccDateTimeTagDataEntry.cs

@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/>
public bool Equals(IccDateTimeTagDataEntry other)
{
if (other == null)
if (other is null)
{
return false;
}

5
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));
}
/// <summary>
@ -45,7 +44,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/>
public bool Equals(IccFix16ArrayTagDataEntry other)
{
if (other == null)
if (other is null)
{
return false;
}

2
src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs

@ -117,7 +117,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/>
public bool Equals(IccLut16TagDataEntry other)
{
if (other == null)
if (other is null)
{
return false;
}

2
src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs

@ -120,7 +120,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/>
public bool Equals(IccLut8TagDataEntry other)
{
if (other == null)
if (other is null)
{
return false;
}

10
src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutAToBTagDataEntry.cs

@ -153,7 +153,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/>
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;
}

10
src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLutBToATagDataEntry.cs

@ -153,7 +153,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/>
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;
}

2
src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMeasurementTagDataEntry.cs

@ -79,7 +79,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/>
public bool Equals(IccMeasurementTagDataEntry other)
{
if (other == null)
if (other is null)
{
return false;
}

5
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));
}
/// <summary>
@ -47,7 +46,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/>
public bool Equals(IccMultiLocalizedUnicodeTagDataEntry other)
{
if (other == null)
if (other is null)
{
return false;
}

2
src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccMultiProcessElementsTagDataEntry.cs

@ -65,7 +65,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/>
public bool Equals(IccMultiProcessElementsTagDataEntry other)
{
if (other == null)
if (other is null)
{
return false;
}

3
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));
}
/// <summary>

3
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));
}
/// <summary>

4
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));
}
/// <summary>

5
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));
}
/// <summary>
/// Gets the Signature
/// Gets the signature data
/// </summary>
public string SignatureData { get; }

2
src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccTextDescriptionTagDataEntry.cs

@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <returns>The converted entry</returns>
public static explicit operator IccMultiLocalizedUnicodeTagDataEntry(IccTextDescriptionTagDataEntry textEntry)
{
if (textEntry == null)
if (textEntry is null)
{
return null;
}

3
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));
}
/// <summary>

3
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));
}
/// <summary>

3
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));
}
/// <summary>

5
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));
}
/// <summary>
@ -45,7 +44,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/>
public bool Equals(IccUInt32ArrayTagDataEntry other)
{
if (other == null)
if (other is null)
{
return false;
}

5
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));
}
/// <summary>
@ -46,7 +45,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/>
public bool Equals(IccUInt64ArrayTagDataEntry other)
{
if (other == null)
if (other is null)
{
return false;
}

5
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));
}
/// <summary>
@ -45,7 +44,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/>
public bool Equals(IccUInt8ArrayTagDataEntry other)
{
if (other == null)
if (other is null)
{
return false;
}

12
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));
}
/// <summary>
@ -65,7 +61,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/>
public bool Equals(IccUcrBgTagDataEntry other)
{
if (other == null)
if (other is null)
{
return false;
}

5
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));
}
/// <summary>
@ -45,7 +44,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/>
public bool Equals(IccUnknownTagDataEntry other)
{
if (other == null)
if (other is null)
{
return false;
}

3
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));
}
/// <summary>

2
src/ImageSharp/MetaData/Profiles/ICC/Various/IccClut.cs

@ -116,7 +116,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <inheritdoc/>
public bool Equals(IccClut other)
{
if (other == null)
if (other is null)
{
return false;
}

4
src/ImageSharp/MetaData/Profiles/ICC/Various/IccColorantTableEntry.cs

@ -28,9 +28,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <param name="pcs3">Third PCS value</param>
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;

7
src/ImageSharp/MetaData/Profiles/ICC/Various/IccLocalizedString.cs

@ -29,11 +29,8 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <param name="text">The text value of this string</param>
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));
}
/// <summary>

3
src/ImageSharp/MetaData/Profiles/ICC/Various/IccLut.cs

@ -16,8 +16,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <param name="values">The LUT values</param>
public IccLut(float[] values)
{
Guard.NotNull(values, nameof(values));
this.Values = values;
this.Values = values ?? throw new ArgumentNullException(nameof(values));
}
/// <summary>

2
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));
}

63
src/ImageSharp/PixelFormats/PixelBlenderMode.cs → src/ImageSharp/PixelFormats/PixelAlphaCompositionMode.cs

@ -4,55 +4,15 @@
namespace SixLabors.ImageSharp.PixelFormats
{
/// <summary>
/// Enumerates the various blending modes.
/// Enumerates the various alpha composition modes.
/// </summary>
public enum PixelBlenderMode
{
public enum PixelAlphaCompositionMode
{
/// <summary>
/// Default blending mode, also known as "Normal" or "Alpha Blending"
/// </summary>
Normal = 0,
/// <summary>
/// Blends the 2 values by multiplication.
/// </summary>
Multiply,
/// <summary>
/// Blends the 2 values by addition.
/// </summary>
Add,
/// <summary>
/// Blends the 2 values by subtraction.
/// </summary>
Subtract,
/// <summary>
/// Multiplies the complements of the backdrop and source values, then complements the result.
/// </summary>
Screen,
/// <summary>
/// Selects the minimum of the backdrop and source values.
/// </summary>
Darken,
/// <summary>
/// Selects the max of the backdrop and source values.
/// </summary>
Lighten,
/// <summary>
/// Multiplies or screens the values, depending on the backdrop vector values.
/// </summary>
Overlay,
/// <summary>
/// Multiplies or screens the colors, depending on the source value.
/// returns the destination over the source.
/// </summary>
HardLight,
SrcOver = 0,
/// <summary>
/// returns the source colors.
/// </summary>
@ -61,22 +21,17 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <summary>
/// returns the source over the destination.
/// </summary>
Atop,
/// <summary>
/// returns the destination over the source.
/// </summary>
Over,
SrcAtop,
/// <summary>
/// The source where the destination and source overlap.
/// </summary>
In,
SrcIn,
/// <summary>
/// The destination where the destination and source overlap.
/// </summary>
Out,
SrcOut,
/// <summary>
/// The destination where the source does not overlap it.

56
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
{
/// <summary>
/// Enumerates the various color blending modes.
/// </summary>
public enum PixelColorBlendingMode
{
/// <summary>
/// Default blending mode, also known as "Normal" or "Alpha Blending"
/// </summary>
Normal = 0,
/// <summary>
/// Blends the 2 values by multiplication.
/// </summary>
Multiply,
/// <summary>
/// Blends the 2 values by addition.
/// </summary>
Add,
/// <summary>
/// Blends the 2 values by subtraction.
/// </summary>
Subtract,
/// <summary>
/// Multiplies the complements of the backdrop and source values, then complements the result.
/// </summary>
Screen,
/// <summary>
/// Selects the minimum of the backdrop and source values.
/// </summary>
Darken,
/// <summary>
/// Selects the max of the backdrop and source values.
/// </summary>
Lighten,
/// <summary>
/// Multiplies or screens the values, depending on the backdrop vector values.
/// </summary>
Overlay,
/// <summary>
/// Multiplies or screens the colors, depending on the source value.
/// </summary>
HardLight,
}
}

265
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
{
/// <content>
/// Provides access to pixel blenders
/// </content>
public partial class PixelOperations<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Find an instance of the pixel blender.
/// </summary>
/// <param name="mode">The blending mode to apply</param>
/// <returns>A <see cref="PixelBlender{TPixel}"/>.</returns>
internal virtual PixelBlender<TPixel> GetPixelBlender(PixelBlenderMode mode)
{
switch (mode)
{
case PixelBlenderMode.Multiply: return DefaultPixelBlenders<TPixel>.MultiplySrcOver.Instance;
case PixelBlenderMode.Add: return DefaultPixelBlenders<TPixel>.AddSrcOver.Instance;
case PixelBlenderMode.Subtract: return DefaultPixelBlenders<TPixel>.SubtractSrcOver.Instance;
case PixelBlenderMode.Screen: return DefaultPixelBlenders<TPixel>.ScreenSrcOver.Instance;
case PixelBlenderMode.Darken: return DefaultPixelBlenders<TPixel>.DarkenSrcOver.Instance;
case PixelBlenderMode.Lighten: return DefaultPixelBlenders<TPixel>.LightenSrcOver.Instance;
case PixelBlenderMode.Overlay: return DefaultPixelBlenders<TPixel>.OverlaySrcOver.Instance;
case PixelBlenderMode.HardLight: return DefaultPixelBlenders<TPixel>.HardLightSrcOver.Instance;
case PixelBlenderMode.Src: return DefaultPixelBlenders<TPixel>.NormalSrc.Instance;
case PixelBlenderMode.Atop: return DefaultPixelBlenders<TPixel>.NormalSrcAtop.Instance;
case PixelBlenderMode.Over: return DefaultPixelBlenders<TPixel>.NormalSrcOver.Instance;
case PixelBlenderMode.In: return DefaultPixelBlenders<TPixel>.NormalSrcIn.Instance;
case PixelBlenderMode.Out: return DefaultPixelBlenders<TPixel>.NormalSrcOut.Instance;
case PixelBlenderMode.Dest: return DefaultPixelBlenders<TPixel>.NormalDest.Instance;
case PixelBlenderMode.DestAtop: return DefaultPixelBlenders<TPixel>.NormalDestAtop.Instance;
case PixelBlenderMode.DestOver: return DefaultPixelBlenders<TPixel>.NormalDestOver.Instance;
case PixelBlenderMode.DestIn: return DefaultPixelBlenders<TPixel>.NormalDestIn.Instance;
case PixelBlenderMode.DestOut: return DefaultPixelBlenders<TPixel>.NormalDestOut.Instance;
case PixelBlenderMode.Clear: return DefaultPixelBlenders<TPixel>.NormalClear.Instance;
case PixelBlenderMode.Xor: return DefaultPixelBlenders<TPixel>.NormalXor.Instance;
case PixelBlenderMode.Normal:
default:
return DefaultPixelBlenders<TPixel>.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
{
/// <content>
/// Provides access to pixel blenders
/// </content>
public partial class PixelOperations<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Find an instance of the pixel blender.
/// </summary>
/// <param name="options">the blending and composition to apply</param>
/// <returns>A <see cref="PixelBlender{TPixel}"/>.</returns>
internal PixelBlender<TPixel> GetPixelBlender(GraphicsOptions options)
{
return this.GetPixelBlender(options.ColorBlendingMode, options.AlphaCompositionMode);
}
/// <summary>
/// Find an instance of the pixel blender.
/// </summary>
/// <param name="colorMode">The color blending mode to apply</param>
/// <param name="alphaMode">The alpha composition mode to apply</param>
/// <returns>A <see cref="PixelBlender{TPixel}"/>.</returns>
internal virtual PixelBlender<TPixel> GetPixelBlender(PixelColorBlendingMode colorMode, PixelAlphaCompositionMode alphaMode)
{
switch (alphaMode)
{
case PixelAlphaCompositionMode.Clear:
switch (colorMode)
{
case PixelColorBlendingMode.Multiply: return DefaultPixelBlenders<TPixel>.MultiplyClear.Instance;
case PixelColorBlendingMode.Add: return DefaultPixelBlenders<TPixel>.AddClear.Instance;
case PixelColorBlendingMode.Subtract: return DefaultPixelBlenders<TPixel>.SubtractClear.Instance;
case PixelColorBlendingMode.Screen: return DefaultPixelBlenders<TPixel>.ScreenClear.Instance;
case PixelColorBlendingMode.Darken: return DefaultPixelBlenders<TPixel>.DarkenClear.Instance;
case PixelColorBlendingMode.Lighten: return DefaultPixelBlenders<TPixel>.LightenClear.Instance;
case PixelColorBlendingMode.Overlay: return DefaultPixelBlenders<TPixel>.OverlayClear.Instance;
case PixelColorBlendingMode.HardLight: return DefaultPixelBlenders<TPixel>.HardLightClear.Instance;
case PixelColorBlendingMode.Normal:
default: return DefaultPixelBlenders<TPixel>.NormalClear.Instance;
}
case PixelAlphaCompositionMode.Xor:
switch (colorMode)
{
case PixelColorBlendingMode.Multiply: return DefaultPixelBlenders<TPixel>.MultiplyXor.Instance;
case PixelColorBlendingMode.Add: return DefaultPixelBlenders<TPixel>.AddXor.Instance;
case PixelColorBlendingMode.Subtract: return DefaultPixelBlenders<TPixel>.SubtractXor.Instance;
case PixelColorBlendingMode.Screen: return DefaultPixelBlenders<TPixel>.ScreenXor.Instance;
case PixelColorBlendingMode.Darken: return DefaultPixelBlenders<TPixel>.DarkenXor.Instance;
case PixelColorBlendingMode.Lighten: return DefaultPixelBlenders<TPixel>.LightenXor.Instance;
case PixelColorBlendingMode.Overlay: return DefaultPixelBlenders<TPixel>.OverlayXor.Instance;
case PixelColorBlendingMode.HardLight: return DefaultPixelBlenders<TPixel>.HardLightXor.Instance;
case PixelColorBlendingMode.Normal:
default: return DefaultPixelBlenders<TPixel>.NormalXor.Instance;
}
case PixelAlphaCompositionMode.Src:
switch (colorMode)
{
case PixelColorBlendingMode.Multiply: return DefaultPixelBlenders<TPixel>.MultiplySrc.Instance;
case PixelColorBlendingMode.Add: return DefaultPixelBlenders<TPixel>.AddSrc.Instance;
case PixelColorBlendingMode.Subtract: return DefaultPixelBlenders<TPixel>.SubtractSrc.Instance;
case PixelColorBlendingMode.Screen: return DefaultPixelBlenders<TPixel>.ScreenSrc.Instance;
case PixelColorBlendingMode.Darken: return DefaultPixelBlenders<TPixel>.DarkenSrc.Instance;
case PixelColorBlendingMode.Lighten: return DefaultPixelBlenders<TPixel>.LightenSrc.Instance;
case PixelColorBlendingMode.Overlay: return DefaultPixelBlenders<TPixel>.OverlaySrc.Instance;
case PixelColorBlendingMode.HardLight: return DefaultPixelBlenders<TPixel>.HardLightSrc.Instance;
case PixelColorBlendingMode.Normal:
default: return DefaultPixelBlenders<TPixel>.NormalSrc.Instance;
}
case PixelAlphaCompositionMode.SrcAtop:
switch (colorMode)
{
case PixelColorBlendingMode.Multiply: return DefaultPixelBlenders<TPixel>.MultiplySrcAtop.Instance;
case PixelColorBlendingMode.Add: return DefaultPixelBlenders<TPixel>.AddSrcAtop.Instance;
case PixelColorBlendingMode.Subtract: return DefaultPixelBlenders<TPixel>.SubtractSrcAtop.Instance;
case PixelColorBlendingMode.Screen: return DefaultPixelBlenders<TPixel>.ScreenSrcAtop.Instance;
case PixelColorBlendingMode.Darken: return DefaultPixelBlenders<TPixel>.DarkenSrcAtop.Instance;
case PixelColorBlendingMode.Lighten: return DefaultPixelBlenders<TPixel>.LightenSrcAtop.Instance;
case PixelColorBlendingMode.Overlay: return DefaultPixelBlenders<TPixel>.OverlaySrcAtop.Instance;
case PixelColorBlendingMode.HardLight: return DefaultPixelBlenders<TPixel>.HardLightSrcAtop.Instance;
case PixelColorBlendingMode.Normal:
default: return DefaultPixelBlenders<TPixel>.NormalSrcAtop.Instance;
}
case PixelAlphaCompositionMode.SrcIn:
switch (colorMode)
{
case PixelColorBlendingMode.Multiply: return DefaultPixelBlenders<TPixel>.MultiplySrcIn.Instance;
case PixelColorBlendingMode.Add: return DefaultPixelBlenders<TPixel>.AddSrcIn.Instance;
case PixelColorBlendingMode.Subtract: return DefaultPixelBlenders<TPixel>.SubtractSrcIn.Instance;
case PixelColorBlendingMode.Screen: return DefaultPixelBlenders<TPixel>.ScreenSrcIn.Instance;
case PixelColorBlendingMode.Darken: return DefaultPixelBlenders<TPixel>.DarkenSrcIn.Instance;
case PixelColorBlendingMode.Lighten: return DefaultPixelBlenders<TPixel>.LightenSrcIn.Instance;
case PixelColorBlendingMode.Overlay: return DefaultPixelBlenders<TPixel>.OverlaySrcIn.Instance;
case PixelColorBlendingMode.HardLight: return DefaultPixelBlenders<TPixel>.HardLightSrcIn.Instance;
case PixelColorBlendingMode.Normal:
default: return DefaultPixelBlenders<TPixel>.NormalSrcIn.Instance;
}
case PixelAlphaCompositionMode.SrcOut:
switch (colorMode)
{
case PixelColorBlendingMode.Multiply: return DefaultPixelBlenders<TPixel>.MultiplySrcOut.Instance;
case PixelColorBlendingMode.Add: return DefaultPixelBlenders<TPixel>.AddSrcOut.Instance;
case PixelColorBlendingMode.Subtract: return DefaultPixelBlenders<TPixel>.SubtractSrcOut.Instance;
case PixelColorBlendingMode.Screen: return DefaultPixelBlenders<TPixel>.ScreenSrcOut.Instance;
case PixelColorBlendingMode.Darken: return DefaultPixelBlenders<TPixel>.DarkenSrcOut.Instance;
case PixelColorBlendingMode.Lighten: return DefaultPixelBlenders<TPixel>.LightenSrcOut.Instance;
case PixelColorBlendingMode.Overlay: return DefaultPixelBlenders<TPixel>.OverlaySrcOut.Instance;
case PixelColorBlendingMode.HardLight: return DefaultPixelBlenders<TPixel>.HardLightSrcOut.Instance;
case PixelColorBlendingMode.Normal:
default: return DefaultPixelBlenders<TPixel>.NormalSrcOut.Instance;
}
case PixelAlphaCompositionMode.Dest:
switch (colorMode)
{
case PixelColorBlendingMode.Multiply: return DefaultPixelBlenders<TPixel>.MultiplyDest.Instance;
case PixelColorBlendingMode.Add: return DefaultPixelBlenders<TPixel>.AddDest.Instance;
case PixelColorBlendingMode.Subtract: return DefaultPixelBlenders<TPixel>.SubtractDest.Instance;
case PixelColorBlendingMode.Screen: return DefaultPixelBlenders<TPixel>.ScreenDest.Instance;
case PixelColorBlendingMode.Darken: return DefaultPixelBlenders<TPixel>.DarkenDest.Instance;
case PixelColorBlendingMode.Lighten: return DefaultPixelBlenders<TPixel>.LightenDest.Instance;
case PixelColorBlendingMode.Overlay: return DefaultPixelBlenders<TPixel>.OverlayDest.Instance;
case PixelColorBlendingMode.HardLight: return DefaultPixelBlenders<TPixel>.HardLightDest.Instance;
case PixelColorBlendingMode.Normal:
default: return DefaultPixelBlenders<TPixel>.NormalDest.Instance;
}
case PixelAlphaCompositionMode.DestAtop:
switch (colorMode)
{
case PixelColorBlendingMode.Multiply: return DefaultPixelBlenders<TPixel>.MultiplyDestAtop.Instance;
case PixelColorBlendingMode.Add: return DefaultPixelBlenders<TPixel>.AddDestAtop.Instance;
case PixelColorBlendingMode.Subtract: return DefaultPixelBlenders<TPixel>.SubtractDestAtop.Instance;
case PixelColorBlendingMode.Screen: return DefaultPixelBlenders<TPixel>.ScreenDestAtop.Instance;
case PixelColorBlendingMode.Darken: return DefaultPixelBlenders<TPixel>.DarkenDestAtop.Instance;
case PixelColorBlendingMode.Lighten: return DefaultPixelBlenders<TPixel>.LightenDestAtop.Instance;
case PixelColorBlendingMode.Overlay: return DefaultPixelBlenders<TPixel>.OverlayDestAtop.Instance;
case PixelColorBlendingMode.HardLight: return DefaultPixelBlenders<TPixel>.HardLightDestAtop.Instance;
case PixelColorBlendingMode.Normal:
default: return DefaultPixelBlenders<TPixel>.NormalDestAtop.Instance;
}
case PixelAlphaCompositionMode.DestIn:
switch (colorMode)
{
case PixelColorBlendingMode.Multiply: return DefaultPixelBlenders<TPixel>.MultiplyDestIn.Instance;
case PixelColorBlendingMode.Add: return DefaultPixelBlenders<TPixel>.AddDestIn.Instance;
case PixelColorBlendingMode.Subtract: return DefaultPixelBlenders<TPixel>.SubtractDestIn.Instance;
case PixelColorBlendingMode.Screen: return DefaultPixelBlenders<TPixel>.ScreenDestIn.Instance;
case PixelColorBlendingMode.Darken: return DefaultPixelBlenders<TPixel>.DarkenDestIn.Instance;
case PixelColorBlendingMode.Lighten: return DefaultPixelBlenders<TPixel>.LightenDestIn.Instance;
case PixelColorBlendingMode.Overlay: return DefaultPixelBlenders<TPixel>.OverlayDestIn.Instance;
case PixelColorBlendingMode.HardLight: return DefaultPixelBlenders<TPixel>.HardLightDestIn.Instance;
case PixelColorBlendingMode.Normal:
default: return DefaultPixelBlenders<TPixel>.NormalDestIn.Instance;
}
case PixelAlphaCompositionMode.DestOut:
switch (colorMode)
{
case PixelColorBlendingMode.Multiply: return DefaultPixelBlenders<TPixel>.MultiplyDestOut.Instance;
case PixelColorBlendingMode.Add: return DefaultPixelBlenders<TPixel>.AddDestOut.Instance;
case PixelColorBlendingMode.Subtract: return DefaultPixelBlenders<TPixel>.SubtractDestOut.Instance;
case PixelColorBlendingMode.Screen: return DefaultPixelBlenders<TPixel>.ScreenDestOut.Instance;
case PixelColorBlendingMode.Darken: return DefaultPixelBlenders<TPixel>.DarkenDestOut.Instance;
case PixelColorBlendingMode.Lighten: return DefaultPixelBlenders<TPixel>.LightenDestOut.Instance;
case PixelColorBlendingMode.Overlay: return DefaultPixelBlenders<TPixel>.OverlayDestOut.Instance;
case PixelColorBlendingMode.HardLight: return DefaultPixelBlenders<TPixel>.HardLightDestOut.Instance;
case PixelColorBlendingMode.Normal:
default: return DefaultPixelBlenders<TPixel>.NormalDestOut.Instance;
}
case PixelAlphaCompositionMode.DestOver:
switch (colorMode)
{
case PixelColorBlendingMode.Multiply: return DefaultPixelBlenders<TPixel>.MultiplyDestOver.Instance;
case PixelColorBlendingMode.Add: return DefaultPixelBlenders<TPixel>.AddDestOver.Instance;
case PixelColorBlendingMode.Subtract: return DefaultPixelBlenders<TPixel>.SubtractDestOver.Instance;
case PixelColorBlendingMode.Screen: return DefaultPixelBlenders<TPixel>.ScreenDestOver.Instance;
case PixelColorBlendingMode.Darken: return DefaultPixelBlenders<TPixel>.DarkenDestOver.Instance;
case PixelColorBlendingMode.Lighten: return DefaultPixelBlenders<TPixel>.LightenDestOver.Instance;
case PixelColorBlendingMode.Overlay: return DefaultPixelBlenders<TPixel>.OverlayDestOver.Instance;
case PixelColorBlendingMode.HardLight: return DefaultPixelBlenders<TPixel>.HardLightDestOver.Instance;
case PixelColorBlendingMode.Normal:
default: return DefaultPixelBlenders<TPixel>.NormalDestOver.Instance;
}
case PixelAlphaCompositionMode.SrcOver:
default:
switch (colorMode)
{
case PixelColorBlendingMode.Multiply: return DefaultPixelBlenders<TPixel>.MultiplySrcOver.Instance;
case PixelColorBlendingMode.Add: return DefaultPixelBlenders<TPixel>.AddSrcOver.Instance;
case PixelColorBlendingMode.Subtract: return DefaultPixelBlenders<TPixel>.SubtractSrcOver.Instance;
case PixelColorBlendingMode.Screen: return DefaultPixelBlenders<TPixel>.ScreenSrcOver.Instance;
case PixelColorBlendingMode.Darken: return DefaultPixelBlenders<TPixel>.DarkenSrcOver.Instance;
case PixelColorBlendingMode.Lighten: return DefaultPixelBlenders<TPixel>.LightenSrcOver.Instance;
case PixelColorBlendingMode.Overlay: return DefaultPixelBlenders<TPixel>.OverlaySrcOver.Instance;
case PixelColorBlendingMode.HardLight: return DefaultPixelBlenders<TPixel>.HardLightSrcOver.Instance;
case PixelColorBlendingMode.Normal:
default: return DefaultPixelBlenders<TPixel>.NormalSrcOver.Instance;
}
}
}
}
}

4
src/ImageSharp/Processing/DefaultInternalImageProcessorContext.cs

@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Processing
/// <inheritdoc/>
public Image<TPixel> 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
/// <inheritdoc/>
public IImageProcessingContext<TPixel> ApplyProcessor(IImageProcessor<TPixel> 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

4
src/ImageSharp/Processing/Processors/Binarization/BinaryOrderedDitherProcessor.cs

@ -33,9 +33,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
/// <param name="lowerColor">The color to use for pixels that are below the threshold.</param>
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;
}

3
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));
}
/// <summary>

4
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
/// <param name="palette">The palette to select substitute colors from.</param>
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<TPixel>.Instance.ToScaledVector4(this.Palette, this.paletteVector, this.Palette.Length);
}

2
src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor.cs

@ -81,7 +81,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays
amountSpan[i] = this.GraphicsOptions.BlendPercentage;
}
PixelBlender<TPixel> blender = PixelOperations<TPixel>.Instance.GetPixelBlender(this.GraphicsOptions.BlenderMode);
PixelBlender<TPixel> blender = PixelOperations<TPixel>.Instance.GetPixelBlender(this.GraphicsOptions);
ParallelFor.WithConfiguration(
minY,
maxY,

2
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<TPixel>.Instance.GetPixelBlender(options.BlenderMode);
this.blender = PixelOperations<TPixel>.Instance.GetPixelBlender(options);
this.GraphicsOptions = options;
}

4
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<TPixel>.Instance.GetPixelBlender(options.BlenderMode);
this.blender = PixelOperations<TPixel>.Instance.GetPixelBlender(options);
}
/// <summary>
@ -56,7 +56,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays
this.VignetteColor = color;
this.RadiusX = radiusX;
this.RadiusY = radiusY;
this.blender = PixelOperations<TPixel>.Instance.GetPixelBlender(options.BlenderMode);
this.blender = PixelOperations<TPixel>.Instance.GetPixelBlender(options);
this.GraphicsOptions = options;
}

6
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);

2
src/ImageSharp/Processing/Processors/Quantization/WuFrameQuantizer{TPixel}.cs

@ -166,7 +166,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization
/// <inheritdoc/>
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++)

4
src/ImageSharp/Processing/Processors/Transforms/AutoOrientProcessor.cs

@ -73,13 +73,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
/// <returns>The <see cref="OrientationMode"/></returns>
private static OrientationMode GetExifOrientation(Image<TPixel> 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;
}

2
src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs

@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
protected override void AfterImageApply(Image<TPixel> source, Image<TPixel> destination, Rectangle sourceRectangle)
{
ExifProfile profile = destination.MetaData.ExifProfile;
if (profile == null)
if (profile is null)
{
return;
}

2
src/ImageSharp/Processing/Processors/Transforms/TransformHelpers.cs

@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
where TPixel : struct, IPixel<TPixel>
{
ExifProfile profile = image.MetaData.ExifProfile;
if (profile == null)
if (profile is null)
{
return;
}

2
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%

32
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<TPixel>(TestImageProvider<TPixel> 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<TPixel>(TestImageProvider<TPixel> provider, PixelColorBlendingMode mode)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
using (var blend = Image.Load<TPixel>(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<TPixel>(TestImageProvider<TPixel> provider, PixelBlenderMode mode)
[WithFileCollection(nameof(TestFiles), PixelTypes, PixelColorBlendingMode.Normal)]
public void ImageShouldDrawTransformedImage<TPixel>(TestImageProvider<TPixel> provider, PixelColorBlendingMode mode)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> 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]);

68
tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs

@ -98,38 +98,38 @@ namespace SixLabors.ImageSharp.Tests.Drawing
useReferenceOutputFrom: nameof(this.FillRegion));
}
public static readonly TheoryData<bool, string, float, PixelBlenderMode, float> BlendData =
new TheoryData<bool, string, float, PixelBlenderMode, float>()
public static readonly TheoryData<bool, string, float, PixelColorBlendingMode, float> BlendData =
new TheoryData<bool, string, float, PixelColorBlendingMode, float>()
{
{ 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<TPixel>
{
@ -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<TPixel> blender = PixelOperations<TPixel>.Instance.GetPixelBlender(blenderMode);
PixelBlender<TPixel> blender = PixelOperations<TPixel>.Instance.GetPixelBlender(blenderMode, PixelAlphaCompositionMode.SrcOver);
TPixel expectedPixel = blender.Blend(bgColor, fillColor, blendPercentage);
image.ComparePixelBufferTo(expectedPixel);

65
tests/ImageSharp.Tests/Drawing/SolidFillBlendedShapesTests.cs

@ -15,14 +15,26 @@ namespace SixLabors.ImageSharp.Tests.Drawing
[GroupOutput("Drawing")]
public class SolidFillBlendedShapesTests
{
public static IEnumerable<object[]> modes =
((PixelBlenderMode[])Enum.GetValues(typeof(PixelBlenderMode))).Select(x => new object[] { x });
public static IEnumerable<object[]> modes = GetAllModeCombinations();
private static IEnumerable<object[]> 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<TPixel>(
TestImageProvider<TPixel> provider,
PixelBlenderMode mode)
PixelColorBlendingMode blending,
PixelAlphaCompositionMode composition)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> img = provider.GetImage())
@ -34,12 +46,12 @@ namespace SixLabors.ImageSharp.Tests.Drawing
NamedColors<TPixel>.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<TPixel>.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<TPixel>(
TestImageProvider<TPixel> provider,
PixelBlenderMode mode)
PixelColorBlendingMode blending,
PixelAlphaCompositionMode composition)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> 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<TPixel>.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<TPixel>.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<TPixel>(
TestImageProvider<TPixel> provider,
PixelBlenderMode mode)
PixelColorBlendingMode blending,
PixelAlphaCompositionMode composition)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> 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<TPixel>.HotPink,
new Rectangle(20 * scaleX, 0, 30 * scaleX, 100 * scaleY)));
var c = NamedColors<TPixel>.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<TPixel>(TestImageProvider<TPixel> provider, PixelBlenderMode mode)
public void _1DarkBlueRect_2BlendBlackEllipse<TPixel>(
TestImageProvider<TPixel> provider,
PixelColorBlendingMode blending,
PixelAlphaCompositionMode composition)
where TPixel : struct, IPixel<TPixel>
{
using(Image<TPixel> 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<TPixel>(TestImageProvider<TPixel> provider, PixelBlenderMode mode, Image<TPixel> img)
private static void VerifyImage<TPixel>(
TestImageProvider<TPixel> provider,
PixelColorBlendingMode blending,
PixelAlphaCompositionMode composition,
Image<TPixel> img)
where TPixel : struct, IPixel<TPixel>
{
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);
}
}
}

4
tests/ImageSharp.Tests/ImageSharp.Tests.csproj

@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net471;netcoreapp2.0;netcoreapp2.1;net47;net462</TargetFrameworks>
<TargetFrameworks>net462;net471;netcoreapp2.1</TargetFrameworks>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<LangVersion>7.2</LangVersion>
<LangVersion>7.3</LangVersion>
<DebugType Condition="$(codecov) != ''">full</DebugType>
<DebugType Condition="$(codecov) == ''">portable</DebugType>
<DebugSymbols>True</DebugSymbols>

101
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<PixelBlenderMode> CompositingOperators =
new TheoryData<PixelBlenderMode>
{
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<Rgba32> provider, PixelBlenderMode mode)
{
var srcFile = TestFile.Create(TestImages.Png.PDSrc);
using (Image<Rgba32> src = srcFile.CreateImage())
using (Image<Rgba32> dest = provider.GetImage())
{
using (Image<Rgba32> 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<PixelAlphaCompositionMode> CompositingOperators =
new TheoryData<PixelAlphaCompositionMode>
{
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<Rgba32> provider, PixelAlphaCompositionMode mode)
{
var srcFile = TestFile.Create(TestImages.Png.PDSrc);
using (Image<Rgba32> src = srcFile.CreateImage())
using (Image<Rgba32> dest = provider.GetImage())
{
GraphicsOptions options = new GraphicsOptions
{
AlphaCompositionMode = mode
};
using (Image<Rgba32> 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);
}
}
}
}
}

74
tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.Blender.cs

@ -12,64 +12,36 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.PixelFormats
{
public class PixelBlenderTests
{
public static TheoryData<object, Type, PixelBlenderMode> BlenderMappings = new TheoryData<object, Type, PixelBlenderMode>()
{
public static TheoryData<object, Type, PixelColorBlendingMode> BlenderMappings = new TheoryData<object, Type, PixelColorBlendingMode>()
{
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.NormalSrcOver), PixelBlenderMode.Normal },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.ScreenSrcOver), PixelBlenderMode.Screen },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.HardLightSrcOver), PixelBlenderMode.HardLight },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.OverlaySrcOver), PixelBlenderMode.Overlay },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.DarkenSrcOver), PixelBlenderMode.Darken },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.LightenSrcOver), PixelBlenderMode.Lighten },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.AddSrcOver), PixelBlenderMode.Add },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.SubtractSrcOver), PixelBlenderMode.Subtract },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.MultiplySrcOver), PixelBlenderMode.Multiply },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.NormalSrc), PixelBlenderMode.Src },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.NormalSrcAtop), PixelBlenderMode.Atop },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.NormalSrcOver), PixelBlenderMode.Over },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.NormalSrcIn), PixelBlenderMode.In },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.NormalSrcOut), PixelBlenderMode.Out },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.NormalDest), PixelBlenderMode.Dest },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.NormalDestAtop), PixelBlenderMode.DestAtop },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.NormalDestOver), PixelBlenderMode.DestOver },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.NormalDestIn), PixelBlenderMode.DestIn },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.NormalDestOut), PixelBlenderMode.DestOut },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.NormalClear), PixelBlenderMode.Clear },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.NormalXor), PixelBlenderMode.Xor },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.NormalSrcOver), PixelBlenderMode.Normal },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.ScreenSrcOver), PixelBlenderMode.Screen },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.HardLightSrcOver), PixelBlenderMode.HardLight },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.OverlaySrcOver), PixelBlenderMode.Overlay },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.DarkenSrcOver), PixelBlenderMode.Darken },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.LightenSrcOver), PixelBlenderMode.Lighten },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.AddSrcOver), PixelBlenderMode.Add },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.SubtractSrcOver), PixelBlenderMode.Subtract },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.MultiplySrcOver), PixelBlenderMode.Multiply },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.NormalSrc), PixelBlenderMode.Src },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.NormalSrcAtop), PixelBlenderMode.Atop },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.NormalSrcOver), PixelBlenderMode.Over },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.NormalSrcIn), PixelBlenderMode.In },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.NormalSrcOut), PixelBlenderMode.Out },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.NormalDest), PixelBlenderMode.Dest },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.NormalDestAtop), PixelBlenderMode.DestAtop },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.NormalDestOver), PixelBlenderMode.DestOver },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.NormalDestIn), PixelBlenderMode.DestIn },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.NormalDestOut), PixelBlenderMode.DestOut },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.NormalClear), PixelBlenderMode.Clear },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.NormalXor), PixelBlenderMode.Xor },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.NormalSrcOver), PixelColorBlendingMode.Normal },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.ScreenSrcOver), PixelColorBlendingMode.Screen },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.HardLightSrcOver), PixelColorBlendingMode.HardLight },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.OverlaySrcOver), PixelColorBlendingMode.Overlay },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.DarkenSrcOver), PixelColorBlendingMode.Darken },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.LightenSrcOver), PixelColorBlendingMode.Lighten },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.AddSrcOver), PixelColorBlendingMode.Add },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.SubtractSrcOver), PixelColorBlendingMode.Subtract },
{ new TestPixel<Rgba32>(), typeof(DefaultPixelBlenders<Rgba32>.MultiplySrcOver), PixelColorBlendingMode.Multiply },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.NormalSrcOver), PixelColorBlendingMode.Normal },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.ScreenSrcOver), PixelColorBlendingMode.Screen },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.HardLightSrcOver), PixelColorBlendingMode.HardLight },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.OverlaySrcOver), PixelColorBlendingMode.Overlay },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.DarkenSrcOver), PixelColorBlendingMode.Darken },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.LightenSrcOver), PixelColorBlendingMode.Lighten },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.AddSrcOver), PixelColorBlendingMode.Add },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.SubtractSrcOver), PixelColorBlendingMode.Subtract },
{ new TestPixel<RgbaVector>(), typeof(DefaultPixelBlenders<RgbaVector>.MultiplySrcOver), PixelColorBlendingMode.Multiply },
};
[Theory]
[MemberData(nameof(BlenderMappings))]
public void ReturnsCorrectBlender<TPixel>(TestPixel<TPixel> pixel, Type type, PixelBlenderMode mode)
public void ReturnsCorrectBlender<TPixel>(TestPixel<TPixel> pixel, Type type, PixelColorBlendingMode mode)
where TPixel : struct, IPixel<TPixel>
{
PixelBlender<TPixel> blender = PixelOperations<TPixel>.Instance.GetPixelBlender(mode);
PixelBlender<TPixel> blender = PixelOperations<TPixel>.Instance.GetPixelBlender(mode, PixelAlphaCompositionMode.SrcOver);
Assert.IsType(type, blender);
}
}

11
tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs

@ -88,6 +88,17 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
where TPixel : struct, IPixel<TPixel>
{
Assert.NotNull(PixelOperations<TPixel>.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));
}
}

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save