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

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

@ -5,8 +5,10 @@
namespace ImageSharp.Drawing.Brushes
{
using ImageSharp.PixelFormats;
/// <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>
public class Brushes
{
@ -15,7 +17,7 @@ namespace ImageSharp.Drawing.Brushes
/// </summary>
/// <param name="color">The color.</param>
/// <returns>A Brush</returns>
public static SolidBrush Solid(Color color)
public static SolidBrush Solid(Rgba32 color)
=> new SolidBrush(color);
/// <summary>
@ -24,8 +26,8 @@ namespace ImageSharp.Drawing.Brushes
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns>
public static PatternBrush Percent10(Color foreColor)
=> new PatternBrush(Brushes<Color>.Percent10(foreColor, Color.Transparent));
public static PatternBrush Percent10(Rgba32 foreColor)
=> new PatternBrush(Brushes<Rgba32>.Percent10(foreColor, Rgba32.Transparent));
/// <summary>
/// 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="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush Percent10(Color foreColor, Color backColor)
=> new PatternBrush(Brushes<Color>.Percent10(foreColor, backColor));
public static PatternBrush Percent10(Rgba32 foreColor, Rgba32 backColor)
=> new PatternBrush(Brushes<Rgba32>.Percent10(foreColor, backColor));
/// <summary>
/// Create as brush that will paint a Percent20 Hatch Pattern with
@ -43,8 +45,8 @@ namespace ImageSharp.Drawing.Brushes
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns>
public static PatternBrush Percent20(Color foreColor)
=> new PatternBrush(Brushes<Color>.Percent20(foreColor, Color.Transparent));
public static PatternBrush Percent20(Rgba32 foreColor)
=> new PatternBrush(Brushes<Rgba32>.Percent20(foreColor, Rgba32.Transparent));
/// <summary>
/// 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="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush Percent20(Color foreColor, Color backColor)
=> new PatternBrush(Brushes<Color>.Percent20(foreColor, backColor));
public static PatternBrush Percent20(Rgba32 foreColor, Rgba32 backColor)
=> new PatternBrush(Brushes<Rgba32>.Percent20(foreColor, backColor));
/// <summary>
/// Create as brush that will paint a Horizontal Hatch Pattern with
@ -62,8 +64,8 @@ namespace ImageSharp.Drawing.Brushes
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns>
public static PatternBrush Horizontal(Color foreColor)
=> new PatternBrush(Brushes<Color>.Horizontal(foreColor, Color.Transparent));
public static PatternBrush Horizontal(Rgba32 foreColor)
=> new PatternBrush(Brushes<Rgba32>.Horizontal(foreColor, Rgba32.Transparent));
/// <summary>
/// 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="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush Horizontal(Color foreColor, Color backColor)
=> new PatternBrush(Brushes<Color>.Horizontal(foreColor, backColor));
public static PatternBrush Horizontal(Rgba32 foreColor, Rgba32 backColor)
=> new PatternBrush(Brushes<Rgba32>.Horizontal(foreColor, backColor));
/// <summary>
/// Create as brush that will paint a Min Hatch Pattern with
@ -81,8 +83,8 @@ namespace ImageSharp.Drawing.Brushes
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns>
public static PatternBrush Min(Color foreColor)
=> new PatternBrush(Brushes<Color>.Min(foreColor, Color.Transparent));
public static PatternBrush Min(Rgba32 foreColor)
=> new PatternBrush(Brushes<Rgba32>.Min(foreColor, Rgba32.Transparent));
/// <summary>
/// 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="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush Min(Color foreColor, Color backColor)
=> new PatternBrush(Brushes<Color>.Min(foreColor, backColor));
public static PatternBrush Min(Rgba32 foreColor, Rgba32 backColor)
=> new PatternBrush(Brushes<Rgba32>.Min(foreColor, backColor));
/// <summary>
/// Create as brush that will paint a Vertical Hatch Pattern with
@ -100,8 +102,8 @@ namespace ImageSharp.Drawing.Brushes
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns>
public static PatternBrush Vertical(Color foreColor)
=> new PatternBrush(Brushes<Color>.Vertical(foreColor, Color.Transparent));
public static PatternBrush Vertical(Rgba32 foreColor)
=> new PatternBrush(Brushes<Rgba32>.Vertical(foreColor, Rgba32.Transparent));
/// <summary>
/// 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="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush Vertical(Color foreColor, Color backColor)
=> new PatternBrush(Brushes<Color>.Vertical(foreColor, backColor));
public static PatternBrush Vertical(Rgba32 foreColor, Rgba32 backColor)
=> new PatternBrush(Brushes<Rgba32>.Vertical(foreColor, backColor));
/// <summary>
/// Create as brush that will paint a Forward Diagonal Hatch Pattern with
@ -119,8 +121,8 @@ namespace ImageSharp.Drawing.Brushes
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns>
public static PatternBrush ForwardDiagonal(Color foreColor)
=> new PatternBrush(Brushes<Color>.ForwardDiagonal(foreColor, Color.Transparent));
public static PatternBrush ForwardDiagonal(Rgba32 foreColor)
=> new PatternBrush(Brushes<Rgba32>.ForwardDiagonal(foreColor, Rgba32.Transparent));
/// <summary>
/// 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="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush ForwardDiagonal(Color foreColor, Color backColor)
=> new PatternBrush(Brushes<Color>.ForwardDiagonal(foreColor, backColor));
public static PatternBrush ForwardDiagonal(Rgba32 foreColor, Rgba32 backColor)
=> new PatternBrush(Brushes<Rgba32>.ForwardDiagonal(foreColor, backColor));
/// <summary>
/// Create as brush that will paint a Backward Diagonal Hatch Pattern with
@ -138,8 +140,8 @@ namespace ImageSharp.Drawing.Brushes
/// </summary>
/// <param name="foreColor">Color of the foreground.</param>
/// <returns>A Brush</returns>
public static PatternBrush BackwardDiagonal(Color foreColor)
=> new PatternBrush(Brushes<Color>.BackwardDiagonal(foreColor, Color.Transparent));
public static PatternBrush BackwardDiagonal(Rgba32 foreColor)
=> new PatternBrush(Brushes<Rgba32>.BackwardDiagonal(foreColor, Rgba32.Transparent));
/// <summary>
/// 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="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush BackwardDiagonal(Color foreColor, Color backColor)
=> new PatternBrush(Brushes<Color>.BackwardDiagonal(foreColor, backColor));
public static PatternBrush BackwardDiagonal(Rgba32 foreColor, Rgba32 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.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Drawing.Brushes
{
using System;
using ImageSharp.PixelFormats;
/// <summary>
/// A collection of methods for creating generic brushes.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A Brush</returns>
public class Brushes<TColor>
where TColor : struct, IPixel<TColor>
public class Brushes<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Percent10 Hatch Pattern
@ -99,8 +99,8 @@ namespace ImageSharp.Drawing.Brushes
/// </summary>
/// <param name="color">The color.</param>
/// <returns>A Brush</returns>
public static SolidBrush<TColor> Solid(TColor color)
=> new SolidBrush<TColor>(color);
public static SolidBrush<TPixel> Solid(TPixel color)
=> new SolidBrush<TPixel>(color);
/// <summary>
/// Create as brush that will paint a Percent10 Hatch Pattern within the specified colors
@ -108,8 +108,8 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush<TColor> Percent10(TColor foreColor, TColor backColor)
=> new PatternBrush<TColor>(foreColor, backColor, Percent10Pattern);
public static PatternBrush<TPixel> Percent10(TPixel foreColor, TPixel backColor)
=> new PatternBrush<TPixel>(foreColor, backColor, Percent10Pattern);
/// <summary>
/// Create as brush that will paint a Percent20 Hatch Pattern within the specified colors
@ -117,8 +117,8 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush<TColor> Percent20(TColor foreColor, TColor backColor)
=> new PatternBrush<TColor>(foreColor, backColor, Percent20Pattern);
public static PatternBrush<TPixel> Percent20(TPixel foreColor, TPixel backColor)
=> new PatternBrush<TPixel>(foreColor, backColor, Percent20Pattern);
/// <summary>
/// Create as brush that will paint a Horizontal Hatch Pattern within the specified colors
@ -126,8 +126,8 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush<TColor> Horizontal(TColor foreColor, TColor backColor)
=> new PatternBrush<TColor>(foreColor, backColor, HorizontalPattern);
public static PatternBrush<TPixel> Horizontal(TPixel foreColor, TPixel backColor)
=> new PatternBrush<TPixel>(foreColor, backColor, HorizontalPattern);
/// <summary>
/// Create as brush that will paint a Min Hatch Pattern within the specified colors
@ -135,8 +135,8 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush<TColor> Min(TColor foreColor, TColor backColor)
=> new PatternBrush<TColor>(foreColor, backColor, MinPattern);
public static PatternBrush<TPixel> Min(TPixel foreColor, TPixel backColor)
=> new PatternBrush<TPixel>(foreColor, backColor, MinPattern);
/// <summary>
/// Create as brush that will paint a Vertical Hatch Pattern within the specified colors
@ -144,8 +144,8 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush<TColor> Vertical(TColor foreColor, TColor backColor)
=> new PatternBrush<TColor>(foreColor, backColor, VerticalPattern);
public static PatternBrush<TPixel> Vertical(TPixel foreColor, TPixel backColor)
=> new PatternBrush<TPixel>(foreColor, backColor, VerticalPattern);
/// <summary>
/// Create as brush that will paint a Forward Diagonal Hatch Pattern within the specified colors
@ -153,8 +153,8 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush<TColor> ForwardDiagonal(TColor foreColor, TColor backColor)
=> new PatternBrush<TColor>(foreColor, backColor, ForwardDiagonalPattern);
public static PatternBrush<TPixel> ForwardDiagonal(TPixel foreColor, TPixel backColor)
=> new PatternBrush<TPixel>(foreColor, backColor, ForwardDiagonalPattern);
/// <summary>
/// Create as brush that will paint a Backward Diagonal Hatch Pattern within the specified colors
@ -162,7 +162,7 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the foreground.</param>
/// <param name="backColor">Color of the background.</param>
/// <returns>A Brush</returns>
public static PatternBrush<TColor> BackwardDiagonal(TColor foreColor, TColor backColor)
=> new PatternBrush<TColor>(foreColor, backColor, BackwardDiagonalPattern);
public static PatternBrush<TPixel> BackwardDiagonal(TPixel foreColor, TPixel backColor)
=> new PatternBrush<TPixel>(foreColor, backColor, BackwardDiagonalPattern);
}
}

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

@ -5,20 +5,19 @@
namespace ImageSharp.Drawing
{
using System;
using ImageSharp.PixelFormats;
using Processors;
/// <summary>
/// Brush represents a logical configuration of a brush which can be used to source pixel colors
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <remarks>
/// A brush is a simple class that will return an <see cref="BrushApplicator{TColor}" /> that will perform the
/// logic for converting a pixel location to a <typeparamref name="TColor"/>.
/// 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="TPixel"/>.
/// </remarks>
public interface IBrush<TColor>
where TColor : struct, IPixel<TColor>
public interface IBrush<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// 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
/// bounding box of the shape not necessarily the bounds of the whole image
/// </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
{
using ImageSharp.PixelFormats;
/// <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>
public class ImageBrush : ImageBrush<Color>
public class ImageBrush : ImageBrush<Rgba32>
{
/// <summary>
/// Initializes a new instance of the <see cref="ImageBrush" /> class.
/// </summary>
/// <param name="image">The image to paint.</param>
public ImageBrush(IImageBase<Color> image)
public ImageBrush(IImageBase<Rgba32> 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.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Drawing.Brushes
{
using System;
using System.Numerics;
using ImageSharp.PixelFormats;
using Processors;
/// <summary>
/// Provides an implementation of an image brush for painting images within areas.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class ImageBrush<TColor> : IBrush<TColor>
where TColor : struct, IPixel<TColor>
/// <typeparam name="TPixel">The pixel format.</typeparam>
public class ImageBrush<TPixel> : IBrush<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// The image to paint.
/// </summary>
private readonly IImageBase<TColor> image;
private readonly IImageBase<TPixel> image;
/// <summary>
/// Initializes a new instance of the <see cref="ImageBrush{TColor}"/> class.
/// Initializes a new instance of the <see cref="ImageBrush{TPixel}"/> class.
/// </summary>
/// <param name="image">The image.</param>
public ImageBrush(IImageBase<TColor> image)
public ImageBrush(IImageBase<TPixel> image)
{
this.image = image;
}
/// <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);
}
@ -40,12 +39,12 @@ namespace ImageSharp.Drawing.Brushes
/// <summary>
/// The image brush applicator.
/// </summary>
private class ImageBrushApplicator : BrushApplicator<TColor>
private class ImageBrushApplicator : BrushApplicator<TPixel>
{
/// <summary>
/// The source pixel accessor.
/// </summary>
private readonly PixelAccessor<TColor> source;
private readonly PixelAccessor<TPixel> source;
/// <summary>
/// The y-length.
@ -74,7 +73,7 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="sourcePixels">
/// The sourcePixels.
/// </param>
public ImageBrushApplicator(PixelAccessor<TColor> sourcePixels, IImageBase<TColor> image, RectangleF region)
public ImageBrushApplicator(PixelAccessor<TPixel> sourcePixels, IImageBase<TPixel> image, RectangleF region)
: base(sourcePixels)
{
this.source = image.Lock();
@ -91,7 +90,7 @@ namespace ImageSharp.Drawing.Brushes
/// <returns>
/// The color
/// </returns>
internal override TColor this[int x, int y]
internal override TPixel this[int x, int y]
{
get
{
@ -135,7 +134,7 @@ namespace ImageSharp.Drawing.Brushes
Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity);
TColor packed = default(TColor);
TPixel packed = default(TPixel);
packed.PackFromVector4(finalColor);
this.Target[targetX, targetY] = packed;
}

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

@ -5,10 +5,12 @@
namespace ImageSharp.Drawing.Brushes
{
using ImageSharp.PixelFormats;
/// <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>
public class PatternBrush : PatternBrush<Color>
public class PatternBrush : PatternBrush<Rgba32>
{
/// <summary>
/// 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="backColor">Color of the back.</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)
{
}
@ -25,7 +27,7 @@ namespace ImageSharp.Drawing.Brushes
/// Initializes a new instance of the <see cref="PatternBrush"/> class.
/// </summary>
/// <param name="brush">The brush.</param>
internal PatternBrush(PatternBrush<Color> brush)
internal PatternBrush(PatternBrush<Rgba32> 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.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -7,7 +7,7 @@ namespace ImageSharp.Drawing.Brushes
{
using System;
using System.Numerics;
using ImageSharp.PixelFormats;
using Processors;
/// <summary>
@ -31,38 +31,38 @@ namespace ImageSharp.Drawing.Brushes
/// 0
/// </para>
/// </remarks>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class PatternBrush<TColor> : IBrush<TColor>
where TColor : struct, IPixel<TColor>
/// <typeparam name="TPixel">The pixel format.</typeparam>
public class PatternBrush<TPixel> : IBrush<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// The pattern.
/// </summary>
private readonly Fast2DArray<TColor> pattern;
private readonly Fast2DArray<TPixel> pattern;
private readonly Fast2DArray<Vector4> patternVector;
/// <summary>
/// Initializes a new instance of the <see cref="PatternBrush{TColor}"/> class.
/// Initializes a new instance of the <see cref="PatternBrush{TPixel}"/> class.
/// </summary>
/// <param name="foreColor">Color of the fore.</param>
/// <param name="backColor">Color of the back.</param>
/// <param name="pattern">The pattern.</param>
public PatternBrush(TColor foreColor, TColor backColor, bool[,] pattern)
public PatternBrush(TPixel foreColor, TPixel backColor, bool[,] pattern)
: this(foreColor, backColor, new Fast2DArray<bool>(pattern))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="PatternBrush{TColor}"/> class.
/// Initializes a new instance of the <see cref="PatternBrush{TPixel}"/> class.
/// </summary>
/// <param name="foreColor">Color of the fore.</param>
/// <param name="backColor">Color of the back.</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 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);
for (int i = 0; i < pattern.Data.Length; i++)
{
@ -80,17 +80,17 @@ namespace ImageSharp.Drawing.Brushes
}
/// <summary>
/// Initializes a new instance of the <see cref="PatternBrush{TColor}"/> class.
/// Initializes a new instance of the <see cref="PatternBrush{TPixel}"/> class.
/// </summary>
/// <param name="brush">The brush.</param>
internal PatternBrush(PatternBrush<TColor> brush)
internal PatternBrush(PatternBrush<TPixel> brush)
{
this.pattern = brush.pattern;
this.patternVector = brush.patternVector;
}
/// <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);
}
@ -98,12 +98,12 @@ namespace ImageSharp.Drawing.Brushes
/// <summary>
/// The pattern brush applicator.
/// </summary>
private class PatternBrushApplicator : BrushApplicator<TColor>
private class PatternBrushApplicator : BrushApplicator<TPixel>
{
/// <summary>
/// The pattern.
/// </summary>
private readonly Fast2DArray<TColor> pattern;
private readonly Fast2DArray<TPixel> pattern;
private readonly Fast2DArray<Vector4> patternVector;
/// <summary>
@ -112,7 +112,7 @@ namespace ImageSharp.Drawing.Brushes
/// <param name="sourcePixels">The sourcePixels.</param>
/// <param name="pattern">The pattern.</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)
{
this.pattern = pattern;
@ -127,7 +127,7 @@ namespace ImageSharp.Drawing.Brushes
/// <returns>
/// The Color.
/// </returns>
internal override TColor this[int x, int y]
internal override TPixel this[int x, int y]
{
get
{
@ -169,7 +169,7 @@ namespace ImageSharp.Drawing.Brushes
Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity);
TColor packed = default(TColor);
TPixel packed = default(TPixel);
packed.PackFromVector4(finalColor);
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.Numerics;
using System.Runtime.CompilerServices;
using ImageSharp.PixelFormats;
/// <summary>
/// primitive that converts a point in to a color for discovering the fill color based on an implementation
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <seealso cref="System.IDisposable" />
public abstract class BrushApplicator<TColor> : IDisposable // disposable will be required if/when there is an ImageBrush
where TColor : struct, IPixel<TColor>
public abstract class BrushApplicator<TPixel> : IDisposable // disposable will be required if/when there is an ImageBrush
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Initializes a new instance of the <see cref="BrushApplicator{TColor}"/> class.
/// Initializes a new instance of the <see cref="BrushApplicator{TPixel}"/> class.
/// </summary>
/// <param name="target">The target.</param>
internal BrushApplicator(PixelAccessor<TColor> target)
internal BrushApplicator(PixelAccessor<TPixel> target)
{
this.Target = target;
}
@ -29,15 +29,15 @@ namespace ImageSharp.Drawing.Processors
/// <summary>
/// Gets the destinaion
/// </summary>
protected PixelAccessor<TColor> Target { get; }
protected PixelAccessor<TPixel> Target { get; }
/// <summary>
/// Gets the color for a single pixel.
/// </summary>
/// <param name="x">The x cordinate.</param>
/// <param name="y">The y cordinate.</param>
/// <returns>The a <typeparamref name="TColor"/> that should be applied to the pixel.</returns>
internal abstract TColor this[int x, int y] { get; }
/// <returns>The a <typeparamref name="TPixel"/> that should be applied to the pixel.</returns>
internal abstract TPixel this[int x, int y] { get; }
/// <inheritdoc/>
public abstract void Dispose();
@ -73,7 +73,7 @@ namespace ImageSharp.Drawing.Processors
Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity);
TColor packed = default(TColor);
TPixel packed = default(TPixel);
packed.PackFromVector4(finalColor);
this.Target[targetX, targetY] = packed;
}

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

@ -5,19 +5,21 @@
namespace ImageSharp.Drawing.Brushes
{
using ImageSharp.PixelFormats;
/// <summary>
/// Provides an implementation of a recolor brush for painting color changes.
/// </summary>
public class RecolorBrush : RecolorBrush<Color>
public class RecolorBrush : RecolorBrush<Rgba32>
{
/// <summary>
/// Initializes a new instance of the <see cref="RecolorBrush" /> class.
/// </summary>
/// <param name="sourceColor">Color of the source.</param>
/// <param name="targetColor">Color of the target.</param>
/// <param name="targeTPixel">Color of the target.</param>
/// <param name="threshold">The threshold.</param>
public RecolorBrush(Color sourceColor, Color targetColor, float threshold)
: base(sourceColor, targetColor, threshold)
public RecolorBrush(Rgba32 sourceColor, Rgba32 targeTPixel, float 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.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Drawing.Brushes
{
using System;
using System.Numerics;
using ImageSharp.PixelFormats;
using Processors;
/// <summary>
/// Provides an implementation of a brush that can recolor an image
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class RecolorBrush<TColor> : IBrush<TColor>
where TColor : struct, IPixel<TColor>
/// <typeparam name="TPixel">The pixel format.</typeparam>
public class RecolorBrush<TPixel> : IBrush<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Initializes a new instance of the <see cref="RecolorBrush{TColor}" /> class.
/// Initializes a new instance of the <see cref="RecolorBrush{TPixel}" /> class.
/// </summary>
/// <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>
public RecolorBrush(TColor sourceColor, TColor targetColor, float threshold)
public RecolorBrush(TPixel sourceColor, TPixel targeTPixel, float threshold)
{
this.SourceColor = sourceColor;
this.Threshold = threshold;
this.TargetColor = targetColor;
this.TargeTPixel = targeTPixel;
}
/// <summary>
@ -44,7 +43,7 @@ namespace ImageSharp.Drawing.Brushes
/// <value>
/// The color of the source.
/// </value>
public TColor SourceColor { get; }
public TPixel SourceColor { get; }
/// <summary>
/// Gets the target color.
@ -52,18 +51,18 @@ namespace ImageSharp.Drawing.Brushes
/// <value>
/// The color of the target.
/// </value>
public TColor TargetColor { get; }
public TPixel TargeTPixel { get; }
/// <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>
/// The recolor brush applicator.
/// </summary>
private class RecolorBrushApplicator : BrushApplicator<TColor>
private class RecolorBrushApplicator : BrushApplicator<TPixel>
{
/// <summary>
/// The source color.
@ -73,7 +72,7 @@ namespace ImageSharp.Drawing.Brushes
/// <summary>
/// The target color.
/// </summary>
private readonly Vector4 targetColor;
private readonly Vector4 targeTPixel;
/// <summary>
/// The threshold.
@ -85,18 +84,18 @@ namespace ImageSharp.Drawing.Brushes
/// </summary>
/// <param name="sourcePixels">The source pixels.</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>
public RecolorBrushApplicator(PixelAccessor<TColor> sourcePixels, TColor sourceColor, TColor targetColor, float threshold)
public RecolorBrushApplicator(PixelAccessor<TPixel> sourcePixels, TPixel sourceColor, TPixel targeTPixel, float threshold)
: base(sourcePixels)
{
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 :)
TColor maxColor = default(TColor);
TPixel maxColor = default(TPixel);
maxColor.PackFromVector4(new Vector4(float.MaxValue));
TColor minColor = default(TColor);
TPixel minColor = default(TPixel);
minColor.PackFromVector4(new Vector4(float.MinValue));
this.threshold = Vector4.DistanceSquared(maxColor.ToVector4(), minColor.ToVector4()) * threshold;
}
@ -109,12 +108,12 @@ namespace ImageSharp.Drawing.Brushes
/// <returns>
/// The color
/// </returns>
internal override TColor this[int x, int y]
internal override TPixel this[int x, int y]
{
get
{
// Offset the requested pixel by the value in the rectangle (the shapes position)
TColor result = this.Target[x, y];
TPixel result = this.Target[x, y];
Vector4 background = result.ToVector4();
float distance = Vector4.DistanceSquared(background, this.sourceColor);
if (distance <= this.threshold)
@ -122,7 +121,7 @@ namespace ImageSharp.Drawing.Brushes
float lerpAmount = (this.threshold - distance) / this.threshold;
Vector4 blended = Vector4BlendTransforms.PremultipliedLerp(
background,
this.targetColor,
this.targeTPixel,
lerpAmount);
result.PackFromVector4(blended);
}
@ -162,12 +161,12 @@ namespace ImageSharp.Drawing.Brushes
float lerpAmount = (this.threshold - distance) / this.threshold;
sourceVector = Vector4BlendTransforms.PremultipliedLerp(
sourceVector,
this.targetColor,
this.targeTPixel,
lerpAmount);
Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity);
TColor packed = default(TColor);
TPixel packed = default(TPixel);
packed.PackFromVector4(finalColor);
this.Target[targetX, targetY] = packed;
}

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

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

21
src/ImageSharp.Drawing/DrawImage.cs

@ -5,9 +5,8 @@
namespace ImageSharp
{
using System;
using Drawing.Processors;
using ImageSharp.PixelFormats;
/// <summary>
/// Extension methods for the <see cref="Image"/> type.
@ -17,13 +16,13 @@ namespace ImageSharp
/// <summary>
/// Draws the given image together with the current one by blending their pixels.
/// </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="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>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Blend<TColor>(this Image<TColor> source, Image<TColor> image, int percent = 50)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Blend<TPixel>(this Image<TPixel> source, Image<TPixel> image, int percent = 50)
where TPixel : struct, IPixel<TPixel>
{
return DrawImage(source, image, percent, default(Size), default(Point));
}
@ -33,13 +32,13 @@ namespace ImageSharp
/// </summary>
/// <param name="source">The image this method extends.</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="size">The size to draw the blended image.</param>
/// <param name="location">The location to draw the blended image.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> DrawImage<TColor>(this Image<TColor> source, Image<TColor> image, int percent, Size size, Point location)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> DrawImage<TPixel>(this Image<TPixel> source, Image<TPixel> image, int percent, Size size, Point location)
where TPixel : struct, IPixel<TPixel>
{
if (size == default(Size))
{
@ -51,7 +50,7 @@ namespace ImageSharp
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;
}
}

63
src/ImageSharp.Drawing/DrawPath.cs

@ -5,43 +5,42 @@
namespace ImageSharp
{
using System;
using Drawing;
using Drawing.Brushes;
using Drawing.Pens;
using Drawing.Processors;
using ImageSharp.PixelFormats;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Draws the outline of the region with the provided pen.
/// </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="pen">The pen.</param>
/// <param name="path">The path.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, Drawable path, GraphicsOptions options)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, IPen<TPixel> pen, Drawable path, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Apply(new DrawPathProcessor<TColor>(pen, path, options));
return source.Apply(new DrawPathProcessor<TPixel>(pen, path, options));
}
/// <summary>
/// Draws the outline of the polygon with the provided pen.
/// </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="pen">The pen.</param>
/// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, Drawable path)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, IPen<TPixel> pen, Drawable path)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, path, GraphicsOptions.Default);
}
@ -49,63 +48,63 @@ namespace ImageSharp
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </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="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Drawable path, GraphicsOptions options)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, float thickness, Drawable path, GraphicsOptions options)
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>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </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="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Drawable path)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, float thickness, Drawable path)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TColor>(brush, thickness), path);
return source.Draw(new Pen<TPixel>(brush, thickness), path);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </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="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, Drawable path, GraphicsOptions options)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, TPixel color, float thickness, Drawable path, GraphicsOptions options)
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>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </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="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, Drawable path)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, TPixel color, float thickness, Drawable path)
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
{
using System;
using Drawing;
using Drawing.Brushes;
using Drawing.Processors;
using ImageSharp.PixelFormats;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Flood fills the image with the specified brush.
/// </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="brush">The details how to fill the region of interest.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush)
where TPixel : struct, IPixel<TPixel>
{
return source.Apply(new FillProcessor<TColor>(brush));
return source.Apply(new FillProcessor<TPixel>(brush));
}
/// <summary>
/// Flood fills the image with the specified color.
/// </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="color">The color.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, TPixel color)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TColor>(color));
return source.Fill(new SolidBrush<TPixel>(color));
}
/// <summary>
/// Flood fills the image with in the region with the specified brush.
/// </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="brush">The brush.</param>
/// <param name="region">The region.</param>
/// <param name="options">The graphics options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, Region region, GraphicsOptions options)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, Region region, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Apply(new FillRegionProcessor<TColor>(brush, region, options));
return source.Apply(new FillRegionProcessor<TPixel>(brush, region, options));
}
/// <summary>
/// Flood fills the image with in the region with the specified brush.
/// </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="brush">The brush.</param>
/// <param name="region">The region.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, Region region)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, Region region)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, region, GraphicsOptions.Default);
}
@ -74,30 +73,30 @@ namespace ImageSharp
/// <summary>
/// Flood fills the image with in the region with the specified color.
/// </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="color">The color.</param>
/// <param name="region">The region.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, Region region, GraphicsOptions options)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, TPixel color, Region region, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TColor>(color), region, options);
return source.Fill(new SolidBrush<TPixel>(color), region, options);
}
/// <summary>
/// Flood fills the image with in the region with the specified color.
/// </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="color">The color.</param>
/// <param name="region">The region.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, Region region)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, TPixel color, Region region)
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>
<Description>An extension to ImageSharp that allows the drawing of images, paths, and text.</Description>
<AssemblyTitle>ImageSharp.Drawing</AssemblyTitle>
<VersionPrefix>1.0.0-alpha6</VersionPrefix>
<VersionPrefix>1.0.0-alpha7</VersionPrefix>
<Authors>James Jackson-South and contributors</Authors>
<TargetFramework>netstandard1.1</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

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

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

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

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

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

@ -5,30 +5,28 @@
namespace ImageSharp
{
using System;
using Drawing;
using Drawing.Brushes;
using Drawing.Pens;
using ImageSharp.PixelFormats;
using SixLabors.Shapes;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Draws the outline of the polygon with the provided pen.
/// </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="pen">The pen.</param>
/// <param name="path">The path.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, IPath path, GraphicsOptions options)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, IPen<TPixel> pen, IPath path, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, new ShapePath(path), options);
}
@ -36,13 +34,13 @@ namespace ImageSharp
/// <summary>
/// Draws the outline of the polygon with the provided pen.
/// </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="pen">The pen.</param>
/// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, IPath path)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, IPen<TPixel> pen, IPath path)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, path, GraphicsOptions.Default);
}
@ -50,63 +48,63 @@ namespace ImageSharp
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </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="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="path">The shape.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IPath path, GraphicsOptions options)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, float thickness, IPath path, GraphicsOptions options)
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>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </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="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IPath path)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, float thickness, IPath path)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TColor>(brush, thickness), path);
return source.Draw(new Pen<TPixel>(brush, thickness), path);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </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="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, IPath path, GraphicsOptions options)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, TPixel color, float thickness, IPath path, GraphicsOptions options)
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>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </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="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, IPath path)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, TPixel color, float thickness, IPath path)
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
{
using System;
using System.Numerics;
using Drawing;
using Drawing.Brushes;
using Drawing.Pens;
using ImageSharp.PixelFormats;
using SixLabors.Shapes;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
/// </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="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> DrawPolygon<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, float thickness, Vector2[] points, GraphicsOptions options)
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>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
/// </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="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> DrawPolygon<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, float thickness, Vector2[] points)
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>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
/// </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="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> DrawPolygon<TPixel>(this Image<TPixel> source, TPixel color, float thickness, Vector2[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawPolygon(new SolidBrush<TColor>(color), thickness, points);
return source.DrawPolygon(new SolidBrush<TPixel>(color), thickness, points);
}
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
/// </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="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> DrawPolygon<TPixel>(this Image<TPixel> source, TPixel color, float thickness, Vector2[] points, GraphicsOptions options)
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>
/// Draws the provided Points as a closed Linear Polygon with the provided Pen.
/// </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="pen">The pen.</param>
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> DrawPolygon<TPixel>(this Image<TPixel> source, IPen<TPixel> pen, Vector2[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, new Polygon(new LinearLineSegment(points)), GraphicsOptions.Default);
}
@ -97,14 +96,14 @@ namespace ImageSharp
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided Pen.
/// </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="pen">The pen.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> DrawPolygon<TPixel>(this Image<TPixel> source, IPen<TPixel> pen, Vector2[] points, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, new Polygon(new LinearLineSegment(points)), options);
}

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

@ -5,28 +5,27 @@
namespace ImageSharp
{
using System;
using Drawing;
using Drawing.Brushes;
using Drawing.Pens;
using ImageSharp.PixelFormats;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Draws the outline of the polygon with the provided pen.
/// </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="pen">The pen.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, Rectangle shape, GraphicsOptions options)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, IPen<TPixel> pen, Rectangle shape, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, new SixLabors.Shapes.Rectangle(shape.X, shape.Y, shape.Width, shape.Height), options);
}
@ -34,13 +33,13 @@ namespace ImageSharp
/// <summary>
/// Draws the outline of the polygon with the provided pen.
/// </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="pen">The pen.</param>
/// <param name="shape">The shape.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, Rectangle shape)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, IPen<TPixel> pen, Rectangle shape)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, shape, GraphicsOptions.Default);
}
@ -48,63 +47,63 @@ namespace ImageSharp
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </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="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Rectangle shape, GraphicsOptions options)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, float thickness, Rectangle shape, GraphicsOptions options)
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>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </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="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Rectangle shape)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, float thickness, Rectangle shape)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TColor>(brush, thickness), shape);
return source.Draw(new Pen<TPixel>(brush, thickness), shape);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </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="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, Rectangle shape, GraphicsOptions options)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, TPixel color, float thickness, Rectangle shape, GraphicsOptions options)
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>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </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="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, Rectangle shape)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Draw<TPixel>(this Image<TPixel> source, TPixel color, float thickness, Rectangle shape)
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
{
using System;
using Drawing;
using Drawing.Brushes;
using ImageSharp.PixelFormats;
using SixLabors.Shapes;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </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="brush">The brush.</param>
/// <param name="path">The shape.</param>
/// <param name="options">The graphics options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, IPath path, GraphicsOptions options)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, IPath path, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, new ShapeRegion(path), options);
}
@ -35,13 +33,13 @@ namespace ImageSharp
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </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="brush">The brush.</param>
/// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, IPath path)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, IPath path)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, new ShapeRegion(path), GraphicsOptions.Default);
}
@ -49,30 +47,30 @@ namespace ImageSharp
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </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="color">The color.</param>
/// <param name="path">The path.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, IPath path, GraphicsOptions options)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, TPixel color, IPath path, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TColor>(color), path, options);
return source.Fill(new SolidBrush<TPixel>(color), path, options);
}
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </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="color">The color.</param>
/// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, IPath path)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, TPixel color, IPath path)
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 Drawing;
using Drawing.Brushes;
using ImageSharp.PixelFormats;
using SixLabors.Shapes;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points
/// </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="brush">The brush.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> FillPolygon<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, Vector2[] points, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, new Polygon(new LinearLineSegment(points)), options);
}
@ -35,13 +35,13 @@ namespace ImageSharp
/// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points
/// </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="brush">The brush.</param>
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, Vector2[] points)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> FillPolygon<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, Vector2[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, new Polygon(new LinearLineSegment(points)));
}
@ -49,30 +49,30 @@ namespace ImageSharp
/// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points
/// </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="color">The color.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, TColor color, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> FillPolygon<TPixel>(this Image<TPixel> source, TPixel color, Vector2[] points, GraphicsOptions options)
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>
/// Flood fills the image in the shape of a Linear polygon described by the points
/// </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="color">The color.</param>
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, TColor color, Vector2[] points)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> FillPolygon<TPixel>(this Image<TPixel> source, TPixel color, Vector2[] points)
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
{
using System;
using Drawing;
using Drawing.Brushes;
using ImageSharp.PixelFormats;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </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="brush">The brush.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, Rectangle shape, GraphicsOptions options)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, Rectangle shape, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, new SixLabors.Shapes.Rectangle(shape.X, shape.Y, shape.Width, shape.Height), options);
}
@ -33,13 +32,13 @@ namespace ImageSharp
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </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="brush">The brush.</param>
/// <param name="shape">The shape.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, Rectangle shape)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, IBrush<TPixel> brush, Rectangle shape)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, new SixLabors.Shapes.Rectangle(shape.X, shape.Y, shape.Width, shape.Height));
}
@ -47,30 +46,30 @@ namespace ImageSharp
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </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="color">The color.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, Rectangle shape, GraphicsOptions options)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, TPixel color, Rectangle shape, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TColor>(color), shape, options);
return source.Fill(new SolidBrush<TPixel>(color), shape, options);
}
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </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="color">The color.</param>
/// <param name="shape">The shape.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, Rectangle shape)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Fill<TPixel>(this Image<TPixel> source, TPixel color, Rectangle shape)
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
{
using System;
using ImageSharp.PixelFormats;
using Processors;
/// <summary>
/// Interface representing a Pen
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
public interface IPen<TColor>
where TColor : struct, IPixel<TColor>
/// <typeparam name="TPixel">The type of the color.</typeparam>
public interface IPen<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Creates the applicator for applying this pen to an Image
@ -26,6 +26,6 @@ namespace ImageSharp.Drawing.Pens
/// <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.
/// </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
{
using ImageSharp.PixelFormats;
/// <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>
public class Pen : Pen<Color>
public class Pen : Pen<Rgba32>
{
/// <summary>
/// Initializes a new instance of the <see cref="Pen"/> class.
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
public Pen(Color color, float width)
public Pen(Rgba32 color, float width)
: base(color, width)
{
}
@ -25,7 +27,7 @@ namespace ImageSharp.Drawing.Pens
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
public Pen(IBrush<Color> brush, float width)
public Pen(IBrush<Rgba32> brush, float width)
: base(brush, width)
{
}
@ -36,7 +38,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</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)
{
}
@ -45,7 +47,7 @@ namespace ImageSharp.Drawing.Pens
/// Initializes a new instance of the <see cref="Pen"/> class.
/// </summary>
/// <param name="pen">The pen.</param>
internal Pen(Pen<Color> pen)
internal Pen(Pen<Rgba32> pen)
: base(pen)
{
}

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

@ -5,6 +5,8 @@
namespace ImageSharp.Drawing.Pens
{
using ImageSharp.PixelFormats;
/// <summary>
/// Common Pen styles
/// </summary>
@ -16,7 +18,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <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>
/// 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="width">The width.</param>
/// <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>
/// Create a pen with a 'Dash' drawing patterns
@ -32,7 +34,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <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>
/// Create a pen with a 'Dash' drawing patterns
@ -40,7 +42,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <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>
/// Create a pen with a 'Dot' drawing patterns
@ -48,7 +50,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <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>
/// Create a pen with a 'Dot' drawing patterns
@ -56,7 +58,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <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>
/// 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="width">The width.</param>
/// <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>
/// 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="width">The width.</param>
/// <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>
/// 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="width">The width.</param>
/// <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>
/// 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="width">The width.</param>
/// <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.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Drawing.Pens
{
using System;
using ImageSharp.PixelFormats;
/// <summary>
/// Common Pen styles
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
public class Pens<TColor>
where TColor : struct, IPixel<TColor>
/// <typeparam name="TPixel">The type of the color.</typeparam>
public class Pens<TPixel>
where TPixel : struct, IPixel<TPixel>
{
private static readonly float[] DashDotPattern = new[] { 3f, 1f, 1f, 1f };
private static readonly float[] DashDotDotPattern = new[] { 3f, 1f, 1f, 1f, 1f, 1f };
@ -25,8 +25,8 @@ namespace ImageSharp.Drawing.Pens
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor> Solid(TColor color, float width)
=> new Pen<TColor>(color, width);
public static Pen<TPixel> Solid(TPixel color, float width)
=> new Pen<TPixel>(color, width);
/// <summary>
/// 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="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor> Solid(IBrush<TColor> brush, float width)
=> new Pen<TColor>(brush, width);
public static Pen<TPixel> Solid(IBrush<TPixel> brush, float width)
=> new Pen<TPixel>(brush, width);
/// <summary>
/// Create a pen with a 'Dash' drawing patterns
@ -43,8 +43,8 @@ namespace ImageSharp.Drawing.Pens
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor> Dash(TColor color, float width)
=> new Pen<TColor>(color, width, DashedPattern);
public static Pen<TPixel> Dash(TPixel color, float width)
=> new Pen<TPixel>(color, width, DashedPattern);
/// <summary>
/// Create a pen with a 'Dash' drawing patterns
@ -52,8 +52,8 @@ namespace ImageSharp.Drawing.Pens
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor> Dash(IBrush<TColor> brush, float width)
=> new Pen<TColor>(brush, width, DashedPattern);
public static Pen<TPixel> Dash(IBrush<TPixel> brush, float width)
=> new Pen<TPixel>(brush, width, DashedPattern);
/// <summary>
/// Create a pen with a 'Dot' drawing patterns
@ -61,8 +61,8 @@ namespace ImageSharp.Drawing.Pens
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor> Dot(TColor color, float width)
=> new Pen<TColor>(color, width, DottedPattern);
public static Pen<TPixel> Dot(TPixel color, float width)
=> new Pen<TPixel>(color, width, DottedPattern);
/// <summary>
/// Create a pen with a 'Dot' drawing patterns
@ -70,8 +70,8 @@ namespace ImageSharp.Drawing.Pens
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor> Dot(IBrush<TColor> brush, float width)
=> new Pen<TColor>(brush, width, DottedPattern);
public static Pen<TPixel> Dot(IBrush<TPixel> brush, float width)
=> new Pen<TPixel>(brush, width, DottedPattern);
/// <summary>
/// Create a pen with a 'Dash Dot' drawing patterns
@ -79,8 +79,8 @@ namespace ImageSharp.Drawing.Pens
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor> DashDot(TColor color, float width)
=> new Pen<TColor>(color, width, DashDotPattern);
public static Pen<TPixel> DashDot(TPixel color, float width)
=> new Pen<TPixel>(color, width, DashDotPattern);
/// <summary>
/// Create a pen with a 'Dash Dot' drawing patterns
@ -88,8 +88,8 @@ namespace ImageSharp.Drawing.Pens
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor> DashDot(IBrush<TColor> brush, float width)
=> new Pen<TColor>(brush, width, DashDotPattern);
public static Pen<TPixel> DashDot(IBrush<TPixel> brush, float width)
=> new Pen<TPixel>(brush, width, DashDotPattern);
/// <summary>
/// Create a pen with a 'Dash Dot Dot' drawing patterns
@ -97,8 +97,8 @@ namespace ImageSharp.Drawing.Pens
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor> DashDotDot(TColor color, float width)
=> new Pen<TColor>(color, width, DashDotDotPattern);
public static Pen<TPixel> DashDotDot(TPixel color, float width)
=> new Pen<TPixel>(color, width, DashDotDotPattern);
/// <summary>
/// Create a pen with a 'Dash Dot Dot' drawing patterns
@ -106,7 +106,7 @@ namespace ImageSharp.Drawing.Pens
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
/// <returns>The Pen</returns>
public static Pen<TColor> DashDotDot(IBrush<TColor> brush, float width)
=> new Pen<TColor>(brush, width, DashDotDotPattern);
public static Pen<TPixel> DashDotDot(IBrush<TPixel> brush, float width)
=> 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.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Drawing.Pens
{
using System;
using System.Numerics;
using ImageSharp.Drawing.Brushes;
using ImageSharp.PixelFormats;
using Processors;
/// <summary>
/// Provides a pen that can apply a pattern to a line with a set brush and thickness
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <remarks>
/// 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
@ -23,30 +23,30 @@ namespace ImageSharp.Drawing.Pens
/// section 3 will be width/2 long and will be filled
/// the the pattern will imidiatly repeat without gap.
/// </remarks>
public class Pen<TColor> : IPen<TColor>
where TColor : struct, IPixel<TColor>
public class Pen<TPixel> : IPen<TPixel>
where TPixel : struct, IPixel<TPixel>
{
private static readonly float[] EmptyPattern = new float[0];
private readonly float[] pattern;
/// <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>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
/// <param name="pattern">The pattern.</param>
public Pen(TColor color, float width, float[] pattern)
: this(new SolidBrush<TColor>(color), width, pattern)
public Pen(TPixel color, float width, float[] pattern)
: this(new SolidBrush<TPixel>(color), width, pattern)
{
}
/// <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>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</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.Width = width;
@ -54,30 +54,30 @@ namespace ImageSharp.Drawing.Pens
}
/// <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>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
public Pen(TColor color, float width)
: this(new SolidBrush<TColor>(color), width)
public Pen(TPixel color, float width)
: this(new SolidBrush<TPixel>(color), width)
{
}
/// <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>
/// <param name="brush">The brush.</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)
{
}
/// <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>
/// <param name="pen">The pen.</param>
internal Pen(Pen<TColor> pen)
internal Pen(Pen<TPixel> pen)
: this(pen.Brush, pen.Width, pen.pattern)
{
}
@ -88,7 +88,7 @@ namespace ImageSharp.Drawing.Pens
/// <value>
/// The brush.
/// </value>
public IBrush<TColor> Brush { get; }
public IBrush<TPixel> Brush { get; }
/// <summary>
/// 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
/// bounding box of the shape not necorserrally the shape of the whole image
/// </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)
{
@ -122,12 +122,12 @@ namespace ImageSharp.Drawing.Pens
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;
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.halfWidth = width / 2;
@ -144,9 +144,9 @@ namespace ImageSharp.Drawing.Pens
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];
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[] pattern;
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.halfWidth = width / 2;
@ -197,16 +197,16 @@ namespace ImageSharp.Drawing.Pens
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
float length = info.DistanceAlongPath % this.totalLength;
// 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
// 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];
float distanceWAway = 0;

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

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

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

@ -6,14 +6,14 @@
namespace ImageSharp.Drawing.Processors
{
using System;
using System.Numerics;
using ImageSharp.PixelFormats;
/// <summary>
/// primitive that converts a <see cref="PointInfo"/> into a color and a distance away from the drawable part of the path.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
public abstract class PenApplicator<TColor> : IDisposable
where TColor : struct, IPixel<TColor>
/// <typeparam name="TPixel">The type of the color.</typeparam>
public abstract class PenApplicator<TPixel> : IDisposable
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Gets the required region.
@ -27,7 +27,7 @@ namespace ImageSharp.Drawing.Processors
public abstract void Dispose();
/// <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>
/// <param name="x">The x.</param>
/// <param name="y">The y.</param>
@ -35,6 +35,6 @@ namespace ImageSharp.Drawing.Processors
/// <returns>
/// Returns the color details and distance from a solid bit of the line.
/// </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.Numerics;
using System.Threading.Tasks;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
/// <summary>
/// Combines two images together by blending the pixels.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
internal class DrawImageProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPixel<TColor>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class DrawImageProcessor<TPixel> : ImageProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Initializes a new instance of the <see cref="DrawImageProcessor{TColor}"/> class.
/// Initializes a new instance of the <see cref="DrawImageProcessor{TPixel}"/> class.
/// </summary>
/// <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="location">The location to draw the blended image.</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));
this.Image = image;
@ -37,7 +37,7 @@ namespace ImageSharp.Drawing.Processors
/// <summary>
/// Gets the image to blend.
/// </summary>
public Image<TColor> Image { get; private set; }
public Image<TPixel> Image { get; private set; }
/// <summary>
/// Gets the alpha percentage value.
@ -55,7 +55,7 @@ namespace ImageSharp.Drawing.Processors
public Point Location { get; }
/// <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)
{
@ -72,8 +72,8 @@ namespace ImageSharp.Drawing.Processors
float alpha = this.Alpha / 100F;
using (PixelAccessor<TColor> toBlendPixels = this.Image.Lock())
using (PixelAccessor<TColor> sourcePixels = source.Lock())
using (PixelAccessor<TPixel> toBlendPixels = this.Image.Lock())
using (PixelAccessor<TPixel> sourcePixels = source.Lock())
{
Parallel.For(
minY,
@ -89,7 +89,7 @@ namespace ImageSharp.Drawing.Processors
// Lerping colors is dependent on the alpha of the blended color
backgroundVector = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, alpha);
TColor packed = default(TColor);
TPixel packed = default(TPixel);
packed.PackFromVector4(backgroundVector);
sourcePixels[x, y] = packed;
}

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

@ -8,28 +8,28 @@ namespace ImageSharp.Drawing.Processors
using System;
using System.Numerics;
using System.Threading.Tasks;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using Pens;
/// <summary>
/// Draws a path using the processor pipeline
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <seealso cref="ImageSharp.Processing.ImageProcessor{TColor}" />
internal class DrawPathProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPixel<TColor>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <seealso cref="ImageSharp.Processing.ImageProcessor{TPixel}" />
internal class DrawPathProcessor<TPixel> : ImageProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
private const float AntialiasFactor = 1f;
private const int PaddingFactor = 1; // needs to been the same or greater than AntialiasFactor
/// <summary>
/// Initializes a new instance of the <see cref="DrawPathProcessor{TColor}" /> class.
/// Initializes a new instance of the <see cref="DrawPathProcessor{TPixel}" /> class.
/// </summary>
/// <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="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.Pen = pen;
@ -44,7 +44,7 @@ namespace ImageSharp.Drawing.Processors
/// <summary>
/// Gets the pen.
/// </summary>
public IPen<TColor> Pen { get; }
public IPen<TPixel> Pen { get; }
/// <summary>
/// Gets the path.
@ -52,10 +52,10 @@ namespace ImageSharp.Drawing.Processors
public Drawable Path { get; }
/// <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 (PenApplicator<TColor> applicator = this.Pen.CreateApplicator(sourcePixels, this.Path.Bounds))
using (PixelAccessor<TPixel> sourcePixels = source.Lock())
using (PenApplicator<TPixel> applicator = this.Pen.CreateApplicator(sourcePixels, this.Path.Bounds))
{
Rectangle rect = RectangleF.Ceiling(applicator.RequiredRegion);
@ -100,7 +100,7 @@ namespace ImageSharp.Drawing.Processors
int offsetX = x - startX;
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);
@ -111,7 +111,7 @@ namespace ImageSharp.Drawing.Processors
Vector4 finalColor = Vector4BlendTransforms.PremultipliedLerp(backgroundVector, sourceVector, opacity);
TColor packed = default(TColor);
TPixel packed = default(TPixel);
packed.PackFromVector4(finalColor);
sourcePixels[offsetX, offsetY] = packed;
}

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

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

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

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

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

@ -10,11 +10,11 @@ namespace ImageSharp
using Drawing;
using Drawing.Brushes;
using Drawing.Pens;
using ImageSharp.PixelFormats;
using SixLabors.Fonts;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -23,17 +23,17 @@ namespace ImageSharp
/// <summary>
/// Draws the text onto the the image filled via the brush.
/// </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="text">The text.</param>
/// <param name="font">The font.</param>
/// <param name="color">The color.</param>
/// <param name="location">The location.</param>
/// <returns>
/// The <see cref="Image{TColor}" />.
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static Image<TColor> DrawText<TColor>(this Image<TColor> source, string text, Font font, TColor color, Vector2 location)
where TColor : struct, IPixel<TColor>
public static Image<TPixel> DrawText<TPixel>(this Image<TPixel> source, string text, Font font, TPixel color, Vector2 location)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, color, location, TextGraphicsOptions.Default);
}
@ -41,7 +41,7 @@ namespace ImageSharp
/// <summary>
/// Draws the text onto the the image filled via the brush.
/// </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="text">The text.</param>
/// <param name="font">The font.</param>
@ -49,28 +49,28 @@ namespace ImageSharp
/// <param name="location">The location.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The <see cref="Image{TColor}" />.
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static Image<TColor> DrawText<TColor>(this Image<TColor> source, string text, Font font, TColor color, Vector2 location, TextGraphicsOptions options)
where TColor : struct, IPixel<TColor>
public static Image<TPixel> DrawText<TPixel>(this Image<TPixel> source, string text, Font font, TPixel color, Vector2 location, TextGraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, Brushes<TColor>.Solid(color), null, location, options);
return source.DrawText(text, font, Brushes<TPixel>.Solid(color), null, location, options);
}
/// <summary>
/// Draws the text onto the the image filled via the brush.
/// </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="text">The text.</param>
/// <param name="font">The font.</param>
/// <param name="brush">The brush.</param>
/// <param name="location">The location.</param>
/// <returns>
/// The <see cref="Image{TColor}" />.
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static Image<TColor> DrawText<TColor>(this Image<TColor> source, string text, Font font, IBrush<TColor> brush, Vector2 location)
where TColor : struct, IPixel<TColor>
public static Image<TPixel> DrawText<TPixel>(this Image<TPixel> source, string text, Font font, IBrush<TPixel> brush, Vector2 location)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, brush, location, TextGraphicsOptions.Default);
}
@ -78,7 +78,7 @@ namespace ImageSharp
/// <summary>
/// Draws the text onto the the image filled via the brush.
/// </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="text">The text.</param>
/// <param name="font">The font.</param>
@ -86,10 +86,10 @@ namespace ImageSharp
/// <param name="location">The location.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The <see cref="Image{TColor}" />.
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static Image<TColor> DrawText<TColor>(this Image<TColor> source, string text, Font font, IBrush<TColor> brush, Vector2 location, TextGraphicsOptions options)
where TColor : struct, IPixel<TColor>
public static Image<TPixel> DrawText<TPixel>(this Image<TPixel> source, string text, Font font, IBrush<TPixel> brush, Vector2 location, TextGraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, brush, null, location, options);
}
@ -97,17 +97,17 @@ namespace ImageSharp
/// <summary>
/// Draws the text onto the the image outlined via the pen.
/// </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="text">The text.</param>
/// <param name="font">The font.</param>
/// <param name="pen">The pen.</param>
/// <param name="location">The location.</param>
/// <returns>
/// The <see cref="Image{TColor}" />.
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static Image<TColor> DrawText<TColor>(this Image<TColor> source, string text, Font font, IPen<TColor> pen, Vector2 location)
where TColor : struct, IPixel<TColor>
public static Image<TPixel> DrawText<TPixel>(this Image<TPixel> source, string text, Font font, IPen<TPixel> pen, Vector2 location)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, pen, location, TextGraphicsOptions.Default);
}
@ -115,7 +115,7 @@ namespace ImageSharp
/// <summary>
/// Draws the text onto the the image outlined via the pen.
/// </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="text">The text.</param>
/// <param name="font">The font.</param>
@ -123,10 +123,10 @@ namespace ImageSharp
/// <param name="location">The location.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The <see cref="Image{TColor}" />.
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static Image<TColor> DrawText<TColor>(this Image<TColor> source, string text, Font font, IPen<TColor> pen, Vector2 location, TextGraphicsOptions options)
where TColor : struct, IPixel<TColor>
public static Image<TPixel> DrawText<TPixel>(this Image<TPixel> source, string text, Font font, IPen<TPixel> pen, Vector2 location, TextGraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, null, pen, location, options);
}
@ -134,7 +134,7 @@ namespace ImageSharp
/// <summary>
/// Draws the text onto the the image filled via the brush then outlined via the pen.
/// </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="text">The text.</param>
/// <param name="font">The font.</param>
@ -142,10 +142,10 @@ namespace ImageSharp
/// <param name="pen">The pen.</param>
/// <param name="location">The location.</param>
/// <returns>
/// The <see cref="Image{TColor}" />.
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static Image<TColor> DrawText<TColor>(this Image<TColor> source, string text, Font font, IBrush<TColor> brush, IPen<TColor> pen, Vector2 location)
where TColor : struct, IPixel<TColor>
public static Image<TPixel> DrawText<TPixel>(this Image<TPixel> source, string text, Font font, IBrush<TPixel> brush, IPen<TPixel> pen, Vector2 location)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, brush, pen, location, TextGraphicsOptions.Default);
}
@ -153,7 +153,7 @@ namespace ImageSharp
/// <summary>
/// Draws the text onto the the image filled via the brush then outlined via the pen.
/// </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="text">The text.</param>
/// <param name="font">The font.</param>
@ -162,10 +162,10 @@ namespace ImageSharp
/// <param name="location">The location.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The <see cref="Image{TColor}" />.
/// The <see cref="Image{TPixel}" />.
/// </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)
where TColor : struct, IPixel<TColor>
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 TPixel : struct, IPixel<TPixel>
{
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
/// a type-specific method for determining approximate equality of instances.
/// </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>
public interface IAlmostEquatable<in TColor, in TPrecision>
public interface IAlmostEquatable<in TPixel, in TPrecision>
where TPrecision : struct, IComparable<TPrecision>
{
/// <summary>
@ -25,6 +25,6 @@ namespace ImageSharp.Colors.Spaces
/// <returns>
/// true if the current object is equal to the other parameter; otherwise, false.
/// </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.Numerics;
using System.Runtime.CompilerServices;
using ImageSharp.PixelFormats;
/// <summary>
/// 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://entropymine.com/imageworsener/srgbformula/"/>
/// </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>
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.Runtime.CompilerServices;
using ImageSharp.PixelFormats;
/// <summary>
/// Provides common mathematical methods.
/// </summary>
@ -100,25 +102,6 @@ namespace ImageSharp
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>
/// Gets the bounding <see cref="Rectangle"/> from the given points.
/// </summary>
@ -162,22 +145,22 @@ namespace ImageSharp
/// Finds the bounding rectangle based on the first instance of any color component other
/// than the given one.
/// </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="componentValue">The color component value to remove.</param>
/// <param name="channel">The <see cref="RgbaComponent"/> channel to test against.</param>
/// <returns>
/// The <see cref="Rectangle"/>.
/// </returns>
public static Rectangle GetFilteredBoundingRectangle<TColor>(ImageBase<TColor> bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B)
where TColor : struct, IPixel<TColor>
public static Rectangle GetFilteredBoundingRectangle<TPixel>(ImageBase<TPixel> bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B)
where TPixel : struct, IPixel<TPixel>
{
int width = bitmap.Width;
int height = bitmap.Height;
Point topLeft = 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
switch (channel)
@ -199,7 +182,7 @@ namespace ImageSharp
break;
}
Func<PixelAccessor<TColor>, int> getMinY = pixels =>
Func<PixelAccessor<TPixel>, int> getMinY = pixels =>
{
for (int y = 0; y < height; y++)
{
@ -215,7 +198,7 @@ namespace ImageSharp
return 0;
};
Func<PixelAccessor<TColor>, int> getMaxY = pixels =>
Func<PixelAccessor<TPixel>, int> getMaxY = pixels =>
{
for (int y = height - 1; y > -1; y--)
{
@ -231,7 +214,7 @@ namespace ImageSharp
return height;
};
Func<PixelAccessor<TColor>, int> getMinX = pixels =>
Func<PixelAccessor<TPixel>, int> getMinX = pixels =>
{
for (int x = 0; x < width; x++)
{
@ -247,7 +230,7 @@ namespace ImageSharp
return 0;
};
Func<PixelAccessor<TColor>, int> getMaxX = pixels =>
Func<PixelAccessor<TPixel>, int> getMaxX = pixels =>
{
for (int x = width - 1; x > -1; x--)
{
@ -263,7 +246,7 @@ namespace ImageSharp
return height;
};
using (PixelAccessor<TColor> bitmapPixels = bitmap.Lock())
using (PixelAccessor<TPixel> bitmapPixels = bitmap.Lock())
{
topLeft.Y = getMinY(bitmapPixels);
topLeft.X = getMinX(bitmapPixels);
@ -273,23 +256,5 @@ namespace ImageSharp
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>
/// Rounds a single-precision floating-point value to the nearest integral value.
/// </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>
/// 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.
@ -204,7 +204,7 @@ namespace ImageSharp
/// <summary>
/// Returns the sine of the specified angle.
/// </summary>
/// <param name="f">An angle, measured in radians. </param>
/// <param name="f">An angle, measured in radians.</param>
/// <returns>
/// 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" />,
@ -216,6 +216,26 @@ namespace ImageSharp
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>
/// Returns the square root of a specified number.
/// </summary>
@ -232,5 +252,23 @@ namespace ImageSharp
{
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.Buffers;
using ImageSharp.PixelFormats;
/// <summary>
/// Provides a resource pool that enables reusing instances of value type arrays for image data <see cref="T:T[]"/>.
/// </summary>
@ -24,7 +26,7 @@ namespace ImageSharp
/// Rents the pixel array from the pool.
/// </summary>
/// <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)
{
return ArrayPool.Rent(minimumLength);

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

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

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

@ -5,7 +5,7 @@
namespace ImageSharp.Dithering
{
using System;
using ImageSharp.PixelFormats;
/// <summary>
/// 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="width">The image width.</param>
/// <param name="height">The image height.</param>
/// <typeparam name="TColor">The pixel format.</typeparam>
void Dither<TColor>(PixelAccessor<TColor> pixels, TColor source, TColor transformed, int x, int y, int width, int height)
where TColor : struct, IPixel<TColor>;
/// <typeparam name="TPixel">The pixel format.</typeparam>
void Dither<TPixel>(PixelAccessor<TPixel> pixels, TPixel source, TPixel transformed, int x, int y, int width, int height)
where TPixel : struct, IPixel<TPixel>;
/// <summary>
/// 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.
/// Generally this would be true for standard two-color dithering but when used in conjunction with color quantization this should be false.
/// </param>
/// <typeparam name="TColor">The pixel format.</typeparam>
void Dither<TColor>(PixelAccessor<TColor> pixels, TColor source, TColor transformed, int x, int y, int width, int height, bool replacePixel)
where TColor : struct, IPixel<TColor>;
/// <typeparam name="TPixel">The pixel format.</typeparam>
void Dither<TPixel>(PixelAccessor<TPixel> pixels, TPixel source, TPixel transformed, int x, int y, int width, int height, bool replacePixel)
where TPixel : struct, IPixel<TPixel>;
}
}

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

@ -5,6 +5,8 @@
namespace ImageSharp.Dithering
{
using ImageSharp.PixelFormats;
/// <summary>
/// Encapsulates properties and methods required to perfom ordered dithering on an image.
/// </summary>
@ -23,8 +25,8 @@ namespace ImageSharp.Dithering
/// <param name="y">The row index.</param>
/// <param name="width">The image width.</param>
/// <param name="height">The image height.</param>
/// <typeparam name="TColor">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)
where TColor : struct, IPixel<TColor>;
/// <typeparam name="TPixel">The pixel format.</typeparam>
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 TPixel : struct, IPixel<TPixel>;
}
}

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

@ -5,6 +5,8 @@
namespace ImageSharp.Dithering.Ordered
{
using ImageSharp.PixelFormats;
/// <summary>
/// The base class for performing ordered ditheroing using a 4x4 matrix.
/// </summary>
@ -25,8 +27,8 @@ namespace ImageSharp.Dithering.Ordered
}
/// <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)
where TColor : struct, IPixel<TColor>
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 TPixel : struct, IPixel<TPixel>
{
// 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

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

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

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

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

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

@ -8,6 +8,8 @@ namespace ImageSharp.Formats
using System;
using System.IO;
using ImageSharp.PixelFormats;
using IO;
/// <summary>
@ -35,13 +37,13 @@ namespace ImageSharp.Formats
}
/// <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>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="image">The <see cref="ImageBase{TColor}"/> to encode from.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <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>
public void Encode<TColor>(ImageBase<TColor> image, Stream stream)
where TColor : struct, IPixel<TColor>
public void Encode<TPixel>(ImageBase<TPixel> image, Stream stream)
where TPixel : struct, IPixel<TPixel>
{
Guard.NotNull(image, nameof(image));
Guard.NotNull(stream, nameof(stream));
@ -124,15 +126,15 @@ namespace ImageSharp.Formats
/// <summary>
/// Writes the pixel data to the binary stream.
/// </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="image">
/// The <see cref="ImageBase{TColor}"/> containing pixel data.
/// The <see cref="ImageBase{TPixel}"/> containing pixel data.
/// </param>
private void WriteImage<TColor>(EndianBinaryWriter writer, ImageBase<TColor> image)
where TColor : struct, IPixel<TColor>
private void WriteImage<TPixel>(EndianBinaryWriter writer, ImageBase<TPixel> image)
where TPixel : struct, IPixel<TPixel>
{
using (PixelAccessor<TColor> pixels = image.Lock())
using (PixelAccessor<TPixel> pixels = image.Lock())
{
switch (this.options.BitsPerPixel)
{
@ -150,13 +152,13 @@ namespace ImageSharp.Formats
/// <summary>
/// Writes the 32bit color palette to the stream.
/// </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="pixels">The <see cref="PixelAccessor{TColor}"/> containing pixel data.</param>
private void Write32Bit<TColor>(EndianBinaryWriter writer, PixelAccessor<TColor> pixels)
where TColor : struct, IPixel<TColor>
/// <param name="pixels">The <see cref="PixelAccessor{TPixel}"/> containing pixel data.</param>
private void Write32Bit<TPixel>(EndianBinaryWriter writer, PixelAccessor<TPixel> pixels)
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--)
{
@ -169,13 +171,13 @@ namespace ImageSharp.Formats
/// <summary>
/// Writes the 24bit color palette to the stream.
/// </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="pixels">The <see cref="PixelAccessor{TColor}"/> containing pixel data.</param>
private void Write24Bit<TColor>(EndianBinaryWriter writer, PixelAccessor<TColor> pixels)
where TColor : struct, IPixel<TColor>
/// <param name="pixels">The <see cref="PixelAccessor{TPixel}"/> containing pixel data.</param>
private void Write24Bit<TPixel>(EndianBinaryWriter writer, PixelAccessor<TPixel> pixels)
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--)
{

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

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

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

@ -8,33 +8,35 @@ namespace ImageSharp.Formats
using System;
using System.IO;
using ImageSharp.PixelFormats;
/// <summary>
/// Decoder for generating an image out of a gif encoded stream.
/// </summary>
public class GifDecoder : IImageDecoder
{
/// <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);
return this.Decode<TColor>(configuration, stream, gifOptions);
return this.Decode<TPixel>(configuration, stream, gifOptions);
}
/// <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>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="configuration">The configuration.</param>
/// <param name="stream">The <see cref="Stream"/> containing image data.</param>
/// <param name="options">The options for the decoder.</param>
/// <returns>The image thats been decoded.</returns>
public Image<TColor> Decode<TColor>(Configuration configuration, Stream stream, IGifDecoderOptions options)
where TColor : struct, IPixel<TColor>
public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream, IGifDecoderOptions options)
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.Text;
using ImageSharp.PixelFormats;
/// <summary>
/// Performs the gif decoding operation.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
internal class GifDecoderCore<TColor>
where TColor : struct, IPixel<TColor>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class GifDecoderCore<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// The temp buffer used to reduce allocations.
@ -50,7 +52,7 @@ namespace ImageSharp.Formats
/// <summary>
/// The previous frame.
/// </summary>
private ImageFrame<TColor> previousFrame;
private ImageFrame<TPixel> previousFrame;
/// <summary>
/// The area to restore.
@ -75,10 +77,10 @@ namespace ImageSharp.Formats
/// <summary>
/// The image to decode the information to.
/// </summary>
private Image<TColor> image;
private Image<TPixel> image;
/// <summary>
/// Initializes a new instance of the <see cref="GifDecoderCore{TColor}"/> class.
/// Initializes a new instance of the <see cref="GifDecoderCore{TPixel}"/> class.
/// </summary>
/// <param name="options">The decoder options.</param>
/// <param name="configuration">The configuration.</param>
@ -93,7 +95,7 @@ namespace ImageSharp.Formats
/// </summary>
/// <param name="stream">The stream containing image data. </param>
/// <returns>The decoded image</returns>
public Image<TColor> Decode(Stream stream)
public Image<TPixel> Decode(Stream stream)
{
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.
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(
$"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 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)
{
this.metaData.Quality = colorTableLength / 3;
// 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);
@ -392,7 +394,7 @@ namespace ImageSharp.Formats
int interlaceIncrement = 8; // The interlacing line increment
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++)
{
@ -441,7 +443,7 @@ namespace ImageSharp.Formats
{
int indexOffset = index * 3;
TColor pixel = default(TColor);
TPixel pixel = default(TPixel);
pixel.PackFromBytes(colorTable[indexOffset], colorTable[indexOffset + 1], colorTable[indexOffset + 2], 255);
pixelAccessor[x, writeY] = pixel;
}
@ -470,7 +472,7 @@ namespace ImageSharp.Formats
/// Restores the current frame area to the background.
/// </summary>
/// <param name="frame">The frame.</param>
private void RestoreToBackground(ImageBase<TColor> frame)
private void RestoreToBackground(ImageBase<TPixel> frame)
{
if (this.restoreArea == null)
{
@ -481,16 +483,16 @@ namespace ImageSharp.Formats
if (this.restoreArea.Value.Width == this.image.Width &&
this.restoreArea.Value.Height == this.image.Height)
{
using (PixelAccessor<TColor> pixelAccessor = frame.Lock())
using (PixelAccessor<TPixel> pixelAccessor = frame.Lock())
{
pixelAccessor.Reset();
}
}
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++)
{

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

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

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

@ -10,6 +10,8 @@ namespace ImageSharp.Formats
using System.IO;
using System.Linq;
using ImageSharp.PixelFormats;
using IO;
using Quantizers;
@ -48,18 +50,18 @@ namespace ImageSharp.Formats
public IQuantizer Quantizer { get; set; }
/// <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>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="image">The <see cref="Image{TColor}"/> to encode from.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <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>
public void Encode<TColor>(Image<TColor> image, Stream stream)
where TColor : struct, IPixel<TColor>
public void Encode<TPixel>(Image<TPixel> image, Stream stream)
where TPixel : struct, IPixel<TPixel>
{
Guard.NotNull(image, nameof(image));
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.
EndianBinaryWriter writer = new EndianBinaryWriter(Endianness.LittleEndian, stream);
@ -72,7 +74,7 @@ namespace ImageSharp.Formats
this.bitDepth = ImageMaths.GetBitsNeededForColorDepth(quality);
// 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);
@ -97,8 +99,8 @@ namespace ImageSharp.Formats
// ReSharper disable once ForCanBeConvertedToForeach
for (int i = 0; i < image.Frames.Count; i++)
{
ImageFrame<TColor> frame = image.Frames[i];
QuantizedImage<TColor> quantizedFrame = ((IQuantizer<TColor>)this.Quantizer).Quantize(frame, quality);
ImageFrame<TPixel> frame = image.Frames[i];
QuantizedImage<TPixel> quantizedFrame = ((IQuantizer<TPixel>)this.Quantizer).Quantize(frame, quality);
this.WriteGraphicalControlExtension(frame, writer, this.GetTransparentIndex(quantizedFrame));
this.WriteImageDescriptor(frame, writer);
@ -117,12 +119,12 @@ namespace ImageSharp.Formats
/// <param name="quantized">
/// The quantized.
/// </param>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>
/// The <see cref="int"/>.
/// </returns>
private int GetTransparentIndex<TColor>(QuantizedImage<TColor> quantized)
where TColor : struct, IPixel<TColor>
private int GetTransparentIndex<TPixel>(QuantizedImage<TPixel> quantized)
where TPixel : struct, IPixel<TPixel>
{
// Find the lowest alpha value and make it the transparent index.
int index = 255;
@ -167,12 +169,12 @@ namespace ImageSharp.Formats
/// <summary>
/// Writes the logical screen descriptor to the stream.
/// </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="writer">The writer to write to the stream with.</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)
where TColor : struct, IPixel<TColor>
private void WriteLogicalScreenDescriptor<TPixel>(Image<TPixel> image, EndianBinaryWriter writer, int tranparencyIndex)
where TPixel : struct, IPixel<TPixel>
{
GifLogicalScreenDescriptor descriptor = new GifLogicalScreenDescriptor
{
@ -233,11 +235,11 @@ namespace ImageSharp.Formats
/// <summary>
/// Writes the image comments to the stream.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="image">The <see cref="ImageBase{TColor}"/> to be encoded.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="ImageBase{TPixel}"/> to be encoded.</param>
/// <param name="writer">The stream to write to.</param>
private void WriteComments<TColor>(Image<TColor> image, EndianBinaryWriter writer)
where TColor : struct, IPixel<TColor>
private void WriteComments<TPixel>(Image<TPixel> image, EndianBinaryWriter writer)
where TPixel : struct, IPixel<TPixel>
{
if (this.options.IgnoreMetadata == true)
{
@ -266,12 +268,12 @@ namespace ImageSharp.Formats
/// <summary>
/// Writes the graphics control extension to the stream.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="image">The <see cref="Image{TColor}"/> to encode.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="Image{TPixel}"/> to encode.</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>
private void WriteGraphicalControlExtension<TColor>(Image<TColor> image, EndianBinaryWriter writer, int transparencyIndex)
where TColor : struct, IPixel<TColor>
private void WriteGraphicalControlExtension<TPixel>(Image<TPixel> image, EndianBinaryWriter writer, int transparencyIndex)
where TPixel : struct, IPixel<TPixel>
{
this.WriteGraphicalControlExtension(image, image.MetaData, writer, transparencyIndex);
}
@ -279,12 +281,12 @@ namespace ImageSharp.Formats
/// <summary>
/// Writes the graphics control extension to the stream.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="imageFrame">The <see cref="ImageFrame{TColor}"/> to encode.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="imageFrame">The <see cref="ImageFrame{TPixel}"/> to encode.</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>
private void WriteGraphicalControlExtension<TColor>(ImageFrame<TColor> imageFrame, EndianBinaryWriter writer, int transparencyIndex)
where TColor : struct, IPixel<TColor>
private void WriteGraphicalControlExtension<TPixel>(ImageFrame<TPixel> imageFrame, EndianBinaryWriter writer, int transparencyIndex)
where TPixel : struct, IPixel<TPixel>
{
this.WriteGraphicalControlExtension(imageFrame, imageFrame.MetaData, writer, transparencyIndex);
}
@ -292,13 +294,13 @@ namespace ImageSharp.Formats
/// <summary>
/// Writes the graphics control extension to the stream.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="image">The <see cref="ImageBase{TColor}"/> to encode.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="ImageBase{TPixel}"/> to encode.</param>
/// <param name="metaData">The metadata of the image or frame.</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>
private void WriteGraphicalControlExtension<TColor>(ImageBase<TColor> image, IMetaData metaData, EndianBinaryWriter writer, int transparencyIndex)
where TColor : struct, IPixel<TColor>
private void WriteGraphicalControlExtension<TPixel>(ImageBase<TPixel> image, IMetaData metaData, EndianBinaryWriter writer, int transparencyIndex)
where TPixel : struct, IPixel<TPixel>
{
// TODO: Check transparency logic.
bool hasTransparent = transparencyIndex < 255;
@ -336,11 +338,11 @@ namespace ImageSharp.Formats
/// <summary>
/// Writes the image descriptor to the stream.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="image">The <see cref="ImageBase{TColor}"/> to be encoded.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="ImageBase{TPixel}"/> to be encoded.</param>
/// <param name="writer">The stream to write to.</param>
private void WriteImageDescriptor<TColor>(ImageBase<TColor> image, EndianBinaryWriter writer)
where TColor : struct, IPixel<TColor>
private void WriteImageDescriptor<TPixel>(ImageBase<TPixel> image, EndianBinaryWriter writer)
where TPixel : struct, IPixel<TPixel>
{
writer.Write(GifConstants.ImageDescriptorLabel); // 2c
@ -362,11 +364,11 @@ namespace ImageSharp.Formats
/// <summary>
/// Writes the color table to the stream.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="image">The <see cref="ImageBase{TColor}"/> to encode.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="ImageBase{TPixel}"/> to encode.</param>
/// <param name="writer">The writer to write to the stream with.</param>
private void WriteColorTable<TColor>(QuantizedImage<TColor> image, EndianBinaryWriter writer)
where TColor : struct, IPixel<TColor>
private void WriteColorTable<TPixel>(QuantizedImage<TPixel> image, EndianBinaryWriter writer)
where TPixel : struct, IPixel<TPixel>
{
// Grab the palette and write it to the stream.
int pixelCount = image.Palette.Length;
@ -397,11 +399,11 @@ namespace ImageSharp.Formats
/// <summary>
/// Writes the image pixel data to the stream.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="image">The <see cref="QuantizedImage{TColor}"/> containing indexed pixels.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="QuantizedImage{TPixel}"/> containing indexed pixels.</param>
/// <param name="writer">The stream to write to.</param>
private void WriteImageData<TColor>(QuantizedImage<TColor> image, EndianBinaryWriter writer)
where TColor : struct, IPixel<TColor>
private void WriteImageData<TPixel>(QuantizedImage<TPixel> image, EndianBinaryWriter writer)
where TPixel : struct, IPixel<TPixel>
{
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 ImageSharp.PixelFormats;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Saves the image to the given stream with the gif format.
/// </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="stream">The stream to save the image to.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns>
/// The <see cref="Image{TColor}"/>.
/// The <see cref="Image{TPixel}"/>.
/// </returns>
public static Image<TColor> SaveAsGif<TColor>(this Image<TColor> source, Stream stream)
where TColor : struct, IPixel<TColor>
public static Image<TPixel> SaveAsGif<TPixel>(this Image<TPixel> source, Stream stream)
where TPixel : struct, IPixel<TPixel>
{
return SaveAsGif(source, stream, null);
}
@ -34,16 +36,16 @@ namespace ImageSharp
/// <summary>
/// Saves the image to the given stream with the gif format.
/// </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="stream">The stream to save the image to.</param>
/// <param name="options">The options for the encoder.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns>
/// The <see cref="Image{TColor}"/>.
/// The <see cref="Image{TPixel}"/>.
/// </returns>
public static Image<TColor> SaveAsGif<TColor>(this Image<TColor> source, Stream stream, IGifEncoderOptions options)
where TColor : struct, IPixel<TColor>
public static Image<TPixel> SaveAsGif<TPixel>(this Image<TPixel> source, Stream stream, IGifEncoderOptions options)
where TPixel : struct, IPixel<TPixel>
{
GifEncoder encoder = new GifEncoder();
encoder.Encode(source, stream, options);

10
src/ImageSharp/Formats/IImageDecoder.cs

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

12
src/ImageSharp/Formats/IImageEncoder.cs

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

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

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

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

@ -8,20 +8,22 @@ namespace ImageSharp.Formats
using System;
using System.IO;
using ImageSharp.PixelFormats;
/// <summary>
/// Image decoder for generating an image out of a jpg stream.
/// </summary>
public class JpegDecoder : IImageDecoder
{
/// <inheritdoc/>
public Image<TColor> Decode<TColor>(Configuration configuration, Stream stream, IDecoderOptions options)
where TColor : struct, IPixel<TColor>
public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream, IDecoderOptions options)
where TPixel : struct, IPixel<TPixel>
{
Guard.NotNull(stream, "stream");
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 ImageSharp.Formats.Jpg;
using ImageSharp.PixelFormats;
/// <summary>
/// Performs the jpeg decoding operation.
@ -121,7 +122,7 @@ namespace ImageSharp.Formats
/// <summary>
/// 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.
/// 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.
/// </summary>
public DecodedBlockArray[] DecodedBlocks { get; }
@ -186,16 +187,16 @@ namespace ImageSharp.Formats
/// Decodes the image from the specified <see cref="Stream"/> and sets
/// the data to image.
/// </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>
/// <returns>The decoded image.</returns>
public Image<TColor> Decode<TColor>(Stream stream)
where TColor : struct, IPixel<TColor>
public Image<TPixel> Decode<TPixel>(Stream stream)
where TPixel : struct, IPixel<TPixel>
{
ImageMetaData metadata = new ImageMetaData();
this.ProcessStream(metadata, stream, false);
this.ProcessBlocksIntoJpegImageChannels<TColor>();
Image<TColor> image = this.ConvertJpegPixelsToImagePixels<TColor>(metadata);
this.ProcessBlocksIntoJpegImageChannels<TPixel>();
Image<TPixel> image = this.ConvertJpegPixelsToImagePixels<TPixel>(metadata);
return image;
}
@ -254,14 +255,14 @@ namespace ImageSharp.Formats
/// Optimized method to pack bytes to the image from the YCbCr color space.
/// This is faster than implicit casting as it avoids double packing.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="packed">The packed pixel.</param>
/// <param name="y">The y luminance component.</param>
/// <param name="cb">The cb chroma component.</param>
/// <param name="cr">The cr chroma component.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void PackYcbCr<TColor>(ref TColor packed, byte y, byte cb, byte cr)
where TColor : struct, IPixel<TColor>
private static void PackYcbCr<TPixel>(ref TPixel packed, byte y, byte cb, byte cr)
where TPixel : struct, IPixel<TPixel>
{
int ccb = cb - 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.
/// We can copy these blocks into <see cref="JpegPixelArea"/>-s afterwards.
/// </summary>
/// <typeparam name="TColor">The pixel type</typeparam>
private void ProcessBlocksIntoJpegImageChannels<TColor>()
where TColor : struct, IPixel<TColor>
/// <typeparam name="TPixel">The pixel type</typeparam>
private void ProcessBlocksIntoJpegImageChannels<TPixel>()
where TPixel : struct, IPixel<TPixel>
{
Parallel.For(
0,
@ -497,15 +498,15 @@ namespace ImageSharp.Formats
}
/// <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>
/// <typeparam name="TColor">The pixel type</typeparam>
/// <typeparam name="TPixel">The pixel type</typeparam>
/// <param name="metadata">The metadata for the image.</param>
/// <returns>The decoded image.</returns>
private Image<TColor> ConvertJpegPixelsToImagePixels<TColor>(ImageMetaData metadata)
where TColor : struct, IPixel<TColor>
private Image<TPixel> ConvertJpegPixelsToImagePixels<TPixel>(ImageMetaData metadata)
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)
{
@ -561,10 +562,10 @@ namespace ImageSharp.Formats
/// <summary>
/// Assigns the horizontal and vertical resolution to the image if it has a JFIF header.
/// </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>
private void AssignResolution<TColor>(Image<TColor> image)
where TColor : struct, IPixel<TColor>
private void AssignResolution<TPixel>(Image<TPixel> image)
where TPixel : struct, IPixel<TPixel>
{
if (this.isJfif && this.horizontalResolution > 0 && this.verticalResolution > 0)
{
@ -589,14 +590,14 @@ namespace ImageSharp.Formats
/// <summary>
/// Converts the image from the original CMYK image pixels.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The image.</param>
private void ConvertFromCmyk<TColor>(Image<TColor> image)
where TColor : struct, IPixel<TColor>
private void ConvertFromCmyk<TPixel>(Image<TPixel> image)
where TPixel : struct, IPixel<TPixel>
{
int scale = this.ComponentArray[0].HorizontalFactor / this.ComponentArray[1].HorizontalFactor;
using (PixelAccessor<TColor> pixels = image.Lock())
using (PixelAccessor<TPixel> pixels = image.Lock())
{
Parallel.For(
0,
@ -613,7 +614,7 @@ namespace ImageSharp.Formats
byte magenta = this.ycbcrImage.CbChannel.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);
pixels[x, y] = packed;
}
@ -626,12 +627,12 @@ namespace ImageSharp.Formats
/// <summary>
/// Converts the image from the original grayscale image pixels.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The image.</param>
private void ConvertFromGrayScale<TColor>(Image<TColor> image)
where TColor : struct, IPixel<TColor>
private void ConvertFromGrayScale<TPixel>(Image<TPixel> image)
where TPixel : struct, IPixel<TPixel>
{
using (PixelAccessor<TColor> pixels = image.Lock())
using (PixelAccessor<TPixel> pixels = image.Lock())
{
Parallel.For(
0,
@ -644,7 +645,7 @@ namespace ImageSharp.Formats
{
byte rgb = this.grayImage.Pixels[yoff + x];
TColor packed = default(TColor);
TPixel packed = default(TPixel);
packed.PackFromBytes(rgb, rgb, rgb, 255);
pixels[x, y] = packed;
}
@ -657,14 +658,14 @@ namespace ImageSharp.Formats
/// <summary>
/// Converts the image from the original RBG image pixels.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The image.</param>
private void ConvertFromRGB<TColor>(Image<TColor> image)
where TColor : struct, IPixel<TColor>
private void ConvertFromRGB<TPixel>(Image<TPixel> image)
where TPixel : struct, IPixel<TPixel>
{
int scale = this.ComponentArray[0].HorizontalFactor / this.ComponentArray[1].HorizontalFactor;
using (PixelAccessor<TColor> pixels = image.Lock())
using (PixelAccessor<TPixel> pixels = image.Lock())
{
Parallel.For(
0,
@ -682,7 +683,7 @@ namespace ImageSharp.Formats
byte green = this.ycbcrImage.CbChannel.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);
pixels[x, y] = packed;
}
@ -695,13 +696,13 @@ namespace ImageSharp.Formats
/// <summary>
/// Converts the image from the original YCbCr image pixels.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The image.</param>
private void ConvertFromYCbCr<TColor>(Image<TColor> image)
where TColor : struct, IPixel<TColor>
private void ConvertFromYCbCr<TPixel>(Image<TPixel> image)
where TPixel : struct, IPixel<TPixel>
{
int scale = this.ComponentArray[0].HorizontalFactor / this.ComponentArray[1].HorizontalFactor;
using (PixelAccessor<TColor> pixels = image.Lock())
using (PixelAccessor<TPixel> pixels = image.Lock())
{
Parallel.For(
0,
@ -719,8 +720,8 @@ namespace ImageSharp.Formats
byte cb = this.ycbcrImage.CbChannel.Pixels[co + (x / scale)];
byte cr = this.ycbcrImage.CrChannel.Pixels[co + (x / scale)];
TColor packed = default(TColor);
PackYcbCr<TColor>(ref packed, yy, cb, cr);
TPixel packed = default(TPixel);
PackYcbCr<TPixel>(ref packed, yy, cb, cr);
pixels[x, y] = packed;
}
});
@ -732,14 +733,14 @@ namespace ImageSharp.Formats
/// <summary>
/// Converts the image from the original YCCK image pixels.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The image.</param>
private void ConvertFromYcck<TColor>(Image<TColor> image)
where TColor : struct, IPixel<TColor>
private void ConvertFromYcck<TPixel>(Image<TPixel> image)
where TPixel : struct, IPixel<TPixel>
{
int scale = this.ComponentArray[0].HorizontalFactor / this.ComponentArray[1].HorizontalFactor;
using (PixelAccessor<TColor> pixels = image.Lock())
using (PixelAccessor<TPixel> pixels = image.Lock())
{
Parallel.For(
0,
@ -756,7 +757,7 @@ namespace ImageSharp.Formats
byte cb = this.ycbcrImage.CbChannel.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);
pixels[x, y] = packed;
}
@ -850,15 +851,15 @@ namespace ImageSharp.Formats
/// Optimized method to pack bytes to the image from the CMYK color space.
/// This is faster than implicit casting as it avoids double packing.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="packed">The packed pixel.</param>
/// <param name="c">The cyan component.</param>
/// <param name="m">The magenta component.</param>
/// <param name="y">The yellow component.</param>
/// <param name="xx">The x-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)
where TColor : struct, IPixel<TColor>
private void PackCmyk<TPixel>(ref TPixel packed, byte c, byte m, byte y, int xx, int yy)
where TPixel : struct, IPixel<TPixel>
{
// Get keyline
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.
/// This is faster than implicit casting as it avoids double packing.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="packed">The packed pixel.</param>
/// <param name="y">The y luminance component.</param>
/// <param name="cb">The cb chroma component.</param>
/// <param name="cr">The cr chroma component.</param>
/// <param name="xx">The x-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)
where TColor : struct, IPixel<TColor>
private void PackYcck<TPixel>(ref TPixel packed, byte y, byte cb, byte cr, int xx, int yy)
where TPixel : struct, IPixel<TPixel>
{
// 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

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

@ -7,14 +7,16 @@ namespace ImageSharp.Formats
{
using System.IO;
using ImageSharp.PixelFormats;
/// <summary>
/// Encoder for writing the data image to a stream in jpeg format.
/// </summary>
public class JpegEncoder : IImageEncoder
{
/// <inheritdoc/>
public void Encode<TColor>(Image<TColor> image, Stream stream, IEncoderOptions options)
where TColor : struct, IPixel<TColor>
public void Encode<TPixel>(Image<TPixel> image, Stream stream, IEncoderOptions options)
where TPixel : struct, IPixel<TPixel>
{
IJpegEncoderOptions gifOptions = JpegEncoderOptions.Create(options);
@ -22,14 +24,14 @@ namespace ImageSharp.Formats
}
/// <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>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="image">The <see cref="Image{TColor}"/> to encode from.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <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="options">The options for the encoder.</param>
public void Encode<TColor>(Image<TColor> image, Stream stream, IJpegEncoderOptions options)
where TColor : struct, IPixel<TColor>
public void Encode<TPixel>(Image<TPixel> image, Stream stream, IJpegEncoderOptions options)
where TPixel : struct, IPixel<TPixel>
{
JpegEncoderCore encode = new JpegEncoderCore(options);
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.Components;
using ImageSharp.PixelFormats;
/// <summary>
/// Image encoder for writing an image to a stream as a jpeg.
@ -165,11 +166,11 @@ namespace ImageSharp.Formats
/// <summary>
/// Encode writes the image to the jpeg baseline format with the given options.
/// </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="stream">The stream to write to.</param>
public void Encode<TColor>(Image<TColor> image, Stream stream)
where TColor : struct, IPixel<TColor>
public void Encode<TPixel>(Image<TPixel> image, Stream stream)
where TPixel : struct, IPixel<TPixel>
{
Guard.NotNull(image, nameof(image));
Guard.NotNull(stream, nameof(stream));
@ -225,7 +226,7 @@ namespace ImageSharp.Formats
this.WriteDefineHuffmanTables(componentCount);
// Write the image data.
using (PixelAccessor<TColor> pixels = image.Lock())
using (PixelAccessor<TPixel> pixels = image.Lock())
{
this.WriteStartOfScan(pixels);
}
@ -282,23 +283,23 @@ namespace ImageSharp.Formats
/// <summary>
/// Converts the 8x8 region of the image whose top-left corner is x,y to its YCbCr values.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="pixels">The pixel accessor.</param>
/// <param name="x">The x-position within the image.</param>
/// <param name="y">The y-position within the image.</param>
/// <param name="yBlock">The luminance block.</param>
/// <param name="cbBlock">The red chroma block.</param>
/// <param name="crBlock">The blue chroma block.</param>
/// <param name="rgbBytes">Temporal <see cref="PixelArea{TColor}"/> provided by the caller</param>
private static void ToYCbCr<TColor>(
PixelAccessor<TColor> pixels,
/// <param name="rgbBytes">Temporal <see cref="PixelArea{TPixel}"/> provided by the caller</param>
private static void ToYCbCr<TPixel>(
PixelAccessor<TPixel> pixels,
int x,
int y,
Block8x8F* yBlock,
Block8x8F* cbBlock,
Block8x8F* crBlock,
PixelArea<TColor> rgbBytes)
where TColor : struct, IPixel<TColor>
PixelArea<TPixel> rgbBytes)
where TPixel : struct, IPixel<TPixel>
{
float* yBlockRaw = (float*)yBlock;
float* cbBlockRaw = (float*)cbBlock;
@ -442,12 +443,12 @@ namespace ImageSharp.Formats
/// <summary>
/// Encodes the image with no subsampling.
/// </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>
private void Encode444<TColor>(PixelAccessor<TColor> pixels)
where TColor : struct, IPixel<TColor>
private void Encode444<TPixel>(PixelAccessor<TPixel> pixels)
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 cb = default(Block8x8F);
Block8x8F cr = default(Block8x8F);
@ -463,7 +464,7 @@ namespace ImageSharp.Formats
// ReSharper disable once InconsistentNaming
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)
{
@ -714,9 +715,9 @@ namespace ImageSharp.Formats
/// Writes the metadata profiles to the image.
/// </summary>
/// <param name="image">The image.</param>
/// <typeparam name="TColor">The pixel format.</typeparam>
private void WriteProfiles<TColor>(Image<TColor> image)
where TColor : struct, IPixel<TColor>
/// <typeparam name="TPixel">The pixel format.</typeparam>
private void WriteProfiles<TPixel>(Image<TPixel> image)
where TPixel : struct, IPixel<TPixel>
{
if (this.options.IgnoreMetadata)
{
@ -786,12 +787,12 @@ namespace ImageSharp.Formats
/// <summary>
/// Writes the StartOfScan marker.
/// </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>
private void WriteStartOfScan<TColor>(PixelAccessor<TColor> pixels)
where TColor : struct, IPixel<TColor>
private void WriteStartOfScan<TPixel>(PixelAccessor<TPixel> pixels)
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.
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
/// at a factor of 2 both horizontally and vertically.
/// </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>
private void Encode420<TColor>(PixelAccessor<TColor> pixels)
where TColor : struct, IPixel<TColor>
private void Encode420<TPixel>(PixelAccessor<TPixel> pixels)
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);
BlockQuad cb = default(BlockQuad);
@ -837,7 +838,7 @@ namespace ImageSharp.Formats
// ReSharper disable once InconsistentNaming
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)
{

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

@ -8,6 +8,8 @@ namespace ImageSharp.Formats.Jpg
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ImageSharp.PixelFormats;
/// <summary>
/// Jpeg specific utilities and extension methods
/// </summary>
@ -16,17 +18,17 @@ namespace ImageSharp.Formats.Jpg
/// <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.
/// </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="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="sourceX">Starting X coord</param>
public static void CopyRGBBytesStretchedTo<TColor>(
this PixelAccessor<TColor> pixels,
PixelArea<TColor> dest,
public static void CopyRGBBytesStretchedTo<TPixel>(
this PixelAccessor<TPixel> pixels,
PixelArea<TPixel> dest,
int sourceY,
int sourceX)
where TColor : struct, IPixel<TColor>
where TPixel : struct, IPixel<TPixel>
{
pixels.SafeCopyTo(dest, sourceY, 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)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool IsInvalidStretchStartingPosition<TColor>(PixelArea<TColor> area, int fromX, int fromY)
where TColor : struct, IPixel<TColor>
private static bool IsInvalidStretchStartingPosition<TPixel>(PixelArea<TPixel> area, int fromX, int fromY)
where TPixel : struct, IPixel<TPixel>
{
return fromX <= 0 || fromY <= 0 || fromX >= area.Width || fromY >= area.Height;
}
private static void StretchPixels<TColor>(PixelArea<TColor> area, int fromX, int fromY)
where TColor : struct, IPixel<TColor>
private static void StretchPixels<TPixel>(PixelArea<TPixel> area, int fromX, int fromY)
where TPixel : struct, IPixel<TPixel>
{
if (IsInvalidStretchStartingPosition(area, fromX, fromY))
{
@ -75,8 +77,8 @@ namespace ImageSharp.Formats.Jpg
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static ref RGB24 GetRowStart<TColor>(PixelArea<TColor> area, int y)
where TColor : struct, IPixel<TColor>
private static ref RGB24 GetRowStart<TPixel>(PixelArea<TPixel> area, int y)
where TPixel : struct, IPixel<TPixel>
{
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 ImageSharp.PixelFormats;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Saves the image to the given stream with the png format.
/// </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="stream">The stream to save the image to.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns>
/// The <see cref="Image{TColor}"/>.
/// The <see cref="Image{TPixel}"/>.
/// </returns>
public static Image<TColor> SaveAsPng<TColor>(this Image<TColor> source, Stream stream)
where TColor : struct, IPixel<TColor>
public static Image<TPixel> SaveAsPng<TPixel>(this Image<TPixel> source, Stream stream)
where TPixel : struct, IPixel<TPixel>
{
return SaveAsPng(source, stream, null);
}
@ -33,16 +35,16 @@ namespace ImageSharp
/// <summary>
/// Saves the image to the given stream with the png format.
/// </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="stream">The stream to save the image to.</param>
/// <param name="options">The options for the encoder.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns>
/// The <see cref="Image{TColor}"/>.
/// The <see cref="Image{TPixel}"/>.
/// </returns>
public static Image<TColor> SaveAsPng<TColor>(this Image<TColor> source, Stream stream, IPngEncoderOptions options)
where TColor : struct, IPixel<TColor>
public static Image<TPixel> SaveAsPng<TPixel>(this Image<TPixel> source, Stream stream, IPngEncoderOptions options)
where TPixel : struct, IPixel<TPixel>
{
PngEncoder encoder = new PngEncoder();
encoder.Encode(source, stream, options);

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

@ -8,6 +8,8 @@ namespace ImageSharp.Formats
using System;
using System.IO;
using ImageSharp.PixelFormats;
/// <summary>
/// Encoder for generating an image out of a png encoded stream.
/// </summary>
@ -31,27 +33,27 @@ namespace ImageSharp.Formats
public class PngDecoder : IImageDecoder
{
/// <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);
return this.Decode<TColor>(configuration, stream, pngOptions);
return this.Decode<TPixel>(configuration, stream, pngOptions);
}
/// <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>
/// <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="stream">The <see cref="Stream"/> containing image data.</param>
/// <param name="options">The options for the decoder.</param>
/// <returns>The decoded image.</returns>
public Image<TColor> Decode<TColor>(Configuration configuration, Stream stream, IPngDecoderOptions options)
where TColor : struct, IPixel<TColor>
public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream, IPngDecoderOptions options)
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.Runtime.CompilerServices;
using ImageSharp.PixelFormats;
using static ComparableExtensions;
/// <summary>
@ -154,7 +156,7 @@ namespace ImageSharp.Formats
/// <summary>
/// Decodes the stream to the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="stream">The stream containing image data. </param>
/// <exception cref="ImageFormatException">
/// 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.
/// </exception>
/// <returns>The decoded image</returns>
public Image<TColor> Decode<TColor>(Stream stream)
where TColor : struct, IPixel<TColor>
public Image<TPixel> Decode<TPixel>(Stream stream)
where TPixel : struct, IPixel<TPixel>
{
ImageMetaData metadata = new ImageMetaData();
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);
}
@ -340,11 +342,11 @@ namespace ImageSharp.Formats
/// <summary>
/// Reads the scanlines within the image.
/// </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="pixels"> The pixel data.</param>
private void ReadScanlines<TColor>(MemoryStream dataStream, PixelAccessor<TColor> pixels)
where TColor : struct, IPixel<TColor>
private void ReadScanlines<TPixel>(MemoryStream dataStream, PixelAccessor<TPixel> pixels)
where TPixel : struct, IPixel<TPixel>
{
this.bytesPerPixel = this.CalculateBytesPerPixel();
this.bytesPerScanline = this.CalculateScanlineLength(this.header.Width) + 1;
@ -371,11 +373,11 @@ namespace ImageSharp.Formats
/// <summary>
/// Decodes the raw pixel data row by row
/// </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="pixels">The image pixel accessor.</param>
private void DecodePixelData<TColor>(Stream compressedStream, PixelAccessor<TColor> pixels)
where TColor : struct, IPixel<TColor>
private void DecodePixelData<TPixel>(Stream compressedStream, PixelAccessor<TPixel> pixels)
where TPixel : struct, IPixel<TPixel>
{
byte[] previousScanline = 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
/// <see href="https://github.com/juehv/DentalImageViewer/blob/8a1a4424b15d6cc453b5de3f273daf3ff5e3a90d/DentalImageViewer/lib/jiu-0.14.3/net/sourceforge/jiu/codecs/PNGCodec.java"/>
/// </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="pixels">The image pixel accessor.</param>
private void DecodeInterlacedPixelData<TColor>(Stream compressedStream, PixelAccessor<TColor> pixels)
where TColor : struct, IPixel<TColor>
private void DecodeInterlacedPixelData<TPixel>(Stream compressedStream, PixelAccessor<TPixel> pixels)
where TPixel : struct, IPixel<TPixel>
{
byte[] previousScanline = ArrayPool<byte>.Shared.Rent(this.bytesPerScanline);
byte[] scanline = ArrayPool<byte>.Shared.Rent(this.bytesPerScanline);
@ -532,14 +534,14 @@ namespace ImageSharp.Formats
/// <summary>
/// Processes the de-filtered scanline filling the image pixel data
/// </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="row">The current image row.</param>
/// <param name="pixels">The image pixels</param>
private void ProcessDefilteredScanline<TColor>(byte[] defilteredScanline, int row, PixelAccessor<TColor> pixels)
where TColor : struct, IPixel<TColor>
private void ProcessDefilteredScanline<TPixel>(byte[] defilteredScanline, int row, PixelAccessor<TPixel> pixels)
where TPixel : struct, IPixel<TPixel>
{
TColor color = default(TColor);
TPixel color = default(TPixel);
switch (this.PngColorType)
{
case PngColorType.Grayscale:
@ -655,16 +657,16 @@ namespace ImageSharp.Formats
/// <summary>
/// Processes the interlaced de-filtered scanline filling the image pixel data
/// </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="row">The current image row.</param>
/// <param name="pixels">The image pixels</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>
private void ProcessInterlacedDefilteredScanline<TColor>(byte[] defilteredScanline, int row, PixelAccessor<TColor> pixels, int pixelOffset = 0, int increment = 1)
where TColor : struct, IPixel<TColor>
private void ProcessInterlacedDefilteredScanline<TPixel>(byte[] defilteredScanline, int row, PixelAccessor<TPixel> pixels, int pixelOffset = 0, int increment = 1)
where TPixel : struct, IPixel<TPixel>
{
TColor color = default(TColor);
TPixel color = default(TPixel);
switch (this.PngColorType)
{

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

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

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

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

36
src/ImageSharp/Image.Create.cs

@ -5,11 +5,7 @@
namespace ImageSharp
{
using System;
using System.Diagnostics;
using System.IO;
using Formats;
using ImageSharp.PixelFormats;
/// <summary>
/// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha
@ -18,10 +14,10 @@ namespace ImageSharp
public sealed partial class Image
{
/// <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.
/// </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="height">The height of the image in pixels.</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.
/// </param>
/// <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>
internal static Image<TColor> Create<TColor>(int width, int height, ImageMetaData metadata, Configuration configuration)
where TColor : struct, IPixel<TColor>
internal static Image<TPixel> Create<TPixel>(int width, int height, ImageMetaData metadata, Configuration configuration)
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
{
return new Image<TColor>(width, height, metadata, configuration);
return new Image<TPixel>(width, height, metadata, configuration);
}
}
/// <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.
/// </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="height">The height of the image in pixels.</param>
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
/// <returns>
/// A new <see cref="Image{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>
internal static Image<TColor> Create<TColor>(int width, int height, Configuration configuration)
where TColor : struct, IPixel<TColor>
internal static Image<TPixel> Create<TPixel>(int width, int height, Configuration configuration)
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 Formats;
using ImageSharp.PixelFormats;
/// <summary>
/// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha
/// packed into a single unsigned integer value.
@ -51,15 +53,15 @@ namespace ImageSharp
/// <summary>
/// Decodes the image stream to the current image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="stream">The stream.</param>
/// <param name="options">The options for the decoder.</param>
/// <param name="config">the configuration.</param>
/// <returns>
/// The decoded image
/// </returns>
private static Image<TColor> Decode<TColor>(Stream stream, IDecoderOptions options, Configuration config)
where TColor : struct, IPixel<TColor>
private static Image<TPixel> Decode<TPixel>(Stream stream, IDecoderOptions options, Configuration config)
where TPixel : struct, IPixel<TPixel>
{
IImageFormat format = DiscoverFormat(stream, config);
if (format == null)
@ -67,7 +69,7 @@ namespace ImageSharp
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;
return img;
}

50
src/ImageSharp/Image.FromBytes.cs

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

11
src/ImageSharp/Image.cs

@ -5,18 +5,15 @@
namespace ImageSharp
{
using System;
using System.Diagnostics;
using System.IO;
using Formats;
using ImageSharp.PixelFormats;
/// <summary>
/// Represents an image. Each pixel is a made up four 8-bit components red, green, blue, and alpha
/// packed into a single unsigned integer value.
/// </summary>
[DebuggerDisplay("Image: {Width}x{Height}")]
public sealed partial class Image : Image<Color>
public sealed partial class Image : Image<Rgba32>
{
/// <summary>
/// Initializes a new instance of the <see cref="Image"/> class
@ -49,7 +46,7 @@ namespace ImageSharp
/// </summary>
/// <param name="other">The other image, where the clone should be made from.</param>
/// <exception cref="System.ArgumentNullException"><paramref name="other"/> is null.</exception>
public Image(Image<Color> other)
public Image(Image<Rgba32> 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.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -6,20 +6,21 @@
namespace ImageSharp
{
using System;
using ImageSharp.PixelFormats;
/// <summary>
/// Encapsulates the basic properties and methods required to manipulate images in varying formats.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public interface IImageBase<TColor> : IImageBase, IDisposable
where TColor : struct, IPixel<TColor>
/// <typeparam name="TPixel">The pixel format.</typeparam>
public interface IImageBase<TPixel> : IImageBase, IDisposable
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// 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
/// of the array for calculations. Use Width * Height.
/// </summary>
TColor[] Pixels { get; }
TPixel[] Pixels { get; }
/// <summary>
/// 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.
/// </remarks>
/// </summary>
/// <returns>The <see cref="PixelAccessor{TColor}"/></returns>
PixelAccessor<TColor> Lock();
/// <returns>The <see cref="PixelAccessor{TPixel}"/></returns>
PixelAccessor<TPixel> Lock();
}
}

12
src/ImageSharp/Image/IImageProcessor.cs

@ -8,12 +8,14 @@ namespace ImageSharp.Processing
using System;
using System.Threading.Tasks;
using ImageSharp.PixelFormats;
/// <summary>
/// Encapsulates methods to alter the pixels of an image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public interface IImageProcessor<TColor>
where TColor : struct, IPixel<TColor>
/// <typeparam name="TPixel">The pixel format.</typeparam>
public interface IImageProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Gets or sets the parallel options for processing tasks in parallel.
@ -27,7 +29,7 @@ namespace ImageSharp.Processing
bool Compand { get; set; }
/// <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>
/// <param name="source">The source image. Cannot be null.</param>
/// <param name="sourceRectangle">
@ -39,6 +41,6 @@ namespace ImageSharp.Processing
/// <exception cref="System.ArgumentException">
/// <paramref name="sourceRectangle"/> doesnt fit the dimension of the image.
/// </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.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -7,16 +7,17 @@ namespace ImageSharp
{
using System;
using System.Diagnostics;
using ImageSharp.PixelFormats;
using Processing;
/// <summary>
/// The base class of all images. Encapsulates the basic properties and methods required to manipulate
/// images in different pixel formats.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPixel">The pixel format.</typeparam>
[DebuggerDisplay("Image: {Width}x{Height}")]
public abstract class ImageBase<TColor> : IImageBase<TColor>
where TColor : struct, IPixel<TColor>
public abstract class ImageBase<TPixel> : IImageBase<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Gets or sets the maximum allowable width in pixels.
@ -31,7 +32,7 @@ namespace ImageSharp
/// <summary>
/// The image pixels
/// </summary>
private TColor[] pixelBuffer;
private TPixel[] pixelBuffer;
/// <summary>
/// A value indicating whether this instance of the given entity has been disposed.
@ -45,7 +46,7 @@ namespace ImageSharp
private bool isDisposed;
/// <summary>
/// Initializes a new instance of the <see cref="ImageBase{TColor}"/> class.
/// Initializes a new instance of the <see cref="ImageBase{TPixel}"/> class.
/// </summary>
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
@ -56,7 +57,7 @@ namespace ImageSharp
}
/// <summary>
/// Initializes a new instance of the <see cref="ImageBase{TColor}"/> class.
/// Initializes a new instance of the <see cref="ImageBase{TPixel}"/> class.
/// </summary>
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
@ -79,15 +80,15 @@ namespace ImageSharp
}
/// <summary>
/// Initializes a new instance of the <see cref="ImageBase{TColor}"/> class.
/// Initializes a new instance of the <see cref="ImageBase{TPixel}"/> class.
/// </summary>
/// <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>
/// <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>
protected ImageBase(ImageBase<TColor> other)
protected ImageBase(ImageBase<TPixel> other)
: this(other.Configuration)
{
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.
this.RentPixels();
using (PixelAccessor<TColor> sourcePixels = other.Lock())
using (PixelAccessor<TColor> target = this.Lock())
using (PixelAccessor<TPixel> sourcePixels = other.Lock())
using (PixelAccessor<TPixel> target = this.Lock())
{
// Check we can do this without crashing
sourcePixels.CopyTo(target);
@ -107,7 +108,7 @@ namespace ImageSharp
}
/// <inheritdoc/>
public TColor[] Pixels => this.pixelBuffer;
public TPixel[] Pixels => this.pixelBuffer;
/// <inheritdoc/>
public int Width { get; private set; }
@ -131,7 +132,7 @@ namespace ImageSharp
/// </summary>
/// <param name="processor">The processor.</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);
}
@ -150,16 +151,16 @@ namespace ImageSharp
}
/// <inheritdoc/>
public PixelAccessor<TColor> Lock()
public PixelAccessor<TPixel> Lock()
{
return new PixelAccessor<TColor>(this);
return new PixelAccessor<TPixel>(this);
}
/// <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.
/// </summary>
/// <param name="pixelSource">The pixel source.</param>
internal void SwapPixelsBuffers(PixelAccessor<TColor> pixelSource)
internal void SwapPixelsBuffers(PixelAccessor<TPixel> pixelSource)
{
Guard.NotNull(pixelSource, nameof(pixelSource));
@ -167,7 +168,7 @@ namespace ImageSharp
int newHeight = pixelSource.Height;
// 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.Height = newHeight;
this.pixelBuffer = newPixels;
@ -221,7 +222,7 @@ namespace ImageSharp
/// </summary>
private void RentPixels()
{
this.pixelBuffer = PixelDataPool<TColor>.Rent(this.Width * this.Height);
this.pixelBuffer = PixelDataPool<TPixel>.Rent(this.Width * this.Height);
}
/// <summary>
@ -229,7 +230,7 @@ namespace ImageSharp
/// </summary>
private void ReturnPixels()
{
PixelDataPool<TColor>.Return(this.pixelBuffer);
PixelDataPool<TPixel>.Return(this.pixelBuffer);
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.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -8,16 +8,17 @@ namespace ImageSharp
using System;
using System.Numerics;
using System.Threading.Tasks;
using ImageSharp.PixelFormats;
/// <summary>
/// Represents a single frame in a animation.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class ImageFrame<TColor> : ImageBase<TColor>, IImageFrame
where TColor : struct, IPixel<TColor>
/// <typeparam name="TPixel">The pixel format.</typeparam>
public class ImageFrame<TPixel> : ImageBase<TPixel>, IImageFrame
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Initializes a new instance of the <see cref="ImageFrame{TColor}"/> class.
/// Initializes a new instance of the <see cref="ImageFrame{TPixel}"/> class.
/// </summary>
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
@ -30,10 +31,10 @@ namespace ImageSharp
}
/// <summary>
/// Initializes a new instance of the <see cref="ImageFrame{TColor}"/> class.
/// Initializes a new instance of the <see cref="ImageFrame{TPixel}"/> class.
/// </summary>
/// <param name="image">The image to create the frame from.</param>
public ImageFrame(ImageBase<TColor> image)
public ImageFrame(ImageBase<TPixel> image)
: base(image)
{
}
@ -53,18 +54,18 @@ namespace ImageSharp
/// Returns a copy of the image frame in the given pixel format.
/// </summary>
/// <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>
/// <returns>The <see cref="ImageFrame{TColor2}"/></returns>
public ImageFrame<TColor2> To<TColor2>(Func<Vector4, Vector4> scaleFunc = null)
where TColor2 : struct, IPixel<TColor2>
/// <typeparam name="TPixel2">The pixel format.</typeparam>
/// <returns>The <see cref="ImageFrame{TPixel2}"/></returns>
public ImageFrame<TPixel2> To<TPixel2>(Func<Vector4, Vector4> scaleFunc = null)
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);
using (PixelAccessor<TColor> pixels = this.Lock())
using (PixelAccessor<TColor2> targetPixels = target.Lock())
using (PixelAccessor<TPixel> pixels = this.Lock())
using (PixelAccessor<TPixel2> targetPixels = target.Lock())
{
Parallel.For(
0,
@ -74,7 +75,7 @@ namespace ImageSharp
{
for (int x = 0; x < target.Width; x++)
{
TColor2 color = default(TColor2);
TPixel2 color = default(TPixel2);
color.PackFromVector4(scaleFunc(pixels[x, y].ToVector4()));
targetPixels[x, y] = color;
}
@ -87,10 +88,10 @@ namespace ImageSharp
/// <summary>
/// Clones the current instance.
/// </summary>
/// <returns>The <see cref="ImageFrame{TColor}"/></returns>
internal virtual ImageFrame<TColor> Clone()
/// <returns>The <see cref="ImageFrame{TPixel}"/></returns>
internal virtual ImageFrame<TPixel> Clone()
{
return new ImageFrame<TColor>(this);
return new ImageFrame<TPixel>(this);
}
/// <summary>

13
src/ImageSharp/Image/ImageProcessingExtensions.cs

@ -5,11 +5,12 @@
namespace ImageSharp
{
using System;
using ImageSharp.PixelFormats;
using Processing;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
{
@ -17,12 +18,12 @@ namespace ImageSharp
/// Applies the processor to the image.
/// <remarks>This method does not resize the target image.</remarks>
/// </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="processor">The processor to apply to the image.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Apply<TColor>(this Image<TColor> source, IImageProcessor<TColor> processor)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Apply<TPixel>(this Image<TPixel> source, IImageProcessor<TPixel> processor)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(processor, source.Bounds);
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.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -6,28 +6,27 @@
namespace ImageSharp
{
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using Formats;
using ImageSharp.PixelFormats;
using Processing;
/// <summary>
/// Encapsulates an image, which consists of the pixel data for a graphics image and its attributes.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPixel">The pixel format.</typeparam>
[DebuggerDisplay("Image: {Width}x{Height}")]
public class Image<TColor> : ImageBase<TColor>, IImage
where TColor : struct, IPixel<TColor>
public class Image<TPixel> : ImageBase<TPixel>, IImage
where TPixel : struct, IPixel<TPixel>
{
/// <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.
/// </summary>
/// <param name="width">The width of the image in pixels.</param>
@ -41,7 +40,7 @@ namespace ImageSharp
}
/// <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.
/// </summary>
/// <param name="width">The width of the image in pixels.</param>
@ -52,19 +51,19 @@ namespace ImageSharp
}
/// <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.
/// </summary>
/// <param name="other">The other image, where the clone should be made from.</param>
/// <exception cref="System.ArgumentNullException"><paramref name="other"/> is null.</exception>
public Image(Image<TColor> other)
public Image(Image<TPixel> other)
: base(other)
{
foreach (ImageFrame<TColor> frame in other.Frames)
foreach (ImageFrame<TPixel> frame in other.Frames)
{
if (frame != null)
{
this.Frames.Add(new ImageFrame<TColor>(frame));
this.Frames.Add(new ImageFrame<TPixel>(frame));
}
}
@ -72,19 +71,19 @@ namespace ImageSharp
}
/// <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.
/// </summary>
/// <param name="other">The other image, where the clone should be made from.</param>
/// <exception cref="System.ArgumentNullException"><paramref name="other"/> is null.</exception>
public Image(ImageBase<TColor> other)
public Image(ImageBase<TPixel> other)
: base(other)
{
this.MetaData = new ImageMetaData();
}
/// <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.
/// </summary>
/// <param name="width">The width of the image in pixels.</param>
@ -138,7 +137,7 @@ namespace ImageSharp
/// Gets the other frames for the animation.
/// </summary>
/// <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>
/// Gets the currently loaded image format.
@ -150,11 +149,11 @@ namespace ImageSharp
/// </summary>
/// <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>
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
base.ApplyProcessor(processor, rectangle);
foreach (ImageFrame<TColor> sourceFrame in this.Frames)
foreach (ImageFrame<TPixel> sourceFrame in this.Frames)
{
sourceFrame.ApplyProcessor(processor, rectangle);
}
@ -165,8 +164,8 @@ namespace ImageSharp
/// </summary>
/// <param name="stream">The stream to save the image to.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns>The <see cref="Image{TColor}"/></returns>
public Image<TColor> Save(Stream stream)
/// <returns>The <see cref="Image{TPixel}"/></returns>
public Image<TPixel> Save(Stream stream)
{
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="options">The options for the encoder.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns>The <see cref="Image{TColor}"/></returns>
public Image<TColor> Save(Stream stream, IEncoderOptions options)
/// <returns>The <see cref="Image{TPixel}"/></returns>
public Image<TPixel> Save(Stream stream, IEncoderOptions options)
{
return this.Save(stream, this.CurrentImageFormat?.Encoder, options);
}
@ -188,8 +187,8 @@ namespace ImageSharp
/// </summary>
/// <param name="stream">The stream to save the image to.</param>
/// <param name="format">The format to save the image as.</param>
/// <returns>The <see cref="Image{TColor}"/></returns>
public Image<TColor> Save(Stream stream, IImageFormat format)
/// <returns>The <see cref="Image{TPixel}"/></returns>
public Image<TPixel> Save(Stream stream, IImageFormat format)
{
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="format">The format to save the image as.</param>
/// <param name="options">The options for the encoder.</param>
/// <returns>The <see cref="Image{TColor}"/></returns>
public Image<TColor> Save(Stream stream, IImageFormat format, IEncoderOptions options)
/// <returns>The <see cref="Image{TPixel}"/></returns>
public Image<TPixel> Save(Stream stream, IImageFormat format, IEncoderOptions options)
{
Guard.NotNull(format, nameof(format));
@ -215,9 +214,9 @@ namespace ImageSharp
/// <param name="encoder">The encoder to save the image with.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream or encoder is null.</exception>
/// <returns>
/// The <see cref="Image{TColor}"/>.
/// The <see cref="Image{TPixel}"/>.
/// </returns>
public Image<TColor> Save(Stream stream, IImageEncoder encoder)
public Image<TPixel> Save(Stream stream, IImageEncoder encoder)
{
return this.Save(stream, encoder, null);
}
@ -230,9 +229,9 @@ namespace ImageSharp
/// <param name="options">The options for the encoder.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream or encoder is null.</exception>
/// <returns>
/// The <see cref="Image{TColor}"/>.
/// The <see cref="Image{TPixel}"/>.
/// </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(encoder, nameof(encoder));
@ -248,8 +247,8 @@ namespace ImageSharp
/// </summary>
/// <param name="filePath">The file path to save the image to.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns>The <see cref="Image{TColor}"/></returns>
public Image<TColor> Save(string filePath)
/// <returns>The <see cref="Image{TPixel}"/></returns>
public Image<TPixel> Save(string filePath)
{
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="options">The options for the encoder.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns>The <see cref="Image{TColor}"/></returns>
public Image<TColor> Save(string filePath, IEncoderOptions options)
/// <returns>The <see cref="Image{TPixel}"/></returns>
public Image<TPixel> Save(string filePath, IEncoderOptions options)
{
string ext = Path.GetExtension(filePath).Trim('.');
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="format">The format to save the image as.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the format is null.</exception>
/// <returns>The <see cref="Image{TColor}"/></returns>
public Image<TColor> Save(string filePath, IImageFormat format)
/// <returns>The <see cref="Image{TPixel}"/></returns>
public Image<TPixel> Save(string filePath, IImageFormat format)
{
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="options">The options for the encoder.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the format is null.</exception>
/// <returns>The <see cref="Image{TColor}"/></returns>
public Image<TColor> Save(string filePath, IImageFormat format, IEncoderOptions options)
/// <returns>The <see cref="Image{TPixel}"/></returns>
public Image<TPixel> Save(string filePath, IImageFormat format, IEncoderOptions options)
{
Guard.NotNull(format, nameof(format));
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="encoder">The encoder to save the image with.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the encoder is null.</exception>
/// <returns>The <see cref="Image{TColor}"/></returns>
public Image<TColor> Save(string filePath, IImageEncoder encoder)
/// <returns>The <see cref="Image{TPixel}"/></returns>
public Image<TPixel> Save(string filePath, IImageEncoder encoder)
{
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="options">The options for the encoder.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the encoder is null.</exception>
/// <returns>The <see cref="Image{TColor}"/></returns>
public Image<TColor> Save(string filePath, IImageEncoder encoder, IEncoderOptions options)
/// <returns>The <see cref="Image{TPixel}"/></returns>
public Image<TPixel> Save(string filePath, IImageEncoder encoder, IEncoderOptions options)
{
Guard.NotNull(encoder, nameof(encoder));
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.
/// </summary>
/// <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>
/// <returns>The <see cref="Image{TColor2}"/></returns>
public Image<TColor2> To<TColor2>(Func<Vector4, Vector4> scaleFunc = null)
where TColor2 : struct, IPixel<TColor2>
/// <typeparam name="TPixel2">The pixel format.</typeparam>
/// <returns>The <see cref="Image{TPixel2}"/></returns>
public Image<TPixel2> To<TPixel2>(Func<Vector4, Vector4> scaleFunc = null)
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);
using (PixelAccessor<TColor> pixels = this.Lock())
using (PixelAccessor<TColor2> targetPixels = target.Lock())
using (PixelAccessor<TPixel> pixels = this.Lock())
using (PixelAccessor<TPixel2> targetPixels = target.Lock())
{
Parallel.For(
0,
@ -375,7 +374,7 @@ namespace ImageSharp
{
for (int x = 0; x < target.Width; x++)
{
TColor2 color = default(TColor2);
TPixel2 color = default(TPixel2);
color.PackFromVector4(scaleFunc(pixels[x, y].ToVector4()));
targetPixels[x, y] = color;
}
@ -384,19 +383,19 @@ namespace ImageSharp
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;
}
/// <summary>
/// Creates a new <see cref="ImageFrame{TColor}"/> from this instance
/// Creates a new <see cref="ImageFrame{TPixel}"/> from this instance
/// </summary>
/// <returns>The <see cref="ImageFrame{TColor}"/></returns>
internal virtual ImageFrame<TColor> ToFrame()
/// <returns>The <see cref="ImageFrame{TPixel}"/></returns>
internal virtual ImageFrame<TPixel> ToFrame()
{
return new ImageFrame<TColor>(this);
return new ImageFrame<TPixel>(this);
}
/// <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.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -8,15 +8,15 @@ namespace ImageSharp
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using ImageSharp.PixelFormats;
/// <summary>
/// Provides per-pixel access to generic <see cref="Image{TColor}"/> pixels.
/// Provides per-pixel access to generic <see cref="Image{TPixel}"/> pixels.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public sealed class PixelAccessor<TColor> : IDisposable, IBuffer2D<TColor>
where TColor : struct, IPixel<TColor>
/// <typeparam name="TPixel">The pixel format.</typeparam>
public sealed class PixelAccessor<TPixel> : IDisposable, IBuffer2D<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// A value indicating whether this instance of the given entity has been disposed.
@ -32,13 +32,13 @@ namespace ImageSharp
/// <summary>
/// The <see cref="Buffer{T}"/> containing the pixel data.
/// </summary>
private Buffer2D<TColor> pixelBuffer;
private Buffer2D<TPixel> pixelBuffer;
/// <summary>
/// Initializes a new instance of the <see cref="PixelAccessor{TColor}"/> class.
/// Initializes a new instance of the <see cref="PixelAccessor{TPixel}"/> class.
/// </summary>
/// <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.MustBeGreaterThan(image.Width, 0, "image width");
@ -49,22 +49,22 @@ namespace ImageSharp
}
/// <summary>
/// Initializes a new instance of the <see cref="PixelAccessor{TColor}"/> class.
/// Initializes a new instance of the <see cref="PixelAccessor{TPixel}"/> class.
/// </summary>
/// <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>
public PixelAccessor(int width, int height)
: this(width, height, Buffer2D<TColor>.CreateClean(width, height))
: this(width, height, Buffer2D<TPixel>.CreateClean(width, height))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="PixelAccessor{TColor}" /> class.
/// Initializes a new instance of the <see cref="PixelAccessor{TPixel}" /> class.
/// </summary>
/// <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="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.MustBeGreaterThan(width, 0, nameof(width));
@ -76,7 +76,7 @@ namespace ImageSharp
}
/// <summary>
/// Finalizes an instance of the <see cref="PixelAccessor{TColor}"/> class.
/// Finalizes an instance of the <see cref="PixelAccessor{TPixel}"/> class.
/// </summary>
~PixelAccessor()
{
@ -86,7 +86,7 @@ namespace ImageSharp
/// <summary>
/// Gets the pixel buffer array.
/// </summary>
public TColor[] PixelArray => this.pixelBuffer.Array;
public TPixel[] PixelArray => this.pixelBuffer.Array;
/// <summary>
/// Gets the size of a single pixel in the number of bytes.
@ -114,17 +114,17 @@ namespace ImageSharp
public ParallelOptions ParallelOptions { get; }
/// <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>
/// Gets or sets the pixel at the specified position.
/// </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="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>
public TColor this[int x, int y]
/// <returns>The <see typeparam="TPixel"/> at the specified position.</returns>
public TPixel this[int x, int y]
{
get
{
@ -179,7 +179,7 @@ namespace ImageSharp
/// <exception cref="NotSupportedException">
/// Thrown when an unsupported component order value is passed.
/// </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);
@ -195,7 +195,7 @@ namespace ImageSharp
/// <exception cref="NotSupportedException">
/// Thrown when an unsupported component order value is passed.
/// </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);
@ -212,7 +212,7 @@ namespace ImageSharp
/// <exception cref="NotSupportedException">
/// Thrown when an unsupported component order value is passed.
/// </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);
if (width < 1)
@ -237,18 +237,18 @@ namespace ImageSharp
/// <param name="pixels">The pixels.</param>
/// <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>
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);
return oldPixels;
}
/// <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>
/// <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);
}
@ -262,12 +262,12 @@ namespace ImageSharp
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
[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++)
{
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);
}
@ -282,12 +282,12 @@ namespace ImageSharp
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
[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++)
{
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);
}
@ -302,12 +302,12 @@ namespace ImageSharp
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
[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++)
{
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);
}
@ -322,12 +322,12 @@ namespace ImageSharp
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
[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++)
{
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);
}
}
@ -341,11 +341,11 @@ namespace ImageSharp
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
[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++)
{
BufferSpan<TColor> source = this.GetRowSpan(sourceX, sourceY + y);
BufferSpan<TPixel> source = this.GetRowSpan(sourceX, sourceY + y);
BufferSpan<byte> destination = area.GetRowSpan(y);
Operations.ToZyxBytes(source, destination, width);
}
@ -360,11 +360,11 @@ namespace ImageSharp
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
[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++)
{
BufferSpan<TColor> source = this.GetRowSpan(sourceX, sourceY + y);
BufferSpan<TPixel> source = this.GetRowSpan(sourceX, sourceY + y);
BufferSpan<byte> destination = area.GetRowSpan(y);
Operations.ToZyxwBytes(source, destination, width);
}
@ -379,11 +379,11 @@ namespace ImageSharp
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
[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++)
{
BufferSpan<TColor> source = this.GetRowSpan(sourceX, sourceY + y);
BufferSpan<TPixel> source = this.GetRowSpan(sourceX, sourceY + y);
BufferSpan<byte> destination = area.GetRowSpan(y);
Operations.ToXyzBytes(source, destination, width);
}
@ -398,19 +398,19 @@ namespace ImageSharp
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
[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++)
{
BufferSpan<TColor> source = this.GetRowSpan(sourceX, sourceY + y);
BufferSpan<TPixel> source = this.GetRowSpan(sourceX, sourceY + y);
BufferSpan<byte> destination = area.GetRowSpan(y);
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>
@ -419,13 +419,13 @@ namespace ImageSharp
/// <param name="width">The width.</param>
/// <param name="height">The height.</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.Width = width;
this.Height = height;
this.PixelSize = Unsafe.SizeOf<TColor>();
this.PixelSize = Unsafe.SizeOf<TPixel>();
this.RowStride = this.Width * this.PixelSize;
}
@ -440,7 +440,7 @@ namespace ImageSharp
/// <exception cref="NotSupportedException">
/// Thrown when an unsupported component order value is passed.
/// </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)
{
@ -472,7 +472,7 @@ namespace ImageSharp
/// <exception cref="NotSupportedException">
/// Thrown when an unsupported component order value is passed.
/// </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)
{
@ -503,7 +503,7 @@ namespace ImageSharp
/// Thrown if the dimensions are not within the bounds of the image.
/// </exception>
[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);
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.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using ImageSharp.PixelFormats;
/// <summary>
/// Represents an area of generic <see cref="Image{TColor}"/> pixels.
/// Represents an area of generic <see cref="Image{TPixel}"/> pixels.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
internal sealed class PixelArea<TColor> : IDisposable
where TColor : struct, IPixel<TColor>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal sealed class PixelArea<TPixel> : IDisposable
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// A value indicating whether this instance of the given entity has been disposed.
@ -33,7 +34,7 @@ namespace ImageSharp
private Buffer<byte> byteBuffer;
/// <summary>
/// Initializes a new instance of the <see cref="PixelArea{TColor}"/> class.
/// Initializes a new instance of the <see cref="PixelArea{TPixel}"/> class.
/// </summary>
/// <param name="width">The width.</param>
/// <param name="bytes">The bytes.</param>
@ -47,7 +48,7 @@ namespace ImageSharp
}
/// <summary>
/// Initializes a new instance of the <see cref="PixelArea{TColor}"/> class.
/// Initializes a new instance of the <see cref="PixelArea{TPixel}"/> class.
/// </summary>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
@ -70,7 +71,7 @@ namespace ImageSharp
}
/// <summary>
/// Initializes a new instance of the <see cref="PixelArea{TColor}"/> class.
/// Initializes a new instance of the <see cref="PixelArea{TPixel}"/> class.
/// </summary>
/// <param name="width">The width.</param>
/// <param name="componentOrder">The component order.</param>
@ -80,7 +81,7 @@ namespace ImageSharp
}
/// <summary>
/// Initializes a new instance of the <see cref="PixelArea{TColor}"/> class.
/// Initializes a new instance of the <see cref="PixelArea{TPixel}"/> class.
/// </summary>
/// <param name="width">The width. </param>
/// <param name="componentOrder">The component order.</param>
@ -91,7 +92,7 @@ namespace ImageSharp
}
/// <summary>
/// Initializes a new instance of the <see cref="PixelArea{TColor}"/> class.
/// Initializes a new instance of the <see cref="PixelArea{TPixel}"/> class.
/// </summary>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
@ -102,7 +103,7 @@ namespace ImageSharp
}
/// <summary>
/// Initializes a new instance of the <see cref="PixelArea{TColor}"/> class.
/// Initializes a new instance of the <see cref="PixelArea{TPixel}"/> class.
/// </summary>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>

18
src/ImageSharp/ImageProcessor.cs

@ -8,12 +8,14 @@ namespace ImageSharp.Processing
using System;
using System.Threading.Tasks;
using ImageSharp.PixelFormats;
/// <summary>
/// Allows the application of processors to images.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
internal abstract class ImageProcessor<TColor> : IImageProcessor<TColor>
where TColor : struct, IPixel<TColor>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal abstract class ImageProcessor<TPixel> : IImageProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <inheritdoc/>
public virtual ParallelOptions ParallelOptions { get; set; }
@ -22,7 +24,7 @@ namespace ImageSharp.Processing
public virtual bool Compand { get; set; } = false;
/// <inheritdoc/>
public void Apply(ImageBase<TColor> source, Rectangle sourceRectangle)
public void Apply(ImageBase<TPixel> source, Rectangle sourceRectangle)
{
if (this.ParallelOptions == null)
{
@ -50,19 +52,19 @@ namespace ImageSharp.Processing
/// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// </param>
protected virtual void BeforeApply(ImageBase<TColor> source, Rectangle sourceRectangle)
protected virtual void BeforeApply(ImageBase<TPixel> source, Rectangle sourceRectangle)
{
}
/// <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.
/// </summary>
/// <param name="source">The source image. Cannot be null.</param>
/// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// </param>
protected abstract void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle);
protected abstract void OnApply(ImageBase<TPixel> source, Rectangle sourceRectangle);
/// <summary>
/// This method is called after the process is applied to prepare the processor.
@ -71,7 +73,7 @@ namespace ImageSharp.Processing
/// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// </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>
<Description>A cross-platform library for the processing of image files; written in C#</Description>
<AssemblyTitle>ImageSharp</AssemblyTitle>
<VersionPrefix>1.0.0-alpha6</VersionPrefix>
<VersionPrefix>1.0.0-alpha7</VersionPrefix>
<Authors>James Jackson-South and contributors</Authors>
<TargetFrameworks>netstandard1.3;netstandard1.1</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

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

@ -10,6 +10,8 @@ namespace ImageSharp
using System.Collections.ObjectModel;
using System.IO;
using ImageSharp.PixelFormats;
/// <summary>
/// Represents an EXIF profile providing access to the collection of values.
/// </summary>
@ -116,12 +118,12 @@ namespace ImageSharp
/// <summary>
/// Returns the thumbnail in the EXIF profile when available.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>
/// The <see cref="Image{TColor}"/>.
/// The <see cref="Image{TPixel}"/>.
/// </returns>
public Image<TColor> CreateThumbnail<TColor>()
where TColor : struct, IPixel<TColor>
public Image<TPixel> CreateThumbnail<TPixel>()
where TPixel : struct, IPixel<TPixel>
{
this.InitializeValues();
@ -137,7 +139,7 @@ namespace ImageSharp
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.
// </copyright>
namespace ImageSharp
namespace ImageSharp.PixelFormats
{
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
/// <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>
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.
// </copyright>
namespace ImageSharp
namespace ImageSharp.PixelFormats
{
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
/// <summary>
/// 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.
/// Ranges from &lt;0, 0, 0, 0&gt; to &lt;1, 1, 1, 1&gt; in vector form.
/// </summary>
/// <remarks>
/// 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.
// </copyright>
namespace ImageSharp
namespace ImageSharp.PixelFormats
{
using System;
using System.Numerics;
@ -11,6 +11,7 @@ namespace ImageSharp
/// <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.
/// Ranges from &lt;0, 0, 0, 1&gt; to &lt;1, 1, 1, 1&gt; in vector form.
/// </summary>
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.
// </copyright>
namespace ImageSharp
namespace ImageSharp.PixelFormats
{
using System;
using System.Numerics;
@ -11,6 +11,7 @@ namespace ImageSharp
/// <summary>
/// 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>
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.
// </copyright>
namespace ImageSharp
namespace ImageSharp.PixelFormats
{
using System;
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.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
namespace ImageSharp.PixelFormats
{
using System.Numerics;
using System.Runtime.CompilerServices;
/// <summary>
/// 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>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class BulkPixelOperations<TColor>
where TColor : struct, IPixel<TColor>
/// <typeparam name="TPixel">The pixel format.</typeparam>
public class BulkPixelOperations<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <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>
public static BulkPixelOperations<TColor> Instance { get; } = default(TColor).CreateBulkOperations();
public static BulkPixelOperations<TPixel> Instance { get; } = default(TPixel).CreateBulkOperations();
/// <summary>
/// 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="destColors">The <see cref="BufferSpan{T}"/> to the destination colors.</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 TColor destRef = ref destColors.DangerousGetPinnableReference();
ref TPixel destRef = ref destColors.DangerousGetPinnableReference();
for (int i = 0; i < count; 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);
}
}
@ -46,14 +46,14 @@ namespace ImageSharp
/// <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="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();
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);
dp = sp.ToVector4();
}
@ -65,15 +65,15 @@ namespace ImageSharp
/// <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="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 TColor destRef = ref destColors.DangerousGetPinnableReference();
ref TPixel destRef = ref destColors.DangerousGetPinnableReference();
for (int i = 0; i < count; i++)
{
int i3 = i * 3;
ref TColor dp = ref Unsafe.Add(ref destRef, i);
ref TPixel dp = ref Unsafe.Add(ref destRef, i);
dp.PackFromBytes(
Unsafe.Add(ref sourceRef, i3),
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="destBytes">The <see cref="BufferSpan{T}"/> to the destination bytes.</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;
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));
}
}
@ -106,15 +106,15 @@ namespace ImageSharp
/// <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="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 TColor destRef = ref destColors.DangerousGetPinnableReference();
ref TPixel destRef = ref destColors.DangerousGetPinnableReference();
for (int i = 0; i < count; i++)
{
int i4 = i * 4;
ref TColor dp = ref Unsafe.Add(ref destRef, i);
ref TPixel dp = ref Unsafe.Add(ref destRef, i);
dp.PackFromBytes(
Unsafe.Add(ref sourceRef, i4),
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="destBytes">The <see cref="BufferSpan{T}"/> to the destination bytes.</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;
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));
}
}
@ -147,15 +147,15 @@ namespace ImageSharp
/// <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="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 TColor destRef = ref destColors.DangerousGetPinnableReference();
ref TPixel destRef = ref destColors.DangerousGetPinnableReference();
for (int i = 0; i < count; i++)
{
int i3 = i * 3;
ref TColor dp = ref Unsafe.Add(ref destRef, i);
ref TPixel dp = ref Unsafe.Add(ref destRef, i);
dp.PackFromBytes(
Unsafe.Add(ref sourceRef, i3 + 2),
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="destBytes">The <see cref="BufferSpan{T}"/> to the destination bytes.</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;
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));
}
}
@ -188,15 +188,15 @@ namespace ImageSharp
/// <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="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 TColor destRef = ref destColors.DangerousGetPinnableReference();
ref TPixel destRef = ref destColors.DangerousGetPinnableReference();
for (int i = 0; i < count; i++)
{
int i4 = i * 4;
ref TColor dp = ref Unsafe.Add(ref destRef, i);
ref TPixel dp = ref Unsafe.Add(ref destRef, i);
dp.PackFromBytes(
Unsafe.Add(ref sourceRef, i4 + 2),
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="destBytes">The <see cref="BufferSpan{T}"/> to the destination bytes.</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;
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));
}
}

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

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
namespace ImageSharp.PixelFormats
{
using System;
using System.Numerics;
@ -11,6 +11,7 @@ namespace ImageSharp
/// <summary>
/// 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>
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.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
namespace ImageSharp.PixelFormats
{
using System;
using System.Globalization;
@ -11,19 +11,19 @@ namespace ImageSharp
/// <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 ColorBuilder<TColor>
where TColor : struct, IPixel<TColor>
/// <typeparam name="TPixel">The type of the color.</typeparam>
public static class ColorBuilder<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <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>
/// <param name="hex">
/// The hexadecimal representation of the combined color components arranged
/// in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax.
/// </param>
/// <returns>Returns a <typeparamref name="TColor"/> that represents the color defined by the provided RGBA heax string.</returns>
public static TColor FromHex(string hex)
/// <returns>Returns a <typeparamref name="TPixel"/> that represents the color defined by the provided RGBA heax string.</returns>
public static TPixel FromHex(string 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));
}
TColor result = default(TColor);
TPixel result = default(TPixel);
result.PackFromBytes(
(byte)(packedValue >> 24),
@ -45,30 +45,30 @@ namespace ImageSharp
}
/// <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>
/// <param name="red">The red intensity.</param>
/// <param name="green">The green 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>
public static TColor FromRGB(byte red, byte green, byte blue)
/// <returns>Returns a <typeparamref name="TPixel"/> that represents the color defined by the provided RGB values with 100% opacity.</returns>
public static TPixel FromRGB(byte red, byte green, byte blue)
{
TColor color = default(TColor);
TPixel color = default(TPixel);
color.PackFromBytes(red, green, blue, 255);
return color;
}
/// <summary>
/// Creates a new <typeparamref name="TColor"/> representation from standard RGBA bytes.
/// Creates a new <typeparamref name="TPixel"/> representation from standard RGBA bytes.
/// </summary>
/// <param name="red">The red intensity.</param>
/// <param name="green">The green intensity.</param>
/// <param name="blue">The blue 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>
public static TColor FromRGBA(byte red, byte green, byte blue, byte alpha)
/// <returns>Returns a <typeparamref name="TPixel"/> that represents the color defined by the provided RGBA values.</returns>
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);
return color;
}

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

Loading…
Cancel
Save