From ea564842c511f252095312d7e3bf950025ff2851 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 14 May 2025 22:12:52 +1000 Subject: [PATCH] Rename type --- .../ColorProfiles/ColorConversionOptions.cs | 14 +++++++------- src/ImageSharp/ColorProfiles/KnownYCbCrMatrices.cs | 6 +++--- src/ImageSharp/ColorProfiles/Y.cs | 4 ++-- src/ImageSharp/ColorProfiles/YCbCr.cs | 8 ++++---- .../{YcbCrMatrix.cs => YCbCrTransform.cs} | 10 +++++----- src/ImageSharp/ColorProfiles/YccK.cs | 8 ++++---- .../ColorProfiles/RbgAndYConversionTests.cs | 6 +++--- 7 files changed, 28 insertions(+), 28 deletions(-) rename src/ImageSharp/ColorProfiles/{YcbCrMatrix.cs => YCbCrTransform.cs} (85%) diff --git a/src/ImageSharp/ColorProfiles/ColorConversionOptions.cs b/src/ImageSharp/ColorProfiles/ColorConversionOptions.cs index 44c7d2ac77..882d246a76 100644 --- a/src/ImageSharp/ColorProfiles/ColorConversionOptions.cs +++ b/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; /// /// Initializes a new instance of the class. @@ -22,7 +22,7 @@ public class ColorConversionOptions public ColorConversionOptions() { this.AdaptationMatrix = KnownChromaticAdaptationMatrices.Bradford; - this.YCbCrMatrix = KnownYCbCrMatrices.BT601; + this.YCbCrTransform = KnownYCbCrMatrices.BT601; } /// @@ -53,13 +53,13 @@ public class ColorConversionOptions /// /// Gets the YCbCr matrix to used to perform conversions from/to RGB. /// - 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; } } diff --git a/src/ImageSharp/ColorProfiles/KnownYCbCrMatrices.cs b/src/ImageSharp/ColorProfiles/KnownYCbCrMatrices.cs index e2b7bf1026..d32833a382 100644 --- a/src/ImageSharp/ColorProfiles/KnownYCbCrMatrices.cs +++ b/src/ImageSharp/ColorProfiles/KnownYCbCrMatrices.cs @@ -15,7 +15,7 @@ public static class KnownYCbCrMatrices /// /// ITU-R BT.601 (SD video standard). /// - 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 /// /// ITU-R BT.709 (HD video, sRGB standard). /// - 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 /// /// ITU-R BT.2020 (UHD/4K video standard). /// - 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, diff --git a/src/ImageSharp/ColorProfiles/Y.cs b/src/ImageSharp/ColorProfiles/Y.cs index 960bf46991..83321a0851 100644 --- a/src/ImageSharp/ColorProfiles/Y.cs +++ b/src/ImageSharp/ColorProfiles/Y.cs @@ -90,8 +90,8 @@ public readonly struct Y : IColorProfile /// 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); } diff --git a/src/ImageSharp/ColorProfiles/YCbCr.cs b/src/ImageSharp/ColorProfiles/YCbCr.cs index 8e7dc57d74..22d629373b 100644 --- a/src/ImageSharp/ColorProfiles/YCbCr.cs +++ b/src/ImageSharp/ColorProfiles/YCbCr.cs @@ -130,8 +130,8 @@ public readonly struct YCbCr : IColorProfile 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 /// 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)); diff --git a/src/ImageSharp/ColorProfiles/YcbCrMatrix.cs b/src/ImageSharp/ColorProfiles/YCbCrTransform.cs similarity index 85% rename from src/ImageSharp/ColorProfiles/YcbCrMatrix.cs rename to src/ImageSharp/ColorProfiles/YCbCrTransform.cs index ccb4ea9861..c90b90708d 100644 --- a/src/ImageSharp/ColorProfiles/YcbCrMatrix.cs +++ b/src/ImageSharp/ColorProfiles/YCbCrTransform.cs @@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.ColorProfiles; /// /// -/// 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 /// /// @@ -17,10 +17,10 @@ namespace SixLabors.ImageSharp.ColorProfiles; /// working spaces will produce incorrect conversions. /// /// -public readonly struct YCbCrMatrix +public readonly struct YCbCrTransform { /// - /// Initializes a new instance of the struct. + /// Initializes a new instance of the struct. /// /// /// 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 (0, 0.5, 0.5). /// - 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 /// public Vector3 Offset { get; } - internal YCbCrMatrix Transpose() + internal YCbCrTransform Transpose() => new(Matrix4x4.Transpose(this.Forward), Matrix4x4.Transpose(this.Inverse), this.Offset); } diff --git a/src/ImageSharp/ColorProfiles/YccK.cs b/src/ImageSharp/ColorProfiles/YccK.cs index f05e1431b2..df5eb48947 100644 --- a/src/ImageSharp/ColorProfiles/YccK.cs +++ b/src/ImageSharp/ColorProfiles/YccK.cs @@ -131,8 +131,8 @@ public readonly struct YccK : IColorProfile /// 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 /// 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)); diff --git a/tests/ImageSharp.Tests/ColorProfiles/RbgAndYConversionTests.cs b/tests/ImageSharp.Tests/ColorProfiles/RbgAndYConversionTests.cs index 1cd6f6cf41..017ba78d0b 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/RbgAndYConversionTests.cs +++ b/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);