diff --git a/.editorconfig b/.editorconfig
index c3fb970c3b..fa43757a9f 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -6,7 +6,7 @@ indent_style = space
indent_size = 4
csharp_style_var_for_built_in_types = false:warning
csharp_style_var_elsewhere = false:warning
-csharp_style_var_when_type_is_apparent = false:warning
+csharp_style_var_when_type_is_apparent = true:warning
end_of_line = crlf
dotnet_sort_system_directives_first = true
dotnet_style_predefined_type_for_locals_parameters_members = true:warning
diff --git a/ImageSharp.ruleset b/ImageSharp.ruleset
index 3f10206fca..0bd9cd11ab 100644
--- a/ImageSharp.ruleset
+++ b/ImageSharp.ruleset
@@ -4,7 +4,7 @@
-
+
diff --git a/ImageSharp.sln b/ImageSharp.sln
index 2802e7ba8a..468bbbf862 100644
--- a/ImageSharp.sln
+++ b/ImageSharp.sln
@@ -1,24 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
-VisualStudioVersion = 15.0.26228.9
+VisualStudioVersion = 15.0.26403.7
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionItems", "{C317F1B1-D75E-4C6D-83EB-80367343E0D7}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.travis.yml = .travis.yml
appveyor.yml = appveyor.yml
+ codecov.yml = codecov.yml
CodeCoverage.runsettings = CodeCoverage.runsettings
- contributing.md = contributing.md
- dotnet-latest.ps1 = dotnet-latest.ps1
+ .github\CONTRIBUTING.md = .github\CONTRIBUTING.md
features.md = features.md
- global.json = global.json
ImageSharp.ruleset = ImageSharp.ruleset
ImageSharp.sln.DotSettings = ImageSharp.sln.DotSettings
NuGet.config = NuGet.config
README.md = README.md
- Rebracer.xml = Rebracer.xml
- Settings.StyleCop = Settings.StyleCop
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{815C0625-CD3D-440F-9F80-2D83856AB7AE}"
diff --git a/README.md b/README.md
index 6ba113e922..ca24275469 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,13 @@
-#
+#
ImageSharp
-**ImageSharp** is a new cross-platform 2D graphics API designed to allow the processing of images without the use of `System.Drawing`.
+**ImageSharp** is a new, fully featured, fully managed, cross-platform, 2D graphics API designed to allow the processing of images without the use of `System.Drawing`.
-> **ImageSharp is still in early stages (alpha) but progress has been pretty quick. As such, please do not use on production environments until the library reaches release candidate status. Pre-release downloads are available from the [MyGet package repository](https://www.myget.org/gallery/imagesharp).**
+Built against .Net Standard 1.1 ImageSharp can be used in device, cloud, and embedded/IoT scenarios.
+
+> **ImageSharp** has made excellent progress and contains many great features but is still considered by us to be still in early stages (alpha). As such, we cannot support its use on production environments until the library reaches release candidate status.
+>
+> Pre-release downloads are available from the [MyGet package repository](https://www.myget.org/gallery/imagesharp).
[](https://raw.githubusercontent.com/JimBobSquarePants/ImageSharp/master/APACHE-2.0-LICENSE.txt)
[](https://github.com/JimBobSquarePants/ImageSharp/issues)
@@ -35,8 +39,8 @@ The **ImageSharp** library is made up of multiple packages.
Packages include:
- **ImageSharp**
- - Contains the Image classes, Colors, Primitives, Configuration, and other core functionality.
- - The IImageFormat interface, Jpeg, Png, Bmp, and Gif formats.
+ - Contains the generic `Image` class, PixelFormats, Primitives, Configuration, and other core functionality.
+ - The `IImageFormat` interface, Jpeg, Png, Bmp, and Gif formats.
- Transform methods like Resize, Crop, Skew, Rotate - Anything that alters the dimensions of the image.
- Non-transform methods like Gaussian Blur, Pixelate, Edge Detection - Anything that maintains the original image dimensions.
@@ -69,15 +73,20 @@ There's plenty there and more coming. Check out the [current features](features.
### API
-Without the constraints of `System.Drawing` We have been able to develop something much more flexible, easier to code against, and much, much less prone to memory leaks. Gone are system-wide process-locks. Images and processors are thread safe usable in parallel processing utilizing all the availables cores.
+Without the constraints of `System.Drawing` We have been able to develop something much more flexible, easier to code against, and much, much less prone to memory leaks.
+
+Gone are system-wide process-locks; ImageSharp images are thread-safe and fully supported in web environments.
-Many `Image` methods are also fluent.
+Many `Image` methods are also fluent.
Here's an example of the code required to resize an image using the default Bicubic resampler then turn the colors into their grayscale equivalent using the BT709 standard matrix.
+`Rgba32` is our default PixelFormat, equivalent to `System.Drawing Color`.
+
On platforms supporting netstandard 1.3+
```csharp
-using (Image image = Image.Load("foo.jpg"))
+// Image.Load(string path) is a shortcut for our default type. Other pixel formats use Image.Load(string path))
+using (Image image = Image.Load("foo.jpg"))
{
image.Resize(image.Width / 2, image.Height / 2)
.Grayscale()
@@ -86,9 +95,10 @@ using (Image image = Image.Load("foo.jpg"))
```
on netstandard 1.1 - 1.2
```csharp
+// Image.Load(Stream stream) is a shortcut for our default type. Other pixel formats use Image.Load(Stream stream))
using (FileStream stream = File.OpenRead("foo.jpg"))
using (FileStream output = File.OpenWrite("bar.jpg"))
-using (Image image = Image.Load(stream))
+using (Image image = Image.Load(stream))
{
image.Resize(image.Width / 2, image.Height / 2)
.Grayscale()
@@ -99,14 +109,14 @@ using (Image image = Image.Load(stream))
Setting individual pixel values is perfomed as follows:
```csharp
-using (image = new Image(400, 400)
-using (var pixels = image.Lock())
+using (Image image = new Image(400, 400)
+using (PixelAccessor pixels = image.Lock())
{
- pixels[200, 200] = Color.White;
+ pixels[200, 200] = Rgba32.White;
}
```
-For advanced usage the `Image` and `PixelAccessor` classes are available allowing developers to implement their own color models in the same manner as Microsoft XNA Game Studio and MonoGame.
+For advanced usage there are multiple [PixelFormat implementations](https://github.com/JimBobSquarePants/ImageSharp/tree/master/src/ImageSharp/PixelFormats) available allowing developers to implement their own color models in the same manner as Microsoft XNA Game Studio and MonoGame.
All in all this should allow image processing to be much more accessible to developers which has always been my goal from the start.
@@ -114,7 +124,7 @@ All in all this should allow image processing to be much more accessible to deve
Please... Spread the word, contribute algorithms, submit performance improvements, unit tests.
-Performance is a biggie, if you know anything about the new vector types and can apply some fancy new stuff with that it would be awesome.
+Performance is a biggie, if you know anything about the `System.Numerics.Vectors` types and can apply some fancy new stuff with that it would be awesome.
There's a lot of developers out there who could write this stuff a lot better and faster than I and I would love to see what we collectively can come up with so please, if you can help in any way it would be most welcome and benificial for all.
@@ -198,4 +208,4 @@ Become a sponsor and get your logo on our README on Github with a link to your s
-
+
\ No newline at end of file
diff --git a/Rebracer.xml b/Rebracer.xml
deleted file mode 100644
index 9b0a654d21..0000000000
--- a/Rebracer.xml
+++ /dev/null
@@ -1,249 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
- HACK:2
- TODO:2
- UNDONE:2
- UnresolvedMergeConflict:3
-
- false
- false
- false
-
-
-
-
- 0
- 0
- 1
- 1
- -1
- -1
- 0
- 1
- 0
- 1
- 1
- 1
- 1
- 1
- 0
- 1
- 1
- 0
- 2
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 1
- 0
- 1
- 0
- 1
- 0
- 0
- 0
- 1
- 1
- 1
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 1
- 0
- 0
- 0
- 0
- 0
- 0
- 1
- 1
- 0
- 1
- 0
- 0
- 0
- 1
- 1
-
-
- false
- true
- true
- true
- true
- Implicit (Windows)|$(VSInstallDir)\JavaScript\References\libhelp.js|$(VSInstallDir)\JavaScript\References\domWindows.js|$(VSInstallDir)\JavaScript\References\underscorefilter.js|$(VSInstallDir)\JavaScript\References\showPlainComments.js;Implicit (Windows 8.1)|$(VSInstallDir)\JavaScript\References\libhelp.js|$(VSInstallDir)\JavaScript\References\sitetypesWindows.js|$(VSInstallDir)\JavaScript\References\domWindows_8.1.js|$(VSInstallDir)\JavaScript\References\underscorefilter.js|$(VSInstallDir)\JavaScript\References\showPlainComments.js;Implicit (Windows Phone 8.1)|$(VSInstallDir)\JavaScript\References\libhelp.js|$(VSInstallDir)\JavaScript\References\sitetypesWindows.js|$(VSInstallDir)\JavaScript\References\domWindowsPhone_8.1.js|$(VSInstallDir)\JavaScript\References\underscorefilter.js|$(VSInstallDir)\JavaScript\References\showPlainComments.js;Implicit (Web)|$(VSInstallDir)\JavaScript\References\libhelp.js|$(VSInstallDir)\JavaScript\References\sitetypesWeb.js|$(VSInstallDir)\JavaScript\References\domWeb.js|$(VSInstallDir)\JavaScript\References\underscorefilter.js|$(VSInstallDir)\JavaScript\References\showPlainComments.js|C:\Users\james.south\AppData\Local\Web Essentials 2015\Modern.Intellisense.js;Dedicated Worker|$(VSInstallDir)\JavaScript\References\libhelp.js|$(VSInstallDir)\JavaScript\References\dedicatedworker.js|$(VSInstallDir)\JavaScript\References\underscorefilter.js|$(VSInstallDir)\JavaScript\References\showPlainComments.js;Generic|$(VSInstallDir)\JavaScript\References\libhelp.js|$(VSInstallDir)\JavaScript\References\underscorefilter.js|$(VSInstallDir)\JavaScript\References\showPlainComments.js;
- true
- true
- true
- false
- true
- true
- false
- false
- true
- true
-
-
- true
- false
- false
- true
- true
- true
- 1
- true
- false
- true
- true
- false
- false
- false
- false
- false
- false
- false
- true
- true
- false
- true
- true
- true
- true
- false
- true
- false
- false
- true
- false
- 1
- true
- 2
- 2
- false
- false
- 0
- true
- true
- 0
- 0
- true
- true
- false
- 0
- 0
- false
- 0
- 1
- false
- true
- false
- 2
- true
- false
- false
- false
- false
- true
- true
- false
- false
- false
- false
- true
- true
- 2
- 2
- 2
- true
- false
- false
- true
- true
- false
- false
- 1
- true
- false
- false
- false
- false
- false
- false
- false
- false
- false
- false
- false
- true
- false
- false
- true
- true
-
-
- false
- false
- true
- false
- true
- true
- true
- true
- true
- true
- true
- false
- true
- true
- false
- false
- true
- true
- false
- false
- false
- false
- false
- false
- false
- false
-
-
- false
- true
- true
- true
- false
- true
- true
- true
-
-
-
-
\ No newline at end of file
diff --git a/Settings.StyleCop b/Settings.StyleCop
deleted file mode 100644
index 2716e8d0ac..0000000000
--- a/Settings.StyleCop
+++ /dev/null
@@ -1,56 +0,0 @@
-
-
-
- enum
- exif
- uint
- lossy
- octree
- png
- quantizer
- unzig
- cb
- cr
- Laplacian
- Sobel
- Scharr
- rgb
- rgba
- rrggbb
- rrggbbaa
- scanline
- scanlines
- png's
- codeword
- unscaled
- zig-zag
- crc
- zlib
- xff
- xda
- ss
- Vol
- pp
- cmyk
- Paeth
- th
- bool
- bools
- desensitivity
- premultiplied
- endianness
- thresholding
-
-
-
-
-
- James Jackson-South
-
- Copyright © James Jackson-South and contributors.
- Licensed under the Apache License, Version 2.0.
-
-
-
-
-
\ No newline at end of file
diff --git a/features.md b/features.md
index 6bc5630eed..1e35b88e0d 100644
--- a/features.md
+++ b/features.md
@@ -13,6 +13,7 @@ We've achieved a lot so far and hope to do a lot more in the future. We're alway
- [ ] Tiff (Help needed)
- **Metadata**
- [x] EXIF Read/Write (Jpeg just now)
+ - [ ] ICC (In Progress)
- **Quantizers (IQuantizer with alpha channel support, dithering, and thresholding)**
- [x] Octree
- [x] Xiaolin Wu
@@ -28,7 +29,6 @@ We've achieved a lot so far and hope to do a lot more in the future. We're alway
- [x] Bayer
- [x] Ordered
- **Basic color structs with implicit operators.**
- - [x] Color - 32bit color in RGBA order (IPackedPixel\).
- [x] Bgra32
- [x] CIE Lab
- [x] CIE XYZ
@@ -38,7 +38,7 @@ We've achieved a lot so far and hope to do a lot more in the future. We're alway
- [x] YCbCr
- **IPackedPixel representations of color models. Compatible with Microsoft XNA Game Studio and MonoGame IPackedVector\.**
- [x] Alpha8
- - [x] Argb
+ - [x] Argb32
- [x] Bgr565
- [x] Bgra444
- [x] Bgra565
@@ -52,7 +52,9 @@ We've achieved a lot so far and hope to do a lot more in the future. We're alway
- [x] NormalizedShort4
- [x] Rg32
- [x] Rgba1010102
+ - [x] Rgba32 - 32bit color in RGBA order - Our default pixel format.
- [x] Rgba64
+ - [x] RgbaVector
- [x] Short2
- [x] Short4
- **Basic shape primitives.**
diff --git a/src/ImageSharp.Drawing/Brushes/Brushes.cs b/src/ImageSharp.Drawing/Brushes/Brushes.cs
index e8269848ce..e39f3dd497 100644
--- a/src/ImageSharp.Drawing/Brushes/Brushes.cs
+++ b/src/ImageSharp.Drawing/Brushes/Brushes.cs
@@ -5,150 +5,254 @@
namespace ImageSharp.Drawing.Brushes
{
+ using ImageSharp.PixelFormats;
+
///
- /// A collection of methods for creating brushes. Brushes use for painting.
+ /// A collection of methods for creating generic brushes.
///
- public class Brushes
+ /// A New
+ public static class Brushes
{
+ ///
+ /// Percent10 Hatch Pattern
+ ///
+ /// ---> x axis
+ /// ^
+ /// | y - axis
+ /// |
+ /// see PatternBrush for details about how to make new patterns work
+ private static readonly bool[,] Percent10Pattern =
+ {
+ { true, false, false, false },
+ { false, false, false, false },
+ { false, false, true, false },
+ { false, false, false, false }
+ };
+
+ ///
+ /// Percent20 pattern.
+ ///
+ private static readonly bool[,] Percent20Pattern =
+ {
+ { true, false, false, false },
+ { false, false, true, false },
+ { true, false, false, false },
+ { false, false, true, false }
+ };
+
+ ///
+ /// Horizontal Hatch Pattern
+ ///
+ private static readonly bool[,] HorizontalPattern =
+ {
+ { false },
+ { true },
+ { false },
+ { false }
+ };
+
+ ///
+ /// Min Pattern
+ ///
+ private static readonly bool[,] MinPattern =
+ {
+ { false },
+ { false },
+ { false },
+ { true }
+ };
+
+ ///
+ /// Vertical Pattern
+ ///
+ private static readonly bool[,] VerticalPattern =
+ {
+ { false, true, false, false },
+ };
+
+ ///
+ /// Forward Diagonal Pattern
+ ///
+ private static readonly bool[,] ForwardDiagonalPattern =
+ {
+ { false, false, false, true },
+ { false, false, true, false },
+ { false, true, false, false },
+ { true, false, false, false }
+ };
+
+ ///
+ /// Backward Diagonal Pattern
+ ///
+ private static readonly bool[,] BackwardDiagonalPattern =
+ {
+ { true, false, false, false },
+ { false, true, false, false },
+ { false, false, true, false },
+ { false, false, false, true }
+ };
+
///
/// Create as brush that will paint a solid color
///
/// The color.
- /// A Brush
- public static SolidBrush Solid(Color color)
- => new SolidBrush(color);
+ /// The pixel format.
+ /// A New
+ public static SolidBrush Solid(TPixel color)
+ where TPixel : struct, IPixel
+ => new SolidBrush(color);
///
- /// Create as brush that will paint a Percent10 Hatch Pattern with
- /// in the specified foreground color and a transparent background
+ /// Create as brush that will paint a Percent10 Hatch Pattern with the specified colors
///
/// Color of the foreground.
- /// A Brush
- public static PatternBrush Percent10(Color foreColor)
- => new PatternBrush(Brushes.Percent10(foreColor, Color.Transparent));
+ /// The pixel format.
+ /// A New
+ public static PatternBrush Percent10(TPixel foreColor)
+ where TPixel : struct, IPixel
+ => new PatternBrush(foreColor, NamedColors.Transparent, Percent10Pattern);
///
- /// Create as brush that will paint a Percent10 Hatch Pattern with
- /// in the specified foreground and background colors
+ /// Create as brush that will paint a Percent10 Hatch Pattern with the specified colors
///
/// Color of the foreground.
/// Color of the background.
- /// A Brush
- public static PatternBrush Percent10(Color foreColor, Color backColor)
- => new PatternBrush(Brushes.Percent10(foreColor, backColor));
+ /// The pixel format.
+ /// A New
+ public static PatternBrush Percent10(TPixel foreColor, TPixel backColor)
+ where TPixel : struct, IPixel
+ => new PatternBrush(foreColor, backColor, Percent10Pattern);
///
- /// Create as brush that will paint a Percent20 Hatch Pattern with
- /// in the specified foreground color and a transparent background
+ /// Create as brush that will paint a Percent20 Hatch Pattern with the specified foreground color and a
+ /// transparent background.
///
/// Color of the foreground.
- /// A Brush
- public static PatternBrush Percent20(Color foreColor)
- => new PatternBrush(Brushes.Percent20(foreColor, Color.Transparent));
+ /// The pixel format.
+ /// A New
+ public static PatternBrush Percent20(TPixel foreColor)
+ where TPixel : struct, IPixel
+ => new PatternBrush(foreColor, NamedColors.Transparent, Percent20Pattern);
///
- /// Create as brush that will paint a Percent20 Hatch Pattern with
- /// in the specified foreground and background colors
+ /// Create as brush that will paint a Percent20 Hatch Pattern with the specified colors
///
/// Color of the foreground.
/// Color of the background.
- /// A Brush
- public static PatternBrush Percent20(Color foreColor, Color backColor)
- => new PatternBrush(Brushes.Percent20(foreColor, backColor));
+ /// The pixel format.
+ /// A New
+ public static PatternBrush Percent20(TPixel foreColor, TPixel backColor)
+ where TPixel : struct, IPixel
+ => new PatternBrush(foreColor, backColor, Percent20Pattern);
///
- /// Create as brush that will paint a Horizontal Hatch Pattern with
- /// in the specified foreground color and a transparent background
+ /// Create as brush that will paint a Horizontal Hatch Pattern with the specified foreground color and a
+ /// transparent background.
///
/// Color of the foreground.
- /// A Brush
- public static PatternBrush Horizontal(Color foreColor)
- => new PatternBrush(Brushes.Horizontal(foreColor, Color.Transparent));
+ /// The pixel format.
+ /// A New
+ public static PatternBrush Horizontal(TPixel foreColor)
+ where TPixel : struct, IPixel
+ => new PatternBrush(foreColor, NamedColors.Transparent, HorizontalPattern);
///
- /// Create as brush that will paint a Horizontal Hatch Pattern with
- /// in the specified foreground and background colors
+ /// Create as brush that will paint a Horizontal Hatch Pattern with the specified colors
///
/// Color of the foreground.
/// Color of the background.
- /// A Brush
- public static PatternBrush Horizontal(Color foreColor, Color backColor)
- => new PatternBrush(Brushes.Horizontal(foreColor, backColor));
+ /// The pixel format.
+ /// A New
+ public static PatternBrush Horizontal(TPixel foreColor, TPixel backColor)
+ where TPixel : struct, IPixel
+ => new PatternBrush(foreColor, backColor, HorizontalPattern);
///
- /// Create as brush that will paint a Min Hatch Pattern with
- /// in the specified foreground color and a transparent background
+ /// Create as brush that will paint a Min Hatch Pattern with the specified foreground color and a
+ /// transparent background.
///
/// Color of the foreground.
- /// A Brush
- public static PatternBrush Min(Color foreColor)
- => new PatternBrush(Brushes.Min(foreColor, Color.Transparent));
+ /// The pixel format.
+ /// A New
+ public static PatternBrush Min(TPixel foreColor)
+ where TPixel : struct, IPixel
+ => new PatternBrush(foreColor, NamedColors.Transparent, MinPattern);
///
- /// Create as brush that will paint a Min Hatch Pattern with
- /// in the specified foreground and background colors
+ /// Create as brush that will paint a Min Hatch Pattern with the specified colors
///
/// Color of the foreground.
/// Color of the background.
- /// A Brush
- public static PatternBrush Min(Color foreColor, Color backColor)
- => new PatternBrush(Brushes.Min(foreColor, backColor));
+ /// The pixel format.
+ /// A New
+ public static PatternBrush Min(TPixel foreColor, TPixel backColor)
+ where TPixel : struct, IPixel
+ => new PatternBrush(foreColor, backColor, MinPattern);
///
- /// Create as brush that will paint a Vertical Hatch Pattern with
- /// in the specified foreground color and a transparent background
+ /// Create as brush that will paint a Vertical Hatch Pattern with the specified foreground color and a
+ /// transparent background.
///
/// Color of the foreground.
- /// A Brush
- public static PatternBrush Vertical(Color foreColor)
- => new PatternBrush(Brushes.Vertical(foreColor, Color.Transparent));
+ /// The pixel format.
+ /// A New
+ public static PatternBrush Vertical(TPixel foreColor)
+ where TPixel : struct, IPixel
+ => new PatternBrush(foreColor, NamedColors.Transparent, VerticalPattern);
///
- /// Create as brush that will paint a Vertical Hatch Pattern with
- /// in the specified foreground and background colors
+ /// Create as brush that will paint a Vertical Hatch Pattern with the specified colors
///
/// Color of the foreground.
/// Color of the background.
- /// A Brush
- public static PatternBrush Vertical(Color foreColor, Color backColor)
- => new PatternBrush(Brushes.Vertical(foreColor, backColor));
+ /// The pixel format.
+ /// A New
+ public static PatternBrush Vertical(TPixel foreColor, TPixel backColor)
+ where TPixel : struct, IPixel
+ => new PatternBrush(foreColor, backColor, VerticalPattern);
///
- /// Create as brush that will paint a Forward Diagonal Hatch Pattern with
- /// in the specified foreground color and a transparent background
+ /// Create as brush that will paint a Forward Diagonal Hatch Pattern with the specified foreground color and a
+ /// transparent background.
///
/// Color of the foreground.
- /// A Brush
- public static PatternBrush ForwardDiagonal(Color foreColor)
- => new PatternBrush(Brushes.ForwardDiagonal(foreColor, Color.Transparent));
+ /// The pixel format.
+ /// A New
+ public static PatternBrush ForwardDiagonal(TPixel foreColor)
+ where TPixel : struct, IPixel
+ => new PatternBrush(foreColor, NamedColors.Transparent, ForwardDiagonalPattern);
///
- /// Create as brush that will paint a Forward Diagonal Hatch Pattern with
- /// in the specified foreground and background colors
+ /// Create as brush that will paint a Forward Diagonal Hatch Pattern with the specified colors
///
/// Color of the foreground.
/// Color of the background.
- /// A Brush
- public static PatternBrush ForwardDiagonal(Color foreColor, Color backColor)
- => new PatternBrush(Brushes.ForwardDiagonal(foreColor, backColor));
+ /// The pixel format.
+ /// A New
+ public static PatternBrush ForwardDiagonal(TPixel foreColor, TPixel backColor)
+ where TPixel : struct, IPixel
+ => new PatternBrush(foreColor, backColor, ForwardDiagonalPattern);
///
- /// Create as brush that will paint a Backward Diagonal Hatch Pattern with
- /// in the specified foreground color and a transparent background
+ /// Create as brush that will paint a Backward Diagonal Hatch Pattern with the specified foreground color and a
+ /// transparent background.
///
/// Color of the foreground.
- /// A Brush
- public static PatternBrush BackwardDiagonal(Color foreColor)
- => new PatternBrush(Brushes.BackwardDiagonal(foreColor, Color.Transparent));
+ /// The pixel format.
+ /// A New
+ public static PatternBrush BackwardDiagonal(TPixel foreColor)
+ where TPixel : struct, IPixel
+ => new PatternBrush(foreColor, NamedColors.Transparent, BackwardDiagonalPattern);
///
- /// Create as brush that will paint a Backward Diagonal Hatch Pattern with
- /// in the specified foreground and background colors
+ /// Create as brush that will paint a Backward Diagonal Hatch Pattern with the specified colors
///
/// Color of the foreground.
/// Color of the background.
- /// A Brush
- public static PatternBrush BackwardDiagonal(Color foreColor, Color backColor)
- => new PatternBrush(Brushes.BackwardDiagonal(foreColor, backColor));
+ /// The pixel format.
+ /// A New
+ public static PatternBrush BackwardDiagonal(TPixel foreColor, TPixel backColor)
+ where TPixel : struct, IPixel
+ => new PatternBrush(foreColor, backColor, BackwardDiagonalPattern);
}
}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Brushes/Brushes{TColor}.cs b/src/ImageSharp.Drawing/Brushes/Brushes{TColor}.cs
deleted file mode 100644
index 6e092bf185..0000000000
--- a/src/ImageSharp.Drawing/Brushes/Brushes{TColor}.cs
+++ /dev/null
@@ -1,168 +0,0 @@
-//
-// Copyright (c) James Jackson-South and contributors.
-// Licensed under the Apache License, Version 2.0.
-//
-
-namespace ImageSharp.Drawing.Brushes
-{
- using System;
-
- ///
- /// A collection of methods for creating generic brushes.
- ///
- /// The pixel format.
- /// A Brush
- public class Brushes
- where TColor : struct, IPixel
- {
- ///
- /// Percent10 Hatch Pattern
- ///
- /// ---> x axis
- /// ^
- /// | y - axis
- /// |
- /// see PatternBrush for details about how to make new patterns work
- private static readonly bool[,] Percent10Pattern =
- {
- { true, false, false, false },
- { false, false, false, false },
- { false, false, true, false },
- { false, false, false, false }
- };
-
- ///
- /// Percent20 pattern.
- ///
- private static readonly bool[,] Percent20Pattern =
- {
- { true, false, false, false },
- { false, false, true, false },
- { true, false, false, false },
- { false, false, true, false }
- };
-
- ///
- /// Horizontal Hatch Pattern
- ///
- private static readonly bool[,] HorizontalPattern =
- {
- { false },
- { true },
- { false },
- { false }
- };
-
- ///
- /// Min Pattern
- ///
- private static readonly bool[,] MinPattern =
- {
- { false },
- { false },
- { false },
- { true }
- };
-
- ///
- /// Vertical Pattern
- ///
- private static readonly bool[,] VerticalPattern =
- {
- { false, true, false, false },
- };
-
- ///
- /// Forward Diagonal Pattern
- ///
- private static readonly bool[,] ForwardDiagonalPattern =
- {
- { false, false, false, true },
- { false, false, true, false },
- { false, true, false, false },
- { true, false, false, false }
- };
-
- ///
- /// Backward Diagonal Pattern
- ///
- private static readonly bool[,] BackwardDiagonalPattern =
- {
- { true, false, false, false },
- { false, true, false, false },
- { false, false, true, false },
- { false, false, false, true }
- };
-
- ///
- /// Create as brush that will paint a solid color
- ///
- /// The color.
- /// A Brush
- public static SolidBrush Solid(TColor color)
- => new SolidBrush(color);
-
- ///
- /// Create as brush that will paint a Percent10 Hatch Pattern within the specified colors
- ///
- /// Color of the foreground.
- /// Color of the background.
- /// A Brush
- public static PatternBrush Percent10(TColor foreColor, TColor backColor)
- => new PatternBrush(foreColor, backColor, Percent10Pattern);
-
- ///
- /// Create as brush that will paint a Percent20 Hatch Pattern within the specified colors
- ///
- /// Color of the foreground.
- /// Color of the background.
- /// A Brush
- public static PatternBrush Percent20(TColor foreColor, TColor backColor)
- => new PatternBrush(foreColor, backColor, Percent20Pattern);
-
- ///
- /// Create as brush that will paint a Horizontal Hatch Pattern within the specified colors
- ///
- /// Color of the foreground.
- /// Color of the background.
- /// A Brush
- public static PatternBrush Horizontal(TColor foreColor, TColor backColor)
- => new PatternBrush(foreColor, backColor, HorizontalPattern);
-
- ///
- /// Create as brush that will paint a Min Hatch Pattern within the specified colors
- ///
- /// Color of the foreground.
- /// Color of the background.
- /// A Brush
- public static PatternBrush Min(TColor foreColor, TColor backColor)
- => new PatternBrush(foreColor, backColor, MinPattern);
-
- ///
- /// Create as brush that will paint a Vertical Hatch Pattern within the specified colors
- ///
- /// Color of the foreground.
- /// Color of the background.
- /// A Brush
- public static PatternBrush Vertical(TColor foreColor, TColor backColor)
- => new PatternBrush(foreColor, backColor, VerticalPattern);
-
- ///
- /// Create as brush that will paint a Forward Diagonal Hatch Pattern within the specified colors
- ///
- /// Color of the foreground.
- /// Color of the background.
- /// A Brush
- public static PatternBrush ForwardDiagonal(TColor foreColor, TColor backColor)
- => new PatternBrush(foreColor, backColor, ForwardDiagonalPattern);
-
- ///
- /// Create as brush that will paint a Backward Diagonal Hatch Pattern within the specified colors
- ///
- /// Color of the foreground.
- /// Color of the background.
- /// A Brush
- public static PatternBrush BackwardDiagonal(TColor foreColor, TColor backColor)
- => new PatternBrush(foreColor, backColor, BackwardDiagonalPattern);
- }
-}
diff --git a/src/ImageSharp.Drawing/Brushes/IBrush.cs b/src/ImageSharp.Drawing/Brushes/IBrush.cs
index df05fa23e1..9534c7a882 100644
--- a/src/ImageSharp.Drawing/Brushes/IBrush.cs
+++ b/src/ImageSharp.Drawing/Brushes/IBrush.cs
@@ -5,26 +5,26 @@
namespace ImageSharp.Drawing
{
- using System;
-
+ using ImageSharp.PixelFormats;
using Processors;
///
/// Brush represents a logical configuration of a brush which can be used to source pixel colors
///
- /// The pixel format.
+ /// The pixel format.
///
- /// A brush is a simple class that will return an that will perform the
- /// logic for converting a pixel location to a .
+ /// A brush is a simple class that will return an that will perform the
+ /// logic for converting a pixel location to a .
///
- public interface IBrush
- where TColor : struct, IPixel
+ public interface IBrush
+ where TPixel : struct, IPixel
{
///
/// Creates the applicator for this brush.
///
/// The pixel source.
/// The region the brush will be applied to.
+ /// The graphic options
///
/// The brush applicator for this brush
///
@@ -32,6 +32,6 @@ namespace ImageSharp.Drawing
/// The when being applied to things like shapes would usually be the
/// bounding box of the shape not necessarily the bounds of the whole image
///
- BrushApplicator CreateApplicator(PixelAccessor pixelSource, RectangleF region);
+ BrushApplicator CreateApplicator(PixelAccessor pixelSource, RectangleF region, GraphicsOptions options);
}
}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Brushes/ImageBrush.cs b/src/ImageSharp.Drawing/Brushes/ImageBrush.cs
deleted file mode 100644
index a7124bfe86..0000000000
--- a/src/ImageSharp.Drawing/Brushes/ImageBrush.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-//
-// Copyright (c) James Jackson-South and contributors.
-// Licensed under the Apache License, Version 2.0.
-//
-
-namespace ImageSharp.Drawing.Brushes
-{
- ///
- /// Provides an implementation of a solid brush for painting with repeating images. The brush uses for painting.
- ///
- public class ImageBrush : ImageBrush
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The image to paint.
- public ImageBrush(IImageBase image)
- : base(image)
- {
- }
- }
-}
diff --git a/src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs b/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs
similarity index 50%
rename from src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs
rename to src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs
index ace929bd6a..6f851e5c3b 100644
--- a/src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs
+++ b/src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs
@@ -1,4 +1,4 @@
-//
+//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
@@ -8,44 +8,46 @@ namespace ImageSharp.Drawing.Brushes
using System;
using System.Numerics;
+ using ImageSharp.Memory;
+ using ImageSharp.PixelFormats;
using Processors;
///
/// Provides an implementation of an image brush for painting images within areas.
///
- /// The pixel format.
- public class ImageBrush : IBrush
- where TColor : struct, IPixel
+ /// The pixel format.
+ public class ImageBrush : IBrush
+ where TPixel : struct, IPixel
{
///
/// The image to paint.
///
- private readonly IImageBase image;
+ private readonly IImageBase image;
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
/// The image.
- public ImageBrush(IImageBase image)
+ public ImageBrush(IImageBase image)
{
this.image = image;
}
///
- public BrushApplicator CreateApplicator(PixelAccessor sourcePixels, RectangleF region)
+ public BrushApplicator CreateApplicator(PixelAccessor sourcePixels, RectangleF region, GraphicsOptions options)
{
- return new ImageBrushApplicator(sourcePixels, this.image, region);
+ return new ImageBrushApplicator(sourcePixels, this.image, region, options);
}
///
/// The image brush applicator.
///
- private class ImageBrushApplicator : BrushApplicator
+ private class ImageBrushApplicator : BrushApplicator
{
///
/// The source pixel accessor.
///
- private readonly PixelAccessor source;
+ private readonly PixelAccessor source;
///
/// The y-length.
@@ -58,9 +60,14 @@ namespace ImageSharp.Drawing.Brushes
private readonly int xLength;
///
- /// The offset.
+ /// The Y offset.
///
- private readonly Vector2 offset;
+ private readonly int offsetY;
+
+ ///
+ /// The X offset.
+ ///
+ private readonly int offsetX;
///
/// Initializes a new instance of the class.
@@ -71,16 +78,18 @@ namespace ImageSharp.Drawing.Brushes
///
/// The region.
///
+ /// The options
///
/// The sourcePixels.
///
- public ImageBrushApplicator(PixelAccessor sourcePixels, IImageBase image, RectangleF region)
- : base(sourcePixels)
+ public ImageBrushApplicator(PixelAccessor sourcePixels, IImageBase image, RectangleF region, GraphicsOptions options)
+ : base(sourcePixels, options)
{
this.source = image.Lock();
this.xLength = image.Width;
this.yLength = image.Height;
- this.offset = new Vector2(MathF.Max(MathF.Floor(region.Top), 0), MathF.Max(MathF.Floor(region.Left), 0));
+ this.offsetY = (int)MathF.Max(MathF.Floor(region.Top), 0);
+ this.offsetX = (int)MathF.Max(MathF.Floor(region.Left), 0);
}
///
@@ -91,17 +100,12 @@ namespace ImageSharp.Drawing.Brushes
///
/// The color
///
- internal override TColor this[int x, int y]
+ internal override TPixel this[int x, int y]
{
get
{
- Vector2 point = new Vector2(x, y);
-
- // Offset the requested pixel by the value in the rectangle (the shapes position)
- point = point - this.offset;
- int srcX = (int)point.X % this.xLength;
- int srcY = (int)point.Y % this.yLength;
-
+ int srcX = (x - this.offsetX) % this.xLength;
+ int srcY = (y - this.offsetY) % this.yLength;
return this.source[srcX, srcY];
}
}
@@ -113,33 +117,27 @@ namespace ImageSharp.Drawing.Brushes
}
///
- internal override void Apply(float[] scanlineBuffer, int scanlineWidth, int offset, int x, int y)
+ internal override void Apply(Span scanline, int x, int y)
{
- Guard.MustBeGreaterThanOrEqualTo(scanlineBuffer.Length, offset + scanlineWidth, nameof(scanlineWidth));
-
- using (PinnedBuffer buffer = new PinnedBuffer(scanlineBuffer))
+ // create a span for colors
+ using (Buffer amountBuffer = new Buffer(scanline.Length))
+ using (Buffer overlay = new Buffer(scanline.Length))
{
- BufferSpan slice = buffer.Slice(offset);
+ int sourceY = (y - this.offsetY) % this.yLength;
+ int offsetX = x - this.offsetX;
+ Span sourceRow = this.source.GetRowSpan(sourceY);
- for (int xPos = 0; xPos < scanlineWidth; xPos++)
+ for (int i = 0; i < scanline.Length; i++)
{
- int targetX = xPos + x;
- int targetY = y;
-
- float opacity = slice[xPos];
- if (opacity > Constants.Epsilon)
- {
- Vector4 backgroundVector = this.Target[targetX, targetY].ToVector4();
-
- Vector4 sourceVector = this[targetX, targetY].ToVector4();
+ amountBuffer[i] = scanline[i] * this.Options.BlendPercentage;
- Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity);
-
- TColor packed = default(TColor);
- packed.PackFromVector4(finalColor);
- this.Target[targetX, targetY] = packed;
- }
+ int sourceX = (i + offsetX) % this.xLength;
+ TPixel pixel = sourceRow[sourceX];
+ overlay[i] = pixel;
}
+
+ Span destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length);
+ this.Blender.Blend(destinationRow, destinationRow, overlay, amountBuffer);
}
}
}
diff --git a/src/ImageSharp.Drawing/Brushes/PatternBrush.cs b/src/ImageSharp.Drawing/Brushes/PatternBrush.cs
deleted file mode 100644
index 5093a7df06..0000000000
--- a/src/ImageSharp.Drawing/Brushes/PatternBrush.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-//
-// Copyright (c) James Jackson-South and contributors.
-// Licensed under the Apache License, Version 2.0.
-//
-
-namespace ImageSharp.Drawing.Brushes
-{
- ///
- /// Provides an implementation of a pattern brush for painting patterns. The brush use for painting.
- ///
- public class PatternBrush : PatternBrush
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// Color of the fore.
- /// Color of the back.
- /// The pattern.
- public PatternBrush(Color foreColor, Color backColor, bool[,] pattern)
- : base(foreColor, backColor, pattern)
- {
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The brush.
- internal PatternBrush(PatternBrush brush)
- : base(brush)
- {
- }
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs b/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs
similarity index 65%
rename from src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs
rename to src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs
index df492a764e..90990e54a9 100644
--- a/src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs
+++ b/src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs
@@ -1,4 +1,4 @@
-//
+//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
@@ -8,6 +8,8 @@ namespace ImageSharp.Drawing.Brushes
using System;
using System.Numerics;
+ using ImageSharp.Memory;
+ using ImageSharp.PixelFormats;
using Processors;
///
@@ -31,38 +33,38 @@ namespace ImageSharp.Drawing.Brushes
/// 0
///
///
- /// The pixel format.
- public class PatternBrush : IBrush
- where TColor : struct, IPixel
+ /// The pixel format.
+ public class PatternBrush : IBrush
+ where TPixel : struct, IPixel
{
///
/// The pattern.
///
- private readonly Fast2DArray pattern;
+ private readonly Fast2DArray pattern;
private readonly Fast2DArray patternVector;
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
/// Color of the fore.
/// Color of the back.
/// The pattern.
- public PatternBrush(TColor foreColor, TColor backColor, bool[,] pattern)
+ public PatternBrush(TPixel foreColor, TPixel backColor, bool[,] pattern)
: this(foreColor, backColor, new Fast2DArray(pattern))
{
}
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
/// Color of the fore.
/// Color of the back.
/// The pattern.
- internal PatternBrush(TColor foreColor, TColor backColor, Fast2DArray pattern)
+ internal PatternBrush(TPixel foreColor, TPixel backColor, Fast2DArray pattern)
{
Vector4 foreColorVector = foreColor.ToVector4();
Vector4 backColorVector = backColor.ToVector4();
- this.pattern = new Fast2DArray(pattern.Width, pattern.Height);
+ this.pattern = new Fast2DArray(pattern.Width, pattern.Height);
this.patternVector = new Fast2DArray(pattern.Width, pattern.Height);
for (int i = 0; i < pattern.Data.Length; i++)
{
@@ -80,30 +82,30 @@ namespace ImageSharp.Drawing.Brushes
}
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
/// The brush.
- internal PatternBrush(PatternBrush brush)
+ internal PatternBrush(PatternBrush brush)
{
this.pattern = brush.pattern;
this.patternVector = brush.patternVector;
}
///
- public BrushApplicator CreateApplicator(PixelAccessor sourcePixels, RectangleF region)
+ public BrushApplicator CreateApplicator(PixelAccessor sourcePixels, RectangleF region, GraphicsOptions options)
{
- return new PatternBrushApplicator(sourcePixels, this.pattern, this.patternVector);
+ return new PatternBrushApplicator(sourcePixels, this.pattern, this.patternVector, options);
}
///
/// The pattern brush applicator.
///
- private class PatternBrushApplicator : BrushApplicator
+ private class PatternBrushApplicator : BrushApplicator
{
///
/// The pattern.
///
- private readonly Fast2DArray pattern;
+ private readonly Fast2DArray pattern;
private readonly Fast2DArray patternVector;
///
@@ -112,8 +114,9 @@ namespace ImageSharp.Drawing.Brushes
/// The sourcePixels.
/// The pattern.
/// The patternVector.
- public PatternBrushApplicator(PixelAccessor sourcePixels, Fast2DArray pattern, Fast2DArray patternVector)
- : base(sourcePixels)
+ /// The options
+ public PatternBrushApplicator(PixelAccessor sourcePixels, Fast2DArray pattern, Fast2DArray patternVector, GraphicsOptions options)
+ : base(sourcePixels, options)
{
this.pattern = pattern;
this.patternVector = patternVector;
@@ -127,7 +130,7 @@ namespace ImageSharp.Drawing.Brushes
///
/// The Color.
///
- internal override TColor this[int x, int y]
+ internal override TPixel this[int x, int y]
{
get
{
@@ -146,34 +149,22 @@ namespace ImageSharp.Drawing.Brushes
}
///
- internal override void Apply(float[] scanlineBuffer, int scanlineWidth, int offset, int x, int y)
+ internal override void Apply(Span scanline, int x, int y)
{
- Guard.MustBeGreaterThanOrEqualTo(scanlineBuffer.Length, offset + scanlineWidth, nameof(scanlineWidth));
-
- using (PinnedBuffer buffer = new PinnedBuffer(scanlineBuffer))
+ int patternY = y % this.pattern.Height;
+ using (Buffer amountBuffer = new Buffer(scanline.Length))
+ using (Buffer overlay = new Buffer(scanline.Length))
{
- BufferSpan slice = buffer.Slice(offset);
-
- for (int xPos = 0; xPos < scanlineWidth; xPos++)
+ for (int i = 0; i < scanline.Length; i++)
{
- int targetX = xPos + x;
- int targetY = y;
-
- float opacity = slice[xPos];
- if (opacity > Constants.Epsilon)
- {
- Vector4 backgroundVector = this.Target[targetX, targetY].ToVector4();
+ amountBuffer[i] = (scanline[i] * this.Options.BlendPercentage).Clamp(0, 1);
- // 2d array index at row/column
- Vector4 sourceVector = this.patternVector[targetY % this.patternVector.Height, targetX % this.patternVector.Width];
-
- Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity);
-
- TColor packed = default(TColor);
- packed.PackFromVector4(finalColor);
- this.Target[targetX, targetY] = packed;
- }
+ int patternX = (x + i) % this.pattern.Width;
+ overlay[i] = this.pattern[patternY, patternX];
}
+
+ Span destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length);
+ this.Blender.Blend(destinationRow, destinationRow, overlay, amountBuffer);
}
}
}
diff --git a/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs b/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs
index 46444e5503..29629324ab 100644
--- a/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs
+++ b/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs
@@ -7,37 +7,54 @@ namespace ImageSharp.Drawing.Processors
{
using System;
using System.Numerics;
- using System.Runtime.CompilerServices;
+
+ using ImageSharp.Memory;
+ using ImageSharp.PixelFormats;
///
/// primitive that converts a point in to a color for discovering the fill color based on an implementation
///
- /// The pixel format.
+ /// The pixel format.
///
- public abstract class BrushApplicator : IDisposable // disposable will be required if/when there is an ImageBrush
- where TColor : struct, IPixel
+ public abstract class BrushApplicator : IDisposable // disposable will be required if/when there is an ImageBrush
+ where TPixel : struct, IPixel
{
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
/// The target.
- internal BrushApplicator(PixelAccessor target)
+ /// The options.
+ internal BrushApplicator(PixelAccessor target, GraphicsOptions options)
{
this.Target = target;
+
+ this.Options = options;
+
+ this.Blender = PixelOperations.Instance.GetPixelBlender(options.BlenderMode);
}
+ ///
+ /// Gets the blendder
+ ///
+ internal PixelBlender Blender { get; }
+
///
/// Gets the destinaion
///
- protected PixelAccessor Target { get; }
+ protected PixelAccessor Target { get; }
+
+ ///
+ /// Gets the blend percentage
+ ///
+ protected GraphicsOptions Options { get; private set; }
///
/// Gets the color for a single pixel.
///
/// The x cordinate.
/// The y cordinate.
- /// The a that should be applied to the pixel.
- internal abstract TColor this[int x, int y] { get; }
+ /// The a that should be applied to the pixel.
+ internal abstract TPixel this[int x, int y] { get; }
///
public abstract void Dispose();
@@ -45,39 +62,27 @@ namespace ImageSharp.Drawing.Processors
///
/// Applies the opactiy weighting for each pixel in a scanline to the target based on the pattern contained in the brush.
///
- /// The a collection of opacity values between 0 and 1 to be merged with the brushed color value before being applied to the target.
- /// The number of pixels effected by this scanline.
- /// The offset fromthe begining of the opacity data starts.
+ /// The a collection of opacity values between 0 and 1 to be merged with the brushed color value before being applied to the target.
/// The x position in the target pixel space that the start of the scanline data corresponds to.
/// The y position in the target pixel space that whole scanline corresponds to.
/// scanlineBuffer will be > scanlineWidth but provide and offset in case we want to share a larger buffer across runs.
- internal virtual void Apply(float[] scanlineBuffer, int scanlineWidth, int offset, int x, int y)
+ internal virtual void Apply(Span scanline, int x, int y)
{
- DebugGuard.MustBeGreaterThanOrEqualTo(scanlineBuffer.Length, offset + scanlineWidth, nameof(scanlineWidth));
-
- using (PinnedBuffer buffer = new PinnedBuffer(scanlineBuffer))
+ using (Buffer amountBuffer = new Buffer(scanline.Length))
+ using (Buffer overlay = new Buffer(scanline.Length))
{
- BufferSpan slice = buffer.Slice(offset);
-
- for (int xPos = 0; xPos < scanlineWidth; xPos++)
+ for (int i = 0; i < scanline.Length; i++)
{
- int targetX = xPos + x;
- int targetY = y;
-
- float opacity = slice[xPos];
- if (opacity > Constants.Epsilon)
+ if (this.Options.BlendPercentage < 1)
{
- Vector4 backgroundVector = this.Target[targetX, targetY].ToVector4();
-
- Vector4 sourceVector = this[targetX, targetY].ToVector4();
-
- Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity);
-
- TColor packed = default(TColor);
- packed.PackFromVector4(finalColor);
- this.Target[targetX, targetY] = packed;
+ amountBuffer[i] = scanline[i] * this.Options.BlendPercentage;
}
+
+ overlay[i] = this[x + i, y];
}
+
+ Span destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length);
+ this.Blender.Blend(destinationRow, destinationRow, overlay, amountBuffer);
}
}
}
diff --git a/src/ImageSharp.Drawing/Brushes/RecolorBrush.cs b/src/ImageSharp.Drawing/Brushes/RecolorBrush.cs
deleted file mode 100644
index 0452a3f015..0000000000
--- a/src/ImageSharp.Drawing/Brushes/RecolorBrush.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-//
-// Copyright (c) James Jackson-South and contributors.
-// Licensed under the Apache License, Version 2.0.
-//
-
-namespace ImageSharp.Drawing.Brushes
-{
- ///
- /// Provides an implementation of a recolor brush for painting color changes.
- ///
- public class RecolorBrush : RecolorBrush
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// Color of the source.
- /// Color of the target.
- /// The threshold.
- public RecolorBrush(Color sourceColor, Color targetColor, float threshold)
- : base(sourceColor, targetColor, threshold)
- {
- }
- }
-}
diff --git a/src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs b/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs
similarity index 56%
rename from src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs
rename to src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs
index 257eeb3ae5..64b91e3844 100644
--- a/src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs
+++ b/src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs
@@ -1,4 +1,4 @@
-//
+//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
@@ -8,26 +8,28 @@ namespace ImageSharp.Drawing.Brushes
using System;
using System.Numerics;
+ using ImageSharp.Memory;
+ using ImageSharp.PixelFormats;
using Processors;
///
/// Provides an implementation of a brush that can recolor an image
///
- /// The pixel format.
- public class RecolorBrush : IBrush
- where TColor : struct, IPixel
+ /// The pixel format.
+ public class RecolorBrush : IBrush
+ where TPixel : struct, IPixel
{
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
/// Color of the source.
- /// Color of the target.
+ /// Color of the target.
/// The threshold as a value between 0 and 1.
- public RecolorBrush(TColor sourceColor, TColor targetColor, float threshold)
+ public RecolorBrush(TPixel sourceColor, TPixel targeTPixel, float threshold)
{
this.SourceColor = sourceColor;
this.Threshold = threshold;
- this.TargetColor = targetColor;
+ this.TargeTPixel = targeTPixel;
}
///
@@ -44,7 +46,7 @@ namespace ImageSharp.Drawing.Brushes
///
/// The color of the source.
///
- public TColor SourceColor { get; }
+ public TPixel SourceColor { get; }
///
/// Gets the target color.
@@ -52,18 +54,18 @@ namespace ImageSharp.Drawing.Brushes
///
/// The color of the target.
///
- public TColor TargetColor { get; }
+ public TPixel TargeTPixel { get; }
///
- public BrushApplicator CreateApplicator(PixelAccessor sourcePixels, RectangleF region)
+ public BrushApplicator CreateApplicator(PixelAccessor sourcePixels, RectangleF region, GraphicsOptions options)
{
- return new RecolorBrushApplicator(sourcePixels, this.SourceColor, this.TargetColor, this.Threshold);
+ return new RecolorBrushApplicator(sourcePixels, this.SourceColor, this.TargeTPixel, this.Threshold, options);
}
///
/// The recolor brush applicator.
///
- private class RecolorBrushApplicator : BrushApplicator
+ private class RecolorBrushApplicator : BrushApplicator
{
///
/// The source color.
@@ -80,6 +82,8 @@ namespace ImageSharp.Drawing.Brushes
///
private readonly float threshold;
+ private readonly TPixel targetColorPixel;
+
///
/// Initializes a new instance of the class.
///
@@ -87,16 +91,18 @@ namespace ImageSharp.Drawing.Brushes
/// Color of the source.
/// Color of the target.
/// The threshold .
- public RecolorBrushApplicator(PixelAccessor sourcePixels, TColor sourceColor, TColor targetColor, float threshold)
- : base(sourcePixels)
+ /// The options
+ public RecolorBrushApplicator(PixelAccessor sourcePixels, TPixel sourceColor, TPixel targetColor, float threshold, GraphicsOptions options)
+ : base(sourcePixels, options)
{
this.sourceColor = sourceColor.ToVector4();
this.targetColor = targetColor.ToVector4();
+ this.targetColorPixel = targetColor;
// Lets hack a min max extreams for a color space by letteing the IPackedPixel clamp our values to something in the correct spaces :)
- TColor maxColor = default(TColor);
+ TPixel maxColor = default(TPixel);
maxColor.PackFromVector4(new Vector4(float.MaxValue));
- TColor minColor = default(TColor);
+ TPixel minColor = default(TPixel);
minColor.PackFromVector4(new Vector4(float.MinValue));
this.threshold = Vector4.DistanceSquared(maxColor.ToVector4(), minColor.ToVector4()) * threshold;
}
@@ -109,22 +115,21 @@ namespace ImageSharp.Drawing.Brushes
///
/// The color
///
- internal override TColor this[int x, int y]
+ internal override TPixel this[int x, int y]
{
get
{
// Offset the requested pixel by the value in the rectangle (the shapes position)
- TColor result = this.Target[x, y];
+ TPixel result = this.Target[x, y];
Vector4 background = result.ToVector4();
float distance = Vector4.DistanceSquared(background, this.sourceColor);
if (distance <= this.threshold)
{
float lerpAmount = (this.threshold - distance) / this.threshold;
- Vector4 blended = Vector4BlendTransforms.PremultipliedLerp(
- background,
- this.targetColor,
+ return this.Blender.Blend(
+ result,
+ this.targetColorPixel,
lerpAmount);
- result.PackFromVector4(blended);
}
return result;
@@ -137,42 +142,24 @@ namespace ImageSharp.Drawing.Brushes
}
///
- internal override void Apply(float[] scanlineBuffer, int scanlineWidth, int offset, int x, int y)
+ internal override void Apply(Span scanline, int x, int y)
{
- Guard.MustBeGreaterThanOrEqualTo(scanlineBuffer.Length, offset + scanlineWidth, nameof(scanlineWidth));
-
- using (PinnedBuffer buffer = new PinnedBuffer(scanlineBuffer))
+ using (Buffer amountBuffer = new Buffer(scanline.Length))
+ using (Buffer overlay = new Buffer(scanline.Length))
{
- BufferSpan slice = buffer.Slice(offset);
-
- for (int xPos = 0; xPos < scanlineWidth; xPos++)
+ for (int i = 0; i < scanline.Length; i++)
{
- int targetX = xPos + x;
- int targetY = y;
-
- float opacity = slice[xPos];
- if (opacity > Constants.Epsilon)
- {
- Vector4 backgroundVector = this.Target[targetX, targetY].ToVector4();
-
- Vector4 sourceVector = backgroundVector;
- float distance = Vector4.DistanceSquared(sourceVector, this.sourceColor);
- if (distance <= this.threshold)
- {
- float lerpAmount = (this.threshold - distance) / this.threshold;
- sourceVector = Vector4BlendTransforms.PremultipliedLerp(
- sourceVector,
- this.targetColor,
- lerpAmount);
-
- Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity);
-
- TColor packed = default(TColor);
- packed.PackFromVector4(finalColor);
- this.Target[targetX, targetY] = packed;
- }
- }
+ amountBuffer[i] = scanline[i] * this.Options.BlendPercentage;
+
+ int offsetX = x + i;
+
+ // no doubt this one can be optermised further but I can't imagine its
+ // actually being used and can probably be removed/interalised for now
+ overlay[i] = this[offsetX, y];
}
+
+ Span destinationRow = this.Target.GetRowSpan(x, y).Slice(0, scanline.Length);
+ this.Blender.Blend(destinationRow, destinationRow, overlay, amountBuffer);
}
}
}
diff --git a/src/ImageSharp.Drawing/Brushes/SolidBrush.cs b/src/ImageSharp.Drawing/Brushes/SolidBrush.cs
deleted file mode 100644
index 123d8a7e31..0000000000
--- a/src/ImageSharp.Drawing/Brushes/SolidBrush.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-//
-// Copyright (c) James Jackson-South and contributors.
-// Licensed under the Apache License, Version 2.0.
-//
-
-namespace ImageSharp.Drawing.Brushes
-{
- ///
- /// Provides an implementation of a solid brush for painting solid color areas. The brush uses for painting.
- ///
- public class SolidBrush : SolidBrush
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The color.
- public SolidBrush(Color color)
- : base(color)
- {
- }
- }
-}
diff --git a/src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs b/src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs
deleted file mode 100644
index 125b07bcac..0000000000
--- a/src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs
+++ /dev/null
@@ -1,118 +0,0 @@
-//
-// Copyright (c) James Jackson-South and contributors.
-// Licensed under the Apache License, Version 2.0.
-//
-
-namespace ImageSharp.Drawing.Brushes
-{
- using System;
- using System.Numerics;
-
- using Processors;
-
- ///
- /// Provides an implementation of a solid brush for painting solid color areas.
- ///
- /// The pixel format.
- public class SolidBrush : IBrush
- where TColor : struct, IPixel