Browse Source

API cleanup (related to #907) (#911)

* temporarily disable target frameworks

* drop DelegateProcessor

* drop IImageProcessingContext<TPixel>

* drop NamedColors<T>

* drop ColorBuilder<T>

* drop the *Base postfix for clean class hierarchies

* re-enable target frameworks

* use MathF in gradient brushes

* Move PngFilterMethod to the correct namespace.
af/merge-core
Anton Firsov 7 years ago
committed by James Jackson-South
parent
commit
34781bff3e
  1. 11
      src/ImageSharp.Drawing/Processing/EllipticGradientBrush.cs
  2. 10
      src/ImageSharp.Drawing/Processing/GradientBrush.cs
  3. 8
      src/ImageSharp.Drawing/Processing/LinearGradientBrush.cs
  4. 8
      src/ImageSharp.Drawing/Processing/RadialGradientBrush.cs
  5. 48
      src/ImageSharp/Color/Color.cs
  6. 2
      src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs
  7. 2
      src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.cs
  8. 2
      src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverterOptions.cs
  9. 4
      src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToLinearRgbConverter.cs
  10. 2
      src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbAndCieXyzConverterBase.cs
  11. 4
      src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbToCieXyzConverter.cs
  12. 2
      src/ImageSharp/ColorSpaces/Conversion/Implementation/RGBPrimariesChromaticityCoordinates.cs
  13. 2
      src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/GammaWorkingSpace.cs
  14. 2
      src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/LWorkingSpace.cs
  15. 2
      src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/Rec2020WorkingSpace.cs
  16. 2
      src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/Rec709WorkingSpace.cs
  17. 10
      src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/RgbWorkingSpace.cs
  18. 2
      src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/SRgbWorkingSpace.cs
  19. 10
      src/ImageSharp/ColorSpaces/LinearRgb.cs
  20. 10
      src/ImageSharp/ColorSpaces/Rgb.cs
  21. 38
      src/ImageSharp/ColorSpaces/RgbWorkingSpaces.cs
  22. 2
      src/ImageSharp/Formats/Png/PngFilterMethod.cs
  23. 104
      src/ImageSharp/PixelFormats/ColorBuilder{TPixel}.cs
  24. 761
      src/ImageSharp/PixelFormats/NamedColors{TPixel}.cs
  25. 55
      src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs
  26. 2
      src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs
  27. 14
      src/ImageSharp/Processing/DefaultImageProcessorContext.cs
  28. 8
      src/ImageSharp/Processing/Extensions/BinaryDiffuseExtensions.cs
  29. 8
      src/ImageSharp/Processing/Extensions/BinaryDitherExtensions.cs
  30. 37
      src/ImageSharp/Processing/Extensions/ProcessingExtensions.cs
  31. 2
      src/ImageSharp/Processing/IImageProcessingContextFactory.cs
  32. 46
      src/ImageSharp/Processing/IImageProcessingContext{TPixel}.cs
  33. 22
      src/ImageSharp/Processing/IInternalImageProcessingContext.cs
  34. 43
      src/ImageSharp/Processing/Processors/DelegateProcessor.cs
  35. 2
      src/ImageSharp/Processing/Processors/Dithering/AtkinsonDiffuser.cs
  36. 2
      src/ImageSharp/Processing/Processors/Dithering/BurksDiffuser.cs
  37. 6
      src/ImageSharp/Processing/Processors/Dithering/ErrorDiffuser.cs
  38. 2
      src/ImageSharp/Processing/Processors/Dithering/FloydSteinbergDiffuser.cs
  39. 2
      src/ImageSharp/Processing/Processors/Dithering/JarvisJudiceNinkeDiffuser.cs
  40. 2
      src/ImageSharp/Processing/Processors/Dithering/Sierra2Diffuser.cs
  41. 2
      src/ImageSharp/Processing/Processors/Dithering/Sierra3Diffuser.cs
  42. 2
      src/ImageSharp/Processing/Processors/Dithering/SierraLiteDiffuser.cs
  43. 2
      src/ImageSharp/Processing/Processors/Dithering/StevensonArceDiffuser.cs
  44. 2
      src/ImageSharp/Processing/Processors/Dithering/StuckiDiffuser.cs
  45. 2
      src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor{TPixel}.cs
  46. 2
      src/ImageSharp/Processing/Processors/Transforms/CropProcessor{TPixel}.cs
  47. 2
      src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor{TPixel}.cs
  48. 2
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs
  49. 2
      src/ImageSharp/Processing/Processors/Transforms/TransformProcessor.cs
  50. 2
      tests/ImageSharp.Benchmarks/Samplers/Glow.cs
  51. 2
      tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs
  52. 6
      tests/ImageSharp.Tests/Colorspaces/Conversion/ApproximateColorspaceComparer.cs
  53. 21
      tests/ImageSharp.Tests/FakeImageOperationsProvider.cs
  54. 60
      tests/ImageSharp.Tests/Image/ImageProcessingContextTests.cs
  55. 8
      tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs
  56. 40
      tests/ImageSharp.Tests/PixelFormats/ColorBuilderTests.cs
  57. 46
      tests/ImageSharp.Tests/PixelFormats/ColorDefinitionTests.cs
  58. 25
      tests/ImageSharp.Tests/Processing/DelegateTest.cs
  59. 10
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/BasicTestPatternProvider.cs
  60. 31
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs

11
src/ImageSharp.Drawing/Processing/EllipticGradientBrush.cs

@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp.Processing
/// a point on the longest extension of the ellipse and
/// the ratio between longest and shortest extension.
/// </summary>
public sealed class EllipticGradientBrush : GradientBrushBase
public sealed class EllipticGradientBrush : GradientBrush
{
private readonly PointF center;
@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.Processing
private readonly float axisRatio;
/// <inheritdoc cref="GradientBrushBase" />
/// <inheritdoc cref="GradientBrush" />
/// <param name="center">The center of the elliptical gradient and 0 for the color stops.</param>
/// <param name="referenceAxisEnd">The end point of the reference axis of the ellipse.</param>
/// <param name="axisRatio">
@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.Processing
this.RepetitionMode);
/// <inheritdoc />
private sealed class RadialGradientBrushApplicator<TPixel> : GradientBrushApplicatorBase<TPixel>
private sealed class RadialGradientBrushApplicator<TPixel> : GradientBrushApplicator<TPixel>
where TPixel : struct, IPixel<TPixel>
{
private readonly PointF center;
@ -149,8 +149,7 @@ namespace SixLabors.ImageSharp.Processing
{
var vA = a - junction;
var vB = b - junction;
return (float)(Math.Atan2(vB.Y, vB.X)
- Math.Atan2(vA.Y, vA.X));
return MathF.Atan2(vB.Y, vB.X) - MathF.Atan2(vA.Y, vA.X);
}
private float DistanceBetween(
@ -162,7 +161,7 @@ namespace SixLabors.ImageSharp.Processing
float dY = p1.Y - p2.Y;
float dYsquared = dY * dY;
return (float)Math.Sqrt(dXsquared + dYsquared);
return MathF.Sqrt(dXsquared + dYsquared);
}
}
}

10
src/ImageSharp.Drawing/Processing/GradientBrushBase.cs → src/ImageSharp.Drawing/Processing/GradientBrush.cs

@ -13,12 +13,12 @@ namespace SixLabors.ImageSharp.Processing
/// <summary>
/// Base class for Gradient brushes
/// </summary>
public abstract class GradientBrushBase : IBrush
public abstract class GradientBrush : IBrush
{
/// <inheritdoc cref="IBrush"/>
/// <param name="repetitionMode">Defines how the colors are repeated beyond the interval [0..1]</param>
/// <param name="colorStops">The gradient colors.</param>
protected GradientBrushBase(
protected GradientBrush(
GradientRepetitionMode repetitionMode,
params ColorStop[] colorStops)
{
@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp.Processing
/// <summary>
/// Base class for gradient brush applicators
/// </summary>
internal abstract class GradientBrushApplicatorBase<TPixel> : BrushApplicator<TPixel>
internal abstract class GradientBrushApplicator<TPixel> : BrushApplicator<TPixel>
where TPixel : struct, IPixel<TPixel>
{
private static readonly TPixel Transparent = Color.Transparent.ToPixel<TPixel>();
@ -56,13 +56,13 @@ namespace SixLabors.ImageSharp.Processing
private readonly GradientRepetitionMode repetitionMode;
/// <summary>
/// Initializes a new instance of the <see cref="GradientBrushApplicatorBase{TPixel}"/> class.
/// Initializes a new instance of the <see cref="GradientBrushApplicator{TPixel}"/> class.
/// </summary>
/// <param name="target">The target.</param>
/// <param name="options">The options.</param>
/// <param name="colorStops">An array of color stops sorted by their position.</param>
/// <param name="repetitionMode">Defines if and how the gradient should be repeated.</param>
protected GradientBrushApplicatorBase(
protected GradientBrushApplicator(
ImageFrame<TPixel> target,
GraphicsOptions options,
ColorStop[] colorStops,

8
src/ImageSharp.Drawing/Processing/LinearGradientBrush.cs

@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Processing
/// Supported right now:
/// - a set of colors in relative distances to each other.
/// </summary>
public sealed class LinearGradientBrush : GradientBrushBase
public sealed class LinearGradientBrush : GradientBrush
{
private readonly PointF p1;
@ -53,7 +53,7 @@ namespace SixLabors.ImageSharp.Processing
/// <summary>
/// The linear gradient brush applicator.
/// </summary>
private sealed class LinearGradientBrushApplicator<TPixel> : GradientBrushApplicatorBase<TPixel>
private sealed class LinearGradientBrushApplicator<TPixel> : GradientBrushApplicator<TPixel>
where TPixel : struct, IPixel<TPixel>
{
private readonly PointF start;
@ -121,7 +121,7 @@ namespace SixLabors.ImageSharp.Processing
// some helpers:
this.alongsSquared = (this.alongX * this.alongX) + (this.alongY * this.alongY);
this.length = (float)Math.Sqrt(this.alongsSquared);
this.length = MathF.Sqrt(this.alongsSquared);
}
protected override float PositionOnGradient(float x, float y)
@ -145,7 +145,7 @@ namespace SixLabors.ImageSharp.Processing
float y4 = y + (k * this.alongX);
// get distance from (x4,y4) to start
float distance = (float)Math.Sqrt(Math.Pow(x4 - this.start.X, 2) + Math.Pow(y4 - this.start.Y, 2));
float distance = MathF.Sqrt(MathF.Pow(x4 - this.start.X, 2) + MathF.Pow(y4 - this.start.Y, 2));
// get and return ratio
float ratio = distance / this.length;

8
src/ImageSharp.Drawing/Processing/RadialGradientBrush.cs

@ -11,13 +11,13 @@ namespace SixLabors.ImageSharp.Processing
/// <summary>
/// A Circular Gradient Brush, defined by center point and radius.
/// </summary>
public sealed class RadialGradientBrush : GradientBrushBase
public sealed class RadialGradientBrush : GradientBrush
{
private readonly PointF center;
private readonly float radius;
/// <inheritdoc cref="GradientBrushBase" />
/// <inheritdoc cref="GradientBrush" />
/// <param name="center">The center of the circular gradient and 0 for the color stops.</param>
/// <param name="radius">The radius of the circular gradient and 1 for the color stops.</param>
/// <param name="repetitionMode">Defines how the colors in the gradient are repeated.</param>
@ -47,7 +47,7 @@ namespace SixLabors.ImageSharp.Processing
this.RepetitionMode);
/// <inheritdoc />
private sealed class RadialGradientBrushApplicator<TPixel> : GradientBrushApplicatorBase<TPixel>
private sealed class RadialGradientBrushApplicator<TPixel> : GradientBrushApplicator<TPixel>
where TPixel : struct, IPixel<TPixel>
{
private readonly PointF center;
@ -90,7 +90,7 @@ namespace SixLabors.ImageSharp.Processing
/// <returns>the position on the color gradient.</returns>
protected override float PositionOnGradient(float x, float y)
{
float distance = (float)Math.Sqrt(Math.Pow(this.center.X - x, 2) + Math.Pow(this.center.Y - y, 2));
float distance = MathF.Sqrt(MathF.Pow(this.center.X - x, 2) + MathF.Pow(this.center.Y - y, 2));
return distance / this.radius;
}

48
src/ImageSharp/Color/Color.cs

@ -104,18 +104,11 @@ namespace SixLabors.ImageSharp
/// in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax.
/// </param>
/// <returns>Returns a <see cref="Color"/> that represents the color defined by the provided RGBA hex string.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static Color FromHex(string hex)
{
Guard.NotNullOrWhiteSpace(hex, nameof(hex));
hex = ToRgbaHex(hex);
if (hex is null || !uint.TryParse(hex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out uint packedValue))
{
throw new ArgumentException("Hexadecimal string is not in the correct format.", nameof(hex));
}
Rgba32 rgba = Rgba32.FromHex(hex);
var rgba = new Rgba32(BinaryPrimitives.ReverseEndianness(packedValue));
return new Color(rgba);
}
@ -189,42 +182,5 @@ namespace SixLabors.ImageSharp
ReadOnlySpan<Rgba64> rgba64Span = MemoryMarshal.Cast<Color, Rgba64>(source);
PixelOperations<TPixel>.Instance.FromRgba64(Configuration.Default, rgba64Span, destination);
}
/// <summary>
/// Converts the specified hex value to an rrggbbaa hex value.
/// </summary>
/// <param name="hex">The hex value to convert.</param>
/// <returns>
/// A rrggbbaa hex value.
/// </returns>
private static string ToRgbaHex(string hex)
{
if (hex[0] == '#')
{
hex = hex.Substring(1);
}
if (hex.Length == 8)
{
return hex;
}
if (hex.Length == 6)
{
return hex + "FF";
}
if (hex.Length < 3 || hex.Length > 4)
{
return null;
}
char r = hex[0];
char g = hex[1];
char b = hex[2];
char a = hex.Length == 3 ? 'F' : hex[3];
return new string(new[] { r, r, g, g, b, b, a, a });
}
}
}

2
src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieXyz.cs

@ -465,7 +465,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// </summary>
/// <param name="workingSpace">The source working space</param>
/// <returns>The <see cref="LinearRgbToCieXyzConverter"/></returns>
private LinearRgbToCieXyzConverter GetLinearRgbToCieXyzConverter(RgbWorkingSpaceBase workingSpace)
private LinearRgbToCieXyzConverter GetLinearRgbToCieXyzConverter(RgbWorkingSpace workingSpace)
{
if (this.linearRgbToCieXyzConverter?.SourceWorkingSpace.Equals(workingSpace) == true)
{

2
src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.cs

@ -18,7 +18,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
private readonly CieXyz targetLuvWhitePoint;
private readonly CieXyz targetLabWhitePoint;
private readonly CieXyz targetHunterLabWhitePoint;
private readonly RgbWorkingSpaceBase targetRgbWorkingSpace;
private readonly RgbWorkingSpace targetRgbWorkingSpace;
private readonly IChromaticAdaptation chromaticAdaptation;
private readonly bool performChromaticAdaptation;
private readonly CieXyzAndLmsConverter cieXyzAndLmsConverter;

2
src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverterOptions.cs

@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion
/// Gets or sets the target working space used *when creating* RGB colors. (RGB colors on the input already contain the working space information)
/// Defaults to: <see cref="Rgb.DefaultWorkingSpace"/>.
/// </summary>
public RgbWorkingSpaceBase TargetRgbWorkingSpace { get; set; } = Rgb.DefaultWorkingSpace;
public RgbWorkingSpace TargetRgbWorkingSpace { get; set; } = Rgb.DefaultWorkingSpace;
/// <summary>
/// Gets or sets the chromatic adaptation method used. When <value>null</value>, no adaptation will be performed.

4
src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/CieXyzToLinearRgbConverter.cs

@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
/// Initializes a new instance of the <see cref="CieXyzToLinearRgbConverter"/> class.
/// </summary>
/// <param name="workingSpace">The target working space.</param>
public CieXyzToLinearRgbConverter(RgbWorkingSpaceBase workingSpace)
public CieXyzToLinearRgbConverter(RgbWorkingSpace workingSpace)
{
this.TargetWorkingSpace = workingSpace;
@ -38,7 +38,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
/// <summary>
/// Gets the target working space.
/// </summary>
public RgbWorkingSpaceBase TargetWorkingSpace { get; }
public RgbWorkingSpace TargetWorkingSpace { get; }
/// <summary>
/// Performs the conversion from the <see cref="CieXyz"/> input to an instance of <see cref="LinearRgb"/> type.

2
src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbAndCieXyzConverterBase.cs

@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
/// </summary>
/// <param name="workingSpace">The Rgb working space.</param>
/// <returns>The <see cref="Matrix4x4"/> based on the chromaticity and working space.</returns>
public static Matrix4x4 GetRgbToCieXyzMatrix(RgbWorkingSpaceBase workingSpace)
public static Matrix4x4 GetRgbToCieXyzMatrix(RgbWorkingSpace workingSpace)
{
DebugGuard.NotNull(workingSpace, nameof(workingSpace));
RgbPrimariesChromaticityCoordinates chromaticity = workingSpace.ChromaticityCoordinates;

4
src/ImageSharp/ColorSpaces/Conversion/Implementation/Converters/LinearRgbToCieXyzConverter.cs

@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
/// Initializes a new instance of the <see cref="LinearRgbToCieXyzConverter"/> class.
/// </summary>
/// <param name="workingSpace">The target working space.</param>
public LinearRgbToCieXyzConverter(RgbWorkingSpaceBase workingSpace)
public LinearRgbToCieXyzConverter(RgbWorkingSpace workingSpace)
{
this.SourceWorkingSpace = workingSpace;
this.conversionMatrix = GetRgbToCieXyzMatrix(workingSpace);
@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
/// <summary>
/// Gets the source working space
/// </summary>
public RgbWorkingSpaceBase SourceWorkingSpace { get; }
public RgbWorkingSpace SourceWorkingSpace { get; }
/// <summary>
/// Performs the conversion from the <see cref="LinearRgb"/> input to an instance of <see cref="CieXyz"/> type.

2
src/ImageSharp/ColorSpaces/Conversion/Implementation/RGBPrimariesChromaticityCoordinates.cs

@ -7,7 +7,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
{
/// <summary>
/// Represents the chromaticity coordinates of RGB primaries.
/// One of the specifiers of <see cref="RgbWorkingSpaceBase"/>.
/// One of the specifiers of <see cref="RgbWorkingSpace"/>.
/// </summary>
public readonly struct RgbPrimariesChromaticityCoordinates : IEquatable<RgbPrimariesChromaticityCoordinates>
{

2
src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/GammaWorkingSpace.cs

@ -10,7 +10,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
/// <summary>
/// The gamma working space.
/// </summary>
public sealed class GammaWorkingSpace : RgbWorkingSpaceBase
public sealed class GammaWorkingSpace : RgbWorkingSpace
{
/// <summary>
/// Initializes a new instance of the <see cref="GammaWorkingSpace" /> class.

2
src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/LWorkingSpace.cs

@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
/// <summary>
/// L* working space.
/// </summary>
public sealed class LWorkingSpace : RgbWorkingSpaceBase
public sealed class LWorkingSpace : RgbWorkingSpace
{
/// <summary>
/// Initializes a new instance of the <see cref="LWorkingSpace" /> class.

2
src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/Rec2020WorkingSpace.cs

@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
/// <summary>
/// Rec. 2020 (ITU-R Recommendation BT.2020F) working space.
/// </summary>
public sealed class Rec2020WorkingSpace : RgbWorkingSpaceBase
public sealed class Rec2020WorkingSpace : RgbWorkingSpace
{
/// <summary>
/// Initializes a new instance of the <see cref="Rec2020WorkingSpace" /> class.

2
src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/Rec709WorkingSpace.cs

@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
/// <summary>
/// Rec. 709 (ITU-R Recommendation BT.709) working space.
/// </summary>
public sealed class Rec709WorkingSpace : RgbWorkingSpaceBase
public sealed class Rec709WorkingSpace : RgbWorkingSpace
{
/// <summary>
/// Initializes a new instance of the <see cref="Rec709WorkingSpace" /> class.

10
src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/RgbWorkingSpaceBase.cs → src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/RgbWorkingSpace.cs

@ -6,16 +6,16 @@ using System;
namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
{
/// <summary>
/// Base class for all implementations of <see cref="RgbWorkingSpaceBase"/>.
/// Base class for all implementations of <see cref="RgbWorkingSpace"/>.
/// </summary>
public abstract class RgbWorkingSpaceBase
public abstract class RgbWorkingSpace
{
/// <summary>
/// Initializes a new instance of the <see cref="RgbWorkingSpaceBase"/> class.
/// Initializes a new instance of the <see cref="RgbWorkingSpace"/> class.
/// </summary>
/// <param name="referenceWhite">The reference white point.</param>
/// <param name="chromaticityCoordinates">The chromaticity of the rgb primaries.</param>
protected RgbWorkingSpaceBase(CieXyz referenceWhite, RgbPrimariesChromaticityCoordinates chromaticityCoordinates)
protected RgbWorkingSpace(CieXyz referenceWhite, RgbPrimariesChromaticityCoordinates chromaticityCoordinates)
{
this.WhitePoint = referenceWhite;
this.ChromaticityCoordinates = chromaticityCoordinates;
@ -66,7 +66,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
return true;
}
if (obj is RgbWorkingSpaceBase other)
if (obj is RgbWorkingSpace other)
{
return this.WhitePoint.Equals(other.WhitePoint)
&& this.ChromaticityCoordinates.Equals(other.ChromaticityCoordinates);

2
src/ImageSharp/ColorSpaces/Conversion/Implementation/WorkingSpaces/SRgbWorkingSpace.cs

@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation
/// <summary>
/// The sRgb working space.
/// </summary>
public sealed class SRgbWorkingSpace : RgbWorkingSpaceBase
public sealed class SRgbWorkingSpace : RgbWorkingSpace
{
/// <summary>
/// Initializes a new instance of the <see cref="SRgbWorkingSpace" /> class.

10
src/ImageSharp/ColorSpaces/LinearRgb.cs

@ -9,7 +9,7 @@ using SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation;
namespace SixLabors.ImageSharp.ColorSpaces
{
/// <summary>
/// Represents an linear Rgb color with specified <see cref="RgbWorkingSpaceBase"/> working space
/// Represents an linear Rgb color with specified <see cref="RgbWorkingSpace"/> working space
/// </summary>
public readonly struct LinearRgb : IEquatable<LinearRgb>
{
@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// <summary>
/// The default LinearRgb working space.
/// </summary>
public static readonly RgbWorkingSpaceBase DefaultWorkingSpace = RgbWorkingSpaces.SRgb;
public static readonly RgbWorkingSpace DefaultWorkingSpace = RgbWorkingSpaces.SRgb;
/// <summary>
/// Gets the red component.
@ -42,7 +42,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// <summary>
/// Gets the LinearRgb color space <seealso cref="RgbWorkingSpaces"/>
/// </summary>
public readonly RgbWorkingSpaceBase WorkingSpace;
public readonly RgbWorkingSpace WorkingSpace;
/// <summary>
/// Initializes a new instance of the <see cref="LinearRgb"/> struct.
@ -64,7 +64,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// <param name="b">The blue component ranging between 0 and 1.</param>
/// <param name="workingSpace">The rgb working space.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public LinearRgb(float r, float g, float b, RgbWorkingSpaceBase workingSpace)
public LinearRgb(float r, float g, float b, RgbWorkingSpace workingSpace)
: this(new Vector3(r, g, b), workingSpace)
{
}
@ -85,7 +85,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// <param name="vector">The vector representing the r, g, b components.</param>
/// <param name="workingSpace">The LinearRgb working space.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public LinearRgb(Vector3 vector, RgbWorkingSpaceBase workingSpace)
public LinearRgb(Vector3 vector, RgbWorkingSpace workingSpace)
{
// Clamp to 0-1 range.
vector = Vector3.Clamp(vector, Min, Max);

10
src/ImageSharp/ColorSpaces/Rgb.cs

@ -10,14 +10,14 @@ using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.ColorSpaces
{
/// <summary>
/// Represents an RGB color with specified <see cref="RgbWorkingSpaceBase"/> working space.
/// Represents an RGB color with specified <see cref="RgbWorkingSpace"/> working space.
/// </summary>
public readonly struct Rgb : IEquatable<Rgb>
{
/// <summary>
/// The default rgb working space.
/// </summary>
public static readonly RgbWorkingSpaceBase DefaultWorkingSpace = RgbWorkingSpaces.SRgb;
public static readonly RgbWorkingSpace DefaultWorkingSpace = RgbWorkingSpaces.SRgb;
private static readonly Vector3 Min = Vector3.Zero;
private static readonly Vector3 Max = Vector3.One;
@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// <summary>
/// Gets the Rgb color space <seealso cref="RgbWorkingSpaces"/>
/// </summary>
public readonly RgbWorkingSpaceBase WorkingSpace;
public readonly RgbWorkingSpace WorkingSpace;
/// <summary>
/// Initializes a new instance of the <see cref="Rgb"/> struct.
@ -65,7 +65,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// <param name="b">The blue component ranging between 0 and 1.</param>
/// <param name="workingSpace">The rgb working space.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public Rgb(float r, float g, float b, RgbWorkingSpaceBase workingSpace)
public Rgb(float r, float g, float b, RgbWorkingSpace workingSpace)
: this(new Vector3(r, g, b), workingSpace)
{
}
@ -86,7 +86,7 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// <param name="vector">The vector representing the r, g, b components.</param>
/// <param name="workingSpace">The rgb working space.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public Rgb(Vector3 vector, RgbWorkingSpaceBase workingSpace)
public Rgb(Vector3 vector, RgbWorkingSpace workingSpace)
{
vector = Vector3.Clamp(vector, Min, Max);
this.R = vector.X;

38
src/ImageSharp/ColorSpaces/RgbWorkingSpaces.cs

@ -19,97 +19,97 @@ namespace SixLabors.ImageSharp.ColorSpaces
/// Uses proper companding function, according to:
/// <see href="http://www.brucelindbloom.com/index.html?Eqn_Rgb_to_XYZ.html"/>
/// </remarks>
public static readonly RgbWorkingSpaceBase SRgb = new SRgbWorkingSpace(Illuminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.3000F, 0.6000F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F)));
public static readonly RgbWorkingSpace SRgb = new SRgbWorkingSpace(Illuminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.3000F, 0.6000F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F)));
/// <summary>
/// Simplified sRgb working space (uses <see cref="GammaCompanding">gamma companding</see> instead of <see cref="SRgbCompanding"/>).
/// See also <see cref="SRgb"/>.
/// </summary>
public static readonly RgbWorkingSpaceBase SRgbSimplified = new GammaWorkingSpace(2.2F, Illuminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.3000F, 0.6000F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F)));
public static readonly RgbWorkingSpace SRgbSimplified = new GammaWorkingSpace(2.2F, Illuminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.3000F, 0.6000F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F)));
/// <summary>
/// Rec. 709 (ITU-R Recommendation BT.709) working space.
/// </summary>
public static readonly RgbWorkingSpaceBase Rec709 = new Rec709WorkingSpace(Illuminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.64F, 0.33F), new CieXyChromaticityCoordinates(0.30F, 0.60F), new CieXyChromaticityCoordinates(0.15F, 0.06F)));
public static readonly RgbWorkingSpace Rec709 = new Rec709WorkingSpace(Illuminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.64F, 0.33F), new CieXyChromaticityCoordinates(0.30F, 0.60F), new CieXyChromaticityCoordinates(0.15F, 0.06F)));
/// <summary>
/// Rec. 2020 (ITU-R Recommendation BT.2020F) working space.
/// </summary>
public static readonly RgbWorkingSpaceBase Rec2020 = new Rec2020WorkingSpace(Illuminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.708F, 0.292F), new CieXyChromaticityCoordinates(0.170F, 0.797F), new CieXyChromaticityCoordinates(0.131F, 0.046F)));
public static readonly RgbWorkingSpace Rec2020 = new Rec2020WorkingSpace(Illuminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.708F, 0.292F), new CieXyChromaticityCoordinates(0.170F, 0.797F), new CieXyChromaticityCoordinates(0.131F, 0.046F)));
/// <summary>
/// ECI Rgb v2 working space.
/// </summary>
public static readonly RgbWorkingSpaceBase ECIRgbv2 = new LWorkingSpace(Illuminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6700F, 0.3300F), new CieXyChromaticityCoordinates(0.2100F, 0.7100F), new CieXyChromaticityCoordinates(0.1400F, 0.0800F)));
public static readonly RgbWorkingSpace ECIRgbv2 = new LWorkingSpace(Illuminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6700F, 0.3300F), new CieXyChromaticityCoordinates(0.2100F, 0.7100F), new CieXyChromaticityCoordinates(0.1400F, 0.0800F)));
/// <summary>
/// Adobe Rgb (1998) working space.
/// </summary>
public static readonly RgbWorkingSpaceBase AdobeRgb1998 = new GammaWorkingSpace(2.2F, Illuminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.2100F, 0.7100F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F)));
public static readonly RgbWorkingSpace AdobeRgb1998 = new GammaWorkingSpace(2.2F, Illuminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.2100F, 0.7100F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F)));
/// <summary>
/// Apple sRgb working space.
/// </summary>
public static readonly RgbWorkingSpaceBase ApplesRgb = new GammaWorkingSpace(1.8F, Illuminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6250F, 0.3400F), new CieXyChromaticityCoordinates(0.2800F, 0.5950F), new CieXyChromaticityCoordinates(0.1550F, 0.0700F)));
public static readonly RgbWorkingSpace ApplesRgb = new GammaWorkingSpace(1.8F, Illuminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6250F, 0.3400F), new CieXyChromaticityCoordinates(0.2800F, 0.5950F), new CieXyChromaticityCoordinates(0.1550F, 0.0700F)));
/// <summary>
/// Best Rgb working space.
/// </summary>
public static readonly RgbWorkingSpaceBase BestRgb = new GammaWorkingSpace(2.2F, Illuminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7347F, 0.2653F), new CieXyChromaticityCoordinates(0.2150F, 0.7750F), new CieXyChromaticityCoordinates(0.1300F, 0.0350F)));
public static readonly RgbWorkingSpace BestRgb = new GammaWorkingSpace(2.2F, Illuminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7347F, 0.2653F), new CieXyChromaticityCoordinates(0.2150F, 0.7750F), new CieXyChromaticityCoordinates(0.1300F, 0.0350F)));
/// <summary>
/// Beta Rgb working space.
/// </summary>
public static readonly RgbWorkingSpaceBase BetaRgb = new GammaWorkingSpace(2.2F, Illuminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6888F, 0.3112F), new CieXyChromaticityCoordinates(0.1986F, 0.7551F), new CieXyChromaticityCoordinates(0.1265F, 0.0352F)));
public static readonly RgbWorkingSpace BetaRgb = new GammaWorkingSpace(2.2F, Illuminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6888F, 0.3112F), new CieXyChromaticityCoordinates(0.1986F, 0.7551F), new CieXyChromaticityCoordinates(0.1265F, 0.0352F)));
/// <summary>
/// Bruce Rgb working space.
/// </summary>
public static readonly RgbWorkingSpaceBase BruceRgb = new GammaWorkingSpace(2.2F, Illuminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.2800F, 0.6500F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F)));
public static readonly RgbWorkingSpace BruceRgb = new GammaWorkingSpace(2.2F, Illuminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.2800F, 0.6500F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F)));
/// <summary>
/// CIE Rgb working space.
/// </summary>
public static readonly RgbWorkingSpaceBase CIERgb = new GammaWorkingSpace(2.2F, Illuminants.E, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7350F, 0.2650F), new CieXyChromaticityCoordinates(0.2740F, 0.7170F), new CieXyChromaticityCoordinates(0.1670F, 0.0090F)));
public static readonly RgbWorkingSpace CIERgb = new GammaWorkingSpace(2.2F, Illuminants.E, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7350F, 0.2650F), new CieXyChromaticityCoordinates(0.2740F, 0.7170F), new CieXyChromaticityCoordinates(0.1670F, 0.0090F)));
/// <summary>
/// ColorMatch Rgb working space.
/// </summary>
public static readonly RgbWorkingSpaceBase ColorMatchRgb = new GammaWorkingSpace(1.8F, Illuminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6300F, 0.3400F), new CieXyChromaticityCoordinates(0.2950F, 0.6050F), new CieXyChromaticityCoordinates(0.1500F, 0.0750F)));
public static readonly RgbWorkingSpace ColorMatchRgb = new GammaWorkingSpace(1.8F, Illuminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6300F, 0.3400F), new CieXyChromaticityCoordinates(0.2950F, 0.6050F), new CieXyChromaticityCoordinates(0.1500F, 0.0750F)));
/// <summary>
/// Don Rgb 4 working space.
/// </summary>
public static readonly RgbWorkingSpaceBase DonRgb4 = new GammaWorkingSpace(2.2F, Illuminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6960F, 0.3000F), new CieXyChromaticityCoordinates(0.2150F, 0.7650F), new CieXyChromaticityCoordinates(0.1300F, 0.0350F)));
public static readonly RgbWorkingSpace DonRgb4 = new GammaWorkingSpace(2.2F, Illuminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6960F, 0.3000F), new CieXyChromaticityCoordinates(0.2150F, 0.7650F), new CieXyChromaticityCoordinates(0.1300F, 0.0350F)));
/// <summary>
/// Ekta Space PS5 working space.
/// </summary>
public static readonly RgbWorkingSpaceBase EktaSpacePS5 = new GammaWorkingSpace(2.2F, Illuminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6950F, 0.3050F), new CieXyChromaticityCoordinates(0.2600F, 0.7000F), new CieXyChromaticityCoordinates(0.1100F, 0.0050F)));
public static readonly RgbWorkingSpace EktaSpacePS5 = new GammaWorkingSpace(2.2F, Illuminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6950F, 0.3050F), new CieXyChromaticityCoordinates(0.2600F, 0.7000F), new CieXyChromaticityCoordinates(0.1100F, 0.0050F)));
/// <summary>
/// NTSC Rgb working space.
/// </summary>
public static readonly RgbWorkingSpaceBase NTSCRgb = new GammaWorkingSpace(2.2F, Illuminants.C, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6700F, 0.3300F), new CieXyChromaticityCoordinates(0.2100F, 0.7100F), new CieXyChromaticityCoordinates(0.1400F, 0.0800F)));
public static readonly RgbWorkingSpace NTSCRgb = new GammaWorkingSpace(2.2F, Illuminants.C, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6700F, 0.3300F), new CieXyChromaticityCoordinates(0.2100F, 0.7100F), new CieXyChromaticityCoordinates(0.1400F, 0.0800F)));
/// <summary>
/// PAL/SECAM Rgb working space.
/// </summary>
public static readonly RgbWorkingSpaceBase PALSECAMRgb = new GammaWorkingSpace(2.2F, Illuminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.2900F, 0.6000F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F)));
public static readonly RgbWorkingSpace PALSECAMRgb = new GammaWorkingSpace(2.2F, Illuminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6400F, 0.3300F), new CieXyChromaticityCoordinates(0.2900F, 0.6000F), new CieXyChromaticityCoordinates(0.1500F, 0.0600F)));
/// <summary>
/// ProPhoto Rgb working space.
/// </summary>
public static readonly RgbWorkingSpaceBase ProPhotoRgb = new GammaWorkingSpace(1.8F, Illuminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7347F, 0.2653F), new CieXyChromaticityCoordinates(0.1596F, 0.8404F), new CieXyChromaticityCoordinates(0.0366F, 0.0001F)));
public static readonly RgbWorkingSpace ProPhotoRgb = new GammaWorkingSpace(1.8F, Illuminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7347F, 0.2653F), new CieXyChromaticityCoordinates(0.1596F, 0.8404F), new CieXyChromaticityCoordinates(0.0366F, 0.0001F)));
/// <summary>
/// SMPTE-C Rgb working space.
/// </summary>
public static readonly RgbWorkingSpaceBase SMPTECRgb = new GammaWorkingSpace(2.2F, Illuminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6300F, 0.3400F), new CieXyChromaticityCoordinates(0.3100F, 0.5950F), new CieXyChromaticityCoordinates(0.1550F, 0.0700F)));
public static readonly RgbWorkingSpace SMPTECRgb = new GammaWorkingSpace(2.2F, Illuminants.D65, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.6300F, 0.3400F), new CieXyChromaticityCoordinates(0.3100F, 0.5950F), new CieXyChromaticityCoordinates(0.1550F, 0.0700F)));
/// <summary>
/// Wide Gamut Rgb working space.
/// </summary>
public static readonly RgbWorkingSpaceBase WideGamutRgb = new GammaWorkingSpace(2.2F, Illuminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7350F, 0.2650F), new CieXyChromaticityCoordinates(0.1150F, 0.8260F), new CieXyChromaticityCoordinates(0.1570F, 0.0180F)));
public static readonly RgbWorkingSpace WideGamutRgb = new GammaWorkingSpace(2.2F, Illuminants.D50, new RgbPrimariesChromaticityCoordinates(new CieXyChromaticityCoordinates(0.7350F, 0.2650F), new CieXyChromaticityCoordinates(0.1150F, 0.8260F), new CieXyChromaticityCoordinates(0.1570F, 0.0180F)));
}
}

2
src/ImageSharp/Formats/PngFilterMethod.cs → src/ImageSharp/Formats/Png/PngFilterMethod.cs

@ -1,7 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Formats
namespace SixLabors.ImageSharp.Formats.Png
{
/// <summary>
/// Provides enumeration of available PNG filter methods.

104
src/ImageSharp/PixelFormats/ColorBuilder{TPixel}.cs

@ -1,104 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Buffers.Binary;
using System.Globalization;
namespace SixLabors.ImageSharp.PixelFormats
{
/// <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 ColorBuilder<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// 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="TPixel"/> that represents the color defined by the provided RGBA hex string.</returns>
public static TPixel FromHex(string hex)
{
Guard.NotNullOrWhiteSpace(hex, nameof(hex));
hex = ToRgbaHex(hex);
if (hex is null || !uint.TryParse(hex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out uint packedValue))
{
throw new ArgumentException("Hexadecimal string is not in the correct format.", nameof(hex));
}
TPixel result = default;
var rgba = new Rgba32(BinaryPrimitives.ReverseEndianness(packedValue));
result.FromRgba32(rgba);
return result;
}
/// <summary>
/// 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="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) => FromRgba(red, green, blue, 255);
/// <summary>
/// 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="TPixel"/> that represents the color defined by the provided RGBA values.</returns>
public static TPixel FromRgba(byte red, byte green, byte blue, byte alpha)
{
TPixel color = default;
color.FromRgba32(new Rgba32(red, green, blue, alpha));
return color;
}
/// <summary>
/// Converts the specified hex value to an rrggbbaa hex value.
/// </summary>
/// <param name="hex">The hex value to convert.</param>
/// <returns>
/// A rrggbbaa hex value.
/// </returns>
private static string ToRgbaHex(string hex)
{
if (hex[0] == '#')
{
hex = hex.Substring(1);
}
if (hex.Length == 8)
{
return hex;
}
if (hex.Length == 6)
{
return hex + "FF";
}
if (hex.Length < 3 || hex.Length > 4)
{
return null;
}
char r = hex[0];
char g = hex[1];
char b = hex[2];
char a = hex.Length == 3 ? 'F' : hex[3];
return new string(new[] { r, r, g, g, b, b, a, a });
}
}
}

761
src/ImageSharp/PixelFormats/NamedColors{TPixel}.cs

@ -1,761 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.PixelFormats
{
/// <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>
/// Thread-safe backing field for the constant palettes.
/// </summary>
private static readonly Lazy<TPixel[]> WebSafePaletteLazy = new Lazy<TPixel[]>(GetWebSafePalette, true);
private static readonly Lazy<TPixel[]> WernerPaletteLazy = new Lazy<TPixel[]>(GetWernerPalette, true);
/// <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);
/// <summary>
/// Gets a <see cref="T:TPixel[]"/> collection of web safe, colors as defined in the CSS Color Module Level 4.
/// </summary>
public static TPixel[] WebSafePalette => WebSafePaletteLazy.Value;
/// <summary>
/// Gets a <see cref="T:TPixel[]"/> collection of colors as defined in the original second edition of Werner’s Nomenclature of Colours 1821.
/// The hex codes were collected and defined by Nicholas Rougeux <see href="https://www.c82.net/werner"/>
/// </summary>
public static TPixel[] WernerPalette => WernerPaletteLazy.Value;
private static TPixel[] GetWebSafePalette() => GetPalette(ColorConstants.WebSafeColors);
private static TPixel[] GetWernerPalette() => GetPalette(ColorConstants.WernerColors);
private static TPixel[] GetPalette(Rgba32[] palette)
{
var converted = new TPixel[palette.Length];
Span<byte> constantsBytes = MemoryMarshal.Cast<Rgba32, byte>(palette.AsSpan());
PixelOperations<TPixel>.Instance.FromRgba32Bytes(
Configuration.Default,
constantsBytes,
converted,
palette.Length);
return converted;
}
}
}

55
src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs

@ -1,6 +1,9 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Buffers.Binary;
using System.Globalization;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -233,7 +236,20 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <returns>
/// The <see cref="Rgba32"/>.
/// </returns>
public static Rgba32 FromHex(string hex) => ColorBuilder<Rgba32>.FromHex(hex);
public static Rgba32 FromHex(string hex)
{
Guard.NotNullOrWhiteSpace(hex, nameof(hex));
hex = ToRgbaHex(hex);
if (hex is null || !uint.TryParse(hex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out uint packedValue))
{
throw new ArgumentException("Hexadecimal string is not in the correct format.", nameof(hex));
}
packedValue = BinaryPrimitives.ReverseEndianness(packedValue);
return Unsafe.As<uint, Rgba32>(ref packedValue);
}
/// <inheritdoc />
public PixelOperations<Rgba32> CreatePixelOperations() => new PixelOperations();
@ -426,5 +442,42 @@ namespace SixLabors.ImageSharp.PixelFormats
this.B = (byte)vector.Z;
this.A = (byte)vector.W;
}
/// <summary>
/// Converts the specified hex value to an rrggbbaa hex value.
/// </summary>
/// <param name="hex">The hex value to convert.</param>
/// <returns>
/// A rrggbbaa hex value.
/// </returns>
private static string ToRgbaHex(string hex)
{
if (hex[0] == '#')
{
hex = hex.Substring(1);
}
if (hex.Length == 8)
{
return hex;
}
if (hex.Length == 6)
{
return hex + "FF";
}
if (hex.Length < 3 || hex.Length > 4)
{
return null;
}
char r = hex[0];
char g = hex[1];
char b = hex[2];
char a = hex.Length == 3 ? 'F' : hex[3];
return new string(new[] { r, r, g, g, b, b, a, a });
}
}
}

2
src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs

@ -94,7 +94,7 @@ namespace SixLabors.ImageSharp.PixelFormats
/// <returns>
/// The <see cref="RgbaVector"/>.
/// </returns>
public static RgbaVector FromHex(string hex) => ColorBuilder<RgbaVector>.FromHex(hex);
public static RgbaVector FromHex(string hex) => Color.FromHex(hex).ToPixel<RgbaVector>();
/// <inheritdoc />
public PixelOperations<RgbaVector> CreatePixelOperations() => new PixelOperations();

14
src/ImageSharp/Processing/DefaultInternalImageProcessorContext.cs → src/ImageSharp/Processing/DefaultImageProcessorContext.cs

@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Processing
/// Performs processor application operations on the source image
/// </summary>
/// <typeparam name="TPixel">The pixel format</typeparam>
internal class DefaultInternalImageProcessorContext<TPixel> : IInternalImageProcessingContext<TPixel>
internal class DefaultImageProcessorContext<TPixel> : IInternalImageProcessingContext<TPixel>
where TPixel : struct, IPixel<TPixel>
{
private readonly bool mutate;
@ -21,11 +21,11 @@ namespace SixLabors.ImageSharp.Processing
private Image<TPixel> destination;
/// <summary>
/// Initializes a new instance of the <see cref="DefaultInternalImageProcessorContext{TPixel}"/> class.
/// Initializes a new instance of the <see cref="DefaultImageProcessorContext{TPixel}"/> class.
/// </summary>
/// <param name="source">The image.</param>
/// <param name="mutate">The mutate.</param>
public DefaultInternalImageProcessorContext(Image<TPixel> source, bool mutate)
public DefaultImageProcessorContext(Image<TPixel> source, bool mutate)
{
this.mutate = mutate;
this.source = source;
@ -39,7 +39,7 @@ namespace SixLabors.ImageSharp.Processing
public MemoryAllocator MemoryAllocator => this.source.GetConfiguration().MemoryAllocator;
/// <inheritdoc/>
public Image<TPixel> Apply()
public Image<TPixel> GetResultImage()
{
if (!this.mutate && this.destination is null)
{
@ -65,8 +65,7 @@ namespace SixLabors.ImageSharp.Processing
return this.ApplyProcessor(processorImplementation);
}
/// <inheritdoc/>
public IImageProcessingContext<TPixel> ApplyProcessor(IImageProcessor<TPixel> processor, Rectangle rectangle)
private IImageProcessingContext ApplyProcessor(IImageProcessor<TPixel> processor, Rectangle rectangle)
{
if (!this.mutate && this.destination is null)
{
@ -86,8 +85,7 @@ namespace SixLabors.ImageSharp.Processing
return this;
}
/// <inheritdoc/>
public IImageProcessingContext<TPixel> ApplyProcessor(IImageProcessor<TPixel> processor)
private IImageProcessingContext ApplyProcessor(IImageProcessor<TPixel> processor)
{
return this.ApplyProcessor(processor, this.GetCurrentBounds());
}

8
src/ImageSharp/Processing/Extensions/BinaryDiffuseExtensions.cs

@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Processing
/// <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="IImageProcessingContext{TPixel}"/> to allow chaining of operations.</returns>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext BinaryDiffuse(
this IImageProcessingContext source,
IErrorDiffuser diffuser,
@ -35,7 +35,7 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="IImageProcessingContext{TPixel}"/> to allow chaining of operations.</returns>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext BinaryDiffuse(
this IImageProcessingContext source,
IErrorDiffuser diffuser,
@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="threshold">The threshold to apply binarization of the image. Must be between 0 and 1.</param>
/// <param name="upperColor">The color to use for pixels that are above the threshold.</param>
/// <param name="lowerColor">The color to use for pixels that are below the threshold</param>
/// <returns>The <see cref="IImageProcessingContext{TPixel}"/> to allow chaining of operations.</returns>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext BinaryDiffuse(
this IImageProcessingContext source,
IErrorDiffuser diffuser,
@ -71,7 +71,7 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="IImageProcessingContext{TPixel}"/> to allow chaining of operations.</returns>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext BinaryDiffuse(
this IImageProcessingContext source,
IErrorDiffuser diffuser,

8
src/ImageSharp/Processing/Extensions/BinaryDitherExtensions.cs

@ -18,7 +18,7 @@ namespace SixLabors.ImageSharp.Processing
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="dither">The ordered ditherer.</param>
/// <returns>The <see cref="IImageProcessingContext{TPixel}"/> to allow chaining of operations.</returns>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext
BinaryDither(this IImageProcessingContext source, IOrderedDither dither) =>
source.ApplyProcessor(new BinaryOrderedDitherProcessor(dither));
@ -30,7 +30,7 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="dither">The ordered ditherer.</param>
/// <param name="upperColor">The color to use for pixels that are above the threshold.</param>
/// <param name="lowerColor">The color to use for pixels that are below the threshold</param>
/// <returns>The <see cref="IImageProcessingContext{TPixel}"/> to allow chaining of operations.</returns>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext BinaryDither(
this IImageProcessingContext source,
IOrderedDither dither,
@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="IImageProcessingContext{TPixel}"/> to allow chaining of operations.</returns>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext BinaryDither(
this IImageProcessingContext source,
IOrderedDither dither,
@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="IImageProcessingContext{TPixel}"/> to allow chaining of operations.</returns>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext BinaryDither(
this IImageProcessingContext source,
IOrderedDither dither,

37
src/ImageSharp/Processing/Extensions/ProcessingExtensions.cs

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
@ -13,18 +14,6 @@ namespace SixLabors.ImageSharp.Processing
/// </summary>
public static class ProcessingExtensions
{
/// <summary>
/// Applies the given operation to the mutable image.
/// Useful when we need to extract information like Width/Height to parametrize the next operation working on the <see cref="IImageProcessingContext{TPixel}"/> chain.
/// To achieve this the method actually implements an "inline" <see cref="IImageProcessor{TPixel}"/> with <paramref name="operation"/> as it's processing logic.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image to mutate.</param>
/// <param name="operation">The operation to perform on the source.</param>
/// <returns>The <see cref="IImageProcessingContext{TPixel}"/> to allow chaining of operations.</returns>
public static IImageProcessingContext<TPixel> Apply<TPixel>(this IImageProcessingContext<TPixel> source, Action<Image<TPixel>> operation)
where TPixel : struct, IPixel<TPixel> => source.ApplyProcessor(new DelegateProcessor<TPixel>(operation));
/// <summary>
/// Mutates the source image by applying the image operation to it.
/// </summary>
@ -48,9 +37,9 @@ namespace SixLabors.ImageSharp.Processing
Guard.NotNull(operation, nameof(operation));
Guard.NotNull(source, nameof(source));
IInternalImageProcessingContext<TPixel> operationsRunner = source.GetConfiguration().ImageOperationsProvider.CreateImageProcessingContext(source, true);
IInternalImageProcessingContext<TPixel> operationsRunner = source.GetConfiguration().ImageOperationsProvider
.CreateImageProcessingContext(source, true);
operation(operationsRunner);
operationsRunner.Apply();
}
/// <summary>
@ -65,9 +54,9 @@ namespace SixLabors.ImageSharp.Processing
Guard.NotNull(operations, nameof(operations));
Guard.NotNull(source, nameof(source));
IInternalImageProcessingContext<TPixel> operationsRunner = source.GetConfiguration().ImageOperationsProvider.CreateImageProcessingContext(source, true);
IInternalImageProcessingContext<TPixel> operationsRunner = source.GetConfiguration().ImageOperationsProvider
.CreateImageProcessingContext(source, true);
operationsRunner.ApplyProcessors(operations);
operationsRunner.Apply();
}
/// <summary>
@ -96,9 +85,10 @@ namespace SixLabors.ImageSharp.Processing
Guard.NotNull(operation, nameof(operation));
Guard.NotNull(source, nameof(source));
IInternalImageProcessingContext<TPixel> operationsRunner = source.GetConfiguration().ImageOperationsProvider.CreateImageProcessingContext(source, false);
IInternalImageProcessingContext<TPixel> operationsRunner = source.GetConfiguration().ImageOperationsProvider
.CreateImageProcessingContext(source, false);
operation(operationsRunner);
return operationsRunner.Apply();
return operationsRunner.GetResultImage();
}
/// <summary>
@ -114,9 +104,10 @@ namespace SixLabors.ImageSharp.Processing
Guard.NotNull(operations, nameof(operations));
Guard.NotNull(source, nameof(source));
IInternalImageProcessingContext<TPixel> operationsRunner = source.GetConfiguration().ImageOperationsProvider.CreateImageProcessingContext(source, false);
IInternalImageProcessingContext<TPixel> operationsRunner = source.GetConfiguration().ImageOperationsProvider
.CreateImageProcessingContext(source, false);
operationsRunner.ApplyProcessors(operations);
return operationsRunner.Apply();
return operationsRunner.GetResultImage();
}
/// <summary>
@ -125,7 +116,9 @@ namespace SixLabors.ImageSharp.Processing
/// <param name="source">The image processing context.</param>
/// <param name="operations">The operations to perform on the source.</param>
/// <returns>The <see cref="IImageProcessor{TPixel}"/> to allow chaining of operations.</returns>
public static IImageProcessingContext ApplyProcessors(this IImageProcessingContext source, params IImageProcessor[] operations)
public static IImageProcessingContext ApplyProcessors(
this IImageProcessingContext source,
params IImageProcessor[] operations)
{
foreach (IImageProcessor p in operations)
{
@ -155,7 +148,7 @@ namespace SixLabors.ImageSharp.Processing
IInternalImageProcessingContext<TPixel> operationsRunner = image.GetConfiguration()
.ImageOperationsProvider.CreateImageProcessingContext(image, this.mutate);
this.operation(operationsRunner);
this.ResultImage = operationsRunner.Apply();
this.ResultImage = operationsRunner.GetResultImage();
}
}
}

2
src/ImageSharp/Processing/IImageProcessingContextFactory.cs

@ -30,7 +30,7 @@ namespace SixLabors.ImageSharp.Processing
public IInternalImageProcessingContext<TPixel> CreateImageProcessingContext<TPixel>(Image<TPixel> source, bool mutate)
where TPixel : struct, IPixel<TPixel>
{
return new DefaultInternalImageProcessorContext<TPixel>(source, mutate);
return new DefaultImageProcessorContext<TPixel>(source, mutate);
}
}
}

46
src/ImageSharp/Processing/IImageProcessingContext{TPixel}.cs

@ -1,46 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing
{
/// <summary>
/// A pixel-specific interface to queue up image operations to apply to an image.
/// </summary>
/// <typeparam name="TPixel">The pixel format</typeparam>
public interface IImageProcessingContext<TPixel> : IImageProcessingContext
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Adds the processor to the current set of image operations to be applied.
/// </summary>
/// <param name="processor">The processor to apply.</param>
/// <param name="rectangle">The area to apply it to.</param>
/// <returns>The current operations class to allow chaining of operations.</returns>
IImageProcessingContext<TPixel> ApplyProcessor(IImageProcessor<TPixel> processor, Rectangle rectangle);
/// <summary>
/// Adds the processor to the current set of image operations to be applied.
/// </summary>
/// <param name="processor">The processor to apply</param>
/// <returns>The current operations class to allow chaining of operations.</returns>
IImageProcessingContext<TPixel> ApplyProcessor(IImageProcessor<TPixel> processor);
}
/// <summary>
/// An internal interface to queue up image operations and have a method to apply them to and return a result
/// </summary>
/// <typeparam name="TPixel">The pixel format</typeparam>
internal interface IInternalImageProcessingContext<TPixel> : IImageProcessingContext<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Adds the processors to the current image
/// </summary>
/// <returns>The current image or a new image depending on whether this is allowed to mutate the source image.</returns>
Image<TPixel> Apply();
}
}

22
src/ImageSharp/Processing/IInternalImageProcessingContext.cs

@ -0,0 +1,22 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Processing
{
/// <summary>
/// An interface for internal operations we don't want to expose on <see cref="IImageProcessingContext"/>.
/// </summary>
/// <typeparam name="TPixel">The pixel type.</typeparam>
internal interface IInternalImageProcessingContext<TPixel> : IImageProcessingContext
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Returns the result image to return by <see cref="ProcessingExtensions.Clone"/>
/// (and other overloads).
/// </summary>
/// <returns>The current image or a new image depending on whether it is requested to mutate the source image.</returns>
Image<TPixel> GetResultImage();
}
}

43
src/ImageSharp/Processing/Processors/DelegateProcessor.cs

@ -1,43 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Processors
{
/// <summary>
/// Allows the application of processing algorithms to images via an action delegate
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class DelegateProcessor<TPixel> : ImageProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Initializes a new instance of the <see cref="DelegateProcessor{TPixel}"/> class.
/// </summary>
/// <param name="action">The action.</param>
public DelegateProcessor(Action<Image<TPixel>> action)
{
this.Action = action;
}
/// <summary>
/// Gets the action that will be applied to the image.
/// </summary>
internal Action<Image<TPixel>> Action { get; }
/// <inheritdoc/>
protected override void BeforeImageApply(Image<TPixel> source, Rectangle sourceRectangle)
{
this.Action?.Invoke(source);
}
/// <inheritdoc/>
protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{
// NOP, we did all we wanted to do inside BeforeImageApply
}
}
}

2
src/ImageSharp/Processing/Processors/Dithering/AtkinsonDiffuser.cs

@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
/// Applies error diffusion based dithering using the Atkinson image dithering algorithm.
/// <see href="http://www.efg2.com/Lab/Library/ImageProcessing/DHALF.TXT"/>
/// </summary>
public sealed class AtkinsonDiffuser : ErrorDiffuserBase
public sealed class AtkinsonDiffuser : ErrorDiffuser
{
/// <summary>
/// The diffusion matrix

2
src/ImageSharp/Processing/Processors/Dithering/BurksDiffuser.cs

@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
/// Applies error diffusion based dithering using the Burks image dithering algorithm.
/// <see href="http://www.efg2.com/Lab/Library/ImageProcessing/DHALF.TXT"/>
/// </summary>
public sealed class BurksDiffuser : ErrorDiffuserBase
public sealed class BurksDiffuser : ErrorDiffuser
{
/// <summary>
/// The diffusion matrix

6
src/ImageSharp/Processing/Processors/Dithering/ErrorDiffuserBase.cs → src/ImageSharp/Processing/Processors/Dithering/ErrorDiffuser.cs

@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
/// <summary>
/// The base class for performing error diffusion based dithering.
/// </summary>
public abstract class ErrorDiffuserBase : IErrorDiffuser
public abstract class ErrorDiffuser : IErrorDiffuser
{
/// <summary>
/// The vector to perform division.
@ -41,11 +41,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
private readonly DenseMatrix<float> matrix;
/// <summary>
/// Initializes a new instance of the <see cref="ErrorDiffuserBase"/> class.
/// Initializes a new instance of the <see cref="ErrorDiffuser"/> class.
/// </summary>
/// <param name="matrix">The dithering matrix.</param>
/// <param name="divisor">The divisor.</param>
internal ErrorDiffuserBase(in DenseMatrix<float> matrix, byte divisor)
internal ErrorDiffuser(in DenseMatrix<float> matrix, byte divisor)
{
Guard.MustBeGreaterThan(divisor, 0, nameof(divisor));

2
src/ImageSharp/Processing/Processors/Dithering/FloydSteinbergDiffuser.cs

@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
/// Applies error diffusion based dithering using the Floyd–Steinberg image dithering algorithm.
/// <see href="http://www.efg2.com/Lab/Library/ImageProcessing/DHALF.TXT"/>
/// </summary>
public sealed class FloydSteinbergDiffuser : ErrorDiffuserBase
public sealed class FloydSteinbergDiffuser : ErrorDiffuser
{
/// <summary>
/// The diffusion matrix

2
src/ImageSharp/Processing/Processors/Dithering/JarvisJudiceNinkeDiffuser.cs

@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
/// Applies error diffusion based dithering using the JarvisJudiceNinke image dithering algorithm.
/// <see href="http://www.efg2.com/Lab/Library/ImageProcessing/DHALF.TXT"/>
/// </summary>
public sealed class JarvisJudiceNinkeDiffuser : ErrorDiffuserBase
public sealed class JarvisJudiceNinkeDiffuser : ErrorDiffuser
{
/// <summary>
/// The diffusion matrix

2
src/ImageSharp/Processing/Processors/Dithering/Sierra2Diffuser.cs

@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
/// Applies error diffusion based dithering using the Sierra2 image dithering algorithm.
/// <see href="http://www.efg2.com/Lab/Library/ImageProcessing/DHALF.TXT"/>
/// </summary>
public sealed class Sierra2Diffuser : ErrorDiffuserBase
public sealed class Sierra2Diffuser : ErrorDiffuser
{
/// <summary>
/// The diffusion matrix

2
src/ImageSharp/Processing/Processors/Dithering/Sierra3Diffuser.cs

@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
/// Applies error diffusion based dithering using the Sierra3 image dithering algorithm.
/// <see href="http://www.efg2.com/Lab/Library/ImageProcessing/DHALF.TXT"/>
/// </summary>
public sealed class Sierra3Diffuser : ErrorDiffuserBase
public sealed class Sierra3Diffuser : ErrorDiffuser
{
/// <summary>
/// The diffusion matrix

2
src/ImageSharp/Processing/Processors/Dithering/SierraLiteDiffuser.cs

@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
/// Applies error diffusion based dithering using the SierraLite image dithering algorithm.
/// <see href="http://www.efg2.com/Lab/Library/ImageProcessing/DHALF.TXT"/>
/// </summary>
public sealed class SierraLiteDiffuser : ErrorDiffuserBase
public sealed class SierraLiteDiffuser : ErrorDiffuser
{
/// <summary>
/// The diffusion matrix

2
src/ImageSharp/Processing/Processors/Dithering/StevensonArceDiffuser.cs

@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
/// <summary>
/// Applies error diffusion based dithering using the Stevenson-Arce image dithering algorithm.
/// </summary>
public sealed class StevensonArceDiffuser : ErrorDiffuserBase
public sealed class StevensonArceDiffuser : ErrorDiffuser
{
/// <summary>
/// The diffusion matrix

2
src/ImageSharp/Processing/Processors/Dithering/StuckiDiffuser.cs

@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Dithering
/// Applies error diffusion based dithering using the Stucki image dithering algorithm.
/// <see href="http://www.efg2.com/Lab/Library/ImageProcessing/DHALF.TXT"/>
/// </summary>
public sealed class StuckiDiffuser : ErrorDiffuserBase
public sealed class StuckiDiffuser : ErrorDiffuser
{
/// <summary>
/// The diffusion matrix

2
src/ImageSharp/Processing/Processors/Transforms/AffineTransformProcessor{TPixel}.cs

@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
/// Provides the base methods to perform affine transforms on an image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class AffineTransformProcessor<TPixel> : TransformProcessorBase<TPixel>
internal class AffineTransformProcessor<TPixel> : TransformProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
public AffineTransformProcessor(AffineTransformProcessor definition)

2
src/ImageSharp/Processing/Processors/Transforms/CropProcessor{TPixel}.cs

@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
/// Provides methods to allow the cropping of an image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class CropProcessor<TPixel> : TransformProcessorBase<TPixel>
internal class CropProcessor<TPixel> : TransformProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
private readonly CropProcessor definition;

2
src/ImageSharp/Processing/Processors/Transforms/ProjectiveTransformProcessor{TPixel}.cs

@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
/// Provides the base methods to perform non-affine transforms on an image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class ProjectiveTransformProcessor<TPixel> : TransformProcessorBase<TPixel>
internal class ProjectiveTransformProcessor<TPixel> : TransformProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
private readonly ProjectiveTransformProcessor definition;

2
src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs

@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
/// The original code has been adapted from <see href="http://www.realtimerendering.com/resources/GraphicsGems/gemsiii/filter_rcg.c"/>.
/// </remarks>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class ResizeProcessor<TPixel> : TransformProcessorBase<TPixel>
internal class ResizeProcessor<TPixel> : TransformProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
// The following fields are not immutable but are optionally created on demand.

2
src/ImageSharp/Processing/Processors/Transforms/TransformProcessorBase.cs → src/ImageSharp/Processing/Processors/Transforms/TransformProcessor.cs

@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
/// The base class for all transform processors. Any processor that changes the dimensions of the image should inherit from this.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal abstract class TransformProcessorBase<TPixel> : CloningImageProcessor<TPixel>
internal abstract class TransformProcessor<TPixel> : CloningImageProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <inheritdoc/>

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

@ -28,7 +28,7 @@ namespace SixLabors.ImageSharp.Benchmarks
public void Setup()
{
this.bulk = new GlowProcessor(Color.Beige, 800 * .5f, GraphicsOptions.Default);
this.parallel = new GlowProcessorParallel<Rgba32>(NamedColors<Rgba32>.Beige) { Radius = 800 * .5f, };
this.parallel = new GlowProcessorParallel<Rgba32>(Color.Beige) { Radius = 800 * .5f, };
}
[Benchmark(Description = "ImageSharp Glow - Bulk")]

2
tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs

@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Tests
{
public abstract class BaseImageOperationsExtensionTest
{
protected readonly IImageProcessingContext<Rgba32> operations;
protected readonly IImageProcessingContext operations;
private readonly FakeImageOperationsProvider.FakeImageOperations<Rgba32> internalOperations;
protected readonly Rectangle rect;
protected readonly GraphicsOptions options;

6
tests/ImageSharp.Tests/Colorspaces/Conversion/ApproximateColorspaceComparer.cs

@ -28,7 +28,7 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces.Conversion
IEqualityComparer<CieXyChromaticityCoordinates>,
IEqualityComparer<RgbPrimariesChromaticityCoordinates>,
IEqualityComparer<GammaWorkingSpace>,
IEqualityComparer<RgbWorkingSpaceBase>
IEqualityComparer<RgbWorkingSpace>
{
private readonly float Epsilon;
@ -222,14 +222,14 @@ namespace SixLabors.ImageSharp.Tests.Colorspaces.Conversion
public int GetHashCode(GammaWorkingSpace obj) => obj.GetHashCode();
/// <inheritdoc/>
public bool Equals(RgbWorkingSpaceBase x, RgbWorkingSpaceBase y)
public bool Equals(RgbWorkingSpace x, RgbWorkingSpace y)
{
return this.Equals(x.WhitePoint, y.WhitePoint)
&& this.Equals(x.ChromaticityCoordinates, y.ChromaticityCoordinates);
}
/// <inheritdoc/>
public int GetHashCode(RgbWorkingSpaceBase obj) => obj.GetHashCode();
public int GetHashCode(RgbWorkingSpace obj) => obj.GetHashCode();
private bool Equals(float x, float y)
{

21
tests/ImageSharp.Tests/FakeImageOperationsProvider.cs

@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Tests
public MemoryAllocator MemoryAllocator => this.Source.GetConfiguration().MemoryAllocator;
public Image<TPixel> Apply()
public Image<TPixel> GetResultImage()
{
return this.Source;
}
@ -86,25 +86,6 @@ namespace SixLabors.ImageSharp.Tests
return this;
}
public IImageProcessingContext<TPixel> ApplyProcessor(IImageProcessor<TPixel> processor, Rectangle rectangle)
{
this.Applied.Add(new AppliedOperation
{
GenericProcessor = processor,
Rectangle = rectangle
});
return this;
}
public IImageProcessingContext<TPixel> ApplyProcessor(IImageProcessor<TPixel> processor)
{
this.Applied.Add(new AppliedOperation
{
GenericProcessor = processor
});
return this;
}
public struct AppliedOperation
{
public Rectangle? Rectangle { get; set; }

60
tests/ImageSharp.Tests/Image/ImageProcessingContextTests.cs

@ -1,60 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives;
using Xunit;
namespace SixLabors.ImageSharp.Tests
{
public class ImageProcessingContextTests
{
// [Fact]
// public void MutatedSizeIsAccuratePerOperation()
// {
// var x500 = new Size(500, 500);
// var x400 = new Size(400, 400);
// var x300 = new Size(300, 300);
// var x200 = new Size(200, 200);
// var x100 = new Size(100, 100);
// using (var image = new Image<Rgba32>(500, 500))
// {
// image.Mutate(x =>
// x.AssertSize(x500)
// .Resize(x400).AssertSize(x400)
// .Resize(x300).AssertSize(x300)
// .Resize(x200).AssertSize(x200)
// .Resize(x100).AssertSize(x100));
// }
// }
//
// [Fact]
// public void ClonedSizeIsAccuratePerOperation()
// {
// var x500 = new Size(500, 500);
// var x400 = new Size(400, 400);
// var x300 = new Size(300, 300);
// var x200 = new Size(200, 200);
// var x100 = new Size(100, 100);
// using (var image = new Image<Rgba32>(500, 500))
// {
// image.Clone(x =>
// x.AssertSize(x500)
// .Resize(x400).AssertSize(x400)
// .Resize(x300).AssertSize(x300)
// .Resize(x200).AssertSize(x200)
// .Resize(x100).AssertSize(x100));
// }
// }
}
public static class SizeAssertationExtensions
{
public static IImageProcessingContext<Rgba32> AssertSize(this IImageProcessingContext<Rgba32> context, Size size)
{
Assert.Equal(size, context.GetCurrentSize());
return context;
}
}
}

8
tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs

@ -113,8 +113,8 @@ namespace SixLabors.ImageSharp.Tests
using (var memoryManager = new BitmapMemoryManager(bmp))
{
Memory<Bgra32> memory = memoryManager.Memory;
Bgra32 bg = NamedColors<Bgra32>.Red;
Bgra32 fg = NamedColors<Bgra32>.Green;
Bgra32 bg = Color.Red;
Bgra32 fg = Color.Green;
using (var image = Image.WrapMemory(memory, bmp.Width, bmp.Height))
{
@ -144,8 +144,8 @@ namespace SixLabors.ImageSharp.Tests
using (var bmp = new Bitmap(51, 23))
{
var memoryManager = new BitmapMemoryManager(bmp);
Bgra32 bg = NamedColors<Bgra32>.Red;
Bgra32 fg = NamedColors<Bgra32>.Green;
Bgra32 bg = Color.Red;
Bgra32 fg = Color.Green;
using (var image = Image.WrapMemory(memoryManager, bmp.Width, bmp.Height))
{

40
tests/ImageSharp.Tests/PixelFormats/ColorBuilderTests.cs

@ -1,40 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Colors
{
public class ColorBuilderTests
{
[Fact]
public void ParseShortHex()
{
Assert.Equal(new Rgb24(255, 255, 255), ColorBuilder<Rgb24>.FromHex("#fff"));
Assert.Equal(new Rgb24(255, 255, 255), ColorBuilder<Rgb24>.FromHex("fff"));
Assert.Equal(new Rgba32(0, 0, 0, 255), ColorBuilder<Rgba32>.FromHex("000f"));
}
[Fact]
public void ParseHexLeadingPoundIsOptional()
{
Assert.Equal(new Rgb24(0, 128, 128), ColorBuilder<Rgb24>.FromHex("#008080"));
Assert.Equal(new Rgb24(0, 128, 128), ColorBuilder<Rgb24>.FromHex("008080"));
}
[Fact]
public void ParseHexThrowsOnEmpty()
{
Assert.Throws<ArgumentException>(() => ColorBuilder<Rgb24>.FromHex(""));
}
[Fact]
public void ParseHexThrowsOnNull()
{
Assert.Throws<ArgumentNullException>(() => ColorBuilder<Rgb24>.FromHex(null));
}
}
}

46
tests/ImageSharp.Tests/PixelFormats/ColorDefinitionTests.cs

@ -1,46 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;
namespace SixLabors.ImageSharp.Tests
{
public class ColorDefinitionTests
{
public static TheoryData<string> ColorNames
{
get
{
var result = new TheoryData<string>();
foreach (string name in typeof(NamedColors<Rgba32>).GetTypeInfo()
.GetFields().Where(x => x.Name != nameof(NamedColors<Rgba32>.WebSafePalette)).Select(x => x.Name))
{
result.Add(name);
}
return result;
}
}
[Theory]
[MemberData(nameof(ColorNames))]
public void AllColorsAreOnGenericAndBaseColor(string name)
{
FieldInfo generic = typeof(NamedColors<Rgba32>).GetTypeInfo().GetField(name);
FieldInfo specific = typeof(Rgba32).GetTypeInfo().GetField(name);
Assert.NotNull(specific);
Assert.NotNull(generic);
Assert.True(specific.Attributes.HasFlag(FieldAttributes.Public), "specific must be public");
Assert.True(specific.Attributes.HasFlag(FieldAttributes.Static), "specific must be static");
Assert.True(generic.Attributes.HasFlag(FieldAttributes.Public), "generic must be public");
Assert.True(generic.Attributes.HasFlag(FieldAttributes.Static), "generic must be static");
Rgba32 expected = (Rgba32)generic.GetValue(null);
Rgba32 actual = (Rgba32)specific.GetValue(null);
Assert.Equal(expected, actual);
}
}
}

25
tests/ImageSharp.Tests/Processing/DelegateTest.cs

@ -1,25 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing
{
using SixLabors.ImageSharp.Processing.Processors;
public class DelegateTest : BaseImageOperationsExtensionTest
{
[Fact]
public void Run_CreatedDelegateProcessor()
{
Action<Image<Rgba32>> action = (i) => { };
this.operations.Apply(action);
DelegateProcessor<Rgba32> processor = this.Verify<DelegateProcessor<Rgba32>>();
Assert.Equal(action, processor.Action);
}
}
}

10
tests/ImageSharp.Tests/TestUtilities/ImageProviders/BasicTestPatternProvider.cs

@ -31,9 +31,9 @@ namespace SixLabors.ImageSharp.Tests
{
var result = new Image<TPixel>(this.Configuration, this.Width, this.Height);
TPixel topLeftColor = NamedColors<TPixel>.Red;
TPixel topRightColor = NamedColors<TPixel>.Green;
TPixel bottomLeftColor = NamedColors<TPixel>.Blue;
TPixel topLeftColor = Color.Red.ToPixel<TPixel>();
TPixel topRightColor = Color.Green.ToPixel<TPixel>();
TPixel bottomLeftColor = Color.Blue.ToPixel<TPixel>();
// Transparent purple:
TPixel bottomRightColor = default;
@ -47,7 +47,7 @@ namespace SixLabors.ImageSharp.Tests
Span<TPixel> row = result.GetPixelRowSpan(y);
row.Slice(0, midX).Fill(topLeftColor);
row.Slice(midX, this.Width-midX).Fill(topRightColor);
row.Slice(midX, this.Width - midX).Fill(topRightColor);
}
for (int y = midY; y < this.Height; y++)
@ -55,7 +55,7 @@ namespace SixLabors.ImageSharp.Tests
Span<TPixel> row = result.GetPixelRowSpan(y);
row.Slice(0, midX).Fill(bottomLeftColor);
row.Slice(midX, this.Width-midX).Fill(bottomRightColor);
row.Slice(midX, this.Width - midX).Fill(bottomRightColor);
}
return result;

31
tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs

@ -21,6 +21,16 @@ namespace SixLabors.ImageSharp.Tests
{
static readonly Dictionary<string, Image<TPixel>> TestImages = new Dictionary<string, Image<TPixel>>();
private static TPixel[] BlackWhitePixels = new[] {
Color.Black.ToPixel<TPixel>(),
Color.White.ToPixel<TPixel>()
};
private static TPixel[] PinkBluePixels = new[] {
Color.HotPink.ToPixel<TPixel>(),
Color.Blue.ToPixel<TPixel>()
};
public TestPatternProvider(int width, int height)
: base(width, height)
{
@ -80,12 +90,6 @@ namespace SixLabors.ImageSharp.Tests
stride = 1;
}
TPixel[] c =
{
NamedColors<TPixel>.HotPink,
NamedColors<TPixel>.Blue
};
for (int y = top; y < bottom; y++)
{
int p = 0;
@ -94,9 +98,9 @@ namespace SixLabors.ImageSharp.Tests
if (x % stride == 0)
{
p++;
p = p % c.Length;
p = p % PinkBluePixels.Length;
}
pixels[x, y] = c[p];
pixels[x, y] = PinkBluePixels[p];
}
}
}
@ -113,11 +117,6 @@ namespace SixLabors.ImageSharp.Tests
int top = 0;
int bottom = pixels.Height / 2;
int stride = pixels.Width / 6;
TPixel[] c =
{
NamedColors<TPixel>.Black,
NamedColors<TPixel>.White
};
int p = 0;
for (int y = top; y < bottom; y++)
@ -125,7 +124,7 @@ namespace SixLabors.ImageSharp.Tests
if (y % stride == 0)
{
p++;
p = p % c.Length;
p = p % BlackWhitePixels.Length;
}
int pstart = p;
for (int x = left; x < right; x++)
@ -133,9 +132,9 @@ namespace SixLabors.ImageSharp.Tests
if (x % stride == 0)
{
p++;
p = p % c.Length;
p = p % BlackWhitePixels.Length;
}
pixels[x, y] = c[p];
pixels[x, y] = BlackWhitePixels[p];
}
p = pstart;
}

Loading…
Cancel
Save