Browse Source

Merge remote-tracking branch 'refs/remotes/origin/master' into feature/icc

af/merge-core
James Jackson-South 9 years ago
parent
commit
ec006586e8
  1. 9
      README.md
  2. 6
      features.md
  3. 62
      src/ImageSharp.Drawing/Brushes/Brushes.cs
  4. 42
      src/ImageSharp.Drawing/Brushes/Brushes{TPixel}.cs
  5. 15
      src/ImageSharp.Drawing/Brushes/IBrush.cs
  6. 8
      src/ImageSharp.Drawing/Brushes/ImageBrush.cs
  7. 29
      src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs
  8. 10
      src/ImageSharp.Drawing/Brushes/PatternBrush.cs
  9. 38
      src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs
  10. 20
      src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs
  11. 10
      src/ImageSharp.Drawing/Brushes/RecolorBrush.cs
  12. 51
      src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs
  13. 8
      src/ImageSharp.Drawing/Brushes/SolidBrush.cs
  14. 31
      src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs
  15. 21
      src/ImageSharp.Drawing/DrawImage.cs
  16. 63
      src/ImageSharp.Drawing/DrawPath.cs
  17. 63
      src/ImageSharp.Drawing/FillRegion.cs
  18. 2
      src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
  19. 61
      src/ImageSharp.Drawing/Paths/DrawBeziers.cs
  20. 61
      src/ImageSharp.Drawing/Paths/DrawLines.cs
  21. 62
      src/ImageSharp.Drawing/Paths/DrawPath.cs
  22. 61
      src/ImageSharp.Drawing/Paths/DrawPolygon.cs
  23. 61
      src/ImageSharp.Drawing/Paths/DrawRectangle.cs
  24. 42
      src/ImageSharp.Drawing/Paths/FillPaths.cs
  25. 40
      src/ImageSharp.Drawing/Paths/FillPolygon.cs
  26. 41
      src/ImageSharp.Drawing/Paths/FillRectangle.cs
  27. 10
      src/ImageSharp.Drawing/Pens/IPen.cs
  28. 14
      src/ImageSharp.Drawing/Pens/Pen.cs
  29. 22
      src/ImageSharp.Drawing/Pens/Pens.cs
  30. 50
      src/ImageSharp.Drawing/Pens/Pens{TPixel}.cs
  31. 60
      src/ImageSharp.Drawing/Pens/Pen{TPixel}.cs
  32. 10
      src/ImageSharp.Drawing/Pens/Processors/ColoredPointInfo.cs
  33. 12
      src/ImageSharp.Drawing/Pens/Processors/PenApplicator.cs
  34. 22
      src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs
  35. 26
      src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs
  36. 25
      src/ImageSharp.Drawing/Processors/FillProcessor.cs
  37. 23
      src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs
  38. 70
      src/ImageSharp.Drawing/Text/DrawText.cs
  39. 728
      src/ImageSharp/Colors/Color.Definitions.cs
  40. 179
      src/ImageSharp/Colors/ColorConstants.cs
  41. 27
      src/ImageSharp/Colors/ColorVector.BulkOperations.cs
  42. 728
      src/ImageSharp/Colors/ColorVector.Definitions.cs
  43. 727
      src/ImageSharp/Colors/NamedColors{TColor}.cs
  44. 6
      src/ImageSharp/Colors/Spaces/IAlmostEquatable.cs
  45. 3
      src/ImageSharp/Common/Extensions/Vector4Extensions.cs
  46. 59
      src/ImageSharp/Common/Helpers/ImageMaths.cs
  47. 42
      src/ImageSharp/Common/Helpers/MathF.cs
  48. 4
      src/ImageSharp/Common/Memory/PixelDataPool{T}.cs
  49. 12
      src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuser.cs
  50. 14
      src/ImageSharp/Dithering/ErrorDiffusion/IErrorDiffuser.cs
  51. 8
      src/ImageSharp/Dithering/Ordered/IOrderedDither.cs
  52. 6
      src/ImageSharp/Dithering/Ordered/OrderedDither4x4.cs
  53. 8
      src/ImageSharp/Formats/Bmp/BmpDecoder.cs
  54. 58
      src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
  55. 16
      src/ImageSharp/Formats/Bmp/BmpEncoder.cs
  56. 42
      src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
  57. 12
      src/ImageSharp/Formats/Bmp/ImageExtensions.cs
  58. 18
      src/ImageSharp/Formats/Gif/GifDecoder.cs
  59. 40
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs
  60. 16
      src/ImageSharp/Formats/Gif/GifEncoder.cs
  61. 88
      src/ImageSharp/Formats/Gif/GifEncoderCore.cs
  62. 20
      src/ImageSharp/Formats/Gif/ImageExtensions.cs
  63. 10
      src/ImageSharp/Formats/IImageDecoder.cs
  64. 12
      src/ImageSharp/Formats/IImageEncoder.cs
  65. 20
      src/ImageSharp/Formats/Jpeg/ImageExtensions.cs
  66. 8
      src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
  67. 105
      src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
  68. 16
      src/ImageSharp/Formats/Jpeg/JpegEncoder.cs
  69. 55
      src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs
  70. 26
      src/ImageSharp/Formats/Jpeg/Utils/JpegUtils.cs
  71. 20
      src/ImageSharp/Formats/Png/ImageExtensions.cs
  72. 18
      src/ImageSharp/Formats/Png/PngDecoder.cs
  73. 50
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  74. 16
      src/ImageSharp/Formats/Png/PngEncoder.cs
  75. 70
      src/ImageSharp/Formats/Png/PngEncoderCore.cs
  76. 36
      src/ImageSharp/Image.Create.cs
  77. 10
      src/ImageSharp/Image.Decode.cs
  78. 50
      src/ImageSharp/Image.FromBytes.cs
  79. 51
      src/ImageSharp/Image.FromFile.cs
  80. 55
      src/ImageSharp/Image.FromStream.cs
  81. 11
      src/ImageSharp/Image.cs
  82. 15
      src/ImageSharp/Image/IImageBase{TPixel}.cs
  83. 12
      src/ImageSharp/Image/IImageProcessor.cs
  84. 43
      src/ImageSharp/Image/ImageBase{TPixel}.cs
  85. 39
      src/ImageSharp/Image/ImageFrame{TPixel}.cs
  86. 13
      src/ImageSharp/Image/ImageProcessingExtensions.cs
  87. 111
      src/ImageSharp/Image/Image{TPixel}.cs
  88. 98
      src/ImageSharp/Image/PixelAccessor{TPixel}.cs
  89. 25
      src/ImageSharp/Image/PixelArea{TPixel}.cs
  90. 18
      src/ImageSharp/ImageProcessor.cs
  91. 2
      src/ImageSharp/ImageSharp.csproj
  92. 12
      src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs
  93. 5
      src/ImageSharp/PixelFormats/Alpha8.cs
  94. 4
      src/ImageSharp/PixelFormats/Argb32.cs
  95. 3
      src/ImageSharp/PixelFormats/Bgr565.cs
  96. 3
      src/ImageSharp/PixelFormats/Bgra4444.cs
  97. 2
      src/ImageSharp/PixelFormats/Bgra5551.cs
  98. 76
      src/ImageSharp/PixelFormats/BulkPixelOperations{TPixel}.cs
  99. 3
      src/ImageSharp/PixelFormats/Byte4.cs
  100. 34
      src/ImageSharp/PixelFormats/ColorBuilder{TPixel}.cs

9
README.md

@ -39,7 +39,7 @@ The **ImageSharp** library is made up of multiple packages.
Packages include: Packages include:
- **ImageSharp** - **ImageSharp**
- Contains the Image classes, Colors, Primitives, Configuration, and other core functionality. - Contains the Image classes, PixelFormats, Primitives, Configuration, and other core functionality.
- The IImageFormat interface, Jpeg, Png, Bmp, and Gif formats. - The IImageFormat interface, Jpeg, Png, Bmp, and Gif formats.
- Transform methods like Resize, Crop, Skew, Rotate - Anything that alters the dimensions of the image. - 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. - Non-transform methods like Gaussian Blur, Pixelate, Edge Detection - Anything that maintains the original image dimensions.
@ -108,11 +108,12 @@ Setting individual pixel values is perfomed as follows:
using (image = new Image(400, 400) using (image = new Image(400, 400)
using (var pixels = image.Lock()) using (var pixels = image.Lock())
{ {
pixels[200, 200] = Color.White; // Rgba32 is our default PixelFormat, equivalent to System.Drawing Color
pixels[200, 200] = Rgba32.White;
} }
``` ```
For advanced usage the `Image<TColor>` and `PixelAccessor<TColor>` 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 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.
All in all this should allow image processing to be much more accessible to developers which has always been my goal from the start. All in all this should allow image processing to be much more accessible to developers which has always been my goal from the start.
@ -204,4 +205,4 @@ Become a sponsor and get your logo on our README on Github with a link to your s
<a href="https://opencollective.com/imagesharp/sponsor/26/website" target="_blank"><img src="https://opencollective.com/imagesharp/sponsor/26/avatar.svg"></a> <a href="https://opencollective.com/imagesharp/sponsor/26/website" target="_blank"><img src="https://opencollective.com/imagesharp/sponsor/26/avatar.svg"></a>
<a href="https://opencollective.com/imagesharp/sponsor/27/website" target="_blank"><img src="https://opencollective.com/imagesharp/sponsor/27/avatar.svg"></a> <a href="https://opencollective.com/imagesharp/sponsor/27/website" target="_blank"><img src="https://opencollective.com/imagesharp/sponsor/27/avatar.svg"></a>
<a href="https://opencollective.com/imagesharp/sponsor/28/website" target="_blank"><img src="https://opencollective.com/imagesharp/sponsor/28/avatar.svg"></a> <a href="https://opencollective.com/imagesharp/sponsor/28/website" target="_blank"><img src="https://opencollective.com/imagesharp/sponsor/28/avatar.svg"></a>
<a href="https://opencollective.com/imagesharp/sponsor/29/website" target="_blank"><img src="https://opencollective.com/imagesharp/sponsor/29/avatar.svg"></a> <a href="https://opencollective.com/imagesharp/sponsor/29/website" target="_blank"><img src="https://opencollective.com/imagesharp/sponsor/29/avatar.svg"></a>

6
features.md

@ -13,6 +13,7 @@ We've achieved a lot so far and hope to do a lot more in the future. We're alway
- [ ] Tiff (Help needed) - [ ] Tiff (Help needed)
- **Metadata** - **Metadata**
- [x] EXIF Read/Write (Jpeg just now) - [x] EXIF Read/Write (Jpeg just now)
- [ ] ICC (In Progress)
- **Quantizers (IQuantizer with alpha channel support, dithering, and thresholding)** - **Quantizers (IQuantizer with alpha channel support, dithering, and thresholding)**
- [x] Octree - [x] Octree
- [x] Xiaolin Wu - [x] Xiaolin Wu
@ -28,7 +29,6 @@ We've achieved a lot so far and hope to do a lot more in the future. We're alway
- [x] Bayer - [x] Bayer
- [x] Ordered - [x] Ordered
- **Basic color structs with implicit operators.** - **Basic color structs with implicit operators.**
- [x] Color - 32bit color in RGBA order (IPackedPixel\<TPacked\>).
- [x] Bgra32 - [x] Bgra32
- [x] CIE Lab - [x] CIE Lab
- [x] CIE XYZ - [x] CIE XYZ
@ -38,7 +38,7 @@ We've achieved a lot so far and hope to do a lot more in the future. We're alway
- [x] YCbCr - [x] YCbCr
- **IPackedPixel representations of color models. Compatible with Microsoft XNA Game Studio and MonoGame IPackedVector\<TPacked\>.** - **IPackedPixel representations of color models. Compatible with Microsoft XNA Game Studio and MonoGame IPackedVector\<TPacked\>.**
- [x] Alpha8 - [x] Alpha8
- [x] Argb - [x] Argb32
- [x] Bgr565 - [x] Bgr565
- [x] Bgra444 - [x] Bgra444
- [x] Bgra565 - [x] Bgra565
@ -52,7 +52,9 @@ We've achieved a lot so far and hope to do a lot more in the future. We're alway
- [x] NormalizedShort4 - [x] NormalizedShort4
- [x] Rg32 - [x] Rg32
- [x] Rgba1010102 - [x] Rgba1010102
- [x] Rgba32 - 32bit color in RGBA order - Our default pixel format.
- [x] Rgba64 - [x] Rgba64
- [x] RgbaVector
- [x] Short2 - [x] Short2
- [x] Short4 - [x] Short4
- **Basic shape primitives.** - **Basic shape primitives.**

62
src/ImageSharp.Drawing/Brushes/Brushes.cs

@ -5,8 +5,10 @@
namespace ImageSharp.Drawing.Brushes namespace ImageSharp.Drawing.Brushes
{ {
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// A collection of methods for creating brushes. Brushes use <see cref="Color"/> for painting. /// A collection of methods for creating brushes. Brushes use <see cref="Rgba32"/> for painting.
/// </summary> /// </summary>
public class Brushes public class Brushes
{ {
@ -15,7 +17,7 @@ namespace ImageSharp.Drawing.Brushes
/// </summary> /// </summary>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <returns>A Brush</returns> /// <returns>A Brush</returns>
public static SolidBrush Solid(Color color) public static SolidBrush Solid(Rgba32 color)
=> new SolidBrush(color); => new SolidBrush(color);
/// <summary> /// <summary>
@ -24,8 +26,8 @@ namespace ImageSharp.Drawing.Brushes
/// </summary> /// </summary>
/// <param name="foreColor">Color of the foreground.</param> /// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns> /// <returns>A Brush</returns>
public static PatternBrush Percent10(Color foreColor) public static PatternBrush Percent10(Rgba32 foreColor)
=> new PatternBrush(Brushes<Color>.Percent10(foreColor, Color.Transparent)); => new PatternBrush(Brushes<Rgba32>.Percent10(foreColor, Rgba32.Transparent));
/// <summary> /// <summary>
/// Create as brush that will paint a Percent10 Hatch Pattern with /// Create as brush that will paint a Percent10 Hatch Pattern with
@ -34,8 +36,8 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param> /// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param> /// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns> /// <returns>A Brush</returns>
public static PatternBrush Percent10(Color foreColor, Color backColor) public static PatternBrush Percent10(Rgba32 foreColor, Rgba32 backColor)
=> new PatternBrush(Brushes<Color>.Percent10(foreColor, backColor)); => new PatternBrush(Brushes<Rgba32>.Percent10(foreColor, backColor));
/// <summary> /// <summary>
/// Create as brush that will paint a Percent20 Hatch Pattern with /// Create as brush that will paint a Percent20 Hatch Pattern with
@ -43,8 +45,8 @@ namespace ImageSharp.Drawing.Brushes
/// </summary> /// </summary>
/// <param name="foreColor">Color of the foreground.</param> /// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns> /// <returns>A Brush</returns>
public static PatternBrush Percent20(Color foreColor) public static PatternBrush Percent20(Rgba32 foreColor)
=> new PatternBrush(Brushes<Color>.Percent20(foreColor, Color.Transparent)); => new PatternBrush(Brushes<Rgba32>.Percent20(foreColor, Rgba32.Transparent));
/// <summary> /// <summary>
/// Create as brush that will paint a Percent20 Hatch Pattern with /// Create as brush that will paint a Percent20 Hatch Pattern with
@ -53,8 +55,8 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param> /// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param> /// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns> /// <returns>A Brush</returns>
public static PatternBrush Percent20(Color foreColor, Color backColor) public static PatternBrush Percent20(Rgba32 foreColor, Rgba32 backColor)
=> new PatternBrush(Brushes<Color>.Percent20(foreColor, backColor)); => new PatternBrush(Brushes<Rgba32>.Percent20(foreColor, backColor));
/// <summary> /// <summary>
/// Create as brush that will paint a Horizontal Hatch Pattern with /// Create as brush that will paint a Horizontal Hatch Pattern with
@ -62,8 +64,8 @@ namespace ImageSharp.Drawing.Brushes
/// </summary> /// </summary>
/// <param name="foreColor">Color of the foreground.</param> /// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns> /// <returns>A Brush</returns>
public static PatternBrush Horizontal(Color foreColor) public static PatternBrush Horizontal(Rgba32 foreColor)
=> new PatternBrush(Brushes<Color>.Horizontal(foreColor, Color.Transparent)); => new PatternBrush(Brushes<Rgba32>.Horizontal(foreColor, Rgba32.Transparent));
/// <summary> /// <summary>
/// Create as brush that will paint a Horizontal Hatch Pattern with /// Create as brush that will paint a Horizontal Hatch Pattern with
@ -72,8 +74,8 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param> /// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param> /// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns> /// <returns>A Brush</returns>
public static PatternBrush Horizontal(Color foreColor, Color backColor) public static PatternBrush Horizontal(Rgba32 foreColor, Rgba32 backColor)
=> new PatternBrush(Brushes<Color>.Horizontal(foreColor, backColor)); => new PatternBrush(Brushes<Rgba32>.Horizontal(foreColor, backColor));
/// <summary> /// <summary>
/// Create as brush that will paint a Min Hatch Pattern with /// Create as brush that will paint a Min Hatch Pattern with
@ -81,8 +83,8 @@ namespace ImageSharp.Drawing.Brushes
/// </summary> /// </summary>
/// <param name="foreColor">Color of the foreground.</param> /// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns> /// <returns>A Brush</returns>
public static PatternBrush Min(Color foreColor) public static PatternBrush Min(Rgba32 foreColor)
=> new PatternBrush(Brushes<Color>.Min(foreColor, Color.Transparent)); => new PatternBrush(Brushes<Rgba32>.Min(foreColor, Rgba32.Transparent));
/// <summary> /// <summary>
/// Create as brush that will paint a Min Hatch Pattern with /// Create as brush that will paint a Min Hatch Pattern with
@ -91,8 +93,8 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param> /// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param> /// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns> /// <returns>A Brush</returns>
public static PatternBrush Min(Color foreColor, Color backColor) public static PatternBrush Min(Rgba32 foreColor, Rgba32 backColor)
=> new PatternBrush(Brushes<Color>.Min(foreColor, backColor)); => new PatternBrush(Brushes<Rgba32>.Min(foreColor, backColor));
/// <summary> /// <summary>
/// Create as brush that will paint a Vertical Hatch Pattern with /// Create as brush that will paint a Vertical Hatch Pattern with
@ -100,8 +102,8 @@ namespace ImageSharp.Drawing.Brushes
/// </summary> /// </summary>
/// <param name="foreColor">Color of the foreground.</param> /// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns> /// <returns>A Brush</returns>
public static PatternBrush Vertical(Color foreColor) public static PatternBrush Vertical(Rgba32 foreColor)
=> new PatternBrush(Brushes<Color>.Vertical(foreColor, Color.Transparent)); => new PatternBrush(Brushes<Rgba32>.Vertical(foreColor, Rgba32.Transparent));
/// <summary> /// <summary>
/// Create as brush that will paint a Vertical Hatch Pattern with /// Create as brush that will paint a Vertical Hatch Pattern with
@ -110,8 +112,8 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param> /// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param> /// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns> /// <returns>A Brush</returns>
public static PatternBrush Vertical(Color foreColor, Color backColor) public static PatternBrush Vertical(Rgba32 foreColor, Rgba32 backColor)
=> new PatternBrush(Brushes<Color>.Vertical(foreColor, backColor)); => new PatternBrush(Brushes<Rgba32>.Vertical(foreColor, backColor));
/// <summary> /// <summary>
/// Create as brush that will paint a Forward Diagonal Hatch Pattern with /// Create as brush that will paint a Forward Diagonal Hatch Pattern with
@ -119,8 +121,8 @@ namespace ImageSharp.Drawing.Brushes
/// </summary> /// </summary>
/// <param name="foreColor">Color of the foreground.</param> /// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns> /// <returns>A Brush</returns>
public static PatternBrush ForwardDiagonal(Color foreColor) public static PatternBrush ForwardDiagonal(Rgba32 foreColor)
=> new PatternBrush(Brushes<Color>.ForwardDiagonal(foreColor, Color.Transparent)); => new PatternBrush(Brushes<Rgba32>.ForwardDiagonal(foreColor, Rgba32.Transparent));
/// <summary> /// <summary>
/// Create as brush that will paint a Forward Diagonal Hatch Pattern with /// Create as brush that will paint a Forward Diagonal Hatch Pattern with
@ -129,8 +131,8 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param> /// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param> /// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns> /// <returns>A Brush</returns>
public static PatternBrush ForwardDiagonal(Color foreColor, Color backColor) public static PatternBrush ForwardDiagonal(Rgba32 foreColor, Rgba32 backColor)
=> new PatternBrush(Brushes<Color>.ForwardDiagonal(foreColor, backColor)); => new PatternBrush(Brushes<Rgba32>.ForwardDiagonal(foreColor, backColor));
/// <summary> /// <summary>
/// Create as brush that will paint a Backward Diagonal Hatch Pattern with /// Create as brush that will paint a Backward Diagonal Hatch Pattern with
@ -138,8 +140,8 @@ namespace ImageSharp.Drawing.Brushes
/// </summary> /// </summary>
/// <param name="foreColor">Color of the foreground.</param> /// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns> /// <returns>A Brush</returns>
public static PatternBrush BackwardDiagonal(Color foreColor) public static PatternBrush BackwardDiagonal(Rgba32 foreColor)
=> new PatternBrush(Brushes<Color>.BackwardDiagonal(foreColor, Color.Transparent)); => new PatternBrush(Brushes<Rgba32>.BackwardDiagonal(foreColor, Rgba32.Transparent));
/// <summary> /// <summary>
/// Create as brush that will paint a Backward Diagonal Hatch Pattern with /// Create as brush that will paint a Backward Diagonal Hatch Pattern with
@ -148,7 +150,7 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param> /// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param> /// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns> /// <returns>A Brush</returns>
public static PatternBrush BackwardDiagonal(Color foreColor, Color backColor) public static PatternBrush BackwardDiagonal(Rgba32 foreColor, Rgba32 backColor)
=> new PatternBrush(Brushes<Color>.BackwardDiagonal(foreColor, backColor)); => new PatternBrush(Brushes<Rgba32>.BackwardDiagonal(foreColor, backColor));
} }
} }

42
src/ImageSharp.Drawing/Brushes/Brushes{TColor}.cs → src/ImageSharp.Drawing/Brushes/Brushes{TPixel}.cs

@ -1,19 +1,19 @@
// <copyright file="Brushes{TColor}.cs" company="James Jackson-South"> // <copyright file="Brushes{TPixel}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
namespace ImageSharp.Drawing.Brushes namespace ImageSharp.Drawing.Brushes
{ {
using System; using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// A collection of methods for creating generic brushes. /// A collection of methods for creating generic brushes.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A Brush</returns> /// <returns>A Brush</returns>
public class Brushes<TColor> public class Brushes<TPixel>
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Percent10 Hatch Pattern /// Percent10 Hatch Pattern
@ -99,8 +99,8 @@ namespace ImageSharp.Drawing.Brushes
/// </summary> /// </summary>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <returns>A Brush</returns> /// <returns>A Brush</returns>
public static SolidBrush<TColor> Solid(TColor color) public static SolidBrush<TPixel> Solid(TPixel color)
=> new SolidBrush<TColor>(color); => new SolidBrush<TPixel>(color);
/// <summary> /// <summary>
/// Create as brush that will paint a Percent10 Hatch Pattern within the specified colors /// Create as brush that will paint a Percent10 Hatch Pattern within the specified colors
@ -108,8 +108,8 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param> /// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param> /// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns> /// <returns>A Brush</returns>
public static PatternBrush<TColor> Percent10(TColor foreColor, TColor backColor) public static PatternBrush<TPixel> Percent10(TPixel foreColor, TPixel backColor)
=> new PatternBrush<TColor>(foreColor, backColor, Percent10Pattern); => new PatternBrush<TPixel>(foreColor, backColor, Percent10Pattern);
/// <summary> /// <summary>
/// Create as brush that will paint a Percent20 Hatch Pattern within the specified colors /// Create as brush that will paint a Percent20 Hatch Pattern within the specified colors
@ -117,8 +117,8 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param> /// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param> /// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns> /// <returns>A Brush</returns>
public static PatternBrush<TColor> Percent20(TColor foreColor, TColor backColor) public static PatternBrush<TPixel> Percent20(TPixel foreColor, TPixel backColor)
=> new PatternBrush<TColor>(foreColor, backColor, Percent20Pattern); => new PatternBrush<TPixel>(foreColor, backColor, Percent20Pattern);
/// <summary> /// <summary>
/// Create as brush that will paint a Horizontal Hatch Pattern within the specified colors /// Create as brush that will paint a Horizontal Hatch Pattern within the specified colors
@ -126,8 +126,8 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param> /// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param> /// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns> /// <returns>A Brush</returns>
public static PatternBrush<TColor> Horizontal(TColor foreColor, TColor backColor) public static PatternBrush<TPixel> Horizontal(TPixel foreColor, TPixel backColor)
=> new PatternBrush<TColor>(foreColor, backColor, HorizontalPattern); => new PatternBrush<TPixel>(foreColor, backColor, HorizontalPattern);
/// <summary> /// <summary>
/// Create as brush that will paint a Min Hatch Pattern within the specified colors /// Create as brush that will paint a Min Hatch Pattern within the specified colors
@ -135,8 +135,8 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param> /// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param> /// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns> /// <returns>A Brush</returns>
public static PatternBrush<TColor> Min(TColor foreColor, TColor backColor) public static PatternBrush<TPixel> Min(TPixel foreColor, TPixel backColor)
=> new PatternBrush<TColor>(foreColor, backColor, MinPattern); => new PatternBrush<TPixel>(foreColor, backColor, MinPattern);
/// <summary> /// <summary>
/// Create as brush that will paint a Vertical Hatch Pattern within the specified colors /// Create as brush that will paint a Vertical Hatch Pattern within the specified colors
@ -144,8 +144,8 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param> /// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param> /// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns> /// <returns>A Brush</returns>
public static PatternBrush<TColor> Vertical(TColor foreColor, TColor backColor) public static PatternBrush<TPixel> Vertical(TPixel foreColor, TPixel backColor)
=> new PatternBrush<TColor>(foreColor, backColor, VerticalPattern); => new PatternBrush<TPixel>(foreColor, backColor, VerticalPattern);
/// <summary> /// <summary>
/// Create as brush that will paint a Forward Diagonal Hatch Pattern within the specified colors /// Create as brush that will paint a Forward Diagonal Hatch Pattern within the specified colors
@ -153,8 +153,8 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param> /// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param> /// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns> /// <returns>A Brush</returns>
public static PatternBrush<TColor> ForwardDiagonal(TColor foreColor, TColor backColor) public static PatternBrush<TPixel> ForwardDiagonal(TPixel foreColor, TPixel backColor)
=> new PatternBrush<TColor>(foreColor, backColor, ForwardDiagonalPattern); => new PatternBrush<TPixel>(foreColor, backColor, ForwardDiagonalPattern);
/// <summary> /// <summary>
/// Create as brush that will paint a Backward Diagonal Hatch Pattern within the specified colors /// Create as brush that will paint a Backward Diagonal Hatch Pattern within the specified colors
@ -162,7 +162,7 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param> /// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param> /// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns> /// <returns>A Brush</returns>
public static PatternBrush<TColor> BackwardDiagonal(TColor foreColor, TColor backColor) public static PatternBrush<TPixel> BackwardDiagonal(TPixel foreColor, TPixel backColor)
=> new PatternBrush<TColor>(foreColor, backColor, BackwardDiagonalPattern); => new PatternBrush<TPixel>(foreColor, backColor, BackwardDiagonalPattern);
} }
} }

15
src/ImageSharp.Drawing/Brushes/IBrush.cs

@ -5,20 +5,19 @@
namespace ImageSharp.Drawing namespace ImageSharp.Drawing
{ {
using System; using ImageSharp.PixelFormats;
using Processors; using Processors;
/// <summary> /// <summary>
/// Brush represents a logical configuration of a brush which can be used to source pixel colors /// Brush represents a logical configuration of a brush which can be used to source pixel colors
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <remarks> /// <remarks>
/// A brush is a simple class that will return an <see cref="BrushApplicator{TColor}" /> that will perform the /// A brush is a simple class that will return an <see cref="BrushApplicator{TPixel}" /> that will perform the
/// logic for converting a pixel location to a <typeparamref name="TColor"/>. /// logic for converting a pixel location to a <typeparamref name="TPixel"/>.
/// </remarks> /// </remarks>
public interface IBrush<TColor> public interface IBrush<TPixel>
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Creates the applicator for this brush. /// Creates the applicator for this brush.
@ -32,6 +31,6 @@ namespace ImageSharp.Drawing
/// The <paramref name="region" /> when being applied to things like shapes would usually be the /// The <paramref name="region" /> when being applied to things like shapes would usually be the
/// bounding box of the shape not necessarily the bounds of the whole image /// bounding box of the shape not necessarily the bounds of the whole image
/// </remarks> /// </remarks>
BrushApplicator<TColor> CreateApplicator(PixelAccessor<TColor> pixelSource, RectangleF region); BrushApplicator<TPixel> CreateApplicator(PixelAccessor<TPixel> pixelSource, RectangleF region);
} }
} }

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

@ -5,16 +5,18 @@
namespace ImageSharp.Drawing.Brushes namespace ImageSharp.Drawing.Brushes
{ {
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Provides an implementation of a solid brush for painting with repeating images. The brush uses <see cref="Color"/> for painting. /// Provides an implementation of a solid brush for painting with repeating images. The brush uses <see cref="Rgba32"/> for painting.
/// </summary> /// </summary>
public class ImageBrush : ImageBrush<Color> public class ImageBrush : ImageBrush<Rgba32>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ImageBrush" /> class. /// Initializes a new instance of the <see cref="ImageBrush" /> class.
/// </summary> /// </summary>
/// <param name="image">The image to paint.</param> /// <param name="image">The image to paint.</param>
public ImageBrush(IImageBase<Color> image) public ImageBrush(IImageBase<Rgba32> image)
: base(image) : base(image)
{ {
} }

29
src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs → src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs

@ -1,38 +1,37 @@
// <copyright file="ImageBrush{TColor}.cs" company="James Jackson-South"> // <copyright file="ImageBrush{TPixel}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
namespace ImageSharp.Drawing.Brushes namespace ImageSharp.Drawing.Brushes
{ {
using System;
using System.Numerics; using System.Numerics;
using ImageSharp.PixelFormats;
using Processors; using Processors;
/// <summary> /// <summary>
/// Provides an implementation of an image brush for painting images within areas. /// Provides an implementation of an image brush for painting images within areas.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
public class ImageBrush<TColor> : IBrush<TColor> public class ImageBrush<TPixel> : IBrush<TPixel>
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// The image to paint. /// The image to paint.
/// </summary> /// </summary>
private readonly IImageBase<TColor> image; private readonly IImageBase<TPixel> image;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ImageBrush{TColor}"/> class. /// Initializes a new instance of the <see cref="ImageBrush{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="image">The image.</param> /// <param name="image">The image.</param>
public ImageBrush(IImageBase<TColor> image) public ImageBrush(IImageBase<TPixel> image)
{ {
this.image = image; this.image = image;
} }
/// <inheritdoc /> /// <inheritdoc />
public BrushApplicator<TColor> CreateApplicator(PixelAccessor<TColor> sourcePixels, RectangleF region) public BrushApplicator<TPixel> CreateApplicator(PixelAccessor<TPixel> sourcePixels, RectangleF region)
{ {
return new ImageBrushApplicator(sourcePixels, this.image, region); return new ImageBrushApplicator(sourcePixels, this.image, region);
} }
@ -40,12 +39,12 @@ namespace ImageSharp.Drawing.Brushes
/// <summary> /// <summary>
/// The image brush applicator. /// The image brush applicator.
/// </summary> /// </summary>
private class ImageBrushApplicator : BrushApplicator<TColor> private class ImageBrushApplicator : BrushApplicator<TPixel>
{ {
/// <summary> /// <summary>
/// The source pixel accessor. /// The source pixel accessor.
/// </summary> /// </summary>
private readonly PixelAccessor<TColor> source; private readonly PixelAccessor<TPixel> source;
/// <summary> /// <summary>
/// The y-length. /// The y-length.
@ -74,7 +73,7 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="sourcePixels"> /// <param name="sourcePixels">
/// The sourcePixels. /// The sourcePixels.
/// </param> /// </param>
public ImageBrushApplicator(PixelAccessor<TColor> sourcePixels, IImageBase<TColor> image, RectangleF region) public ImageBrushApplicator(PixelAccessor<TPixel> sourcePixels, IImageBase<TPixel> image, RectangleF region)
: base(sourcePixels) : base(sourcePixels)
{ {
this.source = image.Lock(); this.source = image.Lock();
@ -91,7 +90,7 @@ namespace ImageSharp.Drawing.Brushes
/// <returns> /// <returns>
/// The color /// The color
/// </returns> /// </returns>
internal override TColor this[int x, int y] internal override TPixel this[int x, int y]
{ {
get get
{ {
@ -135,7 +134,7 @@ namespace ImageSharp.Drawing.Brushes
Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity); Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity);
TColor packed = default(TColor); TPixel packed = default(TPixel);
packed.PackFromVector4(finalColor); packed.PackFromVector4(finalColor);
this.Target[targetX, targetY] = packed; this.Target[targetX, targetY] = packed;
} }

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

@ -5,10 +5,12 @@
namespace ImageSharp.Drawing.Brushes namespace ImageSharp.Drawing.Brushes
{ {
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Provides an implementation of a pattern brush for painting patterns. The brush use <see cref="Color"/> for painting. /// Provides an implementation of a pattern brush for painting patterns. The brush use <see cref="Rgba32"/> for painting.
/// </summary> /// </summary>
public class PatternBrush : PatternBrush<Color> public class PatternBrush : PatternBrush<Rgba32>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PatternBrush"/> class. /// Initializes a new instance of the <see cref="PatternBrush"/> class.
@ -16,7 +18,7 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the fore.</param> /// <param name="foreColor">Color of the fore.</param>
/// <param name="backColor">Color of the back.</param> /// <param name="backColor">Color of the back.</param>
/// <param name="pattern">The pattern.</param> /// <param name="pattern">The pattern.</param>
public PatternBrush(Color foreColor, Color backColor, bool[,] pattern) public PatternBrush(Rgba32 foreColor, Rgba32 backColor, bool[,] pattern)
: base(foreColor, backColor, pattern) : base(foreColor, backColor, pattern)
{ {
} }
@ -25,7 +27,7 @@ namespace ImageSharp.Drawing.Brushes
/// Initializes a new instance of the <see cref="PatternBrush"/> class. /// Initializes a new instance of the <see cref="PatternBrush"/> class.
/// </summary> /// </summary>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
internal PatternBrush(PatternBrush<Color> brush) internal PatternBrush(PatternBrush<Rgba32> brush)
: base(brush) : base(brush)
{ {
} }

38
src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs → src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs

@ -1,4 +1,4 @@
// <copyright file="PatternBrush{TColor}.cs" company="James Jackson-South"> // <copyright file="PatternBrush{TPixel}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
@ -7,7 +7,7 @@ namespace ImageSharp.Drawing.Brushes
{ {
using System; using System;
using System.Numerics; using System.Numerics;
using ImageSharp.PixelFormats;
using Processors; using Processors;
/// <summary> /// <summary>
@ -31,38 +31,38 @@ namespace ImageSharp.Drawing.Brushes
/// 0 /// 0
/// </para> /// </para>
/// </remarks> /// </remarks>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
public class PatternBrush<TColor> : IBrush<TColor> public class PatternBrush<TPixel> : IBrush<TPixel>
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// The pattern. /// The pattern.
/// </summary> /// </summary>
private readonly Fast2DArray<TColor> pattern; private readonly Fast2DArray<TPixel> pattern;
private readonly Fast2DArray<Vector4> patternVector; private readonly Fast2DArray<Vector4> patternVector;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PatternBrush{TColor}"/> class. /// Initializes a new instance of the <see cref="PatternBrush{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="foreColor">Color of the fore.</param> /// <param name="foreColor">Color of the fore.</param>
/// <param name="backColor">Color of the back.</param> /// <param name="backColor">Color of the back.</param>
/// <param name="pattern">The pattern.</param> /// <param name="pattern">The pattern.</param>
public PatternBrush(TColor foreColor, TColor backColor, bool[,] pattern) public PatternBrush(TPixel foreColor, TPixel backColor, bool[,] pattern)
: this(foreColor, backColor, new Fast2DArray<bool>(pattern)) : this(foreColor, backColor, new Fast2DArray<bool>(pattern))
{ {
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PatternBrush{TColor}"/> class. /// Initializes a new instance of the <see cref="PatternBrush{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="foreColor">Color of the fore.</param> /// <param name="foreColor">Color of the fore.</param>
/// <param name="backColor">Color of the back.</param> /// <param name="backColor">Color of the back.</param>
/// <param name="pattern">The pattern.</param> /// <param name="pattern">The pattern.</param>
internal PatternBrush(TColor foreColor, TColor backColor, Fast2DArray<bool> pattern) internal PatternBrush(TPixel foreColor, TPixel backColor, Fast2DArray<bool> pattern)
{ {
Vector4 foreColorVector = foreColor.ToVector4(); Vector4 foreColorVector = foreColor.ToVector4();
Vector4 backColorVector = backColor.ToVector4(); Vector4 backColorVector = backColor.ToVector4();
this.pattern = new Fast2DArray<TColor>(pattern.Width, pattern.Height); this.pattern = new Fast2DArray<TPixel>(pattern.Width, pattern.Height);
this.patternVector = new Fast2DArray<Vector4>(pattern.Width, pattern.Height); this.patternVector = new Fast2DArray<Vector4>(pattern.Width, pattern.Height);
for (int i = 0; i < pattern.Data.Length; i++) for (int i = 0; i < pattern.Data.Length; i++)
{ {
@ -80,17 +80,17 @@ namespace ImageSharp.Drawing.Brushes
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PatternBrush{TColor}"/> class. /// Initializes a new instance of the <see cref="PatternBrush{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
internal PatternBrush(PatternBrush<TColor> brush) internal PatternBrush(PatternBrush<TPixel> brush)
{ {
this.pattern = brush.pattern; this.pattern = brush.pattern;
this.patternVector = brush.patternVector; this.patternVector = brush.patternVector;
} }
/// <inheritdoc /> /// <inheritdoc />
public BrushApplicator<TColor> CreateApplicator(PixelAccessor<TColor> sourcePixels, RectangleF region) public BrushApplicator<TPixel> CreateApplicator(PixelAccessor<TPixel> sourcePixels, RectangleF region)
{ {
return new PatternBrushApplicator(sourcePixels, this.pattern, this.patternVector); return new PatternBrushApplicator(sourcePixels, this.pattern, this.patternVector);
} }
@ -98,12 +98,12 @@ namespace ImageSharp.Drawing.Brushes
/// <summary> /// <summary>
/// The pattern brush applicator. /// The pattern brush applicator.
/// </summary> /// </summary>
private class PatternBrushApplicator : BrushApplicator<TColor> private class PatternBrushApplicator : BrushApplicator<TPixel>
{ {
/// <summary> /// <summary>
/// The pattern. /// The pattern.
/// </summary> /// </summary>
private readonly Fast2DArray<TColor> pattern; private readonly Fast2DArray<TPixel> pattern;
private readonly Fast2DArray<Vector4> patternVector; private readonly Fast2DArray<Vector4> patternVector;
/// <summary> /// <summary>
@ -112,7 +112,7 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="sourcePixels">The sourcePixels.</param> /// <param name="sourcePixels">The sourcePixels.</param>
/// <param name="pattern">The pattern.</param> /// <param name="pattern">The pattern.</param>
/// <param name="patternVector">The patternVector.</param> /// <param name="patternVector">The patternVector.</param>
public PatternBrushApplicator(PixelAccessor<TColor> sourcePixels, Fast2DArray<TColor> pattern, Fast2DArray<Vector4> patternVector) public PatternBrushApplicator(PixelAccessor<TPixel> sourcePixels, Fast2DArray<TPixel> pattern, Fast2DArray<Vector4> patternVector)
: base(sourcePixels) : base(sourcePixels)
{ {
this.pattern = pattern; this.pattern = pattern;
@ -127,7 +127,7 @@ namespace ImageSharp.Drawing.Brushes
/// <returns> /// <returns>
/// The Color. /// The Color.
/// </returns> /// </returns>
internal override TColor this[int x, int y] internal override TPixel this[int x, int y]
{ {
get get
{ {
@ -169,7 +169,7 @@ namespace ImageSharp.Drawing.Brushes
Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity); Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity);
TColor packed = default(TColor); TPixel packed = default(TPixel);
packed.PackFromVector4(finalColor); packed.PackFromVector4(finalColor);
this.Target[targetX, targetY] = packed; this.Target[targetX, targetY] = packed;
} }

20
src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs

@ -7,21 +7,21 @@ namespace ImageSharp.Drawing.Processors
{ {
using System; using System;
using System.Numerics; using System.Numerics;
using System.Runtime.CompilerServices; using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// primitive that converts a point in to a color for discovering the fill color based on an implementation /// primitive that converts a point in to a color for discovering the fill color based on an implementation
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <seealso cref="System.IDisposable" /> /// <seealso cref="System.IDisposable" />
public abstract class BrushApplicator<TColor> : IDisposable // disposable will be required if/when there is an ImageBrush public abstract class BrushApplicator<TPixel> : IDisposable // disposable will be required if/when there is an ImageBrush
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="BrushApplicator{TColor}"/> class. /// Initializes a new instance of the <see cref="BrushApplicator{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="target">The target.</param> /// <param name="target">The target.</param>
internal BrushApplicator(PixelAccessor<TColor> target) internal BrushApplicator(PixelAccessor<TPixel> target)
{ {
this.Target = target; this.Target = target;
} }
@ -29,15 +29,15 @@ namespace ImageSharp.Drawing.Processors
/// <summary> /// <summary>
/// Gets the destinaion /// Gets the destinaion
/// </summary> /// </summary>
protected PixelAccessor<TColor> Target { get; } protected PixelAccessor<TPixel> Target { get; }
/// <summary> /// <summary>
/// Gets the color for a single pixel. /// Gets the color for a single pixel.
/// </summary> /// </summary>
/// <param name="x">The x cordinate.</param> /// <param name="x">The x cordinate.</param>
/// <param name="y">The y cordinate.</param> /// <param name="y">The y cordinate.</param>
/// <returns>The a <typeparamref name="TColor"/> that should be applied to the pixel.</returns> /// <returns>The a <typeparamref name="TPixel"/> that should be applied to the pixel.</returns>
internal abstract TColor this[int x, int y] { get; } internal abstract TPixel this[int x, int y] { get; }
/// <inheritdoc/> /// <inheritdoc/>
public abstract void Dispose(); public abstract void Dispose();
@ -73,7 +73,7 @@ namespace ImageSharp.Drawing.Processors
Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity); Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity);
TColor packed = default(TColor); TPixel packed = default(TPixel);
packed.PackFromVector4(finalColor); packed.PackFromVector4(finalColor);
this.Target[targetX, targetY] = packed; this.Target[targetX, targetY] = packed;
} }

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

@ -5,19 +5,21 @@
namespace ImageSharp.Drawing.Brushes namespace ImageSharp.Drawing.Brushes
{ {
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Provides an implementation of a recolor brush for painting color changes. /// Provides an implementation of a recolor brush for painting color changes.
/// </summary> /// </summary>
public class RecolorBrush : RecolorBrush<Color> public class RecolorBrush : RecolorBrush<Rgba32>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="RecolorBrush" /> class. /// Initializes a new instance of the <see cref="RecolorBrush" /> class.
/// </summary> /// </summary>
/// <param name="sourceColor">Color of the source.</param> /// <param name="sourceColor">Color of the source.</param>
/// <param name="targetColor">Color of the target.</param> /// <param name="targeTPixel">Color of the target.</param>
/// <param name="threshold">The threshold.</param> /// <param name="threshold">The threshold.</param>
public RecolorBrush(Color sourceColor, Color targetColor, float threshold) public RecolorBrush(Rgba32 sourceColor, Rgba32 targeTPixel, float threshold)
: base(sourceColor, targetColor, threshold) : base(sourceColor, targeTPixel, threshold)
{ {
} }
} }

51
src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs → src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs

@ -1,33 +1,32 @@
// <copyright file="RecolorBrush{TColor}.cs" company="James Jackson-South"> // <copyright file="RecolorBrush{TPixel}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
namespace ImageSharp.Drawing.Brushes namespace ImageSharp.Drawing.Brushes
{ {
using System;
using System.Numerics; using System.Numerics;
using ImageSharp.PixelFormats;
using Processors; using Processors;
/// <summary> /// <summary>
/// Provides an implementation of a brush that can recolor an image /// Provides an implementation of a brush that can recolor an image
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
public class RecolorBrush<TColor> : IBrush<TColor> public class RecolorBrush<TPixel> : IBrush<TPixel>
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="RecolorBrush{TColor}" /> class. /// Initializes a new instance of the <see cref="RecolorBrush{TPixel}" /> class.
/// </summary> /// </summary>
/// <param name="sourceColor">Color of the source.</param> /// <param name="sourceColor">Color of the source.</param>
/// <param name="targetColor">Color of the target.</param> /// <param name="targeTPixel">Color of the target.</param>
/// <param name="threshold">The threshold as a value between 0 and 1.</param> /// <param name="threshold">The threshold as a value between 0 and 1.</param>
public RecolorBrush(TColor sourceColor, TColor targetColor, float threshold) public RecolorBrush(TPixel sourceColor, TPixel targeTPixel, float threshold)
{ {
this.SourceColor = sourceColor; this.SourceColor = sourceColor;
this.Threshold = threshold; this.Threshold = threshold;
this.TargetColor = targetColor; this.TargeTPixel = targeTPixel;
} }
/// <summary> /// <summary>
@ -44,7 +43,7 @@ namespace ImageSharp.Drawing.Brushes
/// <value> /// <value>
/// The color of the source. /// The color of the source.
/// </value> /// </value>
public TColor SourceColor { get; } public TPixel SourceColor { get; }
/// <summary> /// <summary>
/// Gets the target color. /// Gets the target color.
@ -52,18 +51,18 @@ namespace ImageSharp.Drawing.Brushes
/// <value> /// <value>
/// The color of the target. /// The color of the target.
/// </value> /// </value>
public TColor TargetColor { get; } public TPixel TargeTPixel { get; }
/// <inheritdoc /> /// <inheritdoc />
public BrushApplicator<TColor> CreateApplicator(PixelAccessor<TColor> sourcePixels, RectangleF region) public BrushApplicator<TPixel> CreateApplicator(PixelAccessor<TPixel> sourcePixels, RectangleF region)
{ {
return new RecolorBrushApplicator(sourcePixels, this.SourceColor, this.TargetColor, this.Threshold); return new RecolorBrushApplicator(sourcePixels, this.SourceColor, this.TargeTPixel, this.Threshold);
} }
/// <summary> /// <summary>
/// The recolor brush applicator. /// The recolor brush applicator.
/// </summary> /// </summary>
private class RecolorBrushApplicator : BrushApplicator<TColor> private class RecolorBrushApplicator : BrushApplicator<TPixel>
{ {
/// <summary> /// <summary>
/// The source color. /// The source color.
@ -73,7 +72,7 @@ namespace ImageSharp.Drawing.Brushes
/// <summary> /// <summary>
/// The target color. /// The target color.
/// </summary> /// </summary>
private readonly Vector4 targetColor; private readonly Vector4 targeTPixel;
/// <summary> /// <summary>
/// The threshold. /// The threshold.
@ -85,18 +84,18 @@ namespace ImageSharp.Drawing.Brushes
/// </summary> /// </summary>
/// <param name="sourcePixels">The source pixels.</param> /// <param name="sourcePixels">The source pixels.</param>
/// <param name="sourceColor">Color of the source.</param> /// <param name="sourceColor">Color of the source.</param>
/// <param name="targetColor">Color of the target.</param> /// <param name="targeTPixel">Color of the target.</param>
/// <param name="threshold">The threshold .</param> /// <param name="threshold">The threshold .</param>
public RecolorBrushApplicator(PixelAccessor<TColor> sourcePixels, TColor sourceColor, TColor targetColor, float threshold) public RecolorBrushApplicator(PixelAccessor<TPixel> sourcePixels, TPixel sourceColor, TPixel targeTPixel, float threshold)
: base(sourcePixels) : base(sourcePixels)
{ {
this.sourceColor = sourceColor.ToVector4(); this.sourceColor = sourceColor.ToVector4();
this.targetColor = targetColor.ToVector4(); this.targeTPixel = targeTPixel.ToVector4();
// Lets hack a min max extreams for a color space by letteing the IPackedPixel clamp our values to something in the correct spaces :) // Lets hack a min max extreams for a color space by letteing the IPackedPixel clamp our values to something in the correct spaces :)
TColor maxColor = default(TColor); TPixel maxColor = default(TPixel);
maxColor.PackFromVector4(new Vector4(float.MaxValue)); maxColor.PackFromVector4(new Vector4(float.MaxValue));
TColor minColor = default(TColor); TPixel minColor = default(TPixel);
minColor.PackFromVector4(new Vector4(float.MinValue)); minColor.PackFromVector4(new Vector4(float.MinValue));
this.threshold = Vector4.DistanceSquared(maxColor.ToVector4(), minColor.ToVector4()) * threshold; this.threshold = Vector4.DistanceSquared(maxColor.ToVector4(), minColor.ToVector4()) * threshold;
} }
@ -109,12 +108,12 @@ namespace ImageSharp.Drawing.Brushes
/// <returns> /// <returns>
/// The color /// The color
/// </returns> /// </returns>
internal override TColor this[int x, int y] internal override TPixel this[int x, int y]
{ {
get get
{ {
// Offset the requested pixel by the value in the rectangle (the shapes position) // Offset the requested pixel by the value in the rectangle (the shapes position)
TColor result = this.Target[x, y]; TPixel result = this.Target[x, y];
Vector4 background = result.ToVector4(); Vector4 background = result.ToVector4();
float distance = Vector4.DistanceSquared(background, this.sourceColor); float distance = Vector4.DistanceSquared(background, this.sourceColor);
if (distance <= this.threshold) if (distance <= this.threshold)
@ -122,7 +121,7 @@ namespace ImageSharp.Drawing.Brushes
float lerpAmount = (this.threshold - distance) / this.threshold; float lerpAmount = (this.threshold - distance) / this.threshold;
Vector4 blended = Vector4BlendTransforms.PremultipliedLerp( Vector4 blended = Vector4BlendTransforms.PremultipliedLerp(
background, background,
this.targetColor, this.targeTPixel,
lerpAmount); lerpAmount);
result.PackFromVector4(blended); result.PackFromVector4(blended);
} }
@ -162,12 +161,12 @@ namespace ImageSharp.Drawing.Brushes
float lerpAmount = (this.threshold - distance) / this.threshold; float lerpAmount = (this.threshold - distance) / this.threshold;
sourceVector = Vector4BlendTransforms.PremultipliedLerp( sourceVector = Vector4BlendTransforms.PremultipliedLerp(
sourceVector, sourceVector,
this.targetColor, this.targeTPixel,
lerpAmount); lerpAmount);
Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity); Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity);
TColor packed = default(TColor); TPixel packed = default(TPixel);
packed.PackFromVector4(finalColor); packed.PackFromVector4(finalColor);
this.Target[targetX, targetY] = packed; this.Target[targetX, targetY] = packed;
} }

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

@ -5,16 +5,18 @@
namespace ImageSharp.Drawing.Brushes namespace ImageSharp.Drawing.Brushes
{ {
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Provides an implementation of a solid brush for painting solid color areas. The brush uses <see cref="Color"/> for painting. /// Provides an implementation of a solid brush for painting solid color areas. The brush uses <see cref="Rgba32"/> for painting.
/// </summary> /// </summary>
public class SolidBrush : SolidBrush<Color> public class SolidBrush : SolidBrush<Rgba32>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="SolidBrush" /> class. /// Initializes a new instance of the <see cref="SolidBrush" /> class.
/// </summary> /// </summary>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
public SolidBrush(Color color) public SolidBrush(Rgba32 color)
: base(color) : base(color)
{ {
} }

31
src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs → src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs

@ -1,32 +1,31 @@
// <copyright file="SolidBrush{TColor}.cs" company="James Jackson-South"> // <copyright file="SolidBrush{TPixel}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
namespace ImageSharp.Drawing.Brushes namespace ImageSharp.Drawing.Brushes
{ {
using System;
using System.Numerics; using System.Numerics;
using ImageSharp.PixelFormats;
using Processors; using Processors;
/// <summary> /// <summary>
/// Provides an implementation of a solid brush for painting solid color areas. /// Provides an implementation of a solid brush for painting solid color areas.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
public class SolidBrush<TColor> : IBrush<TColor> public class SolidBrush<TPixel> : IBrush<TPixel>
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// The color to paint. /// The color to paint.
/// </summary> /// </summary>
private readonly TColor color; private readonly TPixel color;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="SolidBrush{TColor}"/> class. /// Initializes a new instance of the <see cref="SolidBrush{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
public SolidBrush(TColor color) public SolidBrush(TPixel color)
{ {
this.color = color; this.color = color;
} }
@ -37,10 +36,10 @@ namespace ImageSharp.Drawing.Brushes
/// <value> /// <value>
/// The color. /// The color.
/// </value> /// </value>
public TColor Color => this.color; public TPixel Color => this.color;
/// <inheritdoc /> /// <inheritdoc />
public BrushApplicator<TColor> CreateApplicator(PixelAccessor<TColor> sourcePixels, RectangleF region) public BrushApplicator<TPixel> CreateApplicator(PixelAccessor<TPixel> sourcePixels, RectangleF region)
{ {
return new SolidBrushApplicator(sourcePixels, this.color); return new SolidBrushApplicator(sourcePixels, this.color);
} }
@ -48,12 +47,12 @@ namespace ImageSharp.Drawing.Brushes
/// <summary> /// <summary>
/// The solid brush applicator. /// The solid brush applicator.
/// </summary> /// </summary>
private class SolidBrushApplicator : BrushApplicator<TColor> private class SolidBrushApplicator : BrushApplicator<TPixel>
{ {
/// <summary> /// <summary>
/// The solid color. /// The solid color.
/// </summary> /// </summary>
private readonly TColor color; private readonly TPixel color;
private readonly Vector4 colorVector; private readonly Vector4 colorVector;
/// <summary> /// <summary>
@ -61,7 +60,7 @@ namespace ImageSharp.Drawing.Brushes
/// </summary> /// </summary>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="sourcePixels">The sourcePixels.</param> /// <param name="sourcePixels">The sourcePixels.</param>
public SolidBrushApplicator(PixelAccessor<TColor> sourcePixels, TColor color) public SolidBrushApplicator(PixelAccessor<TPixel> sourcePixels, TPixel color)
: base(sourcePixels) : base(sourcePixels)
{ {
this.color = color; this.color = color;
@ -76,7 +75,7 @@ namespace ImageSharp.Drawing.Brushes
/// <returns> /// <returns>
/// The color /// The color
/// </returns> /// </returns>
internal override TColor this[int x, int y] => this.color; internal override TPixel this[int x, int y] => this.color;
/// <inheritdoc /> /// <inheritdoc />
public override void Dispose() public override void Dispose()
@ -106,7 +105,7 @@ namespace ImageSharp.Drawing.Brushes
Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity); Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity);
TColor packed = default(TColor); TPixel packed = default(TPixel);
packed.PackFromVector4(finalColor); packed.PackFromVector4(finalColor);
this.Target[targetX, targetY] = packed; this.Target[targetX, targetY] = packed;
} }

21
src/ImageSharp.Drawing/DrawImage.cs

@ -5,9 +5,8 @@
namespace ImageSharp namespace ImageSharp
{ {
using System;
using Drawing.Processors; using Drawing.Processors;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image"/> type. /// Extension methods for the <see cref="Image"/> type.
@ -17,13 +16,13 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Draws the given image together with the current one by blending their pixels. /// Draws the given image together with the current one by blending their pixels.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="image">The image to blend with the currently processing image.</param> /// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="percent">The opacity of the image image to blend. Must be between 0 and 100.</param> /// <param name="percent">The opacity of the image image to blend. Must be between 0 and 100.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Blend<TColor>(this Image<TColor> source, Image<TColor> image, int percent = 50) public static Image<TPixel> Blend<TPixel>(this Image<TPixel> source, Image<TPixel> image, int percent = 50)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return DrawImage(source, image, percent, default(Size), default(Point)); return DrawImage(source, image, percent, default(Size), default(Point));
} }
@ -33,13 +32,13 @@ namespace ImageSharp
/// </summary> /// </summary>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="image">The image to blend with the currently processing image.</param> /// <param name="image">The image to blend with the currently processing image.</param>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="percent">The opacity of the image image to blend. Must be between 0 and 100.</param> /// <param name="percent">The opacity of the image image to blend. Must be between 0 and 100.</param>
/// <param name="size">The size to draw the blended image.</param> /// <param name="size">The size to draw the blended image.</param>
/// <param name="location">The location to draw the blended image.</param> /// <param name="location">The location to draw the blended image.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> DrawImage<TColor>(this Image<TColor> source, Image<TColor> image, int percent, Size size, Point location) public static Image<TPixel> DrawImage<TPixel>(this Image<TPixel> source, Image<TPixel> image, int percent, Size size, Point location)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
if (size == default(Size)) if (size == default(Size))
{ {
@ -51,7 +50,7 @@ namespace ImageSharp
location = Point.Empty; location = Point.Empty;
} }
source.ApplyProcessor(new DrawImageProcessor<TColor>(image, size, location, percent), source.Bounds); source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, size, location, percent), source.Bounds);
return source; return source;
} }
} }

63
src/ImageSharp.Drawing/DrawPath.cs

@ -5,43 +5,42 @@
namespace ImageSharp namespace ImageSharp
{ {
using System;
using Drawing; using Drawing;
using Drawing.Brushes; using Drawing.Brushes;
using Drawing.Pens; using Drawing.Pens;
using Drawing.Processors; using Drawing.Processors;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Draws the outline of the region with the provided pen. /// Draws the outline of the region with the provided pen.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, Drawable path, GraphicsOptions options) public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, IPen<TPixel> pen, Drawable path, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Apply(new DrawPathProcessor<TColor>(pen, path, options)); return source.Apply(new DrawPathProcessor<TPixel>(pen, path, options));
} }
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided pen. /// Draws the outline of the polygon with the provided pen.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, Drawable path) public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, IPen<TPixel> pen, Drawable path)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(pen, path, GraphicsOptions.Default); return source.Draw(pen, path, GraphicsOptions.Default);
} }
@ -49,63 +48,63 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness. /// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Drawable path, GraphicsOptions options) public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, float thickness, Drawable path, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(new Pen<TColor>(brush, thickness), path, options); return source.Draw(new Pen<TPixel>(brush, thickness), path, options);
} }
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness. /// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Drawable path) public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, float thickness, Drawable path)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(new Pen<TColor>(brush, thickness), path); return source.Draw(new Pen<TPixel>(brush, thickness), path);
} }
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness. /// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, Drawable path, GraphicsOptions options) public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, TPixel color, float thickness, Drawable path, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(new SolidBrush<TColor>(color), thickness, path, options); return source.Draw(new SolidBrush<TPixel>(color), thickness, path, options);
} }
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness. /// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, Drawable path) public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, TPixel color, float thickness, Drawable path)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(new SolidBrush<TColor>(color), thickness, path); return source.Draw(new SolidBrush<TPixel>(color), thickness, path);
} }
} }
} }

63
src/ImageSharp.Drawing/FillRegion.cs

@ -5,68 +5,67 @@
namespace ImageSharp namespace ImageSharp
{ {
using System;
using Drawing; using Drawing;
using Drawing.Brushes; using Drawing.Brushes;
using Drawing.Processors; using Drawing.Processors;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Flood fills the image with the specified brush. /// Flood fills the image with the specified brush.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The details how to fill the region of interest.</param> /// <param name="brush">The details how to fill the region of interest.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush) public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Apply(new FillProcessor<TColor>(brush)); return source.Apply(new FillProcessor<TPixel>(brush));
} }
/// <summary> /// <summary>
/// Flood fills the image with the specified color. /// Flood fills the image with the specified color.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color) public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, TPixel color)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Fill(new SolidBrush<TColor>(color)); return source.Fill(new SolidBrush<TPixel>(color));
} }
/// <summary> /// <summary>
/// Flood fills the image with in the region with the specified brush. /// Flood fills the image with in the region with the specified brush.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="region">The region.</param> /// <param name="region">The region.</param>
/// <param name="options">The graphics options.</param> /// <param name="options">The graphics options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, Region region, GraphicsOptions options) public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, Region region, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Apply(new FillRegionProcessor<TColor>(brush, region, options)); return source.Apply(new FillRegionProcessor<TPixel>(brush, region, options));
} }
/// <summary> /// <summary>
/// Flood fills the image with in the region with the specified brush. /// Flood fills the image with in the region with the specified brush.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="region">The region.</param> /// <param name="region">The region.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, Region region) public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, Region region)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Fill(brush, region, GraphicsOptions.Default); return source.Fill(brush, region, GraphicsOptions.Default);
} }
@ -74,30 +73,30 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Flood fills the image with in the region with the specified color. /// Flood fills the image with in the region with the specified color.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="region">The region.</param> /// <param name="region">The region.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, Region region, GraphicsOptions options) public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, TPixel color, Region region, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Fill(new SolidBrush<TColor>(color), region, options); return source.Fill(new SolidBrush<TPixel>(color), region, options);
} }
/// <summary> /// <summary>
/// Flood fills the image with in the region with the specified color. /// Flood fills the image with in the region with the specified color.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="region">The region.</param> /// <param name="region">The region.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, Region region) public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, TPixel color, Region region)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Fill(new SolidBrush<TColor>(color), region); return source.Fill(new SolidBrush<TPixel>(color), region);
} }
} }
} }

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

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

61
src/ImageSharp.Drawing/Paths/DrawBeziers.cs

@ -5,92 +5,91 @@
namespace ImageSharp namespace ImageSharp
{ {
using System;
using System.Numerics; using System.Numerics;
using Drawing; using Drawing;
using Drawing.Brushes; using Drawing.Brushes;
using Drawing.Pens; using Drawing.Pens;
using ImageSharp.PixelFormats;
using SixLabors.Shapes; using SixLabors.Shapes;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points, GraphicsOptions options) public static Image<TPixel> DrawBeziers<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(new Pen<TColor>(brush, thickness), new Path(new BezierLineSegment(points)), options); return source.Draw(new Pen<TPixel>(brush, thickness), new Path(new BezierLineSegment(points)), options);
} }
/// <summary> /// <summary>
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points) public static Image<TPixel> DrawBeziers<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, float thickness, Vector2[] points)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(new Pen<TColor>(brush, thickness), new Path(new BezierLineSegment(points))); return source.Draw(new Pen<TPixel>(brush, thickness), new Path(new BezierLineSegment(points)));
} }
/// <summary> /// <summary>
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points) public static Image<TPixel> DrawBeziers<TPixel>(this Image<TPixel> source, TPixel color, float thickness, Vector2[] points)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.DrawBeziers(new SolidBrush<TColor>(color), thickness, points); return source.DrawBeziers(new SolidBrush<TPixel>(color), thickness, points);
} }
/// <summary> /// <summary>
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points, GraphicsOptions options) public static Image<TPixel> DrawBeziers<TPixel>(this Image<TPixel> source, TPixel color, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.DrawBeziers(new SolidBrush<TColor>(color), thickness, points, options); return source.DrawBeziers(new SolidBrush<TPixel>(color), thickness, points, options);
} }
/// <summary> /// <summary>
/// Draws the provided Points as an open Bezier path with the supplied pen /// Draws the provided Points as an open Bezier path with the supplied pen
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points, GraphicsOptions options) public static Image<TPixel> DrawBeziers<TPixel>(this Image<TPixel> source, IPen<TPixel> pen, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(pen, new Path(new BezierLineSegment(points)), options); return source.Draw(pen, new Path(new BezierLineSegment(points)), options);
} }
@ -98,13 +97,13 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Draws the provided Points as an open Bezier path with the supplied pen /// Draws the provided Points as an open Bezier path with the supplied pen
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points) public static Image<TPixel> DrawBeziers<TPixel>(this Image<TPixel> source, IPen<TPixel> pen, Vector2[] points)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(pen, new Path(new BezierLineSegment(points))); return source.Draw(pen, new Path(new BezierLineSegment(points)));
} }

61
src/ImageSharp.Drawing/Paths/DrawLines.cs

@ -5,92 +5,91 @@
namespace ImageSharp namespace ImageSharp
{ {
using System;
using System.Numerics; using System.Numerics;
using Drawing; using Drawing;
using Drawing.Brushes; using Drawing.Brushes;
using Drawing.Pens; using Drawing.Pens;
using ImageSharp.PixelFormats;
using SixLabors.Shapes; using SixLabors.Shapes;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points, GraphicsOptions options) public static Image<TPixel> DrawLines<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(new Pen<TColor>(brush, thickness), new Path(new LinearLineSegment(points)), options); return source.Draw(new Pen<TPixel>(brush, thickness), new Path(new LinearLineSegment(points)), options);
} }
/// <summary> /// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points) public static Image<TPixel> DrawLines<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, float thickness, Vector2[] points)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(new Pen<TColor>(brush, thickness), new Path(new LinearLineSegment(points))); return source.Draw(new Pen<TPixel>(brush, thickness), new Path(new LinearLineSegment(points)));
} }
/// <summary> /// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points) public static Image<TPixel> DrawLines<TPixel>(this Image<TPixel> source, TPixel color, float thickness, Vector2[] points)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.DrawLines(new SolidBrush<TColor>(color), thickness, points); return source.DrawLines(new SolidBrush<TPixel>(color), thickness, points);
} }
/// <summary> /// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>> /// <returns>The <see cref="Image{TPixel}"/>.</returns>>
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points, GraphicsOptions options) public static Image<TPixel> DrawLines<TPixel>(this Image<TPixel> source, TPixel color, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.DrawLines(new SolidBrush<TColor>(color), thickness, points, options); return source.DrawLines(new SolidBrush<TPixel>(color), thickness, points, options);
} }
/// <summary> /// <summary>
/// Draws the provided Points as an open Linear path with the supplied pen /// Draws the provided Points as an open Linear path with the supplied pen
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points, GraphicsOptions options) public static Image<TPixel> DrawLines<TPixel>(this Image<TPixel> source, IPen<TPixel> pen, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(pen, new Path(new LinearLineSegment(points)), options); return source.Draw(pen, new Path(new LinearLineSegment(points)), options);
} }
@ -98,13 +97,13 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Draws the provided Points as an open Linear path with the supplied pen /// Draws the provided Points as an open Linear path with the supplied pen
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points) public static Image<TPixel> DrawLines<TPixel>(this Image<TPixel> source, IPen<TPixel> pen, Vector2[] points)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(pen, new Path(new LinearLineSegment(points))); return source.Draw(pen, new Path(new LinearLineSegment(points)));
} }

62
src/ImageSharp.Drawing/Paths/DrawPath.cs

@ -5,30 +5,28 @@
namespace ImageSharp namespace ImageSharp
{ {
using System;
using Drawing; using Drawing;
using Drawing.Brushes; using Drawing.Brushes;
using Drawing.Pens; using Drawing.Pens;
using ImageSharp.PixelFormats;
using SixLabors.Shapes; using SixLabors.Shapes;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided pen. /// Draws the outline of the polygon with the provided pen.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, IPath path, GraphicsOptions options) public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, IPen<TPixel> pen, IPath path, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(pen, new ShapePath(path), options); return source.Draw(pen, new ShapePath(path), options);
} }
@ -36,13 +34,13 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided pen. /// Draws the outline of the polygon with the provided pen.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, IPath path) public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, IPen<TPixel> pen, IPath path)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(pen, path, GraphicsOptions.Default); return source.Draw(pen, path, GraphicsOptions.Default);
} }
@ -50,63 +48,63 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness. /// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="path">The shape.</param> /// <param name="path">The shape.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IPath path, GraphicsOptions options) public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, float thickness, IPath path, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(new Pen<TColor>(brush, thickness), path, options); return source.Draw(new Pen<TPixel>(brush, thickness), path, options);
} }
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness. /// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IPath path) public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, float thickness, IPath path)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(new Pen<TColor>(brush, thickness), path); return source.Draw(new Pen<TPixel>(brush, thickness), path);
} }
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness. /// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, IPath path, GraphicsOptions options) public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, TPixel color, float thickness, IPath path, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(new SolidBrush<TColor>(color), thickness, path, options); return source.Draw(new SolidBrush<TPixel>(color), thickness, path, options);
} }
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness. /// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, IPath path) public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, TPixel color, float thickness, IPath path)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(new SolidBrush<TColor>(color), thickness, path); return source.Draw(new SolidBrush<TPixel>(color), thickness, path);
} }
} }
} }

61
src/ImageSharp.Drawing/Paths/DrawPolygon.cs

@ -5,91 +5,90 @@
namespace ImageSharp namespace ImageSharp
{ {
using System;
using System.Numerics; using System.Numerics;
using Drawing; using Drawing;
using Drawing.Brushes; using Drawing.Brushes;
using Drawing.Pens; using Drawing.Pens;
using ImageSharp.PixelFormats;
using SixLabors.Shapes; using SixLabors.Shapes;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points, GraphicsOptions options) public static Image<TPixel> DrawPolygon<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(new Pen<TColor>(brush, thickness), new Polygon(new LinearLineSegment(points)), options); return source.Draw(new Pen<TPixel>(brush, thickness), new Polygon(new LinearLineSegment(points)), options);
} }
/// <summary> /// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points) public static Image<TPixel> DrawPolygon<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, float thickness, Vector2[] points)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(new Pen<TColor>(brush, thickness), new Polygon(new LinearLineSegment(points))); return source.Draw(new Pen<TPixel>(brush, thickness), new Polygon(new LinearLineSegment(points)));
} }
/// <summary> /// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points) public static Image<TPixel> DrawPolygon<TPixel>(this Image<TPixel> source, TPixel color, float thickness, Vector2[] points)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.DrawPolygon(new SolidBrush<TColor>(color), thickness, points); return source.DrawPolygon(new SolidBrush<TPixel>(color), thickness, points);
} }
/// <summary> /// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points, GraphicsOptions options) public static Image<TPixel> DrawPolygon<TPixel>(this Image<TPixel> source, TPixel color, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.DrawPolygon(new SolidBrush<TColor>(color), thickness, points, options); return source.DrawPolygon(new SolidBrush<TPixel>(color), thickness, points, options);
} }
/// <summary> /// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided Pen. /// Draws the provided Points as a closed Linear Polygon with the provided Pen.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points) public static Image<TPixel> DrawPolygon<TPixel>(this Image<TPixel> source, IPen<TPixel> pen, Vector2[] points)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(pen, new Polygon(new LinearLineSegment(points)), GraphicsOptions.Default); return source.Draw(pen, new Polygon(new LinearLineSegment(points)), GraphicsOptions.Default);
} }
@ -97,14 +96,14 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided Pen. /// Draws the provided Points as a closed Linear Polygon with the provided Pen.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points, GraphicsOptions options) public static Image<TPixel> DrawPolygon<TPixel>(this Image<TPixel> source, IPen<TPixel> pen, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(pen, new Polygon(new LinearLineSegment(points)), options); return source.Draw(pen, new Polygon(new LinearLineSegment(points)), options);
} }

61
src/ImageSharp.Drawing/Paths/DrawRectangle.cs

@ -5,28 +5,27 @@
namespace ImageSharp namespace ImageSharp
{ {
using System;
using Drawing; using Drawing;
using Drawing.Brushes; using Drawing.Brushes;
using Drawing.Pens; using Drawing.Pens;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided pen. /// Draws the outline of the polygon with the provided pen.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="shape">The shape.</param> /// <param name="shape">The shape.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, Rectangle shape, GraphicsOptions options) public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, IPen<TPixel> pen, Rectangle shape, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(pen, new SixLabors.Shapes.Rectangle(shape.X, shape.Y, shape.Width, shape.Height), options); return source.Draw(pen, new SixLabors.Shapes.Rectangle(shape.X, shape.Y, shape.Width, shape.Height), options);
} }
@ -34,13 +33,13 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided pen. /// Draws the outline of the polygon with the provided pen.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="shape">The shape.</param> /// <param name="shape">The shape.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, Rectangle shape) public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, IPen<TPixel> pen, Rectangle shape)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(pen, shape, GraphicsOptions.Default); return source.Draw(pen, shape, GraphicsOptions.Default);
} }
@ -48,63 +47,63 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness. /// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param> /// <param name="shape">The shape.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Rectangle shape, GraphicsOptions options) public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, float thickness, Rectangle shape, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(new Pen<TColor>(brush, thickness), shape, options); return source.Draw(new Pen<TPixel>(brush, thickness), shape, options);
} }
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness. /// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param> /// <param name="shape">The shape.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Rectangle shape) public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, float thickness, Rectangle shape)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(new Pen<TColor>(brush, thickness), shape); return source.Draw(new Pen<TPixel>(brush, thickness), shape);
} }
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness. /// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param> /// <param name="shape">The shape.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, Rectangle shape, GraphicsOptions options) public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, TPixel color, float thickness, Rectangle shape, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(new SolidBrush<TColor>(color), thickness, shape, options); return source.Draw(new SolidBrush<TPixel>(color), thickness, shape, options);
} }
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness. /// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param> /// <param name="shape">The shape.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, Rectangle shape) public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, TPixel color, float thickness, Rectangle shape)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Draw(new SolidBrush<TColor>(color), thickness, shape); return source.Draw(new SolidBrush<TPixel>(color), thickness, shape);
} }
} }
} }

42
src/ImageSharp.Drawing/Paths/FillPaths.cs

@ -5,29 +5,27 @@
namespace ImageSharp namespace ImageSharp
{ {
using System;
using Drawing; using Drawing;
using Drawing.Brushes; using Drawing.Brushes;
using ImageSharp.PixelFormats;
using SixLabors.Shapes; using SixLabors.Shapes;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush.. /// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="path">The shape.</param> /// <param name="path">The shape.</param>
/// <param name="options">The graphics options.</param> /// <param name="options">The graphics options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, IPath path, GraphicsOptions options) public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, IPath path, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Fill(brush, new ShapeRegion(path), options); return source.Fill(brush, new ShapeRegion(path), options);
} }
@ -35,13 +33,13 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush. /// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, IPath path) public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, IPath path)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Fill(brush, new ShapeRegion(path), GraphicsOptions.Default); return source.Fill(brush, new ShapeRegion(path), GraphicsOptions.Default);
} }
@ -49,30 +47,30 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush.. /// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, IPath path, GraphicsOptions options) public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, TPixel color, IPath path, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Fill(new SolidBrush<TColor>(color), path, options); return source.Fill(new SolidBrush<TPixel>(color), path, options);
} }
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush.. /// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, IPath path) public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, TPixel color, IPath path)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Fill(new SolidBrush<TColor>(color), path); return source.Fill(new SolidBrush<TPixel>(color), path);
} }
} }
} }

40
src/ImageSharp.Drawing/Paths/FillPolygon.cs

@ -9,25 +9,25 @@ namespace ImageSharp
using System.Numerics; using System.Numerics;
using Drawing; using Drawing;
using Drawing.Brushes; using Drawing.Brushes;
using ImageSharp.PixelFormats;
using SixLabors.Shapes; using SixLabors.Shapes;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points /// Flood fills the image in the shape of a Linear polygon described by the points
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, Vector2[] points, GraphicsOptions options) public static Image<TPixel> FillPolygon<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Fill(brush, new Polygon(new LinearLineSegment(points)), options); return source.Fill(brush, new Polygon(new LinearLineSegment(points)), options);
} }
@ -35,13 +35,13 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points /// Flood fills the image in the shape of a Linear polygon described by the points
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, Vector2[] points) public static Image<TPixel> FillPolygon<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, Vector2[] points)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Fill(brush, new Polygon(new LinearLineSegment(points))); return source.Fill(brush, new Polygon(new LinearLineSegment(points)));
} }
@ -49,30 +49,30 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points /// Flood fills the image in the shape of a Linear polygon described by the points
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, TColor color, Vector2[] points, GraphicsOptions options) public static Image<TPixel> FillPolygon<TPixel>(this Image<TPixel> source, TPixel color, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Fill(new SolidBrush<TColor>(color), new Polygon(new LinearLineSegment(points)), options); return source.Fill(new SolidBrush<TPixel>(color), new Polygon(new LinearLineSegment(points)), options);
} }
/// <summary> /// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points /// Flood fills the image in the shape of a Linear polygon described by the points
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, TColor color, Vector2[] points) public static Image<TPixel> FillPolygon<TPixel>(this Image<TPixel> source, TPixel color, Vector2[] points)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Fill(new SolidBrush<TColor>(color), new Polygon(new LinearLineSegment(points))); return source.Fill(new SolidBrush<TPixel>(color), new Polygon(new LinearLineSegment(points)));
} }
} }
} }

41
src/ImageSharp.Drawing/Paths/FillRectangle.cs

@ -5,27 +5,26 @@
namespace ImageSharp namespace ImageSharp
{ {
using System;
using Drawing; using Drawing;
using Drawing.Brushes; using Drawing.Brushes;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush.. /// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="shape">The shape.</param> /// <param name="shape">The shape.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, Rectangle shape, GraphicsOptions options) public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, Rectangle shape, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Fill(brush, new SixLabors.Shapes.Rectangle(shape.X, shape.Y, shape.Width, shape.Height), options); return source.Fill(brush, new SixLabors.Shapes.Rectangle(shape.X, shape.Y, shape.Width, shape.Height), options);
} }
@ -33,13 +32,13 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush.. /// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="shape">The shape.</param> /// <param name="shape">The shape.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, Rectangle shape) public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, Rectangle shape)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Fill(brush, new SixLabors.Shapes.Rectangle(shape.X, shape.Y, shape.Width, shape.Height)); return source.Fill(brush, new SixLabors.Shapes.Rectangle(shape.X, shape.Y, shape.Width, shape.Height));
} }
@ -47,30 +46,30 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush.. /// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="shape">The shape.</param> /// <param name="shape">The shape.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, Rectangle shape, GraphicsOptions options) public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, TPixel color, Rectangle shape, GraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Fill(new SolidBrush<TColor>(color), shape, options); return source.Fill(new SolidBrush<TPixel>(color), shape, options);
} }
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush.. /// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="shape">The shape.</param> /// <param name="shape">The shape.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, Rectangle shape) public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, TPixel color, Rectangle shape)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.Fill(new SolidBrush<TColor>(color), shape); return source.Fill(new SolidBrush<TPixel>(color), shape);
} }
} }
} }

10
src/ImageSharp.Drawing/Pens/IPen.cs

@ -5,15 +5,15 @@
namespace ImageSharp.Drawing.Pens namespace ImageSharp.Drawing.Pens
{ {
using System; using ImageSharp.PixelFormats;
using Processors; using Processors;
/// <summary> /// <summary>
/// Interface representing a Pen /// Interface representing a Pen
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
public interface IPen<TColor> public interface IPen<TPixel>
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Creates the applicator for applying this pen to an Image /// Creates the applicator for applying this pen to an Image
@ -26,6 +26,6 @@ namespace ImageSharp.Drawing.Pens
/// <remarks> /// <remarks>
/// The <paramref name="region" /> when being applied to things like shapes would usually be the bounding box of the shape not necessarily the shape of the whole image. /// The <paramref name="region" /> when being applied to things like shapes would usually be the bounding box of the shape not necessarily the shape of the whole image.
/// </remarks> /// </remarks>
PenApplicator<TColor> CreateApplicator(PixelAccessor<TColor> pixelSource, RectangleF region); PenApplicator<TPixel> CreateApplicator(PixelAccessor<TPixel> pixelSource, RectangleF region);
} }
} }

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

@ -5,17 +5,19 @@
namespace ImageSharp.Drawing.Pens namespace ImageSharp.Drawing.Pens
{ {
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Represents a <see cref="Pen{TColor}"/> in the <see cref="Color"/> color space. /// Represents a <see cref="Pen{TPixel}"/> in the <see cref="Rgba32"/> color space.
/// </summary> /// </summary>
public class Pen : Pen<Color> public class Pen : Pen<Rgba32>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Pen"/> class. /// Initializes a new instance of the <see cref="Pen"/> class.
/// </summary> /// </summary>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
public Pen(Color color, float width) public Pen(Rgba32 color, float width)
: base(color, width) : base(color, width)
{ {
} }
@ -25,7 +27,7 @@ namespace ImageSharp.Drawing.Pens
/// </summary> /// </summary>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
public Pen(IBrush<Color> brush, float width) public Pen(IBrush<Rgba32> brush, float width)
: base(brush, width) : base(brush, width)
{ {
} }
@ -36,7 +38,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <param name="pattern">The pattern.</param> /// <param name="pattern">The pattern.</param>
public Pen(IBrush<Color> brush, float width, float[] pattern) public Pen(IBrush<Rgba32> brush, float width, float[] pattern)
: base(brush, width, pattern) : base(brush, width, pattern)
{ {
} }
@ -45,7 +47,7 @@ namespace ImageSharp.Drawing.Pens
/// Initializes a new instance of the <see cref="Pen"/> class. /// Initializes a new instance of the <see cref="Pen"/> class.
/// </summary> /// </summary>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
internal Pen(Pen<Color> pen) internal Pen(Pen<Rgba32> pen)
: base(pen) : base(pen)
{ {
} }

22
src/ImageSharp.Drawing/Pens/Pens.cs

@ -5,6 +5,8 @@
namespace ImageSharp.Drawing.Pens namespace ImageSharp.Drawing.Pens
{ {
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Common Pen styles /// Common Pen styles
/// </summary> /// </summary>
@ -16,7 +18,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <returns>The Pen</returns> /// <returns>The Pen</returns>
public static Pen Solid(Color color, float width) => new Pen(color, width); public static Pen Solid(Rgba32 color, float width) => new Pen(color, width);
/// <summary> /// <summary>
/// Create a solid pen with out any drawing patterns /// Create a solid pen with out any drawing patterns
@ -24,7 +26,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <returns>The Pen</returns> /// <returns>The Pen</returns>
public static Pen Solid(IBrush<Color> brush, float width) => new Pen(brush, width); public static Pen Solid(IBrush<Rgba32> brush, float width) => new Pen(brush, width);
/// <summary> /// <summary>
/// Create a pen with a 'Dash' drawing patterns /// Create a pen with a 'Dash' drawing patterns
@ -32,7 +34,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <returns>The Pen</returns> /// <returns>The Pen</returns>
public static Pen Dash(Color color, float width) => new Pen(Pens<Color>.Dash(color, width)); public static Pen Dash(Rgba32 color, float width) => new Pen(Pens<Rgba32>.Dash(color, width));
/// <summary> /// <summary>
/// Create a pen with a 'Dash' drawing patterns /// Create a pen with a 'Dash' drawing patterns
@ -40,7 +42,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <returns>The Pen</returns> /// <returns>The Pen</returns>
public static Pen Dash(IBrush<Color> brush, float width) => new Pen(Pens<Color>.Dash(brush, width)); public static Pen Dash(IBrush<Rgba32> brush, float width) => new Pen(Pens<Rgba32>.Dash(brush, width));
/// <summary> /// <summary>
/// Create a pen with a 'Dot' drawing patterns /// Create a pen with a 'Dot' drawing patterns
@ -48,7 +50,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <returns>The Pen</returns> /// <returns>The Pen</returns>
public static Pen Dot(Color color, float width) => new Pen(Pens<Color>.Dot(color, width)); public static Pen Dot(Rgba32 color, float width) => new Pen(Pens<Rgba32>.Dot(color, width));
/// <summary> /// <summary>
/// Create a pen with a 'Dot' drawing patterns /// Create a pen with a 'Dot' drawing patterns
@ -56,7 +58,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <returns>The Pen</returns> /// <returns>The Pen</returns>
public static Pen Dot(IBrush<Color> brush, float width) => new Pen(Pens<Color>.Dot(brush, width)); public static Pen Dot(IBrush<Rgba32> brush, float width) => new Pen(Pens<Rgba32>.Dot(brush, width));
/// <summary> /// <summary>
/// Create a pen with a 'Dash Dot' drawing patterns /// Create a pen with a 'Dash Dot' drawing patterns
@ -64,7 +66,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <returns>The Pen</returns> /// <returns>The Pen</returns>
public static Pen DashDot(Color color, float width) => new Pen(Pens<Color>.DashDot(color, width)); public static Pen DashDot(Rgba32 color, float width) => new Pen(Pens<Rgba32>.DashDot(color, width));
/// <summary> /// <summary>
/// Create a pen with a 'Dash Dot' drawing patterns /// Create a pen with a 'Dash Dot' drawing patterns
@ -72,7 +74,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <returns>The Pen</returns> /// <returns>The Pen</returns>
public static Pen DashDot(IBrush<Color> brush, float width) => new Pen(Pens<Color>.DashDot(brush, width)); public static Pen DashDot(IBrush<Rgba32> brush, float width) => new Pen(Pens<Rgba32>.DashDot(brush, width));
/// <summary> /// <summary>
/// Create a pen with a 'Dash Dot Dot' drawing patterns /// Create a pen with a 'Dash Dot Dot' drawing patterns
@ -80,7 +82,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <returns>The Pen</returns> /// <returns>The Pen</returns>
public static Pen DashDotDot(Color color, float width) => new Pen(Pens<Color>.DashDotDot(color, width)); public static Pen DashDotDot(Rgba32 color, float width) => new Pen(Pens<Rgba32>.DashDotDot(color, width));
/// <summary> /// <summary>
/// Create a pen with a 'Dash Dot Dot' drawing patterns /// Create a pen with a 'Dash Dot Dot' drawing patterns
@ -88,6 +90,6 @@ namespace ImageSharp.Drawing.Pens
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <returns>The Pen</returns> /// <returns>The Pen</returns>
public static Pen DashDotDot(IBrush<Color> brush, float width) => new Pen(Pens<Color>.DashDotDot(brush, width)); public static Pen DashDotDot(IBrush<Rgba32> brush, float width) => new Pen(Pens<Rgba32>.DashDotDot(brush, width));
} }
} }

50
src/ImageSharp.Drawing/Pens/Pens{TColor}.cs → src/ImageSharp.Drawing/Pens/Pens{TPixel}.cs

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

60
src/ImageSharp.Drawing/Pens/Pen{TColor}.cs → src/ImageSharp.Drawing/Pens/Pen{TPixel}.cs

@ -1,20 +1,20 @@
// <copyright file="Pen{TColor}.cs" company="James Jackson-South"> // <copyright file="Pen{TPixel}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
namespace ImageSharp.Drawing.Pens namespace ImageSharp.Drawing.Pens
{ {
using System;
using System.Numerics; using System.Numerics;
using ImageSharp.Drawing.Brushes; using ImageSharp.Drawing.Brushes;
using ImageSharp.PixelFormats;
using Processors; using Processors;
/// <summary> /// <summary>
/// Provides a pen that can apply a pattern to a line with a set brush and thickness /// Provides a pen that can apply a pattern to a line with a set brush and thickness
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <remarks> /// <remarks>
/// The pattern will be in to the form of new float[]{ 1f, 2f, 0.5f} this will be /// The pattern will be in to the form of new float[]{ 1f, 2f, 0.5f} this will be
/// converted into a pattern that is 3.5 times longer that the width with 3 sections /// converted into a pattern that is 3.5 times longer that the width with 3 sections
@ -23,30 +23,30 @@ namespace ImageSharp.Drawing.Pens
/// section 3 will be width/2 long and will be filled /// section 3 will be width/2 long and will be filled
/// the the pattern will imidiatly repeat without gap. /// the the pattern will imidiatly repeat without gap.
/// </remarks> /// </remarks>
public class Pen<TColor> : IPen<TColor> public class Pen<TPixel> : IPen<TPixel>
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
private static readonly float[] EmptyPattern = new float[0]; private static readonly float[] EmptyPattern = new float[0];
private readonly float[] pattern; private readonly float[] pattern;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ImageSharp.Drawing.Pens.Pen{TColor}"/> class. /// Initializes a new instance of the <see cref="ImageSharp.Drawing.Pens.Pen{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <param name="pattern">The pattern.</param> /// <param name="pattern">The pattern.</param>
public Pen(TColor color, float width, float[] pattern) public Pen(TPixel color, float width, float[] pattern)
: this(new SolidBrush<TColor>(color), width, pattern) : this(new SolidBrush<TPixel>(color), width, pattern)
{ {
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ImageSharp.Drawing.Pens.Pen{TColor}"/> class. /// Initializes a new instance of the <see cref="ImageSharp.Drawing.Pens.Pen{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <param name="pattern">The pattern.</param> /// <param name="pattern">The pattern.</param>
public Pen(IBrush<TColor> brush, float width, float[] pattern) public Pen(IBrush<TPixel> brush, float width, float[] pattern)
{ {
this.Brush = brush; this.Brush = brush;
this.Width = width; this.Width = width;
@ -54,30 +54,30 @@ namespace ImageSharp.Drawing.Pens
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ImageSharp.Drawing.Pens.Pen{TColor}"/> class. /// Initializes a new instance of the <see cref="ImageSharp.Drawing.Pens.Pen{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
public Pen(TColor color, float width) public Pen(TPixel color, float width)
: this(new SolidBrush<TColor>(color), width) : this(new SolidBrush<TPixel>(color), width)
{ {
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ImageSharp.Drawing.Pens.Pen{TColor}"/> class. /// Initializes a new instance of the <see cref="ImageSharp.Drawing.Pens.Pen{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
public Pen(IBrush<TColor> brush, float width) public Pen(IBrush<TPixel> brush, float width)
: this(brush, width, EmptyPattern) : this(brush, width, EmptyPattern)
{ {
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ImageSharp.Drawing.Pens.Pen{TColor}"/> class. /// Initializes a new instance of the <see cref="ImageSharp.Drawing.Pens.Pen{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
internal Pen(Pen<TColor> pen) internal Pen(Pen<TPixel> pen)
: this(pen.Brush, pen.Width, pen.pattern) : this(pen.Brush, pen.Width, pen.pattern)
{ {
} }
@ -88,7 +88,7 @@ namespace ImageSharp.Drawing.Pens
/// <value> /// <value>
/// The brush. /// The brush.
/// </value> /// </value>
public IBrush<TColor> Brush { get; } public IBrush<TPixel> Brush { get; }
/// <summary> /// <summary>
/// Gets the width. /// Gets the width.
@ -110,7 +110,7 @@ namespace ImageSharp.Drawing.Pens
/// The <paramref name="region" /> when being applied to things like shapes would ussually be the /// The <paramref name="region" /> when being applied to things like shapes would ussually be the
/// bounding box of the shape not necorserrally the shape of the whole image /// bounding box of the shape not necorserrally the shape of the whole image
/// </remarks> /// </remarks>
public PenApplicator<TColor> CreateApplicator(PixelAccessor<TColor> sourcePixels, RectangleF region) public PenApplicator<TPixel> CreateApplicator(PixelAccessor<TPixel> sourcePixels, RectangleF region)
{ {
if (this.pattern == null || this.pattern.Length < 2) if (this.pattern == null || this.pattern.Length < 2)
{ {
@ -122,12 +122,12 @@ namespace ImageSharp.Drawing.Pens
return new PatternPenApplicator(sourcePixels, this.Brush, region, this.Width, this.pattern); return new PatternPenApplicator(sourcePixels, this.Brush, region, this.Width, this.pattern);
} }
private class SolidPenApplicator : PenApplicator<TColor> private class SolidPenApplicator : PenApplicator<TPixel>
{ {
private readonly BrushApplicator<TColor> brush; private readonly BrushApplicator<TPixel> brush;
private readonly float halfWidth; private readonly float halfWidth;
public SolidPenApplicator(PixelAccessor<TColor> sourcePixels, IBrush<TColor> brush, RectangleF region, float width) public SolidPenApplicator(PixelAccessor<TPixel> sourcePixels, IBrush<TPixel> brush, RectangleF region, float width)
{ {
this.brush = brush.CreateApplicator(sourcePixels, region); this.brush = brush.CreateApplicator(sourcePixels, region);
this.halfWidth = width / 2; this.halfWidth = width / 2;
@ -144,9 +144,9 @@ namespace ImageSharp.Drawing.Pens
this.brush.Dispose(); this.brush.Dispose();
} }
public override ColoredPointInfo<TColor> GetColor(int x, int y, PointInfo info) public override ColoredPointInfo<TPixel> GetColor(int x, int y, PointInfo info)
{ {
ColoredPointInfo<TColor> result = default(ColoredPointInfo<TColor>); ColoredPointInfo<TPixel> result = default(ColoredPointInfo<TPixel>);
result.Color = this.brush[x, y]; result.Color = this.brush[x, y];
if (info.DistanceFromPath < this.halfWidth) if (info.DistanceFromPath < this.halfWidth)
@ -163,14 +163,14 @@ namespace ImageSharp.Drawing.Pens
} }
} }
private class PatternPenApplicator : PenApplicator<TColor> private class PatternPenApplicator : PenApplicator<TPixel>
{ {
private readonly BrushApplicator<TColor> brush; private readonly BrushApplicator<TPixel> brush;
private readonly float halfWidth; private readonly float halfWidth;
private readonly float[] pattern; private readonly float[] pattern;
private readonly float totalLength; private readonly float totalLength;
public PatternPenApplicator(PixelAccessor<TColor> sourcePixels, IBrush<TColor> brush, RectangleF region, float width, float[] pattern) public PatternPenApplicator(PixelAccessor<TPixel> sourcePixels, IBrush<TPixel> brush, RectangleF region, float width, float[] pattern)
{ {
this.brush = brush.CreateApplicator(sourcePixels, region); this.brush = brush.CreateApplicator(sourcePixels, region);
this.halfWidth = width / 2; this.halfWidth = width / 2;
@ -197,16 +197,16 @@ namespace ImageSharp.Drawing.Pens
this.brush.Dispose(); this.brush.Dispose();
} }
public override ColoredPointInfo<TColor> GetColor(int x, int y, PointInfo info) public override ColoredPointInfo<TPixel> GetColor(int x, int y, PointInfo info)
{ {
ColoredPointInfo<TColor> infoResult = default(ColoredPointInfo<TColor>); ColoredPointInfo<TPixel> infoResult = default(ColoredPointInfo<TPixel>);
infoResult.DistanceFromElement = float.MaxValue; // is really outside the element infoResult.DistanceFromElement = float.MaxValue; // is really outside the element
float length = info.DistanceAlongPath % this.totalLength; float length = info.DistanceAlongPath % this.totalLength;
// we can treat the DistanceAlongPath and DistanceFromPath as x,y coords for the pattern // we can treat the DistanceAlongPath and DistanceFromPath as x,y coords for the pattern
// we need to calcualte the distance from the outside edge of the pattern // we need to calcualte the distance from the outside edge of the pattern
// and set them on the ColoredPointInfo<TColor> along with the color. // and set them on the ColoredPointInfo<TPixel> along with the color.
infoResult.Color = this.brush[x, y]; infoResult.Color = this.brush[x, y];
float distanceWAway = 0; float distanceWAway = 0;

10
src/ImageSharp.Drawing/Pens/Processors/ColoredPointInfo.cs

@ -5,19 +5,19 @@
namespace ImageSharp.Drawing.Processors namespace ImageSharp.Drawing.Processors
{ {
using System; using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Returns details about how far away from the inside of a shape and the color the pixel could be. /// Returns details about how far away from the inside of a shape and the color the pixel could be.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
public struct ColoredPointInfo<TColor> public struct ColoredPointInfo<TPixel>
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// The color /// The color
/// </summary> /// </summary>
public TColor Color; public TPixel Color;
/// <summary> /// <summary>
/// The distance from element /// The distance from element

12
src/ImageSharp.Drawing/Pens/Processors/PenApplicator.cs

@ -6,14 +6,14 @@
namespace ImageSharp.Drawing.Processors namespace ImageSharp.Drawing.Processors
{ {
using System; using System;
using System.Numerics; using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// primitive that converts a <see cref="PointInfo"/> into a color and a distance away from the drawable part of the path. /// primitive that converts a <see cref="PointInfo"/> into a color and a distance away from the drawable part of the path.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
public abstract class PenApplicator<TColor> : IDisposable public abstract class PenApplicator<TPixel> : IDisposable
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Gets the required region. /// Gets the required region.
@ -27,7 +27,7 @@ namespace ImageSharp.Drawing.Processors
public abstract void Dispose(); public abstract void Dispose();
/// <summary> /// <summary>
/// Gets a <see cref="ColoredPointInfo{TColor}" /> from a point represented by a <see cref="PointInfo" />. /// Gets a <see cref="ColoredPointInfo{TPixel}" /> from a point represented by a <see cref="PointInfo" />.
/// </summary> /// </summary>
/// <param name="x">The x.</param> /// <param name="x">The x.</param>
/// <param name="y">The y.</param> /// <param name="y">The y.</param>
@ -35,6 +35,6 @@ namespace ImageSharp.Drawing.Processors
/// <returns> /// <returns>
/// Returns the color details and distance from a solid bit of the line. /// Returns the color details and distance from a solid bit of the line.
/// </returns> /// </returns>
public abstract ColoredPointInfo<TColor> GetColor(int x, int y, PointInfo info); public abstract ColoredPointInfo<TPixel> GetColor(int x, int y, PointInfo info);
} }
} }

22
src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs

@ -8,24 +8,24 @@ namespace ImageSharp.Drawing.Processors
using System; using System;
using System.Numerics; using System.Numerics;
using System.Threading.Tasks; using System.Threading.Tasks;
using ImageSharp.PixelFormats;
using ImageSharp.Processing; using ImageSharp.Processing;
/// <summary> /// <summary>
/// Combines two images together by blending the pixels. /// Combines two images together by blending the pixels.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
internal class DrawImageProcessor<TColor> : ImageProcessor<TColor> internal class DrawImageProcessor<TPixel> : ImageProcessor<TPixel>
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="DrawImageProcessor{TColor}"/> class. /// Initializes a new instance of the <see cref="DrawImageProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="image">The image to blend with the currently processing image.</param> /// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="size">The size to draw the blended image.</param> /// <param name="size">The size to draw the blended image.</param>
/// <param name="location">The location to draw the blended image.</param> /// <param name="location">The location to draw the blended image.</param>
/// <param name="alpha">The opacity of the image to blend. Between 0 and 100.</param> /// <param name="alpha">The opacity of the image to blend. Between 0 and 100.</param>
public DrawImageProcessor(Image<TColor> image, Size size, Point location, int alpha = 100) public DrawImageProcessor(Image<TPixel> image, Size size, Point location, int alpha = 100)
{ {
Guard.MustBeBetweenOrEqualTo(alpha, 0, 100, nameof(alpha)); Guard.MustBeBetweenOrEqualTo(alpha, 0, 100, nameof(alpha));
this.Image = image; this.Image = image;
@ -37,7 +37,7 @@ namespace ImageSharp.Drawing.Processors
/// <summary> /// <summary>
/// Gets the image to blend. /// Gets the image to blend.
/// </summary> /// </summary>
public Image<TColor> Image { get; private set; } public Image<TPixel> Image { get; private set; }
/// <summary> /// <summary>
/// Gets the alpha percentage value. /// Gets the alpha percentage value.
@ -55,7 +55,7 @@ namespace ImageSharp.Drawing.Processors
public Point Location { get; } public Point Location { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle) protected override void OnApply(ImageBase<TPixel> source, Rectangle sourceRectangle)
{ {
if (this.Image.Bounds.Size != this.Size) if (this.Image.Bounds.Size != this.Size)
{ {
@ -72,8 +72,8 @@ namespace ImageSharp.Drawing.Processors
float alpha = this.Alpha / 100F; float alpha = this.Alpha / 100F;
using (PixelAccessor<TColor> toBlendPixels = this.Image.Lock()) using (PixelAccessor<TPixel> toBlendPixels = this.Image.Lock())
using (PixelAccessor<TColor> sourcePixels = source.Lock()) using (PixelAccessor<TPixel> sourcePixels = source.Lock())
{ {
Parallel.For( Parallel.For(
minY, minY,
@ -89,7 +89,7 @@ namespace ImageSharp.Drawing.Processors
// Lerping colors is dependent on the alpha of the blended color // Lerping colors is dependent on the alpha of the blended color
backgroundVector = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, alpha); backgroundVector = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, alpha);
TColor packed = default(TColor); TPixel packed = default(TPixel);
packed.PackFromVector4(backgroundVector); packed.PackFromVector4(backgroundVector);
sourcePixels[x, y] = packed; sourcePixels[x, y] = packed;
} }

26
src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs

@ -8,28 +8,28 @@ namespace ImageSharp.Drawing.Processors
using System; using System;
using System.Numerics; using System.Numerics;
using System.Threading.Tasks; using System.Threading.Tasks;
using ImageSharp.PixelFormats;
using ImageSharp.Processing; using ImageSharp.Processing;
using Pens; using Pens;
/// <summary> /// <summary>
/// Draws a path using the processor pipeline /// Draws a path using the processor pipeline
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <seealso cref="ImageSharp.Processing.ImageProcessor{TColor}" /> /// <seealso cref="ImageSharp.Processing.ImageProcessor{TPixel}" />
internal class DrawPathProcessor<TColor> : ImageProcessor<TColor> internal class DrawPathProcessor<TPixel> : ImageProcessor<TPixel>
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
private const float AntialiasFactor = 1f; private const float AntialiasFactor = 1f;
private const int PaddingFactor = 1; // needs to been the same or greater than AntialiasFactor private const int PaddingFactor = 1; // needs to been the same or greater than AntialiasFactor
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="DrawPathProcessor{TColor}" /> class. /// Initializes a new instance of the <see cref="DrawPathProcessor{TPixel}" /> class.
/// </summary> /// </summary>
/// <param name="pen">The details how to draw the outline/path.</param> /// <param name="pen">The details how to draw the outline/path.</param>
/// <param name="drawable">The details of the paths and outlines to draw.</param> /// <param name="drawable">The details of the paths and outlines to draw.</param>
/// <param name="options">The drawing configuration options.</param> /// <param name="options">The drawing configuration options.</param>
public DrawPathProcessor(IPen<TColor> pen, Drawable drawable, GraphicsOptions options) public DrawPathProcessor(IPen<TPixel> pen, Drawable drawable, GraphicsOptions options)
{ {
this.Path = drawable; this.Path = drawable;
this.Pen = pen; this.Pen = pen;
@ -44,7 +44,7 @@ namespace ImageSharp.Drawing.Processors
/// <summary> /// <summary>
/// Gets the pen. /// Gets the pen.
/// </summary> /// </summary>
public IPen<TColor> Pen { get; } public IPen<TPixel> Pen { get; }
/// <summary> /// <summary>
/// Gets the path. /// Gets the path.
@ -52,10 +52,10 @@ namespace ImageSharp.Drawing.Processors
public Drawable Path { get; } public Drawable Path { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle) protected override void OnApply(ImageBase<TPixel> source, Rectangle sourceRectangle)
{ {
using (PixelAccessor<TColor> sourcePixels = source.Lock()) using (PixelAccessor<TPixel> sourcePixels = source.Lock())
using (PenApplicator<TColor> applicator = this.Pen.CreateApplicator(sourcePixels, this.Path.Bounds)) using (PenApplicator<TPixel> applicator = this.Pen.CreateApplicator(sourcePixels, this.Path.Bounds))
{ {
Rectangle rect = RectangleF.Ceiling(applicator.RequiredRegion); Rectangle rect = RectangleF.Ceiling(applicator.RequiredRegion);
@ -100,7 +100,7 @@ namespace ImageSharp.Drawing.Processors
int offsetX = x - startX; int offsetX = x - startX;
PointInfo info = this.Path.GetPointInfo(offsetX, offsetY); PointInfo info = this.Path.GetPointInfo(offsetX, offsetY);
ColoredPointInfo<TColor> color = applicator.GetColor(offsetX, offsetY, info); ColoredPointInfo<TPixel> color = applicator.GetColor(offsetX, offsetY, info);
float opacity = this.Opacity(color.DistanceFromElement); float opacity = this.Opacity(color.DistanceFromElement);
@ -111,7 +111,7 @@ namespace ImageSharp.Drawing.Processors
Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity); Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity);
TColor packed = default(TColor); TPixel packed = default(TPixel);
packed.PackFromVector4(finalColor); packed.PackFromVector4(finalColor);
sourcePixels[offsetX, offsetY] = packed; sourcePixels[offsetX, offsetY] = packed;
} }

25
src/ImageSharp.Drawing/Processors/FillProcessor.cs

@ -10,31 +10,32 @@ namespace ImageSharp.Drawing.Processors
using System.Threading.Tasks; using System.Threading.Tasks;
using Drawing; using Drawing;
using ImageSharp.PixelFormats;
using ImageSharp.Processing; using ImageSharp.Processing;
/// <summary> /// <summary>
/// Using the bursh as a source of pixels colors blends the brush color with source. /// Using the bursh as a source of pixels colors blends the brush color with source.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
internal class FillProcessor<TColor> : ImageProcessor<TColor> internal class FillProcessor<TPixel> : ImageProcessor<TPixel>
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// The brush. /// The brush.
/// </summary> /// </summary>
private readonly IBrush<TColor> brush; private readonly IBrush<TPixel> brush;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="FillProcessor{TColor}"/> class. /// Initializes a new instance of the <see cref="FillProcessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="brush">The brush to source pixel colors from.</param> /// <param name="brush">The brush to source pixel colors from.</param>
public FillProcessor(IBrush<TColor> brush) public FillProcessor(IBrush<TPixel> brush)
{ {
this.brush = brush; this.brush = brush;
} }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle) protected override void OnApply(ImageBase<TPixel> source, Rectangle sourceRectangle)
{ {
int startX = sourceRectangle.X; int startX = sourceRectangle.X;
int endX = sourceRectangle.Right; int endX = sourceRectangle.Right;
@ -59,10 +60,10 @@ namespace ImageSharp.Drawing.Processors
} }
// we could possibly do some optermising by having knowledge about the individual brushes operate // we could possibly do some optermising by having knowledge about the individual brushes operate
// for example If brush is SolidBrush<TColor> then we could just get the color upfront // for example If brush is SolidBrush<TPixel> then we could just get the color upfront
// and skip using the IBrushApplicator<TColor>?. // and skip using the IBrushApplicator<TPixel>?.
using (PixelAccessor<TColor> sourcePixels = source.Lock()) using (PixelAccessor<TPixel> sourcePixels = source.Lock())
using (BrushApplicator<TColor> applicator = this.brush.CreateApplicator(sourcePixels, sourceRectangle)) using (BrushApplicator<TPixel> applicator = this.brush.CreateApplicator(sourcePixels, sourceRectangle))
{ {
Parallel.For( Parallel.For(
minY, minY,
@ -80,7 +81,7 @@ namespace ImageSharp.Drawing.Processors
Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, 1); Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, 1);
TColor packed = default(TColor); TPixel packed = default(TPixel);
packed.PackFromVector4(finalColor); packed.PackFromVector4(finalColor);
sourcePixels[offsetX, offsetY] = packed; sourcePixels[offsetX, offsetY] = packed;
} }

23
src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs

@ -7,29 +7,28 @@ namespace ImageSharp.Drawing.Processors
{ {
using System; using System;
using System.Buffers; using System.Buffers;
using System.Numerics;
using System.Threading.Tasks;
using Drawing; using Drawing;
using ImageSharp.PixelFormats;
using ImageSharp.Processing; using ImageSharp.Processing;
/// <summary> /// <summary>
/// Usinf a brsuh and a shape fills shape with contents of brush the /// Usinf a brsuh and a shape fills shape with contents of brush the
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <seealso cref="ImageSharp.Processing.ImageProcessor{TColor}" /> /// <seealso cref="ImageSharp.Processing.ImageProcessor{TPixel}" />
internal class FillRegionProcessor<TColor> : ImageProcessor<TColor> internal class FillRegionProcessor<TPixel> : ImageProcessor<TPixel>
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
private const float AntialiasFactor = 1f; private const float AntialiasFactor = 1f;
private const int DrawPadding = 1; private const int DrawPadding = 1;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="FillRegionProcessor{TColor}" /> class. /// Initializes a new instance of the <see cref="FillRegionProcessor{TPixel}" /> class.
/// </summary> /// </summary>
/// <param name="brush">The details how to fill the region of interest.</param> /// <param name="brush">The details how to fill the region of interest.</param>
/// <param name="region">The region of interest to be filled.</param> /// <param name="region">The region of interest to be filled.</param>
/// <param name="options">The configuration options.</param> /// <param name="options">The configuration options.</param>
public FillRegionProcessor(IBrush<TColor> brush, Region region, GraphicsOptions options) public FillRegionProcessor(IBrush<TPixel> brush, Region region, GraphicsOptions options)
{ {
this.Region = region; this.Region = region;
this.Brush = brush; this.Brush = brush;
@ -39,7 +38,7 @@ namespace ImageSharp.Drawing.Processors
/// <summary> /// <summary>
/// Gets the brush. /// Gets the brush.
/// </summary> /// </summary>
public IBrush<TColor> Brush { get; } public IBrush<TPixel> Brush { get; }
/// <summary> /// <summary>
/// Gets the region that this processor applies to. /// Gets the region that this processor applies to.
@ -55,7 +54,7 @@ namespace ImageSharp.Drawing.Processors
public GraphicsOptions Options { get; } public GraphicsOptions Options { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle) protected override void OnApply(ImageBase<TPixel> source, Rectangle sourceRectangle)
{ {
Region region = this.Region; Region region = this.Region;
Rectangle rect = region.Bounds; Rectangle rect = region.Bounds;
@ -88,8 +87,8 @@ namespace ImageSharp.Drawing.Processors
} }
} }
using (PixelAccessor<TColor> sourcePixels = source.Lock()) using (PixelAccessor<TPixel> sourcePixels = source.Lock())
using (BrushApplicator<TColor> applicator = this.Brush.CreateApplicator(sourcePixels, rect)) using (BrushApplicator<TPixel> applicator = this.Brush.CreateApplicator(sourcePixels, rect))
{ {
float[] buffer = arrayPool.Rent(maxIntersections); float[] buffer = arrayPool.Rent(maxIntersections);
int scanlineWidth = maxX - minX; int scanlineWidth = maxX - minX;

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

@ -10,11 +10,11 @@ namespace ImageSharp
using Drawing; using Drawing;
using Drawing.Brushes; using Drawing.Brushes;
using Drawing.Pens; using Drawing.Pens;
using ImageSharp.PixelFormats;
using SixLabors.Fonts; using SixLabors.Fonts;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
@ -23,17 +23,17 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Draws the text onto the the image filled via the brush. /// Draws the text onto the the image filled via the brush.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="text">The text.</param> /// <param name="text">The text.</param>
/// <param name="font">The font.</param> /// <param name="font">The font.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="location">The location.</param> /// <param name="location">The location.</param>
/// <returns> /// <returns>
/// The <see cref="Image{TColor}" />. /// The <see cref="Image{TPixel}" />.
/// </returns> /// </returns>
public static Image<TColor> DrawText<TColor>(this Image<TColor> source, string text, Font font, TColor color, Vector2 location) public static Image<TPixel> DrawText<TPixel>(this Image<TPixel> source, string text, Font font, TPixel color, Vector2 location)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.DrawText(text, font, color, location, TextGraphicsOptions.Default); return source.DrawText(text, font, color, location, TextGraphicsOptions.Default);
} }
@ -41,7 +41,7 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Draws the text onto the the image filled via the brush. /// Draws the text onto the the image filled via the brush.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="text">The text.</param> /// <param name="text">The text.</param>
/// <param name="font">The font.</param> /// <param name="font">The font.</param>
@ -49,28 +49,28 @@ namespace ImageSharp
/// <param name="location">The location.</param> /// <param name="location">The location.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns> /// <returns>
/// The <see cref="Image{TColor}" />. /// The <see cref="Image{TPixel}" />.
/// </returns> /// </returns>
public static Image<TColor> DrawText<TColor>(this Image<TColor> source, string text, Font font, TColor color, Vector2 location, TextGraphicsOptions options) public static Image<TPixel> DrawText<TPixel>(this Image<TPixel> source, string text, Font font, TPixel color, Vector2 location, TextGraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.DrawText(text, font, Brushes<TColor>.Solid(color), null, location, options); return source.DrawText(text, font, Brushes<TPixel>.Solid(color), null, location, options);
} }
/// <summary> /// <summary>
/// Draws the text onto the the image filled via the brush. /// Draws the text onto the the image filled via the brush.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="text">The text.</param> /// <param name="text">The text.</param>
/// <param name="font">The font.</param> /// <param name="font">The font.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="location">The location.</param> /// <param name="location">The location.</param>
/// <returns> /// <returns>
/// The <see cref="Image{TColor}" />. /// The <see cref="Image{TPixel}" />.
/// </returns> /// </returns>
public static Image<TColor> DrawText<TColor>(this Image<TColor> source, string text, Font font, IBrush<TColor> brush, Vector2 location) public static Image<TPixel> DrawText<TPixel>(this Image<TPixel> source, string text, Font font, IBrush<TPixel> brush, Vector2 location)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.DrawText(text, font, brush, location, TextGraphicsOptions.Default); return source.DrawText(text, font, brush, location, TextGraphicsOptions.Default);
} }
@ -78,7 +78,7 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Draws the text onto the the image filled via the brush. /// Draws the text onto the the image filled via the brush.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="text">The text.</param> /// <param name="text">The text.</param>
/// <param name="font">The font.</param> /// <param name="font">The font.</param>
@ -86,10 +86,10 @@ namespace ImageSharp
/// <param name="location">The location.</param> /// <param name="location">The location.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns> /// <returns>
/// The <see cref="Image{TColor}" />. /// The <see cref="Image{TPixel}" />.
/// </returns> /// </returns>
public static Image<TColor> DrawText<TColor>(this Image<TColor> source, string text, Font font, IBrush<TColor> brush, Vector2 location, TextGraphicsOptions options) public static Image<TPixel> DrawText<TPixel>(this Image<TPixel> source, string text, Font font, IBrush<TPixel> brush, Vector2 location, TextGraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.DrawText(text, font, brush, null, location, options); return source.DrawText(text, font, brush, null, location, options);
} }
@ -97,17 +97,17 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Draws the text onto the the image outlined via the pen. /// Draws the text onto the the image outlined via the pen.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="text">The text.</param> /// <param name="text">The text.</param>
/// <param name="font">The font.</param> /// <param name="font">The font.</param>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="location">The location.</param> /// <param name="location">The location.</param>
/// <returns> /// <returns>
/// The <see cref="Image{TColor}" />. /// The <see cref="Image{TPixel}" />.
/// </returns> /// </returns>
public static Image<TColor> DrawText<TColor>(this Image<TColor> source, string text, Font font, IPen<TColor> pen, Vector2 location) public static Image<TPixel> DrawText<TPixel>(this Image<TPixel> source, string text, Font font, IPen<TPixel> pen, Vector2 location)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.DrawText(text, font, pen, location, TextGraphicsOptions.Default); return source.DrawText(text, font, pen, location, TextGraphicsOptions.Default);
} }
@ -115,7 +115,7 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Draws the text onto the the image outlined via the pen. /// Draws the text onto the the image outlined via the pen.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="text">The text.</param> /// <param name="text">The text.</param>
/// <param name="font">The font.</param> /// <param name="font">The font.</param>
@ -123,10 +123,10 @@ namespace ImageSharp
/// <param name="location">The location.</param> /// <param name="location">The location.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns> /// <returns>
/// The <see cref="Image{TColor}" />. /// The <see cref="Image{TPixel}" />.
/// </returns> /// </returns>
public static Image<TColor> DrawText<TColor>(this Image<TColor> source, string text, Font font, IPen<TColor> pen, Vector2 location, TextGraphicsOptions options) public static Image<TPixel> DrawText<TPixel>(this Image<TPixel> source, string text, Font font, IPen<TPixel> pen, Vector2 location, TextGraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.DrawText(text, font, null, pen, location, options); return source.DrawText(text, font, null, pen, location, options);
} }
@ -134,7 +134,7 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Draws the text onto the the image filled via the brush then outlined via the pen. /// Draws the text onto the the image filled via the brush then outlined via the pen.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="text">The text.</param> /// <param name="text">The text.</param>
/// <param name="font">The font.</param> /// <param name="font">The font.</param>
@ -142,10 +142,10 @@ namespace ImageSharp
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="location">The location.</param> /// <param name="location">The location.</param>
/// <returns> /// <returns>
/// The <see cref="Image{TColor}" />. /// The <see cref="Image{TPixel}" />.
/// </returns> /// </returns>
public static Image<TColor> DrawText<TColor>(this Image<TColor> source, string text, Font font, IBrush<TColor> brush, IPen<TColor> pen, Vector2 location) public static Image<TPixel> DrawText<TPixel>(this Image<TPixel> source, string text, Font font, IBrush<TPixel> brush, IPen<TPixel> pen, Vector2 location)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return source.DrawText(text, font, brush, pen, location, TextGraphicsOptions.Default); return source.DrawText(text, font, brush, pen, location, TextGraphicsOptions.Default);
} }
@ -153,7 +153,7 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Draws the text onto the the image filled via the brush then outlined via the pen. /// Draws the text onto the the image filled via the brush then outlined via the pen.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="text">The text.</param> /// <param name="text">The text.</param>
/// <param name="font">The font.</param> /// <param name="font">The font.</param>
@ -162,10 +162,10 @@ namespace ImageSharp
/// <param name="location">The location.</param> /// <param name="location">The location.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <returns> /// <returns>
/// The <see cref="Image{TColor}" />. /// The <see cref="Image{TPixel}" />.
/// </returns> /// </returns>
public static Image<TColor> DrawText<TColor>(this Image<TColor> source, string text, Font font, IBrush<TColor> brush, IPen<TColor> pen, Vector2 location, TextGraphicsOptions options) public static Image<TPixel> DrawText<TPixel>(this Image<TPixel> source, string text, Font font, IBrush<TPixel> brush, IPen<TPixel> pen, Vector2 location, TextGraphicsOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
GlyphBuilder glyphBuilder = new GlyphBuilder(location); GlyphBuilder glyphBuilder = new GlyphBuilder(location);

728
src/ImageSharp/Colors/Color.Definitions.cs

@ -1,728 +0,0 @@
// <copyright file="Color.Definitions.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
/// <summary>
/// Packed vector 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.
/// </summary>
/// <remarks>
/// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,
/// as it avoids the need to create new values for modification operations.
/// </remarks>
public partial struct Color
{
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F0F8FF.
/// </summary>
public static readonly Color AliceBlue = NamedColors<Color>.AliceBlue;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FAEBD7.
/// </summary>
public static readonly Color AntiqueWhite = NamedColors<Color>.AntiqueWhite;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #00FFFF.
/// </summary>
public static readonly Color Aqua = NamedColors<Color>.Aqua;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #7FFFD4.
/// </summary>
public static readonly Color Aquamarine = NamedColors<Color>.Aquamarine;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F0FFFF.
/// </summary>
public static readonly Color Azure = NamedColors<Color>.Azure;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F5F5DC.
/// </summary>
public static readonly Color Beige = NamedColors<Color>.Beige;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFE4C4.
/// </summary>
public static readonly Color Bisque = NamedColors<Color>.Bisque;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #000000.
/// </summary>
public static readonly Color Black = NamedColors<Color>.Black;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFEBCD.
/// </summary>
public static readonly Color BlanchedAlmond = NamedColors<Color>.BlanchedAlmond;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #0000FF.
/// </summary>
public static readonly Color Blue = NamedColors<Color>.Blue;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #8A2BE2.
/// </summary>
public static readonly Color BlueViolet = NamedColors<Color>.BlueViolet;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #A52A2A.
/// </summary>
public static readonly Color Brown = NamedColors<Color>.Brown;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #DEB887.
/// </summary>
public static readonly Color BurlyWood = NamedColors<Color>.BurlyWood;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #5F9EA0.
/// </summary>
public static readonly Color CadetBlue = NamedColors<Color>.CadetBlue;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #7FFF00.
/// </summary>
public static readonly Color Chartreuse = NamedColors<Color>.Chartreuse;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #D2691E.
/// </summary>
public static readonly Color Chocolate = NamedColors<Color>.Chocolate;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF7F50.
/// </summary>
public static readonly Color Coral = NamedColors<Color>.Coral;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #6495ED.
/// </summary>
public static readonly Color CornflowerBlue = NamedColors<Color>.CornflowerBlue;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFF8DC.
/// </summary>
public static readonly Color Cornsilk = NamedColors<Color>.Cornsilk;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #DC143C.
/// </summary>
public static readonly Color Crimson = NamedColors<Color>.Crimson;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #00FFFF.
/// </summary>
public static readonly Color Cyan = NamedColors<Color>.Cyan;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #00008B.
/// </summary>
public static readonly Color DarkBlue = NamedColors<Color>.DarkBlue;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #008B8B.
/// </summary>
public static readonly Color DarkCyan = NamedColors<Color>.DarkCyan;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #B8860B.
/// </summary>
public static readonly Color DarkGoldenrod = NamedColors<Color>.DarkGoldenrod;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #A9A9A9.
/// </summary>
public static readonly Color DarkGray = NamedColors<Color>.DarkGray;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #006400.
/// </summary>
public static readonly Color DarkGreen = NamedColors<Color>.DarkGreen;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #BDB76B.
/// </summary>
public static readonly Color DarkKhaki = NamedColors<Color>.DarkKhaki;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #8B008B.
/// </summary>
public static readonly Color DarkMagenta = NamedColors<Color>.DarkMagenta;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #556B2F.
/// </summary>
public static readonly Color DarkOliveGreen = NamedColors<Color>.DarkOliveGreen;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF8C00.
/// </summary>
public static readonly Color DarkOrange = NamedColors<Color>.DarkOrange;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #9932CC.
/// </summary>
public static readonly Color DarkOrchid = NamedColors<Color>.DarkOrchid;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #8B0000.
/// </summary>
public static readonly Color DarkRed = NamedColors<Color>.DarkRed;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #E9967A.
/// </summary>
public static readonly Color DarkSalmon = NamedColors<Color>.DarkSalmon;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #8FBC8B.
/// </summary>
public static readonly Color DarkSeaGreen = NamedColors<Color>.DarkSeaGreen;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #483D8B.
/// </summary>
public static readonly Color DarkSlateBlue = NamedColors<Color>.DarkSlateBlue;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #2F4F4F.
/// </summary>
public static readonly Color DarkSlateGray = NamedColors<Color>.DarkSlateGray;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #00CED1.
/// </summary>
public static readonly Color DarkTurquoise = NamedColors<Color>.DarkTurquoise;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #9400D3.
/// </summary>
public static readonly Color DarkViolet = NamedColors<Color>.DarkViolet;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF1493.
/// </summary>
public static readonly Color DeepPink = NamedColors<Color>.DeepPink;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #00BFFF.
/// </summary>
public static readonly Color DeepSkyBlue = NamedColors<Color>.DeepSkyBlue;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #696969.
/// </summary>
public static readonly Color DimGray = NamedColors<Color>.DimGray;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #1E90FF.
/// </summary>
public static readonly Color DodgerBlue = NamedColors<Color>.DodgerBlue;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #B22222.
/// </summary>
public static readonly Color Firebrick = NamedColors<Color>.Firebrick;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFAF0.
/// </summary>
public static readonly Color FloralWhite = NamedColors<Color>.FloralWhite;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #228B22.
/// </summary>
public static readonly Color ForestGreen = NamedColors<Color>.ForestGreen;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF00FF.
/// </summary>
public static readonly Color Fuchsia = NamedColors<Color>.Fuchsia;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #DCDCDC.
/// </summary>
public static readonly Color Gainsboro = NamedColors<Color>.Gainsboro;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F8F8FF.
/// </summary>
public static readonly Color GhostWhite = NamedColors<Color>.GhostWhite;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFD700.
/// </summary>
public static readonly Color Gold = NamedColors<Color>.Gold;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #DAA520.
/// </summary>
public static readonly Color Goldenrod = NamedColors<Color>.Goldenrod;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #808080.
/// </summary>
public static readonly Color Gray = NamedColors<Color>.Gray;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #008000.
/// </summary>
public static readonly Color Green = NamedColors<Color>.Green;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #ADFF2F.
/// </summary>
public static readonly Color GreenYellow = NamedColors<Color>.GreenYellow;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F0FFF0.
/// </summary>
public static readonly Color Honeydew = NamedColors<Color>.Honeydew;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF69B4.
/// </summary>
public static readonly Color HotPink = NamedColors<Color>.HotPink;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #CD5C5C.
/// </summary>
public static readonly Color IndianRed = NamedColors<Color>.IndianRed;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #4B0082.
/// </summary>
public static readonly Color Indigo = NamedColors<Color>.Indigo;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFFF0.
/// </summary>
public static readonly Color Ivory = NamedColors<Color>.Ivory;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F0E68C.
/// </summary>
public static readonly Color Khaki = NamedColors<Color>.Khaki;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #E6E6FA.
/// </summary>
public static readonly Color Lavender = NamedColors<Color>.Lavender;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFF0F5.
/// </summary>
public static readonly Color LavenderBlush = NamedColors<Color>.LavenderBlush;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #7CFC00.
/// </summary>
public static readonly Color LawnGreen = NamedColors<Color>.LawnGreen;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFACD.
/// </summary>
public static readonly Color LemonChiffon = NamedColors<Color>.LemonChiffon;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #ADD8E6.
/// </summary>
public static readonly Color LightBlue = NamedColors<Color>.LightBlue;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F08080.
/// </summary>
public static readonly Color LightCoral = NamedColors<Color>.LightCoral;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #E0FFFF.
/// </summary>
public static readonly Color LightCyan = NamedColors<Color>.LightCyan;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FAFAD2.
/// </summary>
public static readonly Color LightGoldenrodYellow = NamedColors<Color>.LightGoldenrodYellow;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #D3D3D3.
/// </summary>
public static readonly Color LightGray = NamedColors<Color>.LightGray;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #90EE90.
/// </summary>
public static readonly Color LightGreen = NamedColors<Color>.LightGreen;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFB6C1.
/// </summary>
public static readonly Color LightPink = NamedColors<Color>.LightPink;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFA07A.
/// </summary>
public static readonly Color LightSalmon = NamedColors<Color>.LightSalmon;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #20B2AA.
/// </summary>
public static readonly Color LightSeaGreen = NamedColors<Color>.LightSeaGreen;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #87CEFA.
/// </summary>
public static readonly Color LightSkyBlue = NamedColors<Color>.LightSkyBlue;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #778899.
/// </summary>
public static readonly Color LightSlateGray = NamedColors<Color>.LightSlateGray;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #B0C4DE.
/// </summary>
public static readonly Color LightSteelBlue = NamedColors<Color>.LightSteelBlue;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFFE0.
/// </summary>
public static readonly Color LightYellow = NamedColors<Color>.LightYellow;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #00FF00.
/// </summary>
public static readonly Color Lime = NamedColors<Color>.Lime;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #32CD32.
/// </summary>
public static readonly Color LimeGreen = NamedColors<Color>.LimeGreen;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FAF0E6.
/// </summary>
public static readonly Color Linen = NamedColors<Color>.Linen;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF00FF.
/// </summary>
public static readonly Color Magenta = NamedColors<Color>.Magenta;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #800000.
/// </summary>
public static readonly Color Maroon = NamedColors<Color>.Maroon;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #66CDAA.
/// </summary>
public static readonly Color MediumAquamarine = NamedColors<Color>.MediumAquamarine;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #0000CD.
/// </summary>
public static readonly Color MediumBlue = NamedColors<Color>.MediumBlue;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #BA55D3.
/// </summary>
public static readonly Color MediumOrchid = NamedColors<Color>.MediumOrchid;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #9370DB.
/// </summary>
public static readonly Color MediumPurple = NamedColors<Color>.MediumPurple;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #3CB371.
/// </summary>
public static readonly Color MediumSeaGreen = NamedColors<Color>.MediumSeaGreen;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #7B68EE.
/// </summary>
public static readonly Color MediumSlateBlue = NamedColors<Color>.MediumSlateBlue;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #00FA9A.
/// </summary>
public static readonly Color MediumSpringGreen = NamedColors<Color>.MediumSpringGreen;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #48D1CC.
/// </summary>
public static readonly Color MediumTurquoise = NamedColors<Color>.MediumTurquoise;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #C71585.
/// </summary>
public static readonly Color MediumVioletRed = NamedColors<Color>.MediumVioletRed;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #191970.
/// </summary>
public static readonly Color MidnightBlue = NamedColors<Color>.MidnightBlue;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F5FFFA.
/// </summary>
public static readonly Color MintCream = NamedColors<Color>.MintCream;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFE4E1.
/// </summary>
public static readonly Color MistyRose = NamedColors<Color>.MistyRose;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFE4B5.
/// </summary>
public static readonly Color Moccasin = NamedColors<Color>.Moccasin;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFDEAD.
/// </summary>
public static readonly Color NavajoWhite = NamedColors<Color>.NavajoWhite;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #000080.
/// </summary>
public static readonly Color Navy = NamedColors<Color>.Navy;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FDF5E6.
/// </summary>
public static readonly Color OldLace = NamedColors<Color>.OldLace;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #808000.
/// </summary>
public static readonly Color Olive = NamedColors<Color>.Olive;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #6B8E23.
/// </summary>
public static readonly Color OliveDrab = NamedColors<Color>.OliveDrab;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFA500.
/// </summary>
public static readonly Color Orange = NamedColors<Color>.Orange;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF4500.
/// </summary>
public static readonly Color OrangeRed = NamedColors<Color>.OrangeRed;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #DA70D6.
/// </summary>
public static readonly Color Orchid = NamedColors<Color>.Orchid;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #EEE8AA.
/// </summary>
public static readonly Color PaleGoldenrod = NamedColors<Color>.PaleGoldenrod;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #98FB98.
/// </summary>
public static readonly Color PaleGreen = NamedColors<Color>.PaleGreen;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #AFEEEE.
/// </summary>
public static readonly Color PaleTurquoise = NamedColors<Color>.PaleTurquoise;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #DB7093.
/// </summary>
public static readonly Color PaleVioletRed = NamedColors<Color>.PaleVioletRed;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFEFD5.
/// </summary>
public static readonly Color PapayaWhip = NamedColors<Color>.PapayaWhip;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFDAB9.
/// </summary>
public static readonly Color PeachPuff = NamedColors<Color>.PeachPuff;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #CD853F.
/// </summary>
public static readonly Color Peru = NamedColors<Color>.Peru;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFC0CB.
/// </summary>
public static readonly Color Pink = NamedColors<Color>.Pink;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #DDA0DD.
/// </summary>
public static readonly Color Plum = NamedColors<Color>.Plum;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #B0E0E6.
/// </summary>
public static readonly Color PowderBlue = NamedColors<Color>.PowderBlue;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #800080.
/// </summary>
public static readonly Color Purple = NamedColors<Color>.Purple;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #663399.
/// </summary>
public static readonly Color RebeccaPurple = NamedColors<Color>.RebeccaPurple;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF0000.
/// </summary>
public static readonly Color Red = NamedColors<Color>.Red;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #BC8F8F.
/// </summary>
public static readonly Color RosyBrown = NamedColors<Color>.RosyBrown;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #4169E1.
/// </summary>
public static readonly Color RoyalBlue = NamedColors<Color>.RoyalBlue;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #8B4513.
/// </summary>
public static readonly Color SaddleBrown = NamedColors<Color>.SaddleBrown;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FA8072.
/// </summary>
public static readonly Color Salmon = NamedColors<Color>.Salmon;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F4A460.
/// </summary>
public static readonly Color SandyBrown = NamedColors<Color>.SandyBrown;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #2E8B57.
/// </summary>
public static readonly Color SeaGreen = NamedColors<Color>.SeaGreen;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFF5EE.
/// </summary>
public static readonly Color SeaShell = NamedColors<Color>.SeaShell;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #A0522D.
/// </summary>
public static readonly Color Sienna = NamedColors<Color>.Sienna;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #C0C0C0.
/// </summary>
public static readonly Color Silver = NamedColors<Color>.Silver;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #87CEEB.
/// </summary>
public static readonly Color SkyBlue = NamedColors<Color>.SkyBlue;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #6A5ACD.
/// </summary>
public static readonly Color SlateBlue = NamedColors<Color>.SlateBlue;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #708090.
/// </summary>
public static readonly Color SlateGray = NamedColors<Color>.SlateGray;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFAFA.
/// </summary>
public static readonly Color Snow = NamedColors<Color>.Snow;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #00FF7F.
/// </summary>
public static readonly Color SpringGreen = NamedColors<Color>.SpringGreen;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #4682B4.
/// </summary>
public static readonly Color SteelBlue = NamedColors<Color>.SteelBlue;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #D2B48C.
/// </summary>
public static readonly Color Tan = NamedColors<Color>.Tan;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #008080.
/// </summary>
public static readonly Color Teal = NamedColors<Color>.Teal;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #D8BFD8.
/// </summary>
public static readonly Color Thistle = NamedColors<Color>.Thistle;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FF6347.
/// </summary>
public static readonly Color Tomato = NamedColors<Color>.Tomato;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFFFF.
/// </summary>
public static readonly Color Transparent = NamedColors<Color>.Transparent;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #40E0D0.
/// </summary>
public static readonly Color Turquoise = NamedColors<Color>.Turquoise;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #EE82EE.
/// </summary>
public static readonly Color Violet = NamedColors<Color>.Violet;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F5DEB3.
/// </summary>
public static readonly Color Wheat = NamedColors<Color>.Wheat;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFFFF.
/// </summary>
public static readonly Color White = NamedColors<Color>.White;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #F5F5F5.
/// </summary>
public static readonly Color WhiteSmoke = NamedColors<Color>.WhiteSmoke;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #FFFF00.
/// </summary>
public static readonly Color Yellow = NamedColors<Color>.Yellow;
/// <summary>
/// Represents a <see cref="Color"/> matching the W3C definition that has an hex value of #9ACD32.
/// </summary>
public static readonly Color YellowGreen = NamedColors<Color>.YellowGreen;
}
}

179
src/ImageSharp/Colors/ColorConstants.cs

@ -1,179 +0,0 @@
// <copyright file="ColorConstants.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.Collections.Generic;
/// <summary>
/// Provides useful color definitions.
/// </summary>
public static class ColorConstants
{
/// <summary>
/// Provides a lazy, one time method of returning the colors.
/// </summary>
private static readonly Lazy<Color[]> SafeColors = new Lazy<Color[]>(GetWebSafeColors);
/// <summary>
/// Gets a collection of named, web safe, colors as defined in the CSS Color Module Level 4.
/// </summary>
public static Color[] WebSafeColors => SafeColors.Value;
/// <summary>
/// Returns an array of web safe colors.
/// </summary>
/// <returns>The <see cref="T:Color[]"/></returns>
private static Color[] GetWebSafeColors()
{
return new List<Color>
{
Color.AliceBlue,
Color.AntiqueWhite,
Color.Aqua,
Color.Aquamarine,
Color.Azure,
Color.Beige,
Color.Bisque,
Color.Black,
Color.BlanchedAlmond,
Color.Blue,
Color.BlueViolet,
Color.Brown,
Color.BurlyWood,
Color.CadetBlue,
Color.Chartreuse,
Color.Chocolate,
Color.Coral,
Color.CornflowerBlue,
Color.Cornsilk,
Color.Crimson,
Color.Cyan,
Color.DarkBlue,
Color.DarkCyan,
Color.DarkGoldenrod,
Color.DarkGray,
Color.DarkGreen,
Color.DarkKhaki,
Color.DarkMagenta,
Color.DarkOliveGreen,
Color.DarkOrange,
Color.DarkOrchid,
Color.DarkRed,
Color.DarkSalmon,
Color.DarkSeaGreen,
Color.DarkSlateBlue,
Color.DarkSlateGray,
Color.DarkTurquoise,
Color.DarkViolet,
Color.DeepPink,
Color.DeepSkyBlue,
Color.DimGray,
Color.DodgerBlue,
Color.Firebrick,
Color.FloralWhite,
Color.ForestGreen,
Color.Fuchsia,
Color.Gainsboro,
Color.GhostWhite,
Color.Gold,
Color.Goldenrod,
Color.Gray,
Color.Green,
Color.GreenYellow,
Color.Honeydew,
Color.HotPink,
Color.IndianRed,
Color.Indigo,
Color.Ivory,
Color.Khaki,
Color.Lavender,
Color.LavenderBlush,
Color.LawnGreen,
Color.LemonChiffon,
Color.LightBlue,
Color.LightCoral,
Color.LightCyan,
Color.LightGoldenrodYellow,
Color.LightGray,
Color.LightGreen,
Color.LightPink,
Color.LightSalmon,
Color.LightSeaGreen,
Color.LightSkyBlue,
Color.LightSlateGray,
Color.LightSteelBlue,
Color.LightYellow,
Color.Lime,
Color.LimeGreen,
Color.Linen,
Color.Magenta,
Color.Maroon,
Color.MediumAquamarine,
Color.MediumBlue,
Color.MediumOrchid,
Color.MediumPurple,
Color.MediumSeaGreen,
Color.MediumSlateBlue,
Color.MediumSpringGreen,
Color.MediumTurquoise,
Color.MediumVioletRed,
Color.MidnightBlue,
Color.MintCream,
Color.MistyRose,
Color.Moccasin,
Color.NavajoWhite,
Color.Navy,
Color.OldLace,
Color.Olive,
Color.OliveDrab,
Color.Orange,
Color.OrangeRed,
Color.Orchid,
Color.PaleGoldenrod,
Color.PaleGreen,
Color.PaleTurquoise,
Color.PaleVioletRed,
Color.PapayaWhip,
Color.PeachPuff,
Color.Peru,
Color.Pink,
Color.Plum,
Color.PowderBlue,
Color.Purple,
Color.RebeccaPurple,
Color.Red,
Color.RosyBrown,
Color.RoyalBlue,
Color.SaddleBrown,
Color.Salmon,
Color.SandyBrown,
Color.SeaGreen,
Color.SeaShell,
Color.Sienna,
Color.Silver,
Color.SkyBlue,
Color.SlateBlue,
Color.SlateGray,
Color.Snow,
Color.SpringGreen,
Color.SteelBlue,
Color.Tan,
Color.Teal,
Color.Thistle,
Color.Tomato,
Color.Transparent,
Color.Turquoise,
Color.Violet,
Color.Wheat,
Color.White,
Color.WhiteSmoke,
Color.Yellow,
Color.YellowGreen
}.ToArray();
}
}
}

27
src/ImageSharp/Colors/ColorVector.BulkOperations.cs

@ -1,27 +0,0 @@
namespace ImageSharp
{
using System.Numerics;
/// <summary>
/// Unpacked pixel type containing four 16-bit unsigned normalized values typically ranging from 0 to 1.
/// The color components are stored in red, green, blue, and alpha order.
/// </summary>
/// <remarks>
/// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,
/// as it avoids the need to create new values for modification operations.
/// </remarks>
public partial struct ColorVector
{
/// <summary>
/// <see cref="BulkPixelOperations{TColor}"/> implementation optimized for <see cref="ColorVector"/>.
/// </summary>
internal class BulkOperations : BulkPixelOperations<ColorVector>
{
/// <inheritdoc />
internal override unsafe void ToVector4(BufferSpan<ColorVector> sourceColors, BufferSpan<Vector4> destVectors, int count)
{
BufferSpan.Copy(sourceColors.AsBytes(), destVectors.AsBytes(), count * sizeof(Vector4));
}
}
}
}

728
src/ImageSharp/Colors/ColorVector.Definitions.cs

@ -1,728 +0,0 @@
// <copyright file="ColorVector.Definitions.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
/// <summary>
/// Unpacked pixel type containing four 16-bit floating-point values typically ranging from 0 to 1.
/// The color components are stored in red, green, blue, and alpha order.
/// </summary>
/// <remarks>
/// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,
/// as it avoids the need to create new values for modification operations.
/// </remarks>
public partial struct ColorVector
{
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F0F8FF.
/// </summary>
public static readonly ColorVector AliceBlue = NamedColors<ColorVector>.AliceBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FAEBD7.
/// </summary>
public static readonly ColorVector AntiqueWhite = NamedColors<ColorVector>.AntiqueWhite;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #00FFFF.
/// </summary>
public static readonly ColorVector Aqua = NamedColors<ColorVector>.Aqua;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #7FFFD4.
/// </summary>
public static readonly ColorVector Aquamarine = NamedColors<ColorVector>.Aquamarine;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F0FFFF.
/// </summary>
public static readonly ColorVector Azure = NamedColors<ColorVector>.Azure;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F5F5DC.
/// </summary>
public static readonly ColorVector Beige = NamedColors<ColorVector>.Beige;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFE4C4.
/// </summary>
public static readonly ColorVector Bisque = NamedColors<ColorVector>.Bisque;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #000000.
/// </summary>
public static readonly ColorVector Black = NamedColors<ColorVector>.Black;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFEBCD.
/// </summary>
public static readonly ColorVector BlanchedAlmond = NamedColors<ColorVector>.BlanchedAlmond;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #0000FF.
/// </summary>
public static readonly ColorVector Blue = NamedColors<ColorVector>.Blue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #8A2BE2.
/// </summary>
public static readonly ColorVector BlueViolet = NamedColors<ColorVector>.BlueViolet;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #A52A2A.
/// </summary>
public static readonly ColorVector Brown = NamedColors<ColorVector>.Brown;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #DEB887.
/// </summary>
public static readonly ColorVector BurlyWood = NamedColors<ColorVector>.BurlyWood;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #5F9EA0.
/// </summary>
public static readonly ColorVector CadetBlue = NamedColors<ColorVector>.CadetBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #7FFF00.
/// </summary>
public static readonly ColorVector Chartreuse = NamedColors<ColorVector>.Chartreuse;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #D2691E.
/// </summary>
public static readonly ColorVector Chocolate = NamedColors<ColorVector>.Chocolate;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF7F50.
/// </summary>
public static readonly ColorVector Coral = NamedColors<ColorVector>.Coral;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #6495ED.
/// </summary>
public static readonly ColorVector CornflowerBlue = NamedColors<ColorVector>.CornflowerBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFF8DC.
/// </summary>
public static readonly ColorVector Cornsilk = NamedColors<ColorVector>.Cornsilk;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #DC143C.
/// </summary>
public static readonly ColorVector Crimson = NamedColors<ColorVector>.Crimson;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #00FFFF.
/// </summary>
public static readonly ColorVector Cyan = NamedColors<ColorVector>.Cyan;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #00008B.
/// </summary>
public static readonly ColorVector DarkBlue = NamedColors<ColorVector>.DarkBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #008B8B.
/// </summary>
public static readonly ColorVector DarkCyan = NamedColors<ColorVector>.DarkCyan;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #B8860B.
/// </summary>
public static readonly ColorVector DarkGoldenrod = NamedColors<ColorVector>.DarkGoldenrod;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #A9A9A9.
/// </summary>
public static readonly ColorVector DarkGray = NamedColors<ColorVector>.DarkGray;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #006400.
/// </summary>
public static readonly ColorVector DarkGreen = NamedColors<ColorVector>.DarkGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #BDB76B.
/// </summary>
public static readonly ColorVector DarkKhaki = NamedColors<ColorVector>.DarkKhaki;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #8B008B.
/// </summary>
public static readonly ColorVector DarkMagenta = NamedColors<ColorVector>.DarkMagenta;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #556B2F.
/// </summary>
public static readonly ColorVector DarkOliveGreen = NamedColors<ColorVector>.DarkOliveGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF8C00.
/// </summary>
public static readonly ColorVector DarkOrange = NamedColors<ColorVector>.DarkOrange;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #9932CC.
/// </summary>
public static readonly ColorVector DarkOrchid = NamedColors<ColorVector>.DarkOrchid;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #8B0000.
/// </summary>
public static readonly ColorVector DarkRed = NamedColors<ColorVector>.DarkRed;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #E9967A.
/// </summary>
public static readonly ColorVector DarkSalmon = NamedColors<ColorVector>.DarkSalmon;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #8FBC8B.
/// </summary>
public static readonly ColorVector DarkSeaGreen = NamedColors<ColorVector>.DarkSeaGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #483D8B.
/// </summary>
public static readonly ColorVector DarkSlateBlue = NamedColors<ColorVector>.DarkSlateBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #2F4F4F.
/// </summary>
public static readonly ColorVector DarkSlateGray = NamedColors<ColorVector>.DarkSlateGray;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #00CED1.
/// </summary>
public static readonly ColorVector DarkTurquoise = NamedColors<ColorVector>.DarkTurquoise;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #9400D3.
/// </summary>
public static readonly ColorVector DarkViolet = NamedColors<ColorVector>.DarkViolet;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF1493.
/// </summary>
public static readonly ColorVector DeepPink = NamedColors<ColorVector>.DeepPink;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #00BFFF.
/// </summary>
public static readonly ColorVector DeepSkyBlue = NamedColors<ColorVector>.DeepSkyBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #696969.
/// </summary>
public static readonly ColorVector DimGray = NamedColors<ColorVector>.DimGray;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #1E90FF.
/// </summary>
public static readonly ColorVector DodgerBlue = NamedColors<ColorVector>.DodgerBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #B22222.
/// </summary>
public static readonly ColorVector Firebrick = NamedColors<ColorVector>.Firebrick;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFFAF0.
/// </summary>
public static readonly ColorVector FloralWhite = NamedColors<ColorVector>.FloralWhite;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #228B22.
/// </summary>
public static readonly ColorVector ForestGreen = NamedColors<ColorVector>.ForestGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF00FF.
/// </summary>
public static readonly ColorVector Fuchsia = NamedColors<ColorVector>.Fuchsia;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #DCDCDC.
/// </summary>
public static readonly ColorVector Gainsboro = NamedColors<ColorVector>.Gainsboro;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F8F8FF.
/// </summary>
public static readonly ColorVector GhostWhite = NamedColors<ColorVector>.GhostWhite;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFD700.
/// </summary>
public static readonly ColorVector Gold = NamedColors<ColorVector>.Gold;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #DAA520.
/// </summary>
public static readonly ColorVector Goldenrod = NamedColors<ColorVector>.Goldenrod;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #808080.
/// </summary>
public static readonly ColorVector Gray = NamedColors<ColorVector>.Gray;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #008000.
/// </summary>
public static readonly ColorVector Green = NamedColors<ColorVector>.Green;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #ADFF2F.
/// </summary>
public static readonly ColorVector GreenYellow = NamedColors<ColorVector>.GreenYellow;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F0FFF0.
/// </summary>
public static readonly ColorVector Honeydew = NamedColors<ColorVector>.Honeydew;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF69B4.
/// </summary>
public static readonly ColorVector HotPink = NamedColors<ColorVector>.HotPink;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #CD5C5C.
/// </summary>
public static readonly ColorVector IndianRed = NamedColors<ColorVector>.IndianRed;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #4B0082.
/// </summary>
public static readonly ColorVector Indigo = NamedColors<ColorVector>.Indigo;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFFFF0.
/// </summary>
public static readonly ColorVector Ivory = NamedColors<ColorVector>.Ivory;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F0E68C.
/// </summary>
public static readonly ColorVector Khaki = NamedColors<ColorVector>.Khaki;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #E6E6FA.
/// </summary>
public static readonly ColorVector Lavender = NamedColors<ColorVector>.Lavender;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFF0F5.
/// </summary>
public static readonly ColorVector LavenderBlush = NamedColors<ColorVector>.LavenderBlush;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #7CFC00.
/// </summary>
public static readonly ColorVector LawnGreen = NamedColors<ColorVector>.LawnGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFFACD.
/// </summary>
public static readonly ColorVector LemonChiffon = NamedColors<ColorVector>.LemonChiffon;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #ADD8E6.
/// </summary>
public static readonly ColorVector LightBlue = NamedColors<ColorVector>.LightBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F08080.
/// </summary>
public static readonly ColorVector LightCoral = NamedColors<ColorVector>.LightCoral;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #E0FFFF.
/// </summary>
public static readonly ColorVector LightCyan = NamedColors<ColorVector>.LightCyan;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FAFAD2.
/// </summary>
public static readonly ColorVector LightGoldenrodYellow = NamedColors<ColorVector>.LightGoldenrodYellow;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #D3D3D3.
/// </summary>
public static readonly ColorVector LightGray = NamedColors<ColorVector>.LightGray;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #90EE90.
/// </summary>
public static readonly ColorVector LightGreen = NamedColors<ColorVector>.LightGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFB6C1.
/// </summary>
public static readonly ColorVector LightPink = NamedColors<ColorVector>.LightPink;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFA07A.
/// </summary>
public static readonly ColorVector LightSalmon = NamedColors<ColorVector>.LightSalmon;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #20B2AA.
/// </summary>
public static readonly ColorVector LightSeaGreen = NamedColors<ColorVector>.LightSeaGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #87CEFA.
/// </summary>
public static readonly ColorVector LightSkyBlue = NamedColors<ColorVector>.LightSkyBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #778899.
/// </summary>
public static readonly ColorVector LightSlateGray = NamedColors<ColorVector>.LightSlateGray;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #B0C4DE.
/// </summary>
public static readonly ColorVector LightSteelBlue = NamedColors<ColorVector>.LightSteelBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFFFE0.
/// </summary>
public static readonly ColorVector LightYellow = NamedColors<ColorVector>.LightYellow;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #00FF00.
/// </summary>
public static readonly ColorVector Lime = NamedColors<ColorVector>.Lime;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #32CD32.
/// </summary>
public static readonly ColorVector LimeGreen = NamedColors<ColorVector>.LimeGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FAF0E6.
/// </summary>
public static readonly ColorVector Linen = NamedColors<ColorVector>.Linen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF00FF.
/// </summary>
public static readonly ColorVector Magenta = NamedColors<ColorVector>.Magenta;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #800000.
/// </summary>
public static readonly ColorVector Maroon = NamedColors<ColorVector>.Maroon;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #66CDAA.
/// </summary>
public static readonly ColorVector MediumAquamarine = NamedColors<ColorVector>.MediumAquamarine;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #0000CD.
/// </summary>
public static readonly ColorVector MediumBlue = NamedColors<ColorVector>.MediumBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #BA55D3.
/// </summary>
public static readonly ColorVector MediumOrchid = NamedColors<ColorVector>.MediumOrchid;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #9370DB.
/// </summary>
public static readonly ColorVector MediumPurple = NamedColors<ColorVector>.MediumPurple;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #3CB371.
/// </summary>
public static readonly ColorVector MediumSeaGreen = NamedColors<ColorVector>.MediumSeaGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #7B68EE.
/// </summary>
public static readonly ColorVector MediumSlateBlue = NamedColors<ColorVector>.MediumSlateBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #00FA9A.
/// </summary>
public static readonly ColorVector MediumSpringGreen = NamedColors<ColorVector>.MediumSpringGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #48D1CC.
/// </summary>
public static readonly ColorVector MediumTurquoise = NamedColors<ColorVector>.MediumTurquoise;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #C71585.
/// </summary>
public static readonly ColorVector MediumVioletRed = NamedColors<ColorVector>.MediumVioletRed;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #191970.
/// </summary>
public static readonly ColorVector MidnightBlue = NamedColors<ColorVector>.MidnightBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F5FFFA.
/// </summary>
public static readonly ColorVector MintCream = NamedColors<ColorVector>.MintCream;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFE4E1.
/// </summary>
public static readonly ColorVector MistyRose = NamedColors<ColorVector>.MistyRose;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFE4B5.
/// </summary>
public static readonly ColorVector Moccasin = NamedColors<ColorVector>.Moccasin;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFDEAD.
/// </summary>
public static readonly ColorVector NavajoWhite = NamedColors<ColorVector>.NavajoWhite;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #000080.
/// </summary>
public static readonly ColorVector Navy = NamedColors<ColorVector>.Navy;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FDF5E6.
/// </summary>
public static readonly ColorVector OldLace = NamedColors<ColorVector>.OldLace;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #808000.
/// </summary>
public static readonly ColorVector Olive = NamedColors<ColorVector>.Olive;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #6B8E23.
/// </summary>
public static readonly ColorVector OliveDrab = NamedColors<ColorVector>.OliveDrab;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFA500.
/// </summary>
public static readonly ColorVector Orange = NamedColors<ColorVector>.Orange;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF4500.
/// </summary>
public static readonly ColorVector OrangeRed = NamedColors<ColorVector>.OrangeRed;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #DA70D6.
/// </summary>
public static readonly ColorVector Orchid = NamedColors<ColorVector>.Orchid;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #EEE8AA.
/// </summary>
public static readonly ColorVector PaleGoldenrod = NamedColors<ColorVector>.PaleGoldenrod;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #98FB98.
/// </summary>
public static readonly ColorVector PaleGreen = NamedColors<ColorVector>.PaleGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #AFEEEE.
/// </summary>
public static readonly ColorVector PaleTurquoise = NamedColors<ColorVector>.PaleTurquoise;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #DB7093.
/// </summary>
public static readonly ColorVector PaleVioletRed = NamedColors<ColorVector>.PaleVioletRed;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFEFD5.
/// </summary>
public static readonly ColorVector PapayaWhip = NamedColors<ColorVector>.PapayaWhip;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFDAB9.
/// </summary>
public static readonly ColorVector PeachPuff = NamedColors<ColorVector>.PeachPuff;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #CD853F.
/// </summary>
public static readonly ColorVector Peru = NamedColors<ColorVector>.Peru;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFC0CB.
/// </summary>
public static readonly ColorVector Pink = NamedColors<ColorVector>.Pink;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #DDA0DD.
/// </summary>
public static readonly ColorVector Plum = NamedColors<ColorVector>.Plum;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #B0E0E6.
/// </summary>
public static readonly ColorVector PowderBlue = NamedColors<ColorVector>.PowderBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #800080.
/// </summary>
public static readonly ColorVector Purple = NamedColors<ColorVector>.Purple;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #663399.
/// </summary>
public static readonly ColorVector RebeccaPurple = NamedColors<ColorVector>.RebeccaPurple;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF0000.
/// </summary>
public static readonly ColorVector Red = NamedColors<ColorVector>.Red;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #BC8F8F.
/// </summary>
public static readonly ColorVector RosyBrown = NamedColors<ColorVector>.RosyBrown;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #4169E1.
/// </summary>
public static readonly ColorVector RoyalBlue = NamedColors<ColorVector>.RoyalBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #8B4513.
/// </summary>
public static readonly ColorVector SaddleBrown = NamedColors<ColorVector>.SaddleBrown;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FA8072.
/// </summary>
public static readonly ColorVector Salmon = NamedColors<ColorVector>.Salmon;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F4A460.
/// </summary>
public static readonly ColorVector SandyBrown = NamedColors<ColorVector>.SandyBrown;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #2E8B57.
/// </summary>
public static readonly ColorVector SeaGreen = NamedColors<ColorVector>.SeaGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFF5EE.
/// </summary>
public static readonly ColorVector SeaShell = NamedColors<ColorVector>.SeaShell;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #A0522D.
/// </summary>
public static readonly ColorVector Sienna = NamedColors<ColorVector>.Sienna;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #C0C0C0.
/// </summary>
public static readonly ColorVector Silver = NamedColors<ColorVector>.Silver;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #87CEEB.
/// </summary>
public static readonly ColorVector SkyBlue = NamedColors<ColorVector>.SkyBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #6A5ACD.
/// </summary>
public static readonly ColorVector SlateBlue = NamedColors<ColorVector>.SlateBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #708090.
/// </summary>
public static readonly ColorVector SlateGray = NamedColors<ColorVector>.SlateGray;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFFAFA.
/// </summary>
public static readonly ColorVector Snow = NamedColors<ColorVector>.Snow;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #00FF7F.
/// </summary>
public static readonly ColorVector SpringGreen = NamedColors<ColorVector>.SpringGreen;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #4682B4.
/// </summary>
public static readonly ColorVector SteelBlue = NamedColors<ColorVector>.SteelBlue;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #D2B48C.
/// </summary>
public static readonly ColorVector Tan = NamedColors<ColorVector>.Tan;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #008080.
/// </summary>
public static readonly ColorVector Teal = NamedColors<ColorVector>.Teal;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #D8BFD8.
/// </summary>
public static readonly ColorVector Thistle = NamedColors<ColorVector>.Thistle;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FF6347.
/// </summary>
public static readonly ColorVector Tomato = NamedColors<ColorVector>.Tomato;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFFFFF.
/// </summary>
public static readonly ColorVector Transparent = NamedColors<ColorVector>.Transparent;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #40E0D0.
/// </summary>
public static readonly ColorVector Turquoise = NamedColors<ColorVector>.Turquoise;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #EE82EE.
/// </summary>
public static readonly ColorVector Violet = NamedColors<ColorVector>.Violet;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F5DEB3.
/// </summary>
public static readonly ColorVector Wheat = NamedColors<ColorVector>.Wheat;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFFFFF.
/// </summary>
public static readonly ColorVector White = NamedColors<ColorVector>.White;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #F5F5F5.
/// </summary>
public static readonly ColorVector WhiteSmoke = NamedColors<ColorVector>.WhiteSmoke;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #FFFF00.
/// </summary>
public static readonly ColorVector Yellow = NamedColors<ColorVector>.Yellow;
/// <summary>
/// Represents a <see cref="ColorVector"/> matching the W3C definition that has an hex value of #9ACD32.
/// </summary>
public static readonly ColorVector YellowGreen = NamedColors<ColorVector>.YellowGreen;
}
}

727
src/ImageSharp/Colors/NamedColors{TColor}.cs

@ -1,727 +0,0 @@
// <copyright file="NamedColors{TColor}.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;
/// <summary>
/// A set of named colors mapped to the provided color space.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
public static class NamedColors<TColor>
where TColor : struct, IPixel<TColor>
{
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #F0F8FF.
/// </summary>
public static readonly TColor AliceBlue = ColorBuilder<TColor>.FromRGBA(240, 248, 255, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FAEBD7.
/// </summary>
public static readonly TColor AntiqueWhite = ColorBuilder<TColor>.FromRGBA(250, 235, 215, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #00FFFF.
/// </summary>
public static readonly TColor Aqua = ColorBuilder<TColor>.FromRGBA(0, 255, 255, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #7FFFD4.
/// </summary>
public static readonly TColor Aquamarine = ColorBuilder<TColor>.FromRGBA(127, 255, 212, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #F0FFFF.
/// </summary>
public static readonly TColor Azure = ColorBuilder<TColor>.FromRGBA(240, 255, 255, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #F5F5DC.
/// </summary>
public static readonly TColor Beige = ColorBuilder<TColor>.FromRGBA(245, 245, 220, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFE4C4.
/// </summary>
public static readonly TColor Bisque = ColorBuilder<TColor>.FromRGBA(255, 228, 196, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #000000.
/// </summary>
public static readonly TColor Black = ColorBuilder<TColor>.FromRGBA(0, 0, 0, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFEBCD.
/// </summary>
public static readonly TColor BlanchedAlmond = ColorBuilder<TColor>.FromRGBA(255, 235, 205, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #0000FF.
/// </summary>
public static readonly TColor Blue = ColorBuilder<TColor>.FromRGBA(0, 0, 255, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #8A2BE2.
/// </summary>
public static readonly TColor BlueViolet = ColorBuilder<TColor>.FromRGBA(138, 43, 226, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #A52A2A.
/// </summary>
public static readonly TColor Brown = ColorBuilder<TColor>.FromRGBA(165, 42, 42, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #DEB887.
/// </summary>
public static readonly TColor BurlyWood = ColorBuilder<TColor>.FromRGBA(222, 184, 135, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #5F9EA0.
/// </summary>
public static readonly TColor CadetBlue = ColorBuilder<TColor>.FromRGBA(95, 158, 160, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #7FFF00.
/// </summary>
public static readonly TColor Chartreuse = ColorBuilder<TColor>.FromRGBA(127, 255, 0, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #D2691E.
/// </summary>
public static readonly TColor Chocolate = ColorBuilder<TColor>.FromRGBA(210, 105, 30, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FF7F50.
/// </summary>
public static readonly TColor Coral = ColorBuilder<TColor>.FromRGBA(255, 127, 80, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #6495ED.
/// </summary>
public static readonly TColor CornflowerBlue = ColorBuilder<TColor>.FromRGBA(100, 149, 237, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFF8DC.
/// </summary>
public static readonly TColor Cornsilk = ColorBuilder<TColor>.FromRGBA(255, 248, 220, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #DC143C.
/// </summary>
public static readonly TColor Crimson = ColorBuilder<TColor>.FromRGBA(220, 20, 60, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #00FFFF.
/// </summary>
public static readonly TColor Cyan = ColorBuilder<TColor>.FromRGBA(0, 255, 255, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #00008B.
/// </summary>
public static readonly TColor DarkBlue = ColorBuilder<TColor>.FromRGBA(0, 0, 139, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #008B8B.
/// </summary>
public static readonly TColor DarkCyan = ColorBuilder<TColor>.FromRGBA(0, 139, 139, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #B8860B.
/// </summary>
public static readonly TColor DarkGoldenrod = ColorBuilder<TColor>.FromRGBA(184, 134, 11, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #A9A9A9.
/// </summary>
public static readonly TColor DarkGray = ColorBuilder<TColor>.FromRGBA(169, 169, 169, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #006400.
/// </summary>
public static readonly TColor DarkGreen = ColorBuilder<TColor>.FromRGBA(0, 100, 0, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #BDB76B.
/// </summary>
public static readonly TColor DarkKhaki = ColorBuilder<TColor>.FromRGBA(189, 183, 107, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #8B008B.
/// </summary>
public static readonly TColor DarkMagenta = ColorBuilder<TColor>.FromRGBA(139, 0, 139, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #556B2F.
/// </summary>
public static readonly TColor DarkOliveGreen = ColorBuilder<TColor>.FromRGBA(85, 107, 47, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FF8C00.
/// </summary>
public static readonly TColor DarkOrange = ColorBuilder<TColor>.FromRGBA(255, 140, 0, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #9932CC.
/// </summary>
public static readonly TColor DarkOrchid = ColorBuilder<TColor>.FromRGBA(153, 50, 204, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #8B0000.
/// </summary>
public static readonly TColor DarkRed = ColorBuilder<TColor>.FromRGBA(139, 0, 0, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #E9967A.
/// </summary>
public static readonly TColor DarkSalmon = ColorBuilder<TColor>.FromRGBA(233, 150, 122, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #8FBC8B.
/// </summary>
public static readonly TColor DarkSeaGreen = ColorBuilder<TColor>.FromRGBA(143, 188, 139, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #483D8B.
/// </summary>
public static readonly TColor DarkSlateBlue = ColorBuilder<TColor>.FromRGBA(72, 61, 139, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #2F4F4F.
/// </summary>
public static readonly TColor DarkSlateGray = ColorBuilder<TColor>.FromRGBA(47, 79, 79, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #00CED1.
/// </summary>
public static readonly TColor DarkTurquoise = ColorBuilder<TColor>.FromRGBA(0, 206, 209, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #9400D3.
/// </summary>
public static readonly TColor DarkViolet = ColorBuilder<TColor>.FromRGBA(148, 0, 211, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FF1493.
/// </summary>
public static readonly TColor DeepPink = ColorBuilder<TColor>.FromRGBA(255, 20, 147, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #00BFFF.
/// </summary>
public static readonly TColor DeepSkyBlue = ColorBuilder<TColor>.FromRGBA(0, 191, 255, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #696969.
/// </summary>
public static readonly TColor DimGray = ColorBuilder<TColor>.FromRGBA(105, 105, 105, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #1E90FF.
/// </summary>
public static readonly TColor DodgerBlue = ColorBuilder<TColor>.FromRGBA(30, 144, 255, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #B22222.
/// </summary>
public static readonly TColor Firebrick = ColorBuilder<TColor>.FromRGBA(178, 34, 34, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFFAF0.
/// </summary>
public static readonly TColor FloralWhite = ColorBuilder<TColor>.FromRGBA(255, 250, 240, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #228B22.
/// </summary>
public static readonly TColor ForestGreen = ColorBuilder<TColor>.FromRGBA(34, 139, 34, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FF00FF.
/// </summary>
public static readonly TColor Fuchsia = ColorBuilder<TColor>.FromRGBA(255, 0, 255, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #DCDCDC.
/// </summary>
public static readonly TColor Gainsboro = ColorBuilder<TColor>.FromRGBA(220, 220, 220, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #F8F8FF.
/// </summary>
public static readonly TColor GhostWhite = ColorBuilder<TColor>.FromRGBA(248, 248, 255, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFD700.
/// </summary>
public static readonly TColor Gold = ColorBuilder<TColor>.FromRGBA(255, 215, 0, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #DAA520.
/// </summary>
public static readonly TColor Goldenrod = ColorBuilder<TColor>.FromRGBA(218, 165, 32, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #808080.
/// </summary>
public static readonly TColor Gray = ColorBuilder<TColor>.FromRGBA(128, 128, 128, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #008000.
/// </summary>
public static readonly TColor Green = ColorBuilder<TColor>.FromRGBA(0, 128, 0, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #ADFF2F.
/// </summary>
public static readonly TColor GreenYellow = ColorBuilder<TColor>.FromRGBA(173, 255, 47, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #F0FFF0.
/// </summary>
public static readonly TColor Honeydew = ColorBuilder<TColor>.FromRGBA(240, 255, 240, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FF69B4.
/// </summary>
public static readonly TColor HotPink = ColorBuilder<TColor>.FromRGBA(255, 105, 180, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #CD5C5C.
/// </summary>
public static readonly TColor IndianRed = ColorBuilder<TColor>.FromRGBA(205, 92, 92, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #4B0082.
/// </summary>
public static readonly TColor Indigo = ColorBuilder<TColor>.FromRGBA(75, 0, 130, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFFFF0.
/// </summary>
public static readonly TColor Ivory = ColorBuilder<TColor>.FromRGBA(255, 255, 240, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #F0E68C.
/// </summary>
public static readonly TColor Khaki = ColorBuilder<TColor>.FromRGBA(240, 230, 140, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #E6E6FA.
/// </summary>
public static readonly TColor Lavender = ColorBuilder<TColor>.FromRGBA(230, 230, 250, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFF0F5.
/// </summary>
public static readonly TColor LavenderBlush = ColorBuilder<TColor>.FromRGBA(255, 240, 245, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #7CFC00.
/// </summary>
public static readonly TColor LawnGreen = ColorBuilder<TColor>.FromRGBA(124, 252, 0, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFFACD.
/// </summary>
public static readonly TColor LemonChiffon = ColorBuilder<TColor>.FromRGBA(255, 250, 205, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #ADD8E6.
/// </summary>
public static readonly TColor LightBlue = ColorBuilder<TColor>.FromRGBA(173, 216, 230, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #F08080.
/// </summary>
public static readonly TColor LightCoral = ColorBuilder<TColor>.FromRGBA(240, 128, 128, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #E0FFFF.
/// </summary>
public static readonly TColor LightCyan = ColorBuilder<TColor>.FromRGBA(224, 255, 255, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FAFAD2.
/// </summary>
public static readonly TColor LightGoldenrodYellow = ColorBuilder<TColor>.FromRGBA(250, 250, 210, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #D3D3D3.
/// </summary>
public static readonly TColor LightGray = ColorBuilder<TColor>.FromRGBA(211, 211, 211, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #90EE90.
/// </summary>
public static readonly TColor LightGreen = ColorBuilder<TColor>.FromRGBA(144, 238, 144, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFB6C1.
/// </summary>
public static readonly TColor LightPink = ColorBuilder<TColor>.FromRGBA(255, 182, 193, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFA07A.
/// </summary>
public static readonly TColor LightSalmon = ColorBuilder<TColor>.FromRGBA(255, 160, 122, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #20B2AA.
/// </summary>
public static readonly TColor LightSeaGreen = ColorBuilder<TColor>.FromRGBA(32, 178, 170, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #87CEFA.
/// </summary>
public static readonly TColor LightSkyBlue = ColorBuilder<TColor>.FromRGBA(135, 206, 250, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #778899.
/// </summary>
public static readonly TColor LightSlateGray = ColorBuilder<TColor>.FromRGBA(119, 136, 153, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #B0C4DE.
/// </summary>
public static readonly TColor LightSteelBlue = ColorBuilder<TColor>.FromRGBA(176, 196, 222, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFFFE0.
/// </summary>
public static readonly TColor LightYellow = ColorBuilder<TColor>.FromRGBA(255, 255, 224, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #00FF00.
/// </summary>
public static readonly TColor Lime = ColorBuilder<TColor>.FromRGBA(0, 255, 0, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #32CD32.
/// </summary>
public static readonly TColor LimeGreen = ColorBuilder<TColor>.FromRGBA(50, 205, 50, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FAF0E6.
/// </summary>
public static readonly TColor Linen = ColorBuilder<TColor>.FromRGBA(250, 240, 230, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FF00FF.
/// </summary>
public static readonly TColor Magenta = ColorBuilder<TColor>.FromRGBA(255, 0, 255, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #800000.
/// </summary>
public static readonly TColor Maroon = ColorBuilder<TColor>.FromRGBA(128, 0, 0, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #66CDAA.
/// </summary>
public static readonly TColor MediumAquamarine = ColorBuilder<TColor>.FromRGBA(102, 205, 170, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #0000CD.
/// </summary>
public static readonly TColor MediumBlue = ColorBuilder<TColor>.FromRGBA(0, 0, 205, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #BA55D3.
/// </summary>
public static readonly TColor MediumOrchid = ColorBuilder<TColor>.FromRGBA(186, 85, 211, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #9370DB.
/// </summary>
public static readonly TColor MediumPurple = ColorBuilder<TColor>.FromRGBA(147, 112, 219, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #3CB371.
/// </summary>
public static readonly TColor MediumSeaGreen = ColorBuilder<TColor>.FromRGBA(60, 179, 113, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #7B68EE.
/// </summary>
public static readonly TColor MediumSlateBlue = ColorBuilder<TColor>.FromRGBA(123, 104, 238, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #00FA9A.
/// </summary>
public static readonly TColor MediumSpringGreen = ColorBuilder<TColor>.FromRGBA(0, 250, 154, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #48D1CC.
/// </summary>
public static readonly TColor MediumTurquoise = ColorBuilder<TColor>.FromRGBA(72, 209, 204, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #C71585.
/// </summary>
public static readonly TColor MediumVioletRed = ColorBuilder<TColor>.FromRGBA(199, 21, 133, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #191970.
/// </summary>
public static readonly TColor MidnightBlue = ColorBuilder<TColor>.FromRGBA(25, 25, 112, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #F5FFFA.
/// </summary>
public static readonly TColor MintCream = ColorBuilder<TColor>.FromRGBA(245, 255, 250, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFE4E1.
/// </summary>
public static readonly TColor MistyRose = ColorBuilder<TColor>.FromRGBA(255, 228, 225, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFE4B5.
/// </summary>
public static readonly TColor Moccasin = ColorBuilder<TColor>.FromRGBA(255, 228, 181, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFDEAD.
/// </summary>
public static readonly TColor NavajoWhite = ColorBuilder<TColor>.FromRGBA(255, 222, 173, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #000080.
/// </summary>
public static readonly TColor Navy = ColorBuilder<TColor>.FromRGBA(0, 0, 128, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FDF5E6.
/// </summary>
public static readonly TColor OldLace = ColorBuilder<TColor>.FromRGBA(253, 245, 230, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #808000.
/// </summary>
public static readonly TColor Olive = ColorBuilder<TColor>.FromRGBA(128, 128, 0, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #6B8E23.
/// </summary>
public static readonly TColor OliveDrab = ColorBuilder<TColor>.FromRGBA(107, 142, 35, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFA500.
/// </summary>
public static readonly TColor Orange = ColorBuilder<TColor>.FromRGBA(255, 165, 0, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FF4500.
/// </summary>
public static readonly TColor OrangeRed = ColorBuilder<TColor>.FromRGBA(255, 69, 0, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #DA70D6.
/// </summary>
public static readonly TColor Orchid = ColorBuilder<TColor>.FromRGBA(218, 112, 214, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #EEE8AA.
/// </summary>
public static readonly TColor PaleGoldenrod = ColorBuilder<TColor>.FromRGBA(238, 232, 170, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #98FB98.
/// </summary>
public static readonly TColor PaleGreen = ColorBuilder<TColor>.FromRGBA(152, 251, 152, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #AFEEEE.
/// </summary>
public static readonly TColor PaleTurquoise = ColorBuilder<TColor>.FromRGBA(175, 238, 238, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #DB7093.
/// </summary>
public static readonly TColor PaleVioletRed = ColorBuilder<TColor>.FromRGBA(219, 112, 147, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFEFD5.
/// </summary>
public static readonly TColor PapayaWhip = ColorBuilder<TColor>.FromRGBA(255, 239, 213, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFDAB9.
/// </summary>
public static readonly TColor PeachPuff = ColorBuilder<TColor>.FromRGBA(255, 218, 185, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #CD853F.
/// </summary>
public static readonly TColor Peru = ColorBuilder<TColor>.FromRGBA(205, 133, 63, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFC0CB.
/// </summary>
public static readonly TColor Pink = ColorBuilder<TColor>.FromRGBA(255, 192, 203, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #DDA0DD.
/// </summary>
public static readonly TColor Plum = ColorBuilder<TColor>.FromRGBA(221, 160, 221, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #B0E0E6.
/// </summary>
public static readonly TColor PowderBlue = ColorBuilder<TColor>.FromRGBA(176, 224, 230, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #800080.
/// </summary>
public static readonly TColor Purple = ColorBuilder<TColor>.FromRGBA(128, 0, 128, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #663399.
/// </summary>
public static readonly TColor RebeccaPurple = ColorBuilder<TColor>.FromRGBA(102, 51, 153, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FF0000.
/// </summary>
public static readonly TColor Red = ColorBuilder<TColor>.FromRGBA(255, 0, 0, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #BC8F8F.
/// </summary>
public static readonly TColor RosyBrown = ColorBuilder<TColor>.FromRGBA(188, 143, 143, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #4169E1.
/// </summary>
public static readonly TColor RoyalBlue = ColorBuilder<TColor>.FromRGBA(65, 105, 225, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #8B4513.
/// </summary>
public static readonly TColor SaddleBrown = ColorBuilder<TColor>.FromRGBA(139, 69, 19, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FA8072.
/// </summary>
public static readonly TColor Salmon = ColorBuilder<TColor>.FromRGBA(250, 128, 114, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #F4A460.
/// </summary>
public static readonly TColor SandyBrown = ColorBuilder<TColor>.FromRGBA(244, 164, 96, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #2E8B57.
/// </summary>
public static readonly TColor SeaGreen = ColorBuilder<TColor>.FromRGBA(46, 139, 87, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFF5EE.
/// </summary>
public static readonly TColor SeaShell = ColorBuilder<TColor>.FromRGBA(255, 245, 238, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #A0522D.
/// </summary>
public static readonly TColor Sienna = ColorBuilder<TColor>.FromRGBA(160, 82, 45, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #C0C0C0.
/// </summary>
public static readonly TColor Silver = ColorBuilder<TColor>.FromRGBA(192, 192, 192, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #87CEEB.
/// </summary>
public static readonly TColor SkyBlue = ColorBuilder<TColor>.FromRGBA(135, 206, 235, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #6A5ACD.
/// </summary>
public static readonly TColor SlateBlue = ColorBuilder<TColor>.FromRGBA(106, 90, 205, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #708090.
/// </summary>
public static readonly TColor SlateGray = ColorBuilder<TColor>.FromRGBA(112, 128, 144, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFFAFA.
/// </summary>
public static readonly TColor Snow = ColorBuilder<TColor>.FromRGBA(255, 250, 250, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #00FF7F.
/// </summary>
public static readonly TColor SpringGreen = ColorBuilder<TColor>.FromRGBA(0, 255, 127, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #4682B4.
/// </summary>
public static readonly TColor SteelBlue = ColorBuilder<TColor>.FromRGBA(70, 130, 180, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #D2B48C.
/// </summary>
public static readonly TColor Tan = ColorBuilder<TColor>.FromRGBA(210, 180, 140, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #008080.
/// </summary>
public static readonly TColor Teal = ColorBuilder<TColor>.FromRGBA(0, 128, 128, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #D8BFD8.
/// </summary>
public static readonly TColor Thistle = ColorBuilder<TColor>.FromRGBA(216, 191, 216, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FF6347.
/// </summary>
public static readonly TColor Tomato = ColorBuilder<TColor>.FromRGBA(255, 99, 71, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFFFFF.
/// </summary>
public static readonly TColor Transparent = ColorBuilder<TColor>.FromRGBA(255, 255, 255, 0);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #40E0D0.
/// </summary>
public static readonly TColor Turquoise = ColorBuilder<TColor>.FromRGBA(64, 224, 208, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #EE82EE.
/// </summary>
public static readonly TColor Violet = ColorBuilder<TColor>.FromRGBA(238, 130, 238, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #F5DEB3.
/// </summary>
public static readonly TColor Wheat = ColorBuilder<TColor>.FromRGBA(245, 222, 179, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFFFFF.
/// </summary>
public static readonly TColor White = ColorBuilder<TColor>.FromRGBA(255, 255, 255, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #F5F5F5.
/// </summary>
public static readonly TColor WhiteSmoke = ColorBuilder<TColor>.FromRGBA(245, 245, 245, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #FFFF00.
/// </summary>
public static readonly TColor Yellow = ColorBuilder<TColor>.FromRGBA(255, 255, 0, 255);
/// <summary>
/// Represents a <see paramref="TColor"/> matching the W3C definition that has an hex value of #9ACD32.
/// </summary>
public static readonly TColor YellowGreen = ColorBuilder<TColor>.FromRGBA(154, 205, 50, 255);
}
}

6
src/ImageSharp/Colors/Spaces/IAlmostEquatable.cs

@ -11,9 +11,9 @@ namespace ImageSharp.Colors.Spaces
/// Defines a generalized method that a value type or class implements to create /// Defines a generalized method that a value type or class implements to create
/// a type-specific method for determining approximate equality of instances. /// a type-specific method for determining approximate equality of instances.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of objects to compare.</typeparam> /// <typeparam name="TPixel">The type of objects to compare.</typeparam>
/// <typeparam name="TPrecision">The object specifying the type to specify precision with.</typeparam> /// <typeparam name="TPrecision">The object specifying the type to specify precision with.</typeparam>
public interface IAlmostEquatable<in TColor, in TPrecision> public interface IAlmostEquatable<in TPixel, in TPrecision>
where TPrecision : struct, IComparable<TPrecision> where TPrecision : struct, IComparable<TPrecision>
{ {
/// <summary> /// <summary>
@ -25,6 +25,6 @@ namespace ImageSharp.Colors.Spaces
/// <returns> /// <returns>
/// true if the current object is equal to the other parameter; otherwise, false. /// true if the current object is equal to the other parameter; otherwise, false.
/// </returns> /// </returns>
bool AlmostEquals(TColor other, TPrecision precision); bool AlmostEquals(TPixel other, TPrecision precision);
} }
} }

3
src/ImageSharp/Common/Extensions/Vector4Extensions.cs

@ -8,6 +8,7 @@ namespace ImageSharp
using System; using System;
using System.Numerics; using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Vector4"/> struct. /// Extension methods for the <see cref="Vector4"/> struct.
@ -32,7 +33,7 @@ namespace ImageSharp
/// <see href="http://www.4p8.com/eric.brasseur/gamma.html#formulas"/> /// <see href="http://www.4p8.com/eric.brasseur/gamma.html#formulas"/>
/// <see href="http://entropymine.com/imageworsener/srgbformula/"/> /// <see href="http://entropymine.com/imageworsener/srgbformula/"/>
/// </summary> /// </summary>
/// <param name="gamma">The <see cref="Color"/> whose signal to expand.</param> /// <param name="gamma">The <see cref="Rgba32"/> whose signal to expand.</param>
/// <returns>The <see cref="Vector4"/>.</returns> /// <returns>The <see cref="Vector4"/>.</returns>
public static Vector4 Expand(this Vector4 gamma) public static Vector4 Expand(this Vector4 gamma)
{ {

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

@ -10,6 +10,8 @@ namespace ImageSharp
using System.Numerics; using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Provides common mathematical methods. /// Provides common mathematical methods.
/// </summary> /// </summary>
@ -100,25 +102,6 @@ namespace ImageSharp
return 0F; return 0F;
} }
/// <summary>
/// Gets the result of a sine cardinal function for the given value.
/// </summary>
/// <param name="x">The value to calculate the result for.</param>
/// <returns>
/// The <see cref="float"/>.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float SinC(float x)
{
if (MathF.Abs(x) > Constants.Epsilon)
{
x *= MathF.PI;
return Clean(MathF.Sin(x) / x);
}
return 1.0f;
}
/// <summary> /// <summary>
/// Gets the bounding <see cref="Rectangle"/> from the given points. /// Gets the bounding <see cref="Rectangle"/> from the given points.
/// </summary> /// </summary>
@ -162,22 +145,22 @@ namespace ImageSharp
/// Finds the bounding rectangle based on the first instance of any color component other /// Finds the bounding rectangle based on the first instance of any color component other
/// than the given one. /// than the given one.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <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"/> to search within.</param>
/// <param name="componentValue">The color component value to remove.</param> /// <param name="componentValue">The color component value to remove.</param>
/// <param name="channel">The <see cref="RgbaComponent"/> channel to test against.</param> /// <param name="channel">The <see cref="RgbaComponent"/> channel to test against.</param>
/// <returns> /// <returns>
/// The <see cref="Rectangle"/>. /// The <see cref="Rectangle"/>.
/// </returns> /// </returns>
public static Rectangle GetFilteredBoundingRectangle<TColor>(ImageBase<TColor> bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B) public static Rectangle GetFilteredBoundingRectangle<TPixel>(ImageBase<TPixel> bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
int width = bitmap.Width; int width = bitmap.Width;
int height = bitmap.Height; int height = bitmap.Height;
Point topLeft = default(Point); Point topLeft = default(Point);
Point bottomRight = default(Point); Point bottomRight = default(Point);
Func<PixelAccessor<TColor>, int, int, float, bool> delegateFunc; Func<PixelAccessor<TPixel>, int, int, float, bool> delegateFunc;
// Determine which channel to check against // Determine which channel to check against
switch (channel) switch (channel)
@ -199,7 +182,7 @@ namespace ImageSharp
break; break;
} }
Func<PixelAccessor<TColor>, int> getMinY = pixels => Func<PixelAccessor<TPixel>, int> getMinY = pixels =>
{ {
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
@ -215,7 +198,7 @@ namespace ImageSharp
return 0; return 0;
}; };
Func<PixelAccessor<TColor>, int> getMaxY = pixels => Func<PixelAccessor<TPixel>, int> getMaxY = pixels =>
{ {
for (int y = height - 1; y > -1; y--) for (int y = height - 1; y > -1; y--)
{ {
@ -231,7 +214,7 @@ namespace ImageSharp
return height; return height;
}; };
Func<PixelAccessor<TColor>, int> getMinX = pixels => Func<PixelAccessor<TPixel>, int> getMinX = pixels =>
{ {
for (int x = 0; x < width; x++) for (int x = 0; x < width; x++)
{ {
@ -247,7 +230,7 @@ namespace ImageSharp
return 0; return 0;
}; };
Func<PixelAccessor<TColor>, int> getMaxX = pixels => Func<PixelAccessor<TPixel>, int> getMaxX = pixels =>
{ {
for (int x = width - 1; x > -1; x--) for (int x = width - 1; x > -1; x--)
{ {
@ -263,7 +246,7 @@ namespace ImageSharp
return height; return height;
}; };
using (PixelAccessor<TColor> bitmapPixels = bitmap.Lock()) using (PixelAccessor<TPixel> bitmapPixels = bitmap.Lock())
{ {
topLeft.Y = getMinY(bitmapPixels); topLeft.Y = getMinY(bitmapPixels);
topLeft.X = getMinX(bitmapPixels); topLeft.X = getMinX(bitmapPixels);
@ -273,23 +256,5 @@ namespace ImageSharp
return GetBoundingRectangle(topLeft, bottomRight); return GetBoundingRectangle(topLeft, bottomRight);
} }
/// <summary>
/// Ensures that any passed double is correctly rounded to zero
/// </summary>
/// <param name="x">The value to clean.</param>
/// <returns>
/// The <see cref="float"/>
/// </returns>.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static float Clean(float x)
{
if (MathF.Abs(x) < Constants.Epsilon)
{
return 0F;
}
return x;
}
} }
} }

42
src/ImageSharp/Common/Helpers/MathF.cs

@ -189,7 +189,7 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Rounds a single-precision floating-point value to the nearest integral value. /// Rounds a single-precision floating-point value to the nearest integral value.
/// </summary> /// </summary>
/// <param name="f">A single-precision floating-point number to be rounded. </param> /// <param name="f">A single-precision floating-point number to be rounded.</param>
/// <returns> /// <returns>
/// The integer nearest <paramref name="f" />. /// The integer nearest <paramref name="f" />.
/// If the fractional component of <paramref name="f" /> is halfway between two integers, one of which is even and the other odd, then the even number is returned. /// If the fractional component of <paramref name="f" /> is halfway between two integers, one of which is even and the other odd, then the even number is returned.
@ -204,7 +204,7 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Returns the sine of the specified angle. /// Returns the sine of the specified angle.
/// </summary> /// </summary>
/// <param name="f">An angle, measured in radians. </param> /// <param name="f">An angle, measured in radians.</param>
/// <returns> /// <returns>
/// The sine of <paramref name="f" />. /// The sine of <paramref name="f" />.
/// If <paramref name="f" /> is equal to <see cref="F:System.Single.NaN" />, <see cref="F:System.Single.NegativeInfinity" />, /// If <paramref name="f" /> is equal to <see cref="F:System.Single.NaN" />, <see cref="F:System.Single.NegativeInfinity" />,
@ -216,6 +216,26 @@ namespace ImageSharp
return (float)Math.Sin(f); return (float)Math.Sin(f);
} }
/// <summary>
/// Returns the result of a normalized sine cardinal function for the given value.
/// SinC(x) = sin(pi*x)/(pi*x).
/// </summary>
/// <param name="f">A single-precision floating-point number to calculate the result for.</param>
/// <returns>
/// The sine cardinal of <paramref name="f" />.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float SinC(float f)
{
if (Abs(f) > Constants.Epsilon)
{
f *= PI;
return Clean(Sin(f) / f);
}
return 1F;
}
/// <summary> /// <summary>
/// Returns the square root of a specified number. /// Returns the square root of a specified number.
/// </summary> /// </summary>
@ -232,5 +252,23 @@ namespace ImageSharp
{ {
return (float)Math.Sqrt(f); return (float)Math.Sqrt(f);
} }
/// <summary>
/// Ensures that any passed float is correctly rounded to zero
/// </summary>
/// <param name="x">The value to clean.</param>
/// <returns>
/// The <see cref="float"/>
/// </returns>.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static float Clean(float x)
{
if (Abs(x) < Constants.Epsilon)
{
return 0F;
}
return x;
}
} }
} }

4
src/ImageSharp/Common/Memory/PixelDataPool{T}.cs

@ -8,6 +8,8 @@ namespace ImageSharp
using System; using System;
using System.Buffers; using System.Buffers;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Provides a resource pool that enables reusing instances of value type arrays for image data <see cref="T:T[]"/>. /// Provides a resource pool that enables reusing instances of value type arrays for image data <see cref="T:T[]"/>.
/// </summary> /// </summary>
@ -24,7 +26,7 @@ namespace ImageSharp
/// Rents the pixel array from the pool. /// Rents the pixel array from the pool.
/// </summary> /// </summary>
/// <param name="minimumLength">The minimum length of the array to return.</param> /// <param name="minimumLength">The minimum length of the array to return.</param>
/// <returns>The <see cref="T:TColor[]"/></returns> /// <returns>The <see cref="T:TPixel[]"/></returns>
public static T[] Rent(int minimumLength) public static T[] Rent(int minimumLength)
{ {
return ArrayPool.Rent(minimumLength); return ArrayPool.Rent(minimumLength);

12
src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuser.cs

@ -8,6 +8,8 @@ namespace ImageSharp.Dithering
using System.Numerics; using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// The base class for performing error diffusion based dithering. /// The base class for performing error diffusion based dithering.
/// </summary> /// </summary>
@ -68,16 +70,16 @@ namespace ImageSharp.Dithering
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Dither<TColor>(PixelAccessor<TColor> pixels, TColor source, TColor transformed, int x, int y, int width, int height) public void Dither<TPixel>(PixelAccessor<TPixel> pixels, TPixel source, TPixel transformed, int x, int y, int width, int height)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
this.Dither(pixels, source, transformed, x, y, width, height, true); this.Dither(pixels, source, transformed, x, y, width, height, true);
} }
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Dither<TColor>(PixelAccessor<TColor> pixels, TColor source, TColor transformed, int x, int y, int width, int height, bool replacePixel) public void Dither<TPixel>(PixelAccessor<TPixel> pixels, TPixel source, TPixel transformed, int x, int y, int width, int height, bool replacePixel)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
if (replacePixel) if (replacePixel)
{ {
@ -113,7 +115,7 @@ namespace ImageSharp.Dithering
Vector4 result = ((error * coefficientVector) / this.divisorVector) + offsetColor; Vector4 result = ((error * coefficientVector) / this.divisorVector) + offsetColor;
result.W = offsetColor.W; result.W = offsetColor.W;
TColor packed = default(TColor); TPixel packed = default(TPixel);
packed.PackFromVector4(result); packed.PackFromVector4(result);
pixels[matrixX, matrixY] = packed; pixels[matrixX, matrixY] = packed;
} }

14
src/ImageSharp/Dithering/ErrorDiffusion/IErrorDiffuser.cs

@ -5,7 +5,7 @@
namespace ImageSharp.Dithering namespace ImageSharp.Dithering
{ {
using System; using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Encapsulates properties and methods required to perfom diffused error dithering on an image. /// Encapsulates properties and methods required to perfom diffused error dithering on an image.
@ -22,9 +22,9 @@ namespace ImageSharp.Dithering
/// <param name="y">The row index.</param> /// <param name="y">The row index.</param>
/// <param name="width">The image width.</param> /// <param name="width">The image width.</param>
/// <param name="height">The image height.</param> /// <param name="height">The image height.</param>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
void Dither<TColor>(PixelAccessor<TColor> pixels, TColor source, TColor transformed, int x, int y, int width, int height) void Dither<TPixel>(PixelAccessor<TPixel> pixels, TPixel source, TPixel transformed, int x, int y, int width, int height)
where TColor : struct, IPixel<TColor>; where TPixel : struct, IPixel<TPixel>;
/// <summary> /// <summary>
/// Transforms the image applying the dither matrix. This method alters the input pixels array /// Transforms the image applying the dither matrix. This method alters the input pixels array
@ -40,8 +40,8 @@ namespace ImageSharp.Dithering
/// Whether to replace the pixel at the given coordinates with the transformed value. /// Whether to replace the pixel at the given coordinates with the transformed value.
/// Generally this would be true for standard two-color dithering but when used in conjunction with color quantization this should be false. /// Generally this would be true for standard two-color dithering but when used in conjunction with color quantization this should be false.
/// </param> /// </param>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
void Dither<TColor>(PixelAccessor<TColor> pixels, TColor source, TColor transformed, int x, int y, int width, int height, bool replacePixel) void Dither<TPixel>(PixelAccessor<TPixel> pixels, TPixel source, TPixel transformed, int x, int y, int width, int height, bool replacePixel)
where TColor : struct, IPixel<TColor>; where TPixel : struct, IPixel<TPixel>;
} }
} }

8
src/ImageSharp/Dithering/Ordered/IOrderedDither.cs

@ -5,6 +5,8 @@
namespace ImageSharp.Dithering namespace ImageSharp.Dithering
{ {
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Encapsulates properties and methods required to perfom ordered dithering on an image. /// Encapsulates properties and methods required to perfom ordered dithering on an image.
/// </summary> /// </summary>
@ -23,8 +25,8 @@ namespace ImageSharp.Dithering
/// <param name="y">The row index.</param> /// <param name="y">The row index.</param>
/// <param name="width">The image width.</param> /// <param name="width">The image width.</param>
/// <param name="height">The image height.</param> /// <param name="height">The image height.</param>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
void Dither<TColor>(PixelAccessor<TColor> pixels, TColor source, TColor upper, TColor lower, byte[] bytes, int index, int x, int y, int width, int height) void Dither<TPixel>(PixelAccessor<TPixel> pixels, TPixel source, TPixel upper, TPixel lower, byte[] bytes, int index, int x, int y, int width, int height)
where TColor : struct, IPixel<TColor>; where TPixel : struct, IPixel<TPixel>;
} }
} }

6
src/ImageSharp/Dithering/Ordered/OrderedDither4x4.cs

@ -5,6 +5,8 @@
namespace ImageSharp.Dithering.Ordered namespace ImageSharp.Dithering.Ordered
{ {
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// The base class for performing ordered ditheroing using a 4x4 matrix. /// The base class for performing ordered ditheroing using a 4x4 matrix.
/// </summary> /// </summary>
@ -25,8 +27,8 @@ namespace ImageSharp.Dithering.Ordered
} }
/// <inheritdoc /> /// <inheritdoc />
public void Dither<TColor>(PixelAccessor<TColor> pixels, TColor source, TColor upper, TColor lower, byte[] bytes, int index, int x, int y, int width, int height) public void Dither<TPixel>(PixelAccessor<TPixel> pixels, TPixel source, TPixel upper, TPixel lower, byte[] bytes, int index, int x, int y, int width, int height)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
// TODO: This doesn't really cut it for me. // TODO: This doesn't really cut it for me.
// I'd rather be using float but we need to add some sort of movalization vector methods to all IPixel implementations // I'd rather be using float but we need to add some sort of movalization vector methods to all IPixel implementations

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

@ -8,6 +8,8 @@ namespace ImageSharp.Formats
using System; using System;
using System.IO; using System.IO;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Image decoder for generating an image out of a Windows bitmap stream. /// Image decoder for generating an image out of a Windows bitmap stream.
/// </summary> /// </summary>
@ -26,13 +28,13 @@ namespace ImageSharp.Formats
public class BmpDecoder : IImageDecoder public class BmpDecoder : IImageDecoder
{ {
/// <inheritdoc/> /// <inheritdoc/>
public Image<TColor> Decode<TColor>(Configuration configuration, Stream stream, IDecoderOptions options) public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream, IDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
Guard.NotNull(stream, "stream"); Guard.NotNull(stream, "stream");
return new BmpDecoderCore(configuration).Decode<TColor>(stream); return new BmpDecoderCore(configuration).Decode<TPixel>(stream);
} }
} }
} }

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

@ -7,6 +7,8 @@ namespace ImageSharp.Formats
using System; using System;
using System.IO; using System.IO;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Performs the bmp decoding operation. /// Performs the bmp decoding operation.
/// </summary> /// </summary>
@ -58,15 +60,15 @@ namespace ImageSharp.Formats
/// Decodes the image from the specified this._stream and sets /// Decodes the image from the specified this._stream and sets
/// the data to image. /// the data to image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="stream">The stream, where the image should be /// <param name="stream">The stream, where the image should be
/// decoded from. Cannot be null (Nothing in Visual Basic).</param> /// decoded from. Cannot be null (Nothing in Visual Basic).</param>
/// <exception cref="System.ArgumentNullException"> /// <exception cref="System.ArgumentNullException">
/// <para><paramref name="stream"/> is null.</para> /// <para><paramref name="stream"/> is null.</para>
/// </exception> /// </exception>
/// <returns>The decoded image.</returns> /// <returns>The decoded image.</returns>
public Image<TColor> Decode<TColor>(Stream stream) public Image<TPixel> Decode<TPixel>(Stream stream)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
this.currentStream = stream; this.currentStream = stream;
@ -118,15 +120,15 @@ namespace ImageSharp.Formats
this.currentStream.Read(palette, 0, colorMapSize); this.currentStream.Read(palette, 0, colorMapSize);
} }
if (this.infoHeader.Width > Image<TColor>.MaxWidth || this.infoHeader.Height > Image<TColor>.MaxHeight) if (this.infoHeader.Width > Image<TPixel>.MaxWidth || this.infoHeader.Height > Image<TPixel>.MaxHeight)
{ {
throw new ArgumentOutOfRangeException( throw new ArgumentOutOfRangeException(
$"The input bitmap '{this.infoHeader.Width}x{this.infoHeader.Height}' is " $"The input bitmap '{this.infoHeader.Width}x{this.infoHeader.Height}' is "
+ $"bigger then the max allowed size '{Image<TColor>.MaxWidth}x{Image<TColor>.MaxHeight}'"); + $"bigger then the max allowed size '{Image<TPixel>.MaxWidth}x{Image<TPixel>.MaxHeight}'");
} }
Image<TColor> image = Image.Create<TColor>(this.infoHeader.Width, this.infoHeader.Height, this.configuration); Image<TPixel> image = Image.Create<TPixel>(this.infoHeader.Width, this.infoHeader.Height, this.configuration);
using (PixelAccessor<TColor> pixels = image.Lock()) using (PixelAccessor<TPixel> pixels = image.Lock())
{ {
switch (this.infoHeader.Compression) switch (this.infoHeader.Compression)
{ {
@ -213,15 +215,15 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Reads the color palette from the stream. /// Reads the color palette from the stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="pixels">The <see cref="PixelAccessor{TColor}"/> to assign the palette to.</param> /// <param name="pixels">The <see cref="PixelAccessor{TPixel}"/> to assign the palette to.</param>
/// <param name="colors">The <see cref="T:byte[]"/> containing the colors.</param> /// <param name="colors">The <see cref="T:byte[]"/> containing the colors.</param>
/// <param name="width">The width of the bitmap.</param> /// <param name="width">The width of the bitmap.</param>
/// <param name="height">The height of the bitmap.</param> /// <param name="height">The height of the bitmap.</param>
/// <param name="bits">The number of bits per pixel.</param> /// <param name="bits">The number of bits per pixel.</param>
/// <param name="inverted">Whether the bitmap is inverted.</param> /// <param name="inverted">Whether the bitmap is inverted.</param>
private void ReadRgbPalette<TColor>(PixelAccessor<TColor> pixels, byte[] colors, int width, int height, int bits, bool inverted) private void ReadRgbPalette<TPixel>(PixelAccessor<TPixel> pixels, byte[] colors, int width, int height, int bits, bool inverted)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
// Pixels per byte (bits per pixel) // Pixels per byte (bits per pixel)
int ppb = 8 / bits; int ppb = 8 / bits;
@ -239,7 +241,7 @@ namespace ImageSharp.Formats
} }
byte[] row = new byte[arrayWidth + padding]; byte[] row = new byte[arrayWidth + padding];
TColor color = default(TColor); TPixel color = default(TPixel);
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
@ -270,21 +272,21 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Reads the 16 bit color palette from the stream /// Reads the 16 bit color palette from the stream
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="pixels">The <see cref="PixelAccessor{TColor}"/> to assign the palette to.</param> /// <param name="pixels">The <see cref="PixelAccessor{TPixel}"/> to assign the palette to.</param>
/// <param name="width">The width of the bitmap.</param> /// <param name="width">The width of the bitmap.</param>
/// <param name="height">The height of the bitmap.</param> /// <param name="height">The height of the bitmap.</param>
/// <param name="inverted">Whether the bitmap is inverted.</param> /// <param name="inverted">Whether the bitmap is inverted.</param>
private void ReadRgb16<TColor>(PixelAccessor<TColor> pixels, int width, int height, bool inverted) private void ReadRgb16<TPixel>(PixelAccessor<TPixel> pixels, int width, int height, bool inverted)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
// We divide here as we will store the colors in our floating point format. // We divide here as we will store the colors in our floating point format.
const int ScaleR = 8; // 256/32 const int ScaleR = 8; // 256/32
const int ScaleG = 4; // 256/64 const int ScaleG = 4; // 256/64
const int ComponentCount = 2; const int ComponentCount = 2;
TColor color = default(TColor); TPixel color = default(TPixel);
using (PixelArea<TColor> row = new PixelArea<TColor>(width, ComponentOrder.Xyz)) using (PixelArea<TPixel> row = new PixelArea<TPixel>(width, ComponentOrder.Xyz))
{ {
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
@ -312,16 +314,16 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Reads the 24 bit color palette from the stream /// Reads the 24 bit color palette from the stream
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="pixels">The <see cref="PixelAccessor{TColor}"/> to assign the palette to.</param> /// <param name="pixels">The <see cref="PixelAccessor{TPixel}"/> to assign the palette to.</param>
/// <param name="width">The width of the bitmap.</param> /// <param name="width">The width of the bitmap.</param>
/// <param name="height">The height of the bitmap.</param> /// <param name="height">The height of the bitmap.</param>
/// <param name="inverted">Whether the bitmap is inverted.</param> /// <param name="inverted">Whether the bitmap is inverted.</param>
private void ReadRgb24<TColor>(PixelAccessor<TColor> pixels, int width, int height, bool inverted) private void ReadRgb24<TPixel>(PixelAccessor<TPixel> pixels, int width, int height, bool inverted)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
int padding = CalculatePadding(width, 3); int padding = CalculatePadding(width, 3);
using (PixelArea<TColor> row = new PixelArea<TColor>(width, ComponentOrder.Zyx, padding)) using (PixelArea<TPixel> row = new PixelArea<TPixel>(width, ComponentOrder.Zyx, padding))
{ {
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
@ -336,16 +338,16 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Reads the 32 bit color palette from the stream /// Reads the 32 bit color palette from the stream
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="pixels">The <see cref="PixelAccessor{TColor}"/> to assign the palette to.</param> /// <param name="pixels">The <see cref="PixelAccessor{TPixel}"/> to assign the palette to.</param>
/// <param name="width">The width of the bitmap.</param> /// <param name="width">The width of the bitmap.</param>
/// <param name="height">The height of the bitmap.</param> /// <param name="height">The height of the bitmap.</param>
/// <param name="inverted">Whether the bitmap is inverted.</param> /// <param name="inverted">Whether the bitmap is inverted.</param>
private void ReadRgb32<TColor>(PixelAccessor<TColor> pixels, int width, int height, bool inverted) private void ReadRgb32<TPixel>(PixelAccessor<TPixel> pixels, int width, int height, bool inverted)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
int padding = CalculatePadding(width, 4); int padding = CalculatePadding(width, 4);
using (PixelArea<TColor> row = new PixelArea<TColor>(width, ComponentOrder.Zyxw, padding)) using (PixelArea<TPixel> row = new PixelArea<TPixel>(width, ComponentOrder.Zyxw, padding))
{ {
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {

16
src/ImageSharp/Formats/Bmp/BmpEncoder.cs

@ -8,6 +8,8 @@ namespace ImageSharp.Formats
using System; using System;
using System.IO; using System.IO;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Image encoder for writing an image to a stream as a Windows bitmap. /// Image encoder for writing an image to a stream as a Windows bitmap.
/// </summary> /// </summary>
@ -15,8 +17,8 @@ namespace ImageSharp.Formats
public class BmpEncoder : IImageEncoder public class BmpEncoder : IImageEncoder
{ {
/// <inheritdoc/> /// <inheritdoc/>
public void Encode<TColor>(Image<TColor> image, Stream stream, IEncoderOptions options) public void Encode<TPixel>(Image<TPixel> image, Stream stream, IEncoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
IBmpEncoderOptions bmpOptions = BmpEncoderOptions.Create(options); IBmpEncoderOptions bmpOptions = BmpEncoderOptions.Create(options);
@ -24,14 +26,14 @@ namespace ImageSharp.Formats
} }
/// <summary> /// <summary>
/// Encodes the image to the specified stream from the <see cref="Image{TColor}"/>. /// Encodes the image to the specified stream from the <see cref="Image{TPixel}"/>.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="Image{TColor}"/> to encode from.</param> /// <param name="image">The <see cref="Image{TPixel}"/> to encode from.</param>
/// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param> /// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param>
/// <param name="options">The options for the encoder.</param> /// <param name="options">The options for the encoder.</param>
public void Encode<TColor>(Image<TColor> image, Stream stream, IBmpEncoderOptions options) public void Encode<TPixel>(Image<TPixel> image, Stream stream, IBmpEncoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
BmpEncoderCore encoder = new BmpEncoderCore(options); BmpEncoderCore encoder = new BmpEncoderCore(options);
encoder.Encode(image, stream); encoder.Encode(image, stream);

42
src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs

@ -8,6 +8,8 @@ namespace ImageSharp.Formats
using System; using System;
using System.IO; using System.IO;
using ImageSharp.PixelFormats;
using IO; using IO;
/// <summary> /// <summary>
@ -35,13 +37,13 @@ namespace ImageSharp.Formats
} }
/// <summary> /// <summary>
/// Encodes the image to the specified stream from the <see cref="ImageBase{TColor}"/>. /// Encodes the image to the specified stream from the <see cref="ImageBase{TPixel}"/>.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="ImageBase{TColor}"/> to encode from.</param> /// <param name="image">The <see cref="ImageBase{TPixel}"/> to encode from.</param>
/// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param> /// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param>
public void Encode<TColor>(ImageBase<TColor> image, Stream stream) public void Encode<TPixel>(ImageBase<TPixel> image, Stream stream)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
Guard.NotNull(image, nameof(image)); Guard.NotNull(image, nameof(image));
Guard.NotNull(stream, nameof(stream)); Guard.NotNull(stream, nameof(stream));
@ -124,15 +126,15 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Writes the pixel data to the binary stream. /// Writes the pixel data to the binary stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="writer">The <see cref="EndianBinaryWriter"/> containing the stream to write to.</param> /// <param name="writer">The <see cref="EndianBinaryWriter"/> containing the stream to write to.</param>
/// <param name="image"> /// <param name="image">
/// The <see cref="ImageBase{TColor}"/> containing pixel data. /// The <see cref="ImageBase{TPixel}"/> containing pixel data.
/// </param> /// </param>
private void WriteImage<TColor>(EndianBinaryWriter writer, ImageBase<TColor> image) private void WriteImage<TPixel>(EndianBinaryWriter writer, ImageBase<TPixel> image)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
using (PixelAccessor<TColor> pixels = image.Lock()) using (PixelAccessor<TPixel> pixels = image.Lock())
{ {
switch (this.options.BitsPerPixel) switch (this.options.BitsPerPixel)
{ {
@ -150,13 +152,13 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Writes the 32bit color palette to the stream. /// Writes the 32bit color palette to the stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="writer">The <see cref="EndianBinaryWriter"/> containing the stream to write to.</param> /// <param name="writer">The <see cref="EndianBinaryWriter"/> containing the stream to write to.</param>
/// <param name="pixels">The <see cref="PixelAccessor{TColor}"/> containing pixel data.</param> /// <param name="pixels">The <see cref="PixelAccessor{TPixel}"/> containing pixel data.</param>
private void Write32Bit<TColor>(EndianBinaryWriter writer, PixelAccessor<TColor> pixels) private void Write32Bit<TPixel>(EndianBinaryWriter writer, PixelAccessor<TPixel> pixels)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
using (PixelArea<TColor> row = new PixelArea<TColor>(pixels.Width, ComponentOrder.Zyxw, this.padding)) using (PixelArea<TPixel> row = new PixelArea<TPixel>(pixels.Width, ComponentOrder.Zyxw, this.padding))
{ {
for (int y = pixels.Height - 1; y >= 0; y--) for (int y = pixels.Height - 1; y >= 0; y--)
{ {
@ -169,13 +171,13 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Writes the 24bit color palette to the stream. /// Writes the 24bit color palette to the stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="writer">The <see cref="EndianBinaryWriter"/> containing the stream to write to.</param> /// <param name="writer">The <see cref="EndianBinaryWriter"/> containing the stream to write to.</param>
/// <param name="pixels">The <see cref="PixelAccessor{TColor}"/> containing pixel data.</param> /// <param name="pixels">The <see cref="PixelAccessor{TPixel}"/> containing pixel data.</param>
private void Write24Bit<TColor>(EndianBinaryWriter writer, PixelAccessor<TColor> pixels) private void Write24Bit<TPixel>(EndianBinaryWriter writer, PixelAccessor<TPixel> pixels)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
using (PixelArea<TColor> row = new PixelArea<TColor>(pixels.Width, ComponentOrder.Zyx, this.padding)) using (PixelArea<TPixel> row = new PixelArea<TPixel>(pixels.Width, ComponentOrder.Zyx, this.padding))
{ {
for (int y = pixels.Height - 1; y >= 0; y--) for (int y = pixels.Height - 1; y >= 0; y--)
{ {

12
src/ImageSharp/Formats/Bmp/ImageExtensions.cs

@ -10,23 +10,25 @@ namespace ImageSharp
using Formats; using Formats;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Saves the image to the given stream with the bmp format. /// Saves the image to the given stream with the bmp format.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="stream">The stream to save the image to.</param> /// <param name="stream">The stream to save the image to.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns> /// <returns>
/// The <see cref="Image{TColoR}"/>. /// The <see cref="Image{TPixel}"/>.
/// </returns> /// </returns>
public static Image<TColor> SaveAsBmp<TColor>(this Image<TColor> source, Stream stream) public static Image<TPixel> SaveAsBmp<TPixel>(this Image<TPixel> source, Stream stream)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
=> source.Save(stream, new BmpEncoder()); => source.Save(stream, new BmpEncoder());
} }
} }

18
src/ImageSharp/Formats/Gif/GifDecoder.cs

@ -8,33 +8,35 @@ namespace ImageSharp.Formats
using System; using System;
using System.IO; using System.IO;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Decoder for generating an image out of a gif encoded stream. /// Decoder for generating an image out of a gif encoded stream.
/// </summary> /// </summary>
public class GifDecoder : IImageDecoder public class GifDecoder : IImageDecoder
{ {
/// <inheritdoc/> /// <inheritdoc/>
public Image<TColor> Decode<TColor>(Configuration configuration, Stream stream, IDecoderOptions options) public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream, IDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
IGifDecoderOptions gifOptions = GifDecoderOptions.Create(options); IGifDecoderOptions gifOptions = GifDecoderOptions.Create(options);
return this.Decode<TColor>(configuration, stream, gifOptions); return this.Decode<TPixel>(configuration, stream, gifOptions);
} }
/// <summary> /// <summary>
/// Decodes the image from the specified stream to the <see cref="ImageBase{TColor}"/>. /// Decodes the image from the specified stream to the <see cref="ImageBase{TPixel}"/>.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="configuration">The configuration.</param> /// <param name="configuration">The configuration.</param>
/// <param name="stream">The <see cref="Stream"/> containing image data.</param> /// <param name="stream">The <see cref="Stream"/> containing image data.</param>
/// <param name="options">The options for the decoder.</param> /// <param name="options">The options for the decoder.</param>
/// <returns>The image thats been decoded.</returns> /// <returns>The image thats been decoded.</returns>
public Image<TColor> Decode<TColor>(Configuration configuration, Stream stream, IGifDecoderOptions options) public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream, IGifDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return new GifDecoderCore<TColor>(options, configuration).Decode(stream); return new GifDecoderCore<TPixel>(options, configuration).Decode(stream);
} }
} }
} }

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

@ -10,12 +10,14 @@ namespace ImageSharp.Formats
using System.IO; using System.IO;
using System.Text; using System.Text;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Performs the gif decoding operation. /// Performs the gif decoding operation.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
internal class GifDecoderCore<TColor> internal class GifDecoderCore<TPixel>
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// The temp buffer used to reduce allocations. /// The temp buffer used to reduce allocations.
@ -50,7 +52,7 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// The previous frame. /// The previous frame.
/// </summary> /// </summary>
private ImageFrame<TColor> previousFrame; private ImageFrame<TPixel> previousFrame;
/// <summary> /// <summary>
/// The area to restore. /// The area to restore.
@ -75,10 +77,10 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// The image to decode the information to. /// The image to decode the information to.
/// </summary> /// </summary>
private Image<TColor> image; private Image<TPixel> image;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="GifDecoderCore{TColor}"/> class. /// Initializes a new instance of the <see cref="GifDecoderCore{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="options">The decoder options.</param> /// <param name="options">The decoder options.</param>
/// <param name="configuration">The configuration.</param> /// <param name="configuration">The configuration.</param>
@ -93,7 +95,7 @@ namespace ImageSharp.Formats
/// </summary> /// </summary>
/// <param name="stream">The stream containing image data. </param> /// <param name="stream">The stream containing image data. </param>
/// <returns>The decoded image</returns> /// <returns>The decoded image</returns>
public Image<TColor> Decode(Stream stream) public Image<TPixel> Decode(Stream stream)
{ {
try try
{ {
@ -227,10 +229,10 @@ namespace ImageSharp.Formats
} }
/* // No point doing this as the max width/height is always int.Max and that always bigger than the max size of a gif which is stored in a short. /* // No point doing this as the max width/height is always int.Max and that always bigger than the max size of a gif which is stored in a short.
if (this.logicalScreenDescriptor.Width > Image<TColor>.MaxWidth || this.logicalScreenDescriptor.Height > Image<TColor>.MaxHeight) if (this.logicalScreenDescriptor.Width > Image<TPixel>.MaxWidth || this.logicalScreenDescriptor.Height > Image<TPixel>.MaxHeight)
{ {
throw new ArgumentOutOfRangeException( throw new ArgumentOutOfRangeException(
$"The input gif '{this.logicalScreenDescriptor.Width}x{this.logicalScreenDescriptor.Height}' is bigger then the max allowed size '{Image<TColor>.MaxWidth}x{Image<TColor>.MaxHeight}'"); $"The input gif '{this.logicalScreenDescriptor.Width}x{this.logicalScreenDescriptor.Height}' is bigger then the max allowed size '{Image<TPixel>.MaxWidth}x{Image<TPixel>.MaxHeight}'");
} }
*/ */
} }
@ -351,18 +353,18 @@ namespace ImageSharp.Formats
int imageWidth = this.logicalScreenDescriptor.Width; int imageWidth = this.logicalScreenDescriptor.Width;
int imageHeight = this.logicalScreenDescriptor.Height; int imageHeight = this.logicalScreenDescriptor.Height;
ImageFrame<TColor> previousFrame = null; ImageFrame<TPixel> previousFrame = null;
ImageFrame<TColor> currentFrame = null; ImageFrame<TPixel> currentFrame = null;
ImageBase<TColor> image; ImageBase<TPixel> image;
if (this.previousFrame == null) if (this.previousFrame == null)
{ {
this.metaData.Quality = colorTableLength / 3; this.metaData.Quality = colorTableLength / 3;
// This initializes the image to become fully transparent because the alpha channel is zero. // This initializes the image to become fully transparent because the alpha channel is zero.
this.image = Image.Create<TColor>(imageWidth, imageHeight, this.metaData, this.configuration); this.image = Image.Create<TPixel>(imageWidth, imageHeight, this.metaData, this.configuration);
this.SetFrameDelay(this.metaData); this.SetFrameDelay(this.metaData);
@ -392,7 +394,7 @@ namespace ImageSharp.Formats
int interlaceIncrement = 8; // The interlacing line increment int interlaceIncrement = 8; // The interlacing line increment
int interlaceY = 0; // The current interlaced line int interlaceY = 0; // The current interlaced line
using (PixelAccessor<TColor> pixelAccessor = image.Lock()) using (PixelAccessor<TPixel> pixelAccessor = image.Lock())
{ {
for (int y = descriptor.Top; y < descriptor.Top + descriptor.Height; y++) for (int y = descriptor.Top; y < descriptor.Top + descriptor.Height; y++)
{ {
@ -441,7 +443,7 @@ namespace ImageSharp.Formats
{ {
int indexOffset = index * 3; int indexOffset = index * 3;
TColor pixel = default(TColor); TPixel pixel = default(TPixel);
pixel.PackFromBytes(colorTable[indexOffset], colorTable[indexOffset + 1], colorTable[indexOffset + 2], 255); pixel.PackFromBytes(colorTable[indexOffset], colorTable[indexOffset + 1], colorTable[indexOffset + 2], 255);
pixelAccessor[x, writeY] = pixel; pixelAccessor[x, writeY] = pixel;
} }
@ -470,7 +472,7 @@ namespace ImageSharp.Formats
/// Restores the current frame area to the background. /// Restores the current frame area to the background.
/// </summary> /// </summary>
/// <param name="frame">The frame.</param> /// <param name="frame">The frame.</param>
private void RestoreToBackground(ImageBase<TColor> frame) private void RestoreToBackground(ImageBase<TPixel> frame)
{ {
if (this.restoreArea == null) if (this.restoreArea == null)
{ {
@ -481,16 +483,16 @@ namespace ImageSharp.Formats
if (this.restoreArea.Value.Width == this.image.Width && if (this.restoreArea.Value.Width == this.image.Width &&
this.restoreArea.Value.Height == this.image.Height) this.restoreArea.Value.Height == this.image.Height)
{ {
using (PixelAccessor<TColor> pixelAccessor = frame.Lock()) using (PixelAccessor<TPixel> pixelAccessor = frame.Lock())
{ {
pixelAccessor.Reset(); pixelAccessor.Reset();
} }
} }
else else
{ {
using (PixelArea<TColor> emptyRow = new PixelArea<TColor>(this.restoreArea.Value.Width, ComponentOrder.Xyzw)) using (PixelArea<TPixel> emptyRow = new PixelArea<TPixel>(this.restoreArea.Value.Width, ComponentOrder.Xyzw))
{ {
using (PixelAccessor<TColor> pixelAccessor = frame.Lock()) using (PixelAccessor<TPixel> pixelAccessor = frame.Lock())
{ {
for (int y = this.restoreArea.Value.Top; y < this.restoreArea.Value.Top + this.restoreArea.Value.Height; y++) for (int y = this.restoreArea.Value.Top; y < this.restoreArea.Value.Top + this.restoreArea.Value.Height; y++)
{ {

16
src/ImageSharp/Formats/Gif/GifEncoder.cs

@ -8,14 +8,16 @@ namespace ImageSharp.Formats
using System; using System;
using System.IO; using System.IO;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Image encoder for writing image data to a stream in gif format. /// Image encoder for writing image data to a stream in gif format.
/// </summary> /// </summary>
public class GifEncoder : IImageEncoder public class GifEncoder : IImageEncoder
{ {
/// <inheritdoc/> /// <inheritdoc/>
public void Encode<TColor>(Image<TColor> image, Stream stream, IEncoderOptions options) public void Encode<TPixel>(Image<TPixel> image, Stream stream, IEncoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
IGifEncoderOptions gifOptions = GifEncoderOptions.Create(options); IGifEncoderOptions gifOptions = GifEncoderOptions.Create(options);
@ -23,14 +25,14 @@ namespace ImageSharp.Formats
} }
/// <summary> /// <summary>
/// Encodes the image to the specified stream from the <see cref="Image{TColor}"/>. /// Encodes the image to the specified stream from the <see cref="Image{TPixel}"/>.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="Image{TColor}"/> to encode from.</param> /// <param name="image">The <see cref="Image{TPixel}"/> to encode from.</param>
/// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param> /// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param>
/// <param name="options">The options for the encoder.</param> /// <param name="options">The options for the encoder.</param>
public void Encode<TColor>(Image<TColor> image, Stream stream, IGifEncoderOptions options) public void Encode<TPixel>(Image<TPixel> image, Stream stream, IGifEncoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
GifEncoderCore encoder = new GifEncoderCore(options); GifEncoderCore encoder = new GifEncoderCore(options);
encoder.Encode(image, stream); encoder.Encode(image, stream);

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

@ -10,6 +10,8 @@ namespace ImageSharp.Formats
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using ImageSharp.PixelFormats;
using IO; using IO;
using Quantizers; using Quantizers;
@ -48,18 +50,18 @@ namespace ImageSharp.Formats
public IQuantizer Quantizer { get; set; } public IQuantizer Quantizer { get; set; }
/// <summary> /// <summary>
/// Encodes the image to the specified stream from the <see cref="Image{TColor}"/>. /// Encodes the image to the specified stream from the <see cref="Image{TPixel}"/>.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="Image{TColor}"/> to encode from.</param> /// <param name="image">The <see cref="Image{TPixel}"/> to encode from.</param>
/// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param> /// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param>
public void Encode<TColor>(Image<TColor> image, Stream stream) public void Encode<TPixel>(Image<TPixel> image, Stream stream)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
Guard.NotNull(image, nameof(image)); Guard.NotNull(image, nameof(image));
Guard.NotNull(stream, nameof(stream)); Guard.NotNull(stream, nameof(stream));
this.Quantizer = this.options.Quantizer ?? new OctreeQuantizer<TColor>(); this.Quantizer = this.options.Quantizer ?? new OctreeQuantizer<TPixel>();
// Do not use IDisposable pattern here as we want to preserve the stream. // Do not use IDisposable pattern here as we want to preserve the stream.
EndianBinaryWriter writer = new EndianBinaryWriter(Endianness.LittleEndian, stream); EndianBinaryWriter writer = new EndianBinaryWriter(Endianness.LittleEndian, stream);
@ -72,7 +74,7 @@ namespace ImageSharp.Formats
this.bitDepth = ImageMaths.GetBitsNeededForColorDepth(quality); this.bitDepth = ImageMaths.GetBitsNeededForColorDepth(quality);
// Quantize the image returning a palette. // Quantize the image returning a palette.
QuantizedImage<TColor> quantized = ((IQuantizer<TColor>)this.Quantizer).Quantize(image, quality); QuantizedImage<TPixel> quantized = ((IQuantizer<TPixel>)this.Quantizer).Quantize(image, quality);
int index = this.GetTransparentIndex(quantized); int index = this.GetTransparentIndex(quantized);
@ -97,8 +99,8 @@ namespace ImageSharp.Formats
// ReSharper disable once ForCanBeConvertedToForeach // ReSharper disable once ForCanBeConvertedToForeach
for (int i = 0; i < image.Frames.Count; i++) for (int i = 0; i < image.Frames.Count; i++)
{ {
ImageFrame<TColor> frame = image.Frames[i]; ImageFrame<TPixel> frame = image.Frames[i];
QuantizedImage<TColor> quantizedFrame = ((IQuantizer<TColor>)this.Quantizer).Quantize(frame, quality); QuantizedImage<TPixel> quantizedFrame = ((IQuantizer<TPixel>)this.Quantizer).Quantize(frame, quality);
this.WriteGraphicalControlExtension(frame, writer, this.GetTransparentIndex(quantizedFrame)); this.WriteGraphicalControlExtension(frame, writer, this.GetTransparentIndex(quantizedFrame));
this.WriteImageDescriptor(frame, writer); this.WriteImageDescriptor(frame, writer);
@ -117,12 +119,12 @@ namespace ImageSharp.Formats
/// <param name="quantized"> /// <param name="quantized">
/// The quantized. /// The quantized.
/// </param> /// </param>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns> /// <returns>
/// The <see cref="int"/>. /// The <see cref="int"/>.
/// </returns> /// </returns>
private int GetTransparentIndex<TColor>(QuantizedImage<TColor> quantized) private int GetTransparentIndex<TPixel>(QuantizedImage<TPixel> quantized)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
// Find the lowest alpha value and make it the transparent index. // Find the lowest alpha value and make it the transparent index.
int index = 255; int index = 255;
@ -167,12 +169,12 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Writes the logical screen descriptor to the stream. /// Writes the logical screen descriptor to the stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The image to encode.</param> /// <param name="image">The image to encode.</param>
/// <param name="writer">The writer to write to the stream with.</param> /// <param name="writer">The writer to write to the stream with.</param>
/// <param name="tranparencyIndex">The transparency index to set the default background index to.</param> /// <param name="tranparencyIndex">The transparency index to set the default background index to.</param>
private void WriteLogicalScreenDescriptor<TColor>(Image<TColor> image, EndianBinaryWriter writer, int tranparencyIndex) private void WriteLogicalScreenDescriptor<TPixel>(Image<TPixel> image, EndianBinaryWriter writer, int tranparencyIndex)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
GifLogicalScreenDescriptor descriptor = new GifLogicalScreenDescriptor GifLogicalScreenDescriptor descriptor = new GifLogicalScreenDescriptor
{ {
@ -233,11 +235,11 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Writes the image comments to the stream. /// Writes the image comments to the stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="ImageBase{TColor}"/> to be encoded.</param> /// <param name="image">The <see cref="ImageBase{TPixel}"/> to be encoded.</param>
/// <param name="writer">The stream to write to.</param> /// <param name="writer">The stream to write to.</param>
private void WriteComments<TColor>(Image<TColor> image, EndianBinaryWriter writer) private void WriteComments<TPixel>(Image<TPixel> image, EndianBinaryWriter writer)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
if (this.options.IgnoreMetadata == true) if (this.options.IgnoreMetadata == true)
{ {
@ -266,12 +268,12 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Writes the graphics control extension to the stream. /// Writes the graphics control extension to the stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="Image{TColor}"/> to encode.</param> /// <param name="image">The <see cref="Image{TPixel}"/> to encode.</param>
/// <param name="writer">The stream to write to.</param> /// <param name="writer">The stream to write to.</param>
/// <param name="transparencyIndex">The index of the color in the color palette to make transparent.</param> /// <param name="transparencyIndex">The index of the color in the color palette to make transparent.</param>
private void WriteGraphicalControlExtension<TColor>(Image<TColor> image, EndianBinaryWriter writer, int transparencyIndex) private void WriteGraphicalControlExtension<TPixel>(Image<TPixel> image, EndianBinaryWriter writer, int transparencyIndex)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
this.WriteGraphicalControlExtension(image, image.MetaData, writer, transparencyIndex); this.WriteGraphicalControlExtension(image, image.MetaData, writer, transparencyIndex);
} }
@ -279,12 +281,12 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Writes the graphics control extension to the stream. /// Writes the graphics control extension to the stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="imageFrame">The <see cref="ImageFrame{TColor}"/> to encode.</param> /// <param name="imageFrame">The <see cref="ImageFrame{TPixel}"/> to encode.</param>
/// <param name="writer">The stream to write to.</param> /// <param name="writer">The stream to write to.</param>
/// <param name="transparencyIndex">The index of the color in the color palette to make transparent.</param> /// <param name="transparencyIndex">The index of the color in the color palette to make transparent.</param>
private void WriteGraphicalControlExtension<TColor>(ImageFrame<TColor> imageFrame, EndianBinaryWriter writer, int transparencyIndex) private void WriteGraphicalControlExtension<TPixel>(ImageFrame<TPixel> imageFrame, EndianBinaryWriter writer, int transparencyIndex)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
this.WriteGraphicalControlExtension(imageFrame, imageFrame.MetaData, writer, transparencyIndex); this.WriteGraphicalControlExtension(imageFrame, imageFrame.MetaData, writer, transparencyIndex);
} }
@ -292,13 +294,13 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Writes the graphics control extension to the stream. /// Writes the graphics control extension to the stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="ImageBase{TColor}"/> to encode.</param> /// <param name="image">The <see cref="ImageBase{TPixel}"/> to encode.</param>
/// <param name="metaData">The metadata of the image or frame.</param> /// <param name="metaData">The metadata of the image or frame.</param>
/// <param name="writer">The stream to write to.</param> /// <param name="writer">The stream to write to.</param>
/// <param name="transparencyIndex">The index of the color in the color palette to make transparent.</param> /// <param name="transparencyIndex">The index of the color in the color palette to make transparent.</param>
private void WriteGraphicalControlExtension<TColor>(ImageBase<TColor> image, IMetaData metaData, EndianBinaryWriter writer, int transparencyIndex) private void WriteGraphicalControlExtension<TPixel>(ImageBase<TPixel> image, IMetaData metaData, EndianBinaryWriter writer, int transparencyIndex)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
// TODO: Check transparency logic. // TODO: Check transparency logic.
bool hasTransparent = transparencyIndex < 255; bool hasTransparent = transparencyIndex < 255;
@ -336,11 +338,11 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Writes the image descriptor to the stream. /// Writes the image descriptor to the stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="ImageBase{TColor}"/> to be encoded.</param> /// <param name="image">The <see cref="ImageBase{TPixel}"/> to be encoded.</param>
/// <param name="writer">The stream to write to.</param> /// <param name="writer">The stream to write to.</param>
private void WriteImageDescriptor<TColor>(ImageBase<TColor> image, EndianBinaryWriter writer) private void WriteImageDescriptor<TPixel>(ImageBase<TPixel> image, EndianBinaryWriter writer)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
writer.Write(GifConstants.ImageDescriptorLabel); // 2c writer.Write(GifConstants.ImageDescriptorLabel); // 2c
@ -362,11 +364,11 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Writes the color table to the stream. /// Writes the color table to the stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="ImageBase{TColor}"/> to encode.</param> /// <param name="image">The <see cref="ImageBase{TPixel}"/> to encode.</param>
/// <param name="writer">The writer to write to the stream with.</param> /// <param name="writer">The writer to write to the stream with.</param>
private void WriteColorTable<TColor>(QuantizedImage<TColor> image, EndianBinaryWriter writer) private void WriteColorTable<TPixel>(QuantizedImage<TPixel> image, EndianBinaryWriter writer)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
// Grab the palette and write it to the stream. // Grab the palette and write it to the stream.
int pixelCount = image.Palette.Length; int pixelCount = image.Palette.Length;
@ -397,11 +399,11 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Writes the image pixel data to the stream. /// Writes the image pixel data to the stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="QuantizedImage{TColor}"/> containing indexed pixels.</param> /// <param name="image">The <see cref="QuantizedImage{TPixel}"/> containing indexed pixels.</param>
/// <param name="writer">The stream to write to.</param> /// <param name="writer">The stream to write to.</param>
private void WriteImageData<TColor>(QuantizedImage<TColor> image, EndianBinaryWriter writer) private void WriteImageData<TPixel>(QuantizedImage<TPixel> image, EndianBinaryWriter writer)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
using (LzwEncoder encoder = new LzwEncoder(image.Pixels, (byte)this.bitDepth)) using (LzwEncoder encoder = new LzwEncoder(image.Pixels, (byte)this.bitDepth))
{ {

20
src/ImageSharp/Formats/Gif/ImageExtensions.cs

@ -10,23 +10,25 @@ namespace ImageSharp
using Formats; using Formats;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Saves the image to the given stream with the gif format. /// Saves the image to the given stream with the gif format.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="stream">The stream to save the image to.</param> /// <param name="stream">The stream to save the image to.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns> /// <returns>
/// The <see cref="Image{TColor}"/>. /// The <see cref="Image{TPixel}"/>.
/// </returns> /// </returns>
public static Image<TColor> SaveAsGif<TColor>(this Image<TColor> source, Stream stream) public static Image<TPixel> SaveAsGif<TPixel>(this Image<TPixel> source, Stream stream)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return SaveAsGif(source, stream, null); return SaveAsGif(source, stream, null);
} }
@ -34,16 +36,16 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Saves the image to the given stream with the gif format. /// Saves the image to the given stream with the gif format.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="stream">The stream to save the image to.</param> /// <param name="stream">The stream to save the image to.</param>
/// <param name="options">The options for the encoder.</param> /// <param name="options">The options for the encoder.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns> /// <returns>
/// The <see cref="Image{TColor}"/>. /// The <see cref="Image{TPixel}"/>.
/// </returns> /// </returns>
public static Image<TColor> SaveAsGif<TColor>(this Image<TColor> source, Stream stream, IGifEncoderOptions options) public static Image<TPixel> SaveAsGif<TPixel>(this Image<TPixel> source, Stream stream, IGifEncoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
GifEncoder encoder = new GifEncoder(); GifEncoder encoder = new GifEncoder();
encoder.Encode(source, stream, options); encoder.Encode(source, stream, options);

10
src/ImageSharp/Formats/IImageDecoder.cs

@ -8,20 +8,22 @@ namespace ImageSharp.Formats
using System; using System;
using System.IO; using System.IO;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Encapsulates properties and methods required for decoding an image from a stream. /// Encapsulates properties and methods required for decoding an image from a stream.
/// </summary> /// </summary>
public interface IImageDecoder public interface IImageDecoder
{ {
/// <summary> /// <summary>
/// Decodes the image from the specified stream to the <see cref="ImageBase{TColor}"/>. /// Decodes the image from the specified stream to the <see cref="ImageBase{TPixel}"/>.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="configuration">The configuration for the image.</param> /// <param name="configuration">The configuration for the image.</param>
/// <param name="stream">The <see cref="Stream"/> containing image data.</param> /// <param name="stream">The <see cref="Stream"/> containing image data.</param>
/// <param name="options">The options for the decoder.</param> /// <param name="options">The options for the decoder.</param>
/// <returns>The decoded image</returns> /// <returns>The decoded image</returns>
Image<TColor> Decode<TColor>(Configuration configuration, Stream stream, IDecoderOptions options) Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream, IDecoderOptions options)
where TColor : struct, IPixel<TColor>; where TPixel : struct, IPixel<TPixel>;
} }
} }

12
src/ImageSharp/Formats/IImageEncoder.cs

@ -8,19 +8,21 @@ namespace ImageSharp.Formats
using System; using System;
using System.IO; using System.IO;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Encapsulates properties and methods required for encoding an image to a stream. /// Encapsulates properties and methods required for encoding an image to a stream.
/// </summary> /// </summary>
public interface IImageEncoder public interface IImageEncoder
{ {
/// <summary> /// <summary>
/// Encodes the image to the specified stream from the <see cref="Image{TColor}"/>. /// Encodes the image to the specified stream from the <see cref="Image{TPixel}"/>.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="Image{TColor}"/> to encode from.</param> /// <param name="image">The <see cref="Image{TPixel}"/> to encode from.</param>
/// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param> /// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param>
/// <param name="options">The options for the encoder.</param> /// <param name="options">The options for the encoder.</param>
void Encode<TColor>(Image<TColor> image, Stream stream, IEncoderOptions options) void Encode<TPixel>(Image<TPixel> image, Stream stream, IEncoderOptions options)
where TColor : struct, IPixel<TColor>; where TPixel : struct, IPixel<TPixel>;
} }
} }

20
src/ImageSharp/Formats/Jpeg/ImageExtensions.cs

@ -10,23 +10,25 @@ namespace ImageSharp
using Formats; using Formats;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Saves the image to the given stream with the jpeg format. /// Saves the image to the given stream with the jpeg format.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="stream">The stream to save the image to.</param> /// <param name="stream">The stream to save the image to.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns> /// <returns>
/// The <see cref="Image{TColor}"/>. /// The <see cref="Image{TPixel}"/>.
/// </returns> /// </returns>
public static Image<TColor> SaveAsJpeg<TColor>(this Image<TColor> source, Stream stream) public static Image<TPixel> SaveAsJpeg<TPixel>(this Image<TPixel> source, Stream stream)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return SaveAsJpeg(source, stream, null); return SaveAsJpeg(source, stream, null);
} }
@ -34,16 +36,16 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Saves the image to the given stream with the jpeg format. /// Saves the image to the given stream with the jpeg format.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="stream">The stream to save the image to.</param> /// <param name="stream">The stream to save the image to.</param>
/// <param name="options">The options for the encoder.</param> /// <param name="options">The options for the encoder.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns> /// <returns>
/// The <see cref="Image{TColor}"/>. /// The <see cref="Image{TPixel}"/>.
/// </returns> /// </returns>
public static Image<TColor> SaveAsJpeg<TColor>(this Image<TColor> source, Stream stream, IJpegEncoderOptions options) public static Image<TPixel> SaveAsJpeg<TPixel>(this Image<TPixel> source, Stream stream, IJpegEncoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
JpegEncoder encoder = new JpegEncoder(); JpegEncoder encoder = new JpegEncoder();
encoder.Encode(source, stream, options); encoder.Encode(source, stream, options);

8
src/ImageSharp/Formats/Jpeg/JpegDecoder.cs

@ -8,20 +8,22 @@ namespace ImageSharp.Formats
using System; using System;
using System.IO; using System.IO;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Image decoder for generating an image out of a jpg stream. /// Image decoder for generating an image out of a jpg stream.
/// </summary> /// </summary>
public class JpegDecoder : IImageDecoder public class JpegDecoder : IImageDecoder
{ {
/// <inheritdoc/> /// <inheritdoc/>
public Image<TColor> Decode<TColor>(Configuration configuration, Stream stream, IDecoderOptions options) public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream, IDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
Guard.NotNull(stream, "stream"); Guard.NotNull(stream, "stream");
using (JpegDecoderCore decoder = new JpegDecoderCore(options, configuration)) using (JpegDecoderCore decoder = new JpegDecoderCore(options, configuration))
{ {
return decoder.Decode<TColor>(stream); return decoder.Decode<TPixel>(stream);
} }
} }
} }

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

@ -11,6 +11,7 @@ namespace ImageSharp.Formats
using System.Threading.Tasks; using System.Threading.Tasks;
using ImageSharp.Formats.Jpg; using ImageSharp.Formats.Jpg;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Performs the jpeg decoding operation. /// Performs the jpeg decoding operation.
@ -121,7 +122,7 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Gets the array of <see cref="DecodedBlockArray"/>-s storing the "raw" frequency-domain decoded blocks. /// Gets the array of <see cref="DecodedBlockArray"/>-s storing the "raw" frequency-domain decoded blocks.
/// We need to apply IDCT, dequantiazition and unzigging to transform them into color-space blocks. /// We need to apply IDCT, dequantiazition and unzigging to transform them into color-space blocks.
/// This is done by <see cref="ProcessBlocksIntoJpegImageChannels{TColor}"/>. /// This is done by <see cref="ProcessBlocksIntoJpegImageChannels{TPixel}"/>.
/// When <see cref="IsProgressive"/>==true, we are touching these blocks multiple times - each time we process a Scan. /// When <see cref="IsProgressive"/>==true, we are touching these blocks multiple times - each time we process a Scan.
/// </summary> /// </summary>
public DecodedBlockArray[] DecodedBlocks { get; } public DecodedBlockArray[] DecodedBlocks { get; }
@ -186,16 +187,16 @@ namespace ImageSharp.Formats
/// Decodes the image from the specified <see cref="Stream"/> and sets /// Decodes the image from the specified <see cref="Stream"/> and sets
/// the data to image. /// the data to image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="stream">The stream, where the image should be.</param> /// <param name="stream">The stream, where the image should be.</param>
/// <returns>The decoded image.</returns> /// <returns>The decoded image.</returns>
public Image<TColor> Decode<TColor>(Stream stream) public Image<TPixel> Decode<TPixel>(Stream stream)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
ImageMetaData metadata = new ImageMetaData(); ImageMetaData metadata = new ImageMetaData();
this.ProcessStream(metadata, stream, false); this.ProcessStream(metadata, stream, false);
this.ProcessBlocksIntoJpegImageChannels<TColor>(); this.ProcessBlocksIntoJpegImageChannels<TPixel>();
Image<TColor> image = this.ConvertJpegPixelsToImagePixels<TColor>(metadata); Image<TPixel> image = this.ConvertJpegPixelsToImagePixels<TPixel>(metadata);
return image; return image;
} }
@ -254,14 +255,14 @@ namespace ImageSharp.Formats
/// Optimized method to pack bytes to the image from the YCbCr color space. /// Optimized method to pack bytes to the image from the YCbCr color space.
/// This is faster than implicit casting as it avoids double packing. /// This is faster than implicit casting as it avoids double packing.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="packed">The packed pixel.</param> /// <param name="packed">The packed pixel.</param>
/// <param name="y">The y luminance component.</param> /// <param name="y">The y luminance component.</param>
/// <param name="cb">The cb chroma component.</param> /// <param name="cb">The cb chroma component.</param>
/// <param name="cr">The cr chroma component.</param> /// <param name="cr">The cr chroma component.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void PackYcbCr<TColor>(ref TColor packed, byte y, byte cb, byte cr) private static void PackYcbCr<TPixel>(ref TPixel packed, byte y, byte cb, byte cr)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
int ccb = cb - 128; int ccb = cb - 128;
int ccr = cr - 128; int ccr = cr - 128;
@ -481,9 +482,9 @@ namespace ImageSharp.Formats
/// <see cref="DecodedBlocks"/> are in a "raw" frequency-domain form. We need to apply IDCT, dequantization and unzigging to transform them into color-space blocks. /// <see cref="DecodedBlocks"/> are in a "raw" frequency-domain form. We need to apply IDCT, dequantization and unzigging to transform them into color-space blocks.
/// We can copy these blocks into <see cref="JpegPixelArea"/>-s afterwards. /// We can copy these blocks into <see cref="JpegPixelArea"/>-s afterwards.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel type</typeparam> /// <typeparam name="TPixel">The pixel type</typeparam>
private void ProcessBlocksIntoJpegImageChannels<TColor>() private void ProcessBlocksIntoJpegImageChannels<TPixel>()
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
Parallel.For( Parallel.For(
0, 0,
@ -497,15 +498,15 @@ namespace ImageSharp.Formats
} }
/// <summary> /// <summary>
/// Convert the pixel data in <see cref="YCbCrImage"/> and/or <see cref="JpegPixelArea"/> into pixels of <see cref="Image{TColor}"/> /// Convert the pixel data in <see cref="YCbCrImage"/> and/or <see cref="JpegPixelArea"/> into pixels of <see cref="Image{TPixel}"/>
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel type</typeparam> /// <typeparam name="TPixel">The pixel type</typeparam>
/// <param name="metadata">The metadata for the image.</param> /// <param name="metadata">The metadata for the image.</param>
/// <returns>The decoded image.</returns> /// <returns>The decoded image.</returns>
private Image<TColor> ConvertJpegPixelsToImagePixels<TColor>(ImageMetaData metadata) private Image<TPixel> ConvertJpegPixelsToImagePixels<TPixel>(ImageMetaData metadata)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
Image<TColor> image = Image.Create<TColor>(this.ImageWidth, this.ImageHeight, metadata, this.configuration); Image<TPixel> image = Image.Create<TPixel>(this.ImageWidth, this.ImageHeight, metadata, this.configuration);
if (this.grayImage.IsInitialized) if (this.grayImage.IsInitialized)
{ {
@ -561,10 +562,10 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Assigns the horizontal and vertical resolution to the image if it has a JFIF header. /// Assigns the horizontal and vertical resolution to the image if it has a JFIF header.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The image to assign the resolution to.</param> /// <param name="image">The image to assign the resolution to.</param>
private void AssignResolution<TColor>(Image<TColor> image) private void AssignResolution<TPixel>(Image<TPixel> image)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
if (this.isJfif && this.horizontalResolution > 0 && this.verticalResolution > 0) if (this.isJfif && this.horizontalResolution > 0 && this.verticalResolution > 0)
{ {
@ -589,14 +590,14 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Converts the image from the original CMYK image pixels. /// Converts the image from the original CMYK image pixels.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The image.</param> /// <param name="image">The image.</param>
private void ConvertFromCmyk<TColor>(Image<TColor> image) private void ConvertFromCmyk<TPixel>(Image<TPixel> image)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
int scale = this.ComponentArray[0].HorizontalFactor / this.ComponentArray[1].HorizontalFactor; int scale = this.ComponentArray[0].HorizontalFactor / this.ComponentArray[1].HorizontalFactor;
using (PixelAccessor<TColor> pixels = image.Lock()) using (PixelAccessor<TPixel> pixels = image.Lock())
{ {
Parallel.For( Parallel.For(
0, 0,
@ -613,7 +614,7 @@ namespace ImageSharp.Formats
byte magenta = this.ycbcrImage.CbChannel.Pixels[co + (x / scale)]; byte magenta = this.ycbcrImage.CbChannel.Pixels[co + (x / scale)];
byte yellow = this.ycbcrImage.CrChannel.Pixels[co + (x / scale)]; byte yellow = this.ycbcrImage.CrChannel.Pixels[co + (x / scale)];
TColor packed = default(TColor); TPixel packed = default(TPixel);
this.PackCmyk(ref packed, cyan, magenta, yellow, x, y); this.PackCmyk(ref packed, cyan, magenta, yellow, x, y);
pixels[x, y] = packed; pixels[x, y] = packed;
} }
@ -626,12 +627,12 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Converts the image from the original grayscale image pixels. /// Converts the image from the original grayscale image pixels.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The image.</param> /// <param name="image">The image.</param>
private void ConvertFromGrayScale<TColor>(Image<TColor> image) private void ConvertFromGrayScale<TPixel>(Image<TPixel> image)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
using (PixelAccessor<TColor> pixels = image.Lock()) using (PixelAccessor<TPixel> pixels = image.Lock())
{ {
Parallel.For( Parallel.For(
0, 0,
@ -644,7 +645,7 @@ namespace ImageSharp.Formats
{ {
byte rgb = this.grayImage.Pixels[yoff + x]; byte rgb = this.grayImage.Pixels[yoff + x];
TColor packed = default(TColor); TPixel packed = default(TPixel);
packed.PackFromBytes(rgb, rgb, rgb, 255); packed.PackFromBytes(rgb, rgb, rgb, 255);
pixels[x, y] = packed; pixels[x, y] = packed;
} }
@ -657,14 +658,14 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Converts the image from the original RBG image pixels. /// Converts the image from the original RBG image pixels.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The image.</param> /// <param name="image">The image.</param>
private void ConvertFromRGB<TColor>(Image<TColor> image) private void ConvertFromRGB<TPixel>(Image<TPixel> image)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
int scale = this.ComponentArray[0].HorizontalFactor / this.ComponentArray[1].HorizontalFactor; int scale = this.ComponentArray[0].HorizontalFactor / this.ComponentArray[1].HorizontalFactor;
using (PixelAccessor<TColor> pixels = image.Lock()) using (PixelAccessor<TPixel> pixels = image.Lock())
{ {
Parallel.For( Parallel.For(
0, 0,
@ -682,7 +683,7 @@ namespace ImageSharp.Formats
byte green = this.ycbcrImage.CbChannel.Pixels[co + (x / scale)]; byte green = this.ycbcrImage.CbChannel.Pixels[co + (x / scale)];
byte blue = this.ycbcrImage.CrChannel.Pixels[co + (x / scale)]; byte blue = this.ycbcrImage.CrChannel.Pixels[co + (x / scale)];
TColor packed = default(TColor); TPixel packed = default(TPixel);
packed.PackFromBytes(red, green, blue, 255); packed.PackFromBytes(red, green, blue, 255);
pixels[x, y] = packed; pixels[x, y] = packed;
} }
@ -695,13 +696,13 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Converts the image from the original YCbCr image pixels. /// Converts the image from the original YCbCr image pixels.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The image.</param> /// <param name="image">The image.</param>
private void ConvertFromYCbCr<TColor>(Image<TColor> image) private void ConvertFromYCbCr<TPixel>(Image<TPixel> image)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
int scale = this.ComponentArray[0].HorizontalFactor / this.ComponentArray[1].HorizontalFactor; int scale = this.ComponentArray[0].HorizontalFactor / this.ComponentArray[1].HorizontalFactor;
using (PixelAccessor<TColor> pixels = image.Lock()) using (PixelAccessor<TPixel> pixels = image.Lock())
{ {
Parallel.For( Parallel.For(
0, 0,
@ -719,8 +720,8 @@ namespace ImageSharp.Formats
byte cb = this.ycbcrImage.CbChannel.Pixels[co + (x / scale)]; byte cb = this.ycbcrImage.CbChannel.Pixels[co + (x / scale)];
byte cr = this.ycbcrImage.CrChannel.Pixels[co + (x / scale)]; byte cr = this.ycbcrImage.CrChannel.Pixels[co + (x / scale)];
TColor packed = default(TColor); TPixel packed = default(TPixel);
PackYcbCr<TColor>(ref packed, yy, cb, cr); PackYcbCr<TPixel>(ref packed, yy, cb, cr);
pixels[x, y] = packed; pixels[x, y] = packed;
} }
}); });
@ -732,14 +733,14 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Converts the image from the original YCCK image pixels. /// Converts the image from the original YCCK image pixels.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The image.</param> /// <param name="image">The image.</param>
private void ConvertFromYcck<TColor>(Image<TColor> image) private void ConvertFromYcck<TPixel>(Image<TPixel> image)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
int scale = this.ComponentArray[0].HorizontalFactor / this.ComponentArray[1].HorizontalFactor; int scale = this.ComponentArray[0].HorizontalFactor / this.ComponentArray[1].HorizontalFactor;
using (PixelAccessor<TColor> pixels = image.Lock()) using (PixelAccessor<TPixel> pixels = image.Lock())
{ {
Parallel.For( Parallel.For(
0, 0,
@ -756,7 +757,7 @@ namespace ImageSharp.Formats
byte cb = this.ycbcrImage.CbChannel.Pixels[co + (x / scale)]; byte cb = this.ycbcrImage.CbChannel.Pixels[co + (x / scale)];
byte cr = this.ycbcrImage.CrChannel.Pixels[co + (x / scale)]; byte cr = this.ycbcrImage.CrChannel.Pixels[co + (x / scale)];
TColor packed = default(TColor); TPixel packed = default(TPixel);
this.PackYcck(ref packed, yy, cb, cr, x, y); this.PackYcck(ref packed, yy, cb, cr, x, y);
pixels[x, y] = packed; pixels[x, y] = packed;
} }
@ -850,15 +851,15 @@ namespace ImageSharp.Formats
/// Optimized method to pack bytes to the image from the CMYK color space. /// Optimized method to pack bytes to the image from the CMYK color space.
/// This is faster than implicit casting as it avoids double packing. /// This is faster than implicit casting as it avoids double packing.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="packed">The packed pixel.</param> /// <param name="packed">The packed pixel.</param>
/// <param name="c">The cyan component.</param> /// <param name="c">The cyan component.</param>
/// <param name="m">The magenta component.</param> /// <param name="m">The magenta component.</param>
/// <param name="y">The yellow component.</param> /// <param name="y">The yellow component.</param>
/// <param name="xx">The x-position within the image.</param> /// <param name="xx">The x-position within the image.</param>
/// <param name="yy">The y-position within the image.</param> /// <param name="yy">The y-position within the image.</param>
private void PackCmyk<TColor>(ref TColor packed, byte c, byte m, byte y, int xx, int yy) private void PackCmyk<TPixel>(ref TPixel packed, byte c, byte m, byte y, int xx, int yy)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
// Get keyline // Get keyline
float keyline = (255 - this.blackImage[xx, yy]) / 255F; float keyline = (255 - this.blackImage[xx, yy]) / 255F;
@ -875,15 +876,15 @@ namespace ImageSharp.Formats
/// Optimized method to pack bytes to the image from the YCCK color space. /// Optimized method to pack bytes to the image from the YCCK color space.
/// This is faster than implicit casting as it avoids double packing. /// This is faster than implicit casting as it avoids double packing.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="packed">The packed pixel.</param> /// <param name="packed">The packed pixel.</param>
/// <param name="y">The y luminance component.</param> /// <param name="y">The y luminance component.</param>
/// <param name="cb">The cb chroma component.</param> /// <param name="cb">The cb chroma component.</param>
/// <param name="cr">The cr chroma component.</param> /// <param name="cr">The cr chroma component.</param>
/// <param name="xx">The x-position within the image.</param> /// <param name="xx">The x-position within the image.</param>
/// <param name="yy">The y-position within the image.</param> /// <param name="yy">The y-position within the image.</param>
private void PackYcck<TColor>(ref TColor packed, byte y, byte cb, byte cr, int xx, int yy) private void PackYcck<TPixel>(ref TPixel packed, byte y, byte cb, byte cr, int xx, int yy)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
// Convert the YCbCr part of the YCbCrK to RGB, invert the RGB to get // Convert the YCbCr part of the YCbCrK to RGB, invert the RGB to get
// CMY, and patch in the original K. The RGB to CMY inversion cancels // CMY, and patch in the original K. The RGB to CMY inversion cancels

16
src/ImageSharp/Formats/Jpeg/JpegEncoder.cs

@ -7,14 +7,16 @@ namespace ImageSharp.Formats
{ {
using System.IO; using System.IO;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Encoder for writing the data image to a stream in jpeg format. /// Encoder for writing the data image to a stream in jpeg format.
/// </summary> /// </summary>
public class JpegEncoder : IImageEncoder public class JpegEncoder : IImageEncoder
{ {
/// <inheritdoc/> /// <inheritdoc/>
public void Encode<TColor>(Image<TColor> image, Stream stream, IEncoderOptions options) public void Encode<TPixel>(Image<TPixel> image, Stream stream, IEncoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
IJpegEncoderOptions gifOptions = JpegEncoderOptions.Create(options); IJpegEncoderOptions gifOptions = JpegEncoderOptions.Create(options);
@ -22,14 +24,14 @@ namespace ImageSharp.Formats
} }
/// <summary> /// <summary>
/// Encodes the image to the specified stream from the <see cref="Image{TColor}"/>. /// Encodes the image to the specified stream from the <see cref="Image{TPixel}"/>.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="Image{TColor}"/> to encode from.</param> /// <param name="image">The <see cref="Image{TPixel}"/> to encode from.</param>
/// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param> /// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param>
/// <param name="options">The options for the encoder.</param> /// <param name="options">The options for the encoder.</param>
public void Encode<TColor>(Image<TColor> image, Stream stream, IJpegEncoderOptions options) public void Encode<TPixel>(Image<TPixel> image, Stream stream, IJpegEncoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
JpegEncoderCore encode = new JpegEncoderCore(options); JpegEncoderCore encode = new JpegEncoderCore(options);
encode.Encode(image, stream); encode.Encode(image, stream);

55
src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs

@ -12,6 +12,7 @@ namespace ImageSharp.Formats
using ImageSharp.Formats.Jpg; using ImageSharp.Formats.Jpg;
using ImageSharp.Formats.Jpg.Components; using ImageSharp.Formats.Jpg.Components;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Image encoder for writing an image to a stream as a jpeg. /// Image encoder for writing an image to a stream as a jpeg.
@ -165,11 +166,11 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Encode writes the image to the jpeg baseline format with the given options. /// Encode writes the image to the jpeg baseline format with the given options.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The image to write from.</param> /// <param name="image">The image to write from.</param>
/// <param name="stream">The stream to write to.</param> /// <param name="stream">The stream to write to.</param>
public void Encode<TColor>(Image<TColor> image, Stream stream) public void Encode<TPixel>(Image<TPixel> image, Stream stream)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
Guard.NotNull(image, nameof(image)); Guard.NotNull(image, nameof(image));
Guard.NotNull(stream, nameof(stream)); Guard.NotNull(stream, nameof(stream));
@ -225,7 +226,7 @@ namespace ImageSharp.Formats
this.WriteDefineHuffmanTables(componentCount); this.WriteDefineHuffmanTables(componentCount);
// Write the image data. // Write the image data.
using (PixelAccessor<TColor> pixels = image.Lock()) using (PixelAccessor<TPixel> pixels = image.Lock())
{ {
this.WriteStartOfScan(pixels); this.WriteStartOfScan(pixels);
} }
@ -282,23 +283,23 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Converts the 8x8 region of the image whose top-left corner is x,y to its YCbCr values. /// Converts the 8x8 region of the image whose top-left corner is x,y to its YCbCr values.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="pixels">The pixel accessor.</param> /// <param name="pixels">The pixel accessor.</param>
/// <param name="x">The x-position within the image.</param> /// <param name="x">The x-position within the image.</param>
/// <param name="y">The y-position within the image.</param> /// <param name="y">The y-position within the image.</param>
/// <param name="yBlock">The luminance block.</param> /// <param name="yBlock">The luminance block.</param>
/// <param name="cbBlock">The red chroma block.</param> /// <param name="cbBlock">The red chroma block.</param>
/// <param name="crBlock">The blue chroma block.</param> /// <param name="crBlock">The blue chroma block.</param>
/// <param name="rgbBytes">Temporal <see cref="PixelArea{TColor}"/> provided by the caller</param> /// <param name="rgbBytes">Temporal <see cref="PixelArea{TPixel}"/> provided by the caller</param>
private static void ToYCbCr<TColor>( private static void ToYCbCr<TPixel>(
PixelAccessor<TColor> pixels, PixelAccessor<TPixel> pixels,
int x, int x,
int y, int y,
Block8x8F* yBlock, Block8x8F* yBlock,
Block8x8F* cbBlock, Block8x8F* cbBlock,
Block8x8F* crBlock, Block8x8F* crBlock,
PixelArea<TColor> rgbBytes) PixelArea<TPixel> rgbBytes)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
float* yBlockRaw = (float*)yBlock; float* yBlockRaw = (float*)yBlock;
float* cbBlockRaw = (float*)cbBlock; float* cbBlockRaw = (float*)cbBlock;
@ -442,12 +443,12 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Encodes the image with no subsampling. /// Encodes the image with no subsampling.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="pixels">The pixel accessor providing access to the image pixels.</param> /// <param name="pixels">The pixel accessor providing access to the image pixels.</param>
private void Encode444<TColor>(PixelAccessor<TColor> pixels) private void Encode444<TPixel>(PixelAccessor<TPixel> pixels)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
// TODO: Need a JpegScanEncoder<TColor> class or struct that encapsulates the scan-encoding implementation. (Similar to JpegScanDecoder.) // TODO: Need a JpegScanEncoder<TPixel> class or struct that encapsulates the scan-encoding implementation. (Similar to JpegScanDecoder.)
Block8x8F b = default(Block8x8F); Block8x8F b = default(Block8x8F);
Block8x8F cb = default(Block8x8F); Block8x8F cb = default(Block8x8F);
Block8x8F cr = default(Block8x8F); Block8x8F cr = default(Block8x8F);
@ -463,7 +464,7 @@ namespace ImageSharp.Formats
// ReSharper disable once InconsistentNaming // ReSharper disable once InconsistentNaming
int prevDCY = 0, prevDCCb = 0, prevDCCr = 0; int prevDCY = 0, prevDCCb = 0, prevDCCr = 0;
using (PixelArea<TColor> rgbBytes = new PixelArea<TColor>(8, 8, ComponentOrder.Xyz)) using (PixelArea<TPixel> rgbBytes = new PixelArea<TPixel>(8, 8, ComponentOrder.Xyz))
{ {
for (int y = 0; y < pixels.Height; y += 8) for (int y = 0; y < pixels.Height; y += 8)
{ {
@ -714,9 +715,9 @@ namespace ImageSharp.Formats
/// Writes the metadata profiles to the image. /// Writes the metadata profiles to the image.
/// </summary> /// </summary>
/// <param name="image">The image.</param> /// <param name="image">The image.</param>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
private void WriteProfiles<TColor>(Image<TColor> image) private void WriteProfiles<TPixel>(Image<TPixel> image)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
if (this.options.IgnoreMetadata) if (this.options.IgnoreMetadata)
{ {
@ -786,12 +787,12 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Writes the StartOfScan marker. /// Writes the StartOfScan marker.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="pixels">The pixel accessor providing access to the image pixels.</param> /// <param name="pixels">The pixel accessor providing access to the image pixels.</param>
private void WriteStartOfScan<TColor>(PixelAccessor<TColor> pixels) private void WriteStartOfScan<TPixel>(PixelAccessor<TPixel> pixels)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
// TODO: Need a JpegScanEncoder<TColor> class or struct that encapsulates the scan-encoding implementation. (Similar to JpegScanDecoder.) // TODO: Need a JpegScanEncoder<TPixel> class or struct that encapsulates the scan-encoding implementation. (Similar to JpegScanDecoder.)
// TODO: We should allow grayscale writing. // TODO: We should allow grayscale writing.
this.outputStream.Write(SosHeaderYCbCr, 0, SosHeaderYCbCr.Length); this.outputStream.Write(SosHeaderYCbCr, 0, SosHeaderYCbCr.Length);
@ -813,12 +814,12 @@ namespace ImageSharp.Formats
/// Encodes the image with subsampling. The Cb and Cr components are each subsampled /// Encodes the image with subsampling. The Cb and Cr components are each subsampled
/// at a factor of 2 both horizontally and vertically. /// at a factor of 2 both horizontally and vertically.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="pixels">The pixel accessor providing access to the image pixels.</param> /// <param name="pixels">The pixel accessor providing access to the image pixels.</param>
private void Encode420<TColor>(PixelAccessor<TColor> pixels) private void Encode420<TPixel>(PixelAccessor<TPixel> pixels)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
// TODO: Need a JpegScanEncoder<TColor> class or struct that encapsulates the scan-encoding implementation. (Similar to JpegScanDecoder.) // TODO: Need a JpegScanEncoder<TPixel> class or struct that encapsulates the scan-encoding implementation. (Similar to JpegScanDecoder.)
Block8x8F b = default(Block8x8F); Block8x8F b = default(Block8x8F);
BlockQuad cb = default(BlockQuad); BlockQuad cb = default(BlockQuad);
@ -837,7 +838,7 @@ namespace ImageSharp.Formats
// ReSharper disable once InconsistentNaming // ReSharper disable once InconsistentNaming
int prevDCY = 0, prevDCCb = 0, prevDCCr = 0; int prevDCY = 0, prevDCCb = 0, prevDCCr = 0;
using (PixelArea<TColor> rgbBytes = new PixelArea<TColor>(8, 8, ComponentOrder.Xyz)) using (PixelArea<TPixel> rgbBytes = new PixelArea<TPixel>(8, 8, ComponentOrder.Xyz))
{ {
for (int y = 0; y < pixels.Height; y += 16) for (int y = 0; y < pixels.Height; y += 16)
{ {

26
src/ImageSharp/Formats/Jpeg/Utils/JpegUtils.cs

@ -8,6 +8,8 @@ namespace ImageSharp.Formats.Jpg
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Jpeg specific utilities and extension methods /// Jpeg specific utilities and extension methods
/// </summary> /// </summary>
@ -16,17 +18,17 @@ namespace ImageSharp.Formats.Jpg
/// <summary> /// <summary>
/// Copy a region of an image into dest. De "outlier" area will be stretched out with pixels on the right and bottom of the image. /// Copy a region of an image into dest. De "outlier" area will be stretched out with pixels on the right and bottom of the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel type</typeparam> /// <typeparam name="TPixel">The pixel type</typeparam>
/// <param name="pixels">The input pixel acessor</param> /// <param name="pixels">The input pixel acessor</param>
/// <param name="dest">The destination <see cref="PixelArea{TColor}"/></param> /// <param name="dest">The destination <see cref="PixelArea{TPixel}"/></param>
/// <param name="sourceY">Starting Y coord</param> /// <param name="sourceY">Starting Y coord</param>
/// <param name="sourceX">Starting X coord</param> /// <param name="sourceX">Starting X coord</param>
public static void CopyRGBBytesStretchedTo<TColor>( public static void CopyRGBBytesStretchedTo<TPixel>(
this PixelAccessor<TColor> pixels, this PixelAccessor<TPixel> pixels,
PixelArea<TColor> dest, PixelArea<TPixel> dest,
int sourceY, int sourceY,
int sourceX) int sourceX)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
pixels.SafeCopyTo(dest, sourceY, sourceX); pixels.SafeCopyTo(dest, sourceY, sourceX);
int stretchFromX = pixels.Width - sourceX; int stretchFromX = pixels.Width - sourceX;
@ -36,14 +38,14 @@ namespace ImageSharp.Formats.Jpg
// Nothing to stretch if (fromX, fromY) is outside the area, or is at (0,0) // Nothing to stretch if (fromX, fromY) is outside the area, or is at (0,0)
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool IsInvalidStretchStartingPosition<TColor>(PixelArea<TColor> area, int fromX, int fromY) private static bool IsInvalidStretchStartingPosition<TPixel>(PixelArea<TPixel> area, int fromX, int fromY)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return fromX <= 0 || fromY <= 0 || fromX >= area.Width || fromY >= area.Height; return fromX <= 0 || fromY <= 0 || fromX >= area.Width || fromY >= area.Height;
} }
private static void StretchPixels<TColor>(PixelArea<TColor> area, int fromX, int fromY) private static void StretchPixels<TPixel>(PixelArea<TPixel> area, int fromX, int fromY)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
if (IsInvalidStretchStartingPosition(area, fromX, fromY)) if (IsInvalidStretchStartingPosition(area, fromX, fromY))
{ {
@ -75,8 +77,8 @@ namespace ImageSharp.Formats.Jpg
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private static ref RGB24 GetRowStart<TColor>(PixelArea<TColor> area, int y) private static ref RGB24 GetRowStart<TPixel>(PixelArea<TPixel> area, int y)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return ref Unsafe.As<byte, RGB24>(ref area.GetRowSpan(y).DangerousGetPinnableReference()); return ref Unsafe.As<byte, RGB24>(ref area.GetRowSpan(y).DangerousGetPinnableReference());
} }

20
src/ImageSharp/Formats/Png/ImageExtensions.cs

@ -9,23 +9,25 @@ namespace ImageSharp
using Formats; using Formats;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Saves the image to the given stream with the png format. /// Saves the image to the given stream with the png format.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="stream">The stream to save the image to.</param> /// <param name="stream">The stream to save the image to.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns> /// <returns>
/// The <see cref="Image{TColor}"/>. /// The <see cref="Image{TPixel}"/>.
/// </returns> /// </returns>
public static Image<TColor> SaveAsPng<TColor>(this Image<TColor> source, Stream stream) public static Image<TPixel> SaveAsPng<TPixel>(this Image<TPixel> source, Stream stream)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return SaveAsPng(source, stream, null); return SaveAsPng(source, stream, null);
} }
@ -33,16 +35,16 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Saves the image to the given stream with the png format. /// Saves the image to the given stream with the png format.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="stream">The stream to save the image to.</param> /// <param name="stream">The stream to save the image to.</param>
/// <param name="options">The options for the encoder.</param> /// <param name="options">The options for the encoder.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns> /// <returns>
/// The <see cref="Image{TColor}"/>. /// The <see cref="Image{TPixel}"/>.
/// </returns> /// </returns>
public static Image<TColor> SaveAsPng<TColor>(this Image<TColor> source, Stream stream, IPngEncoderOptions options) public static Image<TPixel> SaveAsPng<TPixel>(this Image<TPixel> source, Stream stream, IPngEncoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
PngEncoder encoder = new PngEncoder(); PngEncoder encoder = new PngEncoder();
encoder.Encode(source, stream, options); encoder.Encode(source, stream, options);

18
src/ImageSharp/Formats/Png/PngDecoder.cs

@ -8,6 +8,8 @@ namespace ImageSharp.Formats
using System; using System;
using System.IO; using System.IO;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Encoder for generating an image out of a png encoded stream. /// Encoder for generating an image out of a png encoded stream.
/// </summary> /// </summary>
@ -31,27 +33,27 @@ namespace ImageSharp.Formats
public class PngDecoder : IImageDecoder public class PngDecoder : IImageDecoder
{ {
/// <inheritdoc/> /// <inheritdoc/>
public Image<TColor> Decode<TColor>(Configuration configuration, Stream stream, IDecoderOptions options) public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream, IDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
IPngDecoderOptions pngOptions = PngDecoderOptions.Create(options); IPngDecoderOptions pngOptions = PngDecoderOptions.Create(options);
return this.Decode<TColor>(configuration, stream, pngOptions); return this.Decode<TPixel>(configuration, stream, pngOptions);
} }
/// <summary> /// <summary>
/// Decodes the image from the specified stream to the <see cref="ImageBase{TColor}"/>. /// Decodes the image from the specified stream to the <see cref="ImageBase{TPixel}"/>.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="configuration">The configuration for the image.</param> /// <param name="configuration">The configuration for the image.</param>
/// <param name="stream">The <see cref="Stream"/> containing image data.</param> /// <param name="stream">The <see cref="Stream"/> containing image data.</param>
/// <param name="options">The options for the decoder.</param> /// <param name="options">The options for the decoder.</param>
/// <returns>The decoded image.</returns> /// <returns>The decoded image.</returns>
public Image<TColor> Decode<TColor>(Configuration configuration, Stream stream, IPngDecoderOptions options) public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream, IPngDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return new PngDecoderCore(options, configuration).Decode<TColor>(stream); return new PngDecoderCore(options, configuration).Decode<TPixel>(stream);
} }
} }
} }

50
src/ImageSharp/Formats/Png/PngDecoderCore.cs

@ -12,6 +12,8 @@ namespace ImageSharp.Formats
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using ImageSharp.PixelFormats;
using static ComparableExtensions; using static ComparableExtensions;
/// <summary> /// <summary>
@ -154,7 +156,7 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Decodes the stream to the image. /// Decodes the stream to the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="stream">The stream containing image data. </param> /// <param name="stream">The stream containing image data. </param>
/// <exception cref="ImageFormatException"> /// <exception cref="ImageFormatException">
/// Thrown if the stream does not contain and end chunk. /// Thrown if the stream does not contain and end chunk.
@ -163,8 +165,8 @@ namespace ImageSharp.Formats
/// Thrown if the image is larger than the maximum allowable size. /// Thrown if the image is larger than the maximum allowable size.
/// </exception> /// </exception>
/// <returns>The decoded image</returns> /// <returns>The decoded image</returns>
public Image<TColor> Decode<TColor>(Stream stream) public Image<TPixel> Decode<TPixel>(Stream stream)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
ImageMetaData metadata = new ImageMetaData(); ImageMetaData metadata = new ImageMetaData();
this.currentStream = stream; this.currentStream = stream;
@ -215,14 +217,14 @@ namespace ImageSharp.Formats
} }
} }
if (this.header.Width > Image<TColor>.MaxWidth || this.header.Height > Image<TColor>.MaxHeight) if (this.header.Width > Image<TPixel>.MaxWidth || this.header.Height > Image<TPixel>.MaxHeight)
{ {
throw new ArgumentOutOfRangeException($"The input png '{this.header.Width}x{this.header.Height}' is bigger than the max allowed size '{Image<TColor>.MaxWidth}x{Image<TColor>.MaxHeight}'"); 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<TColor> image = Image.Create<TColor>(this.header.Width, this.header.Height, metadata, this.configuration); Image<TPixel> image = Image.Create<TPixel>(this.header.Width, this.header.Height, metadata, this.configuration);
using (PixelAccessor<TColor> pixels = image.Lock()) using (PixelAccessor<TPixel> pixels = image.Lock())
{ {
this.ReadScanlines(dataStream, pixels); this.ReadScanlines(dataStream, pixels);
} }
@ -340,11 +342,11 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Reads the scanlines within the image. /// Reads the scanlines within the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="dataStream">The <see cref="MemoryStream"/> containing data.</param> /// <param name="dataStream">The <see cref="MemoryStream"/> containing data.</param>
/// <param name="pixels"> The pixel data.</param> /// <param name="pixels"> The pixel data.</param>
private void ReadScanlines<TColor>(MemoryStream dataStream, PixelAccessor<TColor> pixels) private void ReadScanlines<TPixel>(MemoryStream dataStream, PixelAccessor<TPixel> pixels)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
this.bytesPerPixel = this.CalculateBytesPerPixel(); this.bytesPerPixel = this.CalculateBytesPerPixel();
this.bytesPerScanline = this.CalculateScanlineLength(this.header.Width) + 1; this.bytesPerScanline = this.CalculateScanlineLength(this.header.Width) + 1;
@ -371,11 +373,11 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Decodes the raw pixel data row by row /// Decodes the raw pixel data row by row
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="compressedStream">The compressed pixel data stream.</param> /// <param name="compressedStream">The compressed pixel data stream.</param>
/// <param name="pixels">The image pixel accessor.</param> /// <param name="pixels">The image pixel accessor.</param>
private void DecodePixelData<TColor>(Stream compressedStream, PixelAccessor<TColor> pixels) private void DecodePixelData<TPixel>(Stream compressedStream, PixelAccessor<TPixel> pixels)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
byte[] previousScanline = ArrayPool<byte>.Shared.Rent(this.bytesPerScanline); byte[] previousScanline = ArrayPool<byte>.Shared.Rent(this.bytesPerScanline);
byte[] scanline = ArrayPool<byte>.Shared.Rent(this.bytesPerScanline); byte[] scanline = ArrayPool<byte>.Shared.Rent(this.bytesPerScanline);
@ -444,11 +446,11 @@ namespace ImageSharp.Formats
/// Decodes the raw interlaced pixel data row by row /// Decodes the raw interlaced pixel data row by row
/// <see href="https://github.com/juehv/DentalImageViewer/blob/8a1a4424b15d6cc453b5de3f273daf3ff5e3a90d/DentalImageViewer/lib/jiu-0.14.3/net/sourceforge/jiu/codecs/PNGCodec.java"/> /// <see href="https://github.com/juehv/DentalImageViewer/blob/8a1a4424b15d6cc453b5de3f273daf3ff5e3a90d/DentalImageViewer/lib/jiu-0.14.3/net/sourceforge/jiu/codecs/PNGCodec.java"/>
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="compressedStream">The compressed pixel data stream.</param> /// <param name="compressedStream">The compressed pixel data stream.</param>
/// <param name="pixels">The image pixel accessor.</param> /// <param name="pixels">The image pixel accessor.</param>
private void DecodeInterlacedPixelData<TColor>(Stream compressedStream, PixelAccessor<TColor> pixels) private void DecodeInterlacedPixelData<TPixel>(Stream compressedStream, PixelAccessor<TPixel> pixels)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
byte[] previousScanline = ArrayPool<byte>.Shared.Rent(this.bytesPerScanline); byte[] previousScanline = ArrayPool<byte>.Shared.Rent(this.bytesPerScanline);
byte[] scanline = ArrayPool<byte>.Shared.Rent(this.bytesPerScanline); byte[] scanline = ArrayPool<byte>.Shared.Rent(this.bytesPerScanline);
@ -532,14 +534,14 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Processes the de-filtered scanline filling the image pixel data /// Processes the de-filtered scanline filling the image pixel data
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="defilteredScanline">The de-filtered scanline</param> /// <param name="defilteredScanline">The de-filtered scanline</param>
/// <param name="row">The current image row.</param> /// <param name="row">The current image row.</param>
/// <param name="pixels">The image pixels</param> /// <param name="pixels">The image pixels</param>
private void ProcessDefilteredScanline<TColor>(byte[] defilteredScanline, int row, PixelAccessor<TColor> pixels) private void ProcessDefilteredScanline<TPixel>(byte[] defilteredScanline, int row, PixelAccessor<TPixel> pixels)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
TColor color = default(TColor); TPixel color = default(TPixel);
switch (this.PngColorType) switch (this.PngColorType)
{ {
case PngColorType.Grayscale: case PngColorType.Grayscale:
@ -655,16 +657,16 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Processes the interlaced de-filtered scanline filling the image pixel data /// Processes the interlaced de-filtered scanline filling the image pixel data
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="defilteredScanline">The de-filtered scanline</param> /// <param name="defilteredScanline">The de-filtered scanline</param>
/// <param name="row">The current image row.</param> /// <param name="row">The current image row.</param>
/// <param name="pixels">The image pixels</param> /// <param name="pixels">The image pixels</param>
/// <param name="pixelOffset">The column start index. Always 0 for none interlaced images.</param> /// <param name="pixelOffset">The column start index. Always 0 for none interlaced images.</param>
/// <param name="increment">The column increment. Always 1 for none interlaced images.</param> /// <param name="increment">The column increment. Always 1 for none interlaced images.</param>
private void ProcessInterlacedDefilteredScanline<TColor>(byte[] defilteredScanline, int row, PixelAccessor<TColor> pixels, int pixelOffset = 0, int increment = 1) private void ProcessInterlacedDefilteredScanline<TPixel>(byte[] defilteredScanline, int row, PixelAccessor<TPixel> pixels, int pixelOffset = 0, int increment = 1)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
TColor color = default(TColor); TPixel color = default(TPixel);
switch (this.PngColorType) switch (this.PngColorType)
{ {

16
src/ImageSharp/Formats/Png/PngEncoder.cs

@ -7,14 +7,16 @@ namespace ImageSharp.Formats
{ {
using System.IO; using System.IO;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Image encoder for writing image data to a stream in png format. /// Image encoder for writing image data to a stream in png format.
/// </summary> /// </summary>
public class PngEncoder : IImageEncoder public class PngEncoder : IImageEncoder
{ {
/// <inheritdoc/> /// <inheritdoc/>
public void Encode<TColor>(Image<TColor> image, Stream stream, IEncoderOptions options) public void Encode<TPixel>(Image<TPixel> image, Stream stream, IEncoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
IPngEncoderOptions pngOptions = PngEncoderOptions.Create(options); IPngEncoderOptions pngOptions = PngEncoderOptions.Create(options);
@ -22,14 +24,14 @@ namespace ImageSharp.Formats
} }
/// <summary> /// <summary>
/// Encodes the image to the specified stream from the <see cref="Image{TColor}"/>. /// Encodes the image to the specified stream from the <see cref="Image{TPixel}"/>.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="Image{TColor}"/> to encode from.</param> /// <param name="image">The <see cref="Image{TPixel}"/> to encode from.</param>
/// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param> /// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param>
/// <param name="options">The options for the encoder.</param> /// <param name="options">The options for the encoder.</param>
public void Encode<TColor>(Image<TColor> image, Stream stream, IPngEncoderOptions options) public void Encode<TPixel>(Image<TPixel> image, Stream stream, IPngEncoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
PngEncoderCore encode = new PngEncoderCore(options); PngEncoderCore encode = new PngEncoderCore(options);
encode.Encode(image, stream); encode.Encode(image, stream);

70
src/ImageSharp/Formats/Png/PngEncoderCore.cs

@ -10,6 +10,8 @@ namespace ImageSharp.Formats
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using ImageSharp.PixelFormats;
using Quantizers; using Quantizers;
using static ComparableExtensions; using static ComparableExtensions;
@ -114,13 +116,13 @@ namespace ImageSharp.Formats
} }
/// <summary> /// <summary>
/// Encodes the image to the specified stream from the <see cref="Image{TColor}"/>. /// Encodes the image to the specified stream from the <see cref="Image{TPixel}"/>.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="ImageBase{TColor}"/> to encode from.</param> /// <param name="image">The <see cref="ImageBase{TPixel}"/> to encode from.</param>
/// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param> /// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param>
public void Encode<TColor>(Image<TColor> image, Stream stream) public void Encode<TPixel>(Image<TPixel> image, Stream stream)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
Guard.NotNull(image, nameof(image)); Guard.NotNull(image, nameof(image));
Guard.NotNull(stream, nameof(stream)); Guard.NotNull(stream, nameof(stream));
@ -196,7 +198,7 @@ namespace ImageSharp.Formats
this.WritePhysicalChunk(stream, image); this.WritePhysicalChunk(stream, image);
this.WriteGammaChunk(stream); this.WriteGammaChunk(stream);
using (PixelAccessor<TColor> pixels = image.Lock()) using (PixelAccessor<TPixel> pixels = image.Lock())
{ {
this.WriteDataChunks(pixels, stream); this.WriteDataChunks(pixels, stream);
} }
@ -248,27 +250,27 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Collects the indexed pixel data. /// Collects the indexed pixel data.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The image to encode.</param> /// <param name="image">The image to encode.</param>
/// <param name="stream">The <see cref="Stream"/> containing image data.</param> /// <param name="stream">The <see cref="Stream"/> containing image data.</param>
/// <param name="header">The <see cref="PngHeader"/>.</param> /// <param name="header">The <see cref="PngHeader"/>.</param>
private void CollectIndexedBytes<TColor>(ImageBase<TColor> image, Stream stream, PngHeader header) private void CollectIndexedBytes<TPixel>(ImageBase<TPixel> image, Stream stream, PngHeader header)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
// Quantize the image and get the pixels. // Quantize the image and get the pixels.
QuantizedImage<TColor> quantized = this.WritePaletteChunk(stream, header, image); QuantizedImage<TPixel> quantized = this.WritePaletteChunk(stream, header, image);
this.palettePixelData = quantized.Pixels; this.palettePixelData = quantized.Pixels;
} }
/// <summary> /// <summary>
/// Collects a row of grayscale pixels. /// Collects a row of grayscale pixels.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="pixels">The image pixels accessor.</param> /// <param name="pixels">The image pixels accessor.</param>
/// <param name="row">The row index.</param> /// <param name="row">The row index.</param>
/// <param name="rawScanline">The raw scanline.</param> /// <param name="rawScanline">The raw scanline.</param>
private void CollectGrayscaleBytes<TColor>(PixelAccessor<TColor> pixels, int row, byte[] rawScanline) private void CollectGrayscaleBytes<TPixel>(PixelAccessor<TPixel> pixels, int row, byte[] rawScanline)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
// Copy the pixels across from the image. // Copy the pixels across from the image.
// Reuse the chunk type buffer. // Reuse the chunk type buffer.
@ -297,15 +299,15 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Collects a row of true color pixel data. /// Collects a row of true color pixel data.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="pixels">The image pixel accessor.</param> /// <param name="pixels">The image pixel accessor.</param>
/// <param name="row">The row index.</param> /// <param name="row">The row index.</param>
/// <param name="rawScanline">The raw scanline.</param> /// <param name="rawScanline">The raw scanline.</param>
private void CollectColorBytes<TColor>(PixelAccessor<TColor> pixels, int row, byte[] rawScanline) private void CollecTPixelBytes<TPixel>(PixelAccessor<TPixel> pixels, int row, byte[] rawScanline)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
// We can use the optimized PixelAccessor here and copy the bytes in unmanaged memory. // We can use the optimized PixelAccessor here and copy the bytes in unmanaged memory.
using (PixelArea<TColor> pixelRow = new PixelArea<TColor>(this.width, rawScanline, this.bytesPerPixel == 4 ? ComponentOrder.Xyzw : ComponentOrder.Xyz)) using (PixelArea<TPixel> pixelRow = new PixelArea<TPixel>(this.width, rawScanline, this.bytesPerPixel == 4 ? ComponentOrder.Xyzw : ComponentOrder.Xyz))
{ {
pixels.CopyTo(pixelRow, row); pixels.CopyTo(pixelRow, row);
} }
@ -315,15 +317,15 @@ namespace ImageSharp.Formats
/// Encodes the pixel data line by line. /// Encodes the pixel data line by line.
/// Each scanline is encoded in the most optimal manner to improve compression. /// Each scanline is encoded in the most optimal manner to improve compression.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="pixels">The image pixel accessor.</param> /// <param name="pixels">The image pixel accessor.</param>
/// <param name="row">The row.</param> /// <param name="row">The row.</param>
/// <param name="previousScanline">The previous scanline.</param> /// <param name="previousScanline">The previous scanline.</param>
/// <param name="rawScanline">The raw scanline.</param> /// <param name="rawScanline">The raw scanline.</param>
/// <param name="result">The filtered scanline result.</param> /// <param name="result">The filtered scanline result.</param>
/// <returns>The <see cref="T:byte[]"/></returns> /// <returns>The <see cref="T:byte[]"/></returns>
private byte[] EncodePixelRow<TColor>(PixelAccessor<TColor> pixels, int row, byte[] previousScanline, byte[] rawScanline, byte[] result) private byte[] EncodePixelRow<TPixel>(PixelAccessor<TPixel> pixels, int row, byte[] previousScanline, byte[] rawScanline, byte[] result)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
switch (this.pngColorType) switch (this.pngColorType)
{ {
@ -335,7 +337,7 @@ namespace ImageSharp.Formats
this.CollectGrayscaleBytes(pixels, row, rawScanline); this.CollectGrayscaleBytes(pixels, row, rawScanline);
break; break;
default: default:
this.CollectColorBytes(pixels, row, rawScanline); this.CollecTPixelBytes(pixels, row, rawScanline);
break; break;
} }
@ -471,13 +473,13 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Writes the palette chunk to the stream. /// Writes the palette chunk to the stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="stream">The <see cref="Stream"/> containing image data.</param> /// <param name="stream">The <see cref="Stream"/> containing image data.</param>
/// <param name="header">The <see cref="PngHeader"/>.</param> /// <param name="header">The <see cref="PngHeader"/>.</param>
/// <param name="image">The image to encode.</param> /// <param name="image">The image to encode.</param>
/// <returns>The <see cref="QuantizedImage{TColor}"/></returns> /// <returns>The <see cref="QuantizedImage{TPixel}"/></returns>
private QuantizedImage<TColor> WritePaletteChunk<TColor>(Stream stream, PngHeader header, ImageBase<TColor> image) private QuantizedImage<TPixel> WritePaletteChunk<TPixel>(Stream stream, PngHeader header, ImageBase<TPixel> image)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
if (this.quality > 256) if (this.quality > 256)
{ {
@ -486,14 +488,14 @@ namespace ImageSharp.Formats
if (this.quantizer == null) if (this.quantizer == null)
{ {
this.quantizer = new WuQuantizer<TColor>(); this.quantizer = new WuQuantizer<TPixel>();
} }
// Quantize the image returning a palette. This boxing is icky. // Quantize the image returning a palette. This boxing is icky.
QuantizedImage<TColor> quantized = ((IQuantizer<TColor>)this.quantizer).Quantize(image, this.quality); QuantizedImage<TPixel> quantized = ((IQuantizer<TPixel>)this.quantizer).Quantize(image, this.quality);
// Grab the palette and write it to the stream. // Grab the palette and write it to the stream.
TColor[] palette = quantized.Palette; TPixel[] palette = quantized.Palette;
byte pixelCount = palette.Length.ToByte(); byte pixelCount = palette.Length.ToByte();
// Get max colors for bit depth. // Get max colors for bit depth.
@ -548,11 +550,11 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Writes the physical dimension information to the stream. /// Writes the physical dimension information to the stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="stream">The <see cref="Stream"/> containing image data.</param> /// <param name="stream">The <see cref="Stream"/> containing image data.</param>
/// <param name="image">The image.</param> /// <param name="image">The image.</param>
private void WritePhysicalChunk<TColor>(Stream stream, Image<TColor> image) private void WritePhysicalChunk<TPixel>(Stream stream, Image<TPixel> image)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
if (image.MetaData.HorizontalResolution > 0 && image.MetaData.VerticalResolution > 0) if (image.MetaData.HorizontalResolution > 0 && image.MetaData.VerticalResolution > 0)
{ {
@ -593,11 +595,11 @@ namespace ImageSharp.Formats
/// <summary> /// <summary>
/// Writes the pixel information to the stream. /// Writes the pixel information to the stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="pixels">The pixel accessor.</param> /// <param name="pixels">The pixel accessor.</param>
/// <param name="stream">The stream.</param> /// <param name="stream">The stream.</param>
private void WriteDataChunks<TColor>(PixelAccessor<TColor> pixels, Stream stream) private void WriteDataChunks<TPixel>(PixelAccessor<TPixel> pixels, Stream stream)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
int bytesPerScanline = this.width * this.bytesPerPixel; int bytesPerScanline = this.width * this.bytesPerPixel;
byte[] previousScanline = new byte[bytesPerScanline]; byte[] previousScanline = new byte[bytesPerScanline];

36
src/ImageSharp/Image.Create.cs

@ -5,11 +5,7 @@
namespace ImageSharp namespace ImageSharp
{ {
using System; using ImageSharp.PixelFormats;
using System.Diagnostics;
using System.IO;
using Formats;
/// <summary> /// <summary>
/// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha /// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha
@ -18,10 +14,10 @@ namespace ImageSharp
public sealed partial class Image public sealed partial class Image
{ {
/// <summary> /// <summary>
/// Create a new instance of the <see cref="Image{TColor}"/> class /// Create a new instance of the <see cref="Image{TPixel}"/> class
/// with the height and the width of the image. /// with the height and the width of the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="width">The width of the image in pixels.</param> /// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height 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="metadata">The images matadata to preload.</param>
@ -29,38 +25,38 @@ namespace ImageSharp
/// The configuration providing initialization code which allows extending the library. /// The configuration providing initialization code which allows extending the library.
/// </param> /// </param>
/// <returns> /// <returns>
/// A new <see cref="Image{TColor}"/> unless <typeparamref name="TColor"/> is <see cref="Color"/> in which case it returns <see cref="Image" /> /// A new <see cref="Image{TPixel}"/> unless <typeparamref name="TPixel"/> is <see cref="Rgba32"/> in which case it returns <see cref="Image" />
/// </returns> /// </returns>
internal static Image<TColor> Create<TColor>(int width, int height, ImageMetaData metadata, Configuration configuration) internal static Image<TPixel> Create<TPixel>(int width, int height, ImageMetaData metadata, Configuration configuration)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
if (typeof(TColor) == typeof(Color)) if (typeof(TPixel) == typeof(Rgba32))
{ {
return new Image(width, height, metadata, configuration) as Image<TColor>; return new Image(width, height, metadata, configuration) as Image<TPixel>;
} }
else else
{ {
return new Image<TColor>(width, height, metadata, configuration); return new Image<TPixel>(width, height, metadata, configuration);
} }
} }
/// <summary> /// <summary>
/// Create a new instance of the <see cref="Image{TColor}"/> class /// Create a new instance of the <see cref="Image{TPixel}"/> class
/// with the height and the width of the image. /// with the height and the width of the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="width">The width of the image in pixels.</param> /// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param> /// <param name="height">The height of the image in pixels.</param>
/// <param name="configuration"> /// <param name="configuration">
/// The configuration providing initialization code which allows extending the library. /// The configuration providing initialization code which allows extending the library.
/// </param> /// </param>
/// <returns> /// <returns>
/// A new <see cref="Image{TColor}"/> unless <typeparamref name="TColor"/> is <see cref="Color"/> in which case it returns <see cref="Image" /> /// A new <see cref="Image{TPixel}"/> unless <typeparamref name="TPixel"/> is <see cref="Rgba32"/> in which case it returns <see cref="Image" />
/// </returns> /// </returns>
internal static Image<TColor> Create<TColor>(int width, int height, Configuration configuration) internal static Image<TPixel> Create<TPixel>(int width, int height, Configuration configuration)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Image.Create<TColor>(width, height, null, configuration); return Image.Create<TPixel>(width, height, null, configuration);
} }
} }
} }

10
src/ImageSharp/Image.Decode.cs

@ -10,6 +10,8 @@ namespace ImageSharp
using System.Linq; using System.Linq;
using Formats; using Formats;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha /// 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. /// packed into a single unsigned integer value.
@ -51,15 +53,15 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Decodes the image stream to the current image. /// Decodes the image stream to the current image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="stream">The stream.</param> /// <param name="stream">The stream.</param>
/// <param name="options">The options for the decoder.</param> /// <param name="options">The options for the decoder.</param>
/// <param name="config">the configuration.</param> /// <param name="config">the configuration.</param>
/// <returns> /// <returns>
/// The decoded image /// The decoded image
/// </returns> /// </returns>
private static Image<TColor> Decode<TColor>(Stream stream, IDecoderOptions options, Configuration config) private static Image<TPixel> Decode<TPixel>(Stream stream, IDecoderOptions options, Configuration config)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
IImageFormat format = DiscoverFormat(stream, config); IImageFormat format = DiscoverFormat(stream, config);
if (format == null) if (format == null)
@ -67,7 +69,7 @@ namespace ImageSharp
return null; return null;
} }
Image<TColor> img = format.Decoder.Decode<TColor>(config, stream, options); Image<TPixel> img = format.Decoder.Decode<TPixel>(config, stream, options);
img.CurrentImageFormat = format; img.CurrentImageFormat = format;
return img; return img;
} }

50
src/ImageSharp/Image.FromBytes.cs

@ -9,6 +9,8 @@ namespace ImageSharp
using System.IO; using System.IO;
using Formats; using Formats;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha /// 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. /// packed into a single unsigned integer value.
@ -109,70 +111,70 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Loads the image from the given byte array. /// Loads the image from the given byte array.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="data">The byte array containing image data.</param> /// <param name="data">The byte array containing image data.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(byte[] data) public static Image<TPixel> Load<TPixel>(byte[] data)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Load<TColor>(null, data, null); return Load<TPixel>(null, data, null);
} }
/// <summary> /// <summary>
/// Loads the image from the given byte array. /// Loads the image from the given byte array.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="data">The byte array containing image data.</param> /// <param name="data">The byte array containing image data.</param>
/// <param name="options">The options for the decoder.</param> /// <param name="options">The options for the decoder.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(byte[] data, IDecoderOptions options) public static Image<TPixel> Load<TPixel>(byte[] data, IDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Load<TColor>(null, data, options); return Load<TPixel>(null, data, options);
} }
/// <summary> /// <summary>
/// Loads the image from the given byte array. /// Loads the image from the given byte array.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="config">The config for the decoder.</param> /// <param name="config">The config for the decoder.</param>
/// <param name="data">The byte array containing image data.</param> /// <param name="data">The byte array containing image data.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(Configuration config, byte[] data) public static Image<TPixel> Load<TPixel>(Configuration config, byte[] data)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Load<TColor>(config, data, null); return Load<TPixel>(config, data, null);
} }
/// <summary> /// <summary>
/// Loads the image from the given byte array. /// Loads the image from the given byte array.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="data">The byte array containing image data.</param> /// <param name="data">The byte array containing image data.</param>
/// <param name="decoder">The decoder.</param> /// <param name="decoder">The decoder.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(byte[] data, IImageDecoder decoder) public static Image<TPixel> Load<TPixel>(byte[] data, IImageDecoder decoder)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Load<TColor>(data, decoder, null); return Load<TPixel>(data, decoder, null);
} }
/// <summary> /// <summary>
/// Loads the image from the given byte array. /// Loads the image from the given byte array.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="config">The configuration options.</param> /// <param name="config">The configuration options.</param>
/// <param name="data">The byte array containing image data.</param> /// <param name="data">The byte array containing image data.</param>
/// <param name="options">The options for the decoder.</param> /// <param name="options">The options for the decoder.</param>
@ -180,19 +182,19 @@ namespace ImageSharp
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(Configuration config, byte[] data, IDecoderOptions options) public static Image<TPixel> Load<TPixel>(Configuration config, byte[] data, IDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
using (MemoryStream ms = new MemoryStream(data)) using (MemoryStream ms = new MemoryStream(data))
{ {
return Load<TColor>(config, ms, options); return Load<TPixel>(config, ms, options);
} }
} }
/// <summary> /// <summary>
/// Loads the image from the given byte array. /// Loads the image from the given byte array.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="data">The byte array containing image data.</param> /// <param name="data">The byte array containing image data.</param>
/// <param name="decoder">The decoder.</param> /// <param name="decoder">The decoder.</param>
/// <param name="options">The options for the decoder.</param> /// <param name="options">The options for the decoder.</param>
@ -200,12 +202,12 @@ namespace ImageSharp
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(byte[] data, IImageDecoder decoder, IDecoderOptions options) public static Image<TPixel> Load<TPixel>(byte[] data, IImageDecoder decoder, IDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
using (MemoryStream ms = new MemoryStream(data)) using (MemoryStream ms = new MemoryStream(data))
{ {
return Load<TColor>(ms, decoder, options); return Load<TPixel>(ms, decoder, options);
} }
} }
} }

51
src/ImageSharp/Image.FromFile.cs

@ -9,6 +9,7 @@ namespace ImageSharp
using System; using System;
using System.IO; using System.IO;
using Formats; using Formats;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha /// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha
@ -83,7 +84,7 @@ namespace ImageSharp
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image Load(string path, IImageDecoder decoder, IDecoderOptions options) public static Image Load(string path, IImageDecoder decoder, IDecoderOptions options)
{ {
return new Image(Load<Color>(path, decoder, options)); return new Image(Load<Rgba32>(path, decoder, options));
} }
/// <summary> /// <summary>
@ -108,70 +109,70 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Loads the image from the given file. /// Loads the image from the given file.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="path">The file path to the image.</param> /// <param name="path">The file path to the image.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(string path) public static Image<TPixel> Load<TPixel>(string path)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Load<TColor>(null, path, null); return Load<TPixel>(null, path, null);
} }
/// <summary> /// <summary>
/// Loads the image from the given file. /// Loads the image from the given file.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="path">The file path to the image.</param> /// <param name="path">The file path to the image.</param>
/// <param name="options">The options for the decoder.</param> /// <param name="options">The options for the decoder.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(string path, IDecoderOptions options) public static Image<TPixel> Load<TPixel>(string path, IDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Load<TColor>(null, path, options); return Load<TPixel>(null, path, options);
} }
/// <summary> /// <summary>
/// Loads the image from the given file. /// Loads the image from the given file.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="config">The config for the decoder.</param> /// <param name="config">The config for the decoder.</param>
/// <param name="path">The file path to the image.</param> /// <param name="path">The file path to the image.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(Configuration config, string path) public static Image<TPixel> Load<TPixel>(Configuration config, string path)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Load<TColor>(config, path, null); return Load<TPixel>(config, path, null);
} }
/// <summary> /// <summary>
/// Loads the image from the given file. /// Loads the image from the given file.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="path">The file path to the image.</param> /// <param name="path">The file path to the image.</param>
/// <param name="decoder">The decoder.</param> /// <param name="decoder">The decoder.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(string path, IImageDecoder decoder) public static Image<TPixel> Load<TPixel>(string path, IImageDecoder decoder)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Load<TColor>(path, decoder, null); return Load<TPixel>(path, decoder, null);
} }
/// <summary> /// <summary>
/// Loads the image from the given file. /// Loads the image from the given file.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="config">The configuration options.</param> /// <param name="config">The configuration options.</param>
/// <param name="path">The file path to the image.</param> /// <param name="path">The file path to the image.</param>
/// <param name="options">The options for the decoder.</param> /// <param name="options">The options for the decoder.</param>
@ -179,20 +180,20 @@ namespace ImageSharp
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(Configuration config, string path, IDecoderOptions options) public static Image<TPixel> Load<TPixel>(Configuration config, string path, IDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
config = config ?? Configuration.Default; config = config ?? Configuration.Default;
using (Stream s = config.FileSystem.OpenRead(path)) using (Stream s = config.FileSystem.OpenRead(path))
{ {
return Load<TColor>(config, s, options); return Load<TPixel>(config, s, options);
} }
} }
/// <summary> /// <summary>
/// Loads the image from the given file. /// Loads the image from the given file.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="path">The file path to the image.</param> /// <param name="path">The file path to the image.</param>
/// <param name="decoder">The decoder.</param> /// <param name="decoder">The decoder.</param>
/// <param name="options">The options for the decoder.</param> /// <param name="options">The options for the decoder.</param>
@ -200,13 +201,13 @@ namespace ImageSharp
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(string path, IImageDecoder decoder, IDecoderOptions options) public static Image<TPixel> Load<TPixel>(string path, IImageDecoder decoder, IDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
Configuration config = Configuration.Default; Configuration config = Configuration.Default;
using (Stream s = config.FileSystem.OpenRead(path)) using (Stream s = config.FileSystem.OpenRead(path))
{ {
return Load<TColor>(s, decoder, options); return Load<TPixel>(s, decoder, options);
} }
} }
} }

55
src/ImageSharp/Image.FromStream.cs

@ -7,9 +7,12 @@ namespace ImageSharp
{ {
using System; using System;
using System.IO; using System.IO;
using System.Numerics;
using System.Text; using System.Text;
using Formats; using Formats;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha /// 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. /// packed into a single unsigned integer value.
@ -83,7 +86,7 @@ namespace ImageSharp
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image Load(Configuration config, Stream stream, IDecoderOptions options) public static Image Load(Configuration config, Stream stream, IDecoderOptions options)
{ {
Image<Color> image = Load<Color>(config, stream, options); Image<Rgba32> image = Load<Rgba32>(config, stream, options);
return image as Image ?? new Image(image); return image as Image ?? new Image(image);
} }
@ -100,7 +103,7 @@ namespace ImageSharp
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image Load(Stream stream, IImageDecoder decoder, IDecoderOptions options) public static Image Load(Stream stream, IImageDecoder decoder, IDecoderOptions options)
{ {
Image<Color> image = new Image(Load<Color>(stream, decoder, options)); Image<Rgba32> image = new Image(Load<Rgba32>(stream, decoder, options));
return image as Image ?? new Image(image); return image as Image ?? new Image(image);
} }
@ -108,70 +111,70 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Loads the image from the given stream. /// Loads the image from the given stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="stream">The stream containing image information.</param> /// <param name="stream">The stream containing image information.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(Stream stream) public static Image<TPixel> Load<TPixel>(Stream stream)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Load<TColor>(null, stream, null); return Load<TPixel>(null, stream, null);
} }
/// <summary> /// <summary>
/// Loads the image from the given stream. /// Loads the image from the given stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="stream">The stream containing image information.</param> /// <param name="stream">The stream containing image information.</param>
/// <param name="options">The options for the decoder.</param> /// <param name="options">The options for the decoder.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(Stream stream, IDecoderOptions options) public static Image<TPixel> Load<TPixel>(Stream stream, IDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Load<TColor>(null, stream, options); return Load<TPixel>(null, stream, options);
} }
/// <summary> /// <summary>
/// Loads the image from the given stream. /// Loads the image from the given stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="config">The config for the decoder.</param> /// <param name="config">The config for the decoder.</param>
/// <param name="stream">The stream containing image information.</param> /// <param name="stream">The stream containing image information.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(Configuration config, Stream stream) public static Image<TPixel> Load<TPixel>(Configuration config, Stream stream)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Load<TColor>(config, stream, null); return Load<TPixel>(config, stream, null);
} }
/// <summary> /// <summary>
/// Loads the image from the given stream. /// Loads the image from the given stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="stream">The stream containing image information.</param> /// <param name="stream">The stream containing image information.</param>
/// <param name="decoder">The decoder.</param> /// <param name="decoder">The decoder.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(Stream stream, IImageDecoder decoder) public static Image<TPixel> Load<TPixel>(Stream stream, IImageDecoder decoder)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Load<TColor>(stream, decoder, null); return Load<TPixel>(stream, decoder, null);
} }
/// <summary> /// <summary>
/// Loads the image from the given stream. /// Loads the image from the given stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="stream">The stream containing image information.</param> /// <param name="stream">The stream containing image information.</param>
/// <param name="decoder">The decoder.</param> /// <param name="decoder">The decoder.</param>
/// <param name="options">The options for the decoder.</param> /// <param name="options">The options for the decoder.</param>
@ -179,16 +182,16 @@ namespace ImageSharp
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(Stream stream, IImageDecoder decoder, IDecoderOptions options) public static Image<TPixel> Load<TPixel>(Stream stream, IImageDecoder decoder, IDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return WithSeekableStream(stream, s => decoder.Decode<TColor>(Configuration.Default, s, options)); return WithSeekableStream(stream, s => decoder.Decode<TPixel>(Configuration.Default, s, options));
} }
/// <summary> /// <summary>
/// Loads the image from the given stream. /// Loads the image from the given stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="config">The configuration options.</param> /// <param name="config">The configuration options.</param>
/// <param name="stream">The stream containing image information.</param> /// <param name="stream">The stream containing image information.</param>
/// <param name="options">The options for the decoder.</param> /// <param name="options">The options for the decoder.</param>
@ -196,12 +199,12 @@ namespace ImageSharp
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(Configuration config, Stream stream, IDecoderOptions options) public static Image<TPixel> Load<TPixel>(Configuration config, Stream stream, IDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
config = config ?? Configuration.Default; config = config ?? Configuration.Default;
Image<TColor> img = WithSeekableStream(stream, s => Decode<TColor>(s, options, config)); Image<TPixel> img = WithSeekableStream(stream, s => Decode<TPixel>(s, options, config));
if (img != null) if (img != null)
{ {

11
src/ImageSharp/Image.cs

@ -5,18 +5,15 @@
namespace ImageSharp namespace ImageSharp
{ {
using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using ImageSharp.PixelFormats;
using Formats;
/// <summary> /// <summary>
/// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha /// 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. /// packed into a single unsigned integer value.
/// </summary> /// </summary>
[DebuggerDisplay("Image: {Width}x{Height}")] [DebuggerDisplay("Image: {Width}x{Height}")]
public sealed partial class Image : Image<Color> public sealed partial class Image : Image<Rgba32>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Image"/> class /// Initializes a new instance of the <see cref="Image"/> class
@ -49,7 +46,7 @@ namespace ImageSharp
/// </summary> /// </summary>
/// <param name="other">The other image, where the clone should be made from.</param> /// <param name="other">The other image, where the clone should be made from.</param>
/// <exception cref="System.ArgumentNullException"><paramref name="other"/> is null.</exception> /// <exception cref="System.ArgumentNullException"><paramref name="other"/> is null.</exception>
public Image(Image<Color> other) public Image(Image<Rgba32> other)
: base(other) : base(other)
{ {
} }
@ -69,4 +66,4 @@ namespace ImageSharp
{ {
} }
} }
} }

15
src/ImageSharp/Image/IImageBase{TColor}.cs → src/ImageSharp/Image/IImageBase{TPixel}.cs

@ -1,4 +1,4 @@
// <copyright file="IImageBase{TColor}.cs" company="James Jackson-South"> // <copyright file="IImageBase{TPixel}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
@ -6,20 +6,21 @@
namespace ImageSharp namespace ImageSharp
{ {
using System; using System;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Encapsulates the basic properties and methods required to manipulate images in varying formats. /// Encapsulates the basic properties and methods required to manipulate images in varying formats.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
public interface IImageBase<TColor> : IImageBase, IDisposable public interface IImageBase<TPixel> : IImageBase, IDisposable
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Gets the pixels as an array of the given packed pixel format. /// Gets the pixels as an array of the given packed pixel format.
/// Important. Due to the nature in the way this is constructed do not rely on the length /// Important. Due to the nature in the way this is constructed do not rely on the length
/// of the array for calculations. Use Width * Height. /// of the array for calculations. Use Width * Height.
/// </summary> /// </summary>
TColor[] Pixels { get; } TPixel[] Pixels { get; }
/// <summary> /// <summary>
/// Locks the image providing access to the pixels. /// Locks the image providing access to the pixels.
@ -27,7 +28,7 @@ namespace ImageSharp
/// It is imperative that the accessor is correctly disposed off after use. /// It is imperative that the accessor is correctly disposed off after use.
/// </remarks> /// </remarks>
/// </summary> /// </summary>
/// <returns>The <see cref="PixelAccessor{TColor}"/></returns> /// <returns>The <see cref="PixelAccessor{TPixel}"/></returns>
PixelAccessor<TColor> Lock(); PixelAccessor<TPixel> Lock();
} }
} }

12
src/ImageSharp/Image/IImageProcessor.cs

@ -8,12 +8,14 @@ namespace ImageSharp.Processing
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Encapsulates methods to alter the pixels of an image. /// Encapsulates methods to alter the pixels of an image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
public interface IImageProcessor<TColor> public interface IImageProcessor<TPixel>
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Gets or sets the parallel options for processing tasks in parallel. /// Gets or sets the parallel options for processing tasks in parallel.
@ -27,7 +29,7 @@ namespace ImageSharp.Processing
bool Compand { get; set; } bool Compand { get; set; }
/// <summary> /// <summary>
/// Applies the process to the specified portion of the specified <see cref="ImageBase{TColor}"/>. /// Applies the process to the specified portion of the specified <see cref="ImageBase{TPixel}"/>.
/// </summary> /// </summary>
/// <param name="source">The source image. Cannot be null.</param> /// <param name="source">The source image. Cannot be null.</param>
/// <param name="sourceRectangle"> /// <param name="sourceRectangle">
@ -39,6 +41,6 @@ namespace ImageSharp.Processing
/// <exception cref="System.ArgumentException"> /// <exception cref="System.ArgumentException">
/// <paramref name="sourceRectangle"/> doesnt fit the dimension of the image. /// <paramref name="sourceRectangle"/> doesnt fit the dimension of the image.
/// </exception> /// </exception>
void Apply(ImageBase<TColor> source, Rectangle sourceRectangle); void Apply(ImageBase<TPixel> source, Rectangle sourceRectangle);
} }
} }

43
src/ImageSharp/Image/ImageBase{TColor}.cs → src/ImageSharp/Image/ImageBase{TPixel}.cs

@ -1,4 +1,4 @@
// <copyright file="ImageBase{TColor}.cs" company="James Jackson-South"> // <copyright file="ImageBase{TPixel}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
@ -7,16 +7,17 @@ namespace ImageSharp
{ {
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using ImageSharp.PixelFormats;
using Processing; using Processing;
/// <summary> /// <summary>
/// The base class of all images. Encapsulates the basic properties and methods required to manipulate /// The base class of all images. Encapsulates the basic properties and methods required to manipulate
/// images in different pixel formats. /// images in different pixel formats.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
[DebuggerDisplay("Image: {Width}x{Height}")] [DebuggerDisplay("Image: {Width}x{Height}")]
public abstract class ImageBase<TColor> : IImageBase<TColor> public abstract class ImageBase<TPixel> : IImageBase<TPixel>
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Gets or sets the maximum allowable width in pixels. /// Gets or sets the maximum allowable width in pixels.
@ -31,7 +32,7 @@ namespace ImageSharp
/// <summary> /// <summary>
/// The image pixels /// The image pixels
/// </summary> /// </summary>
private TColor[] pixelBuffer; private TPixel[] pixelBuffer;
/// <summary> /// <summary>
/// A value indicating whether this instance of the given entity has been disposed. /// A value indicating whether this instance of the given entity has been disposed.
@ -45,7 +46,7 @@ namespace ImageSharp
private bool isDisposed; private bool isDisposed;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ImageBase{TColor}"/> class. /// Initializes a new instance of the <see cref="ImageBase{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="configuration"> /// <param name="configuration">
/// The configuration providing initialization code which allows extending the library. /// The configuration providing initialization code which allows extending the library.
@ -56,7 +57,7 @@ namespace ImageSharp
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ImageBase{TColor}"/> class. /// Initializes a new instance of the <see cref="ImageBase{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="width">The width of the image in pixels.</param> /// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param> /// <param name="height">The height of the image in pixels.</param>
@ -79,15 +80,15 @@ namespace ImageSharp
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ImageBase{TColor}"/> class. /// Initializes a new instance of the <see cref="ImageBase{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="other"> /// <param name="other">
/// The other <see cref="ImageBase{TColor}"/> to create this instance from. /// The other <see cref="ImageBase{TPixel}"/> to create this instance from.
/// </param> /// </param>
/// <exception cref="System.ArgumentNullException"> /// <exception cref="System.ArgumentNullException">
/// Thrown if the given <see cref="ImageBase{TColor}"/> is null. /// Thrown if the given <see cref="ImageBase{TPixel}"/> is null.
/// </exception> /// </exception>
protected ImageBase(ImageBase<TColor> other) protected ImageBase(ImageBase<TPixel> other)
: this(other.Configuration) : this(other.Configuration)
{ {
Guard.NotNull(other, nameof(other), "Other image cannot be null."); Guard.NotNull(other, nameof(other), "Other image cannot be null.");
@ -98,8 +99,8 @@ namespace ImageSharp
// Rent then copy the pixels. Unsafe.CopyBlock gives us a nice speed boost here. // Rent then copy the pixels. Unsafe.CopyBlock gives us a nice speed boost here.
this.RentPixels(); this.RentPixels();
using (PixelAccessor<TColor> sourcePixels = other.Lock()) using (PixelAccessor<TPixel> sourcePixels = other.Lock())
using (PixelAccessor<TColor> target = this.Lock()) using (PixelAccessor<TPixel> target = this.Lock())
{ {
// Check we can do this without crashing // Check we can do this without crashing
sourcePixels.CopyTo(target); sourcePixels.CopyTo(target);
@ -107,7 +108,7 @@ namespace ImageSharp
} }
/// <inheritdoc/> /// <inheritdoc/>
public TColor[] Pixels => this.pixelBuffer; public TPixel[] Pixels => this.pixelBuffer;
/// <inheritdoc/> /// <inheritdoc/>
public int Width { get; private set; } public int Width { get; private set; }
@ -131,7 +132,7 @@ namespace ImageSharp
/// </summary> /// </summary>
/// <param name="processor">The processor.</param> /// <param name="processor">The processor.</param>
/// <param name="rectangle">The rectangle.</param> /// <param name="rectangle">The rectangle.</param>
public virtual void ApplyProcessor(IImageProcessor<TColor> processor, Rectangle rectangle) public virtual void ApplyProcessor(IImageProcessor<TPixel> processor, Rectangle rectangle)
{ {
processor.Apply(this, rectangle); processor.Apply(this, rectangle);
} }
@ -150,16 +151,16 @@ namespace ImageSharp
} }
/// <inheritdoc/> /// <inheritdoc/>
public PixelAccessor<TColor> Lock() public PixelAccessor<TPixel> Lock()
{ {
return new PixelAccessor<TColor>(this); return new PixelAccessor<TPixel>(this);
} }
/// <summary> /// <summary>
/// Switches the buffers used by the image and the PixelAccessor meaning that the Image will "own" the buffer from the PixelAccessor and the PixelAccessor will now own the Images buffer. /// Switches the buffers used by the image and the PixelAccessor meaning that the Image will "own" the buffer from the PixelAccessor and the PixelAccessor will now own the Images buffer.
/// </summary> /// </summary>
/// <param name="pixelSource">The pixel source.</param> /// <param name="pixelSource">The pixel source.</param>
internal void SwapPixelsBuffers(PixelAccessor<TColor> pixelSource) internal void SwapPixelsBuffers(PixelAccessor<TPixel> pixelSource)
{ {
Guard.NotNull(pixelSource, nameof(pixelSource)); Guard.NotNull(pixelSource, nameof(pixelSource));
@ -167,7 +168,7 @@ namespace ImageSharp
int newHeight = pixelSource.Height; int newHeight = pixelSource.Height;
// Push my memory into the accessor (which in turn unpins the old puffer ready for the images use) // Push my memory into the accessor (which in turn unpins the old puffer ready for the images use)
TColor[] newPixels = pixelSource.ReturnCurrentPixelsAndReplaceThemInternally(this.Width, this.Height, this.pixelBuffer); TPixel[] newPixels = pixelSource.ReturnCurrentColorsAndReplaceThemInternally(this.Width, this.Height, this.pixelBuffer);
this.Width = newWidth; this.Width = newWidth;
this.Height = newHeight; this.Height = newHeight;
this.pixelBuffer = newPixels; this.pixelBuffer = newPixels;
@ -221,7 +222,7 @@ namespace ImageSharp
/// </summary> /// </summary>
private void RentPixels() private void RentPixels()
{ {
this.pixelBuffer = PixelDataPool<TColor>.Rent(this.Width * this.Height); this.pixelBuffer = PixelDataPool<TPixel>.Rent(this.Width * this.Height);
} }
/// <summary> /// <summary>
@ -229,7 +230,7 @@ namespace ImageSharp
/// </summary> /// </summary>
private void ReturnPixels() private void ReturnPixels()
{ {
PixelDataPool<TColor>.Return(this.pixelBuffer); PixelDataPool<TPixel>.Return(this.pixelBuffer);
this.pixelBuffer = null; this.pixelBuffer = null;
} }

39
src/ImageSharp/Image/ImageFrame{TColor}.cs → src/ImageSharp/Image/ImageFrame{TPixel}.cs

@ -1,4 +1,4 @@
// <copyright file="ImageFrame{TColor}.cs" company="James Jackson-South"> // <copyright file="ImageFrame{TPixel}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
@ -8,16 +8,17 @@ namespace ImageSharp
using System; using System;
using System.Numerics; using System.Numerics;
using System.Threading.Tasks; using System.Threading.Tasks;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Represents a single frame in a animation. /// Represents a single frame in a animation.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
public class ImageFrame<TColor> : ImageBase<TColor>, IImageFrame public class ImageFrame<TPixel> : ImageBase<TPixel>, IImageFrame
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ImageFrame{TColor}"/> class. /// Initializes a new instance of the <see cref="ImageFrame{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="width">The width of the image in pixels.</param> /// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param> /// <param name="height">The height of the image in pixels.</param>
@ -30,10 +31,10 @@ namespace ImageSharp
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ImageFrame{TColor}"/> class. /// Initializes a new instance of the <see cref="ImageFrame{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="image">The image to create the frame from.</param> /// <param name="image">The image to create the frame from.</param>
public ImageFrame(ImageBase<TColor> image) public ImageFrame(ImageBase<TPixel> image)
: base(image) : base(image)
{ {
} }
@ -53,18 +54,18 @@ namespace ImageSharp
/// Returns a copy of the image frame in the given pixel format. /// Returns a copy of the image frame in the given pixel format.
/// </summary> /// </summary>
/// <param name="scaleFunc">A function that allows for the correction of vector scaling between unknown color formats.</param> /// <param name="scaleFunc">A function that allows for the correction of vector scaling between unknown color formats.</param>
/// <typeparam name="TColor2">The pixel format.</typeparam> /// <typeparam name="TPixel2">The pixel format.</typeparam>
/// <returns>The <see cref="ImageFrame{TColor2}"/></returns> /// <returns>The <see cref="ImageFrame{TPixel2}"/></returns>
public ImageFrame<TColor2> To<TColor2>(Func<Vector4, Vector4> scaleFunc = null) public ImageFrame<TPixel2> To<TPixel2>(Func<Vector4, Vector4> scaleFunc = null)
where TColor2 : struct, IPixel<TColor2> where TPixel2 : struct, IPixel<TPixel2>
{ {
scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction<TColor, TColor2>(scaleFunc); scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction<TPixel, TPixel2>(scaleFunc);
ImageFrame<TColor2> target = new ImageFrame<TColor2>(this.Width, this.Height, this.Configuration); ImageFrame<TPixel2> target = new ImageFrame<TPixel2>(this.Width, this.Height, this.Configuration);
target.CopyProperties(this); target.CopyProperties(this);
using (PixelAccessor<TColor> pixels = this.Lock()) using (PixelAccessor<TPixel> pixels = this.Lock())
using (PixelAccessor<TColor2> targetPixels = target.Lock()) using (PixelAccessor<TPixel2> targetPixels = target.Lock())
{ {
Parallel.For( Parallel.For(
0, 0,
@ -74,7 +75,7 @@ namespace ImageSharp
{ {
for (int x = 0; x < target.Width; x++) for (int x = 0; x < target.Width; x++)
{ {
TColor2 color = default(TColor2); TPixel2 color = default(TPixel2);
color.PackFromVector4(scaleFunc(pixels[x, y].ToVector4())); color.PackFromVector4(scaleFunc(pixels[x, y].ToVector4()));
targetPixels[x, y] = color; targetPixels[x, y] = color;
} }
@ -87,10 +88,10 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Clones the current instance. /// Clones the current instance.
/// </summary> /// </summary>
/// <returns>The <see cref="ImageFrame{TColor}"/></returns> /// <returns>The <see cref="ImageFrame{TPixel}"/></returns>
internal virtual ImageFrame<TColor> Clone() internal virtual ImageFrame<TPixel> Clone()
{ {
return new ImageFrame<TColor>(this); return new ImageFrame<TPixel>(this);
} }
/// <summary> /// <summary>

13
src/ImageSharp/Image/ImageProcessingExtensions.cs

@ -5,11 +5,12 @@
namespace ImageSharp namespace ImageSharp
{ {
using System; using ImageSharp.PixelFormats;
using Processing; using Processing;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
@ -17,12 +18,12 @@ namespace ImageSharp
/// Applies the processor to the image. /// Applies the processor to the image.
/// <remarks>This method does not resize the target image.</remarks> /// <remarks>This method does not resize the target image.</remarks>
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="processor">The processor to apply to the image.</param> /// <param name="processor">The processor to apply to the image.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Apply<TColor>(this Image<TColor> source, IImageProcessor<TColor> processor) public static Image<TPixel> Apply<TPixel>(this Image<TPixel> source, IImageProcessor<TPixel> processor)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
source.ApplyProcessor(processor, source.Bounds); source.ApplyProcessor(processor, source.Bounds);
return source; return source;

111
src/ImageSharp/Image/Image{TColor}.cs → src/ImageSharp/Image/Image{TPixel}.cs

@ -1,4 +1,4 @@
// <copyright file="Image{TColor}.cs" company="James Jackson-South"> // <copyright file="Image{TPixel}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
@ -6,28 +6,27 @@
namespace ImageSharp namespace ImageSharp
{ {
using System; using System;
using System.Buffers;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Formats; using Formats;
using ImageSharp.PixelFormats;
using Processing; using Processing;
/// <summary> /// <summary>
/// Encapsulates an image, which consists of the pixel data for a graphics image and its attributes. /// Encapsulates an image, which consists of the pixel data for a graphics image and its attributes.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
[DebuggerDisplay("Image: {Width}x{Height}")] [DebuggerDisplay("Image: {Width}x{Height}")]
public class Image<TColor> : ImageBase<TColor>, IImage public class Image<TPixel> : ImageBase<TPixel>, IImage
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Image{TColor}"/> class /// Initializes a new instance of the <see cref="Image{TPixel}"/> class
/// with the height and the width of the image. /// with the height and the width of the image.
/// </summary> /// </summary>
/// <param name="width">The width of the image in pixels.</param> /// <param name="width">The width of the image in pixels.</param>
@ -41,7 +40,7 @@ namespace ImageSharp
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Image{TColor}"/> class /// Initializes a new instance of the <see cref="Image{TPixel}"/> class
/// with the height and the width of the image. /// with the height and the width of the image.
/// </summary> /// </summary>
/// <param name="width">The width of the image in pixels.</param> /// <param name="width">The width of the image in pixels.</param>
@ -52,19 +51,19 @@ namespace ImageSharp
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Image{TColor}"/> class /// Initializes a new instance of the <see cref="Image{TPixel}"/> class
/// by making a copy from another image. /// by making a copy from another image.
/// </summary> /// </summary>
/// <param name="other">The other image, where the clone should be made from.</param> /// <param name="other">The other image, where the clone should be made from.</param>
/// <exception cref="System.ArgumentNullException"><paramref name="other"/> is null.</exception> /// <exception cref="System.ArgumentNullException"><paramref name="other"/> is null.</exception>
public Image(Image<TColor> other) public Image(Image<TPixel> other)
: base(other) : base(other)
{ {
foreach (ImageFrame<TColor> frame in other.Frames) foreach (ImageFrame<TPixel> frame in other.Frames)
{ {
if (frame != null) if (frame != null)
{ {
this.Frames.Add(new ImageFrame<TColor>(frame)); this.Frames.Add(new ImageFrame<TPixel>(frame));
} }
} }
@ -72,19 +71,19 @@ namespace ImageSharp
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Image{TColor}"/> class /// Initializes a new instance of the <see cref="Image{TPixel}"/> class
/// by making a copy from another image. /// by making a copy from another image.
/// </summary> /// </summary>
/// <param name="other">The other image, where the clone should be made from.</param> /// <param name="other">The other image, where the clone should be made from.</param>
/// <exception cref="System.ArgumentNullException"><paramref name="other"/> is null.</exception> /// <exception cref="System.ArgumentNullException"><paramref name="other"/> is null.</exception>
public Image(ImageBase<TColor> other) public Image(ImageBase<TPixel> other)
: base(other) : base(other)
{ {
this.MetaData = new ImageMetaData(); this.MetaData = new ImageMetaData();
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Image{TColor}"/> class /// Initializes a new instance of the <see cref="Image{TPixel}"/> class
/// with the height and the width of the image. /// with the height and the width of the image.
/// </summary> /// </summary>
/// <param name="width">The width of the image in pixels.</param> /// <param name="width">The width of the image in pixels.</param>
@ -138,7 +137,7 @@ namespace ImageSharp
/// Gets the other frames for the animation. /// Gets the other frames for the animation.
/// </summary> /// </summary>
/// <value>The list of frame images.</value> /// <value>The list of frame images.</value>
public IList<ImageFrame<TColor>> Frames { get; } = new List<ImageFrame<TColor>>(); public IList<ImageFrame<TPixel>> Frames { get; } = new List<ImageFrame<TPixel>>();
/// <summary> /// <summary>
/// Gets the currently loaded image format. /// Gets the currently loaded image format.
@ -150,11 +149,11 @@ namespace ImageSharp
/// </summary> /// </summary>
/// <param name="processor">The processor to apply to the image.</param> /// <param name="processor">The processor to apply to the image.</param>
/// <param name="rectangle">The <see cref="Rectangle" /> structure that specifies the portion of the image object to draw.</param> /// <param name="rectangle">The <see cref="Rectangle" /> structure that specifies the portion of the image object to draw.</param>
public override void ApplyProcessor(IImageProcessor<TColor> processor, Rectangle rectangle) public override void ApplyProcessor(IImageProcessor<TPixel> processor, Rectangle rectangle)
{ {
// we want to put this on on here as it gives us a really go place to test/verify processor settings // we want to put this on on here as it gives us a really go place to test/verify processor settings
base.ApplyProcessor(processor, rectangle); base.ApplyProcessor(processor, rectangle);
foreach (ImageFrame<TColor> sourceFrame in this.Frames) foreach (ImageFrame<TPixel> sourceFrame in this.Frames)
{ {
sourceFrame.ApplyProcessor(processor, rectangle); sourceFrame.ApplyProcessor(processor, rectangle);
} }
@ -165,8 +164,8 @@ namespace ImageSharp
/// </summary> /// </summary>
/// <param name="stream">The stream to save the image to.</param> /// <param name="stream">The stream to save the image to.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns>The <see cref="Image{TColor}"/></returns> /// <returns>The <see cref="Image{TPixel}"/></returns>
public Image<TColor> Save(Stream stream) public Image<TPixel> Save(Stream stream)
{ {
return this.Save(stream, (IEncoderOptions)null); return this.Save(stream, (IEncoderOptions)null);
} }
@ -177,8 +176,8 @@ namespace ImageSharp
/// <param name="stream">The stream to save the image to.</param> /// <param name="stream">The stream to save the image to.</param>
/// <param name="options">The options for the encoder.</param> /// <param name="options">The options for the encoder.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns>The <see cref="Image{TColor}"/></returns> /// <returns>The <see cref="Image{TPixel}"/></returns>
public Image<TColor> Save(Stream stream, IEncoderOptions options) public Image<TPixel> Save(Stream stream, IEncoderOptions options)
{ {
return this.Save(stream, this.CurrentImageFormat?.Encoder, options); return this.Save(stream, this.CurrentImageFormat?.Encoder, options);
} }
@ -188,8 +187,8 @@ namespace ImageSharp
/// </summary> /// </summary>
/// <param name="stream">The stream to save the image to.</param> /// <param name="stream">The stream to save the image to.</param>
/// <param name="format">The format to save the image as.</param> /// <param name="format">The format to save the image as.</param>
/// <returns>The <see cref="Image{TColor}"/></returns> /// <returns>The <see cref="Image{TPixel}"/></returns>
public Image<TColor> Save(Stream stream, IImageFormat format) public Image<TPixel> Save(Stream stream, IImageFormat format)
{ {
return this.Save(stream, format, null); return this.Save(stream, format, null);
} }
@ -200,8 +199,8 @@ namespace ImageSharp
/// <param name="stream">The stream to save the image to.</param> /// <param name="stream">The stream to save the image to.</param>
/// <param name="format">The format to save the image as.</param> /// <param name="format">The format to save the image as.</param>
/// <param name="options">The options for the encoder.</param> /// <param name="options">The options for the encoder.</param>
/// <returns>The <see cref="Image{TColor}"/></returns> /// <returns>The <see cref="Image{TPixel}"/></returns>
public Image<TColor> Save(Stream stream, IImageFormat format, IEncoderOptions options) public Image<TPixel> Save(Stream stream, IImageFormat format, IEncoderOptions options)
{ {
Guard.NotNull(format, nameof(format)); Guard.NotNull(format, nameof(format));
@ -215,9 +214,9 @@ namespace ImageSharp
/// <param name="encoder">The encoder to save the image with.</param> /// <param name="encoder">The encoder to save the image with.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream or encoder is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the stream or encoder is null.</exception>
/// <returns> /// <returns>
/// The <see cref="Image{TColor}"/>. /// The <see cref="Image{TPixel}"/>.
/// </returns> /// </returns>
public Image<TColor> Save(Stream stream, IImageEncoder encoder) public Image<TPixel> Save(Stream stream, IImageEncoder encoder)
{ {
return this.Save(stream, encoder, null); return this.Save(stream, encoder, null);
} }
@ -230,9 +229,9 @@ namespace ImageSharp
/// <param name="options">The options for the encoder.</param> /// <param name="options">The options for the encoder.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream or encoder is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the stream or encoder is null.</exception>
/// <returns> /// <returns>
/// The <see cref="Image{TColor}"/>. /// The <see cref="Image{TPixel}"/>.
/// </returns> /// </returns>
public Image<TColor> Save(Stream stream, IImageEncoder encoder, IEncoderOptions options) public Image<TPixel> Save(Stream stream, IImageEncoder encoder, IEncoderOptions options)
{ {
Guard.NotNull(stream, nameof(stream)); Guard.NotNull(stream, nameof(stream));
Guard.NotNull(encoder, nameof(encoder)); Guard.NotNull(encoder, nameof(encoder));
@ -248,8 +247,8 @@ namespace ImageSharp
/// </summary> /// </summary>
/// <param name="filePath">The file path to save the image to.</param> /// <param name="filePath">The file path to save the image to.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns>The <see cref="Image{TColor}"/></returns> /// <returns>The <see cref="Image{TPixel}"/></returns>
public Image<TColor> Save(string filePath) public Image<TPixel> Save(string filePath)
{ {
return this.Save(filePath, (IEncoderOptions)null); return this.Save(filePath, (IEncoderOptions)null);
} }
@ -260,8 +259,8 @@ namespace ImageSharp
/// <param name="filePath">The file path to save the image to.</param> /// <param name="filePath">The file path to save the image to.</param>
/// <param name="options">The options for the encoder.</param> /// <param name="options">The options for the encoder.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns>The <see cref="Image{TColor}"/></returns> /// <returns>The <see cref="Image{TPixel}"/></returns>
public Image<TColor> Save(string filePath, IEncoderOptions options) public Image<TPixel> Save(string filePath, IEncoderOptions options)
{ {
string ext = Path.GetExtension(filePath).Trim('.'); string ext = Path.GetExtension(filePath).Trim('.');
IImageFormat format = this.Configuration.ImageFormats.SingleOrDefault(f => f.SupportedExtensions.Contains(ext, StringComparer.OrdinalIgnoreCase)); IImageFormat format = this.Configuration.ImageFormats.SingleOrDefault(f => f.SupportedExtensions.Contains(ext, StringComparer.OrdinalIgnoreCase));
@ -279,8 +278,8 @@ namespace ImageSharp
/// <param name="filePath">The file path to save the image to.</param> /// <param name="filePath">The file path to save the image to.</param>
/// <param name="format">The format to save the image as.</param> /// <param name="format">The format to save the image as.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the format is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the format is null.</exception>
/// <returns>The <see cref="Image{TColor}"/></returns> /// <returns>The <see cref="Image{TPixel}"/></returns>
public Image<TColor> Save(string filePath, IImageFormat format) public Image<TPixel> Save(string filePath, IImageFormat format)
{ {
return this.Save(filePath, format, null); return this.Save(filePath, format, null);
} }
@ -292,8 +291,8 @@ namespace ImageSharp
/// <param name="format">The format to save the image as.</param> /// <param name="format">The format to save the image as.</param>
/// <param name="options">The options for the encoder.</param> /// <param name="options">The options for the encoder.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the format is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the format is null.</exception>
/// <returns>The <see cref="Image{TColor}"/></returns> /// <returns>The <see cref="Image{TPixel}"/></returns>
public Image<TColor> Save(string filePath, IImageFormat format, IEncoderOptions options) public Image<TPixel> Save(string filePath, IImageFormat format, IEncoderOptions options)
{ {
Guard.NotNull(format, nameof(format)); Guard.NotNull(format, nameof(format));
return this.Save(filePath, format.Encoder, options); return this.Save(filePath, format.Encoder, options);
@ -305,8 +304,8 @@ namespace ImageSharp
/// <param name="filePath">The file path to save the image to.</param> /// <param name="filePath">The file path to save the image to.</param>
/// <param name="encoder">The encoder to save the image with.</param> /// <param name="encoder">The encoder to save the image with.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the encoder is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the encoder is null.</exception>
/// <returns>The <see cref="Image{TColor}"/></returns> /// <returns>The <see cref="Image{TPixel}"/></returns>
public Image<TColor> Save(string filePath, IImageEncoder encoder) public Image<TPixel> Save(string filePath, IImageEncoder encoder)
{ {
return this.Save(filePath, encoder, null); return this.Save(filePath, encoder, null);
} }
@ -318,8 +317,8 @@ namespace ImageSharp
/// <param name="encoder">The encoder to save the image with.</param> /// <param name="encoder">The encoder to save the image with.</param>
/// <param name="options">The options for the encoder.</param> /// <param name="options">The options for the encoder.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the encoder is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the encoder is null.</exception>
/// <returns>The <see cref="Image{TColor}"/></returns> /// <returns>The <see cref="Image{TPixel}"/></returns>
public Image<TColor> Save(string filePath, IImageEncoder encoder, IEncoderOptions options) public Image<TPixel> Save(string filePath, IImageEncoder encoder, IEncoderOptions options)
{ {
Guard.NotNull(encoder, nameof(encoder)); Guard.NotNull(encoder, nameof(encoder));
using (Stream fs = this.Configuration.FileSystem.Create(filePath)) using (Stream fs = this.Configuration.FileSystem.Create(filePath))
@ -354,18 +353,18 @@ namespace ImageSharp
/// Returns a copy of the image in the given pixel format. /// Returns a copy of the image in the given pixel format.
/// </summary> /// </summary>
/// <param name="scaleFunc">A function that allows for the correction of vector scaling between unknown color formats.</param> /// <param name="scaleFunc">A function that allows for the correction of vector scaling between unknown color formats.</param>
/// <typeparam name="TColor2">The pixel format.</typeparam> /// <typeparam name="TPixel2">The pixel format.</typeparam>
/// <returns>The <see cref="Image{TColor2}"/></returns> /// <returns>The <see cref="Image{TPixel2}"/></returns>
public Image<TColor2> To<TColor2>(Func<Vector4, Vector4> scaleFunc = null) public Image<TPixel2> To<TPixel2>(Func<Vector4, Vector4> scaleFunc = null)
where TColor2 : struct, IPixel<TColor2> where TPixel2 : struct, IPixel<TPixel2>
{ {
scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction<TColor, TColor2>(scaleFunc); scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction<TPixel, TPixel2>(scaleFunc);
Image<TColor2> target = new Image<TColor2>(this.Width, this.Height, this.Configuration); Image<TPixel2> target = new Image<TPixel2>(this.Width, this.Height, this.Configuration);
target.CopyProperties(this); target.CopyProperties(this);
using (PixelAccessor<TColor> pixels = this.Lock()) using (PixelAccessor<TPixel> pixels = this.Lock())
using (PixelAccessor<TColor2> targetPixels = target.Lock()) using (PixelAccessor<TPixel2> targetPixels = target.Lock())
{ {
Parallel.For( Parallel.For(
0, 0,
@ -375,7 +374,7 @@ namespace ImageSharp
{ {
for (int x = 0; x < target.Width; x++) for (int x = 0; x < target.Width; x++)
{ {
TColor2 color = default(TColor2); TPixel2 color = default(TPixel2);
color.PackFromVector4(scaleFunc(pixels[x, y].ToVector4())); color.PackFromVector4(scaleFunc(pixels[x, y].ToVector4()));
targetPixels[x, y] = color; targetPixels[x, y] = color;
} }
@ -384,19 +383,19 @@ namespace ImageSharp
for (int i = 0; i < this.Frames.Count; i++) for (int i = 0; i < this.Frames.Count; i++)
{ {
target.Frames.Add(this.Frames[i].To<TColor2>()); target.Frames.Add(this.Frames[i].To<TPixel2>());
} }
return target; return target;
} }
/// <summary> /// <summary>
/// Creates a new <see cref="ImageFrame{TColor}"/> from this instance /// Creates a new <see cref="ImageFrame{TPixel}"/> from this instance
/// </summary> /// </summary>
/// <returns>The <see cref="ImageFrame{TColor}"/></returns> /// <returns>The <see cref="ImageFrame{TPixel}"/></returns>
internal virtual ImageFrame<TColor> ToFrame() internal virtual ImageFrame<TPixel> ToFrame()
{ {
return new ImageFrame<TColor>(this); return new ImageFrame<TPixel>(this);
} }
/// <inheritdoc /> /// <inheritdoc />

98
src/ImageSharp/Image/PixelAccessor{TColor}.cs → src/ImageSharp/Image/PixelAccessor{TPixel}.cs

@ -1,4 +1,4 @@
// <copyright file="PixelAccessor{TColor}.cs" company="James Jackson-South"> // <copyright file="PixelAccessor{TPixel}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
@ -8,15 +8,15 @@ namespace ImageSharp
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Provides per-pixel access to generic <see cref="Image{TColor}"/> pixels. /// Provides per-pixel access to generic <see cref="Image{TPixel}"/> pixels.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
public sealed class PixelAccessor<TColor> : IDisposable, IBuffer2D<TColor> public sealed class PixelAccessor<TPixel> : IDisposable, IBuffer2D<TPixel>
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// A value indicating whether this instance of the given entity has been disposed. /// A value indicating whether this instance of the given entity has been disposed.
@ -32,13 +32,13 @@ namespace ImageSharp
/// <summary> /// <summary>
/// The <see cref="Buffer{T}"/> containing the pixel data. /// The <see cref="Buffer{T}"/> containing the pixel data.
/// </summary> /// </summary>
private Buffer2D<TColor> pixelBuffer; private Buffer2D<TPixel> pixelBuffer;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PixelAccessor{TColor}"/> class. /// Initializes a new instance of the <see cref="PixelAccessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="image">The image to provide pixel access for.</param> /// <param name="image">The image to provide pixel access for.</param>
public PixelAccessor(ImageBase<TColor> image) public PixelAccessor(ImageBase<TPixel> image)
{ {
Guard.NotNull(image, nameof(image)); Guard.NotNull(image, nameof(image));
Guard.MustBeGreaterThan(image.Width, 0, "image width"); Guard.MustBeGreaterThan(image.Width, 0, "image width");
@ -49,22 +49,22 @@ namespace ImageSharp
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PixelAccessor{TColor}"/> class. /// Initializes a new instance of the <see cref="PixelAccessor{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="width">The width of the image represented by the pixel buffer.</param> /// <param name="width">The width of the image represented by the pixel buffer.</param>
/// <param name="height">The height of the image represented by the pixel buffer.</param> /// <param name="height">The height of the image represented by the pixel buffer.</param>
public PixelAccessor(int width, int height) public PixelAccessor(int width, int height)
: this(width, height, Buffer2D<TColor>.CreateClean(width, height)) : this(width, height, Buffer2D<TPixel>.CreateClean(width, height))
{ {
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PixelAccessor{TColor}" /> class. /// Initializes a new instance of the <see cref="PixelAccessor{TPixel}" /> class.
/// </summary> /// </summary>
/// <param name="width">The width of the image represented by the pixel buffer.</param> /// <param name="width">The width of the image represented by the pixel buffer.</param>
/// <param name="height">The height of the image represented by the pixel buffer.</param> /// <param name="height">The height of the image represented by the pixel buffer.</param>
/// <param name="pixels">The pixel buffer.</param> /// <param name="pixels">The pixel buffer.</param>
private PixelAccessor(int width, int height, Buffer2D<TColor> pixels) private PixelAccessor(int width, int height, Buffer2D<TPixel> pixels)
{ {
Guard.NotNull(pixels, nameof(pixels)); Guard.NotNull(pixels, nameof(pixels));
Guard.MustBeGreaterThan(width, 0, nameof(width)); Guard.MustBeGreaterThan(width, 0, nameof(width));
@ -76,7 +76,7 @@ namespace ImageSharp
} }
/// <summary> /// <summary>
/// Finalizes an instance of the <see cref="PixelAccessor{TColor}"/> class. /// Finalizes an instance of the <see cref="PixelAccessor{TPixel}"/> class.
/// </summary> /// </summary>
~PixelAccessor() ~PixelAccessor()
{ {
@ -86,7 +86,7 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Gets the pixel buffer array. /// Gets the pixel buffer array.
/// </summary> /// </summary>
public TColor[] PixelArray => this.pixelBuffer.Array; public TPixel[] PixelArray => this.pixelBuffer.Array;
/// <summary> /// <summary>
/// Gets the size of a single pixel in the number of bytes. /// Gets the size of a single pixel in the number of bytes.
@ -114,17 +114,17 @@ namespace ImageSharp
public ParallelOptions ParallelOptions { get; } public ParallelOptions ParallelOptions { get; }
/// <inheritdoc /> /// <inheritdoc />
BufferSpan<TColor> IBuffer2D<TColor>.Span => this.pixelBuffer; BufferSpan<TPixel> IBuffer2D<TPixel>.Span => this.pixelBuffer;
private static BulkPixelOperations<TColor> Operations => BulkPixelOperations<TColor>.Instance; private static BulkPixelOperations<TPixel> Operations => BulkPixelOperations<TPixel>.Instance;
/// <summary> /// <summary>
/// Gets or sets the pixel at the specified position. /// Gets or sets the pixel at the specified position.
/// </summary> /// </summary>
/// <param name="x">The x-coordinate of the pixel. Must be greater than or equal to zero and less than the width of the image.</param> /// <param name="x">The x-coordinate of the pixel. Must be greater than or equal to zero and less than the width of the image.</param>
/// <param name="y">The y-coordinate of the pixel. Must be greater than or equal to zero and less than the height of the image.</param> /// <param name="y">The y-coordinate of the pixel. Must be greater than or equal to zero and less than the height of the image.</param>
/// <returns>The <see typeparam="TColor"/> at the specified position.</returns> /// <returns>The <see typeparam="TPixel"/> at the specified position.</returns>
public TColor this[int x, int y] public TPixel this[int x, int y]
{ {
get get
{ {
@ -179,7 +179,7 @@ namespace ImageSharp
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown when an unsupported component order value is passed. /// Thrown when an unsupported component order value is passed.
/// </exception> /// </exception>
internal void CopyFrom(PixelArea<TColor> area, int targetY, int targetX = 0) internal void CopyFrom(PixelArea<TPixel> area, int targetY, int targetX = 0)
{ {
this.CheckCoordinates(area, targetX, targetY); this.CheckCoordinates(area, targetX, targetY);
@ -195,7 +195,7 @@ namespace ImageSharp
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown when an unsupported component order value is passed. /// Thrown when an unsupported component order value is passed.
/// </exception> /// </exception>
internal void CopyTo(PixelArea<TColor> area, int sourceY, int sourceX = 0) internal void CopyTo(PixelArea<TPixel> area, int sourceY, int sourceX = 0)
{ {
this.CheckCoordinates(area, sourceX, sourceY); this.CheckCoordinates(area, sourceX, sourceY);
@ -212,7 +212,7 @@ namespace ImageSharp
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown when an unsupported component order value is passed. /// Thrown when an unsupported component order value is passed.
/// </exception> /// </exception>
internal void SafeCopyTo(PixelArea<TColor> area, int sourceY, int sourceX = 0) internal void SafeCopyTo(PixelArea<TPixel> area, int sourceY, int sourceX = 0)
{ {
int width = Math.Min(area.Width, this.Width - sourceX); int width = Math.Min(area.Width, this.Width - sourceX);
if (width < 1) if (width < 1)
@ -237,18 +237,18 @@ namespace ImageSharp
/// <param name="pixels">The pixels.</param> /// <param name="pixels">The pixels.</param>
/// <returns>Returns the old pixel data thats has gust been replaced.</returns> /// <returns>Returns the old pixel data thats has gust been replaced.</returns>
/// <remarks>If <see cref="M:PixelAccessor.PooledMemory"/> is true then caller is responsible for ensuring <see cref="M:PixelDataPool.Return()"/> is called.</remarks> /// <remarks>If <see cref="M:PixelAccessor.PooledMemory"/> is true then caller is responsible for ensuring <see cref="M:PixelDataPool.Return()"/> is called.</remarks>
internal TColor[] ReturnCurrentPixelsAndReplaceThemInternally(int width, int height, TColor[] pixels) internal TPixel[] ReturnCurrentColorsAndReplaceThemInternally(int width, int height, TPixel[] pixels)
{ {
TColor[] oldPixels = this.pixelBuffer.TakeArrayOwnership(); TPixel[] oldPixels = this.pixelBuffer.TakeArrayOwnership();
this.SetPixelBufferUnsafe(width, height, pixels); this.SetPixelBufferUnsafe(width, height, pixels);
return oldPixels; return oldPixels;
} }
/// <summary> /// <summary>
/// Copies the pixels to another <see cref="PixelAccessor{TColor}"/> of the same size. /// Copies the pixels to another <see cref="PixelAccessor{TPixel}"/> of the same size.
/// </summary> /// </summary>
/// <param name="target">The target pixel buffer accessor.</param> /// <param name="target">The target pixel buffer accessor.</param>
internal void CopyTo(PixelAccessor<TColor> target) internal void CopyTo(PixelAccessor<TPixel> target)
{ {
BufferSpan.Copy(this.pixelBuffer.Span, target.pixelBuffer.Span); BufferSpan.Copy(this.pixelBuffer.Span, target.pixelBuffer.Span);
} }
@ -262,12 +262,12 @@ namespace ImageSharp
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <param name="height">The height.</param> /// <param name="height">The height.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private void CopyFromZyx(PixelArea<TColor> area, int targetX, int targetY, int width, int height) private void CopyFromZyx(PixelArea<TPixel> area, int targetX, int targetY, int width, int height)
{ {
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
BufferSpan<byte> source = area.GetRowSpan(y); BufferSpan<byte> source = area.GetRowSpan(y);
BufferSpan<TColor> destination = this.GetRowSpan(targetX, targetY + y); BufferSpan<TPixel> destination = this.GetRowSpan(targetX, targetY + y);
Operations.PackFromZyxBytes(source, destination, width); Operations.PackFromZyxBytes(source, destination, width);
} }
@ -282,12 +282,12 @@ namespace ImageSharp
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <param name="height">The height.</param> /// <param name="height">The height.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private void CopyFromZyxw(PixelArea<TColor> area, int targetX, int targetY, int width, int height) private void CopyFromZyxw(PixelArea<TPixel> area, int targetX, int targetY, int width, int height)
{ {
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
BufferSpan<byte> source = area.GetRowSpan(y); BufferSpan<byte> source = area.GetRowSpan(y);
BufferSpan<TColor> destination = this.GetRowSpan(targetX, targetY + y); BufferSpan<TPixel> destination = this.GetRowSpan(targetX, targetY + y);
Operations.PackFromZyxwBytes(source, destination, width); Operations.PackFromZyxwBytes(source, destination, width);
} }
@ -302,12 +302,12 @@ namespace ImageSharp
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <param name="height">The height.</param> /// <param name="height">The height.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private void CopyFromXyz(PixelArea<TColor> area, int targetX, int targetY, int width, int height) private void CopyFromXyz(PixelArea<TPixel> area, int targetX, int targetY, int width, int height)
{ {
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
BufferSpan<byte> source = area.GetRowSpan(y); BufferSpan<byte> source = area.GetRowSpan(y);
BufferSpan<TColor> destination = this.GetRowSpan(targetX, targetY + y); BufferSpan<TPixel> destination = this.GetRowSpan(targetX, targetY + y);
Operations.PackFromXyzBytes(source, destination, width); Operations.PackFromXyzBytes(source, destination, width);
} }
@ -322,12 +322,12 @@ namespace ImageSharp
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <param name="height">The height.</param> /// <param name="height">The height.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private void CopyFromXyzw(PixelArea<TColor> area, int targetX, int targetY, int width, int height) private void CopyFromXyzw(PixelArea<TPixel> area, int targetX, int targetY, int width, int height)
{ {
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
BufferSpan<byte> source = area.GetRowSpan(y); BufferSpan<byte> source = area.GetRowSpan(y);
BufferSpan<TColor> destination = this.GetRowSpan(targetX, targetY + y); BufferSpan<TPixel> destination = this.GetRowSpan(targetX, targetY + y);
Operations.PackFromXyzwBytes(source, destination, width); Operations.PackFromXyzwBytes(source, destination, width);
} }
} }
@ -341,11 +341,11 @@ namespace ImageSharp
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <param name="height">The height.</param> /// <param name="height">The height.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private void CopyToZyx(PixelArea<TColor> area, int sourceX, int sourceY, int width, int height) private void CopyToZyx(PixelArea<TPixel> area, int sourceX, int sourceY, int width, int height)
{ {
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
BufferSpan<TColor> source = this.GetRowSpan(sourceX, sourceY + y); BufferSpan<TPixel> source = this.GetRowSpan(sourceX, sourceY + y);
BufferSpan<byte> destination = area.GetRowSpan(y); BufferSpan<byte> destination = area.GetRowSpan(y);
Operations.ToZyxBytes(source, destination, width); Operations.ToZyxBytes(source, destination, width);
} }
@ -360,11 +360,11 @@ namespace ImageSharp
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <param name="height">The height.</param> /// <param name="height">The height.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private void CopyToZyxw(PixelArea<TColor> area, int sourceX, int sourceY, int width, int height) private void CopyToZyxw(PixelArea<TPixel> area, int sourceX, int sourceY, int width, int height)
{ {
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
BufferSpan<TColor> source = this.GetRowSpan(sourceX, sourceY + y); BufferSpan<TPixel> source = this.GetRowSpan(sourceX, sourceY + y);
BufferSpan<byte> destination = area.GetRowSpan(y); BufferSpan<byte> destination = area.GetRowSpan(y);
Operations.ToZyxwBytes(source, destination, width); Operations.ToZyxwBytes(source, destination, width);
} }
@ -379,11 +379,11 @@ namespace ImageSharp
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <param name="height">The height.</param> /// <param name="height">The height.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private void CopyToXyz(PixelArea<TColor> area, int sourceX, int sourceY, int width, int height) private void CopyToXyz(PixelArea<TPixel> area, int sourceX, int sourceY, int width, int height)
{ {
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
BufferSpan<TColor> source = this.GetRowSpan(sourceX, sourceY + y); BufferSpan<TPixel> source = this.GetRowSpan(sourceX, sourceY + y);
BufferSpan<byte> destination = area.GetRowSpan(y); BufferSpan<byte> destination = area.GetRowSpan(y);
Operations.ToXyzBytes(source, destination, width); Operations.ToXyzBytes(source, destination, width);
} }
@ -398,19 +398,19 @@ namespace ImageSharp
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <param name="height">The height.</param> /// <param name="height">The height.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private void CopyToXyzw(PixelArea<TColor> area, int sourceX, int sourceY, int width, int height) private void CopyToXyzw(PixelArea<TPixel> area, int sourceX, int sourceY, int width, int height)
{ {
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
BufferSpan<TColor> source = this.GetRowSpan(sourceX, sourceY + y); BufferSpan<TPixel> source = this.GetRowSpan(sourceX, sourceY + y);
BufferSpan<byte> destination = area.GetRowSpan(y); BufferSpan<byte> destination = area.GetRowSpan(y);
Operations.ToXyzwBytes(source, destination, width); Operations.ToXyzwBytes(source, destination, width);
} }
} }
private void SetPixelBufferUnsafe(int width, int height, TColor[] pixels) private void SetPixelBufferUnsafe(int width, int height, TPixel[] pixels)
{ {
this.SetPixelBufferUnsafe(width, height, new Buffer2D<TColor>(pixels, width, height)); this.SetPixelBufferUnsafe(width, height, new Buffer2D<TPixel>(pixels, width, height));
} }
/// <summary> /// <summary>
@ -419,13 +419,13 @@ namespace ImageSharp
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <param name="height">The height.</param> /// <param name="height">The height.</param>
/// <param name="pixels">The pixel buffer</param> /// <param name="pixels">The pixel buffer</param>
private void SetPixelBufferUnsafe(int width, int height, Buffer2D<TColor> pixels) private void SetPixelBufferUnsafe(int width, int height, Buffer2D<TPixel> pixels)
{ {
this.pixelBuffer = pixels; this.pixelBuffer = pixels;
this.Width = width; this.Width = width;
this.Height = height; this.Height = height;
this.PixelSize = Unsafe.SizeOf<TColor>(); this.PixelSize = Unsafe.SizeOf<TPixel>();
this.RowStride = this.Width * this.PixelSize; this.RowStride = this.Width * this.PixelSize;
} }
@ -440,7 +440,7 @@ namespace ImageSharp
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown when an unsupported component order value is passed. /// Thrown when an unsupported component order value is passed.
/// </exception> /// </exception>
private void CopyFrom(PixelArea<TColor> area, int targetX, int targetY, int width, int height) private void CopyFrom(PixelArea<TPixel> area, int targetX, int targetY, int width, int height)
{ {
switch (area.ComponentOrder) switch (area.ComponentOrder)
{ {
@ -472,7 +472,7 @@ namespace ImageSharp
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown when an unsupported component order value is passed. /// Thrown when an unsupported component order value is passed.
/// </exception> /// </exception>
private void CopyTo(PixelArea<TColor> area, int sourceX, int sourceY, int width, int height) private void CopyTo(PixelArea<TPixel> area, int sourceX, int sourceY, int width, int height)
{ {
switch (area.ComponentOrder) switch (area.ComponentOrder)
{ {
@ -503,7 +503,7 @@ namespace ImageSharp
/// Thrown if the dimensions are not within the bounds of the image. /// Thrown if the dimensions are not within the bounds of the image.
/// </exception> /// </exception>
[Conditional("DEBUG")] [Conditional("DEBUG")]
private void CheckCoordinates(PixelArea<TColor> area, int x, int y) private void CheckCoordinates(PixelArea<TPixel> area, int x, int y)
{ {
int width = Math.Min(area.Width, this.Width - x); int width = Math.Min(area.Width, this.Width - x);
if (width < 1) if (width < 1)

25
src/ImageSharp/Image/PixelArea{TColor}.cs → src/ImageSharp/Image/PixelArea{TPixel}.cs

@ -1,20 +1,21 @@
// <copyright file="PixelArea{TColor}.cs" company="James Jackson-South"> // <copyright file="PixelArea{TPixel}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
namespace ImageSharp namespace ImageSharp
{ {
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Runtime.CompilerServices; using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Represents an area of generic <see cref="Image{TColor}"/> pixels. /// Represents an area of generic <see cref="Image{TPixel}"/> pixels.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
internal sealed class PixelArea<TColor> : IDisposable internal sealed class PixelArea<TPixel> : IDisposable
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// A value indicating whether this instance of the given entity has been disposed. /// A value indicating whether this instance of the given entity has been disposed.
@ -33,7 +34,7 @@ namespace ImageSharp
private Buffer<byte> byteBuffer; private Buffer<byte> byteBuffer;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PixelArea{TColor}"/> class. /// Initializes a new instance of the <see cref="PixelArea{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <param name="bytes">The bytes.</param> /// <param name="bytes">The bytes.</param>
@ -47,7 +48,7 @@ namespace ImageSharp
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PixelArea{TColor}"/> class. /// Initializes a new instance of the <see cref="PixelArea{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <param name="height">The height.</param> /// <param name="height">The height.</param>
@ -70,7 +71,7 @@ namespace ImageSharp
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PixelArea{TColor}"/> class. /// Initializes a new instance of the <see cref="PixelArea{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <param name="componentOrder">The component order.</param> /// <param name="componentOrder">The component order.</param>
@ -80,7 +81,7 @@ namespace ImageSharp
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PixelArea{TColor}"/> class. /// Initializes a new instance of the <see cref="PixelArea{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="width">The width. </param> /// <param name="width">The width. </param>
/// <param name="componentOrder">The component order.</param> /// <param name="componentOrder">The component order.</param>
@ -91,7 +92,7 @@ namespace ImageSharp
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PixelArea{TColor}"/> class. /// Initializes a new instance of the <see cref="PixelArea{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <param name="height">The height.</param> /// <param name="height">The height.</param>
@ -102,7 +103,7 @@ namespace ImageSharp
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PixelArea{TColor}"/> class. /// Initializes a new instance of the <see cref="PixelArea{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <param name="height">The height.</param> /// <param name="height">The height.</param>

18
src/ImageSharp/ImageProcessor.cs

@ -8,12 +8,14 @@ namespace ImageSharp.Processing
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Allows the application of processors to images. /// Allows the application of processors to images.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
internal abstract class ImageProcessor<TColor> : IImageProcessor<TColor> internal abstract class ImageProcessor<TPixel> : IImageProcessor<TPixel>
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
/// <inheritdoc/> /// <inheritdoc/>
public virtual ParallelOptions ParallelOptions { get; set; } public virtual ParallelOptions ParallelOptions { get; set; }
@ -22,7 +24,7 @@ namespace ImageSharp.Processing
public virtual bool Compand { get; set; } = false; public virtual bool Compand { get; set; } = false;
/// <inheritdoc/> /// <inheritdoc/>
public void Apply(ImageBase<TColor> source, Rectangle sourceRectangle) public void Apply(ImageBase<TPixel> source, Rectangle sourceRectangle)
{ {
if (this.ParallelOptions == null) if (this.ParallelOptions == null)
{ {
@ -50,19 +52,19 @@ namespace ImageSharp.Processing
/// <param name="sourceRectangle"> /// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// </param> /// </param>
protected virtual void BeforeApply(ImageBase<TColor> source, Rectangle sourceRectangle) protected virtual void BeforeApply(ImageBase<TPixel> source, Rectangle sourceRectangle)
{ {
} }
/// <summary> /// <summary>
/// Applies the process to the specified portion of the specified <see cref="ImageBase{TColor}"/> at the specified location /// Applies the process to the specified portion of the specified <see cref="ImageBase{TPixel}"/> at the specified location
/// and with the specified size. /// and with the specified size.
/// </summary> /// </summary>
/// <param name="source">The source image. Cannot be null.</param> /// <param name="source">The source image. Cannot be null.</param>
/// <param name="sourceRectangle"> /// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// </param> /// </param>
protected abstract void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle); protected abstract void OnApply(ImageBase<TPixel> source, Rectangle sourceRectangle);
/// <summary> /// <summary>
/// This method is called after the process is applied to prepare the processor. /// This method is called after the process is applied to prepare the processor.
@ -71,7 +73,7 @@ namespace ImageSharp.Processing
/// <param name="sourceRectangle"> /// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// </param> /// </param>
protected virtual void AfterApply(ImageBase<TColor> source, Rectangle sourceRectangle) protected virtual void AfterApply(ImageBase<TPixel> source, Rectangle sourceRectangle)
{ {
} }
} }

2
src/ImageSharp/ImageSharp.csproj

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

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

@ -10,6 +10,8 @@ namespace ImageSharp
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.IO; using System.IO;
using ImageSharp.PixelFormats;
/// <summary> /// <summary>
/// Represents an EXIF profile providing access to the collection of values. /// Represents an EXIF profile providing access to the collection of values.
/// </summary> /// </summary>
@ -116,12 +118,12 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Returns the thumbnail in the EXIF profile when available. /// Returns the thumbnail in the EXIF profile when available.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns> /// <returns>
/// The <see cref="Image{TColor}"/>. /// The <see cref="Image{TPixel}"/>.
/// </returns> /// </returns>
public Image<TColor> CreateThumbnail<TColor>() public Image<TPixel> CreateThumbnail<TPixel>()
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
this.InitializeValues(); this.InitializeValues();
@ -137,7 +139,7 @@ namespace ImageSharp
using (MemoryStream memStream = new MemoryStream(this.data, this.thumbnailOffset, this.thumbnailLength)) using (MemoryStream memStream = new MemoryStream(this.data, this.thumbnailOffset, this.thumbnailLength))
{ {
return Image.Load<TColor>(memStream); return Image.Load<TPixel>(memStream);
} }
} }

5
src/ImageSharp/Colors/PackedPixel/Alpha8.cs → src/ImageSharp/PixelFormats/Alpha8.cs

@ -3,14 +3,15 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
namespace ImageSharp namespace ImageSharp.PixelFormats
{ {
using System; using System;
using System.Numerics; using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
/// <summary> /// <summary>
/// Packed pixel type containing a single 8 bit normalized W values ranging from 0 to 1. /// Packed pixel type containing a single 8 bit normalized W values.
/// Ranges from &lt;0, 0, 0, 0&gt; to &lt;0, 0, 0, 1&gt; in vector form.
/// </summary> /// </summary>
public struct Alpha8 : IPixel<Alpha8>, IPackedVector<byte> public struct Alpha8 : IPixel<Alpha8>, IPackedVector<byte>
{ {

4
src/ImageSharp/Colors/PackedPixel/Argb32.cs → src/ImageSharp/PixelFormats/Argb32.cs

@ -3,15 +3,15 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
namespace ImageSharp namespace ImageSharp.PixelFormats
{ {
using System;
using System.Numerics; using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
/// <summary> /// <summary>
/// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255. /// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.
/// The color components are stored in alpha, red, green, and blue order. /// The color components are stored in alpha, red, green, and blue order.
/// Ranges from &lt;0, 0, 0, 0&gt; to &lt;1, 1, 1, 1&gt; in vector form.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// This struct is fully mutable. This is done (against the guidelines) for the sake of performance, /// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,

3
src/ImageSharp/Colors/PackedPixel/Bgr565.cs → src/ImageSharp/PixelFormats/Bgr565.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
namespace ImageSharp namespace ImageSharp.PixelFormats
{ {
using System; using System;
using System.Numerics; using System.Numerics;
@ -11,6 +11,7 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Packed pixel type containing unsigned normalized values ranging from 0 to 1. The x and z components use 5 bits, and the y component uses 6 bits. /// Packed pixel type containing unsigned normalized values ranging from 0 to 1. The x and z components use 5 bits, and the y component uses 6 bits.
/// Ranges from &lt;0, 0, 0, 1&gt; to &lt;1, 1, 1, 1&gt; in vector form.
/// </summary> /// </summary>
public struct Bgr565 : IPixel<Bgr565>, IPackedVector<ushort> public struct Bgr565 : IPixel<Bgr565>, IPackedVector<ushort>
{ {

3
src/ImageSharp/Colors/PackedPixel/Bgra4444.cs → src/ImageSharp/PixelFormats/Bgra4444.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
namespace ImageSharp namespace ImageSharp.PixelFormats
{ {
using System; using System;
using System.Numerics; using System.Numerics;
@ -11,6 +11,7 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Packed pixel type containing unsigned normalized values, ranging from 0 to 1, using 4 bits each for x, y, z, and w. /// Packed pixel type containing unsigned normalized values, ranging from 0 to 1, using 4 bits each for x, y, z, and w.
/// Ranges from &lt;0, 0, 0, 0&gt; to &lt;1, 1, 1, 1&gt; in vector form.
/// </summary> /// </summary>
public struct Bgra4444 : IPixel<Bgra4444>, IPackedVector<ushort> public struct Bgra4444 : IPixel<Bgra4444>, IPackedVector<ushort>
{ {

2
src/ImageSharp/Colors/PackedPixel/Bgra5551.cs → src/ImageSharp/PixelFormats/Bgra5551.cs

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

76
src/ImageSharp/Colors/PackedPixel/BulkPixelOperations{TColor}.cs → src/ImageSharp/PixelFormats/BulkPixelOperations{TPixel}.cs

@ -1,25 +1,25 @@
// <copyright file="BulkPixelOperations{TColor}.cs" company="James Jackson-South"> // <copyright file="BulkPixelOperations{TPixel}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
namespace ImageSharp namespace ImageSharp.PixelFormats
{ {
using System.Numerics; using System.Numerics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
/// <summary> /// <summary>
/// A stateless class implementing Strategy Pattern for batched pixel-data conversion operations /// A stateless class implementing Strategy Pattern for batched pixel-data conversion operations
/// for pixel buffers of type <typeparamref name="TColor"/>. /// for pixel buffers of type <typeparamref name="TPixel"/>.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
public class BulkPixelOperations<TColor> public class BulkPixelOperations<TPixel>
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Gets the global <see cref="BulkPixelOperations{TColor}"/> instance for the pixel type <typeparamref name="TColor"/> /// Gets the global <see cref="BulkPixelOperations{TPixel}"/> instance for the pixel type <typeparamref name="TPixel"/>
/// </summary> /// </summary>
public static BulkPixelOperations<TColor> Instance { get; } = default(TColor).CreateBulkOperations(); public static BulkPixelOperations<TPixel> Instance { get; } = default(TPixel).CreateBulkOperations();
/// <summary> /// <summary>
/// Bulk version of <see cref="IPixel.PackFromVector4(Vector4)"/> /// Bulk version of <see cref="IPixel.PackFromVector4(Vector4)"/>
@ -27,15 +27,15 @@ namespace ImageSharp
/// <param name="sourceVectors">The <see cref="BufferSpan{T}"/> to the source vectors.</param> /// <param name="sourceVectors">The <see cref="BufferSpan{T}"/> to the source vectors.</param>
/// <param name="destColors">The <see cref="BufferSpan{T}"/> to the destination colors.</param> /// <param name="destColors">The <see cref="BufferSpan{T}"/> to the destination colors.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
internal virtual void PackFromVector4(BufferSpan<Vector4> sourceVectors, BufferSpan<TColor> destColors, int count) internal virtual void PackFromVector4(BufferSpan<Vector4> sourceVectors, BufferSpan<TPixel> destColors, int count)
{ {
ref Vector4 sourceRef = ref sourceVectors.DangerousGetPinnableReference(); ref Vector4 sourceRef = ref sourceVectors.DangerousGetPinnableReference();
ref TColor destRef = ref destColors.DangerousGetPinnableReference(); ref TPixel destRef = ref destColors.DangerousGetPinnableReference();
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
ref Vector4 sp = ref Unsafe.Add(ref sourceRef, i); ref Vector4 sp = ref Unsafe.Add(ref sourceRef, i);
ref TColor dp = ref Unsafe.Add(ref destRef, i); ref TPixel dp = ref Unsafe.Add(ref destRef, i);
dp.PackFromVector4(sp); dp.PackFromVector4(sp);
} }
} }
@ -46,14 +46,14 @@ namespace ImageSharp
/// <param name="sourceColors">The <see cref="BufferSpan{T}"/> to the source colors.</param> /// <param name="sourceColors">The <see cref="BufferSpan{T}"/> to the source colors.</param>
/// <param name="destVectors">The <see cref="BufferSpan{T}"/> to the destination vectors.</param> /// <param name="destVectors">The <see cref="BufferSpan{T}"/> to the destination vectors.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
internal virtual void ToVector4(BufferSpan<TColor> sourceColors, BufferSpan<Vector4> destVectors, int count) internal virtual void ToVector4(BufferSpan<TPixel> sourceColors, BufferSpan<Vector4> destVectors, int count)
{ {
ref TColor sourceRef = ref sourceColors.DangerousGetPinnableReference(); ref TPixel sourceRef = ref sourceColors.DangerousGetPinnableReference();
ref Vector4 destRef = ref destVectors.DangerousGetPinnableReference(); ref Vector4 destRef = ref destVectors.DangerousGetPinnableReference();
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
ref TColor sp = ref Unsafe.Add(ref sourceRef, i); ref TPixel sp = ref Unsafe.Add(ref sourceRef, i);
ref Vector4 dp = ref Unsafe.Add(ref destRef, i); ref Vector4 dp = ref Unsafe.Add(ref destRef, i);
dp = sp.ToVector4(); dp = sp.ToVector4();
} }
@ -65,15 +65,15 @@ namespace ImageSharp
/// <param name="sourceBytes">The <see cref="BufferSpan{T}"/> to the source bytes.</param> /// <param name="sourceBytes">The <see cref="BufferSpan{T}"/> to the source bytes.</param>
/// <param name="destColors">The <see cref="BufferSpan{T}"/> to the destination colors.</param> /// <param name="destColors">The <see cref="BufferSpan{T}"/> to the destination colors.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
internal virtual void PackFromXyzBytes(BufferSpan<byte> sourceBytes, BufferSpan<TColor> destColors, int count) internal virtual void PackFromXyzBytes(BufferSpan<byte> sourceBytes, BufferSpan<TPixel> destColors, int count)
{ {
ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference(); ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference();
ref TColor destRef = ref destColors.DangerousGetPinnableReference(); ref TPixel destRef = ref destColors.DangerousGetPinnableReference();
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
int i3 = i * 3; int i3 = i * 3;
ref TColor dp = ref Unsafe.Add(ref destRef, i); ref TPixel dp = ref Unsafe.Add(ref destRef, i);
dp.PackFromBytes( dp.PackFromBytes(
Unsafe.Add(ref sourceRef, i3), Unsafe.Add(ref sourceRef, i3),
Unsafe.Add(ref sourceRef, i3 + 1), Unsafe.Add(ref sourceRef, i3 + 1),
@ -88,14 +88,14 @@ namespace ImageSharp
/// <param name="sourceColors">The <see cref="BufferSpan{T}"/> to the source colors.</param> /// <param name="sourceColors">The <see cref="BufferSpan{T}"/> to the source colors.</param>
/// <param name="destBytes">The <see cref="BufferSpan{T}"/> to the destination bytes.</param> /// <param name="destBytes">The <see cref="BufferSpan{T}"/> to the destination bytes.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
internal virtual void ToXyzBytes(BufferSpan<TColor> sourceColors, BufferSpan<byte> destBytes, int count) internal virtual void ToXyzBytes(BufferSpan<TPixel> sourceColors, BufferSpan<byte> destBytes, int count)
{ {
ref TColor sourceRef = ref sourceColors.DangerousGetPinnableReference(); ref TPixel sourceRef = ref sourceColors.DangerousGetPinnableReference();
byte[] dest = destBytes.Array; byte[] dest = destBytes.Array;
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
ref TColor sp = ref Unsafe.Add(ref sourceRef, i); ref TPixel sp = ref Unsafe.Add(ref sourceRef, i);
sp.ToXyzBytes(dest, destBytes.Start + (i * 3)); sp.ToXyzBytes(dest, destBytes.Start + (i * 3));
} }
} }
@ -106,15 +106,15 @@ namespace ImageSharp
/// <param name="sourceBytes">The <see cref="BufferSpan{T}"/> to the source bytes.</param> /// <param name="sourceBytes">The <see cref="BufferSpan{T}"/> to the source bytes.</param>
/// <param name="destColors">The <see cref="BufferSpan{T}"/> to the destination colors.</param> /// <param name="destColors">The <see cref="BufferSpan{T}"/> to the destination colors.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
internal virtual void PackFromXyzwBytes(BufferSpan<byte> sourceBytes, BufferSpan<TColor> destColors, int count) internal virtual void PackFromXyzwBytes(BufferSpan<byte> sourceBytes, BufferSpan<TPixel> destColors, int count)
{ {
ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference(); ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference();
ref TColor destRef = ref destColors.DangerousGetPinnableReference(); ref TPixel destRef = ref destColors.DangerousGetPinnableReference();
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
int i4 = i * 4; int i4 = i * 4;
ref TColor dp = ref Unsafe.Add(ref destRef, i); ref TPixel dp = ref Unsafe.Add(ref destRef, i);
dp.PackFromBytes( dp.PackFromBytes(
Unsafe.Add(ref sourceRef, i4), Unsafe.Add(ref sourceRef, i4),
Unsafe.Add(ref sourceRef, i4 + 1), Unsafe.Add(ref sourceRef, i4 + 1),
@ -129,14 +129,14 @@ namespace ImageSharp
/// <param name="sourceColors">The <see cref="BufferSpan{T}"/> to the source colors.</param> /// <param name="sourceColors">The <see cref="BufferSpan{T}"/> to the source colors.</param>
/// <param name="destBytes">The <see cref="BufferSpan{T}"/> to the destination bytes.</param> /// <param name="destBytes">The <see cref="BufferSpan{T}"/> to the destination bytes.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
internal virtual void ToXyzwBytes(BufferSpan<TColor> sourceColors, BufferSpan<byte> destBytes, int count) internal virtual void ToXyzwBytes(BufferSpan<TPixel> sourceColors, BufferSpan<byte> destBytes, int count)
{ {
ref TColor sourceRef = ref sourceColors.DangerousGetPinnableReference(); ref TPixel sourceRef = ref sourceColors.DangerousGetPinnableReference();
byte[] dest = destBytes.Array; byte[] dest = destBytes.Array;
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
ref TColor sp = ref Unsafe.Add(ref sourceRef, i); ref TPixel sp = ref Unsafe.Add(ref sourceRef, i);
sp.ToXyzwBytes(dest, destBytes.Start + (i * 4)); sp.ToXyzwBytes(dest, destBytes.Start + (i * 4));
} }
} }
@ -147,15 +147,15 @@ namespace ImageSharp
/// <param name="sourceBytes">The <see cref="BufferSpan{T}"/> to the source bytes.</param> /// <param name="sourceBytes">The <see cref="BufferSpan{T}"/> to the source bytes.</param>
/// <param name="destColors">The <see cref="BufferSpan{T}"/> to the destination colors.</param> /// <param name="destColors">The <see cref="BufferSpan{T}"/> to the destination colors.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
internal virtual void PackFromZyxBytes(BufferSpan<byte> sourceBytes, BufferSpan<TColor> destColors, int count) internal virtual void PackFromZyxBytes(BufferSpan<byte> sourceBytes, BufferSpan<TPixel> destColors, int count)
{ {
ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference(); ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference();
ref TColor destRef = ref destColors.DangerousGetPinnableReference(); ref TPixel destRef = ref destColors.DangerousGetPinnableReference();
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
int i3 = i * 3; int i3 = i * 3;
ref TColor dp = ref Unsafe.Add(ref destRef, i); ref TPixel dp = ref Unsafe.Add(ref destRef, i);
dp.PackFromBytes( dp.PackFromBytes(
Unsafe.Add(ref sourceRef, i3 + 2), Unsafe.Add(ref sourceRef, i3 + 2),
Unsafe.Add(ref sourceRef, i3 + 1), Unsafe.Add(ref sourceRef, i3 + 1),
@ -170,14 +170,14 @@ namespace ImageSharp
/// <param name="sourceColors">The <see cref="BufferSpan{T}"/> to the source colors.</param> /// <param name="sourceColors">The <see cref="BufferSpan{T}"/> to the source colors.</param>
/// <param name="destBytes">The <see cref="BufferSpan{T}"/> to the destination bytes.</param> /// <param name="destBytes">The <see cref="BufferSpan{T}"/> to the destination bytes.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
internal virtual void ToZyxBytes(BufferSpan<TColor> sourceColors, BufferSpan<byte> destBytes, int count) internal virtual void ToZyxBytes(BufferSpan<TPixel> sourceColors, BufferSpan<byte> destBytes, int count)
{ {
ref TColor sourceRef = ref sourceColors.DangerousGetPinnableReference(); ref TPixel sourceRef = ref sourceColors.DangerousGetPinnableReference();
byte[] dest = destBytes.Array; byte[] dest = destBytes.Array;
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
ref TColor sp = ref Unsafe.Add(ref sourceRef, i); ref TPixel sp = ref Unsafe.Add(ref sourceRef, i);
sp.ToZyxBytes(dest, destBytes.Start + (i * 3)); sp.ToZyxBytes(dest, destBytes.Start + (i * 3));
} }
} }
@ -188,15 +188,15 @@ namespace ImageSharp
/// <param name="sourceBytes">The <see cref="BufferSpan{T}"/> to the source bytes.</param> /// <param name="sourceBytes">The <see cref="BufferSpan{T}"/> to the source bytes.</param>
/// <param name="destColors">The <see cref="BufferSpan{T}"/> to the destination colors.</param> /// <param name="destColors">The <see cref="BufferSpan{T}"/> to the destination colors.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
internal virtual void PackFromZyxwBytes(BufferSpan<byte> sourceBytes, BufferSpan<TColor> destColors, int count) internal virtual void PackFromZyxwBytes(BufferSpan<byte> sourceBytes, BufferSpan<TPixel> destColors, int count)
{ {
ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference(); ref byte sourceRef = ref sourceBytes.DangerousGetPinnableReference();
ref TColor destRef = ref destColors.DangerousGetPinnableReference(); ref TPixel destRef = ref destColors.DangerousGetPinnableReference();
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
int i4 = i * 4; int i4 = i * 4;
ref TColor dp = ref Unsafe.Add(ref destRef, i); ref TPixel dp = ref Unsafe.Add(ref destRef, i);
dp.PackFromBytes( dp.PackFromBytes(
Unsafe.Add(ref sourceRef, i4 + 2), Unsafe.Add(ref sourceRef, i4 + 2),
Unsafe.Add(ref sourceRef, i4 + 1), Unsafe.Add(ref sourceRef, i4 + 1),
@ -211,14 +211,14 @@ namespace ImageSharp
/// <param name="sourceColors">The <see cref="BufferSpan{T}"/> to the source colors.</param> /// <param name="sourceColors">The <see cref="BufferSpan{T}"/> to the source colors.</param>
/// <param name="destBytes">The <see cref="BufferSpan{T}"/> to the destination bytes.</param> /// <param name="destBytes">The <see cref="BufferSpan{T}"/> to the destination bytes.</param>
/// <param name="count">The number of pixels to convert.</param> /// <param name="count">The number of pixels to convert.</param>
internal virtual void ToZyxwBytes(BufferSpan<TColor> sourceColors, BufferSpan<byte> destBytes, int count) internal virtual void ToZyxwBytes(BufferSpan<TPixel> sourceColors, BufferSpan<byte> destBytes, int count)
{ {
ref TColor sourceRef = ref sourceColors.DangerousGetPinnableReference(); ref TPixel sourceRef = ref sourceColors.DangerousGetPinnableReference();
byte[] dest = destBytes.Array; byte[] dest = destBytes.Array;
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
ref TColor sp = ref Unsafe.Add(ref sourceRef, i); ref TPixel sp = ref Unsafe.Add(ref sourceRef, i);
sp.ToZyxwBytes(dest, destBytes.Start + (i * 4)); sp.ToZyxwBytes(dest, destBytes.Start + (i * 4));
} }
} }

3
src/ImageSharp/Colors/PackedPixel/Byte4.cs → src/ImageSharp/PixelFormats/Byte4.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
namespace ImageSharp namespace ImageSharp.PixelFormats
{ {
using System; using System;
using System.Numerics; using System.Numerics;
@ -11,6 +11,7 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Packed pixel type containing four 8-bit unsigned integer values, ranging from 0 to 255. /// Packed pixel type containing four 8-bit unsigned integer values, ranging from 0 to 255.
/// Ranges from &lt;0, 0, 0, 0&gt; to &lt;1, 1, 1, 1&gt; in vector form.
/// </summary> /// </summary>
public struct Byte4 : IPixel<Byte4>, IPackedVector<uint> public struct Byte4 : IPixel<Byte4>, IPackedVector<uint>
{ {

34
src/ImageSharp/Colors/ColorBuilder{TColor}.cs → src/ImageSharp/PixelFormats/ColorBuilder{TPixel}.cs

@ -1,9 +1,9 @@
// <copyright file="ColorBuilder{TColor}.cs" company="James Jackson-South"> // <copyright file="ColorBuilder{TPixel}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
namespace ImageSharp namespace ImageSharp.PixelFormats
{ {
using System; using System;
using System.Globalization; using System.Globalization;
@ -11,19 +11,19 @@ namespace ImageSharp
/// <summary> /// <summary>
/// A set of named colors mapped to the provided Color space. /// A set of named colors mapped to the provided Color space.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TPixel">The type of the color.</typeparam>
public static class ColorBuilder<TColor> public static class ColorBuilder<TPixel>
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Creates a new <typeparamref name="TColor"/> representation from the string representing a color. /// Creates a new <typeparamref name="TPixel"/> representation from the string representing a color.
/// </summary> /// </summary>
/// <param name="hex"> /// <param name="hex">
/// The hexadecimal representation of the combined color components arranged /// The hexadecimal representation of the combined color components arranged
/// in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax. /// in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax.
/// </param> /// </param>
/// <returns>Returns a <typeparamref name="TColor"/> that represents the color defined by the provided RGBA heax string.</returns> /// <returns>Returns a <typeparamref name="TPixel"/> that represents the color defined by the provided RGBA heax string.</returns>
public static TColor FromHex(string hex) public static TPixel FromHex(string hex)
{ {
Guard.NotNullOrEmpty(hex, nameof(hex)); Guard.NotNullOrEmpty(hex, nameof(hex));
@ -34,7 +34,7 @@ namespace ImageSharp
throw new ArgumentException("Hexadecimal string is not in the correct format.", nameof(hex)); throw new ArgumentException("Hexadecimal string is not in the correct format.", nameof(hex));
} }
TColor result = default(TColor); TPixel result = default(TPixel);
result.PackFromBytes( result.PackFromBytes(
(byte)(packedValue >> 24), (byte)(packedValue >> 24),
@ -45,30 +45,30 @@ namespace ImageSharp
} }
/// <summary> /// <summary>
/// Creates a new <typeparamref name="TColor"/> representation from standard RGB bytes with 100% opacity. /// Creates a new <typeparamref name="TPixel"/> representation from standard RGB bytes with 100% opacity.
/// </summary> /// </summary>
/// <param name="red">The red intensity.</param> /// <param name="red">The red intensity.</param>
/// <param name="green">The green intensity.</param> /// <param name="green">The green intensity.</param>
/// <param name="blue">The blue intensity.</param> /// <param name="blue">The blue intensity.</param>
/// <returns>Returns a <typeparamref name="TColor"/> that represents the color defined by the provided RGB values with 100% opacity.</returns> /// <returns>Returns a <typeparamref name="TPixel"/> that represents the color defined by the provided RGB values with 100% opacity.</returns>
public static TColor FromRGB(byte red, byte green, byte blue) public static TPixel FromRGB(byte red, byte green, byte blue)
{ {
TColor color = default(TColor); TPixel color = default(TPixel);
color.PackFromBytes(red, green, blue, 255); color.PackFromBytes(red, green, blue, 255);
return color; return color;
} }
/// <summary> /// <summary>
/// Creates a new <typeparamref name="TColor"/> representation from standard RGBA bytes. /// Creates a new <typeparamref name="TPixel"/> representation from standard RGBA bytes.
/// </summary> /// </summary>
/// <param name="red">The red intensity.</param> /// <param name="red">The red intensity.</param>
/// <param name="green">The green intensity.</param> /// <param name="green">The green intensity.</param>
/// <param name="blue">The blue intensity.</param> /// <param name="blue">The blue intensity.</param>
/// <param name="alpha">The alpha intensity.</param> /// <param name="alpha">The alpha intensity.</param>
/// <returns>Returns a <typeparamref name="TColor"/> that represents the color defined by the provided RGBA values.</returns> /// <returns>Returns a <typeparamref name="TPixel"/> that represents the color defined by the provided RGBA values.</returns>
public static TColor FromRGBA(byte red, byte green, byte blue, byte alpha) public static TPixel FromRGBA(byte red, byte green, byte blue, byte alpha)
{ {
TColor color = default(TColor); TPixel color = default(TPixel);
color.PackFromBytes(red, green, blue, alpha); color.PackFromBytes(red, green, blue, alpha);
return color; return color;
} }

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

Loading…
Cancel
Save