diff --git a/README.md b/README.md
index 4d079de39..ca2427546 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
-#
ImageSharp
+#
ImageSharp
**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`.
@@ -39,8 +39,8 @@ The **ImageSharp** library is made up of multiple packages.
Packages include:
- **ImageSharp**
- - Contains the Image classes, PixelFormats, 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.
@@ -77,13 +77,16 @@ Without the constraints of `System.Drawing` We have been able to develop somethi
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()
@@ -92,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()
@@ -105,15 +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())
{
- // Rgba32 is our default PixelFormat, equivalent to System.Drawing Color
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.
@@ -121,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.
diff --git a/src/ImageSharp.Drawing/Brushes/Brushes.cs b/src/ImageSharp.Drawing/Brushes/Brushes.cs
index 8998c60f6..e39f3dd49 100644
--- a/src/ImageSharp.Drawing/Brushes/Brushes.cs
+++ b/src/ImageSharp.Drawing/Brushes/Brushes.cs
@@ -8,149 +8,251 @@ 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(Rgba32 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(Rgba32 foreColor)
- => new PatternBrush(Brushes.Percent10(foreColor, Rgba32.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(Rgba32 foreColor, Rgba32 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(Rgba32 foreColor)
- => new PatternBrush(Brushes.Percent20(foreColor, Rgba32.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(Rgba32 foreColor, Rgba32 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(Rgba32 foreColor)
- => new PatternBrush(Brushes.Horizontal(foreColor, Rgba32.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(Rgba32 foreColor, Rgba32 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(Rgba32 foreColor)
- => new PatternBrush(Brushes.Min(foreColor, Rgba32.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(Rgba32 foreColor, Rgba32 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(Rgba32 foreColor)
- => new PatternBrush(Brushes.Vertical(foreColor, Rgba32.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(Rgba32 foreColor, Rgba32 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(Rgba32 foreColor)
- => new PatternBrush(Brushes.ForwardDiagonal(foreColor, Rgba32.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(Rgba32 foreColor, Rgba32 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(Rgba32 foreColor)
- => new PatternBrush(Brushes.BackwardDiagonal(foreColor, Rgba32.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(Rgba32 foreColor, Rgba32 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{TPixel}.cs b/src/ImageSharp.Drawing/Brushes/Brushes{TPixel}.cs
deleted file mode 100644
index 4b2f6c026..000000000
--- a/src/ImageSharp.Drawing/Brushes/Brushes{TPixel}.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 ImageSharp.PixelFormats;
-
- ///
- /// A collection of methods for creating generic brushes.
- ///
- /// The pixel format.
- /// A Brush
- public class Brushes
- where TPixel : 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(TPixel 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(TPixel foreColor, TPixel 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(TPixel foreColor, TPixel 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(TPixel foreColor, TPixel 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(TPixel foreColor, TPixel 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(TPixel foreColor, TPixel 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(TPixel foreColor, TPixel 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(TPixel foreColor, TPixel backColor)
- => new PatternBrush(foreColor, backColor, BackwardDiagonalPattern);
- }
-}
diff --git a/src/ImageSharp.Drawing/Brushes/ImageBrush.cs b/src/ImageSharp.Drawing/Brushes/ImageBrush.cs
deleted file mode 100644
index 6a3ff1d9d..000000000
--- a/src/ImageSharp.Drawing/Brushes/ImageBrush.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
-{
- using ImageSharp.PixelFormats;
-
- ///
- /// 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/PatternBrush.cs b/src/ImageSharp.Drawing/Brushes/PatternBrush.cs
deleted file mode 100644
index f00862fe7..000000000
--- a/src/ImageSharp.Drawing/Brushes/PatternBrush.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-//
-// Copyright (c) James Jackson-South and contributors.
-// Licensed under the Apache License, Version 2.0.
-//
-
-namespace ImageSharp.Drawing.Brushes
-{
- using ImageSharp.PixelFormats;
-
- ///
- /// 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(Rgba32 foreColor, Rgba32 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/RecolorBrush.cs b/src/ImageSharp.Drawing/Brushes/RecolorBrush.cs
deleted file mode 100644
index bfe5c01e6..000000000
--- a/src/ImageSharp.Drawing/Brushes/RecolorBrush.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-//
-// Copyright (c) James Jackson-South and contributors.
-// Licensed under the Apache License, Version 2.0.
-//
-
-namespace ImageSharp.Drawing.Brushes
-{
- using ImageSharp.PixelFormats;
-
- ///
- /// 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(Rgba32 sourceColor, Rgba32 targeTPixel, float threshold)
- : base(sourceColor, targeTPixel, threshold)
- {
- }
- }
-}
diff --git a/src/ImageSharp.Drawing/Brushes/SolidBrush.cs b/src/ImageSharp.Drawing/Brushes/SolidBrush.cs
deleted file mode 100644
index 8a3ad50e7..000000000
--- a/src/ImageSharp.Drawing/Brushes/SolidBrush.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
-{
- using ImageSharp.PixelFormats;
-
- ///
- /// 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(Rgba32 color)
- : base(color)
- {
- }
- }
-}
diff --git a/src/ImageSharp.Drawing/DrawImage.cs b/src/ImageSharp.Drawing/DrawImage.cs
index acc821292..975bce9ed 100644
--- a/src/ImageSharp.Drawing/DrawImage.cs
+++ b/src/ImageSharp.Drawing/DrawImage.cs
@@ -5,13 +5,11 @@
namespace ImageSharp
{
- using System;
using Drawing.Processors;
- using ImageSharp.Drawing;
using ImageSharp.PixelFormats;
///
- /// Extension methods for the type.
+ /// Extension methods for the type.
///
public static partial class ImageExtensions
{
diff --git a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
index 15b7df2a2..a3552a09c 100644
--- a/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
+++ b/src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
@@ -2,7 +2,7 @@
An extension to ImageSharp that allows the drawing of images, paths, and text.
ImageSharp.Drawing
- 1.0.0-alpha8
+ 1.0.0-alpha9
James Jackson-South and contributors
netstandard1.1
true
diff --git a/src/ImageSharp.Drawing/Pens/Pen.cs b/src/ImageSharp.Drawing/Pens/Pen.cs
deleted file mode 100644
index a3cc3cbdf..000000000
--- a/src/ImageSharp.Drawing/Pens/Pen.cs
+++ /dev/null
@@ -1,55 +0,0 @@
-//
-// Copyright (c) James Jackson-South and contributors.
-// Licensed under the Apache License, Version 2.0.
-//
-
-namespace ImageSharp.Drawing.Pens
-{
- using ImageSharp.PixelFormats;
-
- ///
- /// Represents a in the color space.
- ///
- public class Pen : Pen
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The color.
- /// The width.
- public Pen(Rgba32 color, float width)
- : base(color, width)
- {
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The brush.
- /// The width.
- public Pen(IBrush brush, float width)
- : base(brush, width)
- {
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The brush.
- /// The width.
- /// The pattern.
- public Pen(IBrush brush, float width, float[] pattern)
- : base(brush, width, pattern)
- {
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The pen.
- internal Pen(Pen pen)
- : base(pen)
- {
- }
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Pens/Pens.cs b/src/ImageSharp.Drawing/Pens/Pens.cs
index 5c91df226..364115cb7 100644
--- a/src/ImageSharp.Drawing/Pens/Pens.cs
+++ b/src/ImageSharp.Drawing/Pens/Pens.cs
@@ -10,86 +10,121 @@ namespace ImageSharp.Drawing.Pens
///
/// Common Pen styles
///
- public class Pens
+ public static class Pens
{
+ private static readonly float[] DashDotPattern = new[] { 3f, 1f, 1f, 1f };
+ private static readonly float[] DashDotDotPattern = new[] { 3f, 1f, 1f, 1f, 1f, 1f };
+ private static readonly float[] DottedPattern = new[] { 1f, 1f };
+ private static readonly float[] DashedPattern = new[] { 3f, 1f };
+
///
/// Create a solid pen with out any drawing patterns
///
/// The color.
/// The width.
+ /// The type of the color.
/// The Pen
- public static Pen Solid(Rgba32 color, float width) => new Pen(color, width);
+ public static Pen Solid(TPixel color, float width)
+ where TPixel : struct, IPixel
+ => new Pen(color, width);
///
/// Create a solid pen with out any drawing patterns
///
/// The brush.
/// The width.
+ /// The type of the color.
/// The Pen
- public static Pen Solid(IBrush brush, float width) => new Pen(brush, width);
+ public static Pen Solid(IBrush brush, float width)
+ where TPixel : struct, IPixel
+ => new Pen(brush, width);
///
/// Create a pen with a 'Dash' drawing patterns
///
/// The color.
/// The width.
+ /// The type of the color.
/// The Pen
- public static Pen Dash(Rgba32 color, float width) => new Pen(Pens.Dash(color, width));
+ public static Pen Dash(TPixel color, float width)
+ where TPixel : struct, IPixel
+ => new Pen(color, width, DashedPattern);
///
/// Create a pen with a 'Dash' drawing patterns
///
/// The brush.
/// The width.
+ /// The type of the color.
/// The Pen
- public static Pen Dash(IBrush brush, float width) => new Pen(Pens.Dash(brush, width));
+ public static Pen Dash(IBrush brush, float width)
+ where TPixel : struct, IPixel
+ => new Pen(brush, width, DashedPattern);
///
/// Create a pen with a 'Dot' drawing patterns
///
/// The color.
/// The width.
+ /// The type of the color.
/// The Pen
- public static Pen Dot(Rgba32 color, float width) => new Pen(Pens.Dot(color, width));
+ public static Pen Dot(TPixel color, float width)
+ where TPixel : struct, IPixel
+ => new Pen(color, width, DottedPattern);
///
/// Create a pen with a 'Dot' drawing patterns
///
/// The brush.
/// The width.
+ /// The type of the color.
/// The Pen
- public static Pen Dot(IBrush brush, float width) => new Pen(Pens.Dot(brush, width));
+ public static Pen Dot(IBrush brush, float width)
+ where TPixel : struct, IPixel
+ => new Pen(brush, width, DottedPattern);
///
/// Create a pen with a 'Dash Dot' drawing patterns
///
/// The color.
/// The width.
+ /// The type of the color.
/// The Pen
- public static Pen DashDot(Rgba32 color, float width) => new Pen(Pens.DashDot(color, width));
+ public static Pen DashDot(TPixel color, float width)
+ where TPixel : struct, IPixel
+ => new Pen(color, width, DashDotPattern);
///
/// Create a pen with a 'Dash Dot' drawing patterns
///
/// The brush.
/// The width.
+ /// The type of the color.
/// The Pen
- public static Pen DashDot(IBrush brush, float width) => new Pen(Pens.DashDot(brush, width));
+ public static Pen DashDot(IBrush brush, float width)
+ where TPixel : struct, IPixel
+ => new Pen(brush, width, DashDotPattern);
///
/// Create a pen with a 'Dash Dot Dot' drawing patterns
///
/// The color.
/// The width.
+ /// The type of the color.
/// The Pen
- public static Pen DashDotDot(Rgba32 color, float width) => new Pen(Pens.DashDotDot(color, width));
+ public static Pen DashDotDot(TPixel color, float width)
+ where TPixel : struct, IPixel
+ => new Pen(color, width, DashDotDotPattern);
///
/// Create a pen with a 'Dash Dot Dot' drawing patterns
///
/// The brush.
/// The width.
+ /// The type of the color.
/// The Pen
- public static Pen DashDotDot(IBrush brush, float width) => new Pen(Pens.DashDotDot(brush, width));
+ public static Pen DashDotDot(IBrush brush, float width)
+ where TPixel : struct, IPixel
+ => new Pen(brush, width, DashDotDotPattern);
}
}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Pens/Pens{TPixel}.cs b/src/ImageSharp.Drawing/Pens/Pens{TPixel}.cs
deleted file mode 100644
index 5eb78dc44..000000000
--- a/src/ImageSharp.Drawing/Pens/Pens{TPixel}.cs
+++ /dev/null
@@ -1,112 +0,0 @@
-//
-// Copyright (c) James Jackson-South and contributors.
-// Licensed under the Apache License, Version 2.0.
-//
-
-namespace ImageSharp.Drawing.Pens
-{
- using ImageSharp.PixelFormats;
-
- ///
- /// Common Pen styles
- ///
- /// The type of the color.
- public class Pens
- where TPixel : struct, IPixel
- {
- private static readonly float[] DashDotPattern = new[] { 3f, 1f, 1f, 1f };
- private static readonly float[] DashDotDotPattern = new[] { 3f, 1f, 1f, 1f, 1f, 1f };
- private static readonly float[] DottedPattern = new[] { 1f, 1f };
- private static readonly float[] DashedPattern = new[] { 3f, 1f };
-
- ///
- /// Create a solid pen with out any drawing patterns
- ///
- /// The color.
- /// The width.
- /// The Pen
- public static Pen Solid(TPixel color, float width)
- => new Pen(color, width);
-
- ///
- /// Create a solid pen with out any drawing patterns
- ///
- /// The brush.
- /// The width.
- /// The Pen
- public static Pen Solid(IBrush brush, float width)
- => new Pen(brush, width);
-
- ///
- /// Create a pen with a 'Dash' drawing patterns
- ///
- /// The color.
- /// The width.
- /// The Pen
- public static Pen Dash(TPixel color, float width)
- => new Pen(color, width, DashedPattern);
-
- ///
- /// Create a pen with a 'Dash' drawing patterns
- ///
- /// The brush.
- /// The width.
- /// The Pen
- public static Pen Dash(IBrush brush, float width)
- => new Pen(brush, width, DashedPattern);
-
- ///
- /// Create a pen with a 'Dot' drawing patterns
- ///
- /// The color.
- /// The width.
- /// The Pen
- public static Pen Dot(TPixel color, float width)
- => new Pen(color, width, DottedPattern);
-
- ///
- /// Create a pen with a 'Dot' drawing patterns
- ///
- /// The brush.
- /// The width.
- /// The Pen
- public static Pen Dot(IBrush brush, float width)
- => new Pen(brush, width, DottedPattern);
-
- ///
- /// Create a pen with a 'Dash Dot' drawing patterns
- ///
- /// The color.
- /// The width.
- /// The Pen
- public static Pen DashDot(TPixel color, float width)
- => new Pen(color, width, DashDotPattern);
-
- ///
- /// Create a pen with a 'Dash Dot' drawing patterns
- ///
- /// The brush.
- /// The width.
- /// The Pen
- public static Pen DashDot(IBrush brush, float width)
- => new Pen(brush, width, DashDotPattern);
-
- ///
- /// Create a pen with a 'Dash Dot Dot' drawing patterns
- ///
- /// The color.
- /// The width.
- /// The Pen
- public static Pen DashDotDot(TPixel color, float width)
- => new Pen(color, width, DashDotDotPattern);
-
- ///
- /// Create a pen with a 'Dash Dot Dot' drawing patterns
- ///
- /// The brush.
- /// The width.
- /// The Pen
- public static Pen DashDotDot(IBrush brush, float width)
- => new Pen(brush, width, DashDotDotPattern);
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp.Drawing/Text/DrawText.cs b/src/ImageSharp.Drawing/Text/DrawText.cs
index 1e87fd008..bd33289fa 100644
--- a/src/ImageSharp.Drawing/Text/DrawText.cs
+++ b/src/ImageSharp.Drawing/Text/DrawText.cs
@@ -54,7 +54,7 @@ namespace ImageSharp
public static Image DrawText(this Image source, string text, Font font, TPixel color, Vector2 location, TextGraphicsOptions options)
where TPixel : struct, IPixel
{
- return source.DrawText(text, font, Brushes.Solid(color), null, location, options);
+ return source.DrawText(text, font, Brushes.Solid(color), null, location, options);
}
///
diff --git a/src/ImageSharp/Common/Helpers/ImageMaths.cs b/src/ImageSharp/Common/Helpers/ImageMaths.cs
index 25df0ebf0..0bfcec361 100644
--- a/src/ImageSharp/Common/Helpers/ImageMaths.cs
+++ b/src/ImageSharp/Common/Helpers/ImageMaths.cs
@@ -159,7 +159,7 @@ namespace ImageSharp
/// than the given one.
///
/// The pixel format.
- /// The to search within.
+ /// The to search within.
/// The color component value to remove.
/// The channel to test against.
///
diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
index a9aac5efa..dd91aa11d 100644
--- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
@@ -127,7 +127,7 @@ namespace ImageSharp.Formats
+ $"bigger then the max allowed size '{Image.MaxWidth}x{Image.MaxHeight}'");
}
- Image image = Image.Create(this.infoHeader.Width, this.infoHeader.Height, this.configuration);
+ Image image = new Image(this.configuration, this.infoHeader.Width, this.infoHeader.Height);
using (PixelAccessor pixels = image.Lock())
{
switch (this.infoHeader.Compression)
diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
index 589b7037a..272e4d075 100644
--- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
+++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
@@ -366,7 +366,7 @@ namespace ImageSharp.Formats
this.metaData.Quality = colorTableLength / 3;
// This initializes the image to become fully transparent because the alpha channel is zero.
- this.image = Image.Create(imageWidth, imageHeight, this.metaData, this.configuration);
+ this.image = new Image(this.configuration, imageWidth, imageHeight, this.metaData);
this.SetFrameMetaData(this.metaData);
diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
index 9df21a3b7..22c14ca4e 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
@@ -482,7 +482,7 @@ namespace ImageSharp.Formats
private Image ConvertJpegPixelsToImagePixels(ImageMetaData metadata)
where TPixel : struct, IPixel
{
- Image image = Image.Create(this.ImageWidth, this.ImageHeight, metadata, this.configuration);
+ Image image = new Image(this.configuration, this.ImageWidth, this.ImageHeight, metadata);
if (this.grayImage.IsInitialized)
{
diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs
index 904aa1ff6..67a00efef 100644
--- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs
+++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs
@@ -335,7 +335,7 @@ namespace ImageSharp.Formats
throw new ArgumentOutOfRangeException($"The input png '{this.header.Width}x{this.header.Height}' is bigger than the max allowed size '{Image.MaxWidth}x{Image.MaxHeight}'");
}
- image = Image.Create(this.header.Width, this.header.Height, metadata, this.configuration);
+ image = new Image(this.configuration, this.header.Width, this.header.Height, metadata);
pixels = image.Lock();
this.bytesPerPixel = this.CalculateBytesPerPixel();
this.bytesPerScanline = this.CalculateScanlineLength(this.header.Width) + 1;
diff --git a/src/ImageSharp/Image.Create.cs b/src/ImageSharp/Image.Create.cs
deleted file mode 100644
index 3d92cd66b..000000000
--- a/src/ImageSharp/Image.Create.cs
+++ /dev/null
@@ -1,62 +0,0 @@
-//
-// Copyright (c) James Jackson-South and contributors.
-// Licensed under the Apache License, Version 2.0.
-//
-
-namespace ImageSharp
-{
- using ImageSharp.PixelFormats;
-
- ///
- /// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha
- /// packed into a single unsigned integer value.
- ///
- public sealed partial class Image
- {
- ///
- /// Create a new instance of the class
- /// with the height and the width of the image.
- ///
- /// The pixel format.
- /// The width of the image in pixels.
- /// The height of the image in pixels.
- /// The images matadata to preload.
- ///
- /// The configuration providing initialization code which allows extending the library.
- ///
- ///
- /// A new unless is in which case it returns
- ///
- internal static Image Create(int width, int height, ImageMetaData metadata, Configuration configuration)
- where TPixel : struct, IPixel
- {
- if (typeof(TPixel) == typeof(Rgba32))
- {
- return new Image(width, height, metadata, configuration) as Image;
- }
- else
- {
- return new Image(width, height, metadata, configuration);
- }
- }
-
- ///
- /// Create a new instance of the class
- /// with the height and the width of the image.
- ///
- /// The pixel format.
- /// The width of the image in pixels.
- /// The height of the image in pixels.
- ///
- /// The configuration providing initialization code which allows extending the library.
- ///
- ///
- /// A new unless is in which case it returns
- ///
- internal static Image Create(int width, int height, Configuration configuration)
- where TPixel : struct, IPixel
- {
- return Image.Create(width, height, null, configuration);
- }
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp/Image.cs b/src/ImageSharp/Image.cs
deleted file mode 100644
index 3d33e6263..000000000
--- a/src/ImageSharp/Image.cs
+++ /dev/null
@@ -1,69 +0,0 @@
-//
-// Copyright (c) James Jackson-South and contributors.
-// Licensed under the Apache License, Version 2.0.
-//
-
-namespace ImageSharp
-{
- using System.Diagnostics;
- using ImageSharp.PixelFormats;
-
- ///
- /// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha
- /// packed into a single unsigned integer value.
- ///
- [DebuggerDisplay("Image: {Width}x{Height}")]
- public sealed partial class Image : Image
- {
- ///
- /// Initializes a new instance of the class
- /// with the height and the width of the image.
- ///
- /// The width of the image in pixels.
- /// The height of the image in pixels.
- ///
- /// The configuration providing initialization code which allows extending the library.
- ///
- public Image(int width, int height, Configuration configuration)
- : base(width, height, configuration)
- {
- }
-
- ///
- /// Initializes a new instance of the class
- /// with the height and the width of the image.
- ///
- /// The width of the image in pixels.
- /// The height of the image in pixels.
- public Image(int width, int height)
- : this(width, height, null)
- {
- }
-
- ///
- /// Initializes a new instance of the class
- /// by making a copy from another image.
- ///
- /// The other image, where the clone should be made from.
- /// is null.
- public Image(Image other)
- : base(other)
- {
- }
-
- ///
- /// Initializes a new instance of the class
- /// with the height and the width of the image.
- ///
- /// The width of the image in pixels.
- /// The height of the image in pixels.
- /// The metadata.
- ///
- /// The configuration providing initialization code which allows extending the library.
- ///
- internal Image(int width, int height, ImageMetaData metadata, Configuration configuration)
- : base(width, height, metadata, configuration)
- {
- }
- }
-}
\ No newline at end of file
diff --git a/src/ImageSharp/Image.Decode.cs b/src/ImageSharp/Image/Image.Decode.cs
similarity index 88%
rename from src/ImageSharp/Image.Decode.cs
rename to src/ImageSharp/Image/Image.Decode.cs
index b0e476280..c162f1772 100644
--- a/src/ImageSharp/Image.Decode.cs
+++ b/src/ImageSharp/Image/Image.Decode.cs
@@ -12,11 +12,10 @@ namespace ImageSharp
using ImageSharp.PixelFormats;
- ///
- /// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha
- /// packed into a single unsigned integer value.
- ///
- public sealed partial class Image
+ ///
+ /// Adds static methods allowing the decoding of new images.
+ ///
+ public static partial class Image
{
///
/// By reading the header on the provided stream this calculates the images format.
@@ -53,15 +52,15 @@ namespace ImageSharp
///
/// Decodes the image stream to the current image.
///
- /// The pixel format.
/// The stream.
/// The options for the decoder.
/// the configuration.
+ /// The pixel format.
///
- /// The decoded image
+ /// A new .
///
private static Image Decode(Stream stream, IDecoderOptions options, Configuration config)
- where TPixel : struct, IPixel
+ where TPixel : struct, IPixel
{
IImageFormat format = DiscoverFormat(stream, config);
if (format == null)
@@ -74,4 +73,4 @@ namespace ImageSharp
return img;
}
}
-}
+}
\ No newline at end of file
diff --git a/src/ImageSharp/Image.FromBytes.cs b/src/ImageSharp/Image/Image.FromBytes.cs
similarity index 51%
rename from src/ImageSharp/Image.FromBytes.cs
rename to src/ImageSharp/Image/Image.FromBytes.cs
index 540eb6016..c7309c4b1 100644
--- a/src/ImageSharp/Image.FromBytes.cs
+++ b/src/ImageSharp/Image/Image.FromBytes.cs
@@ -1,122 +1,75 @@
-//
+//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
namespace ImageSharp
{
- using System;
using System.IO;
using Formats;
using ImageSharp.PixelFormats;
- ///
- /// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha
- /// packed into a single unsigned integer value.
- ///
- public sealed partial class Image
+ ///
+ /// Adds static methods allowing the creation of new image from a byte array.
+ ///
+ public static partial class Image
{
///
- /// Loads the image from the given byte array.
+ /// Create a new instance of the class from the given byte array.
///
/// The byte array containing image data.
- ///
- /// Thrown if the stream is not readable nor seekable.
- ///
- /// The image
- public static Image Load(byte[] data)
- {
- return Load(null, data, null);
- }
+ /// A new .
+ public static Image Load(byte[] data) => Load(null, data, null);
///
- /// Loads the image from the given byte array.
+ /// Create a new instance of the class from the given byte array.
///
/// The byte array containing image data.
/// The options for the decoder.
- ///
- /// Thrown if the stream is not readable nor seekable.
- ///
- /// The image
- public static Image Load(byte[] data, IDecoderOptions options)
- {
- return Load(null, data, options);
- }
+ /// A new .
+ public static Image Load(byte[] data, IDecoderOptions options) => Load(null, data, options);
///