diff --git a/.gitattributes b/.gitattributes
index 38abe0d4a..b9a9ddd4c 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -44,7 +44,7 @@
*.sql text eol=lf
*.svg text eol=lf
*.targets text eol=lf
-*.tt text eol=lf
+*.tt text eol=crlf
*.ttinclude text eol=crlf
*.txt text eol=lf
*.vb text eol=lf
diff --git a/.gitignore b/.gitignore
index 494281897..d8f376a41 100644
--- a/.gitignore
+++ b/.gitignore
@@ -204,8 +204,6 @@ FakesAssemblies/
**/node_modules
**/node_modules/*
-**/Images/ActualOutput
-**/Images/ReferenceOutput
# ASP.NET 5
project.lock.json
@@ -218,7 +216,8 @@ artifacts/
*.csproj.bak
#CodeCoverage
-**/CodeCoverage/*
-docs/
-/samples/AvatarWithRoundedCorner/output
/ImageSharp.Coverage.xml
+
+# Tests
+**/Images/ActualOutput
+**/Images/ReferenceOutput
diff --git a/README.md b/README.md
index a5c3457fa..3c343ad13 100644
--- a/README.md
+++ b/README.md
@@ -118,12 +118,18 @@ Alternatively, you can work from command line and/or with a lightweight editor o
- [Visual Studio Code](https://code.visualstudio.com/) with [C# Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp)
- [.NET Core](https://www.microsoft.com/net/core#linuxubuntu)
-To clone ImageSharp locally, click the "Clone in Windows" button above or run the following git commands:
+To clone ImageSharp locally, click the "Clone in [YOUR_OS]" button above or run the following git commands:
```bash
git clone https://github.com/SixLabors/ImageSharp
```
+If working with Windows please ensure that you have enabled log file paths in git (run as Administrator).
+
+```bash
+git config --system core.longpaths true
+```
+
### Submodules
This repository contains [git submodules](https://blog.github.com/2016-02-01-working-with-submodules/). To add the submodules to the project, navigate to the repository root and type:
diff --git a/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs
index 54b7315b2..889b7b567 100644
--- a/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs
+++ b/src/ImageSharp.Drawing/Processing/Processors/Drawing/DrawImageProcessor.cs
@@ -1,99 +1,99 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System.Buffers;
-using System.Threading.Tasks;
-
-using SixLabors.ImageSharp.Memory;
-using SixLabors.ImageSharp.PixelFormats;
-using SixLabors.Memory;
-using SixLabors.Primitives;
-
-namespace SixLabors.ImageSharp.Processing.Processors.Drawing
-{
- ///
- /// Combines two images together by blending the pixels.
- ///
- public class DrawImageProcessor : IImageProcessor
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The image to blend.
- /// The location to draw the blended image.
- /// The blending mode to use when drawing the image.
- /// The Alpha blending mode to use when drawing the image.
- /// The opacity of the image to blend.
- public DrawImageProcessor(
- Image image,
- Point location,
- PixelColorBlendingMode colorBlendingMode,
- PixelAlphaCompositionMode alphaCompositionMode,
- float opacity)
- {
- this.Image = image;
- this.Location = location;
- this.ColorBlendingMode = colorBlendingMode;
- this.AlphaCompositionMode = alphaCompositionMode;
- this.Opacity = opacity;
- }
-
- ///
- /// Gets the image to blend.
- ///
- public Image Image { get; }
-
- ///
- /// Gets the location to draw the blended image.
- ///
- public Point Location { get; }
-
- ///
- /// Gets the blending mode to use when drawing the image.
- ///
- public PixelColorBlendingMode ColorBlendingMode { get; }
-
- ///
- /// Gets the Alpha blending mode to use when drawing the image.
- ///
- public PixelAlphaCompositionMode AlphaCompositionMode { get; }
-
- ///
- /// Gets the opacity of the image to blend.
- ///
- public float Opacity { get; }
-
- ///
- public IImageProcessor CreatePixelSpecificProcessor()
- where TPixelBg : struct, IPixel
- {
- var visitor = new ProcessorFactoryVisitor(this);
- this.Image.AcceptVisitor(visitor);
- return visitor.Result;
- }
-
- private class ProcessorFactoryVisitor : IImageVisitor
- where TPixelBg : struct, IPixel
- {
- private readonly DrawImageProcessor definition;
-
- public ProcessorFactoryVisitor(DrawImageProcessor definition)
- {
- this.definition = definition;
- }
-
- public IImageProcessor Result { get; private set; }
-
- public void Visit(Image image)
- where TPixelFg : struct, IPixel
- {
- this.Result = new DrawImageProcessor(
- image,
- this.definition.Location,
- this.definition.ColorBlendingMode,
- this.definition.AlphaCompositionMode,
- this.definition.Opacity);
- }
- }
- }
+// Copyright (c) Six Labors and contributors.
+// Licensed under the Apache License, Version 2.0.
+
+using System.Buffers;
+using System.Threading.Tasks;
+
+using SixLabors.ImageSharp.Memory;
+using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.Memory;
+using SixLabors.Primitives;
+
+namespace SixLabors.ImageSharp.Processing.Processors.Drawing
+{
+ ///
+ /// Combines two images together by blending the pixels.
+ ///
+ public class DrawImageProcessor : IImageProcessor
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The image to blend.
+ /// The location to draw the blended image.
+ /// The blending mode to use when drawing the image.
+ /// The Alpha blending mode to use when drawing the image.
+ /// The opacity of the image to blend.
+ public DrawImageProcessor(
+ Image image,
+ Point location,
+ PixelColorBlendingMode colorBlendingMode,
+ PixelAlphaCompositionMode alphaCompositionMode,
+ float opacity)
+ {
+ this.Image = image;
+ this.Location = location;
+ this.ColorBlendingMode = colorBlendingMode;
+ this.AlphaCompositionMode = alphaCompositionMode;
+ this.Opacity = opacity;
+ }
+
+ ///
+ /// Gets the image to blend.
+ ///
+ public Image Image { get; }
+
+ ///
+ /// Gets the location to draw the blended image.
+ ///
+ public Point Location { get; }
+
+ ///
+ /// Gets the blending mode to use when drawing the image.
+ ///
+ public PixelColorBlendingMode ColorBlendingMode { get; }
+
+ ///
+ /// Gets the Alpha blending mode to use when drawing the image.
+ ///
+ public PixelAlphaCompositionMode AlphaCompositionMode { get; }
+
+ ///
+ /// Gets the opacity of the image to blend.
+ ///
+ public float Opacity { get; }
+
+ ///
+ public IImageProcessor CreatePixelSpecificProcessor()
+ where TPixelBg : struct, IPixel
+ {
+ var visitor = new ProcessorFactoryVisitor(this);
+ this.Image.AcceptVisitor(visitor);
+ return visitor.Result;
+ }
+
+ private class ProcessorFactoryVisitor : IImageVisitor
+ where TPixelBg : struct, IPixel
+ {
+ private readonly DrawImageProcessor definition;
+
+ public ProcessorFactoryVisitor(DrawImageProcessor definition)
+ {
+ this.definition = definition;
+ }
+
+ public IImageProcessor Result { get; private set; }
+
+ public void Visit(Image image)
+ where TPixelFg : struct, IPixel
+ {
+ this.Result = new DrawImageProcessor(
+ image,
+ this.definition.Location,
+ this.definition.ColorBlendingMode,
+ this.definition.AlphaCompositionMode,
+ this.definition.Opacity);
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs
index d6254c7cf..0f72a4692 100644
--- a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs
+++ b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor.cs
@@ -1,45 +1,45 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System.Threading.Tasks;
-
-using SixLabors.ImageSharp.PixelFormats;
-using SixLabors.Memory;
-
-namespace SixLabors.ImageSharp.Processing.Processors.Drawing
-{
- ///
- /// Defines a processor to fill an with the given
- /// using blending defined by the given .
- ///
- public class FillProcessor : IImageProcessor
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The brush to use for filling.
- /// The defining how to blend the brush pixels over the image pixels.
- public FillProcessor(IBrush brush, GraphicsOptions options)
- {
- this.Brush = brush;
- this.Options = options;
- }
-
- ///
- /// Gets the used for filling the destination image.
- ///
- public IBrush Brush { get; }
-
- ///
- /// Gets the defining how to blend the brush pixels over the image pixels.
- ///
- public GraphicsOptions Options { get; }
-
- ///
- public IImageProcessor CreatePixelSpecificProcessor()
- where TPixel : struct, IPixel
- {
- return new FillProcessor(this);
- }
- }
+// Copyright (c) Six Labors and contributors.
+// Licensed under the Apache License, Version 2.0.
+
+using System.Threading.Tasks;
+
+using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.Memory;
+
+namespace SixLabors.ImageSharp.Processing.Processors.Drawing
+{
+ ///
+ /// Defines a processor to fill an with the given
+ /// using blending defined by the given .
+ ///
+ public class FillProcessor : IImageProcessor
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The brush to use for filling.
+ /// The defining how to blend the brush pixels over the image pixels.
+ public FillProcessor(IBrush brush, GraphicsOptions options)
+ {
+ this.Brush = brush;
+ this.Options = options;
+ }
+
+ ///
+ /// Gets the used for filling the destination image.
+ ///
+ public IBrush Brush { get; }
+
+ ///
+ /// Gets the defining how to blend the brush pixels over the image pixels.
+ ///
+ public GraphicsOptions Options { get; }
+
+ ///
+ public IImageProcessor CreatePixelSpecificProcessor()
+ where TPixel : struct, IPixel
+ {
+ return new FillProcessor(this);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Processing/TextGraphicsOptions.cs b/src/ImageSharp.Drawing/Processing/TextGraphicsOptions.cs
index 7f7332a57..6c140be72 100644
--- a/src/ImageSharp.Drawing/Processing/TextGraphicsOptions.cs
+++ b/src/ImageSharp.Drawing/Processing/TextGraphicsOptions.cs
@@ -1,163 +1,163 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using SixLabors.Fonts;
-using SixLabors.ImageSharp.PixelFormats;
-
-namespace SixLabors.ImageSharp.Processing
-{
- ///
- /// Options for influencing the drawing functions.
- ///
- public struct TextGraphicsOptions
- {
- private const int DefaultTextDpi = 72;
-
- ///
- /// Represents the default .
- ///
- public static readonly TextGraphicsOptions Default = new TextGraphicsOptions(true);
-
- private float? blendPercentage;
-
- private int? antialiasSubpixelDepth;
-
- private bool? antialias;
-
- private bool? applyKerning;
-
- private float? tabWidth;
-
- private float? dpiX;
-
- private float? dpiY;
-
- private HorizontalAlignment? horizontalAlignment;
-
- private VerticalAlignment? verticalAlignment;
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// If set to true [enable antialiasing].
- public TextGraphicsOptions(bool enableAntialiasing)
- {
- this.applyKerning = true;
- this.tabWidth = 4;
- this.WrapTextWidth = 0;
- this.horizontalAlignment = HorizontalAlignment.Left;
- this.verticalAlignment = VerticalAlignment.Top;
-
- this.antialiasSubpixelDepth = 16;
- this.ColorBlendingMode = PixelColorBlendingMode.Normal;
- this.AlphaCompositionMode = PixelAlphaCompositionMode.SrcOver;
- this.blendPercentage = 1;
- this.antialias = enableAntialiasing;
- this.dpiX = DefaultTextDpi;
- this.dpiY = DefaultTextDpi;
- }
-
- ///
- /// Gets or sets a value indicating whether antialiasing should be applied.
- ///
- public bool Antialias { get => this.antialias ?? true; set => this.antialias = value; }
-
- ///
- /// Gets or sets a value indicating the number of subpixels to use while rendering with antialiasing enabled.
- ///
- public int AntialiasSubpixelDepth { get => this.antialiasSubpixelDepth ?? 16; set => this.antialiasSubpixelDepth = value; }
-
- ///
- /// Gets or sets a value indicating the blending percentage to apply to the drawing operation
- ///
- public float BlendPercentage { get => (this.blendPercentage ?? 1).Clamp(0, 1); set => this.blendPercentage = value; }
-
- // In the future we could expose a PixelBlender directly on here
- // or some forms of PixelBlender factory for each pixel type. Will need
- // some API thought post V1.
-
- ///
- /// Gets or sets a value indicating the color blending percentage to apply to the drawing operation
- ///
- public PixelColorBlendingMode ColorBlendingMode { get; set; }
-
- ///
- /// Gets or sets a value indicating the color blending percentage to apply to the drawing operation
- ///
- public PixelAlphaCompositionMode AlphaCompositionMode { get; set; }
-
- ///
- /// Gets or sets a value indicating whether the text should be drawing with kerning enabled.
- ///
- public bool ApplyKerning { get => this.applyKerning ?? true; set => this.applyKerning = value; }
-
- ///
- /// Gets or sets a value indicating the number of space widths a tab should lock to.
- ///
- public float TabWidth { get => this.tabWidth ?? 4; set => this.tabWidth = value; }
-
- ///
- /// Gets or sets a value indicating if greater than zero determine the width at which text should wrap.
- ///
- public float WrapTextWidth { get; set; }
-
- ///
- /// Gets or sets a value indicating the DPI to render text along the X axis.
- ///
- public float DpiX { get => this.dpiX ?? DefaultTextDpi; set => this.dpiX = value; }
-
- ///
- /// Gets or sets a value indicating the DPI to render text along the Y axis.
- ///
- public float DpiY { get => this.dpiY ?? DefaultTextDpi; set => this.dpiY = value; }
-
- ///
- /// Gets or sets a value indicating how to align the text relative to the rendering space.
- /// If is greater than zero it will align relative to the space
- /// defined by the location and width, if equals zero, and thus
- /// wrapping disabled, then the alignment is relative to the drawing location.
- ///
- public HorizontalAlignment HorizontalAlignment { get => this.horizontalAlignment ?? HorizontalAlignment.Left; set => this.horizontalAlignment = value; }
-
- ///
- /// Gets or sets a value indicating how to align the text relative to the rendering space.
- ///
- public VerticalAlignment VerticalAlignment { get => this.verticalAlignment ?? VerticalAlignment.Top; set => this.verticalAlignment = value; }
-
- ///
- /// Performs an implicit conversion from to .
- ///
- /// The options.
- ///
- /// The result of the conversion.
- ///
- public static implicit operator TextGraphicsOptions(GraphicsOptions options)
- {
- return new TextGraphicsOptions(options.Antialias)
- {
- AntialiasSubpixelDepth = options.AntialiasSubpixelDepth,
- blendPercentage = options.BlendPercentage,
- ColorBlendingMode = options.ColorBlendingMode,
- AlphaCompositionMode = options.AlphaCompositionMode
- };
- }
-
- ///
- /// Performs an explicit conversion from to .
- ///
- /// The options.
- ///
- /// The result of the conversion.
- ///
- public static explicit operator GraphicsOptions(TextGraphicsOptions options)
- {
- return new GraphicsOptions(options.Antialias)
- {
- AntialiasSubpixelDepth = options.AntialiasSubpixelDepth,
- ColorBlendingMode = options.ColorBlendingMode,
- AlphaCompositionMode = options.AlphaCompositionMode,
- BlendPercentage = options.BlendPercentage
- };
- }
- }
+// Copyright (c) Six Labors and contributors.
+// Licensed under the Apache License, Version 2.0.
+
+using SixLabors.Fonts;
+using SixLabors.ImageSharp.PixelFormats;
+
+namespace SixLabors.ImageSharp.Processing
+{
+ ///
+ /// Options for influencing the drawing functions.
+ ///
+ public struct TextGraphicsOptions
+ {
+ private const int DefaultTextDpi = 72;
+
+ ///
+ /// Represents the default .
+ ///
+ public static readonly TextGraphicsOptions Default = new TextGraphicsOptions(true);
+
+ private float? blendPercentage;
+
+ private int? antialiasSubpixelDepth;
+
+ private bool? antialias;
+
+ private bool? applyKerning;
+
+ private float? tabWidth;
+
+ private float? dpiX;
+
+ private float? dpiY;
+
+ private HorizontalAlignment? horizontalAlignment;
+
+ private VerticalAlignment? verticalAlignment;
+
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// If set to true [enable antialiasing].
+ public TextGraphicsOptions(bool enableAntialiasing)
+ {
+ this.applyKerning = true;
+ this.tabWidth = 4;
+ this.WrapTextWidth = 0;
+ this.horizontalAlignment = HorizontalAlignment.Left;
+ this.verticalAlignment = VerticalAlignment.Top;
+
+ this.antialiasSubpixelDepth = 16;
+ this.ColorBlendingMode = PixelColorBlendingMode.Normal;
+ this.AlphaCompositionMode = PixelAlphaCompositionMode.SrcOver;
+ this.blendPercentage = 1;
+ this.antialias = enableAntialiasing;
+ this.dpiX = DefaultTextDpi;
+ this.dpiY = DefaultTextDpi;
+ }
+
+ ///
+ /// Gets or sets a value indicating whether antialiasing should be applied.
+ ///
+ public bool Antialias { get => this.antialias ?? true; set => this.antialias = value; }
+
+ ///
+ /// Gets or sets a value indicating the number of subpixels to use while rendering with antialiasing enabled.
+ ///
+ public int AntialiasSubpixelDepth { get => this.antialiasSubpixelDepth ?? 16; set => this.antialiasSubpixelDepth = value; }
+
+ ///
+ /// Gets or sets a value indicating the blending percentage to apply to the drawing operation
+ ///
+ public float BlendPercentage { get => (this.blendPercentage ?? 1).Clamp(0, 1); set => this.blendPercentage = value; }
+
+ // In the future we could expose a PixelBlender directly on here
+ // or some forms of PixelBlender factory for each pixel type. Will need
+ // some API thought post V1.
+
+ ///
+ /// Gets or sets a value indicating the color blending percentage to apply to the drawing operation
+ ///
+ public PixelColorBlendingMode ColorBlendingMode { get; set; }
+
+ ///
+ /// Gets or sets a value indicating the color blending percentage to apply to the drawing operation
+ ///
+ public PixelAlphaCompositionMode AlphaCompositionMode { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether the text should be drawing with kerning enabled.
+ ///
+ public bool ApplyKerning { get => this.applyKerning ?? true; set => this.applyKerning = value; }
+
+ ///
+ /// Gets or sets a value indicating the number of space widths a tab should lock to.
+ ///
+ public float TabWidth { get => this.tabWidth ?? 4; set => this.tabWidth = value; }
+
+ ///
+ /// Gets or sets a value indicating if greater than zero determine the width at which text should wrap.
+ ///
+ public float WrapTextWidth { get; set; }
+
+ ///
+ /// Gets or sets a value indicating the DPI to render text along the X axis.
+ ///
+ public float DpiX { get => this.dpiX ?? DefaultTextDpi; set => this.dpiX = value; }
+
+ ///
+ /// Gets or sets a value indicating the DPI to render text along the Y axis.
+ ///
+ public float DpiY { get => this.dpiY ?? DefaultTextDpi; set => this.dpiY = value; }
+
+ ///
+ /// Gets or sets a value indicating how to align the text relative to the rendering space.
+ /// If is greater than zero it will align relative to the space
+ /// defined by the location and width, if equals zero, and thus
+ /// wrapping disabled, then the alignment is relative to the drawing location.
+ ///
+ public HorizontalAlignment HorizontalAlignment { get => this.horizontalAlignment ?? HorizontalAlignment.Left; set => this.horizontalAlignment = value; }
+
+ ///
+ /// Gets or sets a value indicating how to align the text relative to the rendering space.
+ ///
+ public VerticalAlignment VerticalAlignment { get => this.verticalAlignment ?? VerticalAlignment.Top; set => this.verticalAlignment = value; }
+
+ ///
+ /// Performs an implicit conversion from to .
+ ///
+ /// The options.
+ ///
+ /// The result of the conversion.
+ ///
+ public static implicit operator TextGraphicsOptions(GraphicsOptions options)
+ {
+ return new TextGraphicsOptions(options.Antialias)
+ {
+ AntialiasSubpixelDepth = options.AntialiasSubpixelDepth,
+ blendPercentage = options.BlendPercentage,
+ ColorBlendingMode = options.ColorBlendingMode,
+ AlphaCompositionMode = options.AlphaCompositionMode
+ };
+ }
+
+ ///
+ /// Performs an explicit conversion from to .
+ ///
+ /// The options.
+ ///
+ /// The result of the conversion.
+ ///
+ public static explicit operator GraphicsOptions(TextGraphicsOptions options)
+ {
+ return new GraphicsOptions(options.Antialias)
+ {
+ AntialiasSubpixelDepth = options.AntialiasSubpixelDepth,
+ ColorBlendingMode = options.ColorBlendingMode,
+ AlphaCompositionMode = options.AlphaCompositionMode,
+ BlendPercentage = options.BlendPercentage
+ };
+ }
+ }
}
\ No newline at end of file
diff --git a/src/ImageSharp/Configuration.cs b/src/ImageSharp/Configuration.cs
index 4e8284c2c..0d44db8d8 100644
--- a/src/ImageSharp/Configuration.cs
+++ b/src/ImageSharp/Configuration.cs
@@ -1,164 +1,164 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using System.Collections.Generic;
-using SixLabors.ImageSharp.Formats;
-using SixLabors.ImageSharp.Formats.Bmp;
-using SixLabors.ImageSharp.Formats.Gif;
-using SixLabors.ImageSharp.Formats.Jpeg;
-using SixLabors.ImageSharp.Formats.Png;
-using SixLabors.ImageSharp.IO;
-using SixLabors.ImageSharp.Processing;
-using SixLabors.Memory;
-
-namespace SixLabors.ImageSharp
-{
- ///
- /// Provides configuration code which allows altering default behaviour or extending the library.
- ///
- public sealed class Configuration
- {
- ///
- /// A lazily initialized configuration default instance.
- ///
- private static readonly Lazy Lazy = new Lazy(CreateDefaultInstance);
-
- private int maxDegreeOfParallelism = Environment.ProcessorCount;
-
- ///
- /// Initializes a new instance of the class.
- ///
- public Configuration()
- {
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// A collection of configuration modules to register
- public Configuration(params IConfigurationModule[] configurationModules)
- {
- if (configurationModules != null)
- {
- foreach (IConfigurationModule p in configurationModules)
- {
- p.Configure(this);
- }
- }
- }
-
- ///
- /// Gets the default instance.
- ///
- public static Configuration Default { get; } = Lazy.Value;
-
- ///
- /// Gets or sets the maximum number of concurrent tasks enabled in ImageSharp algorithms
- /// configured with this instance.
- /// Initialized with by default.
- ///
- public int MaxDegreeOfParallelism
- {
- get => this.maxDegreeOfParallelism;
- set
- {
- if (value <= 0)
- {
- throw new ArgumentOutOfRangeException(nameof(this.MaxDegreeOfParallelism));
- }
-
- this.maxDegreeOfParallelism = value;
- }
- }
-
- ///
- /// Gets the currently registered s.
- ///
- public IEnumerable ImageFormats => this.ImageFormatsManager.ImageFormats;
-
- ///
- /// Gets or sets the position in a stream to use for reading when using a seekable stream as an image data source.
- ///
- public ReadOrigin ReadOrigin { get; set; } = ReadOrigin.Current;
-
- ///
- /// Gets or sets the that is currently in use.
- ///
- public ImageFormatManager ImageFormatsManager { get; set; } = new ImageFormatManager();
-
- ///
- /// Gets or sets the that is currently in use.
- ///
- public MemoryAllocator MemoryAllocator { get; set; } = ArrayPoolMemoryAllocator.CreateDefault();
-
- ///
- /// Gets the maximum header size of all the formats.
- ///
- internal int MaxHeaderSize => this.ImageFormatsManager.MaxHeaderSize;
-
- ///
- /// Gets or sets the filesystem helper for accessing the local file system.
- ///
- internal IFileSystem FileSystem { get; set; } = new LocalFileSystem();
-
- ///
- /// Gets or sets the working buffer size hint for image processors.
- /// The default value is 1MB.
- ///
- ///
- /// Currently only used by Resize.
- ///
- internal int WorkingBufferSizeHintInBytes { get; set; } = 1 * 1024 * 1024;
-
- ///
- /// Gets or sets the image operations provider factory.
- ///
- internal IImageProcessingContextFactory ImageOperationsProvider { get; set; } = new DefaultImageOperationsProviderFactory();
-
- ///
- /// Registers a new format provider.
- ///
- /// The configuration provider to call configure on.
- public void Configure(IConfigurationModule configuration)
- {
- Guard.NotNull(configuration, nameof(configuration));
- configuration.Configure(this);
- }
-
- ///
- /// Creates a shallow copy of the .
- ///
- /// A new configuration instance.
- public Configuration Clone()
- {
- return new Configuration
- {
- MaxDegreeOfParallelism = this.MaxDegreeOfParallelism,
- ImageFormatsManager = this.ImageFormatsManager,
- MemoryAllocator = this.MemoryAllocator,
- ImageOperationsProvider = this.ImageOperationsProvider,
- ReadOrigin = this.ReadOrigin,
- FileSystem = this.FileSystem,
- WorkingBufferSizeHintInBytes = this.WorkingBufferSizeHintInBytes,
- };
- }
-
- ///
- /// Creates the default instance with the following s preregistered:
- ///
- ///
- ///
- /// .
- ///
- /// The default configuration of .
- internal static Configuration CreateDefaultInstance()
- {
- return new Configuration(
- new PngConfigurationModule(),
- new JpegConfigurationModule(),
- new GifConfigurationModule(),
- new BmpConfigurationModule());
- }
- }
+// Copyright (c) Six Labors and contributors.
+// Licensed under the Apache License, Version 2.0.
+
+using System;
+using System.Collections.Generic;
+using SixLabors.ImageSharp.Formats;
+using SixLabors.ImageSharp.Formats.Bmp;
+using SixLabors.ImageSharp.Formats.Gif;
+using SixLabors.ImageSharp.Formats.Jpeg;
+using SixLabors.ImageSharp.Formats.Png;
+using SixLabors.ImageSharp.IO;
+using SixLabors.ImageSharp.Processing;
+using SixLabors.Memory;
+
+namespace SixLabors.ImageSharp
+{
+ ///
+ /// Provides configuration code which allows altering default behaviour or extending the library.
+ ///
+ public sealed class Configuration
+ {
+ ///
+ /// A lazily initialized configuration default instance.
+ ///
+ private static readonly Lazy Lazy = new Lazy(CreateDefaultInstance);
+
+ private int maxDegreeOfParallelism = Environment.ProcessorCount;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public Configuration()
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// A collection of configuration modules to register
+ public Configuration(params IConfigurationModule[] configurationModules)
+ {
+ if (configurationModules != null)
+ {
+ foreach (IConfigurationModule p in configurationModules)
+ {
+ p.Configure(this);
+ }
+ }
+ }
+
+ ///
+ /// Gets the default instance.
+ ///
+ public static Configuration Default { get; } = Lazy.Value;
+
+ ///
+ /// Gets or sets the maximum number of concurrent tasks enabled in ImageSharp algorithms
+ /// configured with this instance.
+ /// Initialized with by default.
+ ///
+ public int MaxDegreeOfParallelism
+ {
+ get => this.maxDegreeOfParallelism;
+ set
+ {
+ if (value <= 0)
+ {
+ throw new ArgumentOutOfRangeException(nameof(this.MaxDegreeOfParallelism));
+ }
+
+ this.maxDegreeOfParallelism = value;
+ }
+ }
+
+ ///
+ /// Gets the currently registered s.
+ ///
+ public IEnumerable ImageFormats => this.ImageFormatsManager.ImageFormats;
+
+ ///
+ /// Gets or sets the position in a stream to use for reading when using a seekable stream as an image data source.
+ ///
+ public ReadOrigin ReadOrigin { get; set; } = ReadOrigin.Current;
+
+ ///
+ /// Gets or sets the that is currently in use.
+ ///
+ public ImageFormatManager ImageFormatsManager { get; set; } = new ImageFormatManager();
+
+ ///
+ /// Gets or sets the that is currently in use.
+ ///
+ public MemoryAllocator MemoryAllocator { get; set; } = ArrayPoolMemoryAllocator.CreateDefault();
+
+ ///
+ /// Gets the maximum header size of all the formats.
+ ///
+ internal int MaxHeaderSize => this.ImageFormatsManager.MaxHeaderSize;
+
+ ///
+ /// Gets or sets the filesystem helper for accessing the local file system.
+ ///
+ internal IFileSystem FileSystem { get; set; } = new LocalFileSystem();
+
+ ///
+ /// Gets or sets the working buffer size hint for image processors.
+ /// The default value is 1MB.
+ ///
+ ///
+ /// Currently only used by Resize.
+ ///
+ internal int WorkingBufferSizeHintInBytes { get; set; } = 1 * 1024 * 1024;
+
+ ///
+ /// Gets or sets the image operations provider factory.
+ ///
+ internal IImageProcessingContextFactory ImageOperationsProvider { get; set; } = new DefaultImageOperationsProviderFactory();
+
+ ///
+ /// Registers a new format provider.
+ ///
+ /// The configuration provider to call configure on.
+ public void Configure(IConfigurationModule configuration)
+ {
+ Guard.NotNull(configuration, nameof(configuration));
+ configuration.Configure(this);
+ }
+
+ ///
+ /// Creates a shallow copy of the .
+ ///
+ /// A new configuration instance.
+ public Configuration Clone()
+ {
+ return new Configuration
+ {
+ MaxDegreeOfParallelism = this.MaxDegreeOfParallelism,
+ ImageFormatsManager = this.ImageFormatsManager,
+ MemoryAllocator = this.MemoryAllocator,
+ ImageOperationsProvider = this.ImageOperationsProvider,
+ ReadOrigin = this.ReadOrigin,
+ FileSystem = this.FileSystem,
+ WorkingBufferSizeHintInBytes = this.WorkingBufferSizeHintInBytes,
+ };
+ }
+
+ ///
+ /// Creates the default instance with the following s preregistered:
+ ///
+ ///
+ ///
+ /// .
+ ///
+ /// The default configuration of .
+ internal static Configuration CreateDefaultInstance()
+ {
+ return new Configuration(
+ new PngConfigurationModule(),
+ new JpegConfigurationModule(),
+ new GifConfigurationModule(),
+ new BmpConfigurationModule());
+ }
+ }
}
\ No newline at end of file
diff --git a/src/ImageSharp/Formats/ImageFormatManager.cs b/src/ImageSharp/Formats/ImageFormatManager.cs
index e62805d47..e34155706 100644
--- a/src/ImageSharp/Formats/ImageFormatManager.cs
+++ b/src/ImageSharp/Formats/ImageFormatManager.cs
@@ -1,201 +1,201 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace SixLabors.ImageSharp.Formats
-{
- ///
- /// Collection of Image Formats to be used in class.
- ///
- public class ImageFormatManager
- {
- ///
- /// Used for locking against as there is no ConcurrentSet type.
- ///
- ///
- private static readonly object HashLock = new object();
-
- ///
- /// The list of supported keyed to mime types.
- ///
- private readonly ConcurrentDictionary mimeTypeEncoders = new ConcurrentDictionary();
-
- ///
- /// The list of supported keyed to mime types.
- ///
- private readonly ConcurrentDictionary mimeTypeDecoders = new ConcurrentDictionary();
-
- ///
- /// The list of supported s.
- ///
- private readonly HashSet imageFormats = new HashSet();
-
- ///
- /// The list of supported s.
- ///
- private ConcurrentBag imageFormatDetectors = new ConcurrentBag();
-
- ///
- /// Initializes a new instance of the class.
- ///
- public ImageFormatManager()
- {
- }
-
- ///
- /// Gets the maximum header size of all the formats.
- ///
- internal int MaxHeaderSize { get; private set; }
-
- ///
- /// Gets the currently registered s.
- ///
- public IEnumerable ImageFormats => this.imageFormats;
-
- ///
- /// Gets the currently registered s.
- ///
- internal IEnumerable FormatDetectors => this.imageFormatDetectors;
-
- ///
- /// Gets the currently registered s.
- ///
- internal IEnumerable> ImageDecoders => this.mimeTypeDecoders;
-
- ///
- /// Gets the currently registered s.
- ///
- internal IEnumerable> ImageEncoders => this.mimeTypeEncoders;
-
- ///
- /// Registers a new format provider.
- ///
- /// The format to register as a known format.
- public void AddImageFormat(IImageFormat format)
- {
- Guard.NotNull(format, nameof(format));
- Guard.NotNull(format.MimeTypes, nameof(format.MimeTypes));
- Guard.NotNull(format.FileExtensions, nameof(format.FileExtensions));
-
- lock (HashLock)
- {
- if (!this.imageFormats.Contains(format))
- {
- this.imageFormats.Add(format);
- }
- }
- }
-
- ///
- /// For the specified file extensions type find the e .
- ///
- /// The extension to discover
- /// The if found otherwise null
- public IImageFormat FindFormatByFileExtension(string extension)
- {
- Guard.NotNullOrWhiteSpace(extension, nameof(extension));
-
- if (extension[0] == '.')
- {
- extension = extension.Substring(1);
- }
-
- return this.imageFormats.FirstOrDefault(x => x.FileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase));
- }
-
- ///
- /// For the specified mime type find the .
- ///
- /// The mime-type to discover
- /// The if found; otherwise null
- public IImageFormat FindFormatByMimeType(string mimeType)
- {
- return this.imageFormats.FirstOrDefault(x => x.MimeTypes.Contains(mimeType, StringComparer.OrdinalIgnoreCase));
- }
-
- ///
- /// Sets a specific image encoder as the encoder for a specific image format.
- ///
- /// The image format to register the encoder for.
- /// The encoder to use,
- public void SetEncoder(IImageFormat imageFormat, IImageEncoder encoder)
- {
- Guard.NotNull(imageFormat, nameof(imageFormat));
- Guard.NotNull(encoder, nameof(encoder));
- this.AddImageFormat(imageFormat);
- this.mimeTypeEncoders.AddOrUpdate(imageFormat, encoder, (s, e) => encoder);
- }
-
- ///
- /// Sets a specific image decoder as the decoder for a specific image format.
- ///
- /// The image format to register the encoder for.
- /// The decoder to use,
- public void SetDecoder(IImageFormat imageFormat, IImageDecoder decoder)
- {
- Guard.NotNull(imageFormat, nameof(imageFormat));
- Guard.NotNull(decoder, nameof(decoder));
- this.AddImageFormat(imageFormat);
- this.mimeTypeDecoders.AddOrUpdate(imageFormat, decoder, (s, e) => decoder);
- }
-
- ///
- /// Removes all the registered image format detectors.
- ///
- public void ClearImageFormatDetectors()
- {
- this.imageFormatDetectors = new ConcurrentBag();
- }
-
- ///
- /// Adds a new detector for detecting mime types.
- ///
- /// The detector to add
- public void AddImageFormatDetector(IImageFormatDetector detector)
- {
- Guard.NotNull(detector, nameof(detector));
- this.imageFormatDetectors.Add(detector);
- this.SetMaxHeaderSize();
- }
-
- ///
- /// For the specified mime type find the decoder.
- ///
- /// The format to discover
- /// The if found otherwise null
- public IImageDecoder FindDecoder(IImageFormat format)
- {
- Guard.NotNull(format, nameof(format));
-
- return this.mimeTypeDecoders.TryGetValue(format, out IImageDecoder decoder)
- ? decoder
- : null;
- }
-
- ///
- /// For the specified mime type find the encoder.
- ///
- /// The format to discover
- /// The if found otherwise null
- public IImageEncoder FindEncoder(IImageFormat format)
- {
- Guard.NotNull(format, nameof(format));
-
- return this.mimeTypeEncoders.TryGetValue(format, out IImageEncoder encoder)
- ? encoder
- : null;
- }
-
- ///
- /// Sets the max header size.
- ///
- private void SetMaxHeaderSize()
- {
- this.MaxHeaderSize = this.imageFormatDetectors.Max(x => x.HeaderSize);
- }
- }
-}
+// Copyright (c) Six Labors and contributors.
+// Licensed under the Apache License, Version 2.0.
+
+using System;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace SixLabors.ImageSharp.Formats
+{
+ ///
+ /// Collection of Image Formats to be used in class.
+ ///
+ public class ImageFormatManager
+ {
+ ///
+ /// Used for locking against as there is no ConcurrentSet type.
+ ///
+ ///
+ private static readonly object HashLock = new object();
+
+ ///
+ /// The list of supported keyed to mime types.
+ ///
+ private readonly ConcurrentDictionary mimeTypeEncoders = new ConcurrentDictionary();
+
+ ///
+ /// The list of supported keyed to mime types.
+ ///
+ private readonly ConcurrentDictionary mimeTypeDecoders = new ConcurrentDictionary();
+
+ ///
+ /// The list of supported s.
+ ///
+ private readonly HashSet imageFormats = new HashSet();
+
+ ///
+ /// The list of supported s.
+ ///
+ private ConcurrentBag imageFormatDetectors = new ConcurrentBag();
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public ImageFormatManager()
+ {
+ }
+
+ ///
+ /// Gets the maximum header size of all the formats.
+ ///
+ internal int MaxHeaderSize { get; private set; }
+
+ ///
+ /// Gets the currently registered s.
+ ///
+ public IEnumerable ImageFormats => this.imageFormats;
+
+ ///
+ /// Gets the currently registered s.
+ ///
+ internal IEnumerable FormatDetectors => this.imageFormatDetectors;
+
+ ///
+ /// Gets the currently registered s.
+ ///
+ internal IEnumerable> ImageDecoders => this.mimeTypeDecoders;
+
+ ///
+ /// Gets the currently registered s.
+ ///
+ internal IEnumerable> ImageEncoders => this.mimeTypeEncoders;
+
+ ///
+ /// Registers a new format provider.
+ ///
+ /// The format to register as a known format.
+ public void AddImageFormat(IImageFormat format)
+ {
+ Guard.NotNull(format, nameof(format));
+ Guard.NotNull(format.MimeTypes, nameof(format.MimeTypes));
+ Guard.NotNull(format.FileExtensions, nameof(format.FileExtensions));
+
+ lock (HashLock)
+ {
+ if (!this.imageFormats.Contains(format))
+ {
+ this.imageFormats.Add(format);
+ }
+ }
+ }
+
+ ///
+ /// For the specified file extensions type find the e .
+ ///
+ /// The extension to discover
+ /// The if found otherwise null
+ public IImageFormat FindFormatByFileExtension(string extension)
+ {
+ Guard.NotNullOrWhiteSpace(extension, nameof(extension));
+
+ if (extension[0] == '.')
+ {
+ extension = extension.Substring(1);
+ }
+
+ return this.imageFormats.FirstOrDefault(x => x.FileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase));
+ }
+
+ ///
+ /// For the specified mime type find the .
+ ///
+ /// The mime-type to discover
+ /// The if found; otherwise null
+ public IImageFormat FindFormatByMimeType(string mimeType)
+ {
+ return this.imageFormats.FirstOrDefault(x => x.MimeTypes.Contains(mimeType, StringComparer.OrdinalIgnoreCase));
+ }
+
+ ///
+ /// Sets a specific image encoder as the encoder for a specific image format.
+ ///
+ /// The image format to register the encoder for.
+ /// The encoder to use,
+ public void SetEncoder(IImageFormat imageFormat, IImageEncoder encoder)
+ {
+ Guard.NotNull(imageFormat, nameof(imageFormat));
+ Guard.NotNull(encoder, nameof(encoder));
+ this.AddImageFormat(imageFormat);
+ this.mimeTypeEncoders.AddOrUpdate(imageFormat, encoder, (s, e) => encoder);
+ }
+
+ ///
+ /// Sets a specific image decoder as the decoder for a specific image format.
+ ///
+ /// The image format to register the encoder for.
+ /// The decoder to use,
+ public void SetDecoder(IImageFormat imageFormat, IImageDecoder decoder)
+ {
+ Guard.NotNull(imageFormat, nameof(imageFormat));
+ Guard.NotNull(decoder, nameof(decoder));
+ this.AddImageFormat(imageFormat);
+ this.mimeTypeDecoders.AddOrUpdate(imageFormat, decoder, (s, e) => decoder);
+ }
+
+ ///
+ /// Removes all the registered image format detectors.
+ ///
+ public void ClearImageFormatDetectors()
+ {
+ this.imageFormatDetectors = new ConcurrentBag();
+ }
+
+ ///
+ /// Adds a new detector for detecting mime types.
+ ///
+ /// The detector to add
+ public void AddImageFormatDetector(IImageFormatDetector detector)
+ {
+ Guard.NotNull(detector, nameof(detector));
+ this.imageFormatDetectors.Add(detector);
+ this.SetMaxHeaderSize();
+ }
+
+ ///
+ /// For the specified mime type find the decoder.
+ ///
+ /// The format to discover
+ /// The if found otherwise null
+ public IImageDecoder FindDecoder(IImageFormat format)
+ {
+ Guard.NotNull(format, nameof(format));
+
+ return this.mimeTypeDecoders.TryGetValue(format, out IImageDecoder decoder)
+ ? decoder
+ : null;
+ }
+
+ ///
+ /// For the specified mime type find the encoder.
+ ///
+ /// The format to discover
+ /// The if found otherwise null
+ public IImageEncoder FindEncoder(IImageFormat format)
+ {
+ Guard.NotNull(format, nameof(format));
+
+ return this.mimeTypeEncoders.TryGetValue(format, out IImageEncoder encoder)
+ ? encoder
+ : null;
+ }
+
+ ///
+ /// Sets the max header size.
+ ///
+ private void SetMaxHeaderSize()
+ {
+ this.MaxHeaderSize = this.imageFormatDetectors.Max(x => x.HeaderSize);
+ }
+ }
+}
diff --git a/src/ImageSharp/Formats/Jpeg/5116.DCT_Filter.pdf b/src/ImageSharp/Formats/Jpeg/5116.DCT_Filter.pdf
index 3423fb315..a5967a02e 100644
Binary files a/src/ImageSharp/Formats/Jpeg/5116.DCT_Filter.pdf and b/src/ImageSharp/Formats/Jpeg/5116.DCT_Filter.pdf differ
diff --git a/src/ImageSharp/Formats/Jpeg/itu-t81.pdf b/src/ImageSharp/Formats/Jpeg/itu-t81.pdf
index 83fba254b..1d57c76c2 100644
Binary files a/src/ImageSharp/Formats/Jpeg/itu-t81.pdf and b/src/ImageSharp/Formats/Jpeg/itu-t81.pdf differ
diff --git a/src/ImageSharp/GraphicsOptions.cs b/src/ImageSharp/GraphicsOptions.cs
index 4d5bf6d51..214b10810 100644
--- a/src/ImageSharp/GraphicsOptions.cs
+++ b/src/ImageSharp/GraphicsOptions.cs
@@ -1,177 +1,177 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using SixLabors.ImageSharp.PixelFormats;
-
-namespace SixLabors.ImageSharp
-{
- ///
- /// Options for influencing the drawing functions.
- ///
- public struct GraphicsOptions
- {
- ///
- /// Represents the default .
- ///
- public static readonly GraphicsOptions Default = new GraphicsOptions(true);
-
- private float? blendPercentage;
-
- private int? antialiasSubpixelDepth;
-
- private bool? antialias;
-
- private PixelColorBlendingMode colorBlendingMode;
-
- private PixelAlphaCompositionMode alphaCompositionMode;
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// If set to true [enable antialiasing].
- public GraphicsOptions(bool enableAntialiasing)
- {
- this.colorBlendingMode = PixelColorBlendingMode.Normal;
- this.alphaCompositionMode = PixelAlphaCompositionMode.SrcOver;
- this.blendPercentage = 1;
- this.antialiasSubpixelDepth = 16;
- this.antialias = enableAntialiasing;
- }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// If set to true [enable antialiasing].
- /// blending percentage to apply to the drawing operation
- public GraphicsOptions(bool enableAntialiasing, float opacity)
- {
- Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity));
-
- this.colorBlendingMode = PixelColorBlendingMode.Normal;
- this.alphaCompositionMode = PixelAlphaCompositionMode.SrcOver;
- this.blendPercentage = opacity;
- this.antialiasSubpixelDepth = 16;
- this.antialias = enableAntialiasing;
- }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// If set to true [enable antialiasing].
- /// blending percentage to apply to the drawing operation
- /// color blending mode to apply to the drawing operation
- public GraphicsOptions(bool enableAntialiasing, PixelColorBlendingMode blending, float opacity)
- {
- Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity));
-
- this.colorBlendingMode = blending;
- this.alphaCompositionMode = PixelAlphaCompositionMode.SrcOver;
- this.blendPercentage = opacity;
- this.antialiasSubpixelDepth = 16;
- this.antialias = enableAntialiasing;
- }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// If set to true [enable antialiasing].
- /// blending percentage to apply to the drawing operation
- /// color blending mode to apply to the drawing operation
- /// alpha composition mode to apply to the drawing operation
- public GraphicsOptions(bool enableAntialiasing, PixelColorBlendingMode blending, PixelAlphaCompositionMode composition, float opacity)
- {
- Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity));
-
- this.colorBlendingMode = blending;
- this.alphaCompositionMode = composition;
- this.blendPercentage = opacity;
- this.antialiasSubpixelDepth = 16;
- this.antialias = enableAntialiasing;
- }
-
- ///
- /// Gets or sets a value indicating whether antialiasing should be applied.
- ///
- public bool Antialias
- {
- get => this.antialias ?? true;
- set => this.antialias = value;
- }
-
- ///
- /// Gets or sets a value indicating the number of subpixels to use while rendering with antialiasing enabled.
- ///
- public int AntialiasSubpixelDepth
- {
- get => this.antialiasSubpixelDepth ?? 16;
- set => this.antialiasSubpixelDepth = value;
- }
-
- ///
- /// Gets or sets a value indicating the blending percentage to apply to the drawing operation
- ///
- public float BlendPercentage
- {
- get => (this.blendPercentage ?? 1).Clamp(0, 1);
- set => this.blendPercentage = value;
- }
-
- // In the future we could expose a PixelBlender directly on here
- // or some forms of PixelBlender factory for each pixel type. Will need
- // some API thought post V1.
-
- ///
- /// Gets or sets a value indicating the color blending mode to apply to the drawing operation
- ///
- public PixelColorBlendingMode ColorBlendingMode
- {
- get => this.colorBlendingMode;
- set => this.colorBlendingMode = value;
- }
-
- ///
- /// Gets or sets a value indicating the alpha composition mode to apply to the drawing operation
- ///
- public PixelAlphaCompositionMode AlphaCompositionMode
- {
- get => this.alphaCompositionMode;
- set => this.alphaCompositionMode = value;
- }
-
- ///
- /// Evaluates if a given SOURCE color can completely replace a BACKDROP color given the current blending and composition settings.
- ///
- /// the color
- /// true if the color can be considered opaque
- ///
- /// Blending and composition is an expensive operation, in some cases, like
- /// filling with a solid color, the blending can be avoided by a plain color replacement.
- /// This method can be useful for such processors to select the fast path.
- ///
- internal bool IsOpaqueColorWithoutBlending(Color color)
- {
- 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;
- }
- }
+// Copyright (c) Six Labors and contributors.
+// Licensed under the Apache License, Version 2.0.
+
+using SixLabors.ImageSharp.PixelFormats;
+
+namespace SixLabors.ImageSharp
+{
+ ///
+ /// Options for influencing the drawing functions.
+ ///
+ public struct GraphicsOptions
+ {
+ ///
+ /// Represents the default .
+ ///
+ public static readonly GraphicsOptions Default = new GraphicsOptions(true);
+
+ private float? blendPercentage;
+
+ private int? antialiasSubpixelDepth;
+
+ private bool? antialias;
+
+ private PixelColorBlendingMode colorBlendingMode;
+
+ private PixelAlphaCompositionMode alphaCompositionMode;
+
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// If set to true [enable antialiasing].
+ public GraphicsOptions(bool enableAntialiasing)
+ {
+ this.colorBlendingMode = PixelColorBlendingMode.Normal;
+ this.alphaCompositionMode = PixelAlphaCompositionMode.SrcOver;
+ this.blendPercentage = 1;
+ this.antialiasSubpixelDepth = 16;
+ this.antialias = enableAntialiasing;
+ }
+
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// If set to true [enable antialiasing].
+ /// blending percentage to apply to the drawing operation
+ public GraphicsOptions(bool enableAntialiasing, float opacity)
+ {
+ Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity));
+
+ this.colorBlendingMode = PixelColorBlendingMode.Normal;
+ this.alphaCompositionMode = PixelAlphaCompositionMode.SrcOver;
+ this.blendPercentage = opacity;
+ this.antialiasSubpixelDepth = 16;
+ this.antialias = enableAntialiasing;
+ }
+
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// If set to true [enable antialiasing].
+ /// blending percentage to apply to the drawing operation
+ /// color blending mode to apply to the drawing operation
+ public GraphicsOptions(bool enableAntialiasing, PixelColorBlendingMode blending, float opacity)
+ {
+ Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity));
+
+ this.colorBlendingMode = blending;
+ this.alphaCompositionMode = PixelAlphaCompositionMode.SrcOver;
+ this.blendPercentage = opacity;
+ this.antialiasSubpixelDepth = 16;
+ this.antialias = enableAntialiasing;
+ }
+
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// If set to true [enable antialiasing].
+ /// blending percentage to apply to the drawing operation
+ /// color blending mode to apply to the drawing operation
+ /// alpha composition mode to apply to the drawing operation
+ public GraphicsOptions(bool enableAntialiasing, PixelColorBlendingMode blending, PixelAlphaCompositionMode composition, float opacity)
+ {
+ Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity));
+
+ this.colorBlendingMode = blending;
+ this.alphaCompositionMode = composition;
+ this.blendPercentage = opacity;
+ this.antialiasSubpixelDepth = 16;
+ this.antialias = enableAntialiasing;
+ }
+
+ ///
+ /// Gets or sets a value indicating whether antialiasing should be applied.
+ ///
+ public bool Antialias
+ {
+ get => this.antialias ?? true;
+ set => this.antialias = value;
+ }
+
+ ///
+ /// Gets or sets a value indicating the number of subpixels to use while rendering with antialiasing enabled.
+ ///
+ public int AntialiasSubpixelDepth
+ {
+ get => this.antialiasSubpixelDepth ?? 16;
+ set => this.antialiasSubpixelDepth = value;
+ }
+
+ ///
+ /// Gets or sets a value indicating the blending percentage to apply to the drawing operation
+ ///
+ public float BlendPercentage
+ {
+ get => (this.blendPercentage ?? 1).Clamp(0, 1);
+ set => this.blendPercentage = value;
+ }
+
+ // In the future we could expose a PixelBlender directly on here
+ // or some forms of PixelBlender factory for each pixel type. Will need
+ // some API thought post V1.
+
+ ///
+ /// Gets or sets a value indicating the color blending mode to apply to the drawing operation
+ ///
+ public PixelColorBlendingMode ColorBlendingMode
+ {
+ get => this.colorBlendingMode;
+ set => this.colorBlendingMode = value;
+ }
+
+ ///
+ /// Gets or sets a value indicating the alpha composition mode to apply to the drawing operation
+ ///
+ public PixelAlphaCompositionMode AlphaCompositionMode
+ {
+ get => this.alphaCompositionMode;
+ set => this.alphaCompositionMode = value;
+ }
+
+ ///
+ /// Evaluates if a given SOURCE color can completely replace a BACKDROP color given the current blending and composition settings.
+ ///
+ /// the color
+ /// true if the color can be considered opaque
+ ///
+ /// Blending and composition is an expensive operation, in some cases, like
+ /// filling with a solid color, the blending can be avoided by a plain color replacement.
+ /// This method can be useful for such processors to select the fast path.
+ ///
+ internal bool IsOpaqueColorWithoutBlending(Color color)
+ {
+ if (this.ColorBlendingMode != PixelColorBlendingMode.Normal)
+ {
+ return false;
+ }
+
+ if (this.AlphaCompositionMode != PixelAlphaCompositionMode.SrcOver &&
+ this.AlphaCompositionMode != PixelAlphaCompositionMode.Src)
+ {
+ return false;
+ }
+
+ if (this.BlendPercentage != 1f)
+ {
+ return false;
+ }
+
+ if (color.ToVector4().W != 1f)
+ {
+ return false;
+ }
+
+ return true;
+ }
+ }
}
\ No newline at end of file
diff --git a/src/ImageSharp/PixelFormats/PixelAlphaCompositionMode.cs b/src/ImageSharp/PixelFormats/PixelAlphaCompositionMode.cs
index 2758a7480..0d182d3c2 100644
--- a/src/ImageSharp/PixelFormats/PixelAlphaCompositionMode.cs
+++ b/src/ImageSharp/PixelFormats/PixelAlphaCompositionMode.cs
@@ -7,12 +7,12 @@ namespace SixLabors.ImageSharp.PixelFormats
/// Enumerates the various alpha composition modes.
///
public enum PixelAlphaCompositionMode
- {
+ {
///
/// returns the destination over the source.
///
- SrcOver = 0,
-
+ SrcOver = 0,
+
///
/// returns the source colors.
///
diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs
index 1d3cb53af..0cf8d6bbb 100644
--- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs
+++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs
@@ -1,3810 +1,3810 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-//
-using System;
-using System.Numerics;
-using System.Buffers;
-
-using SixLabors.ImageSharp.Memory;
-using SixLabors.Memory;
-
-namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders
-{
- ///
- /// Collection of Porter Duff alpha blending functions applying different composition models.
- ///
- ///
- /// These functions are designed to be a general solution for all color cases,
- /// that is, they take in account the alpha value of both the backdrop
- /// and source, and there's no need to alpha-premultiply neither the backdrop
- /// nor the source.
- /// Note there are faster functions for when the backdrop color is known
- /// to be opaque
- ///
- internal static class DefaultPixelBlenders
- where TPixel : struct, IPixel
- {
-
- internal class NormalSrc : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static NormalSrc Instance { get; } = new NormalSrc();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- TPixel dest = default;
- dest.FromScaledVector4(PorterDuffFunctions.NormalSrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
- return dest;
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount)
- {
- amount = amount.Clamp(0, 1);
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.NormalSrc(background[i], source[i], amount);
- }
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount)
- {
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.NormalSrc(background[i], source[i], amount[i].Clamp(0, 1));
- }
- }
- }
-
- internal class MultiplySrc : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static MultiplySrc Instance { get; } = new MultiplySrc();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- TPixel dest = default;
- dest.FromScaledVector4(PorterDuffFunctions.MultiplySrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
- return dest;
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount)
- {
- amount = amount.Clamp(0, 1);
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.MultiplySrc(background[i], source[i], amount);
- }
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount)
- {
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.MultiplySrc(background[i], source[i], amount[i].Clamp(0, 1));
- }
- }
- }
-
- internal class AddSrc : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static AddSrc Instance { get; } = new AddSrc();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- TPixel dest = default;
- dest.FromScaledVector4(PorterDuffFunctions.AddSrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
- return dest;
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount)
- {
- amount = amount.Clamp(0, 1);
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.AddSrc(background[i], source[i], amount);
- }
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount)
- {
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.AddSrc(background[i], source[i], amount[i].Clamp(0, 1));
- }
- }
- }
-
- internal class SubtractSrc : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static SubtractSrc Instance { get; } = new SubtractSrc();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- TPixel dest = default;
- dest.FromScaledVector4(PorterDuffFunctions.SubtractSrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
- return dest;
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount)
- {
- amount = amount.Clamp(0, 1);
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.SubtractSrc(background[i], source[i], amount);
- }
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount)
- {
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.SubtractSrc(background[i], source[i], amount[i].Clamp(0, 1));
- }
- }
- }
-
- internal class ScreenSrc : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static ScreenSrc Instance { get; } = new ScreenSrc();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- TPixel dest = default;
- dest.FromScaledVector4(PorterDuffFunctions.ScreenSrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
- return dest;
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount)
- {
- amount = amount.Clamp(0, 1);
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.ScreenSrc(background[i], source[i], amount);
- }
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount)
- {
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.ScreenSrc(background[i], source[i], amount[i].Clamp(0, 1));
- }
- }
- }
-
- internal class DarkenSrc : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static DarkenSrc Instance { get; } = new DarkenSrc();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- TPixel dest = default;
- dest.FromScaledVector4(PorterDuffFunctions.DarkenSrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
- return dest;
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount)
- {
- amount = amount.Clamp(0, 1);
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.DarkenSrc(background[i], source[i], amount);
- }
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount)
- {
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.DarkenSrc(background[i], source[i], amount[i].Clamp(0, 1));
- }
- }
- }
-
- internal class LightenSrc : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static LightenSrc Instance { get; } = new LightenSrc();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- TPixel dest = default;
- dest.FromScaledVector4(PorterDuffFunctions.LightenSrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
- return dest;
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount)
- {
- amount = amount.Clamp(0, 1);
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.LightenSrc(background[i], source[i], amount);
- }
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount)
- {
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.LightenSrc(background[i], source[i], amount[i].Clamp(0, 1));
- }
- }
- }
-
- internal class OverlaySrc : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static OverlaySrc Instance { get; } = new OverlaySrc();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- TPixel dest = default;
- dest.FromScaledVector4(PorterDuffFunctions.OverlaySrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
- return dest;
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount)
- {
- amount = amount.Clamp(0, 1);
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.OverlaySrc(background[i], source[i], amount);
- }
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount)
- {
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.OverlaySrc(background[i], source[i], amount[i].Clamp(0, 1));
- }
- }
- }
-
- internal class HardLightSrc : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static HardLightSrc Instance { get; } = new HardLightSrc();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- TPixel dest = default;
- dest.FromScaledVector4(PorterDuffFunctions.HardLightSrc(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
- return dest;
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount)
- {
- amount = amount.Clamp(0, 1);
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.HardLightSrc(background[i], source[i], amount);
- }
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount)
- {
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.HardLightSrc(background[i], source[i], amount[i].Clamp(0, 1));
- }
- }
- }
-
- internal class NormalSrcAtop : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static NormalSrcAtop Instance { get; } = new NormalSrcAtop();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- TPixel dest = default;
- dest.FromScaledVector4(PorterDuffFunctions.NormalSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
- return dest;
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount)
- {
- amount = amount.Clamp(0, 1);
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.NormalSrcAtop(background[i], source[i], amount);
- }
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount)
- {
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.NormalSrcAtop(background[i], source[i], amount[i].Clamp(0, 1));
- }
- }
- }
-
- internal class MultiplySrcAtop : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static MultiplySrcAtop Instance { get; } = new MultiplySrcAtop();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- TPixel dest = default;
- dest.FromScaledVector4(PorterDuffFunctions.MultiplySrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
- return dest;
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount)
- {
- amount = amount.Clamp(0, 1);
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.MultiplySrcAtop(background[i], source[i], amount);
- }
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount)
- {
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.MultiplySrcAtop(background[i], source[i], amount[i].Clamp(0, 1));
- }
- }
- }
-
- internal class AddSrcAtop : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static AddSrcAtop Instance { get; } = new AddSrcAtop();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- TPixel dest = default;
- dest.FromScaledVector4(PorterDuffFunctions.AddSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
- return dest;
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount)
- {
- amount = amount.Clamp(0, 1);
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.AddSrcAtop(background[i], source[i], amount);
- }
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount)
- {
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.AddSrcAtop(background[i], source[i], amount[i].Clamp(0, 1));
- }
- }
- }
-
- internal class SubtractSrcAtop : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static SubtractSrcAtop Instance { get; } = new SubtractSrcAtop();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- TPixel dest = default;
- dest.FromScaledVector4(PorterDuffFunctions.SubtractSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
- return dest;
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount)
- {
- amount = amount.Clamp(0, 1);
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.SubtractSrcAtop(background[i], source[i], amount);
- }
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount)
- {
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.SubtractSrcAtop(background[i], source[i], amount[i].Clamp(0, 1));
- }
- }
- }
-
- internal class ScreenSrcAtop : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static ScreenSrcAtop Instance { get; } = new ScreenSrcAtop();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- TPixel dest = default;
- dest.FromScaledVector4(PorterDuffFunctions.ScreenSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
- return dest;
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount)
- {
- amount = amount.Clamp(0, 1);
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.ScreenSrcAtop(background[i], source[i], amount);
- }
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount)
- {
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.ScreenSrcAtop(background[i], source[i], amount[i].Clamp(0, 1));
- }
- }
- }
-
- internal class DarkenSrcAtop : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static DarkenSrcAtop Instance { get; } = new DarkenSrcAtop();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- TPixel dest = default;
- dest.FromScaledVector4(PorterDuffFunctions.DarkenSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
- return dest;
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount)
- {
- amount = amount.Clamp(0, 1);
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.DarkenSrcAtop(background[i], source[i], amount);
- }
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount)
- {
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.DarkenSrcAtop(background[i], source[i], amount[i].Clamp(0, 1));
- }
- }
- }
-
- internal class LightenSrcAtop : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static LightenSrcAtop Instance { get; } = new LightenSrcAtop();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- TPixel dest = default;
- dest.FromScaledVector4(PorterDuffFunctions.LightenSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
- return dest;
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount)
- {
- amount = amount.Clamp(0, 1);
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.LightenSrcAtop(background[i], source[i], amount);
- }
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount)
- {
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.LightenSrcAtop(background[i], source[i], amount[i].Clamp(0, 1));
- }
- }
- }
-
- internal class OverlaySrcAtop : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static OverlaySrcAtop Instance { get; } = new OverlaySrcAtop();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- TPixel dest = default;
- dest.FromScaledVector4(PorterDuffFunctions.OverlaySrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
- return dest;
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount)
- {
- amount = amount.Clamp(0, 1);
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.OverlaySrcAtop(background[i], source[i], amount);
- }
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount)
- {
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.OverlaySrcAtop(background[i], source[i], amount[i].Clamp(0, 1));
- }
- }
- }
-
- internal class HardLightSrcAtop : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static HardLightSrcAtop Instance { get; } = new HardLightSrcAtop();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- TPixel dest = default;
- dest.FromScaledVector4(PorterDuffFunctions.HardLightSrcAtop(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
- return dest;
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount)
- {
- amount = amount.Clamp(0, 1);
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.HardLightSrcAtop(background[i], source[i], amount);
- }
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount)
- {
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.HardLightSrcAtop(background[i], source[i], amount[i].Clamp(0, 1));
- }
- }
- }
-
- internal class NormalSrcOver : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static NormalSrcOver Instance { get; } = new NormalSrcOver();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- TPixel dest = default;
- dest.FromScaledVector4(PorterDuffFunctions.NormalSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
- return dest;
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount)
- {
- amount = amount.Clamp(0, 1);
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.NormalSrcOver(background[i], source[i], amount);
- }
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount)
- {
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.NormalSrcOver(background[i], source[i], amount[i].Clamp(0, 1));
- }
- }
- }
-
- internal class MultiplySrcOver : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static MultiplySrcOver Instance { get; } = new MultiplySrcOver();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- TPixel dest = default;
- dest.FromScaledVector4(PorterDuffFunctions.MultiplySrcOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
- return dest;
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount)
- {
- amount = amount.Clamp(0, 1);
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.MultiplySrcOver(background[i], source[i], amount);
- }
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount)
- {
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.MultiplySrcOver(background[i], source[i], amount[i].Clamp(0, 1));
- }
- }
- }
-
- internal class AddSrcOver : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static AddSrcOver Instance { get; } = new AddSrcOver();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- TPixel dest = default;
- dest.FromScaledVector4(PorterDuffFunctions.AddSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
- return dest;
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount)
- {
- amount = amount.Clamp(0, 1);
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.AddSrcOver(background[i], source[i], amount);
- }
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount)
- {
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.AddSrcOver(background[i], source[i], amount[i].Clamp(0, 1));
- }
- }
- }
-
- internal class SubtractSrcOver : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static SubtractSrcOver Instance { get; } = new SubtractSrcOver();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- TPixel dest = default;
- dest.FromScaledVector4(PorterDuffFunctions.SubtractSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
- return dest;
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount)
- {
- amount = amount.Clamp(0, 1);
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.SubtractSrcOver(background[i], source[i], amount);
- }
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount)
- {
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.SubtractSrcOver(background[i], source[i], amount[i].Clamp(0, 1));
- }
- }
- }
-
- internal class ScreenSrcOver : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static ScreenSrcOver Instance { get; } = new ScreenSrcOver();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- TPixel dest = default;
- dest.FromScaledVector4(PorterDuffFunctions.ScreenSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
- return dest;
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, float amount)
- {
- amount = amount.Clamp(0, 1);
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.ScreenSrcOver(background[i], source[i], amount);
- }
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan background, ReadOnlySpan source, ReadOnlySpan amount)
- {
- for (int i = 0; i < destination.Length; i++)
- {
- destination[i] = PorterDuffFunctions.ScreenSrcOver(background[i], source[i], amount[i].Clamp(0, 1));
- }
- }
- }
-
- internal class DarkenSrcOver : PixelBlender
- {
- ///
- /// Gets the static instance of this blender.
- ///
- public static DarkenSrcOver Instance { get; } = new DarkenSrcOver();
-
- ///
- public override TPixel Blend(TPixel background, TPixel source, float amount)
- {
- TPixel dest = default;
- dest.FromScaledVector4(PorterDuffFunctions.DarkenSrcOver(background.ToScaledVector4(), source.ToScaledVector4(), amount.Clamp(0, 1)));
- return dest;
- }
-
- ///
- protected override void BlendFunction(Span destination, ReadOnlySpan