Browse Source

Merge pull request #209 from JimBobSquarePants/chore/remove-non-generic-image

Remove non generic image
pull/210/head
James Jackson-South 9 years ago
committed by GitHub
parent
commit
1a76736296
  1. 25
      README.md
  2. 252
      src/ImageSharp.Drawing/Brushes/Brushes.cs
  3. 168
      src/ImageSharp.Drawing/Brushes/Brushes{TPixel}.cs
  4. 24
      src/ImageSharp.Drawing/Brushes/ImageBrush.cs
  5. 35
      src/ImageSharp.Drawing/Brushes/PatternBrush.cs
  6. 26
      src/ImageSharp.Drawing/Brushes/RecolorBrush.cs
  7. 24
      src/ImageSharp.Drawing/Brushes/SolidBrush.cs
  8. 4
      src/ImageSharp.Drawing/DrawImage.cs
  9. 2
      src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
  10. 55
      src/ImageSharp.Drawing/Pens/Pen.cs
  11. 57
      src/ImageSharp.Drawing/Pens/Pens.cs
  12. 112
      src/ImageSharp.Drawing/Pens/Pens{TPixel}.cs
  13. 2
      src/ImageSharp.Drawing/Text/DrawText.cs
  14. 2
      src/ImageSharp/Common/Helpers/ImageMaths.cs
  15. 2
      src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
  16. 2
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs
  17. 2
      src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
  18. 2
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  19. 62
      src/ImageSharp/Image.Create.cs
  20. 69
      src/ImageSharp/Image.cs
  21. 17
      src/ImageSharp/Image/Image.Decode.cs
  22. 146
      src/ImageSharp/Image/Image.FromBytes.cs
  23. 109
      src/ImageSharp/Image/Image.FromFile.cs
  24. 131
      src/ImageSharp/Image/Image.FromStream.cs
  25. 6
      src/ImageSharp/Image/ImageBase{TPixel}.cs
  26. 2
      src/ImageSharp/Image/ImageFrame{TPixel}.cs
  27. 22
      src/ImageSharp/Image/Image{TPixel}.cs
  28. 2
      src/ImageSharp/ImageSharp.csproj
  29. 1
      src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs
  30. 6
      src/ImageSharp/PixelFormats/README.md
  31. 2
      src/ImageSharp/PixelFormats/Rgba32.ColorspaceTransforms.cs
  32. 4
      src/ImageSharp/PixelFormats/Rgba32.Definitions.cs
  33. 4
      src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs
  34. 4
      src/ImageSharp/PixelFormats/Rgba32.cs
  35. 6
      src/ImageSharp/Processing/Binarization/Dither.cs
  36. 4
      src/ImageSharp/Processing/ColorMatrix/Sepia.cs
  37. 4
      src/ImageSharp/Processing/Effects/Alpha.cs
  38. 4
      src/ImageSharp/Processing/Effects/BackgroundColor.cs
  39. 4
      src/ImageSharp/Processing/Effects/Invert.cs
  40. 0
      src/ImageSharp/Processing/ImageProcessor.cs
  41. 2
      src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs
  42. 2
      src/ImageSharp/Processing/Transforms/AutoOrient.cs
  43. 2
      src/ImageSharp/Processing/Transforms/Crop.cs
  44. 2
      src/ImageSharp/Processing/Transforms/EntropyCrop.cs
  45. 2
      src/ImageSharp/Processing/Transforms/Flip.cs
  46. 6
      src/ImageSharp/Processing/Transforms/Rotate.cs
  47. 2
      src/ImageSharp/Processing/Transforms/RotateFlip.cs
  48. 4
      src/ImageSharp/Processing/Transforms/Skew.cs
  49. 5
      tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs
  50. 6
      tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs
  51. 5
      tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs
  52. 6
      tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs
  53. 5
      tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs
  54. 8
      tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs
  55. 6
      tests/ImageSharp.Benchmarks/Image/CopyPixels.cs
  56. 3
      tests/ImageSharp.Benchmarks/Image/DecodeBmp.cs
  57. 3
      tests/ImageSharp.Benchmarks/Image/DecodeFilteredPng.cs
  58. 3
      tests/ImageSharp.Benchmarks/Image/DecodeGif.cs
  59. 3
      tests/ImageSharp.Benchmarks/Image/DecodeJpeg.cs
  60. 7
      tests/ImageSharp.Benchmarks/Image/DecodeJpegMultiple.cs
  61. 3
      tests/ImageSharp.Benchmarks/Image/DecodePng.cs
  62. 5
      tests/ImageSharp.Benchmarks/Image/EncodeBmp.cs
  63. 5
      tests/ImageSharp.Benchmarks/Image/EncodeGif.cs
  64. 7
      tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs
  65. 5
      tests/ImageSharp.Benchmarks/Image/EncodeJpeg.cs
  66. 5
      tests/ImageSharp.Benchmarks/Image/EncodePng.cs
  67. 3
      tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs
  68. 14
      tests/ImageSharp.Benchmarks/Image/MultiImageBenchmarkBase.cs
  69. 7
      tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs
  70. 5
      tests/ImageSharp.Benchmarks/Samplers/Crop.cs
  71. 7
      tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs
  72. 6
      tests/ImageSharp.Benchmarks/Samplers/Glow.cs
  73. 10
      tests/ImageSharp.Benchmarks/Samplers/Resize.cs
  74. 3
      tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj
  75. 8
      tests/ImageSharp.Tests/ConfigurationTests.cs
  76. 4
      tests/ImageSharp.Tests/Drawing/BeziersTests.cs
  77. 4
      tests/ImageSharp.Tests/Drawing/DrawPathTests.cs
  78. 2
      tests/ImageSharp.Tests/Drawing/FillPatternTests.cs
  79. 4
      tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs
  80. 6
      tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs
  81. 10
      tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs
  82. 16
      tests/ImageSharp.Tests/Drawing/LineTests.cs
  83. 4
      tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs
  84. 4
      tests/ImageSharp.Tests/Drawing/Paths/DrawLinesTests.cs
  85. 6
      tests/ImageSharp.Tests/Drawing/Paths/DrawPath.cs
  86. 4
      tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs
  87. 4
      tests/ImageSharp.Tests/Drawing/Paths/DrawRectangle.cs
  88. 4
      tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs
  89. 6
      tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs
  90. 6
      tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs
  91. 2
      tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs
  92. 6
      tests/ImageSharp.Tests/Drawing/PolygonTests.cs
  93. 8
      tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs
  94. 4
      tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs
  95. 6
      tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs
  96. 24
      tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs
  97. 2
      tests/ImageSharp.Tests/Drawing/Text/DrawText.cs
  98. 2
      tests/ImageSharp.Tests/Drawing/Text/OutputText.cs
  99. 4
      tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs
  100. 22
      tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs

25
README.md

@ -1,5 +1,5 @@
# <img src="https://github.com/JimBobSquarePants/ImageSharp/blob/master/build/icons/imagesharp-logo-256.png" alt="ImageSharp" width="52"/> ImageSharp
# <img src="https://raw.githubusercontent.com/JimBobSquarePants/ImageSharp/master/build/icons/imagesharp-logo-256.png" alt="ImageSharp" width="52"/> 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<TPixel>` 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<TPixel>` 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<TPixel>(string path))
using (Image<Rgba32> 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<TPixel>(Stream stream))
using (FileStream stream = File.OpenRead("foo.jpg"))
using (FileStream output = File.OpenWrite("bar.jpg"))
using (Image image = Image.Load(stream))
using (Image<Rgba32> image = Image.Load<Rgba32>(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<Rgba32> image = new Image<Rgba32>(400, 400)
using (PixelAccessor<Rgba32> pixels = image.Lock())
{
// Rgba32 is our default PixelFormat, equivalent to System.Drawing Color
pixels[200, 200] = Rgba32.White;
}
```
For advanced usage the `Image<TPixel>` and `PixelAccessor<TPixel>` 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.

252
src/ImageSharp.Drawing/Brushes/Brushes.cs

@ -8,149 +8,251 @@ namespace ImageSharp.Drawing.Brushes
using ImageSharp.PixelFormats;
/// <summary>
/// A collection of methods for creating brushes. Brushes use <see cref="Rgba32"/> for painting.
/// A collection of methods for creating generic brushes.
/// </summary>
public class Brushes
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static class Brushes
{
/// <summary>
/// Percent10 Hatch Pattern
/// </summary>
/// ---> 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 }
};
/// <summary>
/// Percent20 pattern.
/// </summary>
private static readonly bool[,] Percent20Pattern =
{
{ true, false, false, false },
{ false, false, true, false },
{ true, false, false, false },
{ false, false, true, false }
};
/// <summary>
/// Horizontal Hatch Pattern
/// </summary>
private static readonly bool[,] HorizontalPattern =
{
{ false },
{ true },
{ false },
{ false }
};
/// <summary>
/// Min Pattern
/// </summary>
private static readonly bool[,] MinPattern =
{
{ false },
{ false },
{ false },
{ true }
};
/// <summary>
/// Vertical Pattern
/// </summary>
private static readonly bool[,] VerticalPattern =
{
{ false, true, false, false },
};
/// <summary>
/// Forward Diagonal Pattern
/// </summary>
private static readonly bool[,] ForwardDiagonalPattern =
{
{ false, false, false, true },
{ false, false, true, false },
{ false, true, false, false },
{ true, false, false, false }
};
/// <summary>
/// Backward Diagonal Pattern
/// </summary>
private static readonly bool[,] BackwardDiagonalPattern =
{
{ true, false, false, false },
{ false, true, false, false },
{ false, false, true, false },
{ false, false, false, true }
};
/// <summary>
/// Create as brush that will paint a solid color
/// </summary>
/// <param name="color">The color.</param>
/// <returns>A Brush</returns>
public static SolidBrush Solid(Rgba32 color)
=> new SolidBrush(color);
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static SolidBrush<TPixel> Solid<TPixel>(TPixel color)
where TPixel : struct, IPixel<TPixel>
=> new SolidBrush<TPixel>(color);
/// <summary>
/// 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
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns>
public static PatternBrush Percent10(Rgba32 foreColor)
=> new PatternBrush(Brushes<Rgba32>.Percent10(foreColor, Rgba32.Transparent));
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> Percent10<TPixel>(TPixel foreColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, NamedColors<TPixel>.Transparent, Percent10Pattern);
/// <summary>
/// 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
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush Percent10(Rgba32 foreColor, Rgba32 backColor)
=> new PatternBrush(Brushes<Rgba32>.Percent10(foreColor, backColor));
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> Percent10<TPixel>(TPixel foreColor, TPixel backColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, backColor, Percent10Pattern);
/// <summary>
/// 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.
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns>
public static PatternBrush Percent20(Rgba32 foreColor)
=> new PatternBrush(Brushes<Rgba32>.Percent20(foreColor, Rgba32.Transparent));
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> Percent20<TPixel>(TPixel foreColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, NamedColors<TPixel>.Transparent, Percent20Pattern);
/// <summary>
/// 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
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush Percent20(Rgba32 foreColor, Rgba32 backColor)
=> new PatternBrush(Brushes<Rgba32>.Percent20(foreColor, backColor));
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> Percent20<TPixel>(TPixel foreColor, TPixel backColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, backColor, Percent20Pattern);
/// <summary>
/// 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.
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns>
public static PatternBrush Horizontal(Rgba32 foreColor)
=> new PatternBrush(Brushes<Rgba32>.Horizontal(foreColor, Rgba32.Transparent));
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> Horizontal<TPixel>(TPixel foreColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, NamedColors<TPixel>.Transparent, HorizontalPattern);
/// <summary>
/// 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
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush Horizontal(Rgba32 foreColor, Rgba32 backColor)
=> new PatternBrush(Brushes<Rgba32>.Horizontal(foreColor, backColor));
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> Horizontal<TPixel>(TPixel foreColor, TPixel backColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, backColor, HorizontalPattern);
/// <summary>
/// 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.
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns>
public static PatternBrush Min(Rgba32 foreColor)
=> new PatternBrush(Brushes<Rgba32>.Min(foreColor, Rgba32.Transparent));
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> Min<TPixel>(TPixel foreColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, NamedColors<TPixel>.Transparent, MinPattern);
/// <summary>
/// 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
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush Min(Rgba32 foreColor, Rgba32 backColor)
=> new PatternBrush(Brushes<Rgba32>.Min(foreColor, backColor));
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> Min<TPixel>(TPixel foreColor, TPixel backColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, backColor, MinPattern);
/// <summary>
/// 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.
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns>
public static PatternBrush Vertical(Rgba32 foreColor)
=> new PatternBrush(Brushes<Rgba32>.Vertical(foreColor, Rgba32.Transparent));
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> Vertical<TPixel>(TPixel foreColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, NamedColors<TPixel>.Transparent, VerticalPattern);
/// <summary>
/// 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
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush Vertical(Rgba32 foreColor, Rgba32 backColor)
=> new PatternBrush(Brushes<Rgba32>.Vertical(foreColor, backColor));
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> Vertical<TPixel>(TPixel foreColor, TPixel backColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, backColor, VerticalPattern);
/// <summary>
/// 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.
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns>
public static PatternBrush ForwardDiagonal(Rgba32 foreColor)
=> new PatternBrush(Brushes<Rgba32>.ForwardDiagonal(foreColor, Rgba32.Transparent));
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> ForwardDiagonal<TPixel>(TPixel foreColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, NamedColors<TPixel>.Transparent, ForwardDiagonalPattern);
/// <summary>
/// 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
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush ForwardDiagonal(Rgba32 foreColor, Rgba32 backColor)
=> new PatternBrush(Brushes<Rgba32>.ForwardDiagonal(foreColor, backColor));
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> ForwardDiagonal<TPixel>(TPixel foreColor, TPixel backColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, backColor, ForwardDiagonalPattern);
/// <summary>
/// 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.
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns>
public static PatternBrush BackwardDiagonal(Rgba32 foreColor)
=> new PatternBrush(Brushes<Rgba32>.BackwardDiagonal(foreColor, Rgba32.Transparent));
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> BackwardDiagonal<TPixel>(TPixel foreColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, NamedColors<TPixel>.Transparent, BackwardDiagonalPattern);
/// <summary>
/// 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
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush BackwardDiagonal(Rgba32 foreColor, Rgba32 backColor)
=> new PatternBrush(Brushes<Rgba32>.BackwardDiagonal(foreColor, backColor));
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A New <see cref="PatternBrush{TPixel}"/></returns>
public static PatternBrush<TPixel> BackwardDiagonal<TPixel>(TPixel foreColor, TPixel backColor)
where TPixel : struct, IPixel<TPixel>
=> new PatternBrush<TPixel>(foreColor, backColor, BackwardDiagonalPattern);
}
}

168
src/ImageSharp.Drawing/Brushes/Brushes{TPixel}.cs

@ -1,168 +0,0 @@
// <copyright file="Brushes{TPixel}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Drawing.Brushes
{
using ImageSharp.PixelFormats;
/// <summary>
/// A collection of methods for creating generic brushes.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A Brush</returns>
public class Brushes<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Percent10 Hatch Pattern
/// </summary>
/// ---> 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 }
};
/// <summary>
/// Percent20 pattern.
/// </summary>
private static readonly bool[,] Percent20Pattern =
{
{ true, false, false, false },
{ false, false, true, false },
{ true, false, false, false },
{ false, false, true, false }
};
/// <summary>
/// Horizontal Hatch Pattern
/// </summary>
private static readonly bool[,] HorizontalPattern =
{
{ false },
{ true },
{ false },
{ false }
};
/// <summary>
/// Min Pattern
/// </summary>
private static readonly bool[,] MinPattern =
{
{ false },
{ false },
{ false },
{ true }
};
/// <summary>
/// Vertical Pattern
/// </summary>
private static readonly bool[,] VerticalPattern =
{
{ false, true, false, false },
};
/// <summary>
/// Forward Diagonal Pattern
/// </summary>
private static readonly bool[,] ForwardDiagonalPattern =
{
{ false, false, false, true },
{ false, false, true, false },
{ false, true, false, false },
{ true, false, false, false }
};
/// <summary>
/// Backward Diagonal Pattern
/// </summary>
private static readonly bool[,] BackwardDiagonalPattern =
{
{ true, false, false, false },
{ false, true, false, false },
{ false, false, true, false },
{ false, false, false, true }
};
/// <summary>
/// Create as brush that will paint a solid color
/// </summary>
/// <param name="color">The color.</param>
/// <returns>A Brush</returns>
public static SolidBrush<TPixel> Solid(TPixel color)
=> new SolidBrush<TPixel>(color);
/// <summary>
/// Create as brush that will paint a Percent10 Hatch Pattern within the specified colors
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush<TPixel> Percent10(TPixel foreColor, TPixel backColor)
=> new PatternBrush<TPixel>(foreColor, backColor, Percent10Pattern);
/// <summary>
/// Create as brush that will paint a Percent20 Hatch Pattern within the specified colors
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush<TPixel> Percent20(TPixel foreColor, TPixel backColor)
=> new PatternBrush<TPixel>(foreColor, backColor, Percent20Pattern);
/// <summary>
/// Create as brush that will paint a Horizontal Hatch Pattern within the specified colors
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush<TPixel> Horizontal(TPixel foreColor, TPixel backColor)
=> new PatternBrush<TPixel>(foreColor, backColor, HorizontalPattern);
/// <summary>
/// Create as brush that will paint a Min Hatch Pattern within the specified colors
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush<TPixel> Min(TPixel foreColor, TPixel backColor)
=> new PatternBrush<TPixel>(foreColor, backColor, MinPattern);
/// <summary>
/// Create as brush that will paint a Vertical Hatch Pattern within the specified colors
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush<TPixel> Vertical(TPixel foreColor, TPixel backColor)
=> new PatternBrush<TPixel>(foreColor, backColor, VerticalPattern);
/// <summary>
/// Create as brush that will paint a Forward Diagonal Hatch Pattern within the specified colors
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush<TPixel> ForwardDiagonal(TPixel foreColor, TPixel backColor)
=> new PatternBrush<TPixel>(foreColor, backColor, ForwardDiagonalPattern);
/// <summary>
/// Create as brush that will paint a Backward Diagonal Hatch Pattern within the specified colors
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush<TPixel> BackwardDiagonal(TPixel foreColor, TPixel backColor)
=> new PatternBrush<TPixel>(foreColor, backColor, BackwardDiagonalPattern);
}
}

24
src/ImageSharp.Drawing/Brushes/ImageBrush.cs

@ -1,24 +0,0 @@
// <copyright file="ImageBrush.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Drawing.Brushes
{
using ImageSharp.PixelFormats;
/// <summary>
/// Provides an implementation of a solid brush for painting with repeating images. The brush uses <see cref="Rgba32"/> for painting.
/// </summary>
public class ImageBrush : ImageBrush<Rgba32>
{
/// <summary>
/// Initializes a new instance of the <see cref="ImageBrush" /> class.
/// </summary>
/// <param name="image">The image to paint.</param>
public ImageBrush(IImageBase<Rgba32> image)
: base(image)
{
}
}
}

35
src/ImageSharp.Drawing/Brushes/PatternBrush.cs

@ -1,35 +0,0 @@
// <copyright file="PatternBrush.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Drawing.Brushes
{
using ImageSharp.PixelFormats;
/// <summary>
/// Provides an implementation of a pattern brush for painting patterns. The brush use <see cref="Rgba32"/> for painting.
/// </summary>
public class PatternBrush : PatternBrush<Rgba32>
{
/// <summary>
/// Initializes a new instance of the <see cref="PatternBrush"/> class.
/// </summary>
/// <param name="foreColor">Color of the fore.</param>
/// <param name="backColor">Color of the back.</param>
/// <param name="pattern">The pattern.</param>
public PatternBrush(Rgba32 foreColor, Rgba32 backColor, bool[,] pattern)
: base(foreColor, backColor, pattern)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="PatternBrush"/> class.
/// </summary>
/// <param name="brush">The brush.</param>
internal PatternBrush(PatternBrush<Rgba32> brush)
: base(brush)
{
}
}
}

26
src/ImageSharp.Drawing/Brushes/RecolorBrush.cs

@ -1,26 +0,0 @@
// <copyright file="RecolorBrush.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Drawing.Brushes
{
using ImageSharp.PixelFormats;
/// <summary>
/// Provides an implementation of a recolor brush for painting color changes.
/// </summary>
public class RecolorBrush : RecolorBrush<Rgba32>
{
/// <summary>
/// Initializes a new instance of the <see cref="RecolorBrush" /> class.
/// </summary>
/// <param name="sourceColor">Color of the source.</param>
/// <param name="targeTPixel">Color of the target.</param>
/// <param name="threshold">The threshold.</param>
public RecolorBrush(Rgba32 sourceColor, Rgba32 targeTPixel, float threshold)
: base(sourceColor, targeTPixel, threshold)
{
}
}
}

24
src/ImageSharp.Drawing/Brushes/SolidBrush.cs

@ -1,24 +0,0 @@
// <copyright file="SolidBrush.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Drawing.Brushes
{
using ImageSharp.PixelFormats;
/// <summary>
/// Provides an implementation of a solid brush for painting solid color areas. The brush uses <see cref="Rgba32"/> for painting.
/// </summary>
public class SolidBrush : SolidBrush<Rgba32>
{
/// <summary>
/// Initializes a new instance of the <see cref="SolidBrush" /> class.
/// </summary>
/// <param name="color">The color.</param>
public SolidBrush(Rgba32 color)
: base(color)
{
}
}
}

4
src/ImageSharp.Drawing/DrawImage.cs

@ -5,13 +5,11 @@
namespace ImageSharp
{
using System;
using Drawing.Processors;
using ImageSharp.Drawing;
using ImageSharp.PixelFormats;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
{

2
src/ImageSharp.Drawing/ImageSharp.Drawing.csproj

@ -2,7 +2,7 @@
<PropertyGroup>
<Description>An extension to ImageSharp that allows the drawing of images, paths, and text.</Description>
<AssemblyTitle>ImageSharp.Drawing</AssemblyTitle>
<VersionPrefix>1.0.0-alpha8</VersionPrefix>
<VersionPrefix>1.0.0-alpha9</VersionPrefix>
<Authors>James Jackson-South and contributors</Authors>
<TargetFramework>netstandard1.1</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

55
src/ImageSharp.Drawing/Pens/Pen.cs

@ -1,55 +0,0 @@
// <copyright file="Pen.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Drawing.Pens
{
using ImageSharp.PixelFormats;
/// <summary>
/// Represents a <see cref="Pen{TPixel}"/> in the <see cref="Rgba32"/> color space.
/// </summary>
public class Pen : Pen<Rgba32>
{
/// <summary>
/// Initializes a new instance of the <see cref="Pen"/> class.
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
public Pen(Rgba32 color, float width)
: base(color, width)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Pen"/> class.
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
public Pen(IBrush<Rgba32> brush, float width)
: base(brush, width)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Pen"/> class.
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <param name="pattern">The pattern.</param>
public Pen(IBrush<Rgba32> brush, float width, float[] pattern)
: base(brush, width, pattern)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Pen"/> class.
/// </summary>
/// <param name="pen">The pen.</param>
internal Pen(Pen<Rgba32> pen)
: base(pen)
{
}
}
}

57
src/ImageSharp.Drawing/Pens/Pens.cs

@ -10,86 +10,121 @@ namespace ImageSharp.Drawing.Pens
/// <summary>
/// Common Pen styles
/// </summary>
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 };
/// <summary>
/// Create a solid pen with out any drawing patterns
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <returns>The Pen</returns>
public static Pen Solid(Rgba32 color, float width) => new Pen(color, width);
public static Pen<TPixel> Solid<TPixel>(TPixel color, float width)
where TPixel : struct, IPixel<TPixel>
=> new Pen<TPixel>(color, width);
/// <summary>
/// Create a solid pen with out any drawing patterns
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <returns>The Pen</returns>
public static Pen Solid(IBrush<Rgba32> brush, float width) => new Pen(brush, width);
public static Pen<TPixel> Solid<TPixel>(IBrush<TPixel> brush, float width)
where TPixel : struct, IPixel<TPixel>
=> new Pen<TPixel>(brush, width);
/// <summary>
/// Create a pen with a 'Dash' drawing patterns
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <returns>The Pen</returns>
public static Pen Dash(Rgba32 color, float width) => new Pen(Pens<Rgba32>.Dash(color, width));
public static Pen<TPixel> Dash<TPixel>(TPixel color, float width)
where TPixel : struct, IPixel<TPixel>
=> new Pen<TPixel>(color, width, DashedPattern);
/// <summary>
/// Create a pen with a 'Dash' drawing patterns
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <returns>The Pen</returns>
public static Pen Dash(IBrush<Rgba32> brush, float width) => new Pen(Pens<Rgba32>.Dash(brush, width));
public static Pen<TPixel> Dash<TPixel>(IBrush<TPixel> brush, float width)
where TPixel : struct, IPixel<TPixel>
=> new Pen<TPixel>(brush, width, DashedPattern);
/// <summary>
/// Create a pen with a 'Dot' drawing patterns
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <returns>The Pen</returns>
public static Pen Dot(Rgba32 color, float width) => new Pen(Pens<Rgba32>.Dot(color, width));
public static Pen<TPixel> Dot<TPixel>(TPixel color, float width)
where TPixel : struct, IPixel<TPixel>
=> new Pen<TPixel>(color, width, DottedPattern);
/// <summary>
/// Create a pen with a 'Dot' drawing patterns
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <returns>The Pen</returns>
public static Pen Dot(IBrush<Rgba32> brush, float width) => new Pen(Pens<Rgba32>.Dot(brush, width));
public static Pen<TPixel> Dot<TPixel>(IBrush<TPixel> brush, float width)
where TPixel : struct, IPixel<TPixel>
=> new Pen<TPixel>(brush, width, DottedPattern);
/// <summary>
/// Create a pen with a 'Dash Dot' drawing patterns
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <returns>The Pen</returns>
public static Pen DashDot(Rgba32 color, float width) => new Pen(Pens<Rgba32>.DashDot(color, width));
public static Pen<TPixel> DashDot<TPixel>(TPixel color, float width)
where TPixel : struct, IPixel<TPixel>
=> new Pen<TPixel>(color, width, DashDotPattern);
/// <summary>
/// Create a pen with a 'Dash Dot' drawing patterns
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <returns>The Pen</returns>
public static Pen DashDot(IBrush<Rgba32> brush, float width) => new Pen(Pens<Rgba32>.DashDot(brush, width));
public static Pen<TPixel> DashDot<TPixel>(IBrush<TPixel> brush, float width)
where TPixel : struct, IPixel<TPixel>
=> new Pen<TPixel>(brush, width, DashDotPattern);
/// <summary>
/// Create a pen with a 'Dash Dot Dot' drawing patterns
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <returns>The Pen</returns>
public static Pen DashDotDot(Rgba32 color, float width) => new Pen(Pens<Rgba32>.DashDotDot(color, width));
public static Pen<TPixel> DashDotDot<TPixel>(TPixel color, float width)
where TPixel : struct, IPixel<TPixel>
=> new Pen<TPixel>(color, width, DashDotDotPattern);
/// <summary>
/// Create a pen with a 'Dash Dot Dot' drawing patterns
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <returns>The Pen</returns>
public static Pen DashDotDot(IBrush<Rgba32> brush, float width) => new Pen(Pens<Rgba32>.DashDotDot(brush, width));
public static Pen<TPixel> DashDotDot<TPixel>(IBrush<TPixel> brush, float width)
where TPixel : struct, IPixel<TPixel>
=> new Pen<TPixel>(brush, width, DashDotDotPattern);
}
}

112
src/ImageSharp.Drawing/Pens/Pens{TPixel}.cs

@ -1,112 +0,0 @@
// <copyright file="Pens{TPixel}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Drawing.Pens
{
using ImageSharp.PixelFormats;
/// <summary>
/// Common Pen styles
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
public class Pens<TPixel>
where TPixel : struct, IPixel<TPixel>
{
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 };
/// <summary>
/// Create a solid pen with out any drawing patterns
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TPixel> Solid(TPixel color, float width)
=> new Pen<TPixel>(color, width);
/// <summary>
/// Create a solid pen with out any drawing patterns
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TPixel> Solid(IBrush<TPixel> brush, float width)
=> new Pen<TPixel>(brush, width);
/// <summary>
/// Create a pen with a 'Dash' drawing patterns
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TPixel> Dash(TPixel color, float width)
=> new Pen<TPixel>(color, width, DashedPattern);
/// <summary>
/// Create a pen with a 'Dash' drawing patterns
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TPixel> Dash(IBrush<TPixel> brush, float width)
=> new Pen<TPixel>(brush, width, DashedPattern);
/// <summary>
/// Create a pen with a 'Dot' drawing patterns
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TPixel> Dot(TPixel color, float width)
=> new Pen<TPixel>(color, width, DottedPattern);
/// <summary>
/// Create a pen with a 'Dot' drawing patterns
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TPixel> Dot(IBrush<TPixel> brush, float width)
=> new Pen<TPixel>(brush, width, DottedPattern);
/// <summary>
/// Create a pen with a 'Dash Dot' drawing patterns
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TPixel> DashDot(TPixel color, float width)
=> new Pen<TPixel>(color, width, DashDotPattern);
/// <summary>
/// Create a pen with a 'Dash Dot' drawing patterns
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TPixel> DashDot(IBrush<TPixel> brush, float width)
=> new Pen<TPixel>(brush, width, DashDotPattern);
/// <summary>
/// Create a pen with a 'Dash Dot Dot' drawing patterns
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TPixel> DashDotDot(TPixel color, float width)
=> new Pen<TPixel>(color, width, DashDotDotPattern);
/// <summary>
/// Create a pen with a 'Dash Dot Dot' drawing patterns
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TPixel> DashDotDot(IBrush<TPixel> brush, float width)
=> new Pen<TPixel>(brush, width, DashDotDotPattern);
}
}

2
src/ImageSharp.Drawing/Text/DrawText.cs

@ -54,7 +54,7 @@ namespace ImageSharp
public static Image<TPixel> DrawText<TPixel>(this Image<TPixel> source, string text, Font font, TPixel color, Vector2 location, TextGraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, Brushes<TPixel>.Solid(color), null, location, options);
return source.DrawText(text, font, Brushes.Solid(color), null, location, options);
}
/// <summary>

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

@ -159,7 +159,7 @@ namespace ImageSharp
/// than the given one.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="bitmap">The <see cref="Image"/> to search within.</param>
/// <param name="bitmap">The <see cref="Image{TPixel}"/> to search within.</param>
/// <param name="componentValue">The color component value to remove.</param>
/// <param name="channel">The <see cref="RgbaComponent"/> channel to test against.</param>
/// <returns>

2
src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs

@ -127,7 +127,7 @@ namespace ImageSharp.Formats
+ $"bigger then the max allowed size '{Image<TPixel>.MaxWidth}x{Image<TPixel>.MaxHeight}'");
}
Image<TPixel> image = Image.Create<TPixel>(this.infoHeader.Width, this.infoHeader.Height, this.configuration);
Image<TPixel> image = new Image<TPixel>(this.configuration, this.infoHeader.Width, this.infoHeader.Height);
using (PixelAccessor<TPixel> pixels = image.Lock())
{
switch (this.infoHeader.Compression)

2
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<TPixel>(imageWidth, imageHeight, this.metaData, this.configuration);
this.image = new Image<TPixel>(this.configuration, imageWidth, imageHeight, this.metaData);
this.SetFrameMetaData(this.metaData);

2
src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

@ -482,7 +482,7 @@ namespace ImageSharp.Formats
private Image<TPixel> ConvertJpegPixelsToImagePixels<TPixel>(ImageMetaData metadata)
where TPixel : struct, IPixel<TPixel>
{
Image<TPixel> image = Image.Create<TPixel>(this.ImageWidth, this.ImageHeight, metadata, this.configuration);
Image<TPixel> image = new Image<TPixel>(this.configuration, this.ImageWidth, this.ImageHeight, metadata);
if (this.grayImage.IsInitialized)
{

2
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<TPixel>.MaxWidth}x{Image<TPixel>.MaxHeight}'");
}
image = Image.Create<TPixel>(this.header.Width, this.header.Height, metadata, this.configuration);
image = new Image<TPixel>(this.configuration, this.header.Width, this.header.Height, metadata);
pixels = image.Lock();
this.bytesPerPixel = this.CalculateBytesPerPixel();
this.bytesPerScanline = this.CalculateScanlineLength(this.header.Width) + 1;

62
src/ImageSharp/Image.Create.cs

@ -1,62 +0,0 @@
// <copyright file="Image.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using ImageSharp.PixelFormats;
/// <summary>
/// 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.
/// </summary>
public sealed partial class Image
{
/// <summary>
/// Create a new instance of the <see cref="Image{TPixel}"/> class
/// with the height and the width of the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
/// <param name="metadata">The images matadata to preload.</param>
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
/// <returns>
/// A new <see cref="Image{TPixel}"/> unless <typeparamref name="TPixel"/> is <see cref="Rgba32"/> in which case it returns <see cref="Image" />
/// </returns>
internal static Image<TPixel> Create<TPixel>(int width, int height, ImageMetaData metadata, Configuration configuration)
where TPixel : struct, IPixel<TPixel>
{
if (typeof(TPixel) == typeof(Rgba32))
{
return new Image(width, height, metadata, configuration) as Image<TPixel>;
}
else
{
return new Image<TPixel>(width, height, metadata, configuration);
}
}
/// <summary>
/// Create a new instance of the <see cref="Image{TPixel}"/> class
/// with the height and the width of the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
/// <returns>
/// A new <see cref="Image{TPixel}"/> unless <typeparamref name="TPixel"/> is <see cref="Rgba32"/> in which case it returns <see cref="Image" />
/// </returns>
internal static Image<TPixel> Create<TPixel>(int width, int height, Configuration configuration)
where TPixel : struct, IPixel<TPixel>
{
return Image.Create<TPixel>(width, height, null, configuration);
}
}
}

69
src/ImageSharp/Image.cs

@ -1,69 +0,0 @@
// <copyright file="Image.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System.Diagnostics;
using ImageSharp.PixelFormats;
/// <summary>
/// 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.
/// </summary>
[DebuggerDisplay("Image: {Width}x{Height}")]
public sealed partial class Image : Image<Rgba32>
{
/// <summary>
/// Initializes a new instance of the <see cref="Image"/> class
/// with the height and the width of the image.
/// </summary>
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
public Image(int width, int height, Configuration configuration)
: base(width, height, configuration)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Image"/> class
/// with the height and the width of the image.
/// </summary>
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
public Image(int width, int height)
: this(width, height, null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Image"/> class
/// by making a copy from another image.
/// </summary>
/// <param name="other">The other image, where the clone should be made from.</param>
/// <exception cref="System.ArgumentNullException"><paramref name="other"/> is null.</exception>
public Image(Image<Rgba32> other)
: base(other)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Image"/> class
/// with the height and the width of the image.
/// </summary>
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
/// <param name="metadata">The metadata.</param>
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
internal Image(int width, int height, ImageMetaData metadata, Configuration configuration)
: base(width, height, metadata, configuration)
{
}
}
}

17
src/ImageSharp/Image.Decode.cs → src/ImageSharp/Image/Image.Decode.cs

@ -12,11 +12,10 @@ namespace ImageSharp
using ImageSharp.PixelFormats;
/// <summary>
/// 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.
/// </summary>
public sealed partial class Image
/// <content>
/// Adds static methods allowing the decoding of new images.
/// </content>
public static partial class Image
{
/// <summary>
/// By reading the header on the provided stream this calculates the images format.
@ -53,15 +52,15 @@ namespace ImageSharp
/// <summary>
/// Decodes the image stream to the current image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="stream">The stream.</param>
/// <param name="options">The options for the decoder.</param>
/// <param name="config">the configuration.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>
/// The decoded image
/// A new <see cref="Image{TPixel}"/>.
/// </returns>
private static Image<TPixel> Decode<TPixel>(Stream stream, IDecoderOptions options, Configuration config)
where TPixel : struct, IPixel<TPixel>
where TPixel : struct, IPixel<TPixel>
{
IImageFormat format = DiscoverFormat(stream, config);
if (format == null)
@ -74,4 +73,4 @@ namespace ImageSharp
return img;
}
}
}
}

146
src/ImageSharp/Image.FromBytes.cs → src/ImageSharp/Image/Image.FromBytes.cs

@ -1,122 +1,75 @@
// <copyright file="Image.FromStream.cs" company="James Jackson-South">
// <copyright file="Image.FromBytes.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System;
using System.IO;
using Formats;
using ImageSharp.PixelFormats;
/// <summary>
/// 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.
/// </summary>
public sealed partial class Image
/// <content>
/// Adds static methods allowing the creation of new image from a byte array.
/// </content>
public static partial class Image
{
/// <summary>
/// Loads the image from the given byte array.
/// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given byte array.
/// </summary>
/// <param name="data">The byte array containing image data.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
public static Image Load(byte[] data)
{
return Load(null, data, null);
}
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>
public static Image<Rgba32> Load(byte[] data) => Load<Rgba32>(null, data, null);
/// <summary>
/// Loads the image from the given byte array.
/// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given byte array.
/// </summary>
/// <param name="data">The byte array containing image data.</param>
/// <param name="options">The options for the decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
public static Image Load(byte[] data, IDecoderOptions options)
{
return Load(null, data, options);
}
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>
public static Image<Rgba32> Load(byte[] data, IDecoderOptions options) => Load<Rgba32>(null, data, options);
/// <summary>
/// Loads the image from the given byte array.
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given byte array.
/// </summary>
/// <param name="config">The config for the decoder.</param>
/// <param name="data">The byte array containing image data.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
public static Image Load(Configuration config, byte[] data)
{
return Load(config, data, null);
}
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>
public static Image<Rgba32> Load(Configuration config, byte[] data) => Load<Rgba32>(config, data, null);
/// <summary>
/// Loads the image from the given byte array.
/// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given byte array.
/// </summary>
/// <param name="data">The byte array containing image data.</param>
/// <param name="decoder">The decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
public static Image Load(byte[] data, IImageDecoder decoder)
{
return Load(data, decoder, null);
}
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>
public static Image<Rgba32> Load(byte[] data, IImageDecoder decoder) => Load<Rgba32>(data, decoder, null);
/// <summary>
/// Loads the image from the given byte array.
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given byte array.
/// </summary>
/// <param name="config">The configuration options.</param>
/// <param name="data">The byte array containing image data.</param>
/// <param name="options">The options for the decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
public static Image Load(Configuration config, byte[] data, IDecoderOptions options)
{
using (MemoryStream ms = new MemoryStream(data))
{
return Load(config, ms, options);
}
}
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>
public static Image<Rgba32> Load(Configuration config, byte[] data, IDecoderOptions options) => Load<Rgba32>(config, data, options);
/// <summary>
/// Loads the image from the given byte array.
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given byte array.
/// </summary>
/// <param name="data">The byte array containing image data.</param>
/// <param name="decoder">The decoder.</param>
/// <param name="options">The options for the decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
public static Image Load(byte[] data, IImageDecoder decoder, IDecoderOptions options)
{
using (MemoryStream ms = new MemoryStream(data))
{
return Load(ms, decoder, options);
}
}
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>
public static Image<Rgba32> Load(byte[] data, IImageDecoder decoder, IDecoderOptions options) => Load<Rgba32>(data, decoder, options);
/// <summary>
/// Loads the image from the given byte array.
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given byte array.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="data">The byte array containing image data.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Load<TPixel>(byte[] data)
where TPixel : struct, IPixel<TPixel>
{
@ -124,15 +77,12 @@ namespace ImageSharp
}
/// <summary>
/// Loads the image from the given byte array.
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given byte array.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="data">The byte array containing image data.</param>
/// <param name="options">The options for the decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Load<TPixel>(byte[] data, IDecoderOptions options)
where TPixel : struct, IPixel<TPixel>
{
@ -140,15 +90,12 @@ namespace ImageSharp
}
/// <summary>
/// Loads the image from the given byte array.
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given byte array.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="config">The config for the decoder.</param>
/// <param name="data">The byte array containing image data.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Load<TPixel>(Configuration config, byte[] data)
where TPixel : struct, IPixel<TPixel>
{
@ -156,15 +103,12 @@ namespace ImageSharp
}
/// <summary>
/// Loads the image from the given byte array.
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given byte array.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="data">The byte array containing image data.</param>
/// <param name="decoder">The decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Load<TPixel>(byte[] data, IImageDecoder decoder)
where TPixel : struct, IPixel<TPixel>
{
@ -172,16 +116,13 @@ namespace ImageSharp
}
/// <summary>
/// Loads the image from the given byte array.
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given byte array.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="config">The configuration options.</param>
/// <param name="data">The byte array containing image data.</param>
/// <param name="options">The options for the decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Load<TPixel>(Configuration config, byte[] data, IDecoderOptions options)
where TPixel : struct, IPixel<TPixel>
{
@ -192,16 +133,13 @@ namespace ImageSharp
}
/// <summary>
/// Loads the image from the given byte array.
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given byte array.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="data">The byte array containing image data.</param>
/// <param name="decoder">The decoder.</param>
/// <param name="options">The options for the decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Load<TPixel>(byte[] data, IImageDecoder decoder, IDecoderOptions options)
where TPixel : struct, IPixel<TPixel>
{
@ -211,4 +149,4 @@ namespace ImageSharp
}
}
}
}
}

109
src/ImageSharp/Image.FromFile.cs → src/ImageSharp/Image/Image.FromFile.cs

@ -11,110 +11,87 @@ namespace ImageSharp
using Formats;
using ImageSharp.PixelFormats;
/// <summary>
/// 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.
/// </summary>
public sealed partial class Image
/// <content>
/// Adds static methods allowing the creation of new image from a given file.
/// </content>
public static partial class Image
{
/// <summary>
/// Loads the image from the given file.
/// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given file.
/// </summary>
/// <param name="path">The file path to the image.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
public static Image Load(string path)
{
return Load(null, path, null);
}
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>
public static Image<Rgba32> Load(string path) => Load<Rgba32>(path);
/// <summary>
/// Loads the image from the given file.
/// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given file.
/// </summary>
/// <param name="path">The file path to the image.</param>
/// <param name="options">The options for the decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
public static Image Load(string path, IDecoderOptions options)
{
return Load(null, path, options);
}
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
public static Image<Rgba32> Load(string path, IDecoderOptions options) => Load<Rgba32>(path, options);
/// <summary>
/// Loads the image from the given file.
/// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given file.
/// </summary>
/// <param name="config">The config for the decoder.</param>
/// <param name="path">The file path to the image.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
public static Image Load(Configuration config, string path)
{
return Load(config, path, null);
}
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>
public static Image<Rgba32> Load(Configuration config, string path) => Load<Rgba32>(config, path);
/// <summary>
/// Loads the image from the given file.
/// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given file.
/// </summary>
/// <param name="path">The file path to the image.</param>
/// <param name="decoder">The decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
public static Image Load(string path, IImageDecoder decoder)
{
return Load(path, decoder, null);
}
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>
public static Image<Rgba32> Load(string path, IImageDecoder decoder) => Load<Rgba32>(path, decoder);
/// <summary>
/// Loads the image from the given file.
/// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given file.
/// </summary>
/// <param name="config">The configuration options.</param>
/// <param name="path">The file path to the image.</param>
/// <param name="decoder">The decoder.</param>
/// <param name="options">The options for the decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
public static Image Load(string path, IImageDecoder decoder, IDecoderOptions options)
{
return new Image(Load<Rgba32>(path, decoder, options));
}
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>
public static Image<Rgba32> Load(Configuration config, string path, IDecoderOptions options) => Load<Rgba32>(config, path, options);
/// <summary>
/// Loads the image from the given file.
/// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given file.
/// </summary>
/// <param name="config">The configuration options.</param>
/// <param name="path">The file path to the image.</param>
/// <param name="decoder">The decoder.</param>
/// <param name="options">The options for the decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
public static Image Load(Configuration config, string path, IDecoderOptions options)
{
config = config ?? Configuration.Default;
using (Stream s = config.FileSystem.OpenRead(path))
{
return Load(config, s, options);
}
}
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>
public static Image<Rgba32> Load(string path, IImageDecoder decoder, IDecoderOptions options) => Load<Rgba32>(path, decoder, options);
/// <summary>
/// Loads the image from the given file.
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given file.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="path">The file path to the image.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Load<TPixel>(string path)
where TPixel : struct, IPixel<TPixel>
{
@ -122,15 +99,15 @@ namespace ImageSharp
}
/// <summary>
/// Loads the image from the given file.
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given file.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="path">The file path to the image.</param>
/// <param name="options">The options for the decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Load<TPixel>(string path, IDecoderOptions options)
where TPixel : struct, IPixel<TPixel>
{
@ -138,15 +115,15 @@ namespace ImageSharp
}
/// <summary>
/// Loads the image from the given file.
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given file.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="config">The config for the decoder.</param>
/// <param name="path">The file path to the image.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Load<TPixel>(Configuration config, string path)
where TPixel : struct, IPixel<TPixel>
{
@ -154,15 +131,15 @@ namespace ImageSharp
}
/// <summary>
/// Loads the image from the given file.
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given file.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="path">The file path to the image.</param>
/// <param name="decoder">The decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Load<TPixel>(string path, IImageDecoder decoder)
where TPixel : struct, IPixel<TPixel>
{
@ -170,16 +147,16 @@ namespace ImageSharp
}
/// <summary>
/// Loads the image from the given file.
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given file.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="config">The configuration options.</param>
/// <param name="path">The file path to the image.</param>
/// <param name="options">The options for the decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Load<TPixel>(Configuration config, string path, IDecoderOptions options)
where TPixel : struct, IPixel<TPixel>
{
@ -191,16 +168,16 @@ namespace ImageSharp
}
/// <summary>
/// Loads the image from the given file.
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given file.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="path">The file path to the image.</param>
/// <param name="decoder">The decoder.</param>
/// <param name="options">The options for the decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Load<TPixel>(string path, IImageDecoder decoder, IDecoderOptions options)
where TPixel : struct, IPixel<TPixel>
{
@ -212,4 +189,4 @@ namespace ImageSharp
}
}
#endif
}
}

131
src/ImageSharp/Image.FromStream.cs → src/ImageSharp/Image/Image.FromStream.cs

@ -7,92 +7,61 @@ namespace ImageSharp
{
using System;
using System.IO;
using System.Numerics;
using System.Text;
using Formats;
using ImageSharp.PixelFormats;
/// <summary>
/// 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.
/// </summary>
public sealed partial class Image
/// <content>
/// Adds static methods allowing the creation of new image from a given stream.
/// </content>
public static partial class Image
{
/// <summary>
/// Loads the image from the given stream.
/// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given stream.
/// </summary>
/// <param name="stream">The stream containing image information.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
public static Image Load(Stream stream)
{
return Load(null, stream, null);
}
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>>
public static Image<Rgba32> Load(Stream stream) => Load<Rgba32>(stream);
/// <summary>
/// Loads the image from the given stream.
/// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given stream.
/// </summary>
/// <param name="stream">The stream containing image information.</param>
/// <param name="options">The options for the decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
public static Image Load(Stream stream, IDecoderOptions options)
{
return Load(null, stream, options);
}
/// <summary>
/// Loads the image from the given stream.
/// </summary>
/// <param name="config">The config for the decoder.</param>
/// <param name="stream">The stream containing image information.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
public static Image Load(Configuration config, Stream stream)
{
return Load(config, stream, null);
}
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>>
public static Image<Rgba32> Load(Stream stream, IDecoderOptions options) => Load<Rgba32>(stream, options);
/// <summary>
/// Loads the image from the given stream.
/// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given stream.
/// </summary>
/// <param name="stream">The stream containing image information.</param>
/// <param name="decoder">The decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
public static Image Load(Stream stream, IImageDecoder decoder)
{
return Load(stream, decoder, null);
}
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>>
public static Image<Rgba32> Load(Stream stream, IImageDecoder decoder) => Load<Rgba32>(stream, decoder);
/// <summary>
/// Loads the image from the given stream.
/// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given stream.
/// </summary>
/// <param name="config">The configuration options.</param>
/// <param name="config">The config for the decoder.</param>
/// <param name="stream">The stream containing image information.</param>
/// <param name="options">The options for the decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
public static Image Load(Configuration config, Stream stream, IDecoderOptions options)
{
Image<Rgba32> image = Load<Rgba32>(config, stream, options);
return image as Image ?? new Image(image);
}
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>>
public static Image<Rgba32> Load(Configuration config, Stream stream) => Load<Rgba32>(config, stream);
/// <summary>
/// Loads the image from the given stream.
/// Create a new instance of the <see cref="Image{Rgba32}"/> class from the given stream.
/// </summary>
/// <param name="stream">The stream containing image information.</param>
/// <param name="decoder">The decoder.</param>
@ -100,23 +69,18 @@ namespace ImageSharp
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
public static Image Load(Stream stream, IImageDecoder decoder, IDecoderOptions options)
{
Image<Rgba32> image = new Image(Load<Rgba32>(stream, decoder, options));
return image as Image ?? new Image(image);
}
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>>
public static Image<Rgba32> Load(Stream stream, IImageDecoder decoder, IDecoderOptions options) => Load<Rgba32>(stream, decoder, options);
/// <summary>
/// Loads the image from the given stream.
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given stream.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="stream">The stream containing image information.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>>
public static Image<TPixel> Load<TPixel>(Stream stream)
where TPixel : struct, IPixel<TPixel>
{
@ -124,15 +88,15 @@ namespace ImageSharp
}
/// <summary>
/// Loads the image from the given stream.
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given stream.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="stream">The stream containing image information.</param>
/// <param name="options">The options for the decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>>
public static Image<TPixel> Load<TPixel>(Stream stream, IDecoderOptions options)
where TPixel : struct, IPixel<TPixel>
{
@ -140,15 +104,15 @@ namespace ImageSharp
}
/// <summary>
/// Loads the image from the given stream.
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given stream.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="config">The config for the decoder.</param>
/// <param name="stream">The stream containing image information.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>>
public static Image<TPixel> Load<TPixel>(Configuration config, Stream stream)
where TPixel : struct, IPixel<TPixel>
{
@ -156,15 +120,15 @@ namespace ImageSharp
}
/// <summary>
/// Loads the image from the given stream.
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given stream.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="stream">The stream containing image information.</param>
/// <param name="decoder">The decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>>
public static Image<TPixel> Load<TPixel>(Stream stream, IImageDecoder decoder)
where TPixel : struct, IPixel<TPixel>
{
@ -172,16 +136,16 @@ namespace ImageSharp
}
/// <summary>
/// Loads the image from the given stream.
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given stream.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="stream">The stream containing image information.</param>
/// <param name="decoder">The decoder.</param>
/// <param name="options">The options for the decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>>
public static Image<TPixel> Load<TPixel>(Stream stream, IImageDecoder decoder, IDecoderOptions options)
where TPixel : struct, IPixel<TPixel>
{
@ -189,21 +153,20 @@ namespace ImageSharp
}
/// <summary>
/// Loads the image from the given stream.
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given stream.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="config">The configuration options.</param>
/// <param name="stream">The stream containing image information.</param>
/// <param name="options">The options for the decoder.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>The image</returns>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>>
public static Image<TPixel> Load<TPixel>(Configuration config, Stream stream, IDecoderOptions options)
where TPixel : struct, IPixel<TPixel>
{
config = config ?? Configuration.Default;
Image<TPixel> img = WithSeekableStream(stream, s => Decode<TPixel>(s, options, config));
if (img != null)
@ -233,17 +196,15 @@ namespace ImageSharp
{
return action(stream);
}
else
// We want to be able to load images from things like HttpContext.Request.Body
using (MemoryStream ms = new MemoryStream())
{
// We want to be able to load images from things like HttpContext.Request.Body
using (MemoryStream ms = new MemoryStream())
{
stream.CopyTo(ms);
ms.Position = 0;
return action(ms);
}
stream.CopyTo(ms);
ms.Position = 0;
return action(ms);
}
}
}
}
}

6
src/ImageSharp/Image/ImageBase{TPixel}.cs

@ -59,15 +59,15 @@ namespace ImageSharp
/// <summary>
/// Initializes a new instance of the <see cref="ImageBase{TPixel}"/> class.
/// </summary>
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown if either <paramref name="width"/> or <paramref name="height"/> are less than or equal to 0.
/// </exception>
protected ImageBase(int width, int height, Configuration configuration)
protected ImageBase(Configuration configuration, int width, int height)
: this(configuration)
{
Guard.MustBeGreaterThan(width, 0, nameof(width));

2
src/ImageSharp/Image/ImageFrame{TPixel}.cs

@ -26,7 +26,7 @@ namespace ImageSharp
/// The configuration providing initialization code which allows extending the library.
/// </param>
public ImageFrame(int width, int height, Configuration configuration = null)
: base(width, height, configuration)
: base(configuration, width, height)
{
}

22
src/ImageSharp/Image/Image{TPixel}.cs

@ -29,13 +29,13 @@ namespace ImageSharp
/// Initializes a new instance of the <see cref="Image{TPixel}"/> class
/// with the height and the width of the image.
/// </summary>
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
public Image(int width, int height, Configuration configuration)
: this(width, height, new ImageMetaData(), configuration)
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
public Image(Configuration configuration, int width, int height)
: this(configuration, width, height, new ImageMetaData())
{
}
@ -46,7 +46,7 @@ namespace ImageSharp
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
public Image(int width, int height)
: this(width, height, null)
: this(null, width, height)
{
}
@ -85,14 +85,14 @@ namespace ImageSharp
/// Initializes a new instance of the <see cref="Image{TPixel}"/> class
/// with the height and the width of the image.
/// </summary>
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
/// <param name="metadata">The images metadata.</param>
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
internal Image(int width, int height, ImageMetaData metadata, Configuration configuration)
: base(width, height, configuration)
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
/// <param name="metadata">The images metadata.</param>
internal Image(Configuration configuration, int width, int height, ImageMetaData metadata)
: base(configuration, width, height)
{
if (!this.Configuration.ImageFormats.Any())
{
@ -359,7 +359,7 @@ namespace ImageSharp
{
scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction<TPixel, TPixel2>(scaleFunc);
Image<TPixel2> target = new Image<TPixel2>(this.Width, this.Height, this.Configuration);
Image<TPixel2> target = new Image<TPixel2>(this.Configuration, this.Width, this.Height);
target.CopyProperties(this);
using (PixelAccessor<TPixel> pixels = this.Lock())

2
src/ImageSharp/ImageSharp.csproj

@ -2,7 +2,7 @@
<PropertyGroup>
<Description>A cross-platform library for the processing of image files; written in C#</Description>
<AssemblyTitle>ImageSharp</AssemblyTitle>
<VersionPrefix>1.0.0-alpha8</VersionPrefix>
<VersionPrefix>1.0.0-alpha9</VersionPrefix>
<Authors>James Jackson-South and contributors</Authors>
<TargetFrameworks>netstandard1.3;netstandard1.1</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

1
src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs

@ -5,7 +5,6 @@
namespace ImageSharp
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;

6
src/ImageSharp/PixelFormats/README.md

@ -1,3 +1,7 @@
Pixel formats adapted and extended from:
https://github.com/MonoGame/MonoGame
https://github.com/MonoGame/MonoGame
Rgba32 is our default format. As such it positioned within the ImageSharp root namespace to ensure visibility of the format.
All other pixel formats should be positioned within ImageSharp.PixelFormats to reduce intellisense burden.

2
src/ImageSharp/PixelFormats/Rgba32.ColorspaceTransforms.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.PixelFormats
namespace ImageSharp
{
using System;
using System.Numerics;

4
src/ImageSharp/PixelFormats/Rgba32.Definitions.cs

@ -3,8 +3,10 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.PixelFormats
namespace ImageSharp
{
using ImageSharp.PixelFormats;
/// <content>
/// Provides standardized deifinitions for named colors.
/// </content>

4
src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs

@ -3,13 +3,15 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.PixelFormats
namespace ImageSharp
{
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ImageSharp.PixelFormats;
/// <content>
/// Provides optimized overrides for bulk operations.
/// </content>

4
src/ImageSharp/PixelFormats/Rgba32.cs

@ -3,12 +3,14 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.PixelFormats
namespace ImageSharp
{
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ImageSharp.PixelFormats;
/// <summary>
/// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
/// The color components are stored in red, green, blue, and alpha order.

6
src/ImageSharp/Processing/Binarization/Dither.cs

@ -12,7 +12,7 @@ namespace ImageSharp
using ImageSharp.Processing.Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -40,7 +40,7 @@ namespace ImageSharp
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="index">The component index to test the threshold against. Must range from 0 to 3.</param>
/// <returns>The <see cref="Image"/>.</returns>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Dither<TPixel>(this Image<TPixel> source, IOrderedDither dither, Rectangle rectangle, int index = 0)
where TPixel : struct, IPixel<TPixel>
{
@ -72,7 +72,7 @@ namespace ImageSharp
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image"/>.</returns>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Dither<TPixel>(this Image<TPixel> source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{

4
src/ImageSharp/Processing/ColorMatrix/Sepia.cs

@ -22,7 +22,7 @@ namespace ImageSharp
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image"/>.</returns>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Sepia<TPixel>(this Image<TPixel> source)
where TPixel : struct, IPixel<TPixel>
{
@ -37,7 +37,7 @@ namespace ImageSharp
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image"/>.</returns>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Sepia<TPixel>(this Image<TPixel> source, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{

4
src/ImageSharp/Processing/Effects/Alpha.cs

@ -12,7 +12,7 @@ namespace ImageSharp
using Processing.Processors;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -38,7 +38,7 @@ namespace ImageSharp
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image"/>.</returns>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Alpha<TPixel>(this Image<TPixel> source, float percent, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{

4
src/ImageSharp/Processing/Effects/BackgroundColor.cs

@ -40,7 +40,7 @@ namespace ImageSharp
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="options">The options effecting pixel blending.</param>
/// <returns>The <see cref="Image"/>.</returns>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> BackgroundColor<TPixel>(this Image<TPixel> source, TPixel color, Rectangle rectangle, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
@ -70,7 +70,7 @@ namespace ImageSharp
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image"/>.</returns>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> BackgroundColor<TPixel>(this Image<TPixel> source, TPixel color, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{

4
src/ImageSharp/Processing/Effects/Invert.cs

@ -21,7 +21,7 @@ namespace ImageSharp
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image"/>.</returns>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Invert<TPixel>(this Image<TPixel> source)
where TPixel : struct, IPixel<TPixel>
{
@ -36,7 +36,7 @@ namespace ImageSharp
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image"/>.</returns>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Invert<TPixel>(this Image<TPixel> source, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{

0
src/ImageSharp/ImageProcessor.cs → src/ImageSharp/Processing/ImageProcessor.cs

2
src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor.cs

@ -12,7 +12,7 @@ namespace ImageSharp.Processing.Processors
/// <summary>
/// An <see cref="IImageProcessor{TPixel}"/> to perform binary threshold filtering against an
/// <see cref="Image"/>. The image will be converted to grayscale before thresholding occurs.
/// <see cref="Image{TPixel}"/>. The image will be converted to grayscale before thresholding occurs.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class BinaryThresholdProcessor<TPixel> : ImageProcessor<TPixel>

2
src/ImageSharp/Processing/Transforms/AutoOrient.cs

@ -22,7 +22,7 @@ namespace ImageSharp
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image to auto rotate.</param>
/// <returns>The <see cref="Image"/></returns>
/// <returns>The <see cref="Image{TPixel}"/></returns>
public static Image<TPixel> AutoOrient<TPixel>(this Image<TPixel> source)
where TPixel : struct, IPixel<TPixel>
{

2
src/ImageSharp/Processing/Transforms/Crop.cs

@ -38,7 +38,7 @@ namespace ImageSharp
/// <param name="cropRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to retain.
/// </param>
/// <returns>The <see cref="Image"/></returns>
/// <returns>The <see cref="Image{TPixel}"/></returns>
public static Image<TPixel> Crop<TPixel>(this Image<TPixel> source, Rectangle cropRectangle)
where TPixel : struct, IPixel<TPixel>
{

2
src/ImageSharp/Processing/Transforms/EntropyCrop.cs

@ -22,7 +22,7 @@ namespace ImageSharp
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image to crop.</param>
/// <param name="threshold">The threshold for entropic density.</param>
/// <returns>The <see cref="Image"/></returns>
/// <returns>The <see cref="Image{TPixel}"/></returns>
public static Image<TPixel> EntropyCrop<TPixel>(this Image<TPixel> source, float threshold = .5f)
where TPixel : struct, IPixel<TPixel>
{

2
src/ImageSharp/Processing/Transforms/Flip.cs

@ -23,7 +23,7 @@ namespace ImageSharp
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image to rotate, flip, or both.</param>
/// <param name="flipType">The <see cref="FlipType"/> to perform the flip.</param>
/// <returns>The <see cref="Image"/></returns>
/// <returns>The <see cref="Image{TPixel}"/></returns>
public static Image<TPixel> Flip<TPixel>(this Image<TPixel> source, FlipType flipType)
where TPixel : struct, IPixel<TPixel>
{

6
src/ImageSharp/Processing/Transforms/Rotate.cs

@ -23,7 +23,7 @@ namespace ImageSharp
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image to rotate.</param>
/// <param name="degrees">The angle in degrees to perform the rotation.</param>
/// <returns>The <see cref="Image"/></returns>
/// <returns>The <see cref="Image{TPixel}"/></returns>
public static Image<TPixel> Rotate<TPixel>(this Image<TPixel> source, float degrees)
where TPixel : struct, IPixel<TPixel>
{
@ -36,7 +36,7 @@ namespace ImageSharp
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image to rotate.</param>
/// <param name="rotateType">The <see cref="RotateType"/> to perform the rotation.</param>
/// <returns>The <see cref="Image"/></returns>
/// <returns>The <see cref="Image{TPixel}"/></returns>
public static Image<TPixel> Rotate<TPixel>(this Image<TPixel> source, RotateType rotateType)
where TPixel : struct, IPixel<TPixel>
{
@ -50,7 +50,7 @@ namespace ImageSharp
/// <param name="source">The image to rotate.</param>
/// <param name="degrees">The angle in degrees to perform the rotation.</param>
/// <param name="expand">Whether to expand the image to fit the rotated result.</param>
/// <returns>The <see cref="Image"/></returns>
/// <returns>The <see cref="Image{TPixel}"/></returns>
public static Image<TPixel> Rotate<TPixel>(this Image<TPixel> source, float degrees, bool expand)
where TPixel : struct, IPixel<TPixel>
{

2
src/ImageSharp/Processing/Transforms/RotateFlip.cs

@ -23,7 +23,7 @@ namespace ImageSharp
/// <param name="source">The image to rotate, flip, or both.</param>
/// <param name="rotateType">The <see cref="RotateType"/> to perform the rotation.</param>
/// <param name="flipType">The <see cref="FlipType"/> to perform the flip.</param>
/// <returns>The <see cref="Image"/></returns>
/// <returns>The <see cref="Image{TPixel}"/></returns>
public static Image<TPixel> RotateFlip<TPixel>(this Image<TPixel> source, RotateType rotateType, FlipType flipType)
where TPixel : struct, IPixel<TPixel>
{

4
src/ImageSharp/Processing/Transforms/Skew.cs

@ -23,7 +23,7 @@ namespace ImageSharp
/// <param name="source">The image to skew.</param>
/// <param name="degreesX">The angle in degrees to perform the rotation along the x-axis.</param>
/// <param name="degreesY">The angle in degrees to perform the rotation along the y-axis.</param>
/// <returns>The <see cref="Image"/></returns>
/// <returns>The <see cref="Image{TPixel}"/></returns>
public static Image<TPixel> Skew<TPixel>(this Image<TPixel> source, float degreesX, float degreesY)
where TPixel : struct, IPixel<TPixel>
{
@ -38,7 +38,7 @@ namespace ImageSharp
/// <param name="degreesX">The angle in degrees to perform the rotation along the x-axis.</param>
/// <param name="degreesY">The angle in degrees to perform the rotation along the y-axis.</param>
/// <param name="expand">Whether to expand the image to fit the skewed result.</param>
/// <returns>The <see cref="Image"/></returns>
/// <returns>The <see cref="Image{TPixel}"/></returns>
public static Image<TPixel> Skew<TPixel>(this Image<TPixel> source, float degreesX, float degreesY, bool expand)
where TPixel : struct, IPixel<TPixel>
{

5
tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs

@ -14,9 +14,6 @@ namespace ImageSharp.Benchmarks
using ImageSharp.PixelFormats;
using CoreImage = ImageSharp.Image;
using CorePoint = ImageSharp.Point;
public class DrawBeziers : BenchmarkBase
{
[Benchmark(Baseline = true, Description = "System.Drawing Draw Beziers")]
@ -48,7 +45,7 @@ namespace ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Draw Beziers")]
public void DrawLinesCore()
{
using (CoreImage image = new CoreImage(800, 800))
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
{
image.DrawBeziers(
Rgba32.HotPink,

6
tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs

@ -14,9 +14,6 @@ namespace ImageSharp.Benchmarks
using ImageSharp.PixelFormats;
using CoreImage = ImageSharp.Image;
using CorePoint = ImageSharp.Point;
public class DrawLines : BenchmarkBase
{
[Benchmark(Baseline = true, Description = "System.Drawing Draw Lines")]
@ -24,7 +21,6 @@ namespace ImageSharp.Benchmarks
{
using (Bitmap destination = new Bitmap(800, 800))
{
using (Graphics graphics = Graphics.FromImage(destination))
{
graphics.InterpolationMode = InterpolationMode.Default;
@ -47,7 +43,7 @@ namespace ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Draw Lines")]
public void DrawLinesCore()
{
using (CoreImage image = new CoreImage(800, 800))
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
{
image.DrawLines(
Rgba32.HotPink,

5
tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs

@ -9,8 +9,7 @@ namespace ImageSharp.Benchmarks
using System.Drawing.Drawing2D;
using BenchmarkDotNet.Attributes;
using CoreImage = ImageSharp.Image;
using CorePoint = ImageSharp.Point;
using System.IO;
using System.Numerics;
@ -46,7 +45,7 @@ namespace ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Draw Polygon")]
public void DrawPolygonCore()
{
using (CoreImage image = new CoreImage(800, 800))
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
{
image.DrawPolygon(
Rgba32.HotPink,

6
tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs

@ -15,8 +15,6 @@ namespace ImageSharp.Benchmarks
using ImageSharp.PixelFormats;
using CoreImage = ImageSharp.Image;
public class FillPolygon : BenchmarkBase
{
private readonly Polygon shape;
@ -55,7 +53,7 @@ namespace ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Fill Polygon")]
public void DrawSolidPolygonCore()
{
using (CoreImage image = new CoreImage(800, 800))
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
{
image.FillPolygon(
Rgba32.HotPink,
@ -75,7 +73,7 @@ namespace ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Fill Polygon - cached shape")]
public void DrawSolidPolygonCoreCahced()
{
using (CoreImage image = new CoreImage(800, 800))
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
{
image.Fill(
Rgba32.HotPink,

5
tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs

@ -9,7 +9,6 @@ namespace ImageSharp.Benchmarks
using System.Drawing.Drawing2D;
using BenchmarkDotNet.Attributes;
using CoreImage = ImageSharp.Image;
using CoreRectangle = ImageSharp.Rectangle;
using CoreSize = ImageSharp.Size;
@ -38,7 +37,7 @@ namespace ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Fill Rectangle")]
public CoreSize FillRactangleCore()
{
using (CoreImage image = new CoreImage(800, 800))
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
{
image.Fill(Rgba32.HotPink, new CoreRectangle(10, 10, 190, 140));
@ -49,7 +48,7 @@ namespace ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Fill Rectangle - As Polygon")]
public CoreSize FillPolygonCore()
{
using (CoreImage image = new CoreImage(800, 800))
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
{
image.FillPolygon(
Rgba32.HotPink,

8
tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs

@ -11,11 +11,9 @@ namespace ImageSharp.Benchmarks
using BenchmarkDotNet.Attributes;
using ImageSharp.PixelFormats;
using ImageSharp.Drawing.Brushes;
using CoreBrushes = ImageSharp.Drawing.Brushes.Brushes;
using CoreImage = ImageSharp.Image;
using ImageSharp.PixelFormats;
public class FillWithPattern
{
@ -40,7 +38,7 @@ namespace ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Fill with Pattern")]
public void DrawPatternPolygon3Core()
{
using (CoreImage image = new CoreImage(800, 800))
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
{
image.Fill(CoreBrushes.BackwardDiagonal(Rgba32.HotPink));

6
tests/ImageSharp.Benchmarks/Image/CopyPixels.cs

@ -11,15 +11,13 @@ namespace ImageSharp.Benchmarks.Image
using ImageSharp.PixelFormats;
using CoreImage = ImageSharp.Image;
public class CopyPixels : BenchmarkBase
{
[Benchmark(Description = "Copy by Pixel")]
public Rgba32 CopyByPixel()
{
using (CoreImage source = new CoreImage(1024, 768))
using (CoreImage target = new CoreImage(1024, 768))
using (Image<Rgba32> source = new Image<Rgba32>(1024, 768))
using (Image<Rgba32> target = new Image<Rgba32>(1024, 768))
{
using (PixelAccessor<Rgba32> sourcePixels = source.Lock())
using (PixelAccessor<Rgba32> targetPixels = target.Lock())

3
tests/ImageSharp.Benchmarks/Image/DecodeBmp.cs

@ -11,6 +11,7 @@ namespace ImageSharp.Benchmarks.Image
using BenchmarkDotNet.Attributes;
using CoreImage = ImageSharp.Image;
using CoreSize = ImageSharp.Size;
public class DecodeBmp : BenchmarkBase
@ -43,7 +44,7 @@ namespace ImageSharp.Benchmarks.Image
{
using (MemoryStream memoryStream = new MemoryStream(this.bmpBytes))
{
using (CoreImage image = CoreImage.Load(memoryStream))
using (Image<Rgba32> image = CoreImage.Load<Rgba32>(memoryStream))
{
return new CoreSize(image.Width, image.Height);
}

3
tests/ImageSharp.Benchmarks/Image/DecodeFilteredPng.cs

@ -10,6 +10,7 @@ namespace ImageSharp.Benchmarks.Image
using BenchmarkDotNet.Attributes;
using ImageSharp;
using CoreImage = ImageSharp.Image;
public class DecodeFilteredPng : BenchmarkBase
{
@ -31,7 +32,7 @@ namespace ImageSharp.Benchmarks.Image
private Size LoadPng(MemoryStream stream)
{
using (Image image = Image.Load(stream))
using (Image<Rgba32> image = CoreImage.Load<Rgba32>(stream))
{
return new Size(image.Width, image.Height);
}

3
tests/ImageSharp.Benchmarks/Image/DecodeGif.cs

@ -11,6 +11,7 @@ namespace ImageSharp.Benchmarks.Image
using BenchmarkDotNet.Attributes;
using CoreImage = ImageSharp.Image;
using CoreSize = ImageSharp.Size;
public class DecodeGif : BenchmarkBase
@ -43,7 +44,7 @@ namespace ImageSharp.Benchmarks.Image
{
using (MemoryStream memoryStream = new MemoryStream(this.gifBytes))
{
using (CoreImage image = CoreImage.Load(memoryStream))
using (Image<Rgba32> image = CoreImage.Load<Rgba32>(memoryStream))
{
return new CoreSize(image.Width, image.Height);
}

3
tests/ImageSharp.Benchmarks/Image/DecodeJpeg.cs

@ -11,6 +11,7 @@ namespace ImageSharp.Benchmarks.Image
using BenchmarkDotNet.Attributes;
using CoreImage = ImageSharp.Image;
using CoreSize = ImageSharp.Size;
public class DecodeJpeg : BenchmarkBase
@ -43,7 +44,7 @@ namespace ImageSharp.Benchmarks.Image
{
using (MemoryStream memoryStream = new MemoryStream(this.jpegBytes))
{
using (CoreImage image = CoreImage.Load(memoryStream))
using (Image<Rgba32> image = CoreImage.Load<Rgba32>(memoryStream))
{
return new CoreSize(image.Width, image.Height);
}

7
tests/ImageSharp.Benchmarks/Image/DecodeJpegMultiple.cs

@ -8,8 +8,7 @@ namespace ImageSharp.Benchmarks.Image
using System.Collections.Generic;
using BenchmarkDotNet.Attributes;
using Image = ImageSharp.Image;
using ImageSharpSize = ImageSharp.Size;
using CoreImage = ImageSharp.Image;
[Config(typeof(Config.Short))]
public class DecodeJpegMultiple : MultiImageBenchmarkBase
@ -25,8 +24,8 @@ namespace ImageSharp.Benchmarks.Image
public void DecodeJpegImageSharp()
{
this.ForEachStream(
ms => ImageSharp.Image.Load(ms)
);
ms => CoreImage.Load<Rgba32>(ms)
);
}
[Benchmark(Baseline = true, Description = "DecodeJpegMultiple - System.Drawing")]

3
tests/ImageSharp.Benchmarks/Image/DecodePng.cs

@ -11,6 +11,7 @@ namespace ImageSharp.Benchmarks.Image
using BenchmarkDotNet.Attributes;
using CoreImage = ImageSharp.Image;
using CoreSize = ImageSharp.Size;
public class DecodePng : BenchmarkBase
@ -43,7 +44,7 @@ namespace ImageSharp.Benchmarks.Image
{
using (MemoryStream memoryStream = new MemoryStream(this.pngBytes))
{
using (CoreImage image = CoreImage.Load(memoryStream))
using (Image<Rgba32> image = CoreImage.Load<Rgba32>(memoryStream))
{
return new CoreSize(image.Width, image.Height);
}

5
tests/ImageSharp.Benchmarks/Image/EncodeBmp.cs

@ -10,6 +10,7 @@ namespace ImageSharp.Benchmarks.Image
using System.IO;
using BenchmarkDotNet.Attributes;
using CoreImage = ImageSharp.Image;
public class EncodeBmp : BenchmarkBase
@ -17,7 +18,7 @@ namespace ImageSharp.Benchmarks.Image
// System.Drawing needs this.
private Stream bmpStream;
private Image bmpDrawing;
private CoreImage bmpCore;
private Image<Rgba32> bmpCore;
[Setup]
public void ReadImages()
@ -25,7 +26,7 @@ namespace ImageSharp.Benchmarks.Image
if (this.bmpStream == null)
{
this.bmpStream = File.OpenRead("../ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp");
this.bmpCore = CoreImage.Load(this.bmpStream);
this.bmpCore = CoreImage.Load<Rgba32>(this.bmpStream);
this.bmpStream.Position = 0;
this.bmpDrawing = Image.FromStream(this.bmpStream);
}

5
tests/ImageSharp.Benchmarks/Image/EncodeGif.cs

@ -10,6 +10,7 @@ namespace ImageSharp.Benchmarks.Image
using System.IO;
using BenchmarkDotNet.Attributes;
using CoreImage = ImageSharp.Image;
public class EncodeGif : BenchmarkBase
@ -17,7 +18,7 @@ namespace ImageSharp.Benchmarks.Image
// System.Drawing needs this.
private Stream bmpStream;
private Image bmpDrawing;
private CoreImage bmpCore;
private Image<Rgba32> bmpCore;
[Setup]
public void ReadImages()
@ -25,7 +26,7 @@ namespace ImageSharp.Benchmarks.Image
if (this.bmpStream == null)
{
this.bmpStream = File.OpenRead("../ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp");
this.bmpCore = CoreImage.Load(this.bmpStream);
this.bmpCore = CoreImage.Load<Rgba32>(this.bmpStream);
this.bmpStream.Position = 0;
this.bmpDrawing = Image.FromStream(this.bmpStream);
}

7
tests/ImageSharp.Benchmarks/Image/EncodeIndexedPng.cs

@ -11,9 +11,10 @@ namespace ImageSharp.Benchmarks.Image
using ImageSharp;
using ImageSharp.Formats;
using ImageSharp.PixelFormats;
using ImageSharp.Quantizers;
using CoreImage = ImageSharp.Image;
/// <summary>
/// Benchmarks saving png files using different quantizers. System.Drawing cannot save indexed png files so we cannot compare.
/// </summary>
@ -21,7 +22,7 @@ namespace ImageSharp.Benchmarks.Image
{
// System.Drawing needs this.
private Stream bmpStream;
private Image bmpCore;
private Image<Rgba32> bmpCore;
[Params(false)]
public bool LargeImage { get; set; }
@ -35,7 +36,7 @@ namespace ImageSharp.Benchmarks.Image
? "../ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg420exif.jpg"
: "../ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp";
this.bmpStream = File.OpenRead(path);
this.bmpCore = Image.Load(this.bmpStream);
this.bmpCore = CoreImage.Load<Rgba32>(this.bmpStream);
this.bmpStream.Position = 0;
}
}

5
tests/ImageSharp.Benchmarks/Image/EncodeJpeg.cs

@ -10,6 +10,7 @@ namespace ImageSharp.Benchmarks.Image
using System.IO;
using BenchmarkDotNet.Attributes;
using CoreImage = ImageSharp.Image;
public class EncodeJpeg : BenchmarkBase
@ -17,7 +18,7 @@ namespace ImageSharp.Benchmarks.Image
// System.Drawing needs this.
private Stream bmpStream;
private Image bmpDrawing;
private CoreImage bmpCore;
private Image<Rgba32> bmpCore;
[Setup]
public void ReadImages()
@ -25,7 +26,7 @@ namespace ImageSharp.Benchmarks.Image
if (this.bmpStream == null)
{
this.bmpStream = File.OpenRead("../ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp");
this.bmpCore = CoreImage.Load(this.bmpStream);
this.bmpCore = CoreImage.Load<Rgba32>(this.bmpStream);
this.bmpStream.Position = 0;
this.bmpDrawing = Image.FromStream(this.bmpStream);
}

5
tests/ImageSharp.Benchmarks/Image/EncodePng.cs

@ -12,7 +12,6 @@ namespace ImageSharp.Benchmarks.Image
using BenchmarkDotNet.Attributes;
using ImageSharp.Formats;
using ImageSharp.PixelFormats;
using ImageSharp.Quantizers;
using CoreImage = ImageSharp.Image;
@ -22,7 +21,7 @@ namespace ImageSharp.Benchmarks.Image
// System.Drawing needs this.
private Stream bmpStream;
private Image bmpDrawing;
private CoreImage bmpCore;
private Image<Rgba32> bmpCore;
[Params(false)]
public bool LargeImage { get; set; }
@ -39,7 +38,7 @@ namespace ImageSharp.Benchmarks.Image
? "../ImageSharp.Tests/TestImages/Formats/Jpg/baseline/jpeg420exif.jpg"
: "../ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp";
this.bmpStream = File.OpenRead(path);
this.bmpCore = CoreImage.Load(this.bmpStream);
this.bmpCore = CoreImage.Load<Rgba32>(this.bmpStream);
this.bmpStream.Position = 0;
this.bmpDrawing = Image.FromStream(this.bmpStream);
}

3
tests/ImageSharp.Benchmarks/Image/GetSetPixel.cs

@ -11,7 +11,6 @@ namespace ImageSharp.Benchmarks.Image
using ImageSharp.PixelFormats;
using CoreImage = ImageSharp.Image;
using SystemColor = System.Drawing.Color;
public class GetSetPixel : BenchmarkBase
@ -29,7 +28,7 @@ namespace ImageSharp.Benchmarks.Image
[Benchmark(Description = "ImageSharp GetSet pixel")]
public Rgba32 ResizeCore()
{
using (CoreImage image = new CoreImage(400, 400))
using (Image<Rgba32> image = new Image<Rgba32>(400, 400))
{
using (PixelAccessor<Rgba32> imagePixels = image.Lock())
{

14
tests/ImageSharp.Benchmarks/Image/MultiImageBenchmarkBase.cs

@ -15,13 +15,13 @@ namespace ImageSharp.Benchmarks.Image
using BenchmarkDotNet.Attributes;
using Image = ImageSharp.Image;
using CoreImage = ImageSharp.Image;
public abstract class MultiImageBenchmarkBase : BenchmarkBase
{
protected Dictionary<string, byte[]> FileNamesToBytes = new Dictionary<string, byte[]>();
protected Dictionary<string, Image> FileNamesToImageSharpImages = new Dictionary<string, Image>();
protected Dictionary<string, Image<Rgba32>> FileNamesToImageSharpImages = new Dictionary<string, Image<Rgba32>>();
protected Dictionary<string, System.Drawing.Bitmap> FileNamesToSystemDrawingImages = new Dictionary<string, System.Drawing.Bitmap>();
/// <summary>
@ -154,7 +154,7 @@ namespace ImageSharp.Benchmarks.Image
using (MemoryStream ms1 = new MemoryStream(bytes))
{
this.FileNamesToImageSharpImages[fn] = Image.Load(ms1);
this.FileNamesToImageSharpImages[fn] = CoreImage.Load<Rgba32>(ms1);
}
@ -162,7 +162,7 @@ namespace ImageSharp.Benchmarks.Image
}
}
protected IEnumerable<KeyValuePair<string, ImageSharp.Image>> FileNames2ImageSharpImages
protected IEnumerable<KeyValuePair<string, Image<Rgba32>>> FileNames2ImageSharpImages
=>
this.EnumeratePairsByBenchmarkSettings(
this.FileNamesToImageSharpImages,
@ -176,9 +176,9 @@ namespace ImageSharp.Benchmarks.Image
protected virtual int LargeImageThresholdInPixels => 700000;
protected void ForEachImageSharpImage(Func<Image, object> operation)
protected void ForEachImageSharpImage(Func<Image<Rgba32>, object> operation)
{
foreach (KeyValuePair<string, Image> kv in this.FileNames2ImageSharpImages)
foreach (KeyValuePair<string, Image<Rgba32>> kv in this.FileNames2ImageSharpImages)
{
try
{
@ -194,7 +194,7 @@ namespace ImageSharp.Benchmarks.Image
}
}
protected void ForEachImageSharpImage(Func<Image, MemoryStream, object> operation)
protected void ForEachImageSharpImage(Func<Image<Rgba32>, MemoryStream, object> operation)
{
using (MemoryStream workStream = new MemoryStream())
{

7
tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs

@ -8,9 +8,6 @@ namespace ImageSharp.Benchmarks
using BenchmarkDotNet.Attributes;
using ImageSharp.PixelFormats;
using ImageSharp.Drawing;
using ImageSharp.Processing.Processors;
using CoreImage = ImageSharp.Image;
using CoreSize = ImageSharp.Size;
using System.Numerics;
using ImageSharp.PixelFormats.PixelBlenders;
@ -57,7 +54,7 @@ namespace ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp BulkVectorConvert")]
public CoreSize BulkVectorConvert()
{
using (CoreImage image = new CoreImage(800, 800))
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
{
Buffer<float> amounts = new Buffer<float>(image.Width);
@ -80,7 +77,7 @@ namespace ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp BulkPixelConvert")]
public CoreSize BulkPixelConvert()
{
using (CoreImage image = new CoreImage(800, 800))
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
{
Buffer<float> amounts = new Buffer<float>(image.Width);

5
tests/ImageSharp.Benchmarks/Samplers/Crop.cs

@ -10,7 +10,8 @@ namespace ImageSharp.Benchmarks
using BenchmarkDotNet.Attributes;
using CoreImage = ImageSharp.Image;
using ImageSharp.PixelFormats;
using CoreSize = ImageSharp.Size;
public class Crop : BenchmarkBase
@ -38,7 +39,7 @@ namespace ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Crop")]
public CoreSize CropResizeCore()
{
using (CoreImage image = new CoreImage(800, 800))
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
{
image.Crop(100, 100);
return new CoreSize(image.Width, image.Height);

7
tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs

@ -9,12 +9,13 @@ namespace ImageSharp.Benchmarks
using BenchmarkDotNet.Attributes;
using CoreImage = ImageSharp.Image;
using Processing;
using CoreImage = ImageSharp.Image;
public class DetectEdges : BenchmarkBase
{
private CoreImage image;
private Image<Rgba32> image;
[Setup]
public void ReadImage()
@ -23,7 +24,7 @@ namespace ImageSharp.Benchmarks
{
using (FileStream stream = File.OpenRead("../ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp"))
{
this.image = CoreImage.Load(stream);
this.image = CoreImage.Load<Rgba32>(stream);
}
}
}

6
tests/ImageSharp.Benchmarks/Samplers/Glow.cs

@ -8,9 +8,7 @@ namespace ImageSharp.Benchmarks
using BenchmarkDotNet.Attributes;
using ImageSharp.PixelFormats;
using ImageSharp.Drawing;
using ImageSharp.Processing.Processors;
using CoreImage = ImageSharp.Image;
using CoreSize = ImageSharp.Size;
using ImageSharp.Processing;
using System.Numerics;
@ -32,7 +30,7 @@ namespace ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Glow - Bulk")]
public CoreSize GlowBulk()
{
using (CoreImage image = new CoreImage(800, 800))
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
{
image.ApplyProcessor(bulk, image.Bounds);
return new CoreSize(image.Width, image.Height);
@ -42,7 +40,7 @@ namespace ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Glow - Parallel")]
public CoreSize GLowSimple()
{
using (CoreImage image = new CoreImage(800, 800))
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
{
image.ApplyProcessor(parallel, image.Bounds);
return new CoreSize(image.Width, image.Height);

10
tests/ImageSharp.Benchmarks/Samplers/Resize.cs

@ -13,8 +13,6 @@ namespace ImageSharp.Benchmarks
using ImageSharp.PixelFormats;
using CoreSize = ImageSharp.Size;
using CoreImage = ImageSharp.Image;
using CoreImageVector = ImageSharp.Image<PixelFormats.RgbaVector>;
public class Resize : BenchmarkBase
{
@ -41,7 +39,7 @@ namespace ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Resize")]
public CoreSize ResizeCore()
{
using (CoreImage image = new CoreImage(2000, 2000))
using (Image<Rgba32> image = new Image<Rgba32>(2000, 2000))
{
image.Resize(400, 400);
return new CoreSize(image.Width, image.Height);
@ -51,7 +49,7 @@ namespace ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Vector Resize")]
public CoreSize ResizeCoreVector()
{
using (CoreImageVector image = new CoreImageVector(2000, 2000))
using (Image<RgbaVector> image = new Image<RgbaVector>(2000, 2000))
{
image.Resize(400, 400);
return new CoreSize(image.Width, image.Height);
@ -61,7 +59,7 @@ namespace ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Compand Resize")]
public CoreSize ResizeCoreCompand()
{
using (CoreImage image = new CoreImage(2000, 2000))
using (Image<Rgba32> image = new Image<Rgba32>(2000, 2000))
{
image.Resize(400, 400, true);
return new CoreSize(image.Width, image.Height);
@ -71,7 +69,7 @@ namespace ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Vector Compand Resize")]
public CoreSize ResizeCoreVectorCompand()
{
using (CoreImageVector image = new CoreImageVector(2000, 2000))
using (Image<RgbaVector> image = new Image<RgbaVector>(2000, 2000))
{
image.Resize(400, 400, true);
return new CoreSize(image.Width, image.Height);

3
tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj

@ -29,4 +29,7 @@
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>

8
tests/ImageSharp.Tests/ConfigurationTests.cs

@ -11,6 +11,8 @@ namespace ImageSharp.Tests
using ImageSharp.Formats;
using ImageSharp.IO;
using ImageSharp.PixelFormats;
using Xunit;
/// <summary>
@ -236,7 +238,7 @@ namespace ImageSharp.Tests
{
Configuration.Default.AddImageFormat(new PngFormat());
Image image = new Image(1, 1);
Image<Rgba32> image = new Image<Rgba32>(1, 1);
Assert.Equal(image.Configuration.ParallelOptions, Configuration.Default.ParallelOptions);
Assert.Equal(image.Configuration.ImageFormats, Configuration.Default.ImageFormats);
}
@ -249,8 +251,8 @@ namespace ImageSharp.Tests
{
Configuration.Default.AddImageFormat(new PngFormat());
Image image = new Image(1, 1);
Image image2 = new Image(image);
Image<Rgba32> image = new Image<Rgba32>(1, 1);
Image<Rgba32> image2 = new Image<Rgba32>(image);
Assert.Equal(image2.Configuration.ParallelOptions, image.Configuration.ParallelOptions);
Assert.True(image2.Configuration.ImageFormats.SequenceEqual(image.Configuration.ImageFormats));
}

4
tests/ImageSharp.Tests/Drawing/BeziersTests.cs

@ -22,7 +22,7 @@ namespace ImageSharp.Tests.Drawing
public void ImageShouldBeOverlayedByBezierLine()
{
string path = this.CreateOutputDirectory("Drawing", "BezierLine");
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/Simple.png"))
{
@ -64,7 +64,7 @@ namespace ImageSharp.Tests.Drawing
Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150);
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/Opacity.png"))
{

4
tests/ImageSharp.Tests/Drawing/DrawPathTests.cs

@ -20,7 +20,7 @@ namespace ImageSharp.Tests.Drawing
public void ImageShouldBeOverlayedByPath()
{
string path = this.CreateOutputDirectory("Drawing", "Path");
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
LinearLineSegment linerSegemnt = new LinearLineSegment(
new Vector2(10, 10),
@ -74,7 +74,7 @@ namespace ImageSharp.Tests.Drawing
ShapePath p = new ShapePath(linerSegemnt, bazierSegment);
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/Opacity.png"))
{

2
tests/ImageSharp.Tests/Drawing/FillPatternTests.cs

@ -18,7 +18,7 @@ namespace ImageSharp.Tests.Drawing
private void Test(string name, Rgba32 background, IBrush<Rgba32> brush, Rgba32[,] expectedPattern)
{
string path = this.CreateOutputDirectory("Fill", "PatternBrush");
using (Image image = new Image(20, 20))
using (Image<Rgba32> image = new Image<Rgba32>(20, 20))
{
image
.Fill(background)

4
tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs

@ -16,7 +16,7 @@ namespace ImageSharp.Tests.Drawing
[InlineData(true, 2, 4)]
[InlineData(true, 5, 5)]
[InlineData(true, 8, 8)]
[InlineData(false, 8, 4)]
[InlineData(false, 8, 4)]
[InlineData(false, 16, 4)] // we always do 4 sub=pixels when antialising is off.
public void MinimumAntialiasSubpixelDepth(bool antialias, int antialiasSubpixelDepth, int expectedAntialiasSubpixelDepth)
{
@ -30,7 +30,7 @@ namespace ImageSharp.Tests.Drawing
AntialiasSubpixelDepth = 1
};
FillRegionProcessor<Rgba32> processor = new FillRegionProcessor<Rgba32>(brush.Object, region.Object, options);
Image img = new Image(1, 1);
Image<Rgba32> img = new Image<Rgba32>(1, 1);
processor.Apply(img, bounds);
region.Verify(x => x.Scan(It.IsAny<float>(), It.IsAny<float[]>(), It.IsAny<int>(), It.IsAny<int>()), Times.Exactly(4));

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

@ -22,7 +22,7 @@ namespace ImageSharp.Tests.Drawing
public void ImageShouldBeFloodFilledWithColorOnDefaultBackground()
{
string path = this.CreateOutputDirectory("Fill", "SolidBrush");
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/DefaultBack.png"))
{
@ -44,7 +44,7 @@ namespace ImageSharp.Tests.Drawing
public void ImageShouldBeFloodFilledWithColor()
{
string path = this.CreateOutputDirectory("Fill", "SolidBrush");
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/Simple.png"))
{
@ -67,7 +67,7 @@ namespace ImageSharp.Tests.Drawing
public void ImageShouldBeFloodFilledWithColorOpacity()
{
string path = this.CreateOutputDirectory("Fill", "SolidBrush");
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150);

10
tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs

@ -32,7 +32,7 @@ namespace ImageSharp.Tests.Drawing
new Vector2(93, 85),
new Vector2(65, 137)));
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/Simple.png"))
{
@ -82,7 +82,7 @@ namespace ImageSharp.Tests.Drawing
new Vector2(263, 25),
new Vector2(235, 57)));
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/SimpleVanishHole.png"))
{
@ -133,7 +133,7 @@ namespace ImageSharp.Tests.Drawing
new Vector2(130, 40),
new Vector2(65, 137)));
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/SimpleOverlapping.png"))
{
@ -179,7 +179,7 @@ namespace ImageSharp.Tests.Drawing
new Vector2(93, 85),
new Vector2(65, 137)));
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/Dashed.png"))
{
@ -207,7 +207,7 @@ namespace ImageSharp.Tests.Drawing
new Vector2(65, 137)));
Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150);
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/Opacity.png"))
{

16
tests/ImageSharp.Tests/Drawing/LineTests.cs

@ -21,7 +21,7 @@ namespace ImageSharp.Tests.Drawing
public void ImageShouldBeOverlayedByPath()
{
string path = this.CreateOutputDirectory("Drawing", "Lines");
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/Simple.png"))
{
@ -51,7 +51,7 @@ namespace ImageSharp.Tests.Drawing
public void ImageShouldBeOverlayedByPath_NoAntialias()
{
string path = this.CreateOutputDirectory("Drawing", "Lines");
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/Simple_noantialias.png"))
{
@ -82,7 +82,7 @@ namespace ImageSharp.Tests.Drawing
public void ImageShouldBeOverlayedByPathDashed()
{
string path = this.CreateOutputDirectory("Drawing", "Lines");
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/Dashed.png"))
{
@ -103,7 +103,7 @@ namespace ImageSharp.Tests.Drawing
public void ImageShouldBeOverlayedByPathDotted()
{
string path = this.CreateOutputDirectory("Drawing", "Lines");
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/Dot.png"))
{
@ -124,7 +124,7 @@ namespace ImageSharp.Tests.Drawing
public void ImageShouldBeOverlayedByPathDashDot()
{
string path = this.CreateOutputDirectory("Drawing", "Lines");
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/DashDot.png"))
{
@ -145,7 +145,7 @@ namespace ImageSharp.Tests.Drawing
public void ImageShouldBeOverlayedByPathDashDotDot()
{
string path = this.CreateOutputDirectory("Drawing", "Lines");
Image image = new Image(500, 500);
Image<Rgba32> image = new Image<Rgba32>(500, 500);
using (FileStream output = File.OpenWrite($"{path}/DashDotDot.png"))
{
@ -167,7 +167,7 @@ namespace ImageSharp.Tests.Drawing
Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150);
Image image = new Image(500, 500);
Image<Rgba32> image = new Image<Rgba32>(500, 500);
using (FileStream output = File.OpenWrite($"{path}/Opacity.png"))
@ -200,7 +200,7 @@ namespace ImageSharp.Tests.Drawing
{
string path = this.CreateOutputDirectory("Drawing", "Lines");
Image image = new Image(500, 500);
Image<Rgba32> image = new Image<Rgba32>(500, 500);
using (FileStream output = File.OpenWrite($"{path}/Rectangle.png"))
{

4
tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs

@ -18,8 +18,8 @@ namespace ImageSharp.Tests.Drawing.Paths
float thickness = 7.2f;
GraphicsOptions noneDefault = new GraphicsOptions();
Rgba32 color = Rgba32.HotPink;
SolidBrush brush = Brushes.Solid(Rgba32.HotPink);
Pen pen = new Pen(Rgba32.Firebrick, 99.9f);
SolidBrush<Rgba32> brush = Brushes.Solid(Rgba32.HotPink);
Pen<Rgba32> pen = new Pen<Rgba32>(Rgba32.Firebrick, 99.9f);
Vector2[] points = new Vector2[] {
new Vector2(10,10),
new Vector2(20,10),

4
tests/ImageSharp.Tests/Drawing/Paths/DrawLinesTests.cs

@ -17,8 +17,8 @@ namespace ImageSharp.Tests.Drawing.Paths
float thickness = 7.2f;
GraphicsOptions noneDefault = new GraphicsOptions();
Rgba32 color = Rgba32.HotPink;
SolidBrush brush = Brushes.Solid(Rgba32.HotPink);
Pen pen = new Pen(Rgba32.Gray, 99.9f);
SolidBrush<Rgba32> brush = Brushes.Solid(Rgba32.HotPink);
Pen<Rgba32> pen = new Pen<Rgba32>(Rgba32.Gray, 99.9f);
Vector2[] points = new Vector2[] {
new Vector2(10,10),
new Vector2(20,10),

6
tests/ImageSharp.Tests/Drawing/Paths/DrawPath.cs

@ -18,8 +18,8 @@ namespace ImageSharp.Tests.Drawing.Paths
float thickness = 7.2f;
GraphicsOptions noneDefault = new GraphicsOptions();
Rgba32 color = Rgba32.HotPink;
SolidBrush brush = Brushes.Solid(Rgba32.HotPink);
Pen pen = new Pen(Rgba32.Gray, 99.9f);
SolidBrush<Rgba32> brush = Brushes.Solid(Rgba32.HotPink);
Pen<Rgba32> pen = new Pen<Rgba32>(Rgba32.Gray, 99.9f);
IPath path = new SixLabors.Shapes.Path(new LinearLineSegment(new Vector2[] {
new Vector2(10,10),
new Vector2(20,10),
@ -50,7 +50,7 @@ namespace ImageSharp.Tests.Drawing.Paths
ShapePath shapepath = Assert.IsType<ShapePath>(processor.Path);
Assert.Equal(path, shapepath.Path);
Pen<Rgba32> pen = Assert.IsType<Pen<Rgba32>>(processor.Pen);
Assert.Equal(brush, pen.Brush);
Assert.Equal(thickness, pen.Width);

4
tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs

@ -18,8 +18,8 @@ namespace ImageSharp.Tests.Drawing.Paths
float thickness = 7.2f;
GraphicsOptions noneDefault = new GraphicsOptions();
Rgba32 color = Rgba32.HotPink;
SolidBrush brush = Brushes.Solid(Rgba32.HotPink);
Pen pen = new Pen(Rgba32.Gray, 99.9f);
SolidBrush<Rgba32> brush = Brushes.Solid(Rgba32.HotPink);
Pen<Rgba32> pen = new Pen<Rgba32>(Rgba32.Gray, 99.9f);
Vector2[] points = new Vector2[] {
new Vector2(10,10),
new Vector2(20,10),

4
tests/ImageSharp.Tests/Drawing/Paths/DrawRectangle.cs

@ -15,8 +15,8 @@ namespace ImageSharp.Tests.Drawing.Paths
float thickness = 7.2f;
GraphicsOptions noneDefault = new GraphicsOptions();
Rgba32 color = Rgba32.HotPink;
SolidBrush brush = Brushes.Solid(Rgba32.HotPink);
Pen pen = new Pen(Rgba32.Gray, 99.9f);
SolidBrush<Rgba32> brush = Brushes.Solid(Rgba32.HotPink);
Pen<Rgba32> pen = new Pen<Rgba32>(Rgba32.Gray, 99.9f);
ImageSharp.Rectangle rectangle = new ImageSharp.Rectangle(10, 10, 98, 324);
private ProcessorWatchingImage img;

4
tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs

@ -15,7 +15,7 @@ namespace ImageSharp.Tests.Drawing.Paths
{
GraphicsOptions noneDefault = new GraphicsOptions();
Rgba32 color = Rgba32.HotPink;
SolidBrush brush = Brushes.Solid(Rgba32.HotPink);
SolidBrush<Rgba32> brush = Brushes.Solid(Rgba32.HotPink);
IPath path = new SixLabors.Shapes.Path(new LinearLineSegment(new Vector2[] {
new Vector2(10,10),
new Vector2(20,10),
@ -45,7 +45,7 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
// path is converted to a polygon before filling
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
LinearLineSegment segments = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);

6
tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs

@ -15,7 +15,7 @@ namespace ImageSharp.Tests.Drawing.Paths
{
GraphicsOptions noneDefault = new GraphicsOptions();
Rgba32 color = Rgba32.HotPink;
SolidBrush brush = Brushes.Solid(Rgba32.HotPink);
SolidBrush<Rgba32> brush = Brushes.Solid(Rgba32.HotPink);
Vector2[] path = new Vector2[] {
new Vector2(10,10),
new Vector2(20,10),
@ -47,7 +47,7 @@ namespace ImageSharp.Tests.Drawing.Paths
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
LinearLineSegment segemnt = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
Assert.Equal(brush, processor.Brush);
}
@ -72,7 +72,7 @@ namespace ImageSharp.Tests.Drawing.Paths
public void CorrectlySetsColorAndPath()
{
img.FillPolygon(color, path);
Assert.NotEmpty(img.ProcessorApplications);
FillRegionProcessor<Rgba32> processor = Assert.IsType<FillRegionProcessor<Rgba32>>(img.ProcessorApplications[0].processor);

6
tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs

@ -14,7 +14,7 @@ namespace ImageSharp.Tests.Drawing.Paths
{
GraphicsOptions noneDefault = new GraphicsOptions();
Rgba32 color = Rgba32.HotPink;
SolidBrush brush = Brushes.Solid(Rgba32.HotPink);
SolidBrush<Rgba32> brush = Brushes.Solid(Rgba32.HotPink);
ImageSharp.Rectangle rectangle = new ImageSharp.Rectangle(10, 10, 77, 76);
private ProcessorWatchingImage img;
@ -45,7 +45,7 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(rect.Location.Y, rectangle.Y);
Assert.Equal(rect.Size.Width, rectangle.Width);
Assert.Equal(rect.Size.Height, rectangle.Height);
Assert.Equal(brush, processor.Brush);
}
@ -73,7 +73,7 @@ namespace ImageSharp.Tests.Drawing.Paths
public void CorrectlySetsColorAndRectangle()
{
img.Fill(color, rectangle);
Assert.NotEmpty(img.ProcessorApplications);
FillRegionProcessor<Rgba32> processor = Assert.IsType<FillRegionProcessor<Rgba32>>(img.ProcessorApplications[0].processor);

2
tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs

@ -17,7 +17,7 @@ namespace ImageSharp.Tests.Drawing.Paths
public List<ProcessorDetails> ProcessorApplications { get; } = new List<ProcessorDetails>();
public ProcessorWatchingImage(int width, int height)
: base(width, height, Configuration.CreateDefaultInstance())
: base(Configuration.CreateDefaultInstance(), width, height)
{
}

6
tests/ImageSharp.Tests/Drawing/PolygonTests.cs

@ -22,7 +22,7 @@ namespace ImageSharp.Tests.Drawing
{
string path = this.CreateOutputDirectory("Drawing", "Polygons");
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/Simple.png"))
{
@ -62,7 +62,7 @@ namespace ImageSharp.Tests.Drawing
Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150);
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/Opacity.png"))
{
@ -93,7 +93,7 @@ namespace ImageSharp.Tests.Drawing
{
string path = this.CreateOutputDirectory("Drawing", "Polygons");
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/Rectangle.png"))
{

8
tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs

@ -20,11 +20,11 @@ namespace ImageSharp.Tests
{
string path = this.CreateOutputDirectory("Drawing", "RecolorImage");
RecolorBrush brush = new RecolorBrush(Rgba32.Yellow, Rgba32.HotPink, 0.2f);
RecolorBrush<Rgba32> brush = new RecolorBrush<Rgba32>(Rgba32.Yellow, Rgba32.HotPink, 0.2f);
foreach (TestFile file in Files)
{
using (Image image = file.CreateImage())
using (Image<Rgba32> image = file.CreateImage())
{
using (FileStream output = File.OpenWrite($"{path}/{file.FileName}"))
{
@ -40,11 +40,11 @@ namespace ImageSharp.Tests
{
string path = this.CreateOutputDirectory("Drawing", "RecolorImage");
RecolorBrush brush = new RecolorBrush(Rgba32.Yellow, Rgba32.HotPink, 0.2f);
RecolorBrush<Rgba32> brush = new RecolorBrush<Rgba32>(Rgba32.Yellow, Rgba32.HotPink, 0.2f);
foreach (TestFile file in Files)
{
using (Image image = file.CreateImage())
using (Image<Rgba32> image = file.CreateImage())
{
using (FileStream output = File.OpenWrite($"{path}/Shaped_{file.FileName}"))
{

4
tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs

@ -26,7 +26,7 @@ namespace ImageSharp.Tests.Drawing
new Vector2(240, 30),
new Vector2(300, 400)
};
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/Simple.png"))
{
@ -61,7 +61,7 @@ namespace ImageSharp.Tests.Drawing
};
Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150);
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/Opacity.png"))
{

6
tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs

@ -32,7 +32,7 @@ namespace ImageSharp.Tests.Drawing
new Vector2(65, 137)));
IPath clipped = simplePath.Clip(hole1);
// var clipped = new Rectangle(10, 10, 100, 100).Clip(new Rectangle(20, 0, 20, 20));
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/Simple.png"))
{
@ -67,7 +67,7 @@ namespace ImageSharp.Tests.Drawing
new Vector2(130, 40),
new Vector2(65, 137)));
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/SimpleOverlapping.png"))
{
@ -102,7 +102,7 @@ namespace ImageSharp.Tests.Drawing
new Vector2(65, 137)));
Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150);
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/Opacity.png"))
{

24
tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs

@ -29,7 +29,7 @@ namespace ImageSharp.Tests.Drawing
new Vector2(50, 300)
};
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/Simple.png"))
{
@ -55,7 +55,7 @@ namespace ImageSharp.Tests.Drawing
new Vector2(50, 300)
};
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/Pattern.png"))
{
@ -81,7 +81,7 @@ namespace ImageSharp.Tests.Drawing
new Vector2(50, 300)
};
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
using (FileStream output = File.OpenWrite($"{path}/Simple_NoAntialias.png"))
{
image
@ -112,11 +112,11 @@ namespace ImageSharp.Tests.Drawing
new Vector2(50, 300)
};
using (Image brushImage = TestFile.Create(TestImages.Bmp.Car).CreateImage())
using (Image image = new Image(500, 500))
using (Image<Rgba32> brushImage = TestFile.Create(TestImages.Bmp.Car).CreateImage())
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
using (FileStream output = File.OpenWrite($"{path}/Image.png"))
{
ImageBrush brush = new ImageBrush(brushImage);
ImageBrush<Rgba32> brush = new ImageBrush<Rgba32>(brushImage);
image
.BackgroundColor(Rgba32.Blue)
@ -136,7 +136,7 @@ namespace ImageSharp.Tests.Drawing
};
Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150);
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/Opacity.png"))
{
@ -161,7 +161,7 @@ namespace ImageSharp.Tests.Drawing
{
string path = this.CreateOutputDirectory("Drawing", "FilledPolygons");
using (Image image = new Image(500, 500))
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{
using (FileStream output = File.OpenWrite($"{path}/Rectangle.png"))
{
@ -191,7 +191,7 @@ namespace ImageSharp.Tests.Drawing
{
string path = this.CreateOutputDirectory("Drawing", "FilledPolygons");
using (Image image = new Image(100, 100))
using (Image<Rgba32> image = new Image<Rgba32>(100, 100))
{
using (FileStream output = File.OpenWrite($"{path}/Triangle.png"))
{
@ -217,7 +217,7 @@ namespace ImageSharp.Tests.Drawing
Configuration config = Configuration.CreateDefaultInstance();
config.ParallelOptions.MaxDegreeOfParallelism = 1;
using (Image image = new Image(100, 100, config))
using (Image<Rgba32> image = new Image<Rgba32>(config, 100, 100))
{
using (FileStream output = File.OpenWrite($"{path}/Septagon.png"))
{
@ -236,7 +236,7 @@ namespace ImageSharp.Tests.Drawing
Configuration config = Configuration.CreateDefaultInstance();
config.ParallelOptions.MaxDegreeOfParallelism = 1;
using (Image image = new Image(100, 100, config))
using (Image<Rgba32> image = new Image<Rgba32>(config, 100, 100))
{
using (FileStream output = File.OpenWrite($"{path}/ellipse.png"))
{
@ -256,7 +256,7 @@ namespace ImageSharp.Tests.Drawing
Configuration config = Configuration.CreateDefaultInstance();
config.ParallelOptions.MaxDegreeOfParallelism = 1;
using (Image image = new Image(200, 200, config))
using (Image<Rgba32> image = new Image<Rgba32>(config, 200, 200))
{
using (FileStream output = File.OpenWrite($"{path}/clipped-corner.png"))
{

2
tests/ImageSharp.Tests/Drawing/Text/DrawText.cs

@ -24,7 +24,7 @@ namespace ImageSharp.Tests.Drawing.Text
{
Rgba32 color = Rgba32.HotPink;
SolidBrush brush = Brushes.Solid(Rgba32.HotPink);
SolidBrush<Rgba32> brush = Brushes.Solid(Rgba32.HotPink);
IPath path = new SixLabors.Shapes.Path(
new LinearLineSegment(

2
tests/ImageSharp.Tests/Drawing/Text/OutputText.cs

@ -32,7 +32,7 @@ namespace ImageSharp.Tests.Drawing.Text
public void DrawAB()
{
//draws 2 overlapping triangle glyphs twice 1 set on each line
using (Image img = new Image(100, 200))
using (Image<Rgba32> img = new Image<Rgba32>(100, 200))
{
img.Fill(Rgba32.DarkBlue)
.DrawText("AB\nAB", new Font(this.Font, 50), Rgba32.Red, new Vector2(0, 0));

4
tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs

@ -7,6 +7,8 @@ using ImageSharp.Formats;
namespace ImageSharp.Tests
{
using ImageSharp.PixelFormats;
using Xunit;
public class BmpEncoderTests : FileTestBase
@ -27,7 +29,7 @@ namespace ImageSharp.Tests
foreach (TestFile file in Files)
{
string filename = file.GetFileNameWithoutExtension(bitsPerPixel);
using (Image image = file.CreateImage())
using (Image<Rgba32> image = file.CreateImage())
{
image.Save($"{path}/{filename}.bmp", new BmpEncoderOptions { BitsPerPixel = bitsPerPixel });
}

22
tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs

@ -7,6 +7,8 @@ namespace ImageSharp.Tests
{
using System.IO;
using ImageSharp.PixelFormats;
using Xunit;
public class GeneralFormatTests : FileTestBase
@ -18,7 +20,7 @@ namespace ImageSharp.Tests
foreach (TestFile file in Files)
{
using (Image image = file.CreateImage())
using (Image<Rgba32> image = file.CreateImage())
{
using (FileStream output = File.OpenWrite($"{path}/{file.FileName}"))
{
@ -37,7 +39,7 @@ namespace ImageSharp.Tests
foreach (TestFile file in Files)
{
using (Image image = file.CreateImage())
using (Image<Rgba32> image = file.CreateImage())
{
string filename = path + "/" + file.FileNameWithoutExtension + ".txt";
File.WriteAllText(filename, image.ToBase64String());
@ -52,7 +54,7 @@ namespace ImageSharp.Tests
foreach (TestFile file in Files)
{
using (Image image = file.CreateImage())
using (Image<Rgba32> image = file.CreateImage())
{
using (FileStream output = File.OpenWrite($"{path}/{file.FileName}"))
{
@ -69,9 +71,9 @@ namespace ImageSharp.Tests
foreach (TestFile file in Files)
{
using (Image srcImage = file.CreateImage())
using (Image<Rgba32> srcImage = file.CreateImage())
{
using (Image image = new Image(srcImage))
using (Image<Rgba32> image = new Image<Rgba32>(srcImage))
{
using (FileStream output = File.OpenWrite($"{path}/Octree-{file.FileName}"))
{
@ -81,7 +83,7 @@ namespace ImageSharp.Tests
}
}
using (Image image = new Image(srcImage))
using (Image<Rgba32> image = new Image<Rgba32>(srcImage))
{
using (FileStream output = File.OpenWrite($"{path}/Wu-{file.FileName}"))
{
@ -90,7 +92,7 @@ namespace ImageSharp.Tests
}
}
using (Image image = new Image(srcImage))
using (Image<Rgba32> image = new Image<Rgba32>(srcImage))
{
using (FileStream output = File.OpenWrite($"{path}/Palette-{file.FileName}"))
{
@ -109,7 +111,7 @@ namespace ImageSharp.Tests
foreach (TestFile file in Files)
{
using (Image image = file.CreateImage())
using (Image<Rgba32> image = file.CreateImage())
{
using (FileStream output = File.OpenWrite($"{path}/{file.FileNameWithoutExtension}.bmp"))
{
@ -142,7 +144,7 @@ namespace ImageSharp.Tests
foreach (TestFile file in Files)
{
byte[] serialized;
using (Image image = file.CreateImage())
using (Image<Rgba32> image = file.CreateImage())
using (MemoryStream memoryStream = new MemoryStream())
{
image.Save(memoryStream);
@ -150,7 +152,7 @@ namespace ImageSharp.Tests
serialized = memoryStream.ToArray();
}
using (Image image2 = Image.Load(serialized))
using (Image<Rgba32> image2 = Image.Load<Rgba32>(serialized))
using (FileStream output = File.OpenWrite($"{path}/{file.FileName}"))
{
image2.Save(output);

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

Loading…
Cancel
Save