Browse Source

Rename type

pull/2922/head
James Jackson-South 1 year ago
parent
commit
ea564842c5
  1. 14
      src/ImageSharp/ColorProfiles/ColorConversionOptions.cs
  2. 6
      src/ImageSharp/ColorProfiles/KnownYCbCrMatrices.cs
  3. 4
      src/ImageSharp/ColorProfiles/Y.cs
  4. 8
      src/ImageSharp/ColorProfiles/YCbCr.cs
  5. 10
      src/ImageSharp/ColorProfiles/YCbCrTransform.cs
  6. 8
      src/ImageSharp/ColorProfiles/YccK.cs
  7. 6
      tests/ImageSharp.Tests/ColorProfiles/RbgAndYConversionTests.cs

14
src/ImageSharp/ColorProfiles/ColorConversionOptions.cs

@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp.ColorProfiles;
public class ColorConversionOptions
{
private Matrix4x4 adaptationMatrix;
private YCbCrMatrix yCbCrMatrix;
private YCbCrTransform yCbCrTransform;
/// <summary>
/// Initializes a new instance of the <see cref="ColorConversionOptions"/> class.
@ -22,7 +22,7 @@ public class ColorConversionOptions
public ColorConversionOptions()
{
this.AdaptationMatrix = KnownChromaticAdaptationMatrices.Bradford;
this.YCbCrMatrix = KnownYCbCrMatrices.BT601;
this.YCbCrTransform = KnownYCbCrMatrices.BT601;
}
/// <summary>
@ -53,13 +53,13 @@ public class ColorConversionOptions
/// <summary>
/// Gets the YCbCr matrix to used to perform conversions from/to RGB.
/// </summary>
public YCbCrMatrix YCbCrMatrix
public YCbCrTransform YCbCrTransform
{
get => this.yCbCrMatrix;
get => this.yCbCrTransform;
init
{
this.yCbCrMatrix = value;
this.TransposedYCbCrMatrix = value.Transpose();
this.yCbCrTransform = value;
this.TransposedYCbCrTransform = value.Transpose();
}
}
@ -88,7 +88,7 @@ public class ColorConversionOptions
}
}
internal YCbCrMatrix TransposedYCbCrMatrix { get; private set; }
internal YCbCrTransform TransposedYCbCrTransform { get; private set; }
internal Matrix4x4 InverseAdaptationMatrix { get; private set; }
}

6
src/ImageSharp/ColorProfiles/KnownYCbCrMatrices.cs

@ -15,7 +15,7 @@ public static class KnownYCbCrMatrices
/// <summary>
/// ITU-R BT.601 (SD video standard).
/// </summary>
public static readonly YCbCrMatrix BT601 = new(
public static readonly YCbCrTransform BT601 = new(
new Matrix4x4(
0.299000F, 0.587000F, 0.114000F, 0F,
-0.168736F, -0.331264F, 0.500000F, 0F,
@ -31,7 +31,7 @@ public static class KnownYCbCrMatrices
/// <summary>
/// ITU-R BT.709 (HD video, sRGB standard).
/// </summary>
public static readonly YCbCrMatrix BT709 = new(
public static readonly YCbCrTransform BT709 = new(
new Matrix4x4(
0.212600F, 0.715200F, 0.072200F, 0F,
-0.114572F, -0.385428F, 0.500000F, 0F,
@ -47,7 +47,7 @@ public static class KnownYCbCrMatrices
/// <summary>
/// ITU-R BT.2020 (UHD/4K video standard).
/// </summary>
public static readonly YCbCrMatrix BT2020 = new(
public static readonly YCbCrTransform BT2020 = new(
new Matrix4x4(
0.262700F, 0.678000F, 0.059300F, 0F,
-0.139630F, -0.360370F, 0.500000F, 0F,

4
src/ImageSharp/ColorProfiles/Y.cs

@ -90,8 +90,8 @@ public readonly struct Y : IColorProfile<Y, Rgb>
/// <inheritdoc/>
public static Y FromProfileConnectingSpace(ColorConversionOptions options, in Rgb source)
{
Matrix4x4 m = options.YCbCrMatrix.Forward;
float offset = options.YCbCrMatrix.Offset.X;
Matrix4x4 m = options.YCbCrTransform.Forward;
float offset = options.YCbCrTransform.Offset.X;
return new(Vector3.Dot(source.AsVector3Unsafe(), new Vector3(m.M11, m.M12, m.M13)) + offset);
}

8
src/ImageSharp/ColorProfiles/YCbCr.cs

@ -130,8 +130,8 @@ public readonly struct YCbCr : IColorProfile<YCbCr, Rgb>
public static YCbCr FromProfileConnectingSpace(ColorConversionOptions options, in Rgb source)
{
Vector3 rgb = source.AsVector3Unsafe();
Matrix4x4 m = options.TransposedYCbCrMatrix.Forward;
Vector3 offset = options.TransposedYCbCrMatrix.Offset;
Matrix4x4 m = options.TransposedYCbCrTransform.Forward;
Vector3 offset = options.TransposedYCbCrTransform.Offset;
return new YCbCr(Vector3.Transform(rgb, m) + offset, true);
}
@ -152,8 +152,8 @@ public readonly struct YCbCr : IColorProfile<YCbCr, Rgb>
/// <inheritdoc/>
public Rgb ToProfileConnectingSpace(ColorConversionOptions options)
{
Matrix4x4 m = options.TransposedYCbCrMatrix.Inverse;
Vector3 offset = options.TransposedYCbCrMatrix.Offset;
Matrix4x4 m = options.TransposedYCbCrTransform.Inverse;
Vector3 offset = options.TransposedYCbCrTransform.Offset;
Vector3 normalized = this.AsVector3Unsafe() - offset;
return Rgb.FromScaledVector3(Vector3.Transform(normalized, m));

10
src/ImageSharp/ColorProfiles/YcbCrMatrix.cs → src/ImageSharp/ColorProfiles/YCbCrTransform.cs

@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.ColorProfiles;
/// <summary>
/// <para>
/// Represents a YCbCr color matrix containing forward and inverse transformation matrices,
/// Represents a YCbCr color transform containing forward and inverse transformation matrices,
/// and the chrominance offsets to apply for full-range encoding
/// </para>
/// <para>
@ -17,10 +17,10 @@ namespace SixLabors.ImageSharp.ColorProfiles;
/// working spaces will produce incorrect conversions.
/// </para>
/// </summary>
public readonly struct YCbCrMatrix
public readonly struct YCbCrTransform
{
/// <summary>
/// Initializes a new instance of the <see cref="YCbCrMatrix"/> struct.
/// Initializes a new instance of the <see cref="YCbCrTransform"/> struct.
/// </summary>
/// <param name="forward">
/// The forward transformation matrix from RGB to YCbCr. The matrix must include the
@ -34,7 +34,7 @@ public readonly struct YCbCrMatrix
/// The chrominance offsets to be added after the forward conversion,
/// and subtracted before the inverse conversion. Usually <c>(0, 0.5, 0.5)</c>.
/// </param>
public YCbCrMatrix(Matrix4x4 forward, Matrix4x4 inverse, Vector3 offset)
public YCbCrTransform(Matrix4x4 forward, Matrix4x4 inverse, Vector3 offset)
{
this.Forward = forward;
this.Inverse = inverse;
@ -56,6 +56,6 @@ public readonly struct YCbCrMatrix
/// </summary>
public Vector3 Offset { get; }
internal YCbCrMatrix Transpose()
internal YCbCrTransform Transpose()
=> new(Matrix4x4.Transpose(this.Forward), Matrix4x4.Transpose(this.Inverse), this.Offset);
}

8
src/ImageSharp/ColorProfiles/YccK.cs

@ -131,8 +131,8 @@ public readonly struct YccK : IColorProfile<YccK, Rgb>
/// <inheritdoc/>
public Rgb ToProfileConnectingSpace(ColorConversionOptions options)
{
Matrix4x4 m = options.TransposedYCbCrMatrix.Inverse;
Vector3 offset = options.TransposedYCbCrMatrix.Offset;
Matrix4x4 m = options.TransposedYCbCrTransform.Inverse;
Vector3 offset = options.TransposedYCbCrTransform.Offset;
Vector3 normalized = this.AsVector3Unsafe() - offset;
return Rgb.FromScaledVector3(Vector3.Transform(normalized, m) * (1F - this.K));
@ -141,8 +141,8 @@ public readonly struct YccK : IColorProfile<YccK, Rgb>
/// <inheritdoc/>
public static YccK FromProfileConnectingSpace(ColorConversionOptions options, in Rgb source)
{
Matrix4x4 m = options.TransposedYCbCrMatrix.Forward;
Vector3 offset = options.TransposedYCbCrMatrix.Offset;
Matrix4x4 m = options.TransposedYCbCrTransform.Forward;
Vector3 offset = options.TransposedYCbCrTransform.Offset;
Vector3 rgb = source.AsVector3Unsafe();
float k = 1F - MathF.Max(rgb.X, MathF.Max(rgb.Y, rgb.Z));

6
tests/ImageSharp.Tests/ColorProfiles/RbgAndYConversionTests.cs

@ -23,7 +23,7 @@ public class RbgAndYConversionTests
{
ColorConversionOptions options = new()
{
YCbCrMatrix = KnownYCbCrMatrices.BT601
YCbCrTransform = KnownYCbCrMatrices.BT601
};
Convert_Rgb_To_Y_Core(r, g, b, y, options);
@ -37,7 +37,7 @@ public class RbgAndYConversionTests
{
ColorConversionOptions options = new()
{
YCbCrMatrix = KnownYCbCrMatrices.BT709
YCbCrTransform = KnownYCbCrMatrices.BT709
};
Convert_Rgb_To_Y_Core(r, g, b, y, options);
@ -51,7 +51,7 @@ public class RbgAndYConversionTests
{
ColorConversionOptions options = new()
{
YCbCrMatrix = KnownYCbCrMatrices.BT2020
YCbCrTransform = KnownYCbCrMatrices.BT2020
};
Convert_Rgb_To_Y_Core(r, g, b, y, options);

Loading…
Cancel
Save