Browse Source

Rename TColor to TPixel

pull/182/head
James Jackson-South 9 years ago
parent
commit
eceb889758
  1. 2
      README.md
  2. 40
      src/ImageSharp.Drawing/Brushes/Brushes{TPixel}.cs
  3. 12
      src/ImageSharp.Drawing/Brushes/IBrush.cs
  4. 27
      src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs
  5. 36
      src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs
  6. 18
      src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs
  7. 6
      src/ImageSharp.Drawing/Brushes/RecolorBrush.cs
  8. 48
      src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs
  9. 28
      src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs
  10. 18
      src/ImageSharp.Drawing/DrawImage.cs
  11. 60
      src/ImageSharp.Drawing/DrawPath.cs
  12. 60
      src/ImageSharp.Drawing/FillRegion.cs
  13. 58
      src/ImageSharp.Drawing/Paths/DrawBeziers.cs
  14. 58
      src/ImageSharp.Drawing/Paths/DrawLines.cs
  15. 58
      src/ImageSharp.Drawing/Paths/DrawPath.cs
  16. 58
      src/ImageSharp.Drawing/Paths/DrawPolygon.cs
  17. 58
      src/ImageSharp.Drawing/Paths/DrawRectangle.cs
  18. 38
      src/ImageSharp.Drawing/Paths/FillPaths.cs
  19. 38
      src/ImageSharp.Drawing/Paths/FillPolygon.cs
  20. 38
      src/ImageSharp.Drawing/Paths/FillRectangle.cs
  21. 8
      src/ImageSharp.Drawing/Pens/IPen.cs
  22. 2
      src/ImageSharp.Drawing/Pens/Pen.cs
  23. 50
      src/ImageSharp.Drawing/Pens/Pens{TPixel}.cs
  24. 58
      src/ImageSharp.Drawing/Pens/Pen{TPixel}.cs
  25. 8
      src/ImageSharp.Drawing/Pens/Processors/ColoredPointInfo.cs
  26. 10
      src/ImageSharp.Drawing/Pens/Processors/PenApplicator.cs
  27. 20
      src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs
  28. 24
      src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs
  29. 24
      src/ImageSharp.Drawing/Processors/FillProcessor.cs
  30. 20
      src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs
  31. 68
      src/ImageSharp.Drawing/Text/DrawText.cs
  32. 32
      src/ImageSharp/Colors/ColorBuilder{TPixel}.cs
  33. 725
      src/ImageSharp/Colors/NamedColors{TColor}.cs
  34. 725
      src/ImageSharp/Colors/NamedColors{TPixel}.cs
  35. 74
      src/ImageSharp/Colors/PackedPixel/BulkPixelOperations{TPixel}.cs
  36. 6
      src/ImageSharp/Colors/PackedPixel/IPixel.cs
  37. 10
      src/ImageSharp/Colors/PackedPixel/PackedPixelConverterHelper.cs
  38. 2
      src/ImageSharp/Colors/Rgba32.BulkOperations.cs
  39. 8
      src/ImageSharp/Colors/Rgba32.ColorspaceTransforms.cs
  40. 2
      src/ImageSharp/Colors/RgbaVector.BulkOperations.cs
  41. 6
      src/ImageSharp/Colors/Spaces/IAlmostEquatable.cs
  42. 18
      src/ImageSharp/Common/Helpers/ImageMaths.cs
  43. 2
      src/ImageSharp/Common/Memory/PixelDataPool{T}.cs
  44. 10
      src/ImageSharp/Dithering/ErrorDiffusion/ErrorDiffuser.cs
  45. 12
      src/ImageSharp/Dithering/ErrorDiffusion/IErrorDiffuser.cs
  46. 6
      src/ImageSharp/Dithering/Ordered/IOrderedDither.cs
  47. 4
      src/ImageSharp/Dithering/Ordered/OrderedDither4x4.cs
  48. 6
      src/ImageSharp/Formats/Bmp/BmpDecoder.cs
  49. 56
      src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
  50. 14
      src/ImageSharp/Formats/Bmp/BmpEncoder.cs
  51. 40
      src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
  52. 10
      src/ImageSharp/Formats/Bmp/ImageExtensions.cs
  53. 16
      src/ImageSharp/Formats/Gif/GifDecoder.cs
  54. 38
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs
  55. 14
      src/ImageSharp/Formats/Gif/GifEncoder.cs
  56. 86
      src/ImageSharp/Formats/Gif/GifEncoderCore.cs
  57. 18
      src/ImageSharp/Formats/Gif/ImageExtensions.cs
  58. 8
      src/ImageSharp/Formats/IImageDecoder.cs
  59. 10
      src/ImageSharp/Formats/IImageEncoder.cs
  60. 18
      src/ImageSharp/Formats/Jpeg/ImageExtensions.cs
  61. 6
      src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
  62. 104
      src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
  63. 14
      src/ImageSharp/Formats/Jpeg/JpegEncoder.cs
  64. 54
      src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs
  65. 24
      src/ImageSharp/Formats/Jpeg/Utils/JpegUtils.cs
  66. 18
      src/ImageSharp/Formats/Png/ImageExtensions.cs
  67. 16
      src/ImageSharp/Formats/Png/PngDecoder.cs
  68. 48
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  69. 14
      src/ImageSharp/Formats/Png/PngEncoder.cs
  70. 68
      src/ImageSharp/Formats/Png/PngEncoderCore.cs
  71. 28
      src/ImageSharp/Image.Create.cs
  72. 8
      src/ImageSharp/Image.Decode.cs
  73. 48
      src/ImageSharp/Image.FromBytes.cs
  74. 48
      src/ImageSharp/Image.FromFile.cs
  75. 48
      src/ImageSharp/Image.FromStream.cs
  76. 14
      src/ImageSharp/Image/IImageBase{TPixel}.cs
  77. 10
      src/ImageSharp/Image/IImageProcessor.cs
  78. 43
      src/ImageSharp/Image/ImageBase{TPixel}.cs
  79. 38
      src/ImageSharp/Image/ImageFrame{TPixel}.cs
  80. 11
      src/ImageSharp/Image/ImageProcessingExtensions.cs
  81. 110
      src/ImageSharp/Image/Image{TPixel}.cs
  82. 98
      src/ImageSharp/Image/PixelAccessor{TPixel}.cs
  83. 23
      src/ImageSharp/Image/PixelArea{TPixel}.cs
  84. 16
      src/ImageSharp/ImageProcessor.cs
  85. 10
      src/ImageSharp/MetaData/Profiles/Exif/ExifProfile.cs
  86. 20
      src/ImageSharp/Processing/Binarization/BinaryThreshold.cs
  87. 32
      src/ImageSharp/Processing/Binarization/Dither.cs
  88. 20
      src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs
  89. 36
      src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs
  90. 24
      src/ImageSharp/Processing/ColorMatrix/Grayscale.cs
  91. 20
      src/ImageSharp/Processing/ColorMatrix/Hue.cs
  92. 20
      src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs
  93. 20
      src/ImageSharp/Processing/ColorMatrix/Lomograph.cs
  94. 20
      src/ImageSharp/Processing/ColorMatrix/Polaroid.cs
  95. 20
      src/ImageSharp/Processing/ColorMatrix/Saturation.cs
  96. 16
      src/ImageSharp/Processing/ColorMatrix/Sepia.cs
  97. 20
      src/ImageSharp/Processing/Convolution/BoxBlur.cs
  98. 80
      src/ImageSharp/Processing/Convolution/DetectEdges.cs
  99. 20
      src/ImageSharp/Processing/Convolution/GaussianBlur.cs
  100. 20
      src/ImageSharp/Processing/Convolution/GaussianSharpen.cs

2
README.md

@ -112,7 +112,7 @@ using (var pixels = image.Lock())
} }
``` ```
For advanced usage the `Image<TColor>` and `PixelAccessor<TColor>` classes are available allowing developers to implement their own color models in the same manner as Microsoft XNA Game Studio and MonoGame. For advanced usage the `Image<TPixel>` and `PixelAccessor<TPixel>` classes are available allowing developers to implement their own color models in the same manner as Microsoft XNA Game Studio and MonoGame.
All in all this should allow image processing to be much more accessible to developers which has always been my goal from the start. All in all this should allow image processing to be much more accessible to developers which has always been my goal from the start.

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

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

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

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

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

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

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

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

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

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

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

@ -14,10 +14,10 @@ namespace ImageSharp.Drawing.Brushes
/// Initializes a new instance of the <see cref="RecolorBrush" /> class. /// Initializes a new instance of the <see cref="RecolorBrush" /> class.
/// </summary> /// </summary>
/// <param name="sourceColor">Color of the source.</param> /// <param name="sourceColor">Color of the source.</param>
/// <param name="targetColor">Color of the target.</param> /// <param name="targeTPixel">Color of the target.</param>
/// <param name="threshold">The threshold.</param> /// <param name="threshold">The threshold.</param>
public RecolorBrush(Rgba32 sourceColor, Rgba32 targetColor, float threshold) public RecolorBrush(Rgba32 sourceColor, Rgba32 targeTPixel, float threshold)
: base(sourceColor, targetColor, threshold) : base(sourceColor, targeTPixel, threshold)
{ {
} }
} }

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

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

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

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

18
src/ImageSharp.Drawing/DrawImage.cs

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

60
src/ImageSharp.Drawing/DrawPath.cs

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

60
src/ImageSharp.Drawing/FillRegion.cs

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -6,7 +6,7 @@
namespace ImageSharp.Drawing.Pens namespace ImageSharp.Drawing.Pens
{ {
/// <summary> /// <summary>
/// Represents a <see cref="Pen{TColor}"/> in the <see cref="Rgba32"/> color space. /// Represents a <see cref="Pen{TPixel}"/> in the <see cref="Rgba32"/> color space.
/// </summary> /// </summary>
public class Pen : Pen<Rgba32> public class Pen : Pen<Rgba32>
{ {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -1,725 +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
{
/// <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);
}
}

725
src/ImageSharp/Colors/NamedColors{TPixel}.cs

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

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

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

6
src/ImageSharp/Colors/PackedPixel/IPixel.cs

@ -16,10 +16,10 @@ namespace ImageSharp
where TSelf : struct, IPixel<TSelf> where TSelf : struct, IPixel<TSelf>
{ {
/// <summary> /// <summary>
/// Creates a <see cref="BulkPixelOperations{TColor}"/> instance for this pixel type. /// Creates a <see cref="BulkPixelOperations{TPixel}"/> instance for this pixel type.
/// This method is not intended to be consumed directly. Use <see cref="BulkPixelOperations{TColor}.Instance"/> instead. /// This method is not intended to be consumed directly. Use <see cref="BulkPixelOperations{TPixel}.Instance"/> instead.
/// </summary> /// </summary>
/// <returns>The <see cref="BulkPixelOperations{TColor}"/> instance.</returns> /// <returns>The <see cref="BulkPixelOperations{TPixel}"/> instance.</returns>
BulkPixelOperations<TSelf> CreateBulkOperations(); BulkPixelOperations<TSelf> CreateBulkOperations();
} }

10
src/ImageSharp/Colors/PackedPixel/PackedPixelConverterHelper.cs

@ -22,10 +22,10 @@ namespace ImageSharp
/// Returns the correct scaling function for the given types The compute scale function. /// Returns the correct scaling function for the given types The compute scale function.
/// </summary> /// </summary>
/// <param name="scaleFunc">The scale function.</param> /// <param name="scaleFunc">The scale function.</param>
/// <typeparam name="TColor">The source pixel format.</typeparam> /// <typeparam name="TPixel">The source pixel format.</typeparam>
/// <typeparam name="TColor2">The target pixel format.</typeparam> /// <typeparam name="TPixel2">The target pixel format.</typeparam>
/// <returns>The <see cref="Func{Vector4,Vector4}"/></returns> /// <returns>The <see cref="Func{Vector4,Vector4}"/></returns>
public static Func<Vector4, Vector4> ComputeScaleFunction<TColor, TColor2>(Func<Vector4, Vector4> scaleFunc) public static Func<Vector4, Vector4> ComputeScaleFunction<TPixel, TPixel2>(Func<Vector4, Vector4> scaleFunc)
{ {
// Custom type with a custom function. // Custom type with a custom function.
if (scaleFunc != null) if (scaleFunc != null)
@ -33,8 +33,8 @@ namespace ImageSharp
return scaleFunc; return scaleFunc;
} }
Type source = typeof(TColor); Type source = typeof(TPixel);
Type target = typeof(TColor2); Type target = typeof(TPixel2);
// Normalized standard // Normalized standard
if (IsStandardNormalizedType(source)) if (IsStandardNormalizedType(source))

2
src/ImageSharp/Colors/Rgba32.BulkOperations.cs

@ -21,7 +21,7 @@ namespace ImageSharp
public partial struct Rgba32 public partial struct Rgba32
{ {
/// <summary> /// <summary>
/// <see cref="BulkPixelOperations{TColor}"/> implementation optimized for <see cref="Rgba32"/>. /// <see cref="BulkPixelOperations{TPixel}"/> implementation optimized for <see cref="Rgba32"/>.
/// </summary> /// </summary>
internal class BulkOperations : BulkPixelOperations<Rgba32> internal class BulkOperations : BulkPixelOperations<Rgba32>
{ {

8
src/ImageSharp/Colors/Rgba32.ColorspaceTransforms.cs

@ -189,9 +189,9 @@ namespace ImageSharp
float temp2 = (l < 0.5f) ? l * (1f + s) : l + s - (l * s); float temp2 = (l < 0.5f) ? l * (1f + s) : l + s - (l * s);
float temp1 = (2f * l) - temp2; float temp1 = (2f * l) - temp2;
r = GeTPixelComponent(temp1, temp2, rangedH + 0.3333333F); r = GetColorComponent(temp1, temp2, rangedH + 0.3333333F);
g = GeTPixelComponent(temp1, temp2, rangedH); g = GetColorComponent(temp1, temp2, rangedH);
b = GeTPixelComponent(temp1, temp2, rangedH - 0.3333333F); b = GetColorComponent(temp1, temp2, rangedH - 0.3333333F);
} }
} }
@ -241,7 +241,7 @@ namespace ImageSharp
/// <returns> /// <returns>
/// The <see cref="float"/>. /// The <see cref="float"/>.
/// </returns> /// </returns>
private static float GeTPixelComponent(float first, float second, float third) private static float GetColorComponent(float first, float second, float third)
{ {
third = MoveIntoRange(third); third = MoveIntoRange(third);
if (third < 0.1666667F) if (third < 0.1666667F)

2
src/ImageSharp/Colors/RgbaVector.BulkOperations.cs

@ -18,7 +18,7 @@ namespace ImageSharp
public partial struct RgbaVector public partial struct RgbaVector
{ {
/// <summary> /// <summary>
/// <see cref="BulkPixelOperations{TColor}"/> implementation optimized for <see cref="RgbaVector"/>. /// <see cref="BulkPixelOperations{TPixel}"/> implementation optimized for <see cref="RgbaVector"/>.
/// </summary> /// </summary>
internal class BulkOperations : BulkPixelOperations<RgbaVector> internal class BulkOperations : BulkPixelOperations<RgbaVector>
{ {

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

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

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

@ -175,22 +175,22 @@ namespace ImageSharp
/// Finds the bounding rectangle based on the first instance of any color component other /// Finds the bounding rectangle based on the first instance of any color component other
/// than the given one. /// than the given one.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="bitmap">The <see cref="Image"/> to search within.</param> /// <param name="bitmap">The <see cref="Image"/> to search within.</param>
/// <param name="componentValue">The color component value to remove.</param> /// <param name="componentValue">The color component value to remove.</param>
/// <param name="channel">The <see cref="RgbaComponent"/> channel to test against.</param> /// <param name="channel">The <see cref="RgbaComponent"/> channel to test against.</param>
/// <returns> /// <returns>
/// The <see cref="Rectangle"/>. /// The <see cref="Rectangle"/>.
/// </returns> /// </returns>
public static Rectangle GetFilteredBoundingRectangle<TColor>(ImageBase<TColor> bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B) public static Rectangle GetFilteredBoundingRectangle<TPixel>(ImageBase<TPixel> bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
int width = bitmap.Width; int width = bitmap.Width;
int height = bitmap.Height; int height = bitmap.Height;
Point topLeft = default(Point); Point topLeft = default(Point);
Point bottomRight = default(Point); Point bottomRight = default(Point);
Func<PixelAccessor<TColor>, int, int, float, bool> delegateFunc; Func<PixelAccessor<TPixel>, int, int, float, bool> delegateFunc;
// Determine which channel to check against // Determine which channel to check against
switch (channel) switch (channel)
@ -212,7 +212,7 @@ namespace ImageSharp
break; break;
} }
Func<PixelAccessor<TColor>, int> getMinY = pixels => Func<PixelAccessor<TPixel>, int> getMinY = pixels =>
{ {
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
@ -228,7 +228,7 @@ namespace ImageSharp
return 0; return 0;
}; };
Func<PixelAccessor<TColor>, int> getMaxY = pixels => Func<PixelAccessor<TPixel>, int> getMaxY = pixels =>
{ {
for (int y = height - 1; y > -1; y--) for (int y = height - 1; y > -1; y--)
{ {
@ -244,7 +244,7 @@ namespace ImageSharp
return height; return height;
}; };
Func<PixelAccessor<TColor>, int> getMinX = pixels => Func<PixelAccessor<TPixel>, int> getMinX = pixels =>
{ {
for (int x = 0; x < width; x++) for (int x = 0; x < width; x++)
{ {
@ -260,7 +260,7 @@ namespace ImageSharp
return 0; return 0;
}; };
Func<PixelAccessor<TColor>, int> getMaxX = pixels => Func<PixelAccessor<TPixel>, int> getMaxX = pixels =>
{ {
for (int x = width - 1; x > -1; x--) for (int x = width - 1; x > -1; x--)
{ {
@ -276,7 +276,7 @@ namespace ImageSharp
return height; return height;
}; };
using (PixelAccessor<TColor> bitmapPixels = bitmap.Lock()) using (PixelAccessor<TPixel> bitmapPixels = bitmap.Lock())
{ {
topLeft.Y = getMinY(bitmapPixels); topLeft.Y = getMinY(bitmapPixels);
topLeft.X = getMinX(bitmapPixels); topLeft.X = getMinX(bitmapPixels);

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

@ -24,7 +24,7 @@ namespace ImageSharp
/// Rents the pixel array from the pool. /// Rents the pixel array from the pool.
/// </summary> /// </summary>
/// <param name="minimumLength">The minimum length of the array to return.</param> /// <param name="minimumLength">The minimum length of the array to return.</param>
/// <returns>The <see cref="T:TColor[]"/></returns> /// <returns>The <see cref="T:TPixel[]"/></returns>
public static T[] Rent(int minimumLength) public static T[] Rent(int minimumLength)
{ {
return ArrayPool.Rent(minimumLength); return ArrayPool.Rent(minimumLength);

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

@ -68,16 +68,16 @@ namespace ImageSharp.Dithering
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Dither<TColor>(PixelAccessor<TColor> pixels, TColor source, TColor transformed, int x, int y, int width, int height) public void Dither<TPixel>(PixelAccessor<TPixel> pixels, TPixel source, TPixel transformed, int x, int y, int width, int height)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
this.Dither(pixels, source, transformed, x, y, width, height, true); this.Dither(pixels, source, transformed, x, y, width, height, true);
} }
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Dither<TColor>(PixelAccessor<TColor> pixels, TColor source, TColor transformed, int x, int y, int width, int height, bool replacePixel) public void Dither<TPixel>(PixelAccessor<TPixel> pixels, TPixel source, TPixel transformed, int x, int y, int width, int height, bool replacePixel)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
if (replacePixel) if (replacePixel)
{ {
@ -113,7 +113,7 @@ namespace ImageSharp.Dithering
Vector4 result = ((error * coefficientVector) / this.divisorVector) + offsetColor; Vector4 result = ((error * coefficientVector) / this.divisorVector) + offsetColor;
result.W = offsetColor.W; result.W = offsetColor.W;
TColor packed = default(TColor); TPixel packed = default(TPixel);
packed.PackFromVector4(result); packed.PackFromVector4(result);
pixels[matrixX, matrixY] = packed; pixels[matrixX, matrixY] = packed;
} }

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

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

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

@ -23,8 +23,8 @@ namespace ImageSharp.Dithering
/// <param name="y">The row index.</param> /// <param name="y">The row index.</param>
/// <param name="width">The image width.</param> /// <param name="width">The image width.</param>
/// <param name="height">The image height.</param> /// <param name="height">The image height.</param>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
void Dither<TColor>(PixelAccessor<TColor> pixels, TColor source, TColor upper, TColor lower, byte[] bytes, int index, int x, int y, int width, int height) void Dither<TPixel>(PixelAccessor<TPixel> pixels, TPixel source, TPixel upper, TPixel lower, byte[] bytes, int index, int x, int y, int width, int height)
where TColor : struct, IPixel<TColor>; where TPixel : struct, IPixel<TPixel>;
} }
} }

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

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

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

@ -26,13 +26,13 @@ namespace ImageSharp.Formats
public class BmpDecoder : IImageDecoder public class BmpDecoder : IImageDecoder
{ {
/// <inheritdoc/> /// <inheritdoc/>
public Image<TColor> Decode<TColor>(Configuration configuration, Stream stream, IDecoderOptions options) public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream, IDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
Guard.NotNull(stream, "stream"); Guard.NotNull(stream, "stream");
return new BmpDecoderCore(configuration).Decode<TColor>(stream); return new BmpDecoderCore(configuration).Decode<TPixel>(stream);
} }
} }
} }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

8
src/ImageSharp/Formats/IImageDecoder.cs

@ -14,14 +14,14 @@ namespace ImageSharp.Formats
public interface IImageDecoder public interface IImageDecoder
{ {
/// <summary> /// <summary>
/// Decodes the image from the specified stream to the <see cref="ImageBase{TColor}"/>. /// Decodes the image from the specified stream to the <see cref="ImageBase{TPixel}"/>.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="configuration">The configuration for the image.</param> /// <param name="configuration">The configuration for the image.</param>
/// <param name="stream">The <see cref="Stream"/> containing image data.</param> /// <param name="stream">The <see cref="Stream"/> containing image data.</param>
/// <param name="options">The options for the decoder.</param> /// <param name="options">The options for the decoder.</param>
/// <returns>The decoded image</returns> /// <returns>The decoded image</returns>
Image<TColor> Decode<TColor>(Configuration configuration, Stream stream, IDecoderOptions options) Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream, IDecoderOptions options)
where TColor : struct, IPixel<TColor>; where TPixel : struct, IPixel<TPixel>;
} }
} }

10
src/ImageSharp/Formats/IImageEncoder.cs

@ -14,13 +14,13 @@ namespace ImageSharp.Formats
public interface IImageEncoder public interface IImageEncoder
{ {
/// <summary> /// <summary>
/// Encodes the image to the specified stream from the <see cref="Image{TColor}"/>. /// Encodes the image to the specified stream from the <see cref="Image{TPixel}"/>.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="Image{TColor}"/> to encode from.</param> /// <param name="image">The <see cref="Image{TPixel}"/> to encode from.</param>
/// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param> /// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param>
/// <param name="options">The options for the encoder.</param> /// <param name="options">The options for the encoder.</param>
void Encode<TColor>(Image<TColor> image, Stream stream, IEncoderOptions options) void Encode<TPixel>(Image<TPixel> image, Stream stream, IEncoderOptions options)
where TColor : struct, IPixel<TColor>; where TPixel : struct, IPixel<TPixel>;
} }
} }

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

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

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

@ -14,14 +14,14 @@ namespace ImageSharp.Formats
public class JpegDecoder : IImageDecoder public class JpegDecoder : IImageDecoder
{ {
/// <inheritdoc/> /// <inheritdoc/>
public Image<TColor> Decode<TColor>(Configuration configuration, Stream stream, IDecoderOptions options) public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream, IDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
Guard.NotNull(stream, "stream"); Guard.NotNull(stream, "stream");
using (JpegDecoderCore decoder = new JpegDecoderCore(options, configuration)) using (JpegDecoderCore decoder = new JpegDecoderCore(options, configuration))
{ {
return decoder.Decode<TColor>(stream); return decoder.Decode<TPixel>(stream);
} }
} }
} }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

28
src/ImageSharp/Image.Create.cs

@ -12,10 +12,10 @@ namespace ImageSharp
public sealed partial class Image public sealed partial class Image
{ {
/// <summary> /// <summary>
/// Create a new instance of the <see cref="Image{TColor}"/> class /// Create a new instance of the <see cref="Image{TPixel}"/> class
/// with the height and the width of the image. /// with the height and the width of the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="width">The width of the image in pixels.</param> /// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param> /// <param name="height">The height of the image in pixels.</param>
/// <param name="metadata">The images matadata to preload.</param> /// <param name="metadata">The images matadata to preload.</param>
@ -23,38 +23,38 @@ namespace ImageSharp
/// The configuration providing initialization code which allows extending the library. /// The configuration providing initialization code which allows extending the library.
/// </param> /// </param>
/// <returns> /// <returns>
/// A new <see cref="Image{TColor}"/> unless <typeparamref name="TColor"/> is <see cref="Rgba32"/> in which case it returns <see cref="Image" /> /// A new <see cref="Image{TPixel}"/> unless <typeparamref name="TPixel"/> is <see cref="Rgba32"/> in which case it returns <see cref="Image" />
/// </returns> /// </returns>
internal static Image<TColor> Create<TColor>(int width, int height, ImageMetaData metadata, Configuration configuration) internal static Image<TPixel> Create<TPixel>(int width, int height, ImageMetaData metadata, Configuration configuration)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
if (typeof(TColor) == typeof(Rgba32)) if (typeof(TPixel) == typeof(Rgba32))
{ {
return new Image(width, height, metadata, configuration) as Image<TColor>; return new Image(width, height, metadata, configuration) as Image<TPixel>;
} }
else else
{ {
return new Image<TColor>(width, height, metadata, configuration); return new Image<TPixel>(width, height, metadata, configuration);
} }
} }
/// <summary> /// <summary>
/// Create a new instance of the <see cref="Image{TColor}"/> class /// Create a new instance of the <see cref="Image{TPixel}"/> class
/// with the height and the width of the image. /// with the height and the width of the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="width">The width of the image in pixels.</param> /// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param> /// <param name="height">The height of the image in pixels.</param>
/// <param name="configuration"> /// <param name="configuration">
/// The configuration providing initialization code which allows extending the library. /// The configuration providing initialization code which allows extending the library.
/// </param> /// </param>
/// <returns> /// <returns>
/// A new <see cref="Image{TColor}"/> unless <typeparamref name="TColor"/> is <see cref="Rgba32"/> in which case it returns <see cref="Image" /> /// A new <see cref="Image{TPixel}"/> unless <typeparamref name="TPixel"/> is <see cref="Rgba32"/> in which case it returns <see cref="Image" />
/// </returns> /// </returns>
internal static Image<TColor> Create<TColor>(int width, int height, Configuration configuration) internal static Image<TPixel> Create<TPixel>(int width, int height, Configuration configuration)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Image.Create<TColor>(width, height, null, configuration); return Image.Create<TPixel>(width, height, null, configuration);
} }
} }
} }

8
src/ImageSharp/Image.Decode.cs

@ -51,15 +51,15 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Decodes the image stream to the current image. /// Decodes the image stream to the current image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="stream">The stream.</param> /// <param name="stream">The stream.</param>
/// <param name="options">The options for the decoder.</param> /// <param name="options">The options for the decoder.</param>
/// <param name="config">the configuration.</param> /// <param name="config">the configuration.</param>
/// <returns> /// <returns>
/// The decoded image /// The decoded image
/// </returns> /// </returns>
private static Image<TColor> Decode<TColor>(Stream stream, IDecoderOptions options, Configuration config) private static Image<TPixel> Decode<TPixel>(Stream stream, IDecoderOptions options, Configuration config)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
IImageFormat format = DiscoverFormat(stream, config); IImageFormat format = DiscoverFormat(stream, config);
if (format == null) if (format == null)
@ -67,7 +67,7 @@ namespace ImageSharp
return null; return null;
} }
Image<TColor> img = format.Decoder.Decode<TColor>(config, stream, options); Image<TPixel> img = format.Decoder.Decode<TPixel>(config, stream, options);
img.CurrentImageFormat = format; img.CurrentImageFormat = format;
return img; return img;
} }

48
src/ImageSharp/Image.FromBytes.cs

@ -109,70 +109,70 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Loads the image from the given byte array. /// Loads the image from the given byte array.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="data">The byte array containing image data.</param> /// <param name="data">The byte array containing image data.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(byte[] data) public static Image<TPixel> Load<TPixel>(byte[] data)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Load<TColor>(null, data, null); return Load<TPixel>(null, data, null);
} }
/// <summary> /// <summary>
/// Loads the image from the given byte array. /// Loads the image from the given byte array.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="data">The byte array containing image data.</param> /// <param name="data">The byte array containing image data.</param>
/// <param name="options">The options for the decoder.</param> /// <param name="options">The options for the decoder.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(byte[] data, IDecoderOptions options) public static Image<TPixel> Load<TPixel>(byte[] data, IDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Load<TColor>(null, data, options); return Load<TPixel>(null, data, options);
} }
/// <summary> /// <summary>
/// Loads the image from the given byte array. /// Loads the image from the given byte array.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="config">The config for the decoder.</param> /// <param name="config">The config for the decoder.</param>
/// <param name="data">The byte array containing image data.</param> /// <param name="data">The byte array containing image data.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(Configuration config, byte[] data) public static Image<TPixel> Load<TPixel>(Configuration config, byte[] data)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Load<TColor>(config, data, null); return Load<TPixel>(config, data, null);
} }
/// <summary> /// <summary>
/// Loads the image from the given byte array. /// Loads the image from the given byte array.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="data">The byte array containing image data.</param> /// <param name="data">The byte array containing image data.</param>
/// <param name="decoder">The decoder.</param> /// <param name="decoder">The decoder.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(byte[] data, IImageDecoder decoder) public static Image<TPixel> Load<TPixel>(byte[] data, IImageDecoder decoder)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Load<TColor>(data, decoder, null); return Load<TPixel>(data, decoder, null);
} }
/// <summary> /// <summary>
/// Loads the image from the given byte array. /// Loads the image from the given byte array.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="config">The configuration options.</param> /// <param name="config">The configuration options.</param>
/// <param name="data">The byte array containing image data.</param> /// <param name="data">The byte array containing image data.</param>
/// <param name="options">The options for the decoder.</param> /// <param name="options">The options for the decoder.</param>
@ -180,19 +180,19 @@ namespace ImageSharp
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(Configuration config, byte[] data, IDecoderOptions options) public static Image<TPixel> Load<TPixel>(Configuration config, byte[] data, IDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
using (MemoryStream ms = new MemoryStream(data)) using (MemoryStream ms = new MemoryStream(data))
{ {
return Load<TColor>(config, ms, options); return Load<TPixel>(config, ms, options);
} }
} }
/// <summary> /// <summary>
/// Loads the image from the given byte array. /// Loads the image from the given byte array.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="data">The byte array containing image data.</param> /// <param name="data">The byte array containing image data.</param>
/// <param name="decoder">The decoder.</param> /// <param name="decoder">The decoder.</param>
/// <param name="options">The options for the decoder.</param> /// <param name="options">The options for the decoder.</param>
@ -200,12 +200,12 @@ namespace ImageSharp
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(byte[] data, IImageDecoder decoder, IDecoderOptions options) public static Image<TPixel> Load<TPixel>(byte[] data, IImageDecoder decoder, IDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
using (MemoryStream ms = new MemoryStream(data)) using (MemoryStream ms = new MemoryStream(data))
{ {
return Load<TColor>(ms, decoder, options); return Load<TPixel>(ms, decoder, options);
} }
} }
} }

48
src/ImageSharp/Image.FromFile.cs

@ -108,70 +108,70 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Loads the image from the given file. /// Loads the image from the given file.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="path">The file path to the image.</param> /// <param name="path">The file path to the image.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(string path) public static Image<TPixel> Load<TPixel>(string path)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Load<TColor>(null, path, null); return Load<TPixel>(null, path, null);
} }
/// <summary> /// <summary>
/// Loads the image from the given file. /// Loads the image from the given file.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="path">The file path to the image.</param> /// <param name="path">The file path to the image.</param>
/// <param name="options">The options for the decoder.</param> /// <param name="options">The options for the decoder.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(string path, IDecoderOptions options) public static Image<TPixel> Load<TPixel>(string path, IDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Load<TColor>(null, path, options); return Load<TPixel>(null, path, options);
} }
/// <summary> /// <summary>
/// Loads the image from the given file. /// Loads the image from the given file.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="config">The config for the decoder.</param> /// <param name="config">The config for the decoder.</param>
/// <param name="path">The file path to the image.</param> /// <param name="path">The file path to the image.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(Configuration config, string path) public static Image<TPixel> Load<TPixel>(Configuration config, string path)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Load<TColor>(config, path, null); return Load<TPixel>(config, path, null);
} }
/// <summary> /// <summary>
/// Loads the image from the given file. /// Loads the image from the given file.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="path">The file path to the image.</param> /// <param name="path">The file path to the image.</param>
/// <param name="decoder">The decoder.</param> /// <param name="decoder">The decoder.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(string path, IImageDecoder decoder) public static Image<TPixel> Load<TPixel>(string path, IImageDecoder decoder)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Load<TColor>(path, decoder, null); return Load<TPixel>(path, decoder, null);
} }
/// <summary> /// <summary>
/// Loads the image from the given file. /// Loads the image from the given file.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="config">The configuration options.</param> /// <param name="config">The configuration options.</param>
/// <param name="path">The file path to the image.</param> /// <param name="path">The file path to the image.</param>
/// <param name="options">The options for the decoder.</param> /// <param name="options">The options for the decoder.</param>
@ -179,20 +179,20 @@ namespace ImageSharp
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(Configuration config, string path, IDecoderOptions options) public static Image<TPixel> Load<TPixel>(Configuration config, string path, IDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
config = config ?? Configuration.Default; config = config ?? Configuration.Default;
using (Stream s = config.FileSystem.OpenRead(path)) using (Stream s = config.FileSystem.OpenRead(path))
{ {
return Load<TColor>(config, s, options); return Load<TPixel>(config, s, options);
} }
} }
/// <summary> /// <summary>
/// Loads the image from the given file. /// Loads the image from the given file.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="path">The file path to the image.</param> /// <param name="path">The file path to the image.</param>
/// <param name="decoder">The decoder.</param> /// <param name="decoder">The decoder.</param>
/// <param name="options">The options for the decoder.</param> /// <param name="options">The options for the decoder.</param>
@ -200,13 +200,13 @@ namespace ImageSharp
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(string path, IImageDecoder decoder, IDecoderOptions options) public static Image<TPixel> Load<TPixel>(string path, IImageDecoder decoder, IDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
Configuration config = Configuration.Default; Configuration config = Configuration.Default;
using (Stream s = config.FileSystem.OpenRead(path)) using (Stream s = config.FileSystem.OpenRead(path))
{ {
return Load<TColor>(s, decoder, options); return Load<TPixel>(s, decoder, options);
} }
} }
} }

48
src/ImageSharp/Image.FromStream.cs

@ -108,70 +108,70 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Loads the image from the given stream. /// Loads the image from the given stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="stream">The stream containing image information.</param> /// <param name="stream">The stream containing image information.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(Stream stream) public static Image<TPixel> Load<TPixel>(Stream stream)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Load<TColor>(null, stream, null); return Load<TPixel>(null, stream, null);
} }
/// <summary> /// <summary>
/// Loads the image from the given stream. /// Loads the image from the given stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="stream">The stream containing image information.</param> /// <param name="stream">The stream containing image information.</param>
/// <param name="options">The options for the decoder.</param> /// <param name="options">The options for the decoder.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(Stream stream, IDecoderOptions options) public static Image<TPixel> Load<TPixel>(Stream stream, IDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Load<TColor>(null, stream, options); return Load<TPixel>(null, stream, options);
} }
/// <summary> /// <summary>
/// Loads the image from the given stream. /// Loads the image from the given stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="config">The config for the decoder.</param> /// <param name="config">The config for the decoder.</param>
/// <param name="stream">The stream containing image information.</param> /// <param name="stream">The stream containing image information.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(Configuration config, Stream stream) public static Image<TPixel> Load<TPixel>(Configuration config, Stream stream)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Load<TColor>(config, stream, null); return Load<TPixel>(config, stream, null);
} }
/// <summary> /// <summary>
/// Loads the image from the given stream. /// Loads the image from the given stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="stream">The stream containing image information.</param> /// <param name="stream">The stream containing image information.</param>
/// <param name="decoder">The decoder.</param> /// <param name="decoder">The decoder.</param>
/// <exception cref="NotSupportedException"> /// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(Stream stream, IImageDecoder decoder) public static Image<TPixel> Load<TPixel>(Stream stream, IImageDecoder decoder)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Load<TColor>(stream, decoder, null); return Load<TPixel>(stream, decoder, null);
} }
/// <summary> /// <summary>
/// Loads the image from the given stream. /// Loads the image from the given stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="stream">The stream containing image information.</param> /// <param name="stream">The stream containing image information.</param>
/// <param name="decoder">The decoder.</param> /// <param name="decoder">The decoder.</param>
/// <param name="options">The options for the decoder.</param> /// <param name="options">The options for the decoder.</param>
@ -179,16 +179,16 @@ namespace ImageSharp
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(Stream stream, IImageDecoder decoder, IDecoderOptions options) public static Image<TPixel> Load<TPixel>(Stream stream, IImageDecoder decoder, IDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return WithSeekableStream(stream, s => decoder.Decode<TColor>(Configuration.Default, s, options)); return WithSeekableStream(stream, s => decoder.Decode<TPixel>(Configuration.Default, s, options));
} }
/// <summary> /// <summary>
/// Loads the image from the given stream. /// Loads the image from the given stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="config">The configuration options.</param> /// <param name="config">The configuration options.</param>
/// <param name="stream">The stream containing image information.</param> /// <param name="stream">The stream containing image information.</param>
/// <param name="options">The options for the decoder.</param> /// <param name="options">The options for the decoder.</param>
@ -196,12 +196,12 @@ namespace ImageSharp
/// Thrown if the stream is not readable nor seekable. /// Thrown if the stream is not readable nor seekable.
/// </exception> /// </exception>
/// <returns>The image</returns> /// <returns>The image</returns>
public static Image<TColor> Load<TColor>(Configuration config, Stream stream, IDecoderOptions options) public static Image<TPixel> Load<TPixel>(Configuration config, Stream stream, IDecoderOptions options)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
config = config ?? Configuration.Default; config = config ?? Configuration.Default;
Image<TColor> img = WithSeekableStream(stream, s => Decode<TColor>(s, options, config)); Image<TPixel> img = WithSeekableStream(stream, s => Decode<TPixel>(s, options, config));
if (img != null) if (img != null)
{ {

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

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

10
src/ImageSharp/Image/IImageProcessor.cs

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

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

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

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

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

11
src/ImageSharp/Image/ImageProcessingExtensions.cs

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

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

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

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

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

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

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

16
src/ImageSharp/ImageProcessor.cs

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

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

@ -116,12 +116,12 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Returns the thumbnail in the EXIF profile when available. /// Returns the thumbnail in the EXIF profile when available.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns> /// <returns>
/// The <see cref="Image{TColor}"/>. /// The <see cref="Image{TPixel}"/>.
/// </returns> /// </returns>
public Image<TColor> CreateThumbnail<TColor>() public Image<TPixel> CreateThumbnail<TPixel>()
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
this.InitializeValues(); this.InitializeValues();
@ -137,7 +137,7 @@ namespace ImageSharp
using (MemoryStream memStream = new MemoryStream(this.data, this.thumbnailOffset, this.thumbnailLength)) using (MemoryStream memStream = new MemoryStream(this.data, this.thumbnailOffset, this.thumbnailLength))
{ {
return Image.Load<TColor>(memStream); return Image.Load<TPixel>(memStream);
} }
} }

20
src/ImageSharp/Processing/Binarization/BinaryThreshold.cs

@ -10,19 +10,19 @@ namespace ImageSharp
using Processing.Processors; using Processing.Processors;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Applies binarization to the image splitting the pixels at the given threshold. /// Applies binarization to the image splitting the pixels at the given threshold.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param> /// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> BinaryThreshold<TColor>(this Image<TColor> source, float threshold) public static Image<TPixel> BinaryThreshold<TPixel>(this Image<TPixel> source, float threshold)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return BinaryThreshold(source, threshold, source.Bounds); return BinaryThreshold(source, threshold, source.Bounds);
} }
@ -30,17 +30,17 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Applies binarization to the image splitting the pixels at the given threshold. /// Applies binarization to the image splitting the pixels at the given threshold.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param> /// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param>
/// <param name="rectangle"> /// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param> /// </param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> BinaryThreshold<TColor>(this Image<TColor> source, float threshold, Rectangle rectangle) public static Image<TPixel> BinaryThreshold<TPixel>(this Image<TPixel> source, float threshold, Rectangle rectangle)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
source.ApplyProcessor(new BinaryThresholdProcessor<TColor>(threshold), rectangle); source.ApplyProcessor(new BinaryThresholdProcessor<TPixel>(threshold), rectangle);
return source; return source;
} }
} }

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

@ -18,13 +18,13 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Dithers the image reducing it to two colors using ordered dithering. /// Dithers the image reducing it to two colors using ordered dithering.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="dither">The ordered ditherer.</param> /// <param name="dither">The ordered ditherer.</param>
/// <param name="index">The component index to test the threshold against. Must range from 0 to 3.</param> /// <param name="index">The component index to test the threshold against. Must range from 0 to 3.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Dither<TColor>(this Image<TColor> source, IOrderedDither dither, int index = 0) public static Image<TPixel> Dither<TPixel>(this Image<TPixel> source, IOrderedDither dither, int index = 0)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Dither(source, dither, source.Bounds, index); return Dither(source, dither, source.Bounds, index);
} }
@ -32,7 +32,7 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Dithers the image reducing it to two colors using ordered dithering. /// Dithers the image reducing it to two colors using ordered dithering.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="dither">The ordered ditherer.</param> /// <param name="dither">The ordered ditherer.</param>
/// <param name="rectangle"> /// <param name="rectangle">
@ -40,23 +40,23 @@ namespace ImageSharp
/// </param> /// </param>
/// <param name="index">The component index to test the threshold against. Must range from 0 to 3.</param> /// <param name="index">The component index to test the threshold against. Must range from 0 to 3.</param>
/// <returns>The <see cref="Image"/>.</returns> /// <returns>The <see cref="Image"/>.</returns>
public static Image<TColor> Dither<TColor>(this Image<TColor> source, IOrderedDither dither, Rectangle rectangle, int index = 0) public static Image<TPixel> Dither<TPixel>(this Image<TPixel> source, IOrderedDither dither, Rectangle rectangle, int index = 0)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
source.ApplyProcessor(new OrderedDitherProcessor<TColor>(dither, index), rectangle); source.ApplyProcessor(new OrderedDitherProcessor<TPixel>(dither, index), rectangle);
return source; return source;
} }
/// <summary> /// <summary>
/// Dithers the image reducing it to two colors using error diffusion. /// Dithers the image reducing it to two colors using error diffusion.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="diffuser">The diffusion algorithm to apply.</param> /// <param name="diffuser">The diffusion algorithm to apply.</param>
/// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param> /// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Dither<TColor>(this Image<TColor> source, IErrorDiffuser diffuser, float threshold) public static Image<TPixel> Dither<TPixel>(this Image<TPixel> source, IErrorDiffuser diffuser, float threshold)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Dither(source, diffuser, threshold, source.Bounds); return Dither(source, diffuser, threshold, source.Bounds);
} }
@ -64,7 +64,7 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Dithers the image reducing it to two colors using error diffusion. /// Dithers the image reducing it to two colors using error diffusion.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="diffuser">The diffusion algorithm to apply.</param> /// <param name="diffuser">The diffusion algorithm to apply.</param>
/// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param> /// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param>
@ -72,10 +72,10 @@ namespace ImageSharp
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param> /// </param>
/// <returns>The <see cref="Image"/>.</returns> /// <returns>The <see cref="Image"/>.</returns>
public static Image<TColor> Dither<TColor>(this Image<TColor> source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle) public static Image<TPixel> Dither<TPixel>(this Image<TPixel> source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
source.ApplyProcessor(new ErrorDiffusionDitherProcessor<TColor>(diffuser, threshold), rectangle); source.ApplyProcessor(new ErrorDiffusionDitherProcessor<TPixel>(diffuser, threshold), rectangle);
return source; return source;
} }
} }

20
src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs

@ -11,18 +11,18 @@ namespace ImageSharp
using Processing.Processors; using Processing.Processors;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Applies black and white toning to the image. /// Applies black and white toning to the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> BlackWhite<TColor>(this Image<TColor> source) public static Image<TPixel> BlackWhite<TPixel>(this Image<TPixel> source)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return BlackWhite(source, source.Bounds); return BlackWhite(source, source.Bounds);
} }
@ -30,16 +30,16 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Applies black and white toning to the image. /// Applies black and white toning to the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="rectangle"> /// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param> /// </param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> BlackWhite<TColor>(this Image<TColor> source, Rectangle rectangle) public static Image<TPixel> BlackWhite<TPixel>(this Image<TPixel> source, Rectangle rectangle)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
source.ApplyProcessor(new BlackWhiteProcessor<TColor>(), rectangle); source.ApplyProcessor(new BlackWhiteProcessor<TPixel>(), rectangle);
return source; return source;
} }
} }

36
src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs

@ -11,19 +11,19 @@ namespace ImageSharp
using Processing.Processors; using Processing.Processors;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Applies the given colorblindness simulator to the image. /// Applies the given colorblindness simulator to the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="colorBlindness">The type of color blindness simulator to apply.</param> /// <param name="colorBlindness">The type of color blindness simulator to apply.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> ColorBlindness<TColor>(this Image<TColor> source, ColorBlindness colorBlindness) public static Image<TPixel> ColorBlindness<TPixel>(this Image<TPixel> source, ColorBlindness colorBlindness)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return ColorBlindness(source, colorBlindness, source.Bounds); return ColorBlindness(source, colorBlindness, source.Bounds);
} }
@ -31,50 +31,50 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Applies the given colorblindness simulator to the image. /// Applies the given colorblindness simulator to the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="colorBlindness">The type of color blindness simulator to apply.</param> /// <param name="colorBlindness">The type of color blindness simulator to apply.</param>
/// <param name="rectangle"> /// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param> /// </param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> ColorBlindness<TColor>(this Image<TColor> source, ColorBlindness colorBlindness, Rectangle rectangle) public static Image<TPixel> ColorBlindness<TPixel>(this Image<TPixel> source, ColorBlindness colorBlindness, Rectangle rectangle)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
IImageProcessor<TColor> processor; IImageProcessor<TPixel> processor;
switch (colorBlindness) switch (colorBlindness)
{ {
case ImageSharp.Processing.ColorBlindness.Achromatomaly: case ImageSharp.Processing.ColorBlindness.Achromatomaly:
processor = new AchromatomalyProcessor<TColor>(); processor = new AchromatomalyProcessor<TPixel>();
break; break;
case ImageSharp.Processing.ColorBlindness.Achromatopsia: case ImageSharp.Processing.ColorBlindness.Achromatopsia:
processor = new AchromatopsiaProcessor<TColor>(); processor = new AchromatopsiaProcessor<TPixel>();
break; break;
case ImageSharp.Processing.ColorBlindness.Deuteranomaly: case ImageSharp.Processing.ColorBlindness.Deuteranomaly:
processor = new DeuteranomalyProcessor<TColor>(); processor = new DeuteranomalyProcessor<TPixel>();
break; break;
case ImageSharp.Processing.ColorBlindness.Deuteranopia: case ImageSharp.Processing.ColorBlindness.Deuteranopia:
processor = new DeuteranopiaProcessor<TColor>(); processor = new DeuteranopiaProcessor<TPixel>();
break; break;
case ImageSharp.Processing.ColorBlindness.Protanomaly: case ImageSharp.Processing.ColorBlindness.Protanomaly:
processor = new ProtanomalyProcessor<TColor>(); processor = new ProtanomalyProcessor<TPixel>();
break; break;
case ImageSharp.Processing.ColorBlindness.Protanopia: case ImageSharp.Processing.ColorBlindness.Protanopia:
processor = new ProtanopiaProcessor<TColor>(); processor = new ProtanopiaProcessor<TPixel>();
break; break;
case ImageSharp.Processing.ColorBlindness.Tritanomaly: case ImageSharp.Processing.ColorBlindness.Tritanomaly:
processor = new TritanomalyProcessor<TColor>(); processor = new TritanomalyProcessor<TPixel>();
break; break;
default: default:
processor = new TritanopiaProcessor<TColor>(); processor = new TritanopiaProcessor<TPixel>();
break; break;
} }

24
src/ImageSharp/Processing/ColorMatrix/Grayscale.cs

@ -11,19 +11,19 @@ namespace ImageSharp
using Processing.Processors; using Processing.Processors;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Applies Grayscale toning to the image. /// Applies Grayscale toning to the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="mode">The formula to apply to perform the operation.</param> /// <param name="mode">The formula to apply to perform the operation.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Grayscale<TColor>(this Image<TColor> source, GrayscaleMode mode = GrayscaleMode.Bt709) public static Image<TPixel> Grayscale<TPixel>(this Image<TPixel> source, GrayscaleMode mode = GrayscaleMode.Bt709)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Grayscale(source, source.Bounds, mode); return Grayscale(source, source.Bounds, mode);
} }
@ -31,19 +31,19 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Applies Grayscale toning to the image. /// Applies Grayscale toning to the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="rectangle"> /// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param> /// </param>
/// <param name="mode">The formula to apply to perform the operation.</param> /// <param name="mode">The formula to apply to perform the operation.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Grayscale<TColor>(this Image<TColor> source, Rectangle rectangle, GrayscaleMode mode = GrayscaleMode.Bt709) public static Image<TPixel> Grayscale<TPixel>(this Image<TPixel> source, Rectangle rectangle, GrayscaleMode mode = GrayscaleMode.Bt709)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
IImageProcessor<TColor> processor = mode == GrayscaleMode.Bt709 IImageProcessor<TPixel> processor = mode == GrayscaleMode.Bt709
? (IImageProcessor<TColor>)new GrayscaleBt709Processor<TColor>() ? (IImageProcessor<TPixel>)new GrayscaleBt709Processor<TPixel>()
: new GrayscaleBt601Processor<TColor>(); : new GrayscaleBt601Processor<TPixel>();
source.ApplyProcessor(processor, rectangle); source.ApplyProcessor(processor, rectangle);
return source; return source;

20
src/ImageSharp/Processing/ColorMatrix/Hue.cs

@ -11,19 +11,19 @@ namespace ImageSharp
using Processing.Processors; using Processing.Processors;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Alters the hue component of the image. /// Alters the hue component of the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="degrees">The angle in degrees to adjust the image.</param> /// <param name="degrees">The angle in degrees to adjust the image.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Hue<TColor>(this Image<TColor> source, float degrees) public static Image<TPixel> Hue<TPixel>(this Image<TPixel> source, float degrees)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Hue(source, degrees, source.Bounds); return Hue(source, degrees, source.Bounds);
} }
@ -31,17 +31,17 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Alters the hue component of the image. /// Alters the hue component of the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="degrees">The angle in degrees to adjust the image.</param> /// <param name="degrees">The angle in degrees to adjust the image.</param>
/// <param name="rectangle"> /// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param> /// </param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Hue<TColor>(this Image<TColor> source, float degrees, Rectangle rectangle) public static Image<TPixel> Hue<TPixel>(this Image<TPixel> source, float degrees, Rectangle rectangle)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
source.ApplyProcessor(new HueProcessor<TColor>(degrees), rectangle); source.ApplyProcessor(new HueProcessor<TPixel>(degrees), rectangle);
return source; return source;
} }
} }

20
src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs

@ -11,18 +11,18 @@ namespace ImageSharp
using Processing.Processors; using Processing.Processors;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Alters the colors of the image recreating an old Kodachrome camera effect. /// Alters the colors of the image recreating an old Kodachrome camera effect.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Kodachrome<TColor>(this Image<TColor> source) public static Image<TPixel> Kodachrome<TPixel>(this Image<TPixel> source)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Kodachrome(source, source.Bounds); return Kodachrome(source, source.Bounds);
} }
@ -30,16 +30,16 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Alters the colors of the image recreating an old Kodachrome camera effect. /// Alters the colors of the image recreating an old Kodachrome camera effect.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="rectangle"> /// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param> /// </param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Kodachrome<TColor>(this Image<TColor> source, Rectangle rectangle) public static Image<TPixel> Kodachrome<TPixel>(this Image<TPixel> source, Rectangle rectangle)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
source.ApplyProcessor(new KodachromeProcessor<TColor>(), rectangle); source.ApplyProcessor(new KodachromeProcessor<TPixel>(), rectangle);
return source; return source;
} }
} }

20
src/ImageSharp/Processing/ColorMatrix/Lomograph.cs

@ -11,18 +11,18 @@ namespace ImageSharp
using Processing.Processors; using Processing.Processors;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Alters the colors of the image recreating an old Lomograph camera effect. /// Alters the colors of the image recreating an old Lomograph camera effect.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Lomograph<TColor>(this Image<TColor> source) public static Image<TPixel> Lomograph<TPixel>(this Image<TPixel> source)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Lomograph(source, source.Bounds); return Lomograph(source, source.Bounds);
} }
@ -30,16 +30,16 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Alters the colors of the image recreating an old Lomograph camera effect. /// Alters the colors of the image recreating an old Lomograph camera effect.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="rectangle"> /// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param> /// </param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Lomograph<TColor>(this Image<TColor> source, Rectangle rectangle) public static Image<TPixel> Lomograph<TPixel>(this Image<TPixel> source, Rectangle rectangle)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
source.ApplyProcessor(new LomographProcessor<TColor>(), rectangle); source.ApplyProcessor(new LomographProcessor<TPixel>(), rectangle);
return source; return source;
} }
} }

20
src/ImageSharp/Processing/ColorMatrix/Polaroid.cs

@ -11,18 +11,18 @@ namespace ImageSharp
using Processing.Processors; using Processing.Processors;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Alters the colors of the image recreating an old Polaroid camera effect. /// Alters the colors of the image recreating an old Polaroid camera effect.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Polaroid<TColor>(this Image<TColor> source) public static Image<TPixel> Polaroid<TPixel>(this Image<TPixel> source)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Polaroid(source, source.Bounds); return Polaroid(source, source.Bounds);
} }
@ -30,16 +30,16 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Alters the colors of the image recreating an old Polaroid camera effect. /// Alters the colors of the image recreating an old Polaroid camera effect.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="rectangle"> /// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param> /// </param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Polaroid<TColor>(this Image<TColor> source, Rectangle rectangle) public static Image<TPixel> Polaroid<TPixel>(this Image<TPixel> source, Rectangle rectangle)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
source.ApplyProcessor(new PolaroidProcessor<TColor>(), rectangle); source.ApplyProcessor(new PolaroidProcessor<TPixel>(), rectangle);
return source; return source;
} }
} }

20
src/ImageSharp/Processing/ColorMatrix/Saturation.cs

@ -11,19 +11,19 @@ namespace ImageSharp
using Processing.Processors; using Processing.Processors;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Alters the saturation component of the image. /// Alters the saturation component of the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="amount">The new saturation of the image. Must be between -100 and 100.</param> /// <param name="amount">The new saturation of the image. Must be between -100 and 100.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Saturation<TColor>(this Image<TColor> source, int amount) public static Image<TPixel> Saturation<TPixel>(this Image<TPixel> source, int amount)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Saturation(source, amount, source.Bounds); return Saturation(source, amount, source.Bounds);
} }
@ -31,17 +31,17 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Alters the saturation component of the image. /// Alters the saturation component of the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="amount">The new saturation of the image. Must be between -100 and 100.</param> /// <param name="amount">The new saturation of the image. Must be between -100 and 100.</param>
/// <param name="rectangle"> /// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param> /// </param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> Saturation<TColor>(this Image<TColor> source, int amount, Rectangle rectangle) public static Image<TPixel> Saturation<TPixel>(this Image<TPixel> source, int amount, Rectangle rectangle)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
source.ApplyProcessor(new SaturationProcessor<TColor>(amount), rectangle); source.ApplyProcessor(new SaturationProcessor<TPixel>(amount), rectangle);
return source; return source;
} }
} }

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

@ -11,18 +11,18 @@ namespace ImageSharp
using Processing.Processors; using Processing.Processors;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Applies sepia toning to the image. /// Applies sepia toning to the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image"/>.</returns> /// <returns>The <see cref="Image"/>.</returns>
public static Image<TColor> Sepia<TColor>(this Image<TColor> source) public static Image<TPixel> Sepia<TPixel>(this Image<TPixel> source)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return Sepia(source, source.Bounds); return Sepia(source, source.Bounds);
} }
@ -30,16 +30,16 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Applies sepia toning to the image. /// Applies sepia toning to the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="rectangle"> /// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param> /// </param>
/// <returns>The <see cref="Image"/>.</returns> /// <returns>The <see cref="Image"/>.</returns>
public static Image<TColor> Sepia<TColor>(this Image<TColor> source, Rectangle rectangle) public static Image<TPixel> Sepia<TPixel>(this Image<TPixel> source, Rectangle rectangle)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
source.ApplyProcessor(new SepiaProcessor<TColor>(), rectangle); source.ApplyProcessor(new SepiaProcessor<TPixel>(), rectangle);
return source; return source;
} }
} }

20
src/ImageSharp/Processing/Convolution/BoxBlur.cs

@ -10,19 +10,19 @@ namespace ImageSharp
using Processing.Processors; using Processing.Processors;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Applies a box blur to the image. /// Applies a box blur to the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="radius">The 'radius' value representing the size of the area to sample.</param> /// <param name="radius">The 'radius' value representing the size of the area to sample.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> BoxBlur<TColor>(this Image<TColor> source, int radius = 7) public static Image<TPixel> BoxBlur<TPixel>(this Image<TPixel> source, int radius = 7)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return BoxBlur(source, radius, source.Bounds); return BoxBlur(source, radius, source.Bounds);
} }
@ -30,17 +30,17 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Applies a box blur to the image. /// Applies a box blur to the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="radius">The 'radius' value representing the size of the area to sample.</param> /// <param name="radius">The 'radius' value representing the size of the area to sample.</param>
/// <param name="rectangle"> /// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param> /// </param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> BoxBlur<TColor>(this Image<TColor> source, int radius, Rectangle rectangle) public static Image<TPixel> BoxBlur<TPixel>(this Image<TPixel> source, int radius, Rectangle rectangle)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
source.ApplyProcessor(new BoxBlurProcessor<TColor>(radius), rectangle); source.ApplyProcessor(new BoxBlurProcessor<TPixel>(radius), rectangle);
return source; return source;
} }
} }

80
src/ImageSharp/Processing/Convolution/DetectEdges.cs

@ -11,49 +11,49 @@ namespace ImageSharp
using Processing.Processors; using Processing.Processors;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Detects any edges within the image. Uses the <see cref="SobelProcessor{TColor}"/> filter /// Detects any edges within the image. Uses the <see cref="SobelProcessor{TPixel}"/> filter
/// operating in Grayscale mode. /// operating in Grayscale mode.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> DetectEdges<TColor>(this Image<TColor> source) public static Image<TPixel> DetectEdges<TPixel>(this Image<TPixel> source)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return DetectEdges(source, source.Bounds, new SobelProcessor<TColor> { Grayscale = true }); return DetectEdges(source, source.Bounds, new SobelProcessor<TPixel> { Grayscale = true });
} }
/// <summary> /// <summary>
/// Detects any edges within the image. Uses the <see cref="SobelProcessor{TColor}"/> filter /// Detects any edges within the image. Uses the <see cref="SobelProcessor{TPixel}"/> filter
/// operating in Grayscale mode. /// operating in Grayscale mode.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="rectangle"> /// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param> /// </param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> DetectEdges<TColor>(this Image<TColor> source, Rectangle rectangle) public static Image<TPixel> DetectEdges<TPixel>(this Image<TPixel> source, Rectangle rectangle)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return DetectEdges(source, rectangle, new SobelProcessor<TColor> { Grayscale = true }); return DetectEdges(source, rectangle, new SobelProcessor<TPixel> { Grayscale = true });
} }
/// <summary> /// <summary>
/// Detects any edges within the image. /// Detects any edges within the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="filter">The filter for detecting edges.</param> /// <param name="filter">The filter for detecting edges.</param>
/// <param name="grayscale">Whether to convert the image to Grayscale first. Defaults to true.</param> /// <param name="grayscale">Whether to convert the image to Grayscale first. Defaults to true.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> DetectEdges<TColor>(this Image<TColor> source, EdgeDetection filter, bool grayscale = true) public static Image<TPixel> DetectEdges<TPixel>(this Image<TPixel> source, EdgeDetection filter, bool grayscale = true)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return DetectEdges(source, filter, source.Bounds, grayscale); return DetectEdges(source, filter, source.Bounds, grayscale);
} }
@ -61,59 +61,59 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Detects any edges within the image. /// Detects any edges within the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="filter">The filter for detecting edges.</param> /// <param name="filter">The filter for detecting edges.</param>
/// <param name="rectangle"> /// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param> /// </param>
/// <param name="grayscale">Whether to convert the image to Grayscale first. Defaults to true.</param> /// <param name="grayscale">Whether to convert the image to Grayscale first. Defaults to true.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> DetectEdges<TColor>(this Image<TColor> source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true) public static Image<TPixel> DetectEdges<TPixel>(this Image<TPixel> source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
IEdgeDetectorProcessor<TColor> processor; IEdgeDetectorProcessor<TPixel> processor;
switch (filter) switch (filter)
{ {
case EdgeDetection.Kayyali: case EdgeDetection.Kayyali:
processor = new KayyaliProcessor<TColor> { Grayscale = grayscale }; processor = new KayyaliProcessor<TPixel> { Grayscale = grayscale };
break; break;
case EdgeDetection.Kirsch: case EdgeDetection.Kirsch:
processor = new KirschProcessor<TColor> { Grayscale = grayscale }; processor = new KirschProcessor<TPixel> { Grayscale = grayscale };
break; break;
case EdgeDetection.Lapacian3X3: case EdgeDetection.Lapacian3X3:
processor = new Laplacian3X3Processor<TColor> { Grayscale = grayscale }; processor = new Laplacian3X3Processor<TPixel> { Grayscale = grayscale };
break; break;
case EdgeDetection.Lapacian5X5: case EdgeDetection.Lapacian5X5:
processor = new Laplacian5X5Processor<TColor> { Grayscale = grayscale }; processor = new Laplacian5X5Processor<TPixel> { Grayscale = grayscale };
break; break;
case EdgeDetection.LaplacianOfGaussian: case EdgeDetection.LaplacianOfGaussian:
processor = new LaplacianOfGaussianProcessor<TColor> { Grayscale = grayscale }; processor = new LaplacianOfGaussianProcessor<TPixel> { Grayscale = grayscale };
break; break;
case EdgeDetection.Prewitt: case EdgeDetection.Prewitt:
processor = new PrewittProcessor<TColor> { Grayscale = grayscale }; processor = new PrewittProcessor<TPixel> { Grayscale = grayscale };
break; break;
case EdgeDetection.RobertsCross: case EdgeDetection.RobertsCross:
processor = new RobertsCrossProcessor<TColor> { Grayscale = grayscale }; processor = new RobertsCrossProcessor<TPixel> { Grayscale = grayscale };
break; break;
case EdgeDetection.Robinson: case EdgeDetection.Robinson:
processor = new RobinsonProcessor<TColor> { Grayscale = grayscale }; processor = new RobinsonProcessor<TPixel> { Grayscale = grayscale };
break; break;
case EdgeDetection.Scharr: case EdgeDetection.Scharr:
processor = new ScharrProcessor<TColor> { Grayscale = grayscale }; processor = new ScharrProcessor<TPixel> { Grayscale = grayscale };
break; break;
default: default:
processor = new SobelProcessor<TColor> { Grayscale = grayscale }; processor = new SobelProcessor<TPixel> { Grayscale = grayscale };
break; break;
} }
@ -123,12 +123,12 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Detects any edges within the image. /// Detects any edges within the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="filter">The filter for detecting edges.</param> /// <param name="filter">The filter for detecting edges.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> DetectEdges<TColor>(this Image<TColor> source, IEdgeDetectorProcessor<TColor> filter) public static Image<TPixel> DetectEdges<TPixel>(this Image<TPixel> source, IEdgeDetectorProcessor<TPixel> filter)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return DetectEdges(source, source.Bounds, filter); return DetectEdges(source, source.Bounds, filter);
} }
@ -136,15 +136,15 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Detects any edges within the image. /// Detects any edges within the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="rectangle"> /// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param> /// </param>
/// <param name="filter">The filter for detecting edges.</param> /// <param name="filter">The filter for detecting edges.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> DetectEdges<TColor>(this Image<TColor> source, Rectangle rectangle, IEdgeDetectorProcessor<TColor> filter) public static Image<TPixel> DetectEdges<TPixel>(this Image<TPixel> source, Rectangle rectangle, IEdgeDetectorProcessor<TPixel> filter)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
source.ApplyProcessor(filter, rectangle); source.ApplyProcessor(filter, rectangle);
return source; return source;

20
src/ImageSharp/Processing/Convolution/GaussianBlur.cs

@ -11,19 +11,19 @@ namespace ImageSharp
using Processing.Processors; using Processing.Processors;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Applies a Gaussian blur to the image. /// Applies a Gaussian blur to the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param> /// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> GaussianBlur<TColor>(this Image<TColor> source, float sigma = 3f) public static Image<TPixel> GaussianBlur<TPixel>(this Image<TPixel> source, float sigma = 3f)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return GaussianBlur(source, sigma, source.Bounds); return GaussianBlur(source, sigma, source.Bounds);
} }
@ -31,17 +31,17 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Applies a Gaussian blur to the image. /// Applies a Gaussian blur to the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param> /// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
/// <param name="rectangle"> /// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param> /// </param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> GaussianBlur<TColor>(this Image<TColor> source, float sigma, Rectangle rectangle) public static Image<TPixel> GaussianBlur<TPixel>(this Image<TPixel> source, float sigma, Rectangle rectangle)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
source.ApplyProcessor(new GaussianBlurProcessor<TColor>(sigma), rectangle); source.ApplyProcessor(new GaussianBlurProcessor<TPixel>(sigma), rectangle);
return source; return source;
} }
} }

20
src/ImageSharp/Processing/Convolution/GaussianSharpen.cs

@ -11,19 +11,19 @@ namespace ImageSharp
using Processing.Processors; using Processing.Processors;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type. /// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Applies a Gaussian sharpening filter to the image. /// Applies a Gaussian sharpening filter to the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param> /// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> GaussianSharpen<TColor>(this Image<TColor> source, float sigma = 3f) public static Image<TPixel> GaussianSharpen<TPixel>(this Image<TPixel> source, float sigma = 3f)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
return GaussianSharpen(source, sigma, source.Bounds); return GaussianSharpen(source, sigma, source.Bounds);
} }
@ -31,17 +31,17 @@ namespace ImageSharp
/// <summary> /// <summary>
/// Applies a Gaussian sharpening filter to the image. /// Applies a Gaussian sharpening filter to the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param> /// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
/// <param name="rectangle"> /// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param> /// </param>
/// <returns>The <see cref="Image{TColor}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TColor> GaussianSharpen<TColor>(this Image<TColor> source, float sigma, Rectangle rectangle) public static Image<TPixel> GaussianSharpen<TPixel>(this Image<TPixel> source, float sigma, Rectangle rectangle)
where TColor : struct, IPixel<TColor> where TPixel : struct, IPixel<TPixel>
{ {
source.ApplyProcessor(new GaussianSharpenProcessor<TColor>(sigma), rectangle); source.ApplyProcessor(new GaussianSharpenProcessor<TPixel>(sigma), rectangle);
return source; return source;
} }
} }

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

Loading…
Cancel
Save