Browse Source

Rename TColor to TPixel

af/merge-core
James Jackson-South 9 years ago
parent
commit
fff223ef07
  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.

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

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

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

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

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

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

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

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

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

18
src/ImageSharp.Drawing/DrawImage.cs

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

60
src/ImageSharp.Drawing/DrawPath.cs

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

60
src/ImageSharp.Drawing/FillRegion.cs

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -16,10 +16,10 @@ namespace ImageSharp
where TSelf : struct, IPixel<TSelf>
{
/// <summary>
/// Creates a <see cref="BulkPixelOperations{TColor}"/> instance for this pixel type.
/// This method is not intended to be consumed directly. Use <see cref="BulkPixelOperations{TColor}.Instance"/> instead.
/// Creates a <see cref="BulkPixelOperations{TPixel}"/> instance for this pixel type.
/// This method is not intended to be consumed directly. Use <see cref="BulkPixelOperations{TPixel}.Instance"/> instead.
/// </summary>
/// <returns>The <see cref="BulkPixelOperations{TColor}"/> instance.</returns>
/// <returns>The <see cref="BulkPixelOperations{TPixel}"/> instance.</returns>
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.
/// </summary>
/// <param name="scaleFunc">The scale function.</param>
/// <typeparam name="TColor">The source pixel format.</typeparam>
/// <typeparam name="TColor2">The target pixel format.</typeparam>
/// <typeparam name="TPixel">The source pixel format.</typeparam>
/// <typeparam name="TPixel2">The target pixel format.</typeparam>
/// <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.
if (scaleFunc != null)
@ -33,8 +33,8 @@ namespace ImageSharp
return scaleFunc;
}
Type source = typeof(TColor);
Type target = typeof(TColor2);
Type source = typeof(TPixel);
Type target = typeof(TPixel2);
// Normalized standard
if (IsStandardNormalizedType(source))

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

@ -21,7 +21,7 @@ namespace ImageSharp
public partial struct Rgba32
{
/// <summary>
/// <see cref="BulkPixelOperations{TColor}"/> implementation optimized for <see cref="Rgba32"/>.
/// <see cref="BulkPixelOperations{TPixel}"/> implementation optimized for <see cref="Rgba32"/>.
/// </summary>
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 temp1 = (2f * l) - temp2;
r = GeTPixelComponent(temp1, temp2, rangedH + 0.3333333F);
g = GeTPixelComponent(temp1, temp2, rangedH);
b = GeTPixelComponent(temp1, temp2, rangedH - 0.3333333F);
r = GetColorComponent(temp1, temp2, rangedH + 0.3333333F);
g = GetColorComponent(temp1, temp2, rangedH);
b = GetColorComponent(temp1, temp2, rangedH - 0.3333333F);
}
}
@ -241,7 +241,7 @@ namespace ImageSharp
/// <returns>
/// The <see cref="float"/>.
/// </returns>
private static float GeTPixelComponent(float first, float second, float third)
private static float GetColorComponent(float first, float second, float third)
{
third = MoveIntoRange(third);
if (third < 0.1666667F)

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

@ -18,7 +18,7 @@ namespace ImageSharp
public partial struct RgbaVector
{
/// <summary>
/// <see cref="BulkPixelOperations{TColor}"/> implementation optimized for <see cref="RgbaVector"/>.
/// <see cref="BulkPixelOperations{TPixel}"/> implementation optimized for <see cref="RgbaVector"/>.
/// </summary>
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
/// a type-specific method for determining approximate equality of instances.
/// </summary>
/// <typeparam name="TColor">The type of objects to compare.</typeparam>
/// <typeparam name="TPixel">The type of objects to compare.</typeparam>
/// <typeparam name="TPrecision">The object specifying the type to specify precision with.</typeparam>
public interface IAlmostEquatable<in TColor, in TPrecision>
public interface IAlmostEquatable<in TPixel, in TPrecision>
where TPrecision : struct, IComparable<TPrecision>
{
/// <summary>
@ -25,6 +25,6 @@ namespace ImageSharp.Colors.Spaces
/// <returns>
/// true if the current object is equal to the other parameter; otherwise, false.
/// </returns>
bool AlmostEquals(TColor other, TPrecision precision);
bool AlmostEquals(TPixel other, TPrecision precision);
}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

8
src/ImageSharp/Formats/IImageDecoder.cs

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

10
src/ImageSharp/Formats/IImageEncoder.cs

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

28
src/ImageSharp/Image.Create.cs

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

8
src/ImageSharp/Image.Decode.cs

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

48
src/ImageSharp/Image.FromBytes.cs

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

48
src/ImageSharp/Image.FromFile.cs

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

48
src/ImageSharp/Image.FromStream.cs

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

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

10
src/ImageSharp/Image/IImageProcessor.cs

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

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

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

11
src/ImageSharp/Image/ImageProcessingExtensions.cs

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

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

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

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

16
src/ImageSharp/ImageProcessor.cs

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

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

@ -116,12 +116,12 @@ namespace ImageSharp
/// <summary>
/// Returns the thumbnail in the EXIF profile when available.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>
/// The <see cref="Image{TColor}"/>.
/// The <see cref="Image{TPixel}"/>.
/// </returns>
public Image<TColor> CreateThumbnail<TColor>()
where TColor : struct, IPixel<TColor>
public Image<TPixel> CreateThumbnail<TPixel>()
where TPixel : struct, IPixel<TPixel>
{
this.InitializeValues();
@ -137,7 +137,7 @@ namespace ImageSharp
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;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Applies binarization to the image splitting the pixels at the given threshold.
/// </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="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> BinaryThreshold<TColor>(this Image<TColor> source, float threshold)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> BinaryThreshold<TPixel>(this Image<TPixel> source, float threshold)
where TPixel : struct, IPixel<TPixel>
{
return BinaryThreshold(source, threshold, source.Bounds);
}
@ -30,17 +30,17 @@ namespace ImageSharp
/// <summary>
/// Applies binarization to the image splitting the pixels at the given threshold.
/// </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="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> BinaryThreshold<TColor>(this Image<TColor> source, float threshold, Rectangle rectangle)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> BinaryThreshold<TPixel>(this Image<TPixel> source, float threshold, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new BinaryThresholdProcessor<TColor>(threshold), rectangle);
source.ApplyProcessor(new BinaryThresholdProcessor<TPixel>(threshold), rectangle);
return source;
}
}

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

@ -18,13 +18,13 @@ namespace ImageSharp
/// <summary>
/// Dithers the image reducing it to two colors using ordered dithering.
/// </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="dither">The ordered ditherer.</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>
public static Image<TColor> Dither<TColor>(this Image<TColor> source, IOrderedDither dither, int index = 0)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Dither<TPixel>(this Image<TPixel> source, IOrderedDither dither, int index = 0)
where TPixel : struct, IPixel<TPixel>
{
return Dither(source, dither, source.Bounds, index);
}
@ -32,7 +32,7 @@ namespace ImageSharp
/// <summary>
/// Dithers the image reducing it to two colors using ordered dithering.
/// </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="dither">The ordered ditherer.</param>
/// <param name="rectangle">
@ -40,23 +40,23 @@ namespace ImageSharp
/// </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>
public static Image<TColor> Dither<TColor>(this Image<TColor> source, IOrderedDither dither, Rectangle rectangle, int index = 0)
where TColor : struct, IPixel<TColor>
public static Image<TPixel> Dither<TPixel>(this Image<TPixel> source, IOrderedDither dither, Rectangle rectangle, int index = 0)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new OrderedDitherProcessor<TColor>(dither, index), rectangle);
source.ApplyProcessor(new OrderedDitherProcessor<TPixel>(dither, index), rectangle);
return source;
}
/// <summary>
/// Dithers the image reducing it to two colors using error diffusion.
/// </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="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>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Dither<TColor>(this Image<TColor> source, IErrorDiffuser diffuser, float threshold)
where TColor : struct, IPixel<TColor>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Dither<TPixel>(this Image<TPixel> source, IErrorDiffuser diffuser, float threshold)
where TPixel : struct, IPixel<TPixel>
{
return Dither(source, diffuser, threshold, source.Bounds);
}
@ -64,7 +64,7 @@ namespace ImageSharp
/// <summary>
/// Dithers the image reducing it to two colors using error diffusion.
/// </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="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>
@ -72,10 +72,10 @@ namespace ImageSharp
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image<TColor> Dither<TColor>(this Image<TColor> source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle)
where TColor : struct, IPixel<TColor>
public static Image<TPixel> Dither<TPixel>(this Image<TPixel> source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new ErrorDiffusionDitherProcessor<TColor>(diffuser, threshold), rectangle);
source.ApplyProcessor(new ErrorDiffusionDitherProcessor<TPixel>(diffuser, threshold), rectangle);
return source;
}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save