diff --git a/.editorconfig b/.editorconfig index c28089d720..af1e5b44c1 100644 --- a/.editorconfig +++ b/.editorconfig @@ -104,8 +104,8 @@ dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:war dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning dotnet_style_parentheses_in_other_operators = always_for_clarity:suggestion # Expression-level preferences -dotnet_style_object_initializer = true:warning -dotnet_style_collection_initializer = true:warning +dotnet_style_object_initializer = true:error +dotnet_style_collection_initializer = true:error dotnet_style_explicit_tuple_names = true:warning dotnet_style_prefer_inferred_tuple_names = true:warning dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning @@ -135,9 +135,9 @@ csharp_style_prefer_null_check_over_type_check = true:warning # https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules#c-style-rules [*.{cs,csx,cake}] # 'var' preferences -csharp_style_var_for_built_in_types = false:warning -csharp_style_var_when_type_is_apparent = false:warning -csharp_style_var_elsewhere = false:warning +csharp_style_var_for_built_in_types = false:error +csharp_style_var_when_type_is_apparent = false:error +csharp_style_var_elsewhere = false:error # Expression-bodied members csharp_style_expression_bodied_methods = true:warning csharp_style_expression_bodied_constructors = true:warning @@ -160,7 +160,7 @@ csharp_style_pattern_local_over_anonymous_function = true:warning csharp_style_deconstructed_variable_declaration = true:warning csharp_style_prefer_index_operator = true:warning csharp_style_prefer_range_operator = true:warning -csharp_style_implicit_object_creation_when_type_is_apparent = true:warning +csharp_style_implicit_object_creation_when_type_is_apparent = true:error # "Null" checking preferences csharp_style_throw_expression = true:warning csharp_style_conditional_delegate_call = true:warning diff --git a/.gitattributes b/.gitattributes index b5f742ab47..f7bd4d061e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -136,3 +136,10 @@ *.ico filter=lfs diff=lfs merge=lfs -text *.cur filter=lfs diff=lfs merge=lfs -text *.ani filter=lfs diff=lfs merge=lfs -text +*.heic filter=lfs diff=lfs merge=lfs -text +*.hif filter=lfs diff=lfs merge=lfs -text +*.avif filter=lfs diff=lfs merge=lfs -text +############################################################################### +# Handle ICC files by git lfs +############################################################################### +*.icc filter=lfs diff=lfs merge=lfs -text diff --git a/shared-infrastructure b/shared-infrastructure index 1dbfb576c8..5e13cde851 160000 --- a/shared-infrastructure +++ b/shared-infrastructure @@ -1 +1 @@ -Subproject commit 1dbfb576c83507645265c79e03369b66cdc0379f +Subproject commit 5e13cde851a3d6e95d0dfdde2a57071f1efda9c3 diff --git a/src/ImageSharp/Advanced/AotCompilerTools.cs b/src/ImageSharp/Advanced/AotCompilerTools.cs index 0d5faabe18..23bf85cf3d 100644 --- a/src/ImageSharp/Advanced/AotCompilerTools.cs +++ b/src/ImageSharp/Advanced/AotCompilerTools.cs @@ -138,10 +138,11 @@ internal static class AotCompilerTools AotCompileResamplers(); AotCompileQuantizers(); AotCompilePixelSamplingStrategys(); + AotCompilePixelMaps(); AotCompileDithers(); AotCompileMemoryManagers(); - Unsafe.SizeOf(); + _ = Unsafe.SizeOf(); // TODO: Do the discovery work to figure out what works and what doesn't. } @@ -514,6 +515,20 @@ internal static class AotCompilerTools default(ExtensivePixelSamplingStrategy).EnumeratePixelRegions(default(ImageFrame)); } + /// + /// This method pre-seeds the all in the AoT compiler. + /// + /// The pixel format. + [Preserve] + private static void AotCompilePixelMaps() + where TPixel : unmanaged, IPixel + { + default(EuclideanPixelMap).GetClosestColor(default, out _); + default(EuclideanPixelMap).GetClosestColor(default, out _); + default(EuclideanPixelMap).GetClosestColor(default, out _); + default(EuclideanPixelMap).GetClosestColor(default, out _); + } + /// /// This method pre-seeds the all in the AoT compiler. /// diff --git a/src/ImageSharp/ColorProfiles/CieLab.cs b/src/ImageSharp/ColorProfiles/CieLab.cs index 377cc20a99..ca72dd745a 100644 --- a/src/ImageSharp/ColorProfiles/CieLab.cs +++ b/src/ImageSharp/ColorProfiles/CieLab.cs @@ -35,7 +35,6 @@ public readonly struct CieLab : IProfileConnectingSpace /// The vector representing the l, a, b components. [MethodImpl(MethodImplOptions.AggressiveInlining)] public CieLab(Vector3 vector) - : this() { this.L = vector.X; this.A = vector.Y; @@ -82,6 +81,49 @@ public readonly struct CieLab : IProfileConnectingSpace [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(CieLab left, CieLab right) => !left.Equals(right); + /// + public Vector4 ToScaledVector4() + { + Vector3 v3 = default; + v3 += this.AsVector3Unsafe(); + v3 += new Vector3(0, 128F, 128F); + v3 /= new Vector3(100F, 255F, 255F); + return new Vector4(v3, 1F); + } + + /// + public static CieLab FromScaledVector4(Vector4 source) + { + Vector3 v3 = source.AsVector3(); + v3 *= new Vector3(100F, 255, 255); + v3 -= new Vector3(0, 128F, 128F); + return new CieLab(v3); + } + + /// + public static void ToScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = source[i].ToScaledVector4(); + } + } + + /// + public static void FromScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = FromScaledVector4(source[i]); + } + } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static CieLab FromProfileConnectingSpace(ColorConversionOptions options, in CieXyz source) @@ -136,7 +178,7 @@ public readonly struct CieLab : IProfileConnectingSpace float yr = l > CieConstants.Kappa * CieConstants.Epsilon ? Numerics.Pow3((l + 16F) / 116F) : l / CieConstants.Kappa; float zr = fz3 > CieConstants.Epsilon ? fz3 : ((116F * fz) - 16F) / CieConstants.Kappa; - CieXyz whitePoint = options.WhitePoint; + CieXyz whitePoint = options.SourceWhitePoint; Vector3 wxyz = new(whitePoint.X, whitePoint.Y, whitePoint.Z); Vector3 xyzr = new(xr, yr, zr); diff --git a/src/ImageSharp/ColorProfiles/CieLch.cs b/src/ImageSharp/ColorProfiles/CieLch.cs index 1319783406..e62aa2ba23 100644 --- a/src/ImageSharp/ColorProfiles/CieLch.cs +++ b/src/ImageSharp/ColorProfiles/CieLch.cs @@ -42,6 +42,17 @@ public readonly struct CieLch : IColorProfile this.H = vector.Z; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#pragma warning disable SA1313 // Parameter names should begin with lower-case letter + private CieLch(Vector3 vector, bool _) +#pragma warning restore SA1313 // Parameter names should begin with lower-case letter + { + vector = Vector3.Clamp(vector, Min, Max); + this.L = vector.X; + this.C = vector.Y; + this.H = vector.Z; + } + /// /// Gets the lightness dimension. /// A value ranging between 0 (black), 100 (diffuse white) or higher (specular white). @@ -50,7 +61,7 @@ public readonly struct CieLch : IColorProfile /// /// Gets the a chroma component. - /// A value ranging from 0 to 200. + /// A value ranging from -200 to 200. /// public float C { get; } @@ -82,6 +93,49 @@ public readonly struct CieLch : IColorProfile [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(CieLch left, CieLch right) => !left.Equals(right); + /// + public Vector4 ToScaledVector4() + { + Vector3 v3 = default; + v3 += this.AsVector3Unsafe(); + v3 += new Vector3(0, 200, 0); + v3 /= new Vector3(100, 400, 360); + return new Vector4(v3, 1F); + } + + /// + public static CieLch FromScaledVector4(Vector4 source) + { + Vector3 v3 = source.AsVector3(); + v3 *= new Vector3(100, 400, 360); + v3 -= new Vector3(0, 200, 0); + return new CieLch(v3, true); + } + + /// + public static void ToScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = source[i].ToScaledVector4(); + } + } + + /// + public static void FromScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = FromScaledVector4(source[i]); + } + } + /// public static CieLch FromProfileConnectingSpace(ColorConversionOptions options, in CieLab source) { diff --git a/src/ImageSharp/ColorProfiles/CieLchuv.cs b/src/ImageSharp/ColorProfiles/CieLchuv.cs index 7fd95feb19..5478752ddc 100644 --- a/src/ImageSharp/ColorProfiles/CieLchuv.cs +++ b/src/ImageSharp/ColorProfiles/CieLchuv.cs @@ -35,7 +35,6 @@ public readonly struct CieLchuv : IColorProfile /// The vector representing the l, c, h components. [MethodImpl(MethodImplOptions.AggressiveInlining)] public CieLchuv(Vector3 vector) - : this() { vector = Vector3.Clamp(vector, Min, Max); this.L = vector.X; @@ -43,6 +42,16 @@ public readonly struct CieLchuv : IColorProfile this.H = vector.Z; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#pragma warning disable SA1313 // Parameter names should begin with lower-case letter + private CieLchuv(Vector3 vector, bool _) +#pragma warning restore SA1313 // Parameter names should begin with lower-case letter + { + this.L = vector.X; + this.C = vector.Y; + this.H = vector.Z; + } + /// /// Gets the lightness dimension. /// A value ranging between 0 (black), 100 (diffuse white) or higher (specular white). @@ -51,7 +60,7 @@ public readonly struct CieLchuv : IColorProfile /// /// Gets the a chroma component. - /// A value ranging from 0 to 200. + /// A value ranging from -200 to 200. /// public float C { get; } @@ -81,6 +90,49 @@ public readonly struct CieLchuv : IColorProfile /// public static bool operator !=(CieLchuv left, CieLchuv right) => !left.Equals(right); + /// + public Vector4 ToScaledVector4() + { + Vector3 v3 = default; + v3 += this.AsVector3Unsafe(); + v3 += new Vector3(0, 200, 0); + v3 /= new Vector3(100, 400, 360); + return new Vector4(v3, 1F); + } + + /// + public static CieLchuv FromScaledVector4(Vector4 source) + { + Vector3 v3 = source.AsVector3(); + v3 *= new Vector3(100, 400, 360); + v3 -= new Vector3(0, 200, 0); + return new CieLchuv(v3, true); + } + + /// + public static void ToScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = source[i].ToScaledVector4(); + } + } + + /// + public static void FromScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = FromScaledVector4(source[i]); + } + } + /// public static CieLchuv FromProfileConnectingSpace(ColorConversionOptions options, in CieXyz source) { diff --git a/src/ImageSharp/ColorProfiles/CieLuv.cs b/src/ImageSharp/ColorProfiles/CieLuv.cs index 97e2826f74..b17c433313 100644 --- a/src/ImageSharp/ColorProfiles/CieLuv.cs +++ b/src/ImageSharp/ColorProfiles/CieLuv.cs @@ -37,7 +37,6 @@ public readonly struct CieLuv : IColorProfile /// The vector representing the l, u, v components. [MethodImpl(MethodImplOptions.AggressiveInlining)] public CieLuv(Vector3 vector) - : this() { this.L = vector.X; this.U = vector.Y; @@ -84,6 +83,18 @@ public readonly struct CieLuv : IColorProfile [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(CieLuv left, CieLuv right) => !left.Equals(right); + /// + public Vector4 ToScaledVector4() => throw new NotImplementedException(); + + /// + public static CieLuv FromScaledVector4(Vector4 source) => throw new NotImplementedException(); + + /// + public static void ToScaledVector4(ReadOnlySpan source, Span destination) => throw new NotImplementedException(); + + /// + public static void FromScaledVector4(ReadOnlySpan source, Span destination) => throw new NotImplementedException(); + /// public static CieLuv FromProfileConnectingSpace(ColorConversionOptions options, in CieXyz source) { @@ -143,7 +154,7 @@ public readonly struct CieLuv : IColorProfile // Use doubles here for accuracy. // Conversion algorithm described here: // http://www.brucelindbloom.com/index.html?Eqn_Luv_to_XYZ.html - CieXyz whitePoint = options.WhitePoint; + CieXyz whitePoint = options.SourceWhitePoint; double l = this.L, u = this.U, v = this.V; diff --git a/src/ImageSharp/ColorProfiles/CieXyy.cs b/src/ImageSharp/ColorProfiles/CieXyy.cs index 62873df147..744b6195e9 100644 --- a/src/ImageSharp/ColorProfiles/CieXyy.cs +++ b/src/ImageSharp/ColorProfiles/CieXyy.cs @@ -35,7 +35,6 @@ public readonly struct CieXyy : IColorProfile /// The vector representing the x, y, Y components. [MethodImpl(MethodImplOptions.AggressiveInlining)] public CieXyy(Vector3 vector) - : this() { // Not clamping as documentation about this space only indicates "usual" ranges this.X = vector.X; @@ -83,6 +82,38 @@ public readonly struct CieXyy : IColorProfile [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(CieXyy left, CieXyy right) => !left.Equals(right); + /// + public Vector4 ToScaledVector4() + => new(this.AsVector3Unsafe(), 1F); + + /// + public static CieXyy FromScaledVector4(Vector4 source) + => new(source.AsVector3()); + + /// + public static void ToScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = source[i].ToScaledVector4(); + } + } + + /// + public static void FromScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = FromScaledVector4(source[i]); + } + } + /// public static CieXyy FromProfileConnectingSpace(ColorConversionOptions options, in CieXyz source) { diff --git a/src/ImageSharp/ColorProfiles/CieXyz.cs b/src/ImageSharp/ColorProfiles/CieXyz.cs index 07f9b47f9b..94fcfb21bb 100644 --- a/src/ImageSharp/ColorProfiles/CieXyz.cs +++ b/src/ImageSharp/ColorProfiles/CieXyz.cs @@ -34,7 +34,6 @@ public readonly struct CieXyz : IProfileConnectingSpace /// /// The vector representing the x, y, z components. public CieXyz(Vector3 vector) - : this() { this.X = vector.X; this.Y = vector.Y; @@ -81,12 +80,85 @@ public readonly struct CieXyz : IProfileConnectingSpace [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(CieXyz left, CieXyz right) => !left.Equals(right); - /// - /// Returns a new representing this instance. - /// - /// The . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Vector3 ToVector3() => new(this.X, this.Y, this.Z); + internal Vector3 ToVector3() => new(this.X, this.Y, this.Z); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal Vector4 ToVector4() + { + Vector3 v3 = default; + v3 += this.AsVector3Unsafe(); + return new Vector4(v3, 1F); + } + + /// + public Vector4 ToScaledVector4() + { + Vector3 v3 = default; + v3 += this.AsVector3Unsafe(); + v3 *= 32768F / 65535; + return new Vector4(v3, 1F); + } + + internal static CieXyz FromVector4(Vector4 source) + { + Vector3 v3 = source.AsVector3(); + return new CieXyz(v3); + } + + /// + public static CieXyz FromScaledVector4(Vector4 source) + { + Vector3 v3 = source.AsVector3(); + v3 *= 65535 / 32768F; + return new CieXyz(v3); + } + + /// + public static void ToScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = source[i].ToScaledVector4(); + } + } + + /// + public static void FromScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = FromScaledVector4(source[i]); + } + } + + internal static void FromVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = FromVector4(source[i]); + } + } + + internal static void ToVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = source[i].ToVector4(); + } + } /// public static CieXyz FromProfileConnectingSpace(ColorConversionOptions options, in CieXyz source) @@ -127,5 +199,5 @@ public readonly struct CieXyz : IProfileConnectingSpace public bool Equals(CieXyz other) => this.AsVector3Unsafe() == other.AsVector3Unsafe(); - private Vector3 AsVector3Unsafe() => Unsafe.As(ref Unsafe.AsRef(in this)); + internal Vector3 AsVector3Unsafe() => Unsafe.As(ref Unsafe.AsRef(in this)); } diff --git a/src/ImageSharp/ColorProfiles/Cmyk.cs b/src/ImageSharp/ColorProfiles/Cmyk.cs index e924904497..ee81ff9f7e 100644 --- a/src/ImageSharp/ColorProfiles/Cmyk.cs +++ b/src/ImageSharp/ColorProfiles/Cmyk.cs @@ -9,6 +9,7 @@ namespace SixLabors.ImageSharp.ColorProfiles; /// /// Represents an CMYK (cyan, magenta, yellow, keyline) color. +/// /// [StructLayout(LayoutKind.Sequential)] public readonly struct Cmyk : IColorProfile @@ -36,7 +37,18 @@ public readonly struct Cmyk : IColorProfile [MethodImpl(MethodImplOptions.AggressiveInlining)] public Cmyk(Vector4 vector) { - vector = Numerics.Clamp(vector, Min, Max); + vector = Vector4.Clamp(vector, Min, Max); + this.C = vector.X; + this.M = vector.Y; + this.Y = vector.Z; + this.K = vector.W; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#pragma warning disable SA1313 // Parameter names should begin with lower-case letter + private Cmyk(Vector4 vector, bool _) +#pragma warning restore SA1313 // Parameter names should begin with lower-case letter + { this.C = vector.X; this.M = vector.Y; this.Y = vector.Z; @@ -89,16 +101,42 @@ public readonly struct Cmyk : IColorProfile [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Cmyk left, Cmyk right) => !left.Equals(right); + /// + public Vector4 ToScaledVector4() + { + Vector4 v4 = default; + v4 += this.AsVector4Unsafe(); + return v4; + } + + /// + public static Cmyk FromScaledVector4(Vector4 source) + => new(source, true); + + /// + public static void ToScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + MemoryMarshal.Cast(source).CopyTo(destination); + } + + /// + public static void FromScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + MemoryMarshal.Cast(source).CopyTo(destination); + } + /// public static Cmyk FromProfileConnectingSpace(ColorConversionOptions options, in Rgb source) { // To CMY - Vector3 cmy = Vector3.One - source.ToScaledVector3(); + Vector3 cmy = Vector3.One - source.AsVector3Unsafe(); // To CMYK Vector3 k = new(MathF.Min(cmy.X, MathF.Min(cmy.Y, cmy.Z))); - if (MathF.Abs(k.X - 1F) < Constants.Epsilon) + if (k.X >= 1F - Constants.Epsilon) { return new Cmyk(0, 0, 0, 1F); } @@ -124,7 +162,7 @@ public readonly struct Cmyk : IColorProfile /// public Rgb ToProfileConnectingSpace(ColorConversionOptions options) { - Vector3 rgb = (Vector3.One - new Vector3(this.C, this.M, this.Y)) * (Vector3.One - new Vector3(this.K)); + Vector3 rgb = (Vector3.One - new Vector3(this.C, this.M, this.Y)) * (1F - this.K); return Rgb.FromScaledVector3(rgb); } @@ -134,8 +172,7 @@ public readonly struct Cmyk : IColorProfile // TODO: We can possibly optimize this by using SIMD for (int i = 0; i < source.Length; i++) { - Cmyk cmyk = source[i]; - destination[i] = cmyk.ToProfileConnectingSpace(options); + destination[i] = source[i].ToProfileConnectingSpace(options); } } diff --git a/src/ImageSharp/ColorProfiles/ColorConversionOptions.cs b/src/ImageSharp/ColorProfiles/ColorConversionOptions.cs index 1eb118834a..44c7d2ac77 100644 --- a/src/ImageSharp/ColorProfiles/ColorConversionOptions.cs +++ b/src/ImageSharp/ColorProfiles/ColorConversionOptions.cs @@ -4,6 +4,7 @@ using System.Numerics; using SixLabors.ImageSharp.ColorProfiles.WorkingSpaces; using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; namespace SixLabors.ImageSharp.ColorProfiles; @@ -13,11 +14,16 @@ namespace SixLabors.ImageSharp.ColorProfiles; public class ColorConversionOptions { private Matrix4x4 adaptationMatrix; + private YCbCrMatrix yCbCrMatrix; /// /// Initializes a new instance of the class. /// - public ColorConversionOptions() => this.AdaptationMatrix = KnownChromaticAdaptationMatrices.Bradford; + public ColorConversionOptions() + { + this.AdaptationMatrix = KnownChromaticAdaptationMatrices.Bradford; + this.YCbCrMatrix = KnownYCbCrMatrices.BT601; + } /// /// Gets the memory allocator. @@ -27,7 +33,7 @@ public class ColorConversionOptions /// /// Gets the source white point used for chromatic adaptation in conversions from/to XYZ color space. /// - public CieXyz WhitePoint { get; init; } = KnownIlluminants.D50; + public CieXyz SourceWhitePoint { get; init; } = KnownIlluminants.D50; /// /// Gets the destination white point used for chromatic adaptation in conversions from/to XYZ color space. @@ -37,13 +43,36 @@ public class ColorConversionOptions /// /// Gets the source working space used for companding in conversions from/to XYZ color space. /// - public RgbWorkingSpace RgbWorkingSpace { get; init; } = KnownRgbWorkingSpaces.SRgb; + public RgbWorkingSpace SourceRgbWorkingSpace { get; init; } = KnownRgbWorkingSpaces.SRgb; /// /// Gets the destination working space used for companding in conversions from/to XYZ color space. /// public RgbWorkingSpace TargetRgbWorkingSpace { get; init; } = KnownRgbWorkingSpaces.SRgb; + /// + /// Gets the YCbCr matrix to used to perform conversions from/to RGB. + /// + public YCbCrMatrix YCbCrMatrix + { + get => this.yCbCrMatrix; + init + { + this.yCbCrMatrix = value; + this.TransposedYCbCrMatrix = value.Transpose(); + } + } + + /// + /// Gets the source ICC profile. + /// + public IccProfile? SourceIccProfile { get; init; } + + /// + /// Gets the target ICC profile. + /// + public IccProfile? TargetIccProfile { get; init; } + /// /// Gets the transformation matrix used in conversion to perform chromatic adaptation. /// for further information. Default is Bradford. @@ -54,10 +83,12 @@ public class ColorConversionOptions init { this.adaptationMatrix = value; - Matrix4x4.Invert(value, out Matrix4x4 inverted); + _ = Matrix4x4.Invert(value, out Matrix4x4 inverted); this.InverseAdaptationMatrix = inverted; } } + internal YCbCrMatrix TransposedYCbCrMatrix { get; private set; } + internal Matrix4x4 InverseAdaptationMatrix { get; private set; } } diff --git a/src/ImageSharp/ColorProfiles/ColorProfileConverter.cs b/src/ImageSharp/ColorProfiles/ColorProfileConverter.cs index 18b90a622a..d0afec4ab2 100644 --- a/src/ImageSharp/ColorProfiles/ColorProfileConverter.cs +++ b/src/ImageSharp/ColorProfiles/ColorProfileConverter.cs @@ -12,7 +12,7 @@ public class ColorProfileConverter /// Initializes a new instance of the class. /// public ColorProfileConverter() - : this(new()) + : this(new()) { } @@ -33,8 +33,8 @@ public class ColorProfileConverter where TTo : struct, IColorProfile { CieXyz sourceWhitePoint = TFrom.GetChromaticAdaptionWhitePointSource() == ChromaticAdaptionWhitePointSource.WhitePoint - ? this.Options.WhitePoint - : this.Options.RgbWorkingSpace.WhitePoint; + ? this.Options.SourceWhitePoint + : this.Options.SourceRgbWorkingSpace.WhitePoint; CieXyz targetWhitePoint = TTo.GetChromaticAdaptionWhitePointSource() == ChromaticAdaptionWhitePointSource.WhitePoint ? this.Options.TargetWhitePoint @@ -42,4 +42,7 @@ public class ColorProfileConverter return (sourceWhitePoint, targetWhitePoint); } + + internal bool ShouldUseIccProfiles() + => this.Options.SourceIccProfile != null && this.Options.TargetIccProfile != null; } diff --git a/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieLabCieLab.cs b/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieLabCieLab.cs index 41ae4b08fa..a2dd5d9ced 100644 --- a/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieLabCieLab.cs +++ b/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieLabCieLab.cs @@ -12,6 +12,11 @@ internal static class ColorProfileConverterExtensionsCieLabCieLab where TFrom : struct, IColorProfile where TTo : struct, IColorProfile { + if (converter.ShouldUseIccProfiles()) + { + return converter.ConvertUsingIccProfile(source); + } + ColorConversionOptions options = converter.Options; // Convert to input PCS @@ -33,6 +38,12 @@ internal static class ColorProfileConverterExtensionsCieLabCieLab where TFrom : struct, IColorProfile where TTo : struct, IColorProfile { + if (converter.ShouldUseIccProfiles()) + { + converter.ConvertUsingIccProfile(source, destination); + return; + } + ColorConversionOptions options = converter.Options; // Convert to input PCS. diff --git a/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieLabCieXyz.cs b/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieLabCieXyz.cs index 04937e927e..096622564c 100644 --- a/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieLabCieXyz.cs +++ b/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieLabCieXyz.cs @@ -12,6 +12,11 @@ internal static class ColorProfileConverterExtensionsCieLabCieXyz where TFrom : struct, IColorProfile where TTo : struct, IColorProfile { + if (converter.ShouldUseIccProfiles()) + { + return converter.ConvertUsingIccProfile(source); + } + ColorConversionOptions options = converter.Options; // Convert to input PCS @@ -32,6 +37,12 @@ internal static class ColorProfileConverterExtensionsCieLabCieXyz where TFrom : struct, IColorProfile where TTo : struct, IColorProfile { + if (converter.ShouldUseIccProfiles()) + { + converter.ConvertUsingIccProfile(source, destination); + return; + } + ColorConversionOptions options = converter.Options; // Convert to input PCS. diff --git a/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieLabRgb.cs b/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieLabRgb.cs index 47e4d2a80a..51be13799c 100644 --- a/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieLabRgb.cs +++ b/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieLabRgb.cs @@ -12,6 +12,11 @@ internal static class ColorProfileConverterExtensionsCieLabRgb where TFrom : struct, IColorProfile where TTo : struct, IColorProfile { + if (converter.ShouldUseIccProfiles()) + { + return converter.ConvertUsingIccProfile(source); + } + ColorConversionOptions options = converter.Options; // Convert to input PCS @@ -33,6 +38,12 @@ internal static class ColorProfileConverterExtensionsCieLabRgb where TFrom : struct, IColorProfile where TTo : struct, IColorProfile { + if (converter.ShouldUseIccProfiles()) + { + converter.ConvertUsingIccProfile(source, destination); + return; + } + ColorConversionOptions options = converter.Options; // Convert to input PCS. diff --git a/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieXyzCieLab.cs b/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieXyzCieLab.cs index 6b1575d04c..3bab4e7b16 100644 --- a/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieXyzCieLab.cs +++ b/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieXyzCieLab.cs @@ -12,6 +12,11 @@ internal static class ColorProfileConverterExtensionsCieXyzCieLab where TFrom : struct, IColorProfile where TTo : struct, IColorProfile { + if (converter.ShouldUseIccProfiles()) + { + return converter.ConvertUsingIccProfile(source); + } + ColorConversionOptions options = converter.Options; // Convert to input PCS @@ -32,6 +37,12 @@ internal static class ColorProfileConverterExtensionsCieXyzCieLab where TFrom : struct, IColorProfile where TTo : struct, IColorProfile { + if (converter.ShouldUseIccProfiles()) + { + converter.ConvertUsingIccProfile(source, destination); + return; + } + ColorConversionOptions options = converter.Options; // Convert to input PCS. diff --git a/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieXyzCieXyz.cs b/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieXyzCieXyz.cs index 8f56a5a663..5188511476 100644 --- a/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieXyzCieXyz.cs +++ b/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieXyzCieXyz.cs @@ -12,6 +12,11 @@ internal static class ColorProfileConverterExtensionsCieXyzCieXyz where TFrom : struct, IColorProfile where TTo : struct, IColorProfile { + if (converter.ShouldUseIccProfiles()) + { + return converter.ConvertUsingIccProfile(source); + } + ColorConversionOptions options = converter.Options; // Convert to input PCS @@ -29,6 +34,12 @@ internal static class ColorProfileConverterExtensionsCieXyzCieXyz where TFrom : struct, IColorProfile where TTo : struct, IColorProfile { + if (converter.ShouldUseIccProfiles()) + { + converter.ConvertUsingIccProfile(source, destination); + return; + } + ColorConversionOptions options = converter.Options; // Convert to input PCS. diff --git a/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieXyzRgb.cs b/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieXyzRgb.cs index 9cc0bd9436..c56bf214b9 100644 --- a/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieXyzRgb.cs +++ b/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsCieXyzRgb.cs @@ -12,6 +12,11 @@ internal static class ColorProfileConverterExtensionsCieXyzRgb where TFrom : struct, IColorProfile where TTo : struct, IColorProfile { + if (converter.ShouldUseIccProfiles()) + { + return converter.ConvertUsingIccProfile(source); + } + ColorConversionOptions options = converter.Options; // Convert to input PCS @@ -32,6 +37,12 @@ internal static class ColorProfileConverterExtensionsCieXyzRgb where TFrom : struct, IColorProfile where TTo : struct, IColorProfile { + if (converter.ShouldUseIccProfiles()) + { + converter.ConvertUsingIccProfile(source, destination); + return; + } + ColorConversionOptions options = converter.Options; // Convert to input PCS. diff --git a/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsIcc.cs b/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsIcc.cs new file mode 100644 index 0000000000..c33f40001a --- /dev/null +++ b/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsIcc.cs @@ -0,0 +1,731 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Buffers; +using System.Diagnostics.CodeAnalysis; +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.Intrinsics; +using SixLabors.ImageSharp.ColorProfiles.Conversion.Icc; +using SixLabors.ImageSharp.ColorProfiles.Icc; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; + +namespace SixLabors.ImageSharp.ColorProfiles; + +internal static class ColorProfileConverterExtensionsIcc +{ + private static readonly float[] PcsV2FromBlackPointScale = + [0.9965153F, 0.9965269F, 0.9965208F, 1F, + 0.9965153F, 0.9965269F, 0.9965208F, 1F, + 0.9965153F, 0.9965269F, 0.9965208F, 1F, + 0.9965153F, 0.9965269F, 0.9965208F, 1F]; + + private static readonly float[] PcsV2FromBlackPointOffset = + [0.00336F, 0.0034731F, 0.00287F, 0F, + 0.00336F, 0.0034731F, 0.00287F, 0F, + 0.00336F, 0.0034731F, 0.00287F, 0F, + 0.00336F, 0.0034731F, 0.00287F, 0F]; + + private static readonly float[] PcsV2ToBlackPointScale = + [1.0034969F, 1.0034852F, 1.0034913F, 1F, + 1.0034969F, 1.0034852F, 1.0034913F, 1F, + 1.0034969F, 1.0034852F, 1.0034913F, 1F, + 1.0034969F, 1.0034852F, 1.0034913F, 1F]; + + private static readonly float[] PcsV2ToBlackPointOffset = + [0.0033717495F, 0.0034852044F, 0.0028800198F, 0F, + 0.0033717495F, 0.0034852044F, 0.0028800198F, 0F, + 0.0033717495F, 0.0034852044F, 0.0028800198F, 0F, + 0.0033717495F, 0.0034852044F, 0.0028800198F, 0F]; + + internal static TTo ConvertUsingIccProfile(this ColorProfileConverter converter, in TFrom source) + where TFrom : struct, IColorProfile + where TTo : struct, IColorProfile + { + // TODO: Validation of ICC Profiles against color profile. Is this possible? + if (converter.Options.SourceIccProfile is null) + { + throw new InvalidOperationException("Source ICC profile is missing."); + } + + if (converter.Options.TargetIccProfile is null) + { + throw new InvalidOperationException("Target ICC profile is missing."); + } + + ConversionParams sourceParams = new(converter.Options.SourceIccProfile, toPcs: true); + ConversionParams targetParams = new(converter.Options.TargetIccProfile, toPcs: false); + + ColorProfileConverter pcsConverter = new(new ColorConversionOptions + { + MemoryAllocator = converter.Options.MemoryAllocator, + SourceWhitePoint = new CieXyz(converter.Options.SourceIccProfile.Header.PcsIlluminant), + TargetWhitePoint = new CieXyz(converter.Options.TargetIccProfile.Header.PcsIlluminant), + }); + + // Normalize the source, then convert to the PCS space. + Vector4 sourcePcs = sourceParams.Converter.Calculate(source.ToScaledVector4()); + + // If both profiles need PCS adjustment, they both share the same unadjusted PCS space + // cancelling out the need to make the adjustment + // except if using TRC transforms, which always requires perceptual handling + // TODO: this does not include adjustment for absolute intent, which would double existing complexity, suggest throwing exception and addressing in future update + bool anyProfileNeedsPerceptualAdjustment = sourceParams.HasNoPerceptualHandling || targetParams.HasNoPerceptualHandling; + bool oneProfileHasV2PerceptualAdjustment = sourceParams.HasV2PerceptualHandling ^ targetParams.HasV2PerceptualHandling; + + Vector4 targetPcs = anyProfileNeedsPerceptualAdjustment || oneProfileHasV2PerceptualAdjustment + ? GetTargetPcsWithPerceptualAdjustment(sourcePcs, sourceParams, targetParams, pcsConverter) + : GetTargetPcsWithoutAdjustment(sourcePcs, sourceParams, targetParams, pcsConverter); + + return TTo.FromScaledVector4(targetParams.Converter.Calculate(targetPcs)); + } + + internal static void ConvertUsingIccProfile(this ColorProfileConverter converter, ReadOnlySpan source, Span destination) + where TFrom : struct, IColorProfile + where TTo : struct, IColorProfile + { + // TODO: Validation of ICC Profiles against color profile. Is this possible? + if (converter.Options.SourceIccProfile is null) + { + throw new InvalidOperationException("Source ICC profile is missing."); + } + + if (converter.Options.TargetIccProfile is null) + { + throw new InvalidOperationException("Target ICC profile is missing."); + } + + Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(destination)); + + ConversionParams sourceParams = new(converter.Options.SourceIccProfile, toPcs: true); + ConversionParams targetParams = new(converter.Options.TargetIccProfile, toPcs: false); + + ColorProfileConverter pcsConverter = new(new ColorConversionOptions + { + MemoryAllocator = converter.Options.MemoryAllocator, + SourceWhitePoint = new CieXyz(converter.Options.SourceIccProfile.Header.PcsIlluminant), + TargetWhitePoint = new CieXyz(converter.Options.TargetIccProfile.Header.PcsIlluminant), + }); + + using IMemoryOwner pcsBuffer = converter.Options.MemoryAllocator.Allocate(source.Length); + Span pcs = pcsBuffer.GetSpan(); + + // Normalize the source, then convert to the PCS space. + TFrom.ToScaledVector4(source, pcs); + sourceParams.Converter.Calculate(pcs, pcs); + + // If both profiles need PCS adjustment, they both share the same unadjusted PCS space + // cancelling out the need to make the adjustment + // except if using TRC transforms, which always requires perceptual handling + // TODO: this does not include adjustment for absolute intent, which would double existing complexity, suggest throwing exception and addressing in future update + bool anyProfileNeedsPerceptualAdjustment = sourceParams.HasNoPerceptualHandling || targetParams.HasNoPerceptualHandling; + bool oneProfileHasV2PerceptualAdjustment = sourceParams.HasV2PerceptualHandling ^ targetParams.HasV2PerceptualHandling; + + if (anyProfileNeedsPerceptualAdjustment || oneProfileHasV2PerceptualAdjustment) + { + GetTargetPcsWithPerceptualAdjustment(pcs, sourceParams, targetParams, pcsConverter); + } + else + { + GetTargetPcsWithoutAdjustment(pcs, sourceParams, targetParams, pcsConverter); + } + + // Convert to the target space. + targetParams.Converter.Calculate(pcs, pcs); + TTo.FromScaledVector4(pcs, destination); + } + + private static Vector4 GetTargetPcsWithoutAdjustment( + Vector4 sourcePcs, + ConversionParams sourceParams, + ConversionParams targetParams, + ColorProfileConverter pcsConverter) + { + // Profile connecting spaces can only be Lab, XYZ. + // 16-bit Lab encodings changed from v2 to v4, but 16-bit LUTs always use the legacy encoding regardless of version + // so ensure that Lab is using the correct encoding when a 16-bit LUT is used + switch (sourceParams.PcsType) + { + // Convert from Lab to XYZ. + case IccColorSpaceType.CieLab when targetParams.PcsType is IccColorSpaceType.CieXyz: + { + sourcePcs = sourceParams.Is16BitLutEntry ? LabV2ToLab(sourcePcs) : sourcePcs; + CieLab lab = CieLab.FromScaledVector4(sourcePcs); + CieXyz xyz = pcsConverter.Convert(in lab); + return xyz.ToScaledVector4(); + } + + // Convert from XYZ to Lab. + case IccColorSpaceType.CieXyz when targetParams.PcsType is IccColorSpaceType.CieLab: + { + CieXyz xyz = CieXyz.FromScaledVector4(sourcePcs); + CieLab lab = pcsConverter.Convert(in xyz); + Vector4 targetPcs = lab.ToScaledVector4(); + return targetParams.Is16BitLutEntry ? LabToLabV2(targetPcs) : targetPcs; + } + + // Convert from XYZ to XYZ. + case IccColorSpaceType.CieXyz when targetParams.PcsType is IccColorSpaceType.CieXyz: + { + CieXyz xyz = CieXyz.FromScaledVector4(sourcePcs); + CieXyz targetXyz = pcsConverter.Convert(in xyz); + return targetXyz.ToScaledVector4(); + } + + // Convert from Lab to Lab. + case IccColorSpaceType.CieLab when targetParams.PcsType is IccColorSpaceType.CieLab: + { + // if both source and target LUT use same v2 LAB encoding, no need to correct them + if (sourceParams.Is16BitLutEntry && targetParams.Is16BitLutEntry) + { + CieLab sourceLab = CieLab.FromScaledVector4(sourcePcs); + CieLab targetLab = pcsConverter.Convert(in sourceLab); + return targetLab.ToScaledVector4(); + } + else + { + sourcePcs = sourceParams.Is16BitLutEntry ? LabV2ToLab(sourcePcs) : sourcePcs; + CieLab sourceLab = CieLab.FromScaledVector4(sourcePcs); + CieLab targetLab = pcsConverter.Convert(in sourceLab); + Vector4 targetPcs = targetLab.ToScaledVector4(); + return targetParams.Is16BitLutEntry ? LabToLabV2(targetPcs) : targetPcs; + } + } + + default: + throw new ArgumentOutOfRangeException($"Source PCS {sourceParams.PcsType} to target PCS {targetParams.PcsType} is not supported"); + } + } + + private static void GetTargetPcsWithoutAdjustment( + Span pcs, + ConversionParams sourceParams, + ConversionParams targetParams, + ColorProfileConverter pcsConverter) + { + // Profile connecting spaces can only be Lab, XYZ. + // 16-bit Lab encodings changed from v2 to v4, but 16-bit LUTs always use the legacy encoding regardless of version + // so ensure that Lab is using the correct encoding when a 16-bit LUT is used + switch (sourceParams.PcsType) + { + // Convert from Lab to XYZ. + case IccColorSpaceType.CieLab when targetParams.PcsType is IccColorSpaceType.CieXyz: + { + if (sourceParams.Is16BitLutEntry) + { + LabV2ToLab(pcs, pcs); + } + + using IMemoryOwner pcsFromBuffer = pcsConverter.Options.MemoryAllocator.Allocate(pcs.Length); + Span pcsFrom = pcsFromBuffer.GetSpan(); + + using IMemoryOwner pcsToBuffer = pcsConverter.Options.MemoryAllocator.Allocate(pcs.Length); + Span pcsTo = pcsToBuffer.GetSpan(); + + CieLab.FromScaledVector4(pcs, pcsFrom); + pcsConverter.Convert(pcsFrom, pcsTo); + + CieXyz.ToScaledVector4(pcsTo, pcs); + break; + } + + // Convert from XYZ to Lab. + case IccColorSpaceType.CieXyz when targetParams.PcsType is IccColorSpaceType.CieLab: + { + using IMemoryOwner pcsFromBuffer = pcsConverter.Options.MemoryAllocator.Allocate(pcs.Length); + Span pcsFrom = pcsFromBuffer.GetSpan(); + + using IMemoryOwner pcsToBuffer = pcsConverter.Options.MemoryAllocator.Allocate(pcs.Length); + Span pcsTo = pcsToBuffer.GetSpan(); + + CieXyz.FromScaledVector4(pcs, pcsFrom); + pcsConverter.Convert(pcsFrom, pcsTo); + + CieLab.ToScaledVector4(pcsTo, pcs); + + if (targetParams.Is16BitLutEntry) + { + LabToLabV2(pcs, pcs); + } + + break; + } + + // Convert from XYZ to XYZ. + case IccColorSpaceType.CieXyz when targetParams.PcsType is IccColorSpaceType.CieXyz: + { + using IMemoryOwner pcsFromToBuffer = pcsConverter.Options.MemoryAllocator.Allocate(pcs.Length); + Span pcsFromTo = pcsFromToBuffer.GetSpan(); + + CieXyz.FromScaledVector4(pcs, pcsFromTo); + pcsConverter.Convert(pcsFromTo, pcsFromTo); + + CieXyz.ToScaledVector4(pcsFromTo, pcs); + break; + } + + // Convert from Lab to Lab. + case IccColorSpaceType.CieLab when targetParams.PcsType is IccColorSpaceType.CieLab: + { + using IMemoryOwner pcsFromToBuffer = pcsConverter.Options.MemoryAllocator.Allocate(pcs.Length); + Span pcsFromTo = pcsFromToBuffer.GetSpan(); + + // if both source and target LUT use same v2 LAB encoding, no need to correct them + if (sourceParams.Is16BitLutEntry && targetParams.Is16BitLutEntry) + { + CieLab.FromScaledVector4(pcs, pcsFromTo); + pcsConverter.Convert(pcsFromTo, pcsFromTo); + CieLab.ToScaledVector4(pcsFromTo, pcs); + } + else + { + if (sourceParams.Is16BitLutEntry) + { + LabV2ToLab(pcs, pcs); + } + + CieLab.FromScaledVector4(pcs, pcsFromTo); + pcsConverter.Convert(pcsFromTo, pcsFromTo); + CieLab.ToScaledVector4(pcsFromTo, pcs); + + if (targetParams.Is16BitLutEntry) + { + LabToLabV2(pcs, pcs); + } + } + + break; + } + + default: + throw new ArgumentOutOfRangeException($"Source PCS {sourceParams.PcsType} to target PCS {targetParams.PcsType} is not supported"); + } + } + + /// + /// Effectively this is with an extra step in the middle. + /// It adjusts PCS by compensating for the black point used for perceptual intent in v2 profiles. + /// The adjustment needs to be performed in XYZ space, potentially an overhead of 2 more conversions. + /// Not required if both spaces need V2 correction, since they both have the same understanding of the PCS. + /// Not compatible with PCS adjustment for absolute intent. + /// + /// The source PCS values. + /// The source profile parameters. + /// The target profile parameters. + /// The converter to use for the PCS adjustments. + /// Thrown when the source or target PCS is not supported. + private static Vector4 GetTargetPcsWithPerceptualAdjustment( + Vector4 sourcePcs, + ConversionParams sourceParams, + ConversionParams targetParams, + ColorProfileConverter pcsConverter) + { + // all conversions are funneled through XYZ in case PCS adjustments need to be made + CieXyz xyz; + + switch (sourceParams.PcsType) + { + // 16-bit Lab encodings changed from v2 to v4, but 16-bit LUTs always use the legacy encoding regardless of version + // so convert Lab to modern v4 encoding when returned from a 16-bit LUT + case IccColorSpaceType.CieLab: + sourcePcs = sourceParams.Is16BitLutEntry ? LabV2ToLab(sourcePcs) : sourcePcs; + CieLab lab = CieLab.FromScaledVector4(sourcePcs); + xyz = pcsConverter.Convert(in lab); + break; + case IccColorSpaceType.CieXyz: + xyz = CieXyz.FromScaledVector4(sourcePcs); + break; + default: + throw new ArgumentOutOfRangeException($"Source PCS {sourceParams.PcsType} is not supported"); + } + + bool oneProfileHasV2PerceptualAdjustment = sourceParams.HasV2PerceptualHandling ^ targetParams.HasV2PerceptualHandling; + + // when converting from device to PCS with v2 perceptual intent + // the black point needs to be adjusted to v4 after converting the PCS values + if (sourceParams.HasNoPerceptualHandling || + (oneProfileHasV2PerceptualAdjustment && sourceParams.HasV2PerceptualHandling)) + { + Vector3 vector = xyz.ToVector3(); + + // when using LAB PCS, negative values are clipped before PCS adjustment (in DemoIccMAX) + if (sourceParams.PcsType == IccColorSpaceType.CieLab) + { + vector = Vector3.Max(vector, Vector3.Zero); + } + + xyz = new CieXyz(AdjustPcsFromV2BlackPoint(vector)); + } + + // when converting from PCS to device with v2 perceptual intent + // the black point needs to be adjusted to v2 before converting the PCS values + if (targetParams.HasNoPerceptualHandling || + (oneProfileHasV2PerceptualAdjustment && targetParams.HasV2PerceptualHandling)) + { + Vector3 vector = AdjustPcsToV2BlackPoint(xyz.AsVector3Unsafe()); + + // when using XYZ PCS, negative values are clipped after PCS adjustment (in DemoIccMAX) + if (targetParams.PcsType == IccColorSpaceType.CieXyz) + { + vector = Vector3.Max(vector, Vector3.Zero); + } + + xyz = new CieXyz(vector); + } + + switch (targetParams.PcsType) + { + // 16-bit Lab encodings changed from v2 to v4, but 16-bit LUTs always use the legacy encoding regardless of version + // so convert Lab back to legacy encoding before using in a 16-bit LUT + case IccColorSpaceType.CieLab: + CieLab lab = pcsConverter.Convert(in xyz); + Vector4 targetPcs = lab.ToScaledVector4(); + return targetParams.Is16BitLutEntry ? LabToLabV2(targetPcs) : targetPcs; + case IccColorSpaceType.CieXyz: + return xyz.ToScaledVector4(); + default: + throw new ArgumentOutOfRangeException($"Target PCS {targetParams.PcsType} is not supported"); + } + } + + /// + /// Effectively this is with an extra step in the middle. + /// It adjusts PCS by compensating for the black point used for perceptual intent in v2 profiles. + /// The adjustment needs to be performed in XYZ space, potentially an overhead of 2 more conversions. + /// Not required if both spaces need V2 correction, since they both have the same understanding of the PCS. + /// Not compatible with PCS adjustment for absolute intent. + /// + /// The PCS values from the source. + /// The source profile parameters. + /// The target profile parameters. + /// The converter to use for the PCS adjustments. + /// Thrown when the source or target PCS is not supported. + private static void GetTargetPcsWithPerceptualAdjustment( + Span pcs, + ConversionParams sourceParams, + ConversionParams targetParams, + ColorProfileConverter pcsConverter) + { + // All conversions are funneled through XYZ in case PCS adjustments need to be made + using IMemoryOwner xyzBuffer = pcsConverter.Options.MemoryAllocator.Allocate(pcs.Length); + Span xyz = xyzBuffer.GetSpan(); + + switch (sourceParams.PcsType) + { + // 16-bit Lab encodings changed from v2 to v4, but 16-bit LUTs always use the legacy encoding regardless of version + // so convert Lab to modern v4 encoding when returned from a 16-bit LUT + case IccColorSpaceType.CieLab: + { + if (sourceParams.Is16BitLutEntry) + { + LabV2ToLab(pcs, pcs); + } + + using IMemoryOwner pcsFromBuffer = pcsConverter.Options.MemoryAllocator.Allocate(pcs.Length); + Span pcsFrom = pcsFromBuffer.GetSpan(); + CieLab.FromScaledVector4(pcs, pcsFrom); + pcsConverter.Convert(pcsFrom, xyz); + break; + } + + case IccColorSpaceType.CieXyz: + CieXyz.FromScaledVector4(pcs, xyz); + break; + default: + throw new ArgumentOutOfRangeException($"Source PCS {sourceParams.PcsType} is not supported"); + } + + bool oneProfileHasV2PerceptualAdjustment = sourceParams.HasV2PerceptualHandling ^ targetParams.HasV2PerceptualHandling; + + using IMemoryOwner vectorBuffer = pcsConverter.Options.MemoryAllocator.Allocate(pcs.Length); + Span vector = vectorBuffer.GetSpan(); + + // When converting from device to PCS with v2 perceptual intent + // the black point needs to be adjusted to v4 after converting the PCS values + if (sourceParams.HasNoPerceptualHandling || + (oneProfileHasV2PerceptualAdjustment && sourceParams.HasV2PerceptualHandling)) + { + CieXyz.ToVector4(xyz, vector); + + // When using LAB PCS, negative values are clipped before PCS adjustment (in DemoIccMAX) + if (sourceParams.PcsType == IccColorSpaceType.CieLab) + { + ClipNegative(vector); + } + + AdjustPcsFromV2BlackPoint(vector, vector); + CieXyz.FromVector4(vector, xyz); + } + + // When converting from PCS to device with v2 perceptual intent + // the black point needs to be adjusted to v2 before converting the PCS values + if (targetParams.HasNoPerceptualHandling || + (oneProfileHasV2PerceptualAdjustment && targetParams.HasV2PerceptualHandling)) + { + CieXyz.ToVector4(xyz, vector); + AdjustPcsToV2BlackPoint(vector, vector); + + // When using XYZ PCS, negative values are clipped after PCS adjustment (in DemoIccMAX) + if (targetParams.PcsType == IccColorSpaceType.CieXyz) + { + ClipNegative(vector); + } + + CieXyz.FromVector4(vector, xyz); + } + + switch (targetParams.PcsType) + { + // 16-bit Lab encodings changed from v2 to v4, but 16-bit LUTs always use the legacy encoding regardless of version + // so convert Lab back to legacy encoding before using in a 16-bit LUT + case IccColorSpaceType.CieLab: + { + using IMemoryOwner pcsToBuffer = pcsConverter.Options.MemoryAllocator.Allocate(pcs.Length); + Span pcsTo = pcsToBuffer.GetSpan(); + pcsConverter.Convert(xyz, pcsTo); + + CieLab.ToScaledVector4(pcsTo, pcs); + + if (targetParams.Is16BitLutEntry) + { + LabToLabV2(pcs, pcs); + } + + break; + } + + case IccColorSpaceType.CieXyz: + CieXyz.ToScaledVector4(xyz, pcs); + break; + default: + throw new ArgumentOutOfRangeException($"Target PCS {targetParams.PcsType} is not supported"); + } + } + + // as per DemoIccMAX icPerceptual values in IccCmm.h + // refBlack = 0.00336F, 0.0034731F, 0.00287F + // refWhite = 0.9642F, 1.0000F, 0.8249F + // scale = 1 - (refBlack / refWhite) + // offset = refBlack + private static Vector3 AdjustPcsFromV2BlackPoint(Vector3 xyz) + => (xyz * new Vector3(0.9965153F, 0.9965269F, 0.9965208F)) + new Vector3(0.00336F, 0.0034731F, 0.00287F); + + // as per DemoIccMAX icPerceptual values in IccCmm.h + // refBlack = 0.00336F, 0.0034731F, 0.00287F + // refWhite = 0.9642F, 1.0000F, 0.8249F + // scale = 1 / (1 - (refBlack / refWhite)) + // offset = -refBlack * scale + private static Vector3 AdjustPcsToV2BlackPoint(Vector3 xyz) + => (xyz * new Vector3(1.0034969F, 1.0034852F, 1.0034913F)) - new Vector3(0.0033717495F, 0.0034852044F, 0.0028800198F); + + private static void AdjustPcsFromV2BlackPoint(Span source, Span destination) + { + if (Vector.IsHardwareAccelerated && Vector.IsSupported && + Vector.Count <= Vector512.Count && + source.Length * 4 >= Vector.Count) + { + // TODO: Check our constants. They may require scaling. + Vector vScale = new(PcsV2FromBlackPointScale.AsSpan()[..Vector.Count]); + Vector vOffset = new(PcsV2FromBlackPointOffset.AsSpan()[..Vector.Count]); + + // SIMD loop + int i = 0; + int simdBatchSize = Vector.Count / 4; // Number of Vector4 elements per SIMD batch + for (; i <= source.Length - simdBatchSize; i += simdBatchSize) + { + // Load the vector from source span + Vector v = Unsafe.ReadUnaligned>(ref Unsafe.As(ref source[i])); + + // Scale and offset the vector + v *= vScale; + v += vOffset; + + // Write the vector to the destination span + Unsafe.WriteUnaligned(ref Unsafe.As(ref destination[i]), v); + } + + // Scalar fallback for remaining elements + for (; i < source.Length; i++) + { + Vector4 s = source[i]; + s *= new Vector4(0.9965153F, 0.9965269F, 0.9965208F, 1F); + s += new Vector4(0.00336F, 0.0034731F, 0.00287F, 0F); + destination[i] = s; + } + } + else + { + // Scalar fallback if SIMD is not supported + for (int i = 0; i < source.Length; i++) + { + Vector4 s = source[i]; + s *= new Vector4(0.9965153F, 0.9965269F, 0.9965208F, 1F); + s += new Vector4(0.00336F, 0.0034731F, 0.00287F, 0F); + destination[i] = s; + } + } + } + + private static void AdjustPcsToV2BlackPoint(Span source, Span destination) + { + if (Vector.IsHardwareAccelerated && Vector.IsSupported && + Vector.Count <= Vector512.Count && + source.Length * 4 >= Vector.Count) + { + // TODO: Check our constants. They may require scaling. + Vector vScale = new(PcsV2ToBlackPointScale.AsSpan()[..Vector.Count]); + Vector vOffset = new(PcsV2ToBlackPointOffset.AsSpan()[..Vector.Count]); + + // SIMD loop + int i = 0; + int simdBatchSize = Vector.Count / 4; // Number of Vector4 elements per SIMD batch + for (; i <= source.Length - simdBatchSize; i += simdBatchSize) + { + // Load the vector from source span + Vector v = Unsafe.ReadUnaligned>(ref Unsafe.As(ref source[i])); + + // Scale and offset the vector + v *= vScale; + v -= vOffset; + + // Write the vector to the destination span + Unsafe.WriteUnaligned(ref Unsafe.As(ref destination[i]), v); + } + + // Scalar fallback for remaining elements + for (; i < source.Length; i++) + { + Vector4 s = source[i]; + s *= new Vector4(1.0034969F, 1.0034852F, 1.0034913F, 1F); + s -= new Vector4(0.0033717495F, 0.0034852044F, 0.0028800198F, 0F); + destination[i] = s; + } + } + else + { + // Scalar fallback if SIMD is not supported + for (int i = 0; i < source.Length; i++) + { + Vector4 s = source[i]; + s *= new Vector4(1.0034969F, 1.0034852F, 1.0034913F, 1F); + s -= new Vector4(0.0033717495F, 0.0034852044F, 0.0028800198F, 0F); + destination[i] = s; + } + } + } + + private static void ClipNegative(Span source) + { + if (Vector.IsHardwareAccelerated && Vector.IsSupported && Vector.Count >= source.Length * 4) + { + // SIMD loop + int i = 0; + int simdBatchSize = Vector.Count / 4; // Number of Vector4 elements per SIMD batch + for (; i <= source.Length - simdBatchSize; i += simdBatchSize) + { + // Load the vector from source span + Vector v = Unsafe.ReadUnaligned>(ref Unsafe.As(ref source[i])); + + v = Vector.Max(v, Vector.Zero); + + // Write the vector to the destination span + Unsafe.WriteUnaligned(ref Unsafe.As(ref source[i]), v); + } + + // Scalar fallback for remaining elements + for (; i < source.Length; i++) + { + ref Vector4 s = ref source[i]; + s = Vector4.Max(s, Vector4.Zero); + } + } + else + { + // Scalar fallback if SIMD is not supported + for (int i = 0; i < source.Length; i++) + { + ref Vector4 s = ref source[i]; + s = Vector4.Max(s, Vector4.Zero); + } + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static Vector4 LabToLabV2(Vector4 input) + => input * 65280F / 65535F; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static Vector4 LabV2ToLab(Vector4 input) + => input * 65535F / 65280F; + + private static void LabToLabV2(Span source, Span destination) + => LabToLab(source, destination, 65280F / 65535F); + + private static void LabV2ToLab(Span source, Span destination) + => LabToLab(source, destination, 65535F / 65280F); + + private static void LabToLab(Span source, Span destination, [ConstantExpected] float scale) + { + if (Vector.IsHardwareAccelerated && Vector.IsSupported) + { + Vector vScale = new(scale); + int i = 0; + + // SIMD loop + int simdBatchSize = Vector.Count / 4; // Number of Vector4 elements per SIMD batch + for (; i <= source.Length - simdBatchSize; i += simdBatchSize) + { + // Load the vector from source span + Vector v = Unsafe.ReadUnaligned>(ref Unsafe.As(ref source[i])); + + // Scale the vector + v *= vScale; + + // Write the scaled vector to the destination span + Unsafe.WriteUnaligned(ref Unsafe.As(ref destination[i]), v); + } + + // Scalar fallback for remaining elements + for (; i < source.Length; i++) + { + destination[i] = source[i] * scale; + } + } + else + { + // Scalar fallback if SIMD is not supported + for (int i = 0; i < source.Length; i++) + { + destination[i] = source[i] * scale; + } + } + } + + private class ConversionParams + { + private readonly IccProfile profile; + + internal ConversionParams(IccProfile profile, bool toPcs) + { + this.profile = profile; + this.Converter = toPcs ? new IccDataToPcsConverter(profile) : new IccPcsToDataConverter(profile); + } + + internal IccConverterBase Converter { get; } + + internal IccProfileHeader Header => this.profile.Header; + + internal IccRenderingIntent Intent => this.Header.RenderingIntent; + + internal IccColorSpaceType PcsType => this.Header.ProfileConnectionSpace; + + internal IccVersion Version => this.Header.Version; + + internal bool HasV2PerceptualHandling => this.Intent == IccRenderingIntent.Perceptual && this.Version.Major == 2; + + internal bool HasNoPerceptualHandling => this.Intent == IccRenderingIntent.Perceptual && this.Converter.IsTrc; + + internal bool Is16BitLutEntry => this.Converter.Is16BitLutEntry; + } +} diff --git a/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsRgbCieLab.cs b/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsRgbCieLab.cs index 415dd94c3f..badbcc6831 100644 --- a/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsRgbCieLab.cs +++ b/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsRgbCieLab.cs @@ -12,6 +12,11 @@ internal static class ColorProfileConverterExtensionsRgbCieLab where TFrom : struct, IColorProfile where TTo : struct, IColorProfile { + if (converter.ShouldUseIccProfiles()) + { + return converter.ConvertUsingIccProfile(source); + } + ColorConversionOptions options = converter.Options; // Convert to input PCS @@ -33,6 +38,12 @@ internal static class ColorProfileConverterExtensionsRgbCieLab where TFrom : struct, IColorProfile where TTo : struct, IColorProfile { + if (converter.ShouldUseIccProfiles()) + { + converter.ConvertUsingIccProfile(source, destination); + return; + } + ColorConversionOptions options = converter.Options; // Convert to input PCS. diff --git a/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsRgbCieXyz.cs b/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsRgbCieXyz.cs index a13f645778..cd7d5e4d65 100644 --- a/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsRgbCieXyz.cs +++ b/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsRgbCieXyz.cs @@ -12,6 +12,11 @@ internal static class ColorProfileConverterExtensionsRgbCieXyz where TFrom : struct, IColorProfile where TTo : struct, IColorProfile { + if (converter.ShouldUseIccProfiles()) + { + return converter.ConvertUsingIccProfile(source); + } + ColorConversionOptions options = converter.Options; // Convert to input PCS @@ -32,6 +37,12 @@ internal static class ColorProfileConverterExtensionsRgbCieXyz where TFrom : struct, IColorProfile where TTo : struct, IColorProfile { + if (converter.ShouldUseIccProfiles()) + { + converter.ConvertUsingIccProfile(source, destination); + return; + } + ColorConversionOptions options = converter.Options; // Convert to input PCS. diff --git a/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsRgbRgb.cs b/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsRgbRgb.cs index c1c75dea1b..2a4b64b1ca 100644 --- a/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsRgbRgb.cs +++ b/src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsRgbRgb.cs @@ -12,6 +12,11 @@ internal static class ColorProfileConverterExtensionsRgbRgb where TFrom : struct, IColorProfile where TTo : struct, IColorProfile { + if (converter.ShouldUseIccProfiles()) + { + return converter.ConvertUsingIccProfile(source); + } + ColorConversionOptions options = converter.Options; // Convert to input PCS @@ -33,6 +38,12 @@ internal static class ColorProfileConverterExtensionsRgbRgb where TFrom : struct, IColorProfile where TTo : struct, IColorProfile { + if (converter.ShouldUseIccProfiles()) + { + converter.ConvertUsingIccProfile(source, destination); + return; + } + ColorConversionOptions options = converter.Options; // Convert to input PCS. diff --git a/src/ImageSharp/ColorProfiles/Hsl.cs b/src/ImageSharp/ColorProfiles/Hsl.cs index 2c98c7df99..7a9365fb75 100644 --- a/src/ImageSharp/ColorProfiles/Hsl.cs +++ b/src/ImageSharp/ColorProfiles/Hsl.cs @@ -41,6 +41,16 @@ public readonly struct Hsl : IColorProfile this.L = vector.Z; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#pragma warning disable SA1313 // Parameter names should begin with lower-case letter + private Hsl(Vector3 vector, bool _) +#pragma warning restore SA1313 // Parameter names should begin with lower-case letter + { + this.H = vector.X; + this.S = vector.Y; + this.L = vector.Z; + } + /// /// Gets the hue component. /// A value ranging between 0 and 360. @@ -83,6 +93,38 @@ public readonly struct Hsl : IColorProfile [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Hsl left, Hsl right) => !left.Equals(right); + /// + public Vector4 ToScaledVector4() + => new(this.AsVector3Unsafe() / 360F, 1F); + + /// + public static Hsl FromScaledVector4(Vector4 source) + => new(source.AsVector3() * 360F, true); + + /// + public static void ToScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = source[i].ToScaledVector4(); + } + } + + /// + public static void FromScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = FromScaledVector4(source[i]); + } + } + /// public static Hsl FromProfileConnectingSpace(ColorConversionOptions options, in Rgb source) { diff --git a/src/ImageSharp/ColorProfiles/Hsv.cs b/src/ImageSharp/ColorProfiles/Hsv.cs index 7535f2463d..1e013fe1fb 100644 --- a/src/ImageSharp/ColorProfiles/Hsv.cs +++ b/src/ImageSharp/ColorProfiles/Hsv.cs @@ -41,6 +41,16 @@ public readonly struct Hsv : IColorProfile this.V = vector.Z; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#pragma warning disable SA1313 // Parameter names should begin with lower-case letter + private Hsv(Vector3 vector, bool _) +#pragma warning restore SA1313 // Parameter names should begin with lower-case letter + { + this.H = vector.X; + this.S = vector.Y; + this.V = vector.Z; + } + /// /// Gets the hue component. /// A value ranging between 0 and 360. @@ -81,6 +91,38 @@ public readonly struct Hsv : IColorProfile [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Hsv left, Hsv right) => !left.Equals(right); + /// + public Vector4 ToScaledVector4() + => new(this.AsVector3Unsafe() / 360F, 1F); + + /// + public static Hsv FromScaledVector4(Vector4 source) + => new(source.AsVector3() * 360F, true); + + /// + public static void ToScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = source[i].ToScaledVector4(); + } + } + + /// + public static void FromScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = FromScaledVector4(source[i]); + } + } + /// public static Hsv FromProfileConnectingSpace(ColorConversionOptions options, in Rgb source) { diff --git a/src/ImageSharp/ColorProfiles/HunterLab.cs b/src/ImageSharp/ColorProfiles/HunterLab.cs index 43ad2ac5c0..e978c6de22 100644 --- a/src/ImageSharp/ColorProfiles/HunterLab.cs +++ b/src/ImageSharp/ColorProfiles/HunterLab.cs @@ -80,6 +80,49 @@ public readonly struct HunterLab : IColorProfile [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(HunterLab left, HunterLab right) => !left.Equals(right); + /// + public Vector4 ToScaledVector4() + { + Vector3 v3 = default; + v3 += this.AsVector3Unsafe(); + v3 += new Vector3(0, 128F, 128F); + v3 /= new Vector3(100F, 255F, 255F); + return new Vector4(v3, 1F); + } + + /// + public static HunterLab FromScaledVector4(Vector4 source) + { + Vector3 v3 = source.AsVector3(); + v3 *= new Vector3(100F, 255, 255); + v3 -= new Vector3(0, 128F, 128F); + return new HunterLab(v3); + } + + /// + public static void ToScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = source[i].ToScaledVector4(); + } + } + + /// + public static void FromScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = FromScaledVector4(source[i]); + } + } + /// public static HunterLab FromProfileConnectingSpace(ColorConversionOptions options, in CieXyz source) { @@ -127,7 +170,7 @@ public readonly struct HunterLab : IColorProfile { // Conversion algorithm described here: // http://en.wikipedia.org/wiki/Lab_color_space#Hunter_Lab - CieXyz whitePoint = options.WhitePoint; + CieXyz whitePoint = options.SourceWhitePoint; float l = this.L, a = this.A, b = this.B; float xn = whitePoint.X, yn = whitePoint.Y, zn = whitePoint.Z; diff --git a/src/ImageSharp/ColorProfiles/IColorProfile.cs b/src/ImageSharp/ColorProfiles/IColorProfile.cs index 6a1b2ee8d0..425e030300 100644 --- a/src/ImageSharp/ColorProfiles/IColorProfile.cs +++ b/src/ImageSharp/ColorProfiles/IColorProfile.cs @@ -1,6 +1,8 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +using System.Numerics; + namespace SixLabors.ImageSharp.ColorProfiles; /// @@ -15,18 +17,60 @@ public interface IColorProfile public static abstract ChromaticAdaptionWhitePointSource GetChromaticAdaptionWhitePointSource(); } +/// +/// Defines the contract for all color profiles. +/// +/// The type of color profile. +public interface IColorProfile : IColorProfile, IEquatable + where TSelf : IColorProfile +{ + /// + /// Expands the pixel into a generic ("scaled") representation + /// with values scaled and clamped between 0 and 1. + /// The vector components are typically expanded in least to greatest significance order. + /// + /// The . + public Vector4 ToScaledVector4(); + +#pragma warning disable CA1000 // Do not declare static members on generic types + /// + /// Initializes the color instance from a generic a generic ("scaled") representation + /// with values scaled and clamped between 0 and 1. + /// + /// The vector to load the pixel from. + /// The . + public static abstract TSelf FromScaledVector4(Vector4 source); + + /// + /// Converts the span of colors to a generic ("scaled") representation + /// with values scaled and clamped between 0 and 1. + /// + /// The color span to convert from. + /// The vector span to write the results to. + public static abstract void ToScaledVector4(ReadOnlySpan source, Span destination); + + /// + /// Converts the span of colors from a generic ("scaled") representation + /// with values scaled and clamped between 0 and 1. + /// + /// The vector span to convert from. + /// The color span to write the results to. + public static abstract void FromScaledVector4(ReadOnlySpan source, Span destination); +#pragma warning restore CA1000 // Do not declare static members on generic types +} + /// /// Defines the contract for all color profiles. /// /// The type of color profile. /// The type of color profile connecting space. -public interface IColorProfile : IColorProfile, IEquatable +public interface IColorProfile : IColorProfile where TSelf : IColorProfile where TProfileSpace : struct, IProfileConnectingSpace { #pragma warning disable CA1000 // Do not declare static members on generic types /// - /// Converts the color from the profile connection space. + /// Initializes the color instance from the profile connection space. /// /// The color profile conversion options. /// The color profile connecting space. diff --git a/src/ImageSharp/ColorProfiles/Icc/Calculators/ClutCalculator.cs b/src/ImageSharp/ColorProfiles/Icc/Calculators/ClutCalculator.cs new file mode 100644 index 0000000000..82d475e578 --- /dev/null +++ b/src/ImageSharp/ColorProfiles/Icc/Calculators/ClutCalculator.cs @@ -0,0 +1,506 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Numerics; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; + +namespace SixLabors.ImageSharp.ColorProfiles.Icc.Calculators; + +/// +/// Implements interpolation methods for color profile lookup tables. +/// Adapted from ICC Reference implementation: +/// https://github.com/InternationalColorConsortium/DemoIccMAX/blob/79ecb74135ad47bac7d42692905a079839b7e105/IccProfLib/IccTagLut.cpp +/// +internal class ClutCalculator : IVector4Calculator +{ + private readonly int inputCount; + private readonly int outputCount; + private readonly float[] lut; + private readonly byte[] gridPointCount; + private readonly byte[] maxGridPoint; + private readonly int[] indexFactor; + private readonly int[] dimSize; + private readonly int nodeCount; + private readonly float[][] nodes; + private readonly float[] g; + private readonly uint[] ig; + private readonly float[] s; + private readonly float[] df; + private readonly uint[] nPower; + private int n000; + private int n001; + private int n010; + private int n011; + private int n100; + private int n101; + private int n110; + private int n111; + private int n1000; + + public ClutCalculator(IccClut clut) + { + Guard.NotNull(clut, nameof(clut)); + Guard.MustBeGreaterThan(clut.InputChannelCount, 0, nameof(clut.InputChannelCount)); + Guard.MustBeGreaterThan(clut.OutputChannelCount, 0, nameof(clut.OutputChannelCount)); + + this.inputCount = clut.InputChannelCount; + this.outputCount = clut.OutputChannelCount; + this.g = new float[this.inputCount]; + this.ig = new uint[this.inputCount]; + this.s = new float[this.inputCount]; + this.nPower = new uint[16]; + this.lut = clut.Values; + this.nodeCount = (int)Math.Pow(2, clut.InputChannelCount); + this.df = new float[this.nodeCount]; + this.nodes = new float[this.nodeCount][]; + this.dimSize = new int[this.inputCount]; + this.gridPointCount = clut.GridPointCount; + this.maxGridPoint = new byte[this.inputCount]; + for (int i = 0; i < this.inputCount; i++) + { + this.maxGridPoint[i] = (byte)(this.gridPointCount[i] - 1); + } + + this.dimSize[this.inputCount - 1] = this.outputCount; + for (int i = this.inputCount - 2; i >= 0; i--) + { + this.dimSize[i] = this.dimSize[i + 1] * this.gridPointCount[i + 1]; + } + + this.indexFactor = this.CalculateIndexFactor(); + } + + public unsafe Vector4 Calculate(Vector4 value) + { + Vector4 result = default; + switch (this.inputCount) + { + case 1: + this.Interpolate1d((float*)&value, (float*)&result); + break; + case 2: + this.Interpolate2d((float*)&value, (float*)&result); + break; + case 3: + this.Interpolate3d((float*)&value, (float*)&result); + break; + case 4: + this.Interpolate4d((float*)&value, (float*)&result); + break; + default: + this.InterpolateNd((float*)&value, (float*)&result); + break; + } + + return result; + } + + private int[] CalculateIndexFactor() + { + int[] factors = new int[16]; + switch (this.inputCount) + { + case 1: + factors[0] = this.n000 = 0; + factors[1] = this.n001 = this.dimSize[0]; + break; + case 2: + factors[0] = this.n000 = 0; + factors[1] = this.n001 = this.dimSize[0]; + factors[2] = this.n010 = this.dimSize[1]; + factors[3] = this.n011 = this.n001 + this.n010; + break; + case 3: + factors[0] = this.n000 = 0; + factors[1] = this.n001 = this.dimSize[0]; + factors[2] = this.n010 = this.dimSize[1]; + factors[3] = this.n011 = this.n001 + this.n010; + factors[4] = this.n100 = this.dimSize[2]; + factors[5] = this.n101 = this.n100 + this.n001; + factors[6] = this.n110 = this.n100 + this.n010; + factors[7] = this.n111 = this.n110 + this.n001; + break; + case 4: + factors[0] = 0; + factors[1] = this.n001 = this.dimSize[0]; + factors[2] = this.n010 = this.dimSize[1]; + factors[3] = factors[2] + factors[1]; + factors[4] = this.n100 = this.dimSize[2]; + factors[5] = factors[4] + factors[1]; + factors[6] = factors[4] + factors[2]; + factors[7] = factors[4] + factors[3]; + factors[8] = this.n1000 = this.dimSize[3]; + factors[9] = factors[8] + factors[1]; + factors[10] = factors[8] + factors[2]; + factors[11] = factors[8] + factors[3]; + factors[12] = factors[8] + factors[4]; + factors[13] = factors[8] + factors[5]; + factors[14] = factors[8] + factors[6]; + factors[15] = factors[8] + factors[7]; + break; + default: + // Initialize ND interpolation variables. + factors[0] = 0; + int count; + for (count = 0; count < this.inputCount; count++) + { + this.nPower[count] = (uint)(1 << (this.inputCount - 1 - count)); + } + + uint[] nPower = [0, 1]; + count = 0; + int nFlag = 1; + for (uint j = 1; j < this.nodeCount; j++) + { + if (j == nPower[1]) + { + factors[j] = this.dimSize[count]; + nPower[0] = (uint)(1 << count); + count++; + nPower[1] = (uint)(1 << count); + nFlag = 1; + } + else + { + factors[j] = factors[nPower[0]] + factors[nFlag]; + nFlag++; + } + } + + break; + } + + return factors; + } + + /// + /// One dimensional interpolation function. + /// + /// The input pixel values, which will be interpolated. + /// The interpolated output pixels. + private unsafe void Interpolate1d(float* srcPixel, float* destPixel) + { + byte mx = this.maxGridPoint[0]; + + float x = UnitClip(srcPixel[0]) * mx; + + uint ix = (uint)x; + + float u = x - ix; + + if (ix == mx) + { + ix--; + u = 1.0f; + } + + float nu = (float)(1.0 - u); + + int i; + Span p = this.lut.AsSpan((int)(ix * this.n001)); + + // Normalize grid units. + float dF0 = nu; + float dF1 = u; + + int offset = 0; + for (i = 0; i < this.outputCount; i++) + { + destPixel[i] = (float)((p[offset + this.n000] * dF0) + (p[offset + this.n001] * dF1)); + offset++; + } + } + + /// + /// Two dimensional interpolation function. + /// + /// The input pixel values, which will be interpolated. + /// The interpolated output pixels. + private unsafe void Interpolate2d(float* srcPixel, float* destPixel) + { + byte mx = this.maxGridPoint[0]; + byte my = this.maxGridPoint[1]; + + float x = UnitClip(srcPixel[0]) * mx; + float y = UnitClip(srcPixel[1]) * my; + + uint ix = (uint)x; + uint iy = (uint)y; + + float u = x - ix; + float t = y - iy; + + if (ix == mx) + { + ix--; + u = 1.0f; + } + + if (iy == my) + { + iy--; + t = 1.0f; + } + + float nt = (float)(1.0 - t); + float nu = (float)(1.0 - u); + + int i; + Span p = this.lut.AsSpan((int)((ix * this.n001) + (iy * this.n010))); + + // Normalize grid units. + float dF0 = nt * nu; + float dF1 = nt * u; + float dF2 = t * nu; + float dF3 = t * u; + + int offset = 0; + for (i = 0; i < this.outputCount; i++) + { + destPixel[i] = (float)((p[offset + this.n000] * dF0) + (p[offset + this.n001] * dF1) + (p[offset + this.n010] * dF2) + (p[offset + this.n011] * dF3)); + offset++; + } + } + + /// + /// Three dimensional interpolation function. + /// + /// The input pixel values, which will be interpolated. + /// The interpolated output pixels. + private unsafe void Interpolate3d(float* srcPixel, float* destPixel) + { + byte mx = this.maxGridPoint[0]; + byte my = this.maxGridPoint[1]; + byte mz = this.maxGridPoint[2]; + + float x = UnitClip(srcPixel[0]) * mx; + float y = UnitClip(srcPixel[1]) * my; + float z = UnitClip(srcPixel[2]) * mz; + + uint ix = (uint)x; + uint iy = (uint)y; + uint iz = (uint)z; + + float u = x - ix; + float t = y - iy; + float s = z - iz; + + if (ix == mx) + { + ix--; + u = 1.0f; + } + + if (iy == my) + { + iy--; + t = 1.0f; + } + + if (iz == mz) + { + iz--; + s = 1.0f; + } + + float ns = (float)(1.0 - s); + float nt = (float)(1.0 - t); + float nu = (float)(1.0 - u); + + Span p = this.lut.AsSpan((int)((ix * this.n001) + (iy * this.n010) + (iz * this.n100))); + + // Normalize grid units + float dF0 = ns * nt * nu; + float dF1 = ns * nt * u; + float dF2 = ns * t * nu; + float dF3 = ns * t * u; + float dF4 = s * nt * nu; + float dF5 = s * nt * u; + float dF6 = s * t * nu; + float dF7 = s * t * u; + + int offset = 0; + for (int i = 0; i < this.outputCount; i++) + { + destPixel[i] = (float)((p[offset + this.n000] * dF0) + + (p[offset + this.n001] * dF1) + + (p[offset + this.n010] * dF2) + + (p[offset + this.n011] * dF3) + + (p[offset + this.n100] * dF4) + + (p[offset + this.n101] * dF5) + + (p[offset + this.n110] * dF6) + + (p[offset + this.n111] * dF7)); + offset++; + } + } + + /// + /// Four dimensional interpolation function. + /// + /// The input pixel values, which will be interpolated. + /// The interpolated output pixels. + private unsafe void Interpolate4d(float* srcPixel, float* destPixel) + { + byte mw = this.maxGridPoint[0]; + byte mx = this.maxGridPoint[1]; + byte my = this.maxGridPoint[2]; + byte mz = this.maxGridPoint[3]; + + float w = UnitClip(srcPixel[0]) * mw; + float x = UnitClip(srcPixel[1]) * mx; + float y = UnitClip(srcPixel[2]) * my; + float z = UnitClip(srcPixel[3]) * mz; + + uint iw = (uint)w; + uint ix = (uint)x; + uint iy = (uint)y; + uint iz = (uint)z; + + float v = w - iw; + float u = x - ix; + float t = y - iy; + float s = z - iz; + + if (iw == mw) + { + iw--; + v = 1.0f; + } + + if (ix == mx) + { + ix--; + u = 1.0f; + } + + if (iy == my) + { + iy--; + t = 1.0f; + } + + if (iz == mz) + { + iz--; + s = 1.0f; + } + + float ns = (float)(1.0 - s); + float nt = (float)(1.0 - t); + float nu = (float)(1.0 - u); + float nv = (float)(1.0 - v); + + Span p = this.lut.AsSpan((int)((iw * this.n001) + (ix * this.n010) + (iy * this.n100) + (iz * this.n1000))); + + // Normalize grid units. + float[] dF = + [ + ns * nt * nu * nv, + ns * nt * nu * v, + ns * nt * u * nv, + ns * nt * u * v, + ns * t * nu * nv, + ns * t * nu * v, + ns * t * u * nv, + ns * t * u * v, + s * nt * nu * nv, + s * nt * nu * v, + s * nt * u * nv, + s * nt * u * v, + s * t * nu * nv, + s * t * nu * v, + s * t * u * nv, + s * t * u * v, + ]; + + int offset = 0; + for (int i = 0; i < this.outputCount; i++) + { + float pv = 0.0f; + for (int j = 0; j < 16; j++) + { + pv += p[offset + this.indexFactor[j]] * dF[j]; + } + + destPixel[i] = pv; + offset++; + } + } + + /// + /// Generic N-dimensional interpolation function. + /// + /// The input pixel values, which will be interpolated. + /// The interpolated output pixels. + private unsafe void InterpolateNd(float* srcPixel, float* destPixel) + { + int index = 0; + for (int i = 0; i < this.inputCount; i++) + { + this.g[i] = UnitClip(srcPixel[i]) * this.maxGridPoint[i]; + this.ig[i] = (uint)this.g[i]; + this.s[this.inputCount - 1 - i] = this.g[i] - this.ig[i]; + if (this.ig[i] == this.maxGridPoint[i]) + { + this.ig[i]--; + this.s[this.inputCount - 1 - i] = 1.0f; + } + + index += (int)this.ig[i] * this.dimSize[i]; + } + + Span p = this.lut.AsSpan(index); + float[] temp = new float[2]; + bool nFlag = false; + + for (int i = 0; i < this.nodeCount; i++) + { + this.df[i] = 1.0f; + } + + for (int i = 0; i < this.inputCount; i++) + { + temp[0] = 1.0f - this.s[i]; + temp[1] = this.s[i]; + index = (int)this.nPower[i]; + for (int j = 0; j < this.nodeCount; j++) + { + this.df[j] *= temp[nFlag ? 1 : 0]; + if ((j + 1) % index == 0) + { + nFlag = !nFlag; + } + } + + nFlag = false; + } + + int offset = 0; + for (int i = 0; i < this.outputCount; i++) + { + float pv = 0; + for (int j = 0; j < this.nodeCount; j++) + { + pv += p[offset + this.indexFactor[j]] * this.df[j]; + } + + destPixel[i] = pv; + offset++; + } + } + + private static float UnitClip(float v) + { + if (v < 0) + { + return 0; + } + + if (v > 1.0) + { + return 1.0f; + } + + return v; + } +} diff --git a/src/ImageSharp/ColorProfiles/Icc/Calculators/ColorTrcCalculator.cs b/src/ImageSharp/ColorProfiles/Icc/Calculators/ColorTrcCalculator.cs new file mode 100644 index 0000000000..3604642c95 --- /dev/null +++ b/src/ImageSharp/ColorProfiles/Icc/Calculators/ColorTrcCalculator.cs @@ -0,0 +1,65 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Numerics; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; + +namespace SixLabors.ImageSharp.ColorProfiles.Icc.Calculators; + +internal class ColorTrcCalculator : IVector4Calculator +{ + private readonly TrcCalculator curveCalculator; + private readonly Matrix4x4 matrix; + private readonly bool toPcs; + + public ColorTrcCalculator( + IccXyzTagDataEntry redMatrixColumn, + IccXyzTagDataEntry greenMatrixColumn, + IccXyzTagDataEntry blueMatrixColumn, + IccTagDataEntry redTrc, + IccTagDataEntry greenTrc, + IccTagDataEntry blueTrc, + bool toPcs) + { + this.toPcs = toPcs; + this.curveCalculator = new TrcCalculator([redTrc, greenTrc, blueTrc], !toPcs); + + Vector3 mr = redMatrixColumn.Data[0]; + Vector3 mg = greenMatrixColumn.Data[0]; + Vector3 mb = blueMatrixColumn.Data[0]; + this.matrix = new Matrix4x4(mr.X, mr.Y, mr.Z, 0, mg.X, mg.Y, mg.Z, 0, mb.X, mb.Y, mb.Z, 0, 0, 0, 0, 1); + + if (!toPcs) + { + Matrix4x4.Invert(this.matrix, out this.matrix); + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Vector4 Calculate(Vector4 value) + { + if (this.toPcs) + { + // input is always linear RGB + value = this.curveCalculator.Calculate(value); + CieXyz xyz = new(Vector4.Transform(value, this.matrix).AsVector3()); + + // when data to PCS, output from calculator is descaled XYZ + // but downstream process requires scaled XYZ + // (see DemoMaxICC IccCmm.cpp : CIccXformMatrixTRC::Apply) + return xyz.ToScaledVector4(); + } + else + { + // input is always XYZ + Vector4 xyz = Vector4.Transform(value, this.matrix); + + // when data to PCS, upstream process provides scaled XYZ + // but input to calculator is descaled XYZ + // (see DemoMaxICC IccCmm.cpp : CIccXformMatrixTRC::Apply) + xyz = new(CieXyz.FromScaledVector4(xyz).AsVector3Unsafe(), 1); + return this.curveCalculator.Calculate(xyz); + } + } +} diff --git a/src/ImageSharp/ColorProfiles/Icc/Calculators/CurveCalculator.CalculationType.cs b/src/ImageSharp/ColorProfiles/Icc/Calculators/CurveCalculator.CalculationType.cs new file mode 100644 index 0000000000..d035bd1793 --- /dev/null +++ b/src/ImageSharp/ColorProfiles/Icc/Calculators/CurveCalculator.CalculationType.cs @@ -0,0 +1,14 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +namespace SixLabors.ImageSharp.ColorProfiles.Conversion.Icc; + +internal partial class CurveCalculator +{ + private enum CalculationType + { + Identity, + Gamma, + Lut, + } +} diff --git a/src/ImageSharp/ColorProfiles/Icc/Calculators/CurveCalculator.cs b/src/ImageSharp/ColorProfiles/Icc/Calculators/CurveCalculator.cs new file mode 100644 index 0000000000..c39eaf958f --- /dev/null +++ b/src/ImageSharp/ColorProfiles/Icc/Calculators/CurveCalculator.cs @@ -0,0 +1,47 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. +#nullable disable + +using SixLabors.ImageSharp.ColorProfiles.Icc.Calculators; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; + +namespace SixLabors.ImageSharp.ColorProfiles.Conversion.Icc; + +internal partial class CurveCalculator : ISingleCalculator +{ + private readonly LutCalculator lutCalculator; + private readonly float gamma; + private readonly CalculationType type; + + public CurveCalculator(IccCurveTagDataEntry entry, bool inverted) + { + if (entry.IsIdentityResponse) + { + this.type = CalculationType.Identity; + } + else if (entry.IsGamma) + { + this.gamma = entry.Gamma; + if (inverted) + { + this.gamma = 1f / this.gamma; + } + + this.type = CalculationType.Gamma; + } + else + { + this.lutCalculator = new LutCalculator(entry.CurveData, inverted); + this.type = CalculationType.Lut; + } + } + + public float Calculate(float value) + => this.type switch + { + CalculationType.Identity => value, + CalculationType.Gamma => MathF.Pow(value, this.gamma), // TODO: This could be optimized using a LUT. See SrgbCompanding + CalculationType.Lut => this.lutCalculator.Calculate(value), + _ => throw new InvalidOperationException("Invalid calculation type"), + }; +} diff --git a/src/ImageSharp/ColorProfiles/Icc/Calculators/GrayTrcCalculator.cs b/src/ImageSharp/ColorProfiles/Icc/Calculators/GrayTrcCalculator.cs new file mode 100644 index 0000000000..8d823c1e95 --- /dev/null +++ b/src/ImageSharp/ColorProfiles/Icc/Calculators/GrayTrcCalculator.cs @@ -0,0 +1,19 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Numerics; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; + +namespace SixLabors.ImageSharp.ColorProfiles.Icc.Calculators; + +internal class GrayTrcCalculator : IVector4Calculator +{ + private readonly TrcCalculator calculator; + + public GrayTrcCalculator(IccTagDataEntry grayTrc, bool toPcs) + => this.calculator = new TrcCalculator(new IccTagDataEntry[] { grayTrc }, !toPcs); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Vector4 Calculate(Vector4 value) => this.calculator.Calculate(value); +} diff --git a/src/ImageSharp/ColorProfiles/Icc/Calculators/ISingleCalculator.cs b/src/ImageSharp/ColorProfiles/Icc/Calculators/ISingleCalculator.cs new file mode 100644 index 0000000000..ce9b7d2f9b --- /dev/null +++ b/src/ImageSharp/ColorProfiles/Icc/Calculators/ISingleCalculator.cs @@ -0,0 +1,17 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +namespace SixLabors.ImageSharp.ColorProfiles.Icc.Calculators; + +/// +/// Represents an ICC calculator with a single floating point value and result +/// +internal interface ISingleCalculator +{ + /// + /// Calculates a result from the given value + /// + /// The input value + /// The calculated result + float Calculate(float value); +} diff --git a/src/ImageSharp/ColorProfiles/Icc/Calculators/IVector4Calculator.cs b/src/ImageSharp/ColorProfiles/Icc/Calculators/IVector4Calculator.cs new file mode 100644 index 0000000000..9beea79503 --- /dev/null +++ b/src/ImageSharp/ColorProfiles/Icc/Calculators/IVector4Calculator.cs @@ -0,0 +1,19 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Numerics; + +namespace SixLabors.ImageSharp.ColorProfiles.Icc.Calculators; + +/// +/// Represents an ICC calculator with values and results +/// +internal interface IVector4Calculator +{ + /// + /// Calculates a result from the given values + /// + /// The input values + /// The calculated result + Vector4 Calculate(Vector4 value); +} diff --git a/src/ImageSharp/ColorProfiles/Icc/Calculators/LutABCalculator.CalculationType.cs b/src/ImageSharp/ColorProfiles/Icc/Calculators/LutABCalculator.CalculationType.cs new file mode 100644 index 0000000000..253239cb79 --- /dev/null +++ b/src/ImageSharp/ColorProfiles/Icc/Calculators/LutABCalculator.CalculationType.cs @@ -0,0 +1,18 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +namespace SixLabors.ImageSharp.ColorProfiles.Conversion.Icc; + +internal partial class LutABCalculator +{ + private enum CalculationType + { + AtoB = 1 << 3, + BtoA = 1 << 4, + + SingleCurve = 1, + CurveMatrix = 2, + CurveClut = 3, + Full = 4, + } +} diff --git a/src/ImageSharp/ColorProfiles/Icc/Calculators/LutABCalculator.cs b/src/ImageSharp/ColorProfiles/Icc/Calculators/LutABCalculator.cs new file mode 100644 index 0000000000..172d806394 --- /dev/null +++ b/src/ImageSharp/ColorProfiles/Icc/Calculators/LutABCalculator.cs @@ -0,0 +1,135 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. +#nullable disable + +using System.Numerics; +using SixLabors.ImageSharp.ColorProfiles.Icc.Calculators; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; + +namespace SixLabors.ImageSharp.ColorProfiles.Conversion.Icc; + +internal partial class LutABCalculator : IVector4Calculator +{ + private CalculationType type; + private TrcCalculator curveACalculator; + private TrcCalculator curveBCalculator; + private TrcCalculator curveMCalculator; + private MatrixCalculator matrixCalculator; + private ClutCalculator clutCalculator; + + public LutABCalculator(IccLutAToBTagDataEntry entry) + { + Guard.NotNull(entry, nameof(entry)); + this.Init(entry.CurveA, entry.CurveB, entry.CurveM, entry.Matrix3x1, entry.Matrix3x3, entry.ClutValues); + this.type |= CalculationType.AtoB; + } + + public LutABCalculator(IccLutBToATagDataEntry entry) + { + Guard.NotNull(entry, nameof(entry)); + this.Init(entry.CurveA, entry.CurveB, entry.CurveM, entry.Matrix3x1, entry.Matrix3x3, entry.ClutValues); + this.type |= CalculationType.BtoA; + } + + public Vector4 Calculate(Vector4 value) + { + switch (this.type) + { + case CalculationType.Full | CalculationType.AtoB: + value = this.curveACalculator.Calculate(value); + value = this.clutCalculator.Calculate(value); + value = this.curveMCalculator.Calculate(value); + value = this.matrixCalculator.Calculate(value); + return this.curveBCalculator.Calculate(value); + + case CalculationType.Full | CalculationType.BtoA: + value = this.curveBCalculator.Calculate(value); + value = this.matrixCalculator.Calculate(value); + value = this.curveMCalculator.Calculate(value); + value = this.clutCalculator.Calculate(value); + return this.curveACalculator.Calculate(value); + + case CalculationType.CurveClut | CalculationType.AtoB: + value = this.curveACalculator.Calculate(value); + value = this.clutCalculator.Calculate(value); + return this.curveBCalculator.Calculate(value); + + case CalculationType.CurveClut | CalculationType.BtoA: + value = this.curveBCalculator.Calculate(value); + value = this.clutCalculator.Calculate(value); + return this.curveACalculator.Calculate(value); + + case CalculationType.CurveMatrix | CalculationType.AtoB: + value = this.curveMCalculator.Calculate(value); + value = this.matrixCalculator.Calculate(value); + return this.curveBCalculator.Calculate(value); + + case CalculationType.CurveMatrix | CalculationType.BtoA: + value = this.curveBCalculator.Calculate(value); + value = this.matrixCalculator.Calculate(value); + return this.curveMCalculator.Calculate(value); + + case CalculationType.SingleCurve | CalculationType.AtoB: + case CalculationType.SingleCurve | CalculationType.BtoA: + return this.curveBCalculator.Calculate(value); + + default: + throw new InvalidOperationException("Invalid calculation type"); + } + } + + private void Init(IccTagDataEntry[] curveA, IccTagDataEntry[] curveB, IccTagDataEntry[] curveM, Vector3? matrix3x1, Matrix4x4? matrix3x3, IccClut clut) + { + bool hasACurve = curveA != null; + bool hasBCurve = curveB != null; + bool hasMCurve = curveM != null; + bool hasMatrix = matrix3x1 != null && matrix3x3 != null; + bool hasClut = clut != null; + + if (hasBCurve && hasMatrix && hasMCurve && hasClut && hasACurve) + { + this.type = CalculationType.Full; + } + else if (hasBCurve && hasClut && hasACurve) + { + this.type = CalculationType.CurveClut; + } + else if (hasBCurve && hasMatrix && hasMCurve) + { + this.type = CalculationType.CurveMatrix; + } + else if (hasBCurve) + { + this.type = CalculationType.SingleCurve; + } + else + { + throw new InvalidIccProfileException("AToB or BToA tag has an invalid configuration"); + } + + if (hasACurve) + { + this.curveACalculator = new TrcCalculator(curveA, false); + } + + if (hasBCurve) + { + this.curveBCalculator = new TrcCalculator(curveB, false); + } + + if (hasMCurve) + { + this.curveMCalculator = new TrcCalculator(curveM, false); + } + + if (hasMatrix) + { + this.matrixCalculator = new MatrixCalculator(matrix3x3.Value, matrix3x1.Value); + } + + if (hasClut) + { + this.clutCalculator = new ClutCalculator(clut); + } + } +} diff --git a/src/ImageSharp/ColorProfiles/Icc/Calculators/LutCalculator.cs b/src/ImageSharp/ColorProfiles/Icc/Calculators/LutCalculator.cs new file mode 100644 index 0000000000..83704ae214 --- /dev/null +++ b/src/ImageSharp/ColorProfiles/Icc/Calculators/LutCalculator.cs @@ -0,0 +1,77 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Runtime.CompilerServices; + +namespace SixLabors.ImageSharp.ColorProfiles.Icc.Calculators; + +internal class LutCalculator : ISingleCalculator +{ + private readonly float[] lut; + private readonly bool inverse; + + public LutCalculator(float[] lut, bool inverse) + { + Guard.NotNull(lut, nameof(lut)); + + this.lut = lut; + this.inverse = inverse; + } + + public float Calculate(float value) + { + if (this.inverse) + { + return this.LookupInverse(value); + } + + return this.Lookup(value); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private float Lookup(float value) + { + value = Math.Max(value, 0); + + float factor = value * (this.lut.Length - 1); + int index = (int)factor; + float low = this.lut[index]; + + float high = 1F; + if (index < this.lut.Length - 1) + { + high = this.lut[index + 1]; + } + + return low + ((high - low) * (factor - index)); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private float LookupInverse(float value) + { + int index = Array.BinarySearch(this.lut, value); + if (index >= 0) + { + return index / (float)(this.lut.Length - 1); + } + + index = ~index; + if (index == 0) + { + return 0; + } + else if (index == this.lut.Length) + { + return 1; + } + + float high = this.lut[index]; + float low = this.lut[index - 1]; + + float valuePercent = (value - low) / (high - low); + float lutRange = 1 / (float)(this.lut.Length - 1); + float lutLow = (index - 1) / (float)(this.lut.Length - 1); + + return lutLow + (valuePercent * lutRange); + } +} diff --git a/src/ImageSharp/ColorProfiles/Icc/Calculators/LutEntryCalculator.cs b/src/ImageSharp/ColorProfiles/Icc/Calculators/LutEntryCalculator.cs new file mode 100644 index 0000000000..c97578ee3f --- /dev/null +++ b/src/ImageSharp/ColorProfiles/Icc/Calculators/LutEntryCalculator.cs @@ -0,0 +1,80 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. +#nullable disable + +using System.Numerics; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; + +namespace SixLabors.ImageSharp.ColorProfiles.Icc.Calculators; + +internal class LutEntryCalculator : IVector4Calculator +{ + private LutCalculator[] inputCurve; + private LutCalculator[] outputCurve; + private ClutCalculator clutCalculator; + private Matrix4x4 matrix; + private bool doTransform; + + public LutEntryCalculator(IccLut8TagDataEntry lut) + { + Guard.NotNull(lut, nameof(lut)); + this.Init(lut.InputValues, lut.OutputValues, lut.ClutValues, lut.Matrix); + this.Is16Bit = false; + } + + public LutEntryCalculator(IccLut16TagDataEntry lut) + { + Guard.NotNull(lut, nameof(lut)); + this.Init(lut.InputValues, lut.OutputValues, lut.ClutValues, lut.Matrix); + this.Is16Bit = true; + } + + internal bool Is16Bit { get; } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Vector4 Calculate(Vector4 value) + { + if (this.doTransform) + { + value = Vector4.Transform(value, this.matrix); + } + + value = CalculateLut(this.inputCurve, value); + value = this.clutCalculator.Calculate(value); + return CalculateLut(this.outputCurve, value); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static Vector4 CalculateLut(LutCalculator[] lut, Vector4 value) + { + ref float f = ref Unsafe.As(ref value); + for (int i = 0; i < lut.Length; i++) + { + Unsafe.Add(ref f, i) = lut[i].Calculate(Unsafe.Add(ref f, i)); + } + + return value; + } + + private void Init(IccLut[] inputCurve, IccLut[] outputCurve, IccClut clut, Matrix4x4 matrix) + { + this.inputCurve = InitLut(inputCurve); + this.outputCurve = InitLut(outputCurve); + this.clutCalculator = new ClutCalculator(clut); + this.matrix = matrix; + + this.doTransform = !matrix.IsIdentity && inputCurve.Length == 3; + } + + private static LutCalculator[] InitLut(IccLut[] curves) + { + LutCalculator[] calculators = new LutCalculator[curves.Length]; + for (int i = 0; i < curves.Length; i++) + { + calculators[i] = new LutCalculator(curves[i].Values, false); + } + + return calculators; + } +} diff --git a/src/ImageSharp/ColorProfiles/Icc/Calculators/MatrixCalculator.cs b/src/ImageSharp/ColorProfiles/Icc/Calculators/MatrixCalculator.cs new file mode 100644 index 0000000000..6be1fdbf95 --- /dev/null +++ b/src/ImageSharp/ColorProfiles/Icc/Calculators/MatrixCalculator.cs @@ -0,0 +1,26 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Numerics; +using System.Runtime.CompilerServices; + +namespace SixLabors.ImageSharp.ColorProfiles.Icc.Calculators; + +internal class MatrixCalculator : IVector4Calculator +{ + private Matrix4x4 matrix2D; + private Vector4 matrix1D; + + public MatrixCalculator(Matrix4x4 matrix3x3, Vector3 matrix3x1) + { + this.matrix2D = matrix3x3; + this.matrix1D = new Vector4(matrix3x1, 0); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Vector4 Calculate(Vector4 value) + { + Vector4 transformed = Vector4.Transform(value, this.matrix2D); + return Vector4.Add(this.matrix1D, transformed); + } +} diff --git a/src/ImageSharp/ColorProfiles/Icc/Calculators/ParametricCurveCalculator.cs b/src/ImageSharp/ColorProfiles/Icc/Calculators/ParametricCurveCalculator.cs new file mode 100644 index 0000000000..2a3945e270 --- /dev/null +++ b/src/ImageSharp/ColorProfiles/Icc/Calculators/ParametricCurveCalculator.cs @@ -0,0 +1,130 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; + +namespace SixLabors.ImageSharp.ColorProfiles.Icc.Calculators; + +internal class ParametricCurveCalculator : ISingleCalculator +{ + private readonly IccParametricCurve curve; + private readonly IccParametricCurveType type; + private const IccParametricCurveType InvertedFlag = (IccParametricCurveType)(1 << 3); + + public ParametricCurveCalculator(IccParametricCurveTagDataEntry entry, bool inverted) + { + Guard.NotNull(entry, nameof(entry)); + this.curve = entry.Curve; + this.type = entry.Curve.Type; + + if (inverted) + { + this.type |= InvertedFlag; + } + } + + public float Calculate(float value) + => this.type switch + { + IccParametricCurveType.Type1 => this.CalculateGamma(value), + IccParametricCurveType.Cie122_1996 => this.CalculateCie122(value), + IccParametricCurveType.Iec61966_3 => this.CalculateIec61966(value), + IccParametricCurveType.SRgb => this.CalculateSRgb(value), + IccParametricCurveType.Type5 => this.CalculateType5(value), + IccParametricCurveType.Type1 | InvertedFlag => this.CalculateInvertedGamma(value), + IccParametricCurveType.Cie122_1996 | InvertedFlag => this.CalculateInvertedCie122(value), + IccParametricCurveType.Iec61966_3 | InvertedFlag => this.CalculateInvertedIec61966(value), + IccParametricCurveType.SRgb | InvertedFlag => this.CalculateInvertedSRgb(value), + IccParametricCurveType.Type5 | InvertedFlag => this.CalculateInvertedType5(value), + _ => throw new InvalidIccProfileException("ParametricCurve"), + }; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private float CalculateGamma(float value) => MathF.Pow(value, this.curve.G); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private float CalculateCie122(float value) + { + if (value >= -this.curve.B / this.curve.A) + { + return MathF.Pow((this.curve.A * value) + this.curve.B, this.curve.G); + } + + return 0; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private float CalculateIec61966(float value) + { + if (value >= -this.curve.B / this.curve.A) + { + return MathF.Pow((this.curve.A * value) + this.curve.B, this.curve.G) + this.curve.C; + } + + return this.curve.C; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private float CalculateSRgb(float value) + { + if (value >= this.curve.D) + { + return MathF.Pow((this.curve.A * value) + this.curve.B, this.curve.G); + } + + return this.curve.C * value; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private float CalculateType5(float value) + { + if (value >= this.curve.D) + { + return MathF.Pow((this.curve.A * value) + this.curve.B, this.curve.G) + this.curve.E; + } + + return (this.curve.C * value) + this.curve.F; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private float CalculateInvertedGamma(float value) + => MathF.Pow(value, 1 / this.curve.G); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private float CalculateInvertedCie122(float value) + => (MathF.Pow(value, 1 / this.curve.G) - this.curve.B) / this.curve.A; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private float CalculateInvertedIec61966(float value) + { + if (value >= this.curve.C) + { + return (MathF.Pow(value - this.curve.C, 1 / this.curve.G) - this.curve.B) / this.curve.A; + } + + return -this.curve.B / this.curve.A; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private float CalculateInvertedSRgb(float value) + { + if (value >= MathF.Pow((this.curve.A * this.curve.D) + this.curve.B, this.curve.G)) + { + return (MathF.Pow(value, 1 / this.curve.G) - this.curve.B) / this.curve.A; + } + + return value / this.curve.C; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private float CalculateInvertedType5(float value) + { + if (value >= (this.curve.C * this.curve.D) + this.curve.F) + { + return (MathF.Pow(value - this.curve.E, 1 / this.curve.G) - this.curve.B) / this.curve.A; + } + + return (value - this.curve.F) / this.curve.C; + } +} diff --git a/src/ImageSharp/ColorProfiles/Icc/Calculators/TrcCalculator.cs b/src/ImageSharp/ColorProfiles/Icc/Calculators/TrcCalculator.cs new file mode 100644 index 0000000000..d2fc5d9b55 --- /dev/null +++ b/src/ImageSharp/ColorProfiles/Icc/Calculators/TrcCalculator.cs @@ -0,0 +1,41 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Numerics; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.ColorProfiles.Conversion.Icc; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; + +namespace SixLabors.ImageSharp.ColorProfiles.Icc.Calculators; + +internal class TrcCalculator : IVector4Calculator +{ + private readonly ISingleCalculator[] calculators; + + public TrcCalculator(IccTagDataEntry[] entries, bool inverted) + { + Guard.NotNull(entries, nameof(entries)); + + this.calculators = new ISingleCalculator[entries.Length]; + for (int i = 0; i < entries.Length; i++) + { + this.calculators[i] = entries[i] switch + { + IccCurveTagDataEntry curve => new CurveCalculator(curve, inverted), + IccParametricCurveTagDataEntry parametricCurve => new ParametricCurveCalculator(parametricCurve, inverted), + _ => throw new InvalidIccProfileException("Invalid Entry."), + }; + } + } + + public unsafe Vector4 Calculate(Vector4 value) + { + ref float f = ref Unsafe.As(ref value); + for (int i = 0; i < this.calculators.Length; i++) + { + Unsafe.Add(ref f, i) = this.calculators[i].Calculate(Unsafe.Add(ref f, i)); + } + + return value; + } +} diff --git a/src/ImageSharp/ColorProfiles/Icc/IccConverterBase.Checks.cs b/src/ImageSharp/ColorProfiles/Icc/IccConverterBase.Checks.cs new file mode 100644 index 0000000000..94f906709a --- /dev/null +++ b/src/ImageSharp/ColorProfiles/Icc/IccConverterBase.Checks.cs @@ -0,0 +1,155 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. +#nullable disable + +using SixLabors.ImageSharp.Metadata.Profiles.Icc; + +namespace SixLabors.ImageSharp.ColorProfiles.Conversion.Icc; + +/// +/// Color converter for ICC profiles +/// +internal abstract partial class IccConverterBase +{ + private static ConversionMethod GetConversionMethod(IccProfile profile, IccRenderingIntent renderingIntent) => profile.Header.Class switch + { + IccProfileClass.InputDevice or + IccProfileClass.DisplayDevice or + IccProfileClass.OutputDevice or + IccProfileClass.ColorSpace => CheckMethod1(profile, renderingIntent), + IccProfileClass.DeviceLink or IccProfileClass.Abstract => CheckMethod2(profile), + _ => ConversionMethod.Invalid, + }; + + private static ConversionMethod CheckMethod1(IccProfile profile, IccRenderingIntent renderingIntent) + { + ConversionMethod method = CheckMethodD(profile, renderingIntent); + if (method != ConversionMethod.Invalid) + { + return method; + } + + method = CheckMethodA(profile, renderingIntent); + if (method != ConversionMethod.Invalid) + { + return method; + } + + method = CheckMethodA0(profile); + if (method != ConversionMethod.Invalid) + { + return method; + } + + method = CheckMethodTrc(profile); + if (method != ConversionMethod.Invalid) + { + return method; + } + + return ConversionMethod.Invalid; + } + + private static ConversionMethod CheckMethodD(IccProfile profile, IccRenderingIntent renderingIntent) + { + if ((HasTag(profile, IccProfileTag.DToB0) || HasTag(profile, IccProfileTag.BToD0)) + && renderingIntent == IccRenderingIntent.Perceptual) + { + return ConversionMethod.D0; + } + + if ((HasTag(profile, IccProfileTag.DToB1) || HasTag(profile, IccProfileTag.BToD1)) + && renderingIntent == IccRenderingIntent.MediaRelativeColorimetric) + { + return ConversionMethod.D1; + } + + if ((HasTag(profile, IccProfileTag.DToB2) || HasTag(profile, IccProfileTag.BToD2)) + && renderingIntent == IccRenderingIntent.Saturation) + { + return ConversionMethod.D2; + } + + if ((HasTag(profile, IccProfileTag.DToB3) || HasTag(profile, IccProfileTag.BToD3)) + && renderingIntent == IccRenderingIntent.AbsoluteColorimetric) + { + return ConversionMethod.D3; + } + + return ConversionMethod.Invalid; + } + + private static ConversionMethod CheckMethodA(IccProfile profile, IccRenderingIntent renderingIntent) + { + if ((HasTag(profile, IccProfileTag.AToB0) || HasTag(profile, IccProfileTag.BToA0)) + && renderingIntent == IccRenderingIntent.Perceptual) + { + return ConversionMethod.A0; + } + + if ((HasTag(profile, IccProfileTag.AToB1) || HasTag(profile, IccProfileTag.BToA1)) + && renderingIntent == IccRenderingIntent.MediaRelativeColorimetric) + { + return ConversionMethod.A1; + } + + if ((HasTag(profile, IccProfileTag.AToB2) || HasTag(profile, IccProfileTag.BToA2)) + && renderingIntent == IccRenderingIntent.Saturation) + { + return ConversionMethod.A2; + } + + return ConversionMethod.Invalid; + } + + private static ConversionMethod CheckMethodA0(IccProfile profile) + { + bool valid = HasTag(profile, IccProfileTag.AToB0) || HasTag(profile, IccProfileTag.BToA0); + return valid ? ConversionMethod.A0 : ConversionMethod.Invalid; + } + + private static ConversionMethod CheckMethodTrc(IccProfile profile) + { + if (HasTag(profile, IccProfileTag.RedMatrixColumn) + && HasTag(profile, IccProfileTag.GreenMatrixColumn) + && HasTag(profile, IccProfileTag.BlueMatrixColumn) + && HasTag(profile, IccProfileTag.RedTrc) + && HasTag(profile, IccProfileTag.GreenTrc) + && HasTag(profile, IccProfileTag.BlueTrc)) + { + return ConversionMethod.ColorTrc; + } + + if (HasTag(profile, IccProfileTag.GrayTrc)) + { + return ConversionMethod.GrayTrc; + } + + return ConversionMethod.Invalid; + } + + private static ConversionMethod CheckMethod2(IccProfile profile) + { + if (HasTag(profile, IccProfileTag.DToB0) || HasTag(profile, IccProfileTag.BToD0)) + { + return ConversionMethod.D0; + } + + if (HasTag(profile, IccProfileTag.AToB0) || HasTag(profile, IccProfileTag.AToB0)) + { + return ConversionMethod.A0; + } + + return ConversionMethod.Invalid; + } + + private static bool HasTag(IccProfile profile, IccProfileTag tag) + => profile.Entries.Any(t => t.TagSignature == tag); + + private static IccTagDataEntry GetTag(IccProfile profile, IccProfileTag tag) + => Array.Find(profile.Entries, t => t.TagSignature == tag); + + private static T GetTag(IccProfile profile, IccProfileTag tag) + where T : IccTagDataEntry + => profile.Entries.OfType().FirstOrDefault(t => t.TagSignature == tag); +} diff --git a/src/ImageSharp/ColorProfiles/Icc/IccConverterBase.ConversionMethod.cs b/src/ImageSharp/ColorProfiles/Icc/IccConverterBase.ConversionMethod.cs new file mode 100644 index 0000000000..43593f0ae9 --- /dev/null +++ b/src/ImageSharp/ColorProfiles/Icc/IccConverterBase.ConversionMethod.cs @@ -0,0 +1,66 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +namespace SixLabors.ImageSharp.ColorProfiles.Conversion.Icc; + +/// +/// Color converter for ICC profiles +/// +internal abstract partial class IccConverterBase +{ + /// + /// Conversion methods with ICC profiles + /// + private enum ConversionMethod + { + /// + /// Conversion using anything but Multi Process Elements with perceptual rendering intent + /// + A0, + + /// + /// Conversion using anything but Multi Process Elements with relative colorimetric rendering intent + /// + A1, + + /// + /// Conversion using anything but Multi Process Elements with saturation rendering intent + /// + A2, + + /// + /// Conversion using Multi Process Elements with perceptual rendering intent + /// + D0, + + /// + /// Conversion using Multi Process Elements with relative colorimetric rendering intent + /// + D1, + + /// + /// Conversion using Multi Process Elements with saturation rendering intent + /// + D2, + + /// + /// Conversion using Multi Process Elements with absolute colorimetric rendering intent + /// + D3, + + /// + /// Conversion of more than one channel using tone reproduction curves + /// + ColorTrc, + + /// + /// Conversion of exactly one channel using a tone reproduction curve + /// + GrayTrc, + + /// + /// No valid conversion method available or found + /// + Invalid, + } +} diff --git a/src/ImageSharp/ColorProfiles/Icc/IccConverterbase.Conversions.cs b/src/ImageSharp/ColorProfiles/Icc/IccConverterbase.Conversions.cs new file mode 100644 index 0000000000..20df08e378 --- /dev/null +++ b/src/ImageSharp/ColorProfiles/Icc/IccConverterbase.Conversions.cs @@ -0,0 +1,109 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using SixLabors.ImageSharp.ColorProfiles.Icc.Calculators; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; + +namespace SixLabors.ImageSharp.ColorProfiles.Conversion.Icc; + +/// +/// Color converter for ICC profiles +/// +internal abstract partial class IccConverterBase +{ + private IVector4Calculator calculator; + + internal bool Is16BitLutEntry => this.calculator is LutEntryCalculator { Is16Bit: true }; + + internal bool IsTrc => this.calculator is ColorTrcCalculator or GrayTrcCalculator; + + /// + /// Checks the profile for available conversion methods and gathers all the information's necessary for it. + /// + /// The profile to use for the conversion. + /// True if the conversion is to the Profile Connection Space. + /// The wanted rendering intent. Can be ignored if not available. + /// Invalid conversion method. + protected void Init(IccProfile profile, bool toPcs, IccRenderingIntent renderingIntent) + => this.calculator = GetConversionMethod(profile, renderingIntent) switch + { + ConversionMethod.D0 => toPcs ? + InitD(profile, IccProfileTag.DToB0) : + InitD(profile, IccProfileTag.BToD0), + ConversionMethod.D1 => toPcs ? + InitD(profile, IccProfileTag.DToB1) : + InitD(profile, IccProfileTag.BToD1), + ConversionMethod.D2 => toPcs ? + InitD(profile, IccProfileTag.DToB2) : + InitD(profile, IccProfileTag.BToD2), + ConversionMethod.D3 => toPcs ? + InitD(profile, IccProfileTag.DToB3) : + InitD(profile, IccProfileTag.BToD3), + ConversionMethod.A0 => toPcs ? + InitA(profile, IccProfileTag.AToB0) : + InitA(profile, IccProfileTag.BToA0), + ConversionMethod.A1 => toPcs ? + InitA(profile, IccProfileTag.AToB1) : + InitA(profile, IccProfileTag.BToA1), + ConversionMethod.A2 => toPcs ? + InitA(profile, IccProfileTag.AToB2) : + InitA(profile, IccProfileTag.BToA2), + ConversionMethod.ColorTrc => InitColorTrc(profile, toPcs), + ConversionMethod.GrayTrc => InitGrayTrc(profile, toPcs), + _ => throw new InvalidIccProfileException("Invalid conversion method."), + }; + + private static IVector4Calculator InitA(IccProfile profile, IccProfileTag tag) + => GetTag(profile, tag) switch + { + IccLut8TagDataEntry lut8 => new LutEntryCalculator(lut8), + IccLut16TagDataEntry lut16 => new LutEntryCalculator(lut16), + IccLutAToBTagDataEntry lutAtoB => new LutABCalculator(lutAtoB), + IccLutBToATagDataEntry lutBtoA => new LutABCalculator(lutBtoA), + _ => throw new InvalidIccProfileException("Invalid entry."), + }; + + private static IVector4Calculator InitD(IccProfile profile, IccProfileTag tag) + { + IccMultiProcessElementsTagDataEntry entry = GetTag(profile, tag) + ?? throw new InvalidIccProfileException("Entry is null."); + + throw new NotImplementedException("Multi process elements are not supported"); + } + + private static ColorTrcCalculator InitColorTrc(IccProfile profile, bool toPcs) + { + IccXyzTagDataEntry redMatrixColumn = GetTag(profile, IccProfileTag.RedMatrixColumn); + IccXyzTagDataEntry greenMatrixColumn = GetTag(profile, IccProfileTag.GreenMatrixColumn); + IccXyzTagDataEntry blueMatrixColumn = GetTag(profile, IccProfileTag.BlueMatrixColumn); + + IccTagDataEntry redTrc = GetTag(profile, IccProfileTag.RedTrc); + IccTagDataEntry greenTrc = GetTag(profile, IccProfileTag.GreenTrc); + IccTagDataEntry blueTrc = GetTag(profile, IccProfileTag.BlueTrc); + + if (redMatrixColumn == null || + greenMatrixColumn == null || + blueMatrixColumn == null || + redTrc == null || + greenTrc == null || + blueTrc == null) + { + throw new InvalidIccProfileException("Missing matrix column or channel."); + } + + return new ColorTrcCalculator( + redMatrixColumn, + greenMatrixColumn, + blueMatrixColumn, + redTrc, + greenTrc, + blueTrc, + toPcs); + } + + private static GrayTrcCalculator InitGrayTrc(IccProfile profile, bool toPcs) + { + IccTagDataEntry entry = GetTag(profile, IccProfileTag.GrayTrc); + return new GrayTrcCalculator(entry, toPcs); + } +} diff --git a/src/ImageSharp/ColorProfiles/Icc/IccConverterbase.cs b/src/ImageSharp/ColorProfiles/Icc/IccConverterbase.cs new file mode 100644 index 0000000000..d9976dc2ac --- /dev/null +++ b/src/ImageSharp/ColorProfiles/Icc/IccConverterbase.cs @@ -0,0 +1,49 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. +#nullable disable + +using System.Numerics; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; + +namespace SixLabors.ImageSharp.ColorProfiles.Conversion.Icc; + +/// +/// Color converter for ICC profiles +/// +internal abstract partial class IccConverterBase +{ + /// + /// Initializes a new instance of the class. + /// + /// The ICC profile to use for the conversions + /// True if the conversion is to the profile connection space (PCS); False if the conversion is to the data space + protected IccConverterBase(IccProfile profile, bool toPcs) + { + Guard.NotNull(profile, nameof(profile)); + this.Init(profile, toPcs, profile.Header.RenderingIntent); + } + + /// + /// Converts colors with the initially provided ICC profile + /// + /// The value to convert + /// The converted value + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Vector4 Calculate(Vector4 value) => this.calculator.Calculate(value); + + /// + /// Converts colors with the initially provided ICC profile + /// + /// The source colors + /// The destination colors + public void Calculate(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + for (int i = 0; i < source.Length; i++) + { + destination[i] = this.Calculate(source[i]); + } + } +} diff --git a/src/ImageSharp/ColorProfiles/Icc/IccDataToDataConverter.cs b/src/ImageSharp/ColorProfiles/Icc/IccDataToDataConverter.cs new file mode 100644 index 0000000000..cb4d89bb53 --- /dev/null +++ b/src/ImageSharp/ColorProfiles/Icc/IccDataToDataConverter.cs @@ -0,0 +1,22 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using SixLabors.ImageSharp.ColorProfiles.Conversion.Icc; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; + +namespace SixLabors.ImageSharp.ColorProfiles.Icc; + +/// +/// Color converter for ICC profiles +/// +internal class IccDataToDataConverter : IccConverterBase +{ + /// + /// Initializes a new instance of the class. + /// + /// The ICC profile to use for the conversions + public IccDataToDataConverter(IccProfile profile) + : base(profile, true) // toPCS is true because in this case the PCS space is also a data space + { + } +} diff --git a/src/ImageSharp/ColorProfiles/Icc/IccDataToPcsConverter.cs b/src/ImageSharp/ColorProfiles/Icc/IccDataToPcsConverter.cs new file mode 100644 index 0000000000..6e95d3cb32 --- /dev/null +++ b/src/ImageSharp/ColorProfiles/Icc/IccDataToPcsConverter.cs @@ -0,0 +1,22 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using SixLabors.ImageSharp.ColorProfiles.Conversion.Icc; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; + +namespace SixLabors.ImageSharp.ColorProfiles.Icc; + +/// +/// Color converter for ICC profiles +/// +internal class IccDataToPcsConverter : IccConverterBase +{ + /// + /// Initializes a new instance of the class. + /// + /// The ICC profile to use for the conversions + public IccDataToPcsConverter(IccProfile profile) + : base(profile, true) + { + } +} diff --git a/src/ImageSharp/ColorProfiles/Icc/IccPcsToDataConverter.cs b/src/ImageSharp/ColorProfiles/Icc/IccPcsToDataConverter.cs new file mode 100644 index 0000000000..d29517fca2 --- /dev/null +++ b/src/ImageSharp/ColorProfiles/Icc/IccPcsToDataConverter.cs @@ -0,0 +1,22 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using SixLabors.ImageSharp.ColorProfiles.Conversion.Icc; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; + +namespace SixLabors.ImageSharp.ColorProfiles.Icc; + +/// +/// Color converter for ICC profiles +/// +internal class IccPcsToDataConverter : IccConverterBase +{ + /// + /// Initializes a new instance of the class. + /// + /// The ICC profile to use for the conversions + public IccPcsToDataConverter(IccProfile profile) + : base(profile, false) + { + } +} diff --git a/src/ImageSharp/ColorProfiles/Icc/IccPcsToPcsConverter.cs b/src/ImageSharp/ColorProfiles/Icc/IccPcsToPcsConverter.cs new file mode 100644 index 0000000000..30b44ca75c --- /dev/null +++ b/src/ImageSharp/ColorProfiles/Icc/IccPcsToPcsConverter.cs @@ -0,0 +1,22 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using SixLabors.ImageSharp.ColorProfiles.Conversion.Icc; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; + +namespace SixLabors.ImageSharp.ColorProfiles.Icc; + +/// +/// Color converter for ICC profiles +/// +internal class IccPcsToPcsConverter : IccConverterBase +{ + /// + /// Initializes a new instance of the class. + /// + /// The ICC profile to use for the conversions + public IccPcsToPcsConverter(IccProfile profile) + : base(profile, true) + { + } +} diff --git a/src/ImageSharp/ColorProfiles/Icc/SrgbV4Profile.Generated.cs b/src/ImageSharp/ColorProfiles/Icc/SrgbV4Profile.Generated.cs new file mode 100644 index 0000000000..a4d673488e --- /dev/null +++ b/src/ImageSharp/ColorProfiles/Icc/SrgbV4Profile.Generated.cs @@ -0,0 +1,45 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +// + +using SixLabors.ImageSharp.Metadata.Profiles.Icc; + +namespace SixLabors.ImageSharp.ColorProfiles.Conversion.Icc; + +internal static class SrgbV4Profile +{ + // Generated using the sRGB-v4.icc profile found at https://github.com/saucecontrol/Compact-ICC-Profiles + private static ReadOnlySpan Data => new byte[] + { + 0, 0, 1, 224, 108, 99, 109, 115, 4, 32, 0, 0, 109, 110, 116, 114, 82, 71, 66, 32, 88, 89, 90, 32, 7, 226, 0, 3, 0, + 20, 0, 9, 0, 14, 0, 29, 97, 99, 115, 112, 77, 83, 70, 84, 0, 0, 0, 0, 115, 97, 119, 115, 99, 116, 114, 108, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 246, 214, 0, 1, 0, 0, 0, 0, 211, 45, 104, 97, 110, 100, 163, 178, 171, + 223, 92, 167, 3, 18, 168, 85, 164, 236, 53, 122, 209, 243, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 100, 101, 115, 99, 0, 0, 0, 252, 0, 0, 0, 36, 99, + 112, 114, 116, 0, 0, 1, 32, 0, 0, 0, 34, 119, 116, 112, 116, 0, 0, 1, 68, 0, 0, 0, 20, 99, 104, 97, 100, 0, 0, + 1, 88, 0, 0, 0, 44, 114, 88, 89, 90, 0, 0, 1, 132, 0, 0, 0, 20, 103, 88, 89, 90, 0, 0, 1, 152, 0, 0, 0, + 20, 98, 88, 89, 90, 0, 0, 1, 172, 0, 0, 0, 20, 114, 84, 82, 67, 0, 0, 1, 192, 0, 0, 0, 32, 103, 84, 82, 67, + 0, 0, 1, 192, 0, 0, 0, 32, 98, 84, 82, 67, 0, 0, 1, 192, 0, 0, 0, 32, 109, 108, 117, 99, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, 12, 101, 110, 85, 83, 0, 0, 0, 8, 0, 0, 0, 28, 0, 115, 0, 82, 0, 71, 0, 66, 109, 108, + 117, 99, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 12, 101, 110, 85, 83, 0, 0, 0, 6, 0, 0, 0, 28, 0, 67, 0, + 67, 0, 48, 0, 33, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, 246, 214, 0, 1, 0, 0, 0, 0, 211, 45, 115, 102, 51, 50, + 0, 0, 0, 0, 0, 1, 12, 63, 0, 0, 5, 221, 255, 255, 243, 38, 0, 0, 7, 144, 0, 0, 253, 146, 255, 255, 251, 161, 255, + 255, 253, 162, 0, 0, 3, 220, 0, 0, 192, 113, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, 111, 160, 0, 0, 56, 242, 0, 0, + 3, 143, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, 98, 150, 0, 0, 183, 137, 0, 0, 24, 218, 88, 89, 90, 32, 0, 0, 0, + 0, 0, 0, 36, 160, 0, 0, 15, 133, 0, 0, 182, 196, 112, 97, 114, 97, 0, 0, 0, 0, 0, 3, 0, 0, 0, 2, 102, 105, + 0, 0, 242, 167, 0, 0, 13, 89, 0, 0, 19, 208, 0, 0, 10, 91, + }; + + private static readonly Lazy LazyIccProfile = new(() => GetIccProfile()); + + public static IccProfile GetProfile() => LazyIccProfile.Value; + + private static IccProfile GetIccProfile() + { + byte[] buffer = new byte[Data.Length]; + Data.CopyTo(buffer); + return new IccProfile(buffer); + } +} + diff --git a/src/ImageSharp/ColorProfiles/KnownYCbCrMatrices.cs b/src/ImageSharp/ColorProfiles/KnownYCbCrMatrices.cs new file mode 100644 index 0000000000..e2b7bf1026 --- /dev/null +++ b/src/ImageSharp/ColorProfiles/KnownYCbCrMatrices.cs @@ -0,0 +1,62 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Numerics; + +namespace SixLabors.ImageSharp.ColorProfiles; + +/// +/// Provides standard YCbCr matrices for RGB to YCbCr conversion. +/// +public static class KnownYCbCrMatrices +{ +#pragma warning disable SA1137 // Elements should have the same indentation +#pragma warning disable SA1117 // Parameters should be on same line or separate lines + /// + /// ITU-R BT.601 (SD video standard). + /// + public static readonly YCbCrMatrix BT601 = new( + new Matrix4x4( + 0.299000F, 0.587000F, 0.114000F, 0F, + -0.168736F, -0.331264F, 0.500000F, 0F, + 0.500000F, -0.418688F, -0.081312F, 0F, + 0F, 0F, 0F, 1F), + new Matrix4x4( + 1.000000F, 0.000000F, 1.402000F, 0F, + 1.000000F, -0.344136F, -0.714136F, 0F, + 1.000000F, 1.772000F, 0.000000F, 0F, + 0F, 0F, 0F, 1F), + new Vector3(0F, 0.5F, 0.5F)); + + /// + /// ITU-R BT.709 (HD video, sRGB standard). + /// + public static readonly YCbCrMatrix BT709 = new( + new Matrix4x4( + 0.212600F, 0.715200F, 0.072200F, 0F, + -0.114572F, -0.385428F, 0.500000F, 0F, + 0.500000F, -0.454153F, -0.045847F, 0F, + 0F, 0F, 0F, 1F), + new Matrix4x4( + 1.000000F, 0.000000F, 1.574800F, 0F, + 1.000000F, -0.187324F, -0.468124F, 0F, + 1.000000F, 1.855600F, 0.000000F, 0F, + 0F, 0F, 0F, 1F), + new Vector3(0F, 0.5F, 0.5F)); + + /// + /// ITU-R BT.2020 (UHD/4K video standard). + /// + public static readonly YCbCrMatrix BT2020 = new( + new Matrix4x4( + 0.262700F, 0.678000F, 0.059300F, 0F, + -0.139630F, -0.360370F, 0.500000F, 0F, + 0.500000F, -0.459786F, -0.040214F, 0F, + 0F, 0F, 0F, 1F), + new Matrix4x4( + 1.000000F, 0.000000F, 1.474600F, 0F, + 1.000000F, -0.164553F, -0.571353F, 0F, + 1.000000F, 1.881400F, 0.000000F, 0F, + 0F, 0F, 0F, 1F), + new Vector3(0F, 0.5F, 0.5F)); +} diff --git a/src/ImageSharp/ColorProfiles/Lms.cs b/src/ImageSharp/ColorProfiles/Lms.cs index 5a6791b2d7..3aa3d72557 100644 --- a/src/ImageSharp/ColorProfiles/Lms.cs +++ b/src/ImageSharp/ColorProfiles/Lms.cs @@ -82,20 +82,53 @@ public readonly struct Lms : IColorProfile [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Lms left, Lms right) => !left.Equals(right); - /// - /// Returns a new representing this instance. - /// - /// The . - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Vector3 ToVector3() => new(this.L, this.M, this.S); + /// + public Vector4 ToScaledVector4() + { + Vector3 v3 = default; + v3 += this.AsVector3Unsafe(); + v3 += new Vector3(1F); + v3 /= 2F; + return new Vector4(v3, 1F); + } /// - public static Lms FromProfileConnectingSpace(ColorConversionOptions options, in CieXyz source) + public static Lms FromScaledVector4(Vector4 source) + { + Vector3 v3 = source.AsVector3(); + v3 *= 2F; + v3 -= new Vector3(1F); + return new Lms(v3); + } + + /// + public static void ToScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = source[i].ToScaledVector4(); + } + } + + /// + public static void FromScaledVector4(ReadOnlySpan source, Span destination) { - Vector3 vector = Vector3.Transform(source.ToVector3(), options.AdaptationMatrix); - return new Lms(vector); + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = FromScaledVector4(source[i]); + } } + /// + public static Lms FromProfileConnectingSpace(ColorConversionOptions options, in CieXyz source) + => new(Vector3.Transform(source.AsVector3Unsafe(), options.AdaptationMatrix)); + /// public static void FromProfileConnectionSpace(ColorConversionOptions options, ReadOnlySpan source, Span destination) { @@ -110,10 +143,7 @@ public readonly struct Lms : IColorProfile /// public CieXyz ToProfileConnectingSpace(ColorConversionOptions options) - { - Vector3 vector = Vector3.Transform(this.ToVector3(), options.InverseAdaptationMatrix); - return new CieXyz(vector); - } + => new(Vector3.Transform(this.AsVector3Unsafe(), options.InverseAdaptationMatrix)); /// public static void ToProfileConnectionSpace(ColorConversionOptions options, ReadOnlySpan source, Span destination) diff --git a/src/ImageSharp/ColorProfiles/Rgb.cs b/src/ImageSharp/ColorProfiles/Rgb.cs index 6698e12cb8..9b95278bc9 100644 --- a/src/ImageSharp/ColorProfiles/Rgb.cs +++ b/src/ImageSharp/ColorProfiles/Rgb.cs @@ -81,11 +81,54 @@ public readonly struct Rgb : IProfileConnectingSpace [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Rgb left, Rgb right) => !left.Equals(right); + /// + /// Initializes the color instance from a generic scaled . + /// + /// The vector to load the color from. + /// The . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Rgb FromScaledVector4(Vector4 source) + => new(source.AsVector3()); + + /// + /// Expands the color into a generic ("scaled") representation + /// with values scaled and usually clamped between 0 and 1. + /// The vector components are typically expanded in least to greatest significance order. + /// + /// The . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Vector4 ToScaledVector4() + => new(this.ToScaledVector3(), 1F); + + /// + public static void ToScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = source[i].ToScaledVector4(); + } + } + + /// + public static void FromScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = FromScaledVector4(source[i]); + } + } + /// public static Rgb FromProfileConnectingSpace(ColorConversionOptions options, in CieXyz source) { // Convert to linear rgb then compress. - Rgb linear = new(Vector3.Transform(source.ToVector3(), GetCieXyzToRgbMatrix(options.TargetRgbWorkingSpace))); + Rgb linear = new(Vector3.Transform(source.AsVector3Unsafe(), GetCieXyzToRgbMatrix(options.TargetRgbWorkingSpace))); return FromScaledVector4(options.TargetRgbWorkingSpace.Compress(linear.ToScaledVector4())); } @@ -98,7 +141,7 @@ public readonly struct Rgb : IProfileConnectingSpace for (int i = 0; i < source.Length; i++) { // Convert to linear rgb then compress. - Rgb linear = new(Vector3.Transform(source[i].ToVector3(), matrix)); + Rgb linear = new(Vector3.Transform(source[i].AsVector3Unsafe(), matrix)); Vector4 nonlinear = options.TargetRgbWorkingSpace.Compress(linear.ToScaledVector4()); destination[i] = FromScaledVector4(nonlinear); } @@ -108,10 +151,10 @@ public readonly struct Rgb : IProfileConnectingSpace public CieXyz ToProfileConnectingSpace(ColorConversionOptions options) { // First expand to linear rgb - Rgb linear = FromScaledVector4(options.RgbWorkingSpace.Expand(this.ToScaledVector4())); + Rgb linear = FromScaledVector4(options.SourceRgbWorkingSpace.Expand(this.ToScaledVector4())); // Then convert to xyz - return new CieXyz(Vector3.Transform(linear.ToScaledVector3(), GetRgbToCieXyzMatrix(options.RgbWorkingSpace))); + return new CieXyz(Vector3.Transform(linear.ToScaledVector3(), GetRgbToCieXyzMatrix(options.SourceRgbWorkingSpace))); } /// @@ -119,13 +162,13 @@ public readonly struct Rgb : IProfileConnectingSpace { Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); - Matrix4x4 matrix = GetRgbToCieXyzMatrix(options.RgbWorkingSpace); + Matrix4x4 matrix = GetRgbToCieXyzMatrix(options.SourceRgbWorkingSpace); for (int i = 0; i < source.Length; i++) { Rgb rgb = source[i]; // First expand to linear rgb - Rgb linear = FromScaledVector4(options.RgbWorkingSpace.Expand(rgb.ToScaledVector4())); + Rgb linear = FromScaledVector4(options.SourceRgbWorkingSpace.Expand(rgb.ToScaledVector4())); // Then convert to xyz destination[i] = new CieXyz(Vector3.Transform(linear.ToScaledVector3(), matrix)); @@ -133,7 +176,8 @@ public readonly struct Rgb : IProfileConnectingSpace } /// - public static ChromaticAdaptionWhitePointSource GetChromaticAdaptionWhitePointSource() => ChromaticAdaptionWhitePointSource.RgbWorkingSpace; + public static ChromaticAdaptionWhitePointSource GetChromaticAdaptionWhitePointSource() + => ChromaticAdaptionWhitePointSource.RgbWorkingSpace; /// /// Initializes the color instance from a generic scaled . @@ -141,19 +185,8 @@ public readonly struct Rgb : IProfileConnectingSpace /// The vector to load the color from. /// The . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Rgb FromScaledVector3(Vector3 source) => new(Vector3.Clamp(source, Vector3.Zero, Vector3.One)); - - /// - /// Initializes the color instance from a generic scaled . - /// - /// The vector to load the color from. - /// The . - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Rgb FromScaledVector4(Vector4 source) - { - source = Vector4.Clamp(source, Vector4.Zero, Vector4.One); - return new(source.X, source.Y, source.Z); - } + public static Rgb FromScaledVector3(Vector3 source) + => new(source); /// /// Initializes the color instance for a source clamped between 0 and 1 @@ -161,7 +194,8 @@ public readonly struct Rgb : IProfileConnectingSpace /// The source to load the color from. /// The . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Rgb Clamp(Rgb source) => new(Vector3.Clamp(new(source.R, source.G, source.B), Vector3.Zero, Vector3.One)); + public static Rgb Clamp(Rgb source) + => new(Vector3.Clamp(source.AsVector3Unsafe(), Vector3.Zero, Vector3.One)); /// /// Expands the color into a generic ("scaled") representation @@ -170,24 +204,12 @@ public readonly struct Rgb : IProfileConnectingSpace /// /// The . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Vector3 ToScaledVector3() => Clamp(this).ToVector3(); - - /// - /// Expands the color into a generic representation. - /// The vector components are typically expanded in least to greatest significance order. - /// - /// The . - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Vector3 ToVector3() => new(this.R, this.G, this.B); - - /// - /// Expands the color into a generic ("scaled") representation - /// with values scaled and usually clamped between 0 and 1. - /// The vector components are typically expanded in least to greatest significance order. - /// - /// The . - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Vector4 ToScaledVector4() => new(this.ToScaledVector3(), 1f); + public Vector3 ToScaledVector3() + { + Vector3 v3 = default; + v3 += this.AsVector3Unsafe(); + return v3; + } /// public override int GetHashCode() => HashCode.Combine(this.R, this.G, this.B); @@ -203,7 +225,7 @@ public readonly struct Rgb : IProfileConnectingSpace public bool Equals(Rgb other) => this.AsVector3Unsafe() == other.AsVector3Unsafe(); - private Vector3 AsVector3Unsafe() => Unsafe.As(ref Unsafe.AsRef(in this)); + internal Vector3 AsVector3Unsafe() => Unsafe.As(ref Unsafe.AsRef(in this)); private static Matrix4x4 GetCieXyzToRgbMatrix(RgbWorkingSpace workingSpace) { @@ -249,7 +271,7 @@ public readonly struct Rgb : IProfileConnectingSpace Matrix4x4.Invert(xyzMatrix, out Matrix4x4 inverseXyzMatrix); - Vector3 vector = Vector3.Transform(workingSpace.WhitePoint.ToVector3(), inverseXyzMatrix); + Vector3 vector = Vector3.Transform(workingSpace.WhitePoint.AsVector3Unsafe(), inverseXyzMatrix); // Use transposed Rows/Columns return new Matrix4x4 diff --git a/src/ImageSharp/ColorProfiles/VonKriesChromaticAdaptation.cs b/src/ImageSharp/ColorProfiles/VonKriesChromaticAdaptation.cs index 2f9a52912e..ec25d0e1c4 100644 --- a/src/ImageSharp/ColorProfiles/VonKriesChromaticAdaptation.cs +++ b/src/ImageSharp/ColorProfiles/VonKriesChromaticAdaptation.cs @@ -34,9 +34,9 @@ public static class VonKriesChromaticAdaptation return new(source.X, source.Y, source.Z); } - Vector3 sourceColorLms = Vector3.Transform(source.ToVector3(), matrix); - Vector3 sourceWhitePointLms = Vector3.Transform(from.ToVector3(), matrix); - Vector3 targetWhitePointLms = Vector3.Transform(to.ToVector3(), matrix); + Vector3 sourceColorLms = Vector3.Transform(source.AsVector3Unsafe(), matrix); + Vector3 sourceWhitePointLms = Vector3.Transform(from.AsVector3Unsafe(), matrix); + Vector3 targetWhitePointLms = Vector3.Transform(to.AsVector3Unsafe(), matrix); Vector3 vector = targetWhitePointLms / sourceWhitePointLms; Vector3 targetColorLms = Vector3.Multiply(vector, sourceColorLms); @@ -76,8 +76,8 @@ public static class VonKriesChromaticAdaptation ref CieXyz sourceBase = ref MemoryMarshal.GetReference(source); ref CieXyz destinationBase = ref MemoryMarshal.GetReference(destination); - Vector3 sourceWhitePointLms = Vector3.Transform(from.ToVector3(), matrix); - Vector3 targetWhitePointLms = Vector3.Transform(to.ToVector3(), matrix); + Vector3 sourceWhitePointLms = Vector3.Transform(from.AsVector3Unsafe(), matrix); + Vector3 targetWhitePointLms = Vector3.Transform(to.AsVector3Unsafe(), matrix); Vector3 vector = targetWhitePointLms / sourceWhitePointLms; @@ -86,7 +86,7 @@ public static class VonKriesChromaticAdaptation ref CieXyz sp = ref Unsafe.Add(ref sourceBase, i); ref CieXyz dp = ref Unsafe.Add(ref destinationBase, i); - Vector3 sourceColorLms = Vector3.Transform(sp.ToVector3(), matrix); + Vector3 sourceColorLms = Vector3.Transform(sp.AsVector3Unsafe(), matrix); Vector3 targetColorLms = Vector3.Multiply(vector, sourceColorLms); dp = new CieXyz(Vector3.Transform(targetColorLms, inverseMatrix)); diff --git a/src/ImageSharp/ColorProfiles/Y.cs b/src/ImageSharp/ColorProfiles/Y.cs new file mode 100644 index 0000000000..960bf46991 --- /dev/null +++ b/src/ImageSharp/ColorProfiles/Y.cs @@ -0,0 +1,142 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace SixLabors.ImageSharp.ColorProfiles; + +/// +/// Represents a Y (luminance) color. +/// +[StructLayout(LayoutKind.Sequential)] +public readonly struct Y : IColorProfile +{ + /// + /// Initializes a new instance of the struct. + /// + /// The luminance component. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Y(float l) => this.L = Numerics.Clamp(l, 0, 1); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#pragma warning disable SA1313 // Parameter names should begin with lower-case letter + private Y(float l, bool _) => this.L = l; +#pragma warning restore SA1313 // Parameter names should begin with lower-case letter + + /// + /// Gets the luminance component. + /// + /// A value ranging between 0 and 1. + public float L { get; } + + /// + /// Compares two objects for equality. + /// + /// The on the left side of the operand. + /// The on the right side of the operand. + /// + /// True if the current left is equal to the parameter; otherwise, false. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool operator ==(Y left, Y right) => left.Equals(right); + + /// + /// Compares two objects for inequality. + /// + /// The on the left side of the operand. + /// The on the right side of the operand. + /// + /// True if the current left is unequal to the parameter; otherwise, false. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool operator !=(Y left, Y right) => !left.Equals(right); + + /// + public Vector4 ToScaledVector4() => new(this.L); + + /// + public static Y FromScaledVector4(Vector4 source) => new(source.X, true); + + /// + public static void ToScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = source[i].ToScaledVector4(); + } + } + + /// + public static void FromScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = FromScaledVector4(source[i]); + } + } + + /// + public Rgb ToProfileConnectingSpace(ColorConversionOptions options) + => new(this.L, this.L, this.L); + + /// + public static Y FromProfileConnectingSpace(ColorConversionOptions options, in Rgb source) + { + Matrix4x4 m = options.YCbCrMatrix.Forward; + float offset = options.YCbCrMatrix.Offset.X; + return new(Vector3.Dot(source.AsVector3Unsafe(), new Vector3(m.M11, m.M12, m.M13)) + offset); + } + + /// + public static void ToProfileConnectionSpace(ColorConversionOptions options, ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: We can optimize this by using SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = source[i].ToProfileConnectingSpace(options); + } + } + + /// + public static void FromProfileConnectionSpace(ColorConversionOptions options, ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: We can optimize this by using SIMD + for (int i = 0; i < source.Length; i++) + { + Rgb rgb = source[i]; + destination[i] = FromProfileConnectingSpace(options, in rgb); + } + } + + /// + public static ChromaticAdaptionWhitePointSource GetChromaticAdaptionWhitePointSource() + => ChromaticAdaptionWhitePointSource.RgbWorkingSpace; + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public override int GetHashCode() + => this.L.GetHashCode(); + + /// + public override string ToString() + => FormattableString.Invariant($"Y({this.L:#0.##})"); + + /// + public override bool Equals(object? obj) + => obj is Y other && this.Equals(other); + + /// + public bool Equals(Y other) => this.L == other.L; +} diff --git a/src/ImageSharp/ColorProfiles/YCbCr.cs b/src/ImageSharp/ColorProfiles/YCbCr.cs index 03bd1d3120..8e7dc57d74 100644 --- a/src/ImageSharp/ColorProfiles/YCbCr.cs +++ b/src/ImageSharp/ColorProfiles/YCbCr.cs @@ -8,15 +8,13 @@ using System.Runtime.InteropServices; namespace SixLabors.ImageSharp.ColorProfiles; /// -/// Represents an YCbCr (luminance, blue chroma, red chroma) color as defined in the ITU-T T.871 specification for the JFIF use with Jpeg. -/// -/// +/// Represents an YCbCr (luminance, blue chroma, red chroma) color. /// [StructLayout(LayoutKind.Sequential)] public readonly struct YCbCr : IColorProfile { private static readonly Vector3 Min = Vector3.Zero; - private static readonly Vector3 Max = new(255); + private static readonly Vector3 Max = Vector3.One; /// /// Initializes a new instance of the struct. @@ -43,21 +41,31 @@ public readonly struct YCbCr : IColorProfile this.Cr = vector.Z; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#pragma warning disable SA1313 // Parameter names should begin with lower-case letter + private YCbCr(Vector3 vector, bool _) +#pragma warning restore SA1313 // Parameter names should begin with lower-case letter + { + this.Y = vector.X; + this.Cb = vector.Y; + this.Cr = vector.Z; + } + /// /// Gets the Y luminance component. - /// A value ranging between 0 and 255. + /// A value ranging between 0 and 1. /// public float Y { get; } /// /// Gets the Cb chroma component. - /// A value ranging between 0 and 255. + /// A value ranging between 0 and 1. /// public float Cb { get; } /// /// Gets the Cr chroma component. - /// A value ranging between 0 and 255. + /// A value ranging between 0 and 1. /// public float Cr { get; } @@ -83,18 +91,49 @@ public readonly struct YCbCr : IColorProfile public static bool operator !=(YCbCr left, YCbCr right) => !left.Equals(right); /// - public static YCbCr FromProfileConnectingSpace(ColorConversionOptions options, in Rgb source) + public Vector4 ToScaledVector4() { - Vector3 rgb = source.ToScaledVector3() * Max; - float r = rgb.X; - float g = rgb.Y; - float b = rgb.Z; + Vector3 v3 = default; + v3 += this.AsVector3Unsafe(); + return new Vector4(v3, 1F); + } - float y = (0.299F * r) + (0.587F * g) + (0.114F * b); - float cb = 128F + ((-0.168736F * r) - (0.331264F * g) + (0.5F * b)); - float cr = 128F + ((0.5F * r) - (0.418688F * g) - (0.081312F * b)); + /// + public static YCbCr FromScaledVector4(Vector4 source) + => new(source.AsVector3(), true); + + /// + public static void ToScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); - return new YCbCr(y, cb, cr); + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = source[i].ToScaledVector4(); + } + } + + /// + public static void FromScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: Optimize via SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = FromScaledVector4(source[i]); + } + } + + /// + public static YCbCr FromProfileConnectingSpace(ColorConversionOptions options, in Rgb source) + { + Vector3 rgb = source.AsVector3Unsafe(); + Matrix4x4 m = options.TransposedYCbCrMatrix.Forward; + Vector3 offset = options.TransposedYCbCrMatrix.Offset; + + return new YCbCr(Vector3.Transform(rgb, m) + offset, true); } /// @@ -113,15 +152,11 @@ public readonly struct YCbCr : IColorProfile /// public Rgb ToProfileConnectingSpace(ColorConversionOptions options) { - float y = this.Y; - float cb = this.Cb - 128F; - float cr = this.Cr - 128F; - - float r = MathF.Round(y + (1.402F * cr), MidpointRounding.AwayFromZero); - float g = MathF.Round(y - (0.344136F * cb) - (0.714136F * cr), MidpointRounding.AwayFromZero); - float b = MathF.Round(y + (1.772F * cb), MidpointRounding.AwayFromZero); + Matrix4x4 m = options.TransposedYCbCrMatrix.Inverse; + Vector3 offset = options.TransposedYCbCrMatrix.Offset; + Vector3 normalized = this.AsVector3Unsafe() - offset; - return Rgb.FromScaledVector3(new Vector3(r, g, b) / Max); + return Rgb.FromScaledVector3(Vector3.Transform(normalized, m)); } /// @@ -132,8 +167,7 @@ public readonly struct YCbCr : IColorProfile // TODO: We can optimize this by using SIMD for (int i = 0; i < source.Length; i++) { - YCbCr ycbcr = source[i]; - destination[i] = ycbcr.ToProfileConnectingSpace(options); + destination[i] = source[i].ToProfileConnectingSpace(options); } } diff --git a/src/ImageSharp/ColorProfiles/YcbCrMatrix.cs b/src/ImageSharp/ColorProfiles/YcbCrMatrix.cs new file mode 100644 index 0000000000..ccb4ea9861 --- /dev/null +++ b/src/ImageSharp/ColorProfiles/YcbCrMatrix.cs @@ -0,0 +1,61 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Numerics; +using SixLabors.ImageSharp.ColorProfiles.WorkingSpaces; + +namespace SixLabors.ImageSharp.ColorProfiles; + +/// +/// +/// Represents a YCbCr color matrix containing forward and inverse transformation matrices, +/// and the chrominance offsets to apply for full-range encoding +/// +/// +/// These matrices must be selected to match the characteristics of the associated , +/// including its transfer function (gamma or companding) and chromaticity coordinates. Using mismatched matrices and +/// working spaces will produce incorrect conversions. +/// +/// +public readonly struct YCbCrMatrix +{ + /// + /// Initializes a new instance of the struct. + /// + /// + /// The forward transformation matrix from RGB to YCbCr. The matrix must include the + /// standard chrominance offsets in the fourth column, such as (0, 0.5, 0.5). + /// + /// + /// The inverse transformation matrix from YCbCr to RGB. This matrix expects that + /// chrominance offsets have already been subtracted prior to application. + /// + /// + /// 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) + { + this.Forward = forward; + this.Inverse = inverse; + this.Offset = offset; + } + + /// + /// Gets the matrix used to convert gamma-encoded RGB to YCbCr. + /// + public Matrix4x4 Forward { get; } + + /// + /// Gets the matrix used to convert YCbCr back to gamma-encoded RGB. + /// + public Matrix4x4 Inverse { get; } + + /// + /// Gets the chrominance offset vector to apply during encoding (add) or decoding (subtract). + /// + public Vector3 Offset { get; } + + internal YCbCrMatrix 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 new file mode 100644 index 0000000000..f05e1431b2 --- /dev/null +++ b/src/ImageSharp/ColorProfiles/YccK.cs @@ -0,0 +1,206 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace SixLabors.ImageSharp.ColorProfiles; + +/// +/// Represents a YCCK (luminance, blue chroma, red chroma, black) color. +/// YCCK is not a true color space but a reversible transform of CMYK, where the CMY components +/// are converted to YCbCr using the ITU-R BT.601 standard, and the K (black) component is preserved separately. +/// +[StructLayout(LayoutKind.Sequential)] +public readonly struct YccK : IColorProfile +{ + private static readonly Vector4 Min = Vector4.Zero; + private static readonly Vector4 Max = Vector4.One; + + /// + /// Initializes a new instance of the struct. + /// + /// The y luminance component. + /// The cb chroma component. + /// The cr chroma component. + /// The keyline black component. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public YccK(float y, float cb, float cr, float k) + : this(new Vector4(y, cb, cr, k)) + { + } + + /// + /// Initializes a new instance of the struct. + /// + /// The vector representing the c, m, y, k components. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public YccK(Vector4 vector) + { + vector = Vector4.Clamp(vector, Min, Max); + this.Y = vector.X; + this.Cb = vector.Y; + this.Cr = vector.Z; + this.K = vector.W; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#pragma warning disable SA1313 // Parameter names should begin with lower-case letter + private YccK(Vector4 vector, bool _) +#pragma warning restore SA1313 // Parameter names should begin with lower-case letter + { + this.Y = vector.X; + this.Cb = vector.Y; + this.Cr = vector.Z; + this.K = vector.W; + } + + /// + /// Gets the Y luminance component. + /// A value ranging between 0 and 1. + /// + public float Y { get; } + + /// + /// Gets the C (blue) chroma component. + /// A value ranging between 0 and 1. + /// + public float Cb { get; } + + /// + /// Gets the C (red) chroma component. + /// A value ranging between 0 and 1. + /// + public float Cr { get; } + + /// + /// Gets the keyline black color component. + /// A value ranging between 0 and 1. + /// + public float K { get; } + + /// + /// Compares two objects for equality. + /// + /// The on the left side of the operand. + /// The on the right side of the operand. + /// + /// True if the current left is equal to the parameter; otherwise, false. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool operator ==(YccK left, YccK right) => left.Equals(right); + + /// + /// Compares two objects for inequality. + /// + /// The on the left side of the operand. + /// The on the right side of the operand. + /// + /// True if the current left is unequal to the parameter; otherwise, false. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool operator !=(YccK left, YccK right) => !left.Equals(right); + + /// + public Vector4 ToScaledVector4() + { + Vector4 v4 = default; + v4 += this.AsVector4Unsafe(); + return v4; + } + + /// + public static YccK FromScaledVector4(Vector4 source) + => new(source, true); + + /// + public static void ToScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + MemoryMarshal.Cast(source).CopyTo(destination); + } + + /// + public static void FromScaledVector4(ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + MemoryMarshal.Cast(source).CopyTo(destination); + } + + /// + public Rgb ToProfileConnectingSpace(ColorConversionOptions options) + { + Matrix4x4 m = options.TransposedYCbCrMatrix.Inverse; + Vector3 offset = options.TransposedYCbCrMatrix.Offset; + Vector3 normalized = this.AsVector3Unsafe() - offset; + + return Rgb.FromScaledVector3(Vector3.Transform(normalized, m) * (1F - this.K)); + } + + /// + public static YccK FromProfileConnectingSpace(ColorConversionOptions options, in Rgb source) + { + Matrix4x4 m = options.TransposedYCbCrMatrix.Forward; + Vector3 offset = options.TransposedYCbCrMatrix.Offset; + + Vector3 rgb = source.AsVector3Unsafe(); + float k = 1F - MathF.Max(rgb.X, MathF.Max(rgb.Y, rgb.Z)); + + if (k >= 1F - Constants.Epsilon) + { + return new YccK(new Vector4(0F, 0.5F, 0.5F, 1F), true); + } + + rgb /= 1F - k; + return new YccK(new Vector4(Vector3.Transform(rgb, m), k) + new Vector4(offset, 0F)); + } + + /// + public static void ToProfileConnectionSpace(ColorConversionOptions options, ReadOnlySpan source, Span destination) + { + // TODO: We can possibly optimize this by using SIMD + for (int i = 0; i < source.Length; i++) + { + destination[i] = source[i].ToProfileConnectingSpace(options); + } + } + + /// + public static void FromProfileConnectionSpace(ColorConversionOptions options, ReadOnlySpan source, Span destination) + { + Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination)); + + // TODO: We can optimize this by using SIMD + for (int i = 0; i < source.Length; i++) + { + Rgb rgb = source[i]; + destination[i] = FromProfileConnectingSpace(options, in rgb); + } + } + + /// + public static ChromaticAdaptionWhitePointSource GetChromaticAdaptionWhitePointSource() + => ChromaticAdaptionWhitePointSource.RgbWorkingSpace; + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public override int GetHashCode() + => HashCode.Combine(this.Y, this.Cb, this.Cr, this.K); + + /// + public override string ToString() + => FormattableString.Invariant($"YccK({this.Y:#0.##}, {this.Cb:#0.##}, {this.Cr:#0.##}, {this.K:#0.##})"); + + /// + public override bool Equals(object? obj) + => obj is YccK other && this.Equals(other); + + /// + public bool Equals(YccK other) + => this.AsVector4Unsafe() == other.AsVector4Unsafe(); + + private Vector3 AsVector3Unsafe() => Unsafe.As(ref Unsafe.AsRef(in this)); + + private Vector4 AsVector4Unsafe() => Unsafe.As(ref Unsafe.AsRef(in this)); +} diff --git a/src/ImageSharp/Common/Extensions/Vector4Extensions.cs b/src/ImageSharp/Common/Extensions/Vector4Extensions.cs new file mode 100644 index 0000000000..4e8ea61742 --- /dev/null +++ b/src/ImageSharp/Common/Extensions/Vector4Extensions.cs @@ -0,0 +1,21 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +#if !NET9_0_OR_GREATER +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.Intrinsics; + +namespace SixLabors.ImageSharp; + +internal static class Vector4Extensions +{ + /// + /// Reinterprets a as a new . + /// + /// The vector to reinterpret. + /// reinterpreted as a new . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Vector3 AsVector3(this Vector4 value) => value.AsVector128().AsVector3(); +} +#endif diff --git a/src/ImageSharp/Common/InlineArray.cs b/src/ImageSharp/Common/InlineArray.cs new file mode 100644 index 0000000000..c20c0d8750 --- /dev/null +++ b/src/ImageSharp/Common/InlineArray.cs @@ -0,0 +1,38 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +// + +using System; +using System.Runtime.CompilerServices; + +namespace SixLabors.ImageSharp; + +/// +/// Represents a safe, fixed sized buffer of 4 elements. +/// +[InlineArray(4)] +internal struct InlineArray4 +{ + private T t; +} + +/// +/// Represents a safe, fixed sized buffer of 8 elements. +/// +[InlineArray(8)] +internal struct InlineArray8 +{ + private T t; +} + +/// +/// Represents a safe, fixed sized buffer of 16 elements. +/// +[InlineArray(16)] +internal struct InlineArray16 +{ + private T t; +} + + diff --git a/src/ImageSharp/Common/InlineArray.tt b/src/ImageSharp/Common/InlineArray.tt new file mode 100644 index 0000000000..ab488591a7 --- /dev/null +++ b/src/ImageSharp/Common/InlineArray.tt @@ -0,0 +1,38 @@ +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.Collections.Generic" #> +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +// + +using System; +using System.Runtime.CompilerServices; + +namespace SixLabors.ImageSharp; + +<#GenerateInlineArrays();#> + +<#+ +private static int[] Lengths = new int[] {4, 8, 16 }; + +void GenerateInlineArrays() +{ + foreach (int length in Lengths) + { +#> +/// +/// Represents a safe, fixed sized buffer of <#=length#> elements. +/// +[InlineArray(<#=length#>)] +internal struct InlineArray<#=length#> +{ + private T t; +} + +<#+ + } +} +#> diff --git a/src/ImageSharp/Formats/AlphaAwareImageEncoder.cs b/src/ImageSharp/Formats/AlphaAwareImageEncoder.cs index f753e7282b..1c1a8b2910 100644 --- a/src/ImageSharp/Formats/AlphaAwareImageEncoder.cs +++ b/src/ImageSharp/Formats/AlphaAwareImageEncoder.cs @@ -1,6 +1,8 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +using SixLabors.ImageSharp.Processing.Processors.Quantization; + namespace SixLabors.ImageSharp.Formats; /// @@ -10,6 +12,8 @@ public abstract class AlphaAwareImageEncoder : ImageEncoder { /// /// Gets or initializes the mode that determines how transparent pixels are handled during encoding. + /// This overrides any other settings that may affect the encoding of transparent pixels + /// including those passed via . /// public TransparentColorMode TransparentColorMode { get; init; } } diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs index 321a559b1e..46da463455 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs @@ -362,10 +362,13 @@ internal sealed class BmpEncoderCore ImageFrame? clonedFrame = null; try { - if (EncodingUtilities.ShouldClearTransparentPixels(this.transparentColorMode)) + // No need to clone when quantizing. The quantizer will do it for us. + // TODO: We should really try to avoid the clone entirely. + int bpp = this.bitsPerPixel != null ? (int)this.bitsPerPixel : 32; + if (bpp > 8 && EncodingUtilities.ShouldReplaceTransparentPixels(this.transparentColorMode)) { clonedFrame = image.Frames.RootFrame.Clone(); - EncodingUtilities.ClearTransparentPixels(clonedFrame, Color.Transparent); + EncodingUtilities.ReplaceTransparentPixels(clonedFrame); } ImageFrame encodingFrame = clonedFrame ?? image.Frames.RootFrame; diff --git a/src/ImageSharp/Formats/Bmp/BmpMetadata.cs b/src/ImageSharp/Formats/Bmp/BmpMetadata.cs index d0c60421c4..1dac74ba3a 100644 --- a/src/ImageSharp/Formats/Bmp/BmpMetadata.cs +++ b/src/ImageSharp/Formats/Bmp/BmpMetadata.cs @@ -158,6 +158,5 @@ public class BmpMetadata : IFormatMetadata /// public void AfterImageApply(Image destination) where TPixel : unmanaged, IPixel - { - } + => this.ColorTable = null; } diff --git a/src/ImageSharp/Formats/ColorProfileHandling.cs b/src/ImageSharp/Formats/ColorProfileHandling.cs new file mode 100644 index 0000000000..e6f4b0a6a0 --- /dev/null +++ b/src/ImageSharp/Formats/ColorProfileHandling.cs @@ -0,0 +1,21 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +namespace SixLabors.ImageSharp.Formats; + +/// +/// Provides enumeration of methods that control how ICC profiles are handled during decode. +/// +public enum ColorProfileHandling +{ + /// + /// Leaves any embedded ICC color profiles intact. + /// + Preserve, + + /// + /// Transforms the pixels of the image based on the conversion of any embedded ICC color profiles to sRGB V4 profile. + /// The original profile is then replaced. + /// + Convert +} diff --git a/src/ImageSharp/Formats/Cur/CurFrameMetadata.cs b/src/ImageSharp/Formats/Cur/CurFrameMetadata.cs index 01b7fbce08..9854854aad 100644 --- a/src/ImageSharp/Formats/Cur/CurFrameMetadata.cs +++ b/src/ImageSharp/Formats/Cur/CurFrameMetadata.cs @@ -104,7 +104,6 @@ public class CurFrameMetadata : IFormatFrameMetadata Compression = compression, EncodingWidth = ClampEncodingDimension(metadata.EncodingWidth), EncodingHeight = ClampEncodingDimension(metadata.EncodingHeight), - ColorTable = compression == IconFrameCompression.Bmp ? metadata.ColorTable : null }; } @@ -113,7 +112,6 @@ public class CurFrameMetadata : IFormatFrameMetadata => new() { PixelTypeInfo = this.GetPixelTypeInfo(), - ColorTable = this.ColorTable, EncodingWidth = this.EncodingWidth, EncodingHeight = this.EncodingHeight }; @@ -126,6 +124,7 @@ public class CurFrameMetadata : IFormatFrameMetadata float ratioY = destination.Height / (float)source.Height; this.EncodingWidth = ScaleEncodingDimension(this.EncodingWidth, destination.Width, ratioX); this.EncodingHeight = ScaleEncodingDimension(this.EncodingHeight, destination.Height, ratioY); + this.ColorTable = null; } /// diff --git a/src/ImageSharp/Formats/Cur/CurMetadata.cs b/src/ImageSharp/Formats/Cur/CurMetadata.cs index 19de7f434d..d8fdb32902 100644 --- a/src/ImageSharp/Formats/Cur/CurMetadata.cs +++ b/src/ImageSharp/Formats/Cur/CurMetadata.cs @@ -71,8 +71,7 @@ public class CurMetadata : IFormatMetadata return new CurMetadata { BmpBitsPerPixel = bbpp, - Compression = compression, - ColorTable = compression == IconFrameCompression.Bmp ? metadata.ColorTable : null + Compression = compression }; } @@ -145,15 +144,13 @@ public class CurMetadata : IFormatMetadata EncodingType = this.Compression == IconFrameCompression.Bmp && this.BmpBitsPerPixel <= BmpBitsPerPixel.Bit8 ? EncodingType.Lossy : EncodingType.Lossless, - PixelTypeInfo = this.GetPixelTypeInfo(), - ColorTable = this.ColorTable + PixelTypeInfo = this.GetPixelTypeInfo() }; /// public void AfterImageApply(Image destination) where TPixel : unmanaged, IPixel - { - } + => this.ColorTable = null; /// IDeepCloneable IDeepCloneable.DeepClone() => this.DeepClone(); diff --git a/src/ImageSharp/Formats/DecoderOptions.cs b/src/ImageSharp/Formats/DecoderOptions.cs index 3b16159b7e..8c6b8fc225 100644 --- a/src/ImageSharp/Formats/DecoderOptions.cs +++ b/src/ImageSharp/Formats/DecoderOptions.cs @@ -60,5 +60,11 @@ public sealed class DecoderOptions /// public SegmentIntegrityHandling SegmentIntegrityHandling { get; init; } = SegmentIntegrityHandling.IgnoreNonCritical; + /// + /// Gets a value that controls how ICC profiles are handled during decode. + /// TODO: Implement this. + /// + internal ColorProfileHandling ColorProfileHandling { get; init; } + internal void SetConfiguration(Configuration configuration) => this.configuration = configuration; } diff --git a/src/ImageSharp/Formats/EncodingUtilities.cs b/src/ImageSharp/Formats/EncodingUtilities.cs index a979fdf6fa..3994743933 100644 --- a/src/ImageSharp/Formats/EncodingUtilities.cs +++ b/src/ImageSharp/Formats/EncodingUtilities.cs @@ -3,6 +3,8 @@ using System.Buffers; using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Runtime.Intrinsics; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; @@ -14,62 +16,132 @@ namespace SixLabors.ImageSharp.Formats; /// internal static class EncodingUtilities { - public static bool ShouldClearTransparentPixels(TransparentColorMode mode) + /// + /// Determines if transparent pixels can be replaced based on the specified color mode and pixel type. + /// + /// The type of the pixel. + /// Indicates the color mode used to assess the ability to replace transparent pixels. + /// Returns true if transparent pixels can be replaced; otherwise, false. + public static bool ShouldReplaceTransparentPixels(TransparentColorMode mode) + where TPixel : unmanaged, IPixel + => mode == TransparentColorMode.Clear && TPixel.GetPixelTypeInfo().AlphaRepresentation == PixelAlphaRepresentation.Unassociated; + + /// + /// Replaces pixels with a transparent alpha component with fully transparent pixels. + /// + /// The type of the pixel. + /// The where the transparent pixels will be changed. + public static void ReplaceTransparentPixels(ImageFrame frame) where TPixel : unmanaged, IPixel - => mode == TransparentColorMode.Clear && - TPixel.GetPixelTypeInfo().AlphaRepresentation == PixelAlphaRepresentation.Unassociated; + => ReplaceTransparentPixels(frame.Configuration, frame.PixelBuffer); /// - /// Convert transparent pixels, to pixels represented by , which can yield - /// to better compression in some cases. + /// Replaces pixels with a transparent alpha component with fully transparent pixels. /// /// The type of the pixel. - /// The cloned where the transparent pixels will be changed. - /// The color to replace transparent pixels with. - public static void ClearTransparentPixels(ImageFrame clone, Color color) + /// The configuration. + /// The where the transparent pixels will be changed. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void ReplaceTransparentPixels(Configuration configuration, Buffer2D buffer) where TPixel : unmanaged, IPixel { - Buffer2DRegion buffer = clone.PixelBuffer.GetRegion(); - ClearTransparentPixels(clone.Configuration, ref buffer, color); + Buffer2DRegion region = buffer.GetRegion(); + ReplaceTransparentPixels(configuration, in region); } /// - /// Convert transparent pixels, to pixels represented by , which can yield - /// to better compression in some cases. + /// Replaces pixels with a transparent alpha component with fully transparent pixels. /// /// The type of the pixel. /// The configuration. - /// The cloned where the transparent pixels will be changed. - /// The color to replace transparent pixels with. - public static void ClearTransparentPixels( + /// The where the transparent pixels will be changed. + public static void ReplaceTransparentPixels( Configuration configuration, - ref Buffer2DRegion clone, - Color color) + in Buffer2DRegion region) where TPixel : unmanaged, IPixel { - using IMemoryOwner vectors = configuration.MemoryAllocator.Allocate(clone.Width); + using IMemoryOwner vectors = configuration.MemoryAllocator.Allocate(region.Width); Span vectorsSpan = vectors.GetSpan(); - Vector4 replacement = color.ToScaledVector4(); - for (int y = 0; y < clone.Height; y++) + for (int y = 0; y < region.Height; y++) { - Span span = clone.DangerousGetRowSpan(y); + Span span = region.DangerousGetRowSpan(y); PixelOperations.Instance.ToVector4(configuration, span, vectorsSpan, PixelConversionModifiers.Scale); - ClearTransparentPixelRow(vectorsSpan, replacement); + ReplaceTransparentPixels(vectorsSpan); PixelOperations.Instance.FromVector4Destructive(configuration, vectorsSpan, span, PixelConversionModifiers.Scale); } } - private static void ClearTransparentPixelRow( - Span vectorsSpan, - Vector4 replacement) + /// + /// Replaces pixels with a transparent alpha component with fully transparent pixels. + /// + /// A span of color vectors that will be checked for transparency and potentially modified. + public static void ReplaceTransparentPixels(Span source) { - if (Vector128.IsHardwareAccelerated) + if (Vector512.IsHardwareAccelerated && source.Length >= 4) + { + Span> source512 = MemoryMarshal.Cast>(source); + for (int i = 0; i < source512.Length; i++) + { + ref Vector512 v = ref source512[i]; + + // Do `vector < threshold` + Vector512 mask = Vector512.Equals(v, Vector512.Zero); + + // Replicate the result for W to all elements (is AllBitsSet if the W was 0 and Zero otherwise) + mask = Vector512.Shuffle(mask, Vector512.Create(3, 3, 3, 3, 7, 7, 7, 7, 11, 11, 11, 11, 15, 15, 15, 15)); + + // Use the mask to select the replacement vector + // (replacement & mask) | (v512 & ~mask) + v = Vector512.ConditionalSelect(mask, Vector512.Zero, v); + } + + int m = Numerics.Modulo4(source.Length); + if (m != 0) + { + for (int i = source.Length - m; i < source.Length; i++) + { + if (source[i].W == 0) + { + source[i] = Vector4.Zero; + } + } + } + } + else if (Vector256.IsHardwareAccelerated && source.Length >= 2) { - Vector128 replacement128 = replacement.AsVector128(); + Span> source256 = MemoryMarshal.Cast>(source); + for (int i = 0; i < source256.Length; i++) + { + ref Vector256 v = ref source256[i]; + + // Do `vector < threshold` + Vector256 mask = Vector256.Equals(v, Vector256.Zero); + + // Replicate the result for W to all elements (is AllBitsSet if the W was 0 and Zero otherwise) + mask = Vector256.Shuffle(mask, Vector256.Create(3, 3, 3, 3, 7, 7, 7, 7)); - for (int i = 0; i < vectorsSpan.Length; i++) + // Use the mask to select the replacement vector + // (replacement & mask) | (v256 & ~mask) + v = Vector256.ConditionalSelect(mask, Vector256.Zero, v); + } + + int m = Numerics.Modulo2(source.Length); + if (m != 0) + { + for (int i = source.Length - m; i < source.Length; i++) + { + if (source[i].W == 0) + { + source[i] = Vector4.Zero; + } + } + } + } + else if (Vector128.IsHardwareAccelerated) + { + for (int i = 0; i < source.Length; i++) { - ref Vector4 v = ref vectorsSpan[i]; + ref Vector4 v = ref source[i]; Vector128 v128 = v.AsVector128(); // Do `vector == 0` @@ -80,16 +152,16 @@ internal static class EncodingUtilities // Use the mask to select the replacement vector // (replacement & mask) | (v128 & ~mask) - v = Vector128.ConditionalSelect(mask, replacement128, v128).AsVector4(); + v = Vector128.ConditionalSelect(mask, Vector128.Zero, v128).AsVector4(); } } else { - for (int i = 0; i < vectorsSpan.Length; i++) + for (int i = 0; i < source.Length; i++) { - if (vectorsSpan[i].W == 0F) + if (source[i].W == 0F) { - vectorsSpan[i] = replacement; + source[i] = Vector4.Zero; } } } diff --git a/src/ImageSharp/Formats/FormatConnectingFrameMetadata.cs b/src/ImageSharp/Formats/FormatConnectingFrameMetadata.cs index ded220c9ad..15a28c301a 100644 --- a/src/ImageSharp/Formats/FormatConnectingFrameMetadata.cs +++ b/src/ImageSharp/Formats/FormatConnectingFrameMetadata.cs @@ -15,11 +15,6 @@ public class FormatConnectingFrameMetadata /// public PixelTypeInfo? PixelTypeInfo { get; init; } - /// - /// Gets the frame color table if any. - /// - public ReadOnlyMemory? ColorTable { get; init; } - /// /// Gets the frame color table mode. /// diff --git a/src/ImageSharp/Formats/FormatConnectingMetadata.cs b/src/ImageSharp/Formats/FormatConnectingMetadata.cs index 9cfe40f385..efa7acdc86 100644 --- a/src/ImageSharp/Formats/FormatConnectingMetadata.cs +++ b/src/ImageSharp/Formats/FormatConnectingMetadata.cs @@ -28,11 +28,6 @@ public class FormatConnectingMetadata /// public PixelTypeInfo PixelTypeInfo { get; init; } - /// - /// Gets the shared color table if any. - /// - public ReadOnlyMemory? ColorTable { get; init; } - /// /// Gets the shared color table mode. /// diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs index e18166c4b8..f6e3643d58 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs @@ -89,6 +89,11 @@ internal sealed class GifDecoderCore : ImageDecoderCore /// private GifMetadata? gifMetadata; + /// + /// The background color index. + /// + private byte backgroundColorIndex; + /// /// Initializes a new instance of the class. /// @@ -108,6 +113,10 @@ internal sealed class GifDecoderCore : ImageDecoderCore uint frameCount = 0; Image? image = null; ImageFrame? previousFrame = null; + FrameDisposalMode? previousDisposalMode = null; + bool globalColorTableUsed = false; + Color backgroundColor = Color.Transparent; + try { this.ReadLogicalScreenDescriptorAndGlobalColorTable(stream); @@ -123,7 +132,7 @@ internal sealed class GifDecoderCore : ImageDecoderCore break; } - this.ReadFrame(stream, ref image, ref previousFrame); + globalColorTableUsed |= this.ReadFrame(stream, ref image, ref previousFrame, ref previousDisposalMode, ref backgroundColor); // Reset per-frame state. this.imageDescriptor = default; @@ -158,6 +167,13 @@ internal sealed class GifDecoderCore : ImageDecoderCore break; } } + + // We cannot always trust the global GIF palette has actually been used. + // https://github.com/SixLabors/ImageSharp/issues/2866 + if (!globalColorTableUsed) + { + this.gifMetadata.ColorTableMode = FrameColorTableMode.Local; + } } finally { @@ -179,6 +195,8 @@ internal sealed class GifDecoderCore : ImageDecoderCore uint frameCount = 0; ImageFrameMetadata? previousFrame = null; List framesMetadata = []; + bool globalColorTableUsed = false; + try { this.ReadLogicalScreenDescriptorAndGlobalColorTable(stream); @@ -194,7 +212,7 @@ internal sealed class GifDecoderCore : ImageDecoderCore break; } - this.ReadFrameMetadata(stream, framesMetadata, ref previousFrame); + globalColorTableUsed |= this.ReadFrameMetadata(stream, framesMetadata, ref previousFrame); // Reset per-frame state. this.imageDescriptor = default; @@ -229,6 +247,13 @@ internal sealed class GifDecoderCore : ImageDecoderCore break; } } + + // We cannot always trust the global GIF palette has actually been used. + // https://github.com/SixLabors/ImageSharp/issues/2866 + if (!globalColorTableUsed) + { + this.gifMetadata.ColorTableMode = FrameColorTableMode.Local; + } } finally { @@ -416,7 +441,15 @@ internal sealed class GifDecoderCore : ImageDecoderCore /// The containing image data. /// The image to decode the information to. /// The previous frame. - private void ReadFrame(BufferedReadStream stream, ref Image? image, ref ImageFrame? previousFrame) + /// The previous frame disposal mode. + /// The background color. + /// Whether the frame has a global color table. + private bool ReadFrame( + BufferedReadStream stream, + ref Image? image, + ref ImageFrame? previousFrame, + ref FrameDisposalMode? previousDisposalMode, + ref Color backgroundColor) where TPixel : unmanaged, IPixel { this.ReadImageDescriptor(stream); @@ -438,10 +471,52 @@ internal sealed class GifDecoderCore : ImageDecoderCore } ReadOnlySpan colorTable = MemoryMarshal.Cast(rawColorTable); - this.ReadFrameColors(stream, ref image, ref previousFrame, colorTable); + + // First frame + if (image is null) + { + if (this.backgroundColorIndex < colorTable.Length) + { + backgroundColor = Color.FromPixel(colorTable[this.backgroundColorIndex]); + } + else + { + backgroundColor = Color.Transparent; + } + + if (this.graphicsControlExtension.TransparencyFlag) + { + backgroundColor = backgroundColor.WithAlpha(0); + } + } + + this.ReadFrameColors(stream, ref image, ref previousFrame, ref previousDisposalMode, colorTable, backgroundColor.ToPixel()); + + // Update from newly decoded frame. + if (this.graphicsControlExtension.DisposalMethod != FrameDisposalMode.RestoreToPrevious) + { + if (this.backgroundColorIndex < colorTable.Length) + { + backgroundColor = Color.FromPixel(colorTable[this.backgroundColorIndex]); + } + else + { + backgroundColor = Color.Transparent; + } + + // TODO: I don't understand why this is always set to alpha of zero. + // This should be dependent on the transparency flag of the graphics + // control extension. ImageMagick does the same. + // if (this.graphicsControlExtension.TransparencyFlag) + { + backgroundColor = backgroundColor.WithAlpha(0); + } + } // Skip any remaining blocks SkipBlock(stream); + + return !hasLocalColorTable; } /// @@ -451,56 +526,73 @@ internal sealed class GifDecoderCore : ImageDecoderCore /// The containing image data. /// The image to decode the information to. /// The previous frame. + /// The previous frame disposal mode. /// The color table containing the available colors. + /// The background color pixel. private void ReadFrameColors( BufferedReadStream stream, ref Image? image, ref ImageFrame? previousFrame, - ReadOnlySpan colorTable) + ref FrameDisposalMode? previousDisposalMode, + ReadOnlySpan colorTable, + TPixel backgroundPixel) where TPixel : unmanaged, IPixel { GifImageDescriptor descriptor = this.imageDescriptor; int imageWidth = this.logicalScreenDescriptor.Width; int imageHeight = this.logicalScreenDescriptor.Height; bool transFlag = this.graphicsControlExtension.TransparencyFlag; + FrameDisposalMode disposalMethod = this.graphicsControlExtension.DisposalMethod; + ImageFrame currentFrame; + ImageFrame? restoreFrame = null; - ImageFrame? prevFrame = null; - ImageFrame? currentFrame = null; - ImageFrame imageFrame; + if (previousFrame is null && previousDisposalMode is null) + { + image = transFlag + ? new Image(this.configuration, imageWidth, imageHeight, this.metadata) + : new Image(this.configuration, imageWidth, imageHeight, backgroundPixel, this.metadata); - if (previousFrame is null) + this.SetFrameMetadata(image.Frames.RootFrame.Metadata); + currentFrame = image.Frames.RootFrame; + } + else { - if (!transFlag) + if (previousFrame != null) { - image = new Image(this.configuration, imageWidth, imageHeight, Color.Black.ToPixel(), this.metadata); + currentFrame = image!.Frames.AddFrame(previousFrame); } else { - // This initializes the image to become fully transparent because the alpha channel is zero. - image = new Image(this.configuration, imageWidth, imageHeight, this.metadata); + currentFrame = image!.Frames.CreateFrame(backgroundPixel); } - this.SetFrameMetadata(image.Frames.RootFrame.Metadata); + this.SetFrameMetadata(currentFrame.Metadata); - imageFrame = image.Frames.RootFrame; - } - else - { if (this.graphicsControlExtension.DisposalMethod == FrameDisposalMode.RestoreToPrevious) { - prevFrame = previousFrame; + restoreFrame = previousFrame; } - // We create a clone of the frame and add it. - // We will overpaint the difference of pixels on the current frame to create a complete image. - // This ensures that we have enough pixel data to process without distortion. #2450 - currentFrame = image!.Frames.AddFrame(previousFrame); + if (previousDisposalMode == FrameDisposalMode.RestoreToBackground) + { + this.RestoreToBackground(currentFrame, backgroundPixel, transFlag); + } + } - this.SetFrameMetadata(currentFrame.Metadata); + if (this.graphicsControlExtension.DisposalMethod == FrameDisposalMode.RestoreToPrevious) + { + previousFrame = restoreFrame; + } + else + { + previousFrame = currentFrame; + } - imageFrame = currentFrame; + previousDisposalMode = disposalMethod; - this.RestoreToBackground(imageFrame); + if (disposalMethod == FrameDisposalMode.RestoreToBackground) + { + this.restoreArea = Rectangle.Intersect(image.Bounds, new(descriptor.Left, descriptor.Top, descriptor.Width, descriptor.Height)); } if (colorTable.Length == 0) @@ -568,7 +660,7 @@ internal sealed class GifDecoderCore : ImageDecoderCore // #403 The left + width value can be larger than the image width int maxX = Math.Min(descriptorRight, imageWidth); - Span row = imageFrame.PixelBuffer.DangerousGetRowSpan(writeY); + Span row = currentFrame.PixelBuffer.DangerousGetRowSpan(writeY); // Take the descriptorLeft..maxX slice of the row, so the loop can be simplified. row = row[descriptorLeft..maxX]; @@ -599,19 +691,6 @@ internal sealed class GifDecoderCore : ImageDecoderCore } } } - - if (prevFrame != null) - { - previousFrame = prevFrame; - return; - } - - previousFrame = currentFrame ?? image.Frames.RootFrame; - - if (this.graphicsControlExtension.DisposalMethod == FrameDisposalMode.RestoreToBackground) - { - this.restoreArea = new Rectangle(descriptor.Left, descriptor.Top, descriptor.Width, descriptor.Height); - } } /// @@ -620,7 +699,8 @@ internal sealed class GifDecoderCore : ImageDecoderCore /// The containing image data. /// The collection of frame metadata. /// The previous frame metadata. - private void ReadFrameMetadata(BufferedReadStream stream, List frameMetadata, ref ImageFrameMetadata? previousFrame) + /// Whether the frame has a global color table. + private bool ReadFrameMetadata(BufferedReadStream stream, List frameMetadata, ref ImageFrameMetadata? previousFrame) { this.ReadImageDescriptor(stream); @@ -632,6 +712,11 @@ internal sealed class GifDecoderCore : ImageDecoderCore this.currentLocalColorTable ??= this.configuration.MemoryAllocator.Allocate(768, AllocationOptions.Clean); stream.Read(this.currentLocalColorTable.GetSpan()[..length]); } + else + { + this.currentLocalColorTable = null; + this.currentLocalColorTableSize = 0; + } // Skip the frame indices. Pixels length + mincode size. // The gif format does not tell us the length of the compressed data beforehand. @@ -649,6 +734,8 @@ internal sealed class GifDecoderCore : ImageDecoderCore // Skip any remaining blocks SkipBlock(stream); + + return !this.imageDescriptor.LocalColorTableFlag; } /// @@ -656,7 +743,9 @@ internal sealed class GifDecoderCore : ImageDecoderCore /// /// The pixel format. /// The frame. - private void RestoreToBackground(ImageFrame frame) + /// The background color. + /// Whether the background is transparent. + private void RestoreToBackground(ImageFrame frame, TPixel background, bool transparent) where TPixel : unmanaged, IPixel { if (this.restoreArea is null) @@ -666,7 +755,14 @@ internal sealed class GifDecoderCore : ImageDecoderCore Rectangle interest = Rectangle.Intersect(frame.Bounds, this.restoreArea.Value); Buffer2DRegion pixelRegion = frame.PixelBuffer.GetRegion(interest); - pixelRegion.Clear(); + if (transparent) + { + pixelRegion.Clear(); + } + else + { + pixelRegion.Fill(background); + } this.restoreArea = null; } @@ -775,7 +871,9 @@ internal sealed class GifDecoderCore : ImageDecoderCore } } - this.gifMetadata.BackgroundColorIndex = this.logicalScreenDescriptor.BackgroundColorIndex; + byte index = this.logicalScreenDescriptor.BackgroundColorIndex; + this.backgroundColorIndex = index; + this.gifMetadata.BackgroundColorIndex = index; } private unsafe struct ScratchBuffer diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index 797e825dc4..43af476f2a 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs @@ -9,7 +9,6 @@ using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Metadata; using SixLabors.ImageSharp.Metadata.Profiles.Xmp; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Quantization; namespace SixLabors.ImageSharp.Formats.Gif; @@ -19,6 +18,8 @@ namespace SixLabors.ImageSharp.Formats.Gif; /// internal sealed class GifEncoderCore { + private readonly GifEncoder encoder; + /// /// Used for allocating memory during processing operations. /// @@ -34,16 +35,6 @@ internal sealed class GifEncoderCore /// private readonly bool skipMetadata; - /// - /// The quantizer used to generate the color palette. - /// - private IQuantizer? quantizer; - - /// - /// Whether the quantizer was supplied via options. - /// - private readonly bool hasQuantizer; - /// /// The color table mode: Global or local. /// @@ -67,6 +58,9 @@ internal sealed class GifEncoderCore /// private readonly ushort? repeatCount; + /// + /// The transparent color mode. + /// private readonly TransparentColorMode transparentColorMode; /// @@ -78,9 +72,8 @@ internal sealed class GifEncoderCore { this.configuration = configuration; this.memoryAllocator = configuration.MemoryAllocator; + this.encoder = encoder; this.skipMetadata = encoder.SkipMetadata; - this.quantizer = encoder.Quantizer; - this.hasQuantizer = encoder.Quantizer is not null; this.colorTableMode = encoder.ColorTableMode; this.pixelSamplingStrategy = encoder.PixelSamplingStrategy; this.backgroundColor = encoder.BackgroundColor; @@ -104,70 +97,76 @@ internal sealed class GifEncoderCore GifMetadata gifMetadata = image.Metadata.CloneGifMetadata(); this.colorTableMode ??= gifMetadata.ColorTableMode; bool useGlobalTable = this.colorTableMode == FrameColorTableMode.Global; - - // Quantize the first image frame returning a palette. - IndexedImageFrame? quantized = null; + bool useGlobalTableForFirstFrame = useGlobalTable; // Work out if there is an explicit transparent index set for the frame. We use that to ensure the // correct value is set for the background index when quantizing. GifFrameMetadata frameMetadata = GetGifFrameMetadata(image.Frames.RootFrame, -1); + if (frameMetadata.ColorTableMode == FrameColorTableMode.Local) + { + useGlobalTableForFirstFrame = false; + } + + // Quantize the first image frame returning a palette. + IndexedImageFrame? quantized = null; + IQuantizer? globalQuantizer = this.encoder.Quantizer; + TransparentColorMode mode = this.transparentColorMode; - if (this.quantizer is null) + // Create a new quantizer options instance augmenting the transparent color mode to match the encoder. + QuantizerOptions options = (this.encoder.Quantizer?.Options ?? new()).DeepClone(o => o.TransparentColorMode = mode); + + if (globalQuantizer is null) { // Is this a gif with color information. If so use that, otherwise use octree. if (gifMetadata.ColorTableMode == FrameColorTableMode.Global && gifMetadata.GlobalColorTable?.Length > 0) { - // We avoid dithering by default to preserve the original colors. int transparencyIndex = GetTransparentIndex(quantized, frameMetadata); if (transparencyIndex >= 0 || gifMetadata.GlobalColorTable.Value.Length < 256) { - this.quantizer = new PaletteQuantizer(gifMetadata.GlobalColorTable.Value, new() { Dither = null }, transparencyIndex); + // We avoid dithering by default to preserve the original colors. + globalQuantizer = new PaletteQuantizer(gifMetadata.GlobalColorTable.Value, options.DeepClone(o => o.Dither = null)); } else { - this.quantizer = KnownQuantizers.Octree; + globalQuantizer = new OctreeQuantizer(options); } } else { - this.quantizer = KnownQuantizers.Octree; + globalQuantizer = new OctreeQuantizer(options); } } - // Quantize the first frame. Checking to see whether we can clear the transparent pixels - // to allow for a smaller color palette and encoded result. - using (IQuantizer frameQuantizer = this.quantizer.CreatePixelSpecificQuantizer(this.configuration)) - { - ImageFrame? clonedFrame = null; - Configuration configuration = this.configuration; - TransparentColorMode mode = this.transparentColorMode; - IPixelSamplingStrategy strategy = this.pixelSamplingStrategy; - if (EncodingUtilities.ShouldClearTransparentPixels(mode)) - { - clonedFrame = image.Frames.RootFrame.Clone(); - - GifFrameMetadata frameMeta = clonedFrame.Metadata.GetGifMetadata(); - Color background = frameMeta.DisposalMode == FrameDisposalMode.RestoreToBackground - ? this.backgroundColor ?? Color.Transparent - : Color.Transparent; - - EncodingUtilities.ClearTransparentPixels(clonedFrame, background); - } - - ImageFrame encodingFrame = clonedFrame ?? image.Frames.RootFrame; + // Quantize the first frame. + IPixelSamplingStrategy strategy = this.pixelSamplingStrategy; + ImageFrame encodingFrame = image.Frames.RootFrame; + if (useGlobalTableForFirstFrame) + { + using IQuantizer firstFrameQuantizer = globalQuantizer.CreatePixelSpecificQuantizer(this.configuration, options); if (useGlobalTable) { - frameQuantizer.BuildPalette(configuration, mode, strategy, image); - quantized = frameQuantizer.QuantizeFrame(encodingFrame, image.Bounds); + firstFrameQuantizer.BuildPalette(strategy, image); } else { - frameQuantizer.BuildPalette(configuration, mode, strategy, encodingFrame); - quantized = frameQuantizer.QuantizeFrame(encodingFrame, image.Bounds); + firstFrameQuantizer.BuildPalette(strategy, encodingFrame); } - clonedFrame?.Dispose(); + quantized = firstFrameQuantizer.QuantizeFrame(encodingFrame, encodingFrame.Bounds); + } + else + { + quantized = this.QuantizeFrameAndUpdateMetadata( + encodingFrame, + globalQuantizer, + default, + encodingFrame.Bounds, + frameMetadata, + true, + false, + frameMetadata.HasTransparency ? frameMetadata.TransparencyIndex : -1, + Color.Transparent); } // Write the header. @@ -181,6 +180,7 @@ internal sealed class GifEncoderCore frameMetadata.TransparencyIndex = ClampIndex(derivedTransparencyIndex); } + // TODO: We should be checking the metadata here also I think? if (!TryGetBackgroundIndex(quantized, this.backgroundColor, out byte backgroundIndex)) { backgroundIndex = derivedTransparencyIndex >= 0 @@ -216,13 +216,18 @@ internal sealed class GifEncoderCore // Capture the global palette for reuse on subsequent frames and cleanup the quantized frame. TPixel[] globalPalette = image.Frames.Count == 1 ? [] : quantized.Palette.ToArray(); - this.EncodeAdditionalFrames( - stream, - image, - globalPalette, - derivedTransparencyIndex, - frameMetadata.DisposalMode, - cancellationToken); + if (image.Frames.Count > 1) + { + using PaletteQuantizer globalFrameQuantizer = new(this.configuration, globalQuantizer.Options, quantized.Palette.ToArray()); + this.EncodeAdditionalFrames( + stream, + image, + globalQuantizer, + globalFrameQuantizer, + derivedTransparencyIndex, + frameMetadata.DisposalMode, + cancellationToken); + } } finally { @@ -248,69 +253,43 @@ internal sealed class GifEncoderCore private void EncodeAdditionalFrames( Stream stream, Image image, - ReadOnlyMemory globalPalette, + IQuantizer globalQuantizer, + PaletteQuantizer globalFrameQuantizer, int globalTransparencyIndex, FrameDisposalMode previousDisposalMode, CancellationToken cancellationToken) where TPixel : unmanaged, IPixel { - if (image.Frames.Count == 1) - { - return; - } - - PaletteQuantizer paletteQuantizer = default; - bool hasPaletteQuantizer = false; - // Store the first frame as a reference for de-duplication comparison. ImageFrame previousFrame = image.Frames.RootFrame; // This frame is reused to store de-duplicated pixel buffers. using ImageFrame encodingFrame = new(previousFrame.Configuration, previousFrame.Size); - try + for (int i = 1; i < image.Frames.Count; i++) { - for (int i = 1; i < image.Frames.Count; i++) - { - cancellationToken.ThrowIfCancellationRequested(); + cancellationToken.ThrowIfCancellationRequested(); - // Gather the metadata for this frame. - ImageFrame currentFrame = image.Frames[i]; - ImageFrame? nextFrame = i < image.Frames.Count - 1 ? image.Frames[i + 1] : null; - GifFrameMetadata gifMetadata = GetGifFrameMetadata(currentFrame, globalTransparencyIndex); - bool useLocal = this.colorTableMode == FrameColorTableMode.Local || (gifMetadata.ColorTableMode == FrameColorTableMode.Local); + // Gather the metadata for this frame. + ImageFrame currentFrame = image.Frames[i]; + ImageFrame? nextFrame = i < image.Frames.Count - 1 ? image.Frames[i + 1] : null; + GifFrameMetadata gifMetadata = GetGifFrameMetadata(currentFrame, globalTransparencyIndex); + bool useLocal = this.colorTableMode == FrameColorTableMode.Local || (gifMetadata.ColorTableMode == FrameColorTableMode.Local); - if (!useLocal && !hasPaletteQuantizer && i > 0) - { - // The palette quantizer can reuse the same global pixel map across multiple frames since the palette is unchanging. - // This allows a reduction of memory usage across multi-frame gifs using a global palette - // and also allows use to reuse the cache from previous runs. - int transparencyIndex = gifMetadata.HasTransparency ? gifMetadata.TransparencyIndex : -1; - paletteQuantizer = new(this.configuration, this.quantizer!.Options, globalPalette, transparencyIndex); - hasPaletteQuantizer = true; - } + this.EncodeAdditionalFrame( + stream, + previousFrame, + currentFrame, + nextFrame, + encodingFrame, + globalQuantizer, + globalFrameQuantizer, + useLocal, + gifMetadata, + previousDisposalMode); - this.EncodeAdditionalFrame( - stream, - previousFrame, - currentFrame, - nextFrame, - encodingFrame, - useLocal, - gifMetadata, - paletteQuantizer, - previousDisposalMode); - - previousFrame = currentFrame; - previousDisposalMode = gifMetadata.DisposalMode; - } - } - finally - { - if (hasPaletteQuantizer) - { - paletteQuantizer.Dispose(); - } + previousFrame = currentFrame; + previousDisposalMode = gifMetadata.DisposalMode; } } @@ -346,9 +325,10 @@ internal sealed class GifEncoderCore ImageFrame currentFrame, ImageFrame? nextFrame, ImageFrame encodingFrame, + IQuantizer globalQuantizer, + PaletteQuantizer globalFrameQuantizer, bool useLocal, GifFrameMetadata metadata, - PaletteQuantizer globalPaletteQuantizer, FrameDisposalMode previousDisposalMode) where TPixel : unmanaged, IPixel { @@ -375,19 +355,16 @@ internal sealed class GifEncoderCore background, true); - if (EncodingUtilities.ShouldClearTransparentPixels(this.transparentColorMode)) - { - EncodingUtilities.ClearTransparentPixels(encodingFrame, background); - } - - using IndexedImageFrame quantized = this.QuantizeAdditionalFrameAndUpdateMetadata( + using IndexedImageFrame quantized = this.QuantizeFrameAndUpdateMetadata( encodingFrame, + globalQuantizer, + globalFrameQuantizer, bounds, metadata, useLocal, - globalPaletteQuantizer, difference, - transparencyIndex); + transparencyIndex, + background); this.WriteGraphicalControlExtension(metadata, stream); @@ -403,14 +380,16 @@ internal sealed class GifEncoderCore this.WriteImageData(indices, stream, quantized.Palette.Length, metadata.TransparencyIndex); } - private IndexedImageFrame QuantizeAdditionalFrameAndUpdateMetadata( + private IndexedImageFrame QuantizeFrameAndUpdateMetadata( ImageFrame encodingFrame, + IQuantizer globalQuantizer, + PaletteQuantizer globalFrameQuantizer, Rectangle bounds, GifFrameMetadata metadata, bool useLocal, - PaletteQuantizer globalPaletteQuantizer, bool hasDuplicates, - int transparencyIndex) + int transparencyIndex, + Color transparentColor) where TPixel : unmanaged, IPixel { IndexedImageFrame quantized; @@ -434,15 +413,19 @@ internal sealed class GifEncoderCore transparencyIndex = palette.Length; metadata.TransparencyIndex = ClampIndex(transparencyIndex); - PaletteQuantizer quantizer = new(palette, new() { Dither = null }, transparencyIndex); - using IQuantizer frameQuantizer = quantizer.CreatePixelSpecificQuantizer(this.configuration, quantizer.Options); + QuantizerOptions options = globalQuantizer.Options.DeepClone(o => + { + o.MaxColors = palette.Length; + o.Dither = null; + }); + PaletteQuantizer quantizer = new(palette, options, transparencyIndex, transparentColor); + using IQuantizer frameQuantizer = quantizer.CreatePixelSpecificQuantizer(this.configuration); quantized = frameQuantizer.BuildPaletteAndQuantizeFrame(encodingFrame, bounds); } else { // We must quantize the frame to generate a local color table. - IQuantizer quantizer = this.hasQuantizer ? this.quantizer! : KnownQuantizers.Octree; - using IQuantizer frameQuantizer = quantizer.CreatePixelSpecificQuantizer(this.configuration, quantizer.Options); + using IQuantizer frameQuantizer = globalQuantizer.CreatePixelSpecificQuantizer(this.configuration); quantized = frameQuantizer.BuildPaletteAndQuantizeFrame(encodingFrame, bounds); // The transparency index derived by the quantizer will differ from the index @@ -454,7 +437,12 @@ internal sealed class GifEncoderCore else { // Just use the local palette. - PaletteQuantizer quantizer = new(palette, new() { Dither = null }, transparencyIndex); + QuantizerOptions paletteOptions = globalQuantizer.Options.DeepClone(o => + { + o.MaxColors = palette.Length; + o.Dither = null; + }); + PaletteQuantizer quantizer = new(palette, paletteOptions, transparencyIndex, transparentColor); using IQuantizer frameQuantizer = quantizer.CreatePixelSpecificQuantizer(this.configuration, quantizer.Options); quantized = frameQuantizer.BuildPaletteAndQuantizeFrame(encodingFrame, bounds); } @@ -462,8 +450,7 @@ internal sealed class GifEncoderCore else { // We must quantize the frame to generate a local color table. - IQuantizer quantizer = this.hasQuantizer ? this.quantizer! : KnownQuantizers.Octree; - using IQuantizer frameQuantizer = quantizer.CreatePixelSpecificQuantizer(this.configuration, quantizer.Options); + using IQuantizer frameQuantizer = globalQuantizer.CreatePixelSpecificQuantizer(this.configuration); quantized = frameQuantizer.BuildPaletteAndQuantizeFrame(encodingFrame, bounds); // The transparency index derived by the quantizer might differ from the index @@ -486,18 +473,19 @@ internal sealed class GifEncoderCore else { // Quantize the image using the global palette. - // Individual frames, though using the shared palette, can use a different transparent index to represent transparency. + // Individual frames, though using the shared palette, can use a different transparent index + // to represent transparency. // A difference was captured but the metadata does not have transparency. if (hasDuplicates && !metadata.HasTransparency) { metadata.HasTransparency = true; - transparencyIndex = globalPaletteQuantizer.Palette.Length; + transparencyIndex = globalFrameQuantizer.Palette.Length; metadata.TransparencyIndex = ClampIndex(transparencyIndex); } - globalPaletteQuantizer.SetTransparentIndex(transparencyIndex); - quantized = globalPaletteQuantizer.QuantizeFrame(encodingFrame, bounds); + globalFrameQuantizer.SetTransparencyIndex(transparencyIndex, transparentColor.ToPixel()); + quantized = globalFrameQuantizer.QuantizeFrame(encodingFrame, bounds); } return quantized; diff --git a/src/ImageSharp/Formats/Gif/GifFrameMetadata.cs b/src/ImageSharp/Formats/Gif/GifFrameMetadata.cs index 5fe892c656..e1b3354ad2 100644 --- a/src/ImageSharp/Formats/Gif/GifFrameMetadata.cs +++ b/src/ImageSharp/Formats/Gif/GifFrameMetadata.cs @@ -1,7 +1,6 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -using System.Numerics; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Formats.Gif; @@ -77,34 +76,12 @@ public class GifFrameMetadata : IFormatFrameMetadata /// public static GifFrameMetadata FromFormatConnectingFrameMetadata(FormatConnectingFrameMetadata metadata) - { - int index = -1; - const float background = 1f; - if (metadata.ColorTable.HasValue) + => new() { - ReadOnlySpan colorTable = metadata.ColorTable.Value.Span; - for (int i = 0; i < colorTable.Length; i++) - { - Vector4 vector = colorTable[i].ToScaledVector4(); - if (vector.W < background) - { - index = i; - } - } - } - - bool hasTransparency = index >= 0; - - return new() - { - LocalColorTable = metadata.ColorTable, ColorTableMode = metadata.ColorTableMode, FrameDelay = (int)Math.Round(metadata.Duration.TotalMilliseconds / 10), DisposalMode = metadata.DisposalMode, - HasTransparency = hasTransparency, - TransparencyIndex = hasTransparency ? unchecked((byte)index) : byte.MinValue, }; - } /// public FormatConnectingFrameMetadata ToFormatConnectingFrameMetadata() @@ -118,7 +95,6 @@ public class GifFrameMetadata : IFormatFrameMetadata return new() { - ColorTable = this.LocalColorTable, ColorTableMode = this.ColorTableMode, Duration = TimeSpan.FromMilliseconds(this.FrameDelay * 10), DisposalMode = this.DisposalMode, @@ -129,8 +105,7 @@ public class GifFrameMetadata : IFormatFrameMetadata /// public void AfterFrameApply(ImageFrame source, ImageFrame destination) where TPixel : unmanaged, IPixel - { - } + => this.LocalColorTable = null; /// IDeepCloneable IDeepCloneable.DeepClone() => this.DeepClone(); diff --git a/src/ImageSharp/Formats/Gif/GifMetadata.cs b/src/ImageSharp/Formats/Gif/GifMetadata.cs index 517609af45..77f600633b 100644 --- a/src/ImageSharp/Formats/Gif/GifMetadata.cs +++ b/src/ImageSharp/Formats/Gif/GifMetadata.cs @@ -71,37 +71,19 @@ public class GifMetadata : IFormatMetadata /// public static GifMetadata FromFormatConnectingMetadata(FormatConnectingMetadata metadata) - { - int index = 0; - Color background = metadata.BackgroundColor; - if (metadata.ColorTable.HasValue) + => new() { - ReadOnlySpan colorTable = metadata.ColorTable.Value.Span; - for (int i = 0; i < colorTable.Length; i++) - { - if (background != colorTable[i]) - { - continue; - } - - index = i; - break; - } - } - - return new() - { - GlobalColorTable = metadata.ColorTable, + // Do not copy the color table or bit depth. + // This will lead to a mismatch when the image is comprised of frames + // extracted individually from a multi-frame image. ColorTableMode = metadata.ColorTableMode, RepeatCount = metadata.RepeatCount, - BackgroundColorIndex = (byte)Numerics.Clamp(index, 0, 255), }; - } /// public PixelTypeInfo GetPixelTypeInfo() { - int bpp = this.GlobalColorTable.HasValue + int bpp = this.ColorTableMode == FrameColorTableMode.Global && this.GlobalColorTable.HasValue ? Numerics.Clamp(ColorNumerics.GetBitsNeededForColorDepth(this.GlobalColorTable.Value.Length), 1, 8) : 8; @@ -114,27 +96,18 @@ public class GifMetadata : IFormatMetadata /// public FormatConnectingMetadata ToFormatConnectingMetadata() - { - Color color = this.GlobalColorTable.HasValue && this.GlobalColorTable.Value.Span.Length > this.BackgroundColorIndex - ? this.GlobalColorTable.Value.Span[this.BackgroundColorIndex] - : Color.Transparent; - - return new() + => new() { AnimateRootFrame = true, - BackgroundColor = color, - ColorTable = this.GlobalColorTable, ColorTableMode = this.ColorTableMode, PixelTypeInfo = this.GetPixelTypeInfo(), RepeatCount = this.RepeatCount, }; - } /// public void AfterImageApply(Image destination) where TPixel : unmanaged, IPixel - { - } + => this.GlobalColorTable = null; /// IDeepCloneable IDeepCloneable.DeepClone() => this.DeepClone(); diff --git a/src/ImageSharp/Formats/IAnimatedImageEncoder.cs b/src/ImageSharp/Formats/IAnimatedImageEncoder.cs index d2c3ad6907..26f2114df2 100644 --- a/src/ImageSharp/Formats/IAnimatedImageEncoder.cs +++ b/src/ImageSharp/Formats/IAnimatedImageEncoder.cs @@ -14,17 +14,17 @@ public interface IAnimatedImageEncoder /// as well as the transparent pixels of the first frame. /// The background color is also used when a frame disposal mode is . /// - Color? BackgroundColor { get; } + public Color? BackgroundColor { get; } /// /// Gets the number of times any animation is repeated in supported encoders. /// - ushort? RepeatCount { get; } + public ushort? RepeatCount { get; } /// /// Gets a value indicating whether the root frame is shown as part of the animated sequence in supported encoders. /// - bool? AnimateRootFrame { get; } + public bool? AnimateRootFrame { get; } } /// diff --git a/src/ImageSharp/Formats/IFormatFrameMetadata.cs b/src/ImageSharp/Formats/IFormatFrameMetadata.cs index 20f27d050c..261cc12639 100644 --- a/src/ImageSharp/Formats/IFormatFrameMetadata.cs +++ b/src/ImageSharp/Formats/IFormatFrameMetadata.cs @@ -14,7 +14,7 @@ public interface IFormatFrameMetadata : IDeepCloneable /// Converts the metadata to a instance. /// /// The . - FormatConnectingFrameMetadata ToFormatConnectingFrameMetadata(); + public FormatConnectingFrameMetadata ToFormatConnectingFrameMetadata(); /// /// This method is called after a process has been applied to the image frame. @@ -22,7 +22,7 @@ public interface IFormatFrameMetadata : IDeepCloneable /// The type of pixel format. /// The source image frame. /// The destination image frame. - void AfterFrameApply(ImageFrame source, ImageFrame destination) + public void AfterFrameApply(ImageFrame source, ImageFrame destination) where TPixel : unmanaged, IPixel; } @@ -39,6 +39,6 @@ public interface IFormatFrameMetadata : IFormatFrameMetadata, IDeepClonea /// The . /// The . #pragma warning disable CA1000 // Do not declare static members on generic types - static abstract TSelf FromFormatConnectingFrameMetadata(FormatConnectingFrameMetadata metadata); + public static abstract TSelf FromFormatConnectingFrameMetadata(FormatConnectingFrameMetadata metadata); #pragma warning restore CA1000 // Do not declare static members on generic types } diff --git a/src/ImageSharp/Formats/IFormatMetadata.cs b/src/ImageSharp/Formats/IFormatMetadata.cs index a351431c94..3142b465cb 100644 --- a/src/ImageSharp/Formats/IFormatMetadata.cs +++ b/src/ImageSharp/Formats/IFormatMetadata.cs @@ -14,20 +14,20 @@ public interface IFormatMetadata : IDeepCloneable /// Converts the metadata to a instance. /// /// The pixel type info. - PixelTypeInfo GetPixelTypeInfo(); + public PixelTypeInfo GetPixelTypeInfo(); /// /// Converts the metadata to a instance. /// /// The . - FormatConnectingMetadata ToFormatConnectingMetadata(); + public FormatConnectingMetadata ToFormatConnectingMetadata(); /// /// This method is called after a process has been applied to the image. /// /// The type of pixel format. /// The destination image . - void AfterImageApply(Image destination) + public void AfterImageApply(Image destination) where TPixel : unmanaged, IPixel; } @@ -44,6 +44,6 @@ public interface IFormatMetadata : IFormatMetadata, IDeepCloneable /// The . /// The . #pragma warning disable CA1000 // Do not declare static members on generic types - static abstract TSelf FromFormatConnectingMetadata(FormatConnectingMetadata metadata); + public static abstract TSelf FromFormatConnectingMetadata(FormatConnectingMetadata metadata); #pragma warning restore CA1000 // Do not declare static members on generic types } diff --git a/src/ImageSharp/Formats/IQuantizingImageEncoder.cs b/src/ImageSharp/Formats/IQuantizingImageEncoder.cs index 5edf6e40e9..1ce2aa0918 100644 --- a/src/ImageSharp/Formats/IQuantizingImageEncoder.cs +++ b/src/ImageSharp/Formats/IQuantizingImageEncoder.cs @@ -13,12 +13,12 @@ public interface IQuantizingImageEncoder /// /// Gets the quantizer used to generate the color palette. /// - IQuantizer? Quantizer { get; } + public IQuantizer? Quantizer { get; } /// /// Gets the used for quantization when building color palettes. /// - IPixelSamplingStrategy PixelSamplingStrategy { get; } + public IPixelSamplingStrategy PixelSamplingStrategy { get; } } /// diff --git a/src/ImageSharp/Formats/ISpecializedDecoderOptions.cs b/src/ImageSharp/Formats/ISpecializedDecoderOptions.cs index e0a4c9b62c..881b5bcd44 100644 --- a/src/ImageSharp/Formats/ISpecializedDecoderOptions.cs +++ b/src/ImageSharp/Formats/ISpecializedDecoderOptions.cs @@ -11,5 +11,5 @@ public interface ISpecializedDecoderOptions /// /// Gets the general decoder options. /// - DecoderOptions GeneralOptions { get; init; } + public DecoderOptions GeneralOptions { get; init; } } diff --git a/src/ImageSharp/Formats/Ico/IcoFrameMetadata.cs b/src/ImageSharp/Formats/Ico/IcoFrameMetadata.cs index 62aa705cbe..31f65133e6 100644 --- a/src/ImageSharp/Formats/Ico/IcoFrameMetadata.cs +++ b/src/ImageSharp/Formats/Ico/IcoFrameMetadata.cs @@ -96,8 +96,7 @@ public class IcoFrameMetadata : IFormatFrameMetadata BmpBitsPerPixel = bbpp, Compression = compression, EncodingWidth = ClampEncodingDimension(metadata.EncodingWidth), - EncodingHeight = ClampEncodingDimension(metadata.EncodingHeight), - ColorTable = compression == IconFrameCompression.Bmp ? metadata.ColorTable : null + EncodingHeight = ClampEncodingDimension(metadata.EncodingHeight) }; } @@ -106,7 +105,6 @@ public class IcoFrameMetadata : IFormatFrameMetadata => new() { PixelTypeInfo = this.GetPixelTypeInfo(), - ColorTable = this.ColorTable, EncodingWidth = this.EncodingWidth, EncodingHeight = this.EncodingHeight }; @@ -119,6 +117,7 @@ public class IcoFrameMetadata : IFormatFrameMetadata float ratioY = destination.Height / (float)source.Height; this.EncodingWidth = ScaleEncodingDimension(this.EncodingWidth, destination.Width, ratioX); this.EncodingHeight = ScaleEncodingDimension(this.EncodingHeight, destination.Height, ratioY); + this.ColorTable = null; } /// diff --git a/src/ImageSharp/Formats/Ico/IcoMetadata.cs b/src/ImageSharp/Formats/Ico/IcoMetadata.cs index a6c2704b31..f8c2ff40f2 100644 --- a/src/ImageSharp/Formats/Ico/IcoMetadata.cs +++ b/src/ImageSharp/Formats/Ico/IcoMetadata.cs @@ -71,8 +71,7 @@ public class IcoMetadata : IFormatMetadata return new IcoMetadata { BmpBitsPerPixel = bbpp, - Compression = compression, - ColorTable = compression == IconFrameCompression.Bmp ? metadata.ColorTable : null + Compression = compression }; } @@ -145,15 +144,13 @@ public class IcoMetadata : IFormatMetadata EncodingType = this.Compression == IconFrameCompression.Bmp && this.BmpBitsPerPixel <= BmpBitsPerPixel.Bit8 ? EncodingType.Lossy : EncodingType.Lossless, - PixelTypeInfo = this.GetPixelTypeInfo(), - ColorTable = this.ColorTable + PixelTypeInfo = this.GetPixelTypeInfo() }; /// public void AfterImageApply(Image destination) where TPixel : unmanaged, IPixel - { - } + => this.ColorTable = null; /// IDeepCloneable IDeepCloneable.DeepClone() => this.DeepClone(); diff --git a/src/ImageSharp/Formats/Icon/IconEncoderCore.cs b/src/ImageSharp/Formats/Icon/IconEncoderCore.cs index 03e01f912f..76b14832ae 100644 --- a/src/ImageSharp/Formats/Icon/IconEncoderCore.cs +++ b/src/ImageSharp/Formats/Icon/IconEncoderCore.cs @@ -120,17 +120,17 @@ internal abstract class IconEncoderCore this.entries = this.iconFileType switch { IconFileType.ICO => - image.Frames.Select(i => + [.. image.Frames.Select(i => { IcoFrameMetadata metadata = i.Metadata.GetIcoMetadata(); return new EncodingFrameMetadata(metadata.Compression, metadata.BmpBitsPerPixel, metadata.ColorTable, metadata.ToIconDirEntry(i.Size)); - }).ToArray(), + })], IconFileType.CUR => - image.Frames.Select(i => + [.. image.Frames.Select(i => { CurFrameMetadata metadata = i.Metadata.GetCurMetadata(); return new EncodingFrameMetadata(metadata.Compression, metadata.BmpBitsPerPixel, metadata.ColorTable, metadata.ToIconDirEntry(i.Size)); - }).ToArray(), + })], _ => throw new NotSupportedException(), }; } @@ -149,9 +149,15 @@ internal abstract class IconEncoderCore if (metadata.ColorTable is null) { + int count = metadata.Entry.ColorCount; + if (count == 0) + { + count = 256; + } + return new WuQuantizer(new() { - MaxColors = metadata.Entry.ColorCount + MaxColors = count }); } diff --git a/src/ImageSharp/Formats/ImageDecoder.cs b/src/ImageSharp/Formats/ImageDecoder.cs index e58cd6a6de..dd148dfedd 100644 --- a/src/ImageSharp/Formats/ImageDecoder.cs +++ b/src/ImageSharp/Formats/ImageDecoder.cs @@ -46,10 +46,10 @@ public abstract class ImageDecoder : IImageDecoder where TPixel : unmanaged, IPixel { Image image = await WithSeekableMemoryStreamAsync( - options, - stream, - (s, ct) => this.Decode(options, s, ct), - cancellationToken).ConfigureAwait(false); + options, + stream, + (s, ct) => this.Decode(options, s, ct), + cancellationToken).ConfigureAwait(false); this.SetDecoderFormat(options.Configuration, image); diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index 484241d52f..b0ec73d2a1 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -1086,7 +1086,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore { PixelBlender blender = PixelOperations.Instance.GetPixelBlender(PixelColorBlendingMode.Normal, PixelAlphaCompositionMode.SrcOver); - blender.Blend(this.configuration, destination, destination, rowSpan, 1f); + blender.Blend(this.configuration, destination, destination, rowSpan, 1F); } } finally @@ -1208,7 +1208,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore { PixelBlender blender = PixelOperations.Instance.GetPixelBlender(PixelColorBlendingMode.Normal, PixelAlphaCompositionMode.SrcOver); - blender.Blend(this.configuration, destination, destination, rowSpan, 1f); + blender.Blend(this.configuration, destination, destination, rowSpan, 1F); } } finally @@ -1866,6 +1866,9 @@ internal sealed class PngDecoderCore : ImageDecoderCore return false; } + // Capture the current position so we can revert back to it if we fail to read a valid chunk. + long position = this.currentStream.Position; + if (!this.TryReadChunkLength(buffer, out int length)) { // IEND @@ -1884,7 +1887,48 @@ internal sealed class PngDecoderCore : ImageDecoderCore } } - PngChunkType type = this.ReadChunkType(buffer); + PngChunkType type; + + // Loop until we get a chunk type that is valid. + while (true) + { + type = this.ReadChunkType(buffer); + if (!IsValidChunkType(type)) + { + // The chunk type is invalid. + // Revert back to the next byte past the previous position and try again. + this.currentStream.Position = ++position; + + // If we are now at the end of the stream, we're done. + if (this.currentStream.Position >= this.currentStream.Length) + { + chunk = default; + return false; + } + + // Read the next chunk’s length. + if (!this.TryReadChunkLength(buffer, out length)) + { + chunk = default; + return false; + } + + while (length < 0) + { + if (!this.TryReadChunkLength(buffer, out length)) + { + chunk = default; + return false; + } + } + + // Continue to try reading the next chunk. + continue; + } + + // We have a valid chunk type. + break; + } // If we're reading color metadata only we're only interested in the IHDR and tRNS chunks. // We can skip most other chunk data in the stream for better performance. @@ -1901,7 +1945,7 @@ internal sealed class PngDecoderCore : ImageDecoderCore // A chunk might report a length that exceeds the length of the stream. // Take the minimum of the two values to ensure we don't read past the end of the stream. - long position = this.currentStream.Position; + position = this.currentStream.Position; chunk = new PngChunk( length: (int)Math.Min(length, this.currentStream.Length - position), type: type, @@ -1919,6 +1963,32 @@ internal sealed class PngDecoderCore : ImageDecoderCore return true; } + /// + /// Determines whether the 4-byte chunk type is valid (all ASCII letters). + /// + /// The chunk type. + [MethodImpl(InliningOptions.ShortMethod)] + private static bool IsValidChunkType(PngChunkType type) + { + uint value = (uint)type; + byte b0 = (byte)(value >> 24); + byte b1 = (byte)(value >> 16); + byte b2 = (byte)(value >> 8); + byte b3 = (byte)value; + return IsAsciiLetter(b0) && IsAsciiLetter(b1) && IsAsciiLetter(b2) && IsAsciiLetter(b3); + } + + /// + /// Returns a value indicating whether the given byte is an ASCII letter. + /// + /// The byte to check. + /// + /// if the byte is an ASCII letter; otherwise, . + /// + [MethodImpl(InliningOptions.ShortMethod)] + private static bool IsAsciiLetter(byte b) + => (b >= (byte)'A' && b <= (byte)'Z') || (b >= (byte)'a' && b <= (byte)'z'); + /// /// Validates the png chunk. /// diff --git a/src/ImageSharp/Formats/Png/PngEncoder.cs b/src/ImageSharp/Formats/Png/PngEncoder.cs index 63e675b505..b6031c1640 100644 --- a/src/ImageSharp/Formats/Png/PngEncoder.cs +++ b/src/ImageSharp/Formats/Png/PngEncoder.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -using SixLabors.ImageSharp.Processing.Processors.Quantization; - namespace SixLabors.ImageSharp.Formats.Png; /// @@ -10,16 +8,6 @@ namespace SixLabors.ImageSharp.Formats.Png; /// public class PngEncoder : QuantizingAnimatedImageEncoder { - /// - /// Initializes a new instance of the class. - /// - public PngEncoder() - - // Hack. TODO: Investigate means to fix/optimize the Wu quantizer. - // The Wu quantizer does not handle the default sampling strategy well for some larger images. - // It's expensive and the results are not better than the extensive strategy. - => this.PixelSamplingStrategy = new ExtensivePixelSamplingStrategy(); - /// /// Gets the number of bits per sample or per palette index (not per pixel). /// Not all values are allowed for all values. @@ -53,11 +41,6 @@ public class PngEncoder : QuantizingAnimatedImageEncoder /// The gamma value of the image. public float? Gamma { get; init; } - /// - /// Gets the transparency threshold. - /// - public byte Threshold { get; init; } = byte.MaxValue; - /// /// Gets a value indicating whether this instance should write an Adam7 interlaced image. /// diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index ea36d9fe1e..e9b76522c9 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -3,8 +3,8 @@ using System.Buffers; using System.Buffers.Binary; +using System.Diagnostics.CodeAnalysis; using System.IO.Hashing; -using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Intrinsics; @@ -119,18 +119,13 @@ internal sealed class PngEncoderCore : IDisposable /// private IQuantizer? quantizer; - /// - /// Any explicit quantized transparent index provided by the background color. - /// - private int derivedTransparencyIndex = -1; - /// /// The default background color of the canvas when animating. /// This color may be used to fill the unused space on the canvas around the frames, /// as well as the transparent pixels of the first frame. /// The background color is also used when a frame disposal mode is . /// - private readonly Color? backgroundColor; + private Color? backgroundColor; /// /// The number of times any animation is repeated. @@ -158,7 +153,6 @@ internal sealed class PngEncoderCore : IDisposable this.memoryAllocator = configuration.MemoryAllocator; this.encoder = encoder; this.quantizer = encoder.Quantizer; - this.backgroundColor = encoder.BackgroundColor; this.repeatCount = encoder.RepeatCount; this.animateRootFrame = encoder.AnimateRootFrame; } @@ -187,74 +181,95 @@ internal sealed class PngEncoderCore : IDisposable ImageFrame? clonedFrame = null; ImageFrame currentFrame = image.Frames.RootFrame; - int currentFrameIndex = 0; + IndexedImageFrame? quantized = null; + PaletteQuantizer? paletteQuantizer = null; + Buffer2DRegion currentFrameRegion = currentFrame.PixelBuffer.GetRegion(); - bool clearTransparency = EncodingUtilities.ShouldClearTransparentPixels(this.encoder.TransparentColorMode); - if (clearTransparency) + try { - currentFrame = clonedFrame = currentFrame.Clone(); - EncodingUtilities.ClearTransparentPixels(currentFrame, Color.Transparent); - } + int currentFrameIndex = 0; - // Do not move this. We require an accurate bit depth for the header chunk. - IndexedImageFrame? quantized = this.CreateQuantizedImageAndUpdateBitDepth( - pngMetadata, - currentFrame, - currentFrame.Bounds, - null); - - this.WriteHeaderChunk(stream); - this.WriteGammaChunk(stream); - this.WriteCicpChunk(stream, metadata); - this.WriteColorProfileChunk(stream, metadata); - this.WritePaletteChunk(stream, quantized); - this.WriteTransparencyChunk(stream, pngMetadata); - this.WritePhysicalChunk(stream, metadata); - this.WriteExifChunk(stream, metadata); - this.WriteXmpChunk(stream, metadata); - this.WriteTextChunks(stream, pngMetadata); + bool clearTransparency = EncodingUtilities.ShouldReplaceTransparentPixels(this.encoder.TransparentColorMode); - if (image.Frames.Count > 1) - { - this.WriteAnimationControlChunk( - stream, - (uint)(image.Frames.Count - (pngMetadata.AnimateRootFrame ? 0 : 1)), - this.repeatCount ?? pngMetadata.RepeatCount); - } + // No need to clone when quantizing. The quantizer will do it for us. + // TODO: We should really try to avoid the clone entirely. + if (clearTransparency && this.colorType is not PngColorType.Palette) + { + currentFrame = clonedFrame = currentFrame.Clone(); + currentFrameRegion = currentFrame.PixelBuffer.GetRegion(); + EncodingUtilities.ReplaceTransparentPixels(this.configuration, in currentFrameRegion); + } - // If the first frame isn't animated, write it as usual and skip it when writing animated frames - bool userAnimateRootFrame = this.animateRootFrame == true; - if ((!userAnimateRootFrame && !pngMetadata.AnimateRootFrame) || image.Frames.Count == 1) - { - cancellationToken.ThrowIfCancellationRequested(); - FrameControl frameControl = new((uint)this.width, (uint)this.height); - this.WriteDataChunks(frameControl, currentFrame.PixelBuffer.GetRegion(), quantized, stream, false); - currentFrameIndex++; - } + // Do not move this. We require an accurate bit depth for the header chunk. + quantized = this.CreateQuantizedImageAndUpdateBitDepth( + pngMetadata, + image, + currentFrame, + currentFrame.Bounds, + null); + + this.WriteHeaderChunk(stream); + this.WriteGammaChunk(stream); + this.WriteCicpChunk(stream, metadata); + this.WriteColorProfileChunk(stream, metadata); + this.WritePaletteChunk(stream, quantized); + this.WriteTransparencyChunk(stream, pngMetadata); + this.WritePhysicalChunk(stream, metadata); + this.WriteExifChunk(stream, metadata); + this.WriteXmpChunk(stream, metadata); + this.WriteTextChunks(stream, pngMetadata); + + if (image.Frames.Count > 1) + { + this.WriteAnimationControlChunk( + stream, + (uint)(image.Frames.Count - (pngMetadata.AnimateRootFrame ? 0 : 1)), + this.repeatCount ?? pngMetadata.RepeatCount); + } + + // If the first frame isn't animated, write it as usual and skip it when writing animated frames + bool userAnimateRootFrame = this.animateRootFrame == true; + if ((!userAnimateRootFrame && !pngMetadata.AnimateRootFrame) || image.Frames.Count == 1) + { + cancellationToken.ThrowIfCancellationRequested(); + FrameControl frameControl = new((uint)this.width, (uint)this.height); + this.WriteDataChunks(in frameControl, in currentFrameRegion, quantized, stream, false); + currentFrameIndex++; + } - try - { if (image.Frames.Count > 1) { // Write the first animated frame. currentFrame = image.Frames[currentFrameIndex]; + currentFrameRegion = currentFrame.PixelBuffer.GetRegion(); + PngFrameMetadata frameMetadata = currentFrame.Metadata.GetPngMetadata(); FrameDisposalMode previousDisposal = frameMetadata.DisposalMode; FrameControl frameControl = this.WriteFrameControlChunk(stream, frameMetadata, currentFrame.Bounds, 0); uint sequenceNumber = 1; if (pngMetadata.AnimateRootFrame) { - this.WriteDataChunks(frameControl, currentFrame.PixelBuffer.GetRegion(), quantized, stream, false); + this.WriteDataChunks(in frameControl, in currentFrameRegion, quantized, stream, false); } else { - sequenceNumber += this.WriteDataChunks(frameControl, currentFrame.PixelBuffer.GetRegion(), quantized, stream, true); + sequenceNumber += this.WriteDataChunks(in frameControl, in currentFrameRegion, quantized, stream, true); } currentFrameIndex++; // Capture the global palette for reuse on subsequent frames. - ReadOnlyMemory? previousPalette = quantized?.Palette.ToArray(); + ReadOnlyMemory previousPalette = quantized?.Palette.ToArray(); + + if (!previousPalette.IsEmpty) + { + // Use the previously derived global palette and a shared quantizer to + // quantize the subsequent frames. This allows us to cache the color matching resolution. + paletteQuantizer ??= new( + this.configuration, + this.quantizer!.Options, + previousPalette); + } // Write following frames. ImageFrame previousFrame = image.Frames.RootFrame; @@ -267,13 +282,26 @@ internal sealed class PngEncoderCore : IDisposable cancellationToken.ThrowIfCancellationRequested(); ImageFrame? prev = previousDisposal == FrameDisposalMode.RestoreToBackground ? null : previousFrame; + currentFrame = image.Frames[currentFrameIndex]; + currentFrameRegion = currentFrame.PixelBuffer.GetRegion(); + ImageFrame? nextFrame = currentFrameIndex < image.Frames.Count - 1 ? image.Frames[currentFrameIndex + 1] : null; frameMetadata = currentFrame.Metadata.GetPngMetadata(); - bool blend = frameMetadata.BlendMode == FrameBlendMode.Over; + + // Determine whether to blend the current frame over the existing canvas. + // Blending is applied only when the blend method is 'Over' (source-over blending) + // and when the frame's disposal method is not 'RestoreToPrevious', which indicates that + // the frame should not permanently alter the canvas. + bool blend = frameMetadata.BlendMode == FrameBlendMode.Over + && frameMetadata.DisposalMode != FrameDisposalMode.RestoreToPrevious; + + // Establish the background color for the current frame. + // If the disposal method is 'RestoreToBackground', use the predefined background color; + // otherwise, use transparent, as no explicit background restoration is needed. Color background = frameMetadata.DisposalMode == FrameDisposalMode.RestoreToBackground - ? this.backgroundColor ?? Color.Transparent + ? this.backgroundColor.Value : Color.Transparent; (bool difference, Rectangle bounds) = @@ -286,9 +314,9 @@ internal sealed class PngEncoderCore : IDisposable background, blend); - if (clearTransparency) + if (clearTransparency && this.colorType is not PngColorType.Palette) { - EncodingUtilities.ClearTransparentPixels(encodingFrame, background); + EncodingUtilities.ReplaceTransparentPixels(encodingFrame); } // Each frame control sequence number must be incremented by the number of frame data chunks that follow. @@ -296,8 +324,20 @@ internal sealed class PngEncoderCore : IDisposable // Dispose of previous quantized frame and reassign. quantized?.Dispose(); - quantized = this.CreateQuantizedImageAndUpdateBitDepth(pngMetadata, encodingFrame, bounds, previousPalette); - sequenceNumber += this.WriteDataChunks(frameControl, encodingFrame.PixelBuffer.GetRegion(bounds), quantized, stream, true) + 1; + + quantized = this.CreateQuantizedFrame( + this.encoder, + this.colorType, + this.bitDepth, + pngMetadata, + image, + encodingFrame, + bounds, + paletteQuantizer, + default); + + Buffer2DRegion encodingFrameRegion = encodingFrame.PixelBuffer.GetRegion(bounds); + sequenceNumber += this.WriteDataChunks(in frameControl, in encodingFrameRegion, quantized, stream, true) + 1; previousFrame = currentFrame; previousDisposal = frameMetadata.DisposalMode; @@ -313,6 +353,7 @@ internal sealed class PngEncoderCore : IDisposable // Dispose of allocations from final frame. clonedFrame?.Dispose(); quantized?.Dispose(); + paletteQuantizer?.Dispose(); } } @@ -328,18 +369,35 @@ internal sealed class PngEncoderCore : IDisposable /// /// The type of the pixel. /// The image metadata. - /// The frame to quantize. + /// The image. + /// The current image frame. /// The area of interest within the frame. - /// Any previously derived palette. + /// The quantizer containing any previously derived palette. /// The quantized image. private IndexedImageFrame? CreateQuantizedImageAndUpdateBitDepth( PngMetadata metadata, + Image image, ImageFrame frame, Rectangle bounds, - ReadOnlyMemory? previousPalette) + PaletteQuantizer? paletteQuantizer) where TPixel : unmanaged, IPixel { - IndexedImageFrame? quantized = this.CreateQuantizedFrame(this.encoder, this.colorType, this.bitDepth, metadata, frame, bounds, previousPalette); + PngFrameMetadata frameMetadata = frame.Metadata.GetPngMetadata(); + Color background = frameMetadata.DisposalMode == FrameDisposalMode.RestoreToBackground + ? this.backgroundColor ?? Color.Transparent + : Color.Transparent; + + IndexedImageFrame? quantized = this.CreateQuantizedFrame( + this.encoder, + this.colorType, + this.bitDepth, + metadata, + image, + frame, + bounds, + paletteQuantizer, + background); + this.bitDepth = CalculateBitDepth(this.colorType, this.bitDepth, quantized); return quantized; } @@ -734,11 +792,6 @@ internal sealed class PngEncoderCore : IDisposable byte alpha = rgba.A; Unsafe.Add(ref colorTableRef, (uint)i) = rgba.Rgb; - if (alpha > this.encoder.Threshold) - { - alpha = byte.MaxValue; - } - hasAlpha = hasAlpha || alpha < byte.MaxValue; Unsafe.Add(ref alphaTableRef, (uint)i) = alpha; } @@ -1105,7 +1158,7 @@ internal sealed class PngEncoderCore : IDisposable /// The quantized pixel data. Can be null. /// The stream. /// Is writing fdAT or IDAT. - private uint WriteDataChunks(FrameControl frameControl, Buffer2DRegion frame, IndexedImageFrame? quantized, Stream stream, bool isFrame) + private uint WriteDataChunks(in FrameControl frameControl, in Buffer2DRegion frame, IndexedImageFrame? quantized, Stream stream, bool isFrame) where TPixel : unmanaged, IPixel { byte[] buffer; @@ -1123,12 +1176,12 @@ internal sealed class PngEncoderCore : IDisposable } else { - this.EncodeAdam7Pixels(frame, deflateStream); + this.EncodeAdam7Pixels(in frame, deflateStream); } } else { - this.EncodePixels(frame, quantized, deflateStream); + this.EncodePixels(in frame, quantized, deflateStream); } } @@ -1196,7 +1249,7 @@ internal sealed class PngEncoderCore : IDisposable /// The image frame pixel buffer. /// The quantized pixels. /// The deflate stream. - private void EncodePixels(Buffer2DRegion pixels, IndexedImageFrame? quantized, ZlibDeflateStream deflateStream) + private void EncodePixels(in Buffer2DRegion pixels, IndexedImageFrame? quantized, ZlibDeflateStream deflateStream) where TPixel : unmanaged, IPixel { int bytesPerScanline = this.CalculateScanlineLength(pixels.Width); @@ -1210,7 +1263,8 @@ internal sealed class PngEncoderCore : IDisposable Span attempt = attemptBuffer.GetSpan(); for (int y = 0; y < pixels.Height; y++) { - this.CollectAndFilterPixelRow(pixels.DangerousGetRowSpan(y), ref filter, ref attempt, quantized, y); + ReadOnlySpan rowSpan = pixels.DangerousGetRowSpan(y); + this.CollectAndFilterPixelRow(rowSpan, ref filter, ref attempt, quantized, y); deflateStream.Write(filter); this.SwapScanlineBuffers(); } @@ -1222,7 +1276,7 @@ internal sealed class PngEncoderCore : IDisposable /// The type of the pixel. /// The image frame pixel buffer. /// The deflate stream. - private void EncodeAdam7Pixels(Buffer2DRegion pixels, ZlibDeflateStream deflateStream) + private void EncodeAdam7Pixels(in Buffer2DRegion pixels, ZlibDeflateStream deflateStream) where TPixel : unmanaged, IPixel { for (int pass = 0; pass < 7; pass++) @@ -1258,7 +1312,8 @@ internal sealed class PngEncoderCore : IDisposable // Encode data // Note: quantized parameter not used // Note: row parameter not used - this.CollectAndFilterPixelRow(block, ref filter, ref attempt, null, -1); + ReadOnlySpan blockSpan = block; + this.CollectAndFilterPixelRow(blockSpan, ref filter, ref attempt, null, -1); deflateStream.Write(filter); this.SwapScanlineBuffers(); @@ -1432,6 +1487,7 @@ internal sealed class PngEncoderCore : IDisposable /// The PNG metadata. /// if set to true [use16 bit]. /// The bytes per pixel. + [MemberNotNull(nameof(backgroundColor))] private void SanitizeAndSetEncoderOptions( PngEncoder encoder, PngMetadata pngMetadata, @@ -1473,6 +1529,7 @@ internal sealed class PngEncoderCore : IDisposable this.interlaceMode = encoder.InterlaceMethod ?? pngMetadata.InterlaceMethod; this.chunkFilter = encoder.SkipMetadata ? PngChunkFilter.ExcludeAll : encoder.ChunkFilter ?? PngChunkFilter.None; + this.backgroundColor = encoder.BackgroundColor ?? pngMetadata.TransparentColor ?? Color.Transparent; } /// @@ -1483,17 +1540,21 @@ internal sealed class PngEncoderCore : IDisposable /// The color type. /// The bits per component. /// The image metadata. - /// The frame to quantize. + /// The image. + /// The current image frame. /// The frame area of interest. - /// Any previously derived palette. + /// The quantizer containing any previously derived palette. + /// The background color. private IndexedImageFrame? CreateQuantizedFrame( QuantizingImageEncoder encoder, PngColorType colorType, byte bitDepth, PngMetadata metadata, + Image image, ImageFrame frame, Rectangle bounds, - ReadOnlyMemory? previousPalette) + PaletteQuantizer? paletteQuantizer, + Color backgroundColor) where TPixel : unmanaged, IPixel { if (colorType is not PngColorType.Palette) @@ -1501,55 +1562,59 @@ internal sealed class PngEncoderCore : IDisposable return null; } - if (previousPalette is not null) + if (paletteQuantizer.HasValue) { - // Use the previously derived palette created by quantizing the root frame to quantize the current frame. - using PaletteQuantizer paletteQuantizer = new( - this.configuration, - this.quantizer!.Options, - previousPalette.Value, - this.derivedTransparencyIndex); - paletteQuantizer.BuildPalette(encoder.PixelSamplingStrategy, frame); - return paletteQuantizer.QuantizeFrame(frame, bounds); + return paletteQuantizer.Value.QuantizeFrame(frame, bounds); } // Use the metadata to determine what quantization depth to use if no quantizer has been set. if (this.quantizer is null) { - if (metadata.ColorTable is not null) + if (metadata.ColorTable?.Length > 0) { // We can use the color data from the decoded metadata here. // We avoid dithering by default to preserve the original colors. - ReadOnlySpan palette = metadata.ColorTable.Value.Span; - - // Certain operations perform alpha premultiplication, which can cause the color to change so we - // must search for the transparency index in the palette. - // Transparent pixels are much more likely to be found at the end of a palette. - int index = -1; - for (int i = palette.Length - 1; i >= 0; i--) - { - Vector4 instance = palette[i].ToScaledVector4(); - if (instance.W == 0f) - { - index = i; - break; - } - } - - this.derivedTransparencyIndex = index; - - this.quantizer = new PaletteQuantizer(metadata.ColorTable.Value, new() { Dither = null }, this.derivedTransparencyIndex); + QuantizerOptions options = new() { Dither = null, TransparentColorMode = encoder.TransparentColorMode }; + this.quantizer = new PaletteQuantizer(metadata.ColorTable.Value, options); } else { - this.quantizer = new WuQuantizer(new QuantizerOptions { MaxColors = ColorNumerics.GetColorCountForBitDepth(bitDepth) }); + // Don't use the default transparency threshold for quantization as PNG can handle multiple transparent colors. + // We choose a value that is close to zero so that edge cases causes by lower bit depths for the alpha channel are handled correctly. + QuantizerOptions options = new() + { + TransparencyThreshold = 0, + MaxColors = ColorNumerics.GetColorCountForBitDepth(bitDepth), + TransparentColorMode = encoder.TransparentColorMode + }; + + this.quantizer = new WuQuantizer(options); } } // Create quantized frame returning the palette and set the bit depth. using IQuantizer frameQuantizer = this.quantizer.CreatePixelSpecificQuantizer(frame.Configuration); - frameQuantizer.BuildPalette(encoder.PixelSamplingStrategy, frame); + if (image.Frames.Count > 1) + { + // Encoding animated frames with a global palette requires a transparent pixel in the palette + // since we only encode the delta between frames. To ensure that we have a transparent pixel + // we create a fake frame with a containing only transparent pixels and add it to the palette. + using Buffer2D fake = image.Configuration.MemoryAllocator.Allocate2D(Math.Min(256, image.Width), Math.Min(256, image.Height)); + TPixel backGroundPixel = backgroundColor.ToPixel(); + for (int i = 0; i < fake.Height; i++) + { + fake.DangerousGetRowSpan(i).Fill(backGroundPixel); + } + + Buffer2DRegion fakeRegion = fake.GetRegion(); + frameQuantizer.AddPaletteColors(in fakeRegion); + } + + frameQuantizer.BuildPalette( + encoder.PixelSamplingStrategy, + image); + return frameQuantizer.QuantizeFrame(frame, bounds); } diff --git a/src/ImageSharp/Formats/Png/PngMetadata.cs b/src/ImageSharp/Formats/Png/PngMetadata.cs index 00cba088cb..59ca3b17a0 100644 --- a/src/ImageSharp/Formats/Png/PngMetadata.cs +++ b/src/ImageSharp/Formats/Png/PngMetadata.cs @@ -93,25 +93,6 @@ public class PngMetadata : IFormatMetadata /// public static PngMetadata FromFormatConnectingMetadata(FormatConnectingMetadata metadata) { - // Should the conversion be from a format that uses a 24bit palette entries (gif) - // we need to clone and adjust the color table to allow for transparency. - Color[]? colorTable = metadata.ColorTable?.ToArray(); - if (colorTable != null) - { - for (int i = 0; i < colorTable.Length; i++) - { - ref Color c = ref colorTable[i]; - if (c != metadata.BackgroundColor) - { - continue; - } - - // Png treats background as fully empty - c = Color.Transparent; - break; - } - } - PngColorType color; PixelColorType colorType = metadata.PixelTypeInfo.ColorType; @@ -152,7 +133,6 @@ public class PngMetadata : IFormatMetadata { ColorType = color, BitDepth = bitDepth, - ColorTable = colorTable, RepeatCount = metadata.RepeatCount, }; } @@ -241,7 +221,6 @@ public class PngMetadata : IFormatMetadata public FormatConnectingMetadata ToFormatConnectingMetadata() => new() { - ColorTable = this.ColorTable, ColorTableMode = FrameColorTableMode.Global, PixelTypeInfo = this.GetPixelTypeInfo(), RepeatCount = (ushort)Numerics.Clamp(this.RepeatCount, 0, ushort.MaxValue), @@ -250,8 +229,7 @@ public class PngMetadata : IFormatMetadata /// public void AfterImageApply(Image destination) where TPixel : unmanaged, IPixel - { - } + => this.ColorTable = null; /// IDeepCloneable IDeepCloneable.DeepClone() => this.DeepClone(); diff --git a/src/ImageSharp/Formats/Qoi/QoiEncoderCore.cs b/src/ImageSharp/Formats/Qoi/QoiEncoderCore.cs index 872cec3fd0..a5e1596b37 100644 --- a/src/ImageSharp/Formats/Qoi/QoiEncoderCore.cs +++ b/src/ImageSharp/Formats/Qoi/QoiEncoderCore.cs @@ -90,10 +90,12 @@ internal class QoiEncoderCore ImageFrame? clonedFrame = null; try { - if (EncodingUtilities.ShouldClearTransparentPixels(this.encoder.TransparentColorMode)) + // TODO: Try to avoid cloning the frame if possible. + // We should be cloning individual scanlines instead. + if (EncodingUtilities.ShouldReplaceTransparentPixels(this.encoder.TransparentColorMode)) { clonedFrame = image.Frames.RootFrame.Clone(); - EncodingUtilities.ClearTransparentPixels(clonedFrame, Color.Transparent); + EncodingUtilities.ReplaceTransparentPixels(clonedFrame); } ImageFrame encodingFrame = clonedFrame ?? image.Frames.RootFrame; diff --git a/src/ImageSharp/Formats/SpecializedImageDecoder{T}.cs b/src/ImageSharp/Formats/SpecializedImageDecoder{T}.cs index 59fa59bb97..38bfe817dd 100644 --- a/src/ImageSharp/Formats/SpecializedImageDecoder{T}.cs +++ b/src/ImageSharp/Formats/SpecializedImageDecoder{T}.cs @@ -24,6 +24,7 @@ public abstract class SpecializedImageDecoder : ImageDecoder, ISpecializedIma s => this.Decode(options, s, default)); this.SetDecoderFormat(options.GeneralOptions.Configuration, image); + return image; } @@ -36,6 +37,7 @@ public abstract class SpecializedImageDecoder : ImageDecoder, ISpecializedIma s => this.Decode(options, s, default)); this.SetDecoderFormat(options.GeneralOptions.Configuration, image); + return image; } @@ -50,6 +52,7 @@ public abstract class SpecializedImageDecoder : ImageDecoder, ISpecializedIma cancellationToken).ConfigureAwait(false); this.SetDecoderFormat(options.GeneralOptions.Configuration, image); + return image; } @@ -63,6 +66,7 @@ public abstract class SpecializedImageDecoder : ImageDecoder, ISpecializedIma cancellationToken).ConfigureAwait(false); this.SetDecoderFormat(options.GeneralOptions.Configuration, image); + return image; } diff --git a/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs b/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs index e2ea9c4fe7..a587e19608 100644 --- a/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs +++ b/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs @@ -110,10 +110,12 @@ internal sealed class TgaEncoderCore ImageFrame? clonedFrame = null; try { - if (EncodingUtilities.ShouldClearTransparentPixels(this.transparentColorMode)) + // TODO: Try to avoid cloning the frame if possible. + // We should be cloning individual scanlines instead. + if (EncodingUtilities.ShouldReplaceTransparentPixels(this.transparentColorMode)) { clonedFrame = image.Frames.RootFrame.Clone(); - EncodingUtilities.ClearTransparentPixels(clonedFrame, Color.Transparent); + EncodingUtilities.ReplaceTransparentPixels(clonedFrame); } ImageFrame encodingFrame = clonedFrame ?? image.Frames.RootFrame; diff --git a/src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs b/src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs index e16bf9831c..d7508b02e8 100644 --- a/src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs +++ b/src/ImageSharp/Formats/Tiff/TiffEncoderCore.cs @@ -146,10 +146,12 @@ internal sealed class TiffEncoderCore { cancellationToken.ThrowIfCancellationRequested(); - if (EncodingUtilities.ShouldClearTransparentPixels(this.transparentColorMode)) + // TODO: Try to avoid cloning the frame if possible. + // We should be cloning individual scanlines instead. + if (EncodingUtilities.ShouldReplaceTransparentPixels(this.transparentColorMode)) { clonedFrame = frame.Clone(); - EncodingUtilities.ClearTransparentPixels(clonedFrame, Color.Transparent); + EncodingUtilities.ReplaceTransparentPixels(clonedFrame); } ImageFrame encodingFrame = clonedFrame ?? frame; diff --git a/src/ImageSharp/Formats/TransparentColorMode.cs b/src/ImageSharp/Formats/TransparentColorMode.cs index 39986b5024..fe88c314f2 100644 --- a/src/ImageSharp/Formats/TransparentColorMode.cs +++ b/src/ImageSharp/Formats/TransparentColorMode.cs @@ -4,7 +4,7 @@ namespace SixLabors.ImageSharp.Formats; /// -/// Specifies how transparent pixels should be handled during encoding. +/// Specifies how pixels with transparent alpha components should be handled during encoding and quantization. /// public enum TransparentColorMode { @@ -18,5 +18,5 @@ public enum TransparentColorMode /// to fully transparent pixels (all components set to zero), /// which may improve compression. /// - Clear = 1, + Clear = 1 } diff --git a/src/ImageSharp/Formats/Webp/BitReader/BitReaderBase.cs b/src/ImageSharp/Formats/Webp/BitReader/BitReaderBase.cs index 83f9e797ab..2b843cc8f6 100644 --- a/src/ImageSharp/Formats/Webp/BitReader/BitReaderBase.cs +++ b/src/ImageSharp/Formats/Webp/BitReader/BitReaderBase.cs @@ -32,7 +32,7 @@ internal abstract class BitReaderBase : IDisposable /// Used for allocating memory during reading data from the stream. protected static IMemoryOwner ReadImageDataFromStream(Stream input, int bytesToRead, MemoryAllocator memoryAllocator) { - IMemoryOwner data = memoryAllocator.Allocate(bytesToRead); + IMemoryOwner data = memoryAllocator.Allocate(bytesToRead, AllocationOptions.Clean); Span dataSpan = data.Memory.Span; input.Read(dataSpan[..bytesToRead], 0, bytesToRead); diff --git a/src/ImageSharp/Formats/Webp/Lossy/Vp8Decoder.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Decoder.cs index b3c5bfaf41..3c8bafa1b2 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Decoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Decoder.cs @@ -67,14 +67,14 @@ internal class Vp8Decoder : IDisposable int extraY = extraRows * this.CacheYStride; int extraUv = extraRows / 2 * this.CacheUvStride; this.YuvBuffer = memoryAllocator.Allocate((WebpConstants.Bps * 17) + (WebpConstants.Bps * 9) + extraY); - this.CacheY = memoryAllocator.Allocate((16 * this.CacheYStride) + extraY); + this.CacheY = memoryAllocator.Allocate((16 * this.CacheYStride) + extraY, AllocationOptions.Clean); int cacheUvSize = (16 * this.CacheUvStride) + extraUv; this.CacheU = memoryAllocator.Allocate(cacheUvSize); this.CacheV = memoryAllocator.Allocate(cacheUvSize); this.TmpYBuffer = memoryAllocator.Allocate((int)width); this.TmpUBuffer = memoryAllocator.Allocate((int)width); this.TmpVBuffer = memoryAllocator.Allocate((int)width); - this.Pixels = memoryAllocator.Allocate((int)(width * height * 4)); + this.Pixels = memoryAllocator.Allocate((int)(width * height * 4), AllocationOptions.Clean); #if DEBUG // Filling those buffers with 205, is only useful for debugging, diff --git a/src/ImageSharp/Formats/Webp/WebpAnimationDecoder.cs b/src/ImageSharp/Formats/Webp/WebpAnimationDecoder.cs index b74337ef37..173d9436dd 100644 --- a/src/ImageSharp/Formats/Webp/WebpAnimationDecoder.cs +++ b/src/ImageSharp/Formats/Webp/WebpAnimationDecoder.cs @@ -81,16 +81,29 @@ internal class WebpAnimationDecoder : IDisposable /// The width of the image. /// The height of the image. /// The size of the image data in bytes. - public Image Decode(BufferedReadStream stream, WebpFeatures features, uint width, uint height, uint completeDataSize) + public Image Decode( + BufferedReadStream stream, + WebpFeatures features, + uint width, + uint height, + uint completeDataSize) where TPixel : unmanaged, IPixel { Image? image = null; ImageFrame? previousFrame = null; + WebpFrameData? prevFrameData = null; this.metadata = new ImageMetadata(); this.webpMetadata = this.metadata.GetWebpMetadata(); this.webpMetadata.RepeatCount = features.AnimationLoopCount; + Color backgroundColor = this.backgroundColorHandling == BackgroundColorHandling.Ignore + ? Color.Transparent + : features.AnimationBackgroundColor!.Value; + + this.webpMetadata.BackgroundColor = backgroundColor; + TPixel backgroundPixel = backgroundColor.ToPixel(); + Span buffer = stackalloc byte[4]; uint frameCount = 0; int remainingBytes = (int)completeDataSize; @@ -101,10 +114,16 @@ internal class WebpAnimationDecoder : IDisposable switch (chunkType) { case WebpChunkType.FrameData: - Color backgroundColor = this.backgroundColorHandling == BackgroundColorHandling.Ignore - ? Color.FromPixel(new Bgra32(0, 0, 0, 0)) - : features.AnimationBackgroundColor!.Value; - uint dataSize = this.ReadFrame(stream, ref image, ref previousFrame, width, height, backgroundColor); + + uint dataSize = this.ReadFrame( + stream, + ref image, + ref previousFrame, + ref prevFrameData, + width, + height, + backgroundPixel); + remainingBytes -= (int)dataSize; break; case WebpChunkType.Xmp: @@ -132,10 +151,18 @@ internal class WebpAnimationDecoder : IDisposable /// The stream, where the image should be decoded from. Cannot be null. /// The image to decode the information to. /// The previous frame. + /// The previous frame data. /// The width of the image. /// The height of the image. /// The default background color of the canvas in. - private uint ReadFrame(BufferedReadStream stream, ref Image? image, ref ImageFrame? previousFrame, uint width, uint height, Color backgroundColor) + private uint ReadFrame( + BufferedReadStream stream, + ref Image? image, + ref ImageFrame? previousFrame, + ref WebpFrameData? prevFrameData, + uint width, + uint height, + TPixel backgroundColor) where TPixel : unmanaged, IPixel { WebpFrameData frameData = WebpFrameData.Parse(stream); @@ -174,40 +201,51 @@ internal class WebpAnimationDecoder : IDisposable break; } - ImageFrame? currentFrame = null; - ImageFrame imageFrame; + ImageFrame currentFrame; if (previousFrame is null) { - image = new Image(this.configuration, (int)width, (int)height, backgroundColor.ToPixel(), this.metadata); - - SetFrameMetadata(image.Frames.RootFrame.Metadata, frameData); + image = new Image(this.configuration, (int)width, (int)height, backgroundColor, this.metadata); - imageFrame = image.Frames.RootFrame; + currentFrame = image.Frames.RootFrame; + SetFrameMetadata(currentFrame.Metadata, frameData); } else { - currentFrame = image!.Frames.AddFrame(previousFrame); // This clones the frame and adds it the collection. + // If the frame is a key frame we do not need to clone the frame or clear it. + bool isKeyFrame = prevFrameData?.DisposalMethod is FrameDisposalMode.RestoreToBackground + && this.restoreArea == image!.Bounds; - SetFrameMetadata(currentFrame.Metadata, frameData); + if (isKeyFrame) + { + currentFrame = image!.Frames.CreateFrame(backgroundColor); + } + else + { + // This clones the frame and adds it the collection. + currentFrame = image!.Frames.AddFrame(previousFrame); + if (prevFrameData?.DisposalMethod is FrameDisposalMode.RestoreToBackground) + { + this.RestoreToBackground(currentFrame, backgroundColor); + } + } - imageFrame = currentFrame; + SetFrameMetadata(currentFrame.Metadata, frameData); } - Rectangle regionRectangle = frameData.Bounds; + Rectangle interest = frameData.Bounds; + bool blend = previousFrame != null && frameData.BlendingMethod == FrameBlendMode.Over; + using Buffer2D pixelData = this.DecodeImageFrameData(frameData, webpInfo); + DrawDecodedImageFrameOnCanvas(pixelData, currentFrame, interest, blend); + + webpInfo?.Dispose(); + previousFrame = currentFrame; + prevFrameData = frameData; if (frameData.DisposalMethod is FrameDisposalMode.RestoreToBackground) { - this.RestoreToBackground(imageFrame, backgroundColor); + this.restoreArea = interest; } - using Buffer2D decodedImageFrame = this.DecodeImageFrameData(frameData, webpInfo); - - bool blend = previousFrame != null && frameData.BlendingMethod == FrameBlendMode.Over; - DrawDecodedImageFrameOnCanvas(decodedImageFrame, imageFrame, regionRectangle, blend); - - previousFrame = currentFrame ?? image.Frames.RootFrame; - this.restoreArea = regionRectangle; - return (uint)(stream.Position - streamStartPosition); } @@ -257,31 +295,26 @@ internal class WebpAnimationDecoder : IDisposable try { - Buffer2D pixelBufferDecoded = decodedFrame.PixelBuffer; + Buffer2D decodeBuffer = decodedFrame.PixelBuffer; if (webpInfo.IsLossless) { - WebpLosslessDecoder losslessDecoder = - new(webpInfo.Vp8LBitReader, this.memoryAllocator, this.configuration); - losslessDecoder.Decode(pixelBufferDecoded, (int)webpInfo.Width, (int)webpInfo.Height); + WebpLosslessDecoder losslessDecoder = new(webpInfo.Vp8LBitReader, this.memoryAllocator, this.configuration); + losslessDecoder.Decode(decodeBuffer, (int)webpInfo.Width, (int)webpInfo.Height); } else { WebpLossyDecoder lossyDecoder = new(webpInfo.Vp8BitReader, this.memoryAllocator, this.configuration); - lossyDecoder.Decode(pixelBufferDecoded, (int)webpInfo.Width, (int)webpInfo.Height, webpInfo, this.alphaData); + lossyDecoder.Decode(decodeBuffer, (int)webpInfo.Width, (int)webpInfo.Height, webpInfo, this.alphaData); } - return pixelBufferDecoded; + return decodeBuffer; } catch { decodedFrame?.Dispose(); throw; } - finally - { - webpInfo.Dispose(); - } } /// @@ -335,7 +368,7 @@ internal class WebpAnimationDecoder : IDisposable /// The pixel format. /// The image frame. /// Color of the background. - private void RestoreToBackground(ImageFrame imageFrame, Color backgroundColor) + private void RestoreToBackground(ImageFrame imageFrame, TPixel backgroundColor) where TPixel : unmanaged, IPixel { if (!this.restoreArea.HasValue) @@ -345,8 +378,9 @@ internal class WebpAnimationDecoder : IDisposable Rectangle interest = Rectangle.Intersect(imageFrame.Bounds, this.restoreArea.Value); Buffer2DRegion pixelRegion = imageFrame.PixelBuffer.GetRegion(interest); - TPixel backgroundPixel = backgroundColor.ToPixel(); - pixelRegion.Fill(backgroundPixel); + pixelRegion.Fill(backgroundColor); + + this.restoreArea = null; } /// diff --git a/src/ImageSharp/Formats/Webp/WebpCommonUtils.cs b/src/ImageSharp/Formats/Webp/WebpCommonUtils.cs index a1e9821c09..1ca409f9a4 100644 --- a/src/ImageSharp/Formats/Webp/WebpCommonUtils.cs +++ b/src/ImageSharp/Formats/Webp/WebpCommonUtils.cs @@ -18,7 +18,7 @@ internal static class WebpCommonUtils /// /// The row to check. /// Returns true if alpha has non-0xff values. - public static unsafe bool CheckNonOpaque(Span row) + public static unsafe bool CheckNonOpaque(ReadOnlySpan row) { if (Avx2.IsSupported) { diff --git a/src/ImageSharp/IDeepCloneable.cs b/src/ImageSharp/IDeepCloneable.cs index 3d00d627e0..8b225da0c7 100644 --- a/src/ImageSharp/IDeepCloneable.cs +++ b/src/ImageSharp/IDeepCloneable.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. namespace SixLabors.ImageSharp; @@ -14,7 +14,7 @@ public interface IDeepCloneable /// Creates a new that is a deep copy of the current instance. /// /// The . - T DeepClone(); + public T DeepClone(); } /// @@ -26,5 +26,5 @@ public interface IDeepCloneable /// Creates a new object that is a deep copy of the current instance. /// /// The . - IDeepCloneable DeepClone(); + public IDeepCloneable DeepClone(); } diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index fde3e94e92..b7629044a0 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -51,6 +51,11 @@ + + True + True + InlineArray.tt + True True @@ -144,6 +149,10 @@ + + TextTemplatingFileGenerator + InlineArray.cs + ImageMetadataExtensions.cs TextTemplatingFileGenerator diff --git a/src/ImageSharp/IndexedImageFrame{TPixel}.cs b/src/ImageSharp/IndexedImageFrame{TPixel}.cs index 6807e77ad2..a88cdb524e 100644 --- a/src/ImageSharp/IndexedImageFrame{TPixel}.cs +++ b/src/ImageSharp/IndexedImageFrame{TPixel}.cs @@ -25,12 +25,12 @@ public sealed class IndexedImageFrame : IPixelSource, IDisposable /// Initializes a new instance of the class. /// /// - /// The configuration which allows altering default behaviour or extending the library. + /// The configuration which allows altering default behavior or extending the library. /// /// The frame width. /// The frame height. /// The color palette. - internal IndexedImageFrame(Configuration configuration, int width, int height, ReadOnlyMemory palette) + public IndexedImageFrame(Configuration configuration, int width, int height, ReadOnlyMemory palette) { Guard.NotNull(configuration, nameof(configuration)); Guard.MustBeLessThanOrEqualTo(palette.Length, QuantizerConstants.MaxColors, nameof(palette)); @@ -42,14 +42,14 @@ public sealed class IndexedImageFrame : IPixelSource, IDisposable this.Height = height; this.pixelBuffer = configuration.MemoryAllocator.Allocate2D(width, height); - // Copy the palette over. We want the lifetime of this frame to be independant of any palette source. + // Copy the palette over. We want the lifetime of this frame to be independent of any palette source. this.paletteOwner = configuration.MemoryAllocator.Allocate(palette.Length); palette.Span.CopyTo(this.paletteOwner.GetSpan()); this.Palette = this.paletteOwner.Memory[..palette.Length]; } /// - /// Gets the configuration which allows altering default behaviour or extending the library. + /// Gets the configuration which allows altering default behavior or extending the library. /// public Configuration Configuration { get; } diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Lut.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Lut.cs index e88dd8d9e1..f3ce6cd79c 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Lut.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Lut.cs @@ -4,24 +4,21 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc; /// -/// Provides methods to read ICC data types +/// Provides methods to read ICC data types. /// internal sealed partial class IccDataReader { /// - /// Reads an 8bit lookup table + /// Reads an 8bit lookup table. /// - /// The read LUT - public IccLut ReadLut8() - { - return new IccLut(this.ReadBytes(256)); - } + /// The read LUT. + public IccLut ReadLut8() => new(this.ReadBytes(256)); /// - /// Reads a 16bit lookup table + /// Reads a 16bit lookup table. /// - /// The number of entries - /// The read LUT + /// The number of entries. + /// The read LUT. public IccLut ReadLut16(int count) { var values = new ushort[count]; @@ -34,16 +31,16 @@ internal sealed partial class IccDataReader } /// - /// Reads a CLUT depending on type + /// Reads a CLUT depending on type. /// - /// Input channel count - /// Output channel count + /// Input channel count. + /// Output channel count. /// If true, it's read as CLUTf32, - /// else read as either CLUT8 or CLUT16 depending on embedded information - /// The read CLUT + /// else read as either CLUT8 or CLUT16 depending on embedded information. + /// The read CLUT. public IccClut ReadClut(int inChannelCount, int outChannelCount, bool isFloat) { - // Grid-points are always 16 bytes long but only 0-inChCount are used + // Grid-points are always 16 bytes long but only 0-inChCount are used. var gridPointCount = new byte[inChannelCount]; Buffer.BlockCopy(this.data, this.AddIndex(16), gridPointCount, 0, inChannelCount); @@ -67,15 +64,14 @@ internal sealed partial class IccDataReader } /// - /// Reads an 8 bit CLUT + /// Reads an 8 bit CLUT. /// - /// Input channel count - /// Output channel count - /// Grid point count for each CLUT channel - /// The read CLUT8 + /// Input channel count. + /// Output channel count. + /// Grid point count for each CLUT channel. + /// The read CLUT8. public IccClut ReadClut8(int inChannelCount, int outChannelCount, byte[] gridPointCount) { - int start = this.currentIndex; int length = 0; for (int i = 0; i < inChannelCount; i++) { @@ -86,27 +82,26 @@ internal sealed partial class IccDataReader const float Max = byte.MaxValue; - var values = new float[length][]; + float[] values = new float[length * outChannelCount]; + int offset = 0; for (int i = 0; i < length; i++) { - values[i] = new float[outChannelCount]; for (int j = 0; j < outChannelCount; j++) { - values[i][j] = this.data[this.currentIndex++] / Max; + values[offset++] = this.data[this.currentIndex++] / Max; } } - this.currentIndex = start + (length * outChannelCount); - return new IccClut(values, gridPointCount, IccClutDataType.UInt8); + return new IccClut(values, gridPointCount, IccClutDataType.UInt8, outChannelCount); } /// - /// Reads a 16 bit CLUT + /// Reads a 16 bit CLUT. /// - /// Input channel count - /// Output channel count - /// Grid point count for each CLUT channel - /// The read CLUT16 + /// Input channel count. + /// Output channel count. + /// Grid point count for each CLUT channel. + /// The read CLUT16. public IccClut ReadClut16(int inChannelCount, int outChannelCount, byte[] gridPointCount) { int start = this.currentIndex; @@ -120,27 +115,27 @@ internal sealed partial class IccDataReader const float Max = ushort.MaxValue; - var values = new float[length][]; + float[] values = new float[length * outChannelCount]; + int offset = 0; for (int i = 0; i < length; i++) { - values[i] = new float[outChannelCount]; for (int j = 0; j < outChannelCount; j++) { - values[i][j] = this.ReadUInt16() / Max; + values[offset++] = this.ReadUInt16() / Max; } } this.currentIndex = start + (length * outChannelCount * 2); - return new IccClut(values, gridPointCount, IccClutDataType.UInt16); + return new IccClut(values, gridPointCount, IccClutDataType.UInt16, outChannelCount); } /// - /// Reads a 32bit floating point CLUT + /// Reads a 32bit floating point CLUT. /// - /// Input channel count - /// Output channel count - /// Grid point count for each CLUT channel - /// The read CLUTf32 + /// Input channel count. + /// Output channel count. + /// Grid point count for each CLUT channel. + /// The read CLUTf32. public IccClut ReadClutF32(int inChCount, int outChCount, byte[] gridPointCount) { int start = this.currentIndex; @@ -152,17 +147,17 @@ internal sealed partial class IccDataReader length /= inChCount; - var values = new float[length][]; + float[] values = new float[length * outChCount]; + int offset = 0; for (int i = 0; i < length; i++) { - values[i] = new float[outChCount]; for (int j = 0; j < outChCount; j++) { - values[i][j] = this.ReadSingle(); + values[offset++] = this.ReadSingle(); } } this.currentIndex = start + (length * outChCount * 4); - return new IccClut(values, gridPointCount, IccClutDataType.Float); + return new IccClut(values, gridPointCount, IccClutDataType.Float, outChCount); } } diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Matrix.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Matrix.cs index 61ecda4aab..ecc9bfbffb 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Matrix.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Matrix.cs @@ -17,16 +17,23 @@ internal sealed partial class IccDataReader /// The read matrix public float[,] ReadMatrix(int xCount, int yCount, bool isSingle) { - var matrix = new float[xCount, yCount]; - for (int y = 0; y < yCount; y++) + float[,] matrix = new float[xCount, yCount]; + + if (isSingle) { - for (int x = 0; x < xCount; x++) + for (int y = 0; y < yCount; y++) { - if (isSingle) + for (int x = 0; x < xCount; x++) { matrix[x, y] = this.ReadSingle(); } - else + } + } + else + { + for (int y = 0; y < yCount; y++) + { + for (int x = 0; x < xCount; x++) { matrix[x, y] = this.ReadFix16(); } @@ -44,14 +51,17 @@ internal sealed partial class IccDataReader /// The read matrix public float[] ReadMatrix(int yCount, bool isSingle) { - var matrix = new float[yCount]; - for (int i = 0; i < yCount; i++) + float[] matrix = new float[yCount]; + if (isSingle) { - if (isSingle) + for (int i = 0; i < yCount; i++) { matrix[i] = this.ReadSingle(); } - else + } + else + { + for (int i = 0; i < yCount; i++) { matrix[i] = this.ReadFix16(); } diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Primitives.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Primitives.cs index 47d946d443..7a526ef1af 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Primitives.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Primitives.cs @@ -16,55 +16,37 @@ internal sealed partial class IccDataReader /// Reads an ushort /// /// the value - public ushort ReadUInt16() - { - return BinaryPrimitives.ReadUInt16BigEndian(this.data.AsSpan(this.AddIndex(2), 2)); - } + public ushort ReadUInt16() => BinaryPrimitives.ReadUInt16BigEndian(this.data.AsSpan(this.AddIndex(2), 2)); /// /// Reads a short /// /// the value - public short ReadInt16() - { - return BinaryPrimitives.ReadInt16BigEndian(this.data.AsSpan(this.AddIndex(2), 2)); - } + public short ReadInt16() => BinaryPrimitives.ReadInt16BigEndian(this.data.AsSpan(this.AddIndex(2), 2)); /// /// Reads an uint /// /// the value - public uint ReadUInt32() - { - return BinaryPrimitives.ReadUInt32BigEndian(this.data.AsSpan(this.AddIndex(4), 4)); - } + public uint ReadUInt32() => BinaryPrimitives.ReadUInt32BigEndian(this.data.AsSpan(this.AddIndex(4), 4)); /// /// Reads an int /// /// the value - public int ReadInt32() - { - return BinaryPrimitives.ReadInt32BigEndian(this.data.AsSpan(this.AddIndex(4), 4)); - } + public int ReadInt32() => BinaryPrimitives.ReadInt32BigEndian(this.data.AsSpan(this.AddIndex(4), 4)); /// /// Reads an ulong /// /// the value - public ulong ReadUInt64() - { - return BinaryPrimitives.ReadUInt64BigEndian(this.data.AsSpan(this.AddIndex(8), 8)); - } + public ulong ReadUInt64() => BinaryPrimitives.ReadUInt64BigEndian(this.data.AsSpan(this.AddIndex(8), 8)); /// /// Reads a long /// /// the value - public long ReadInt64() - { - return BinaryPrimitives.ReadInt64BigEndian(this.data.AsSpan(this.AddIndex(8), 8)); - } + public long ReadInt64() => BinaryPrimitives.ReadInt64BigEndian(this.data.AsSpan(this.AddIndex(8), 8)); /// /// Reads a float. @@ -152,10 +134,7 @@ internal sealed partial class IccDataReader /// Reads an unsigned 16bit number with 8 value bits and 8 fractional bits. /// /// The number as double - public float ReadUFix8() - { - return this.ReadUInt16() / 256f; - } + public float ReadUFix8() => this.ReadUInt16() / 256f; /// /// Reads a number of bytes and advances the index. diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs index ddfc625152..c1b22e82bf 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs @@ -8,21 +8,19 @@ using System.Numerics; namespace SixLabors.ImageSharp.Metadata.Profiles.Icc; /// -/// Provides methods to read ICC data types +/// Provides methods to read ICC data types. /// internal sealed partial class IccDataReader { /// - /// Reads a tag data entry + /// Reads a tag data entry. /// - /// The table entry with reading information - /// the tag data entry + /// The table entry with reading information. + /// The tag data entry. public IccTagDataEntry ReadTagDataEntry(IccTagTableEntry info) { this.currentIndex = (int)info.Offset; - IccTypeSignature type = this.ReadTagDataEntryHeader(); - - switch (type) + switch (this.ReadTagDataEntryHeader()) { case IccTypeSignature.Chromaticity: return this.ReadChromaticityTagDataEntry(); @@ -103,10 +101,10 @@ internal sealed partial class IccDataReader /// /// Reads the header of a /// - /// The read signature + /// The read signature. public IccTypeSignature ReadTagDataEntryHeader() { - var type = (IccTypeSignature)this.ReadUInt32(); + IccTypeSignature type = (IccTypeSignature)this.ReadUInt32(); this.AddIndex(4); // 4 bytes are not used return type; } @@ -114,7 +112,7 @@ internal sealed partial class IccDataReader /// /// Reads the header of a and checks if it's the expected value /// - /// expected value to check against + /// The expected value to check against. public void ReadCheckTagDataEntryHeader(IccTypeSignature expected) { IccTypeSignature type = this.ReadTagDataEntryHeader(); @@ -127,8 +125,8 @@ internal sealed partial class IccDataReader /// /// Reads a with an unknown /// - /// The size of the entry in bytes - /// The read entry + /// The size of the entry in bytes. + /// The read entry. public IccUnknownTagDataEntry ReadUnknownTagDataEntry(uint size) { int count = (int)size - 8; // 8 is the tag header size @@ -138,7 +136,7 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The read entry + /// The read entry. public IccChromaticityTagDataEntry ReadChromaticityTagDataEntry() { ushort channelCount = this.ReadUInt16(); @@ -152,7 +150,7 @@ internal sealed partial class IccDataReader } else { - // The type is not know, so the values need be read + // The type is not know, so the values need be read. double[][] values = new double[channelCount][]; for (int i = 0; i < channelCount; i++) { @@ -166,7 +164,7 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The read entry + /// The read entry. public IccColorantOrderTagDataEntry ReadColorantOrderTagDataEntry() { uint colorantCount = this.ReadUInt32(); @@ -177,7 +175,7 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The read entry + /// The read entry. public IccColorantTableTagDataEntry ReadColorantTableTagDataEntry() { uint colorantCount = this.ReadUInt32(); @@ -193,7 +191,7 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The read entry + /// The read entry. public IccCurveTagDataEntry ReadCurveTagDataEntry() { uint pointCount = this.ReadUInt32(); @@ -222,7 +220,7 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The size of the entry in bytes + /// The size of the entry in bytes. /// The read entry public IccDataTagDataEntry ReadDataTagDataEntry(uint size) { @@ -240,16 +238,13 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The read entry - public IccDateTimeTagDataEntry ReadDateTimeTagDataEntry() - { - return new IccDateTimeTagDataEntry(this.ReadDateTime()); - } + /// The read entry. + public IccDateTimeTagDataEntry ReadDateTimeTagDataEntry() => new IccDateTimeTagDataEntry(this.ReadDateTime()); /// /// Reads a /// - /// The read entry + /// The read entry. public IccLut16TagDataEntry ReadLut16TagDataEntry() { byte inChCount = this.data[this.AddIndex(1)]; @@ -287,7 +282,7 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The read entry + /// The read entry. public IccLut8TagDataEntry ReadLut8TagDataEntry() { byte inChCount = this.data[this.AddIndex(1)]; @@ -322,7 +317,7 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The read entry + /// The read entry. public IccLutAToBTagDataEntry ReadLutAtoBTagDataEntry() { int start = this.currentIndex - 8; // 8 is the tag header size @@ -381,7 +376,7 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The read entry + /// The read entry. public IccLutBToATagDataEntry ReadLutBtoATagDataEntry() { int start = this.currentIndex - 8; // 8 is the tag header size @@ -440,21 +435,18 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The read entry - public IccMeasurementTagDataEntry ReadMeasurementTagDataEntry() - { - return new IccMeasurementTagDataEntry( + /// The read entry. + public IccMeasurementTagDataEntry ReadMeasurementTagDataEntry() => new( observer: (IccStandardObserver)this.ReadUInt32(), xyzBacking: this.ReadXyzNumber(), geometry: (IccMeasurementGeometry)this.ReadUInt32(), flare: this.ReadUFix16(), illuminant: (IccStandardIlluminant)this.ReadUInt32()); - } /// /// Reads a /// - /// The read entry + /// The read entry. public IccMultiLocalizedUnicodeTagDataEntry ReadMultiLocalizedUnicodeTagDataEntry() { int start = this.currentIndex - 8; // 8 is the tag header size @@ -519,7 +511,7 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The read entry + /// The read entry. public IccMultiProcessElementsTagDataEntry ReadMultiProcessElementsTagDataEntry() { int start = this.currentIndex - 8; @@ -547,7 +539,7 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The read entry + /// The read entry. public IccNamedColor2TagDataEntry ReadNamedColor2TagDataEntry() { int vendorFlag = this.ReadInt32(); @@ -569,15 +561,12 @@ internal sealed partial class IccDataReader /// Reads a /// /// The read entry - public IccParametricCurveTagDataEntry ReadParametricCurveTagDataEntry() - { - return new IccParametricCurveTagDataEntry(this.ReadParametricCurve()); - } + public IccParametricCurveTagDataEntry ReadParametricCurveTagDataEntry() => new(this.ReadParametricCurve()); /// /// Reads a /// - /// The read entry + /// The read entry. public IccProfileSequenceDescTagDataEntry ReadProfileSequenceDescTagDataEntry() { uint count = this.ReadUInt32(); @@ -593,7 +582,7 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The read entry + /// The read entry. public IccProfileSequenceIdentifierTagDataEntry ReadProfileSequenceIdentifierTagDataEntry() { int start = this.currentIndex - 8; // 8 is the tag header size @@ -620,7 +609,7 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The read entry + /// The read entry. public IccResponseCurveSet16TagDataEntry ReadResponseCurveSet16TagDataEntry() { int start = this.currentIndex - 8; // 8 is the tag header size @@ -646,8 +635,8 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The size of the entry in bytes - /// The read entry + /// The size of the entry in bytes. + /// The read entry. public IccFix16ArrayTagDataEntry ReadFix16ArrayTagDataEntry(uint size) { uint count = (size - 8) / 4; @@ -663,27 +652,21 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The read entry - public IccSignatureTagDataEntry ReadSignatureTagDataEntry() - { - return new IccSignatureTagDataEntry(this.ReadAsciiString(4)); - } + /// The read entry. + public IccSignatureTagDataEntry ReadSignatureTagDataEntry() => new(this.ReadAsciiString(4)); /// /// Reads a /// - /// The size of the entry in bytes - /// The read entry - public IccTextTagDataEntry ReadTextTagDataEntry(uint size) - { - return new IccTextTagDataEntry(this.ReadAsciiString((int)size - 8)); // 8 is the tag header size - } + /// The size of the entry in bytes. + /// The read entry. + public IccTextTagDataEntry ReadTextTagDataEntry(uint size) => new(this.ReadAsciiString((int)size - 8)); // 8 is the tag header size /// /// Reads a /// - /// The size of the entry in bytes - /// The read entry + /// The size of the entry in bytes. + /// The read entry. public IccUFix16ArrayTagDataEntry ReadUFix16ArrayTagDataEntry(uint size) { uint count = (size - 8) / 4; @@ -699,8 +682,8 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The size of the entry in bytes - /// The read entry + /// The size of the entry in bytes. + /// The read entry. public IccUInt16ArrayTagDataEntry ReadUInt16ArrayTagDataEntry(uint size) { uint count = (size - 8) / 2; @@ -716,8 +699,8 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The size of the entry in bytes - /// The read entry + /// The size of the entry in bytes. + /// The read entry. public IccUInt32ArrayTagDataEntry ReadUInt32ArrayTagDataEntry(uint size) { uint count = (size - 8) / 4; @@ -733,8 +716,8 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The size of the entry in bytes - /// The read entry + /// The size of the entry in bytes. + /// The read entry. public IccUInt64ArrayTagDataEntry ReadUInt64ArrayTagDataEntry(uint size) { uint count = (size - 8) / 8; @@ -750,8 +733,8 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The size of the entry in bytes - /// The read entry + /// The size of the entry in bytes. + /// The read entry. public IccUInt8ArrayTagDataEntry ReadUInt8ArrayTagDataEntry(uint size) { int count = (int)size - 8; // 8 is the tag header size @@ -763,20 +746,17 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The read entry - public IccViewingConditionsTagDataEntry ReadViewingConditionsTagDataEntry() - { - return new IccViewingConditionsTagDataEntry( + /// The read entry. + public IccViewingConditionsTagDataEntry ReadViewingConditionsTagDataEntry() => new( illuminantXyz: this.ReadXyzNumber(), surroundXyz: this.ReadXyzNumber(), illuminant: (IccStandardIlluminant)this.ReadUInt32()); - } /// /// Reads a /// - /// The size of the entry in bytes - /// The read entry + /// The size of the entry in bytes. + /// The read entry. public IccXyzTagDataEntry ReadXyzTagDataEntry(uint size) { uint count = (size - 8) / 12; @@ -792,7 +772,7 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The read entry + /// The read entry. public IccTextDescriptionTagDataEntry ReadTextDescriptionTagDataEntry() { string unicodeValue, scriptcodeValue; @@ -832,7 +812,7 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The read entry + /// The read entry. public IccCrdInfoTagDataEntry ReadCrdInfoTagDataEntry() { uint productNameCount = this.ReadUInt32(); @@ -856,7 +836,7 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The read entry + /// The read entry. public IccScreeningTagDataEntry ReadScreeningTagDataEntry() { var flags = (IccScreeningFlag)this.ReadInt32(); @@ -873,7 +853,7 @@ internal sealed partial class IccDataReader /// /// Reads a /// - /// The size of the entry in bytes + /// The size of the entry in bytes. /// The read entry public IccUcrBgTagDataEntry ReadUcrBgTagDataEntry(uint size) { diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs index 703a3896bb..29394c0820 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs @@ -4,15 +4,15 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Icc; /// -/// Provides methods to write ICC data types +/// Provides methods to write ICC data types. /// internal sealed partial class IccDataWriter { /// - /// Writes an 8bit lookup table + /// Writes an 8bit lookup table. /// - /// The LUT to write - /// The number of bytes written + /// The LUT to write. + /// The number of bytes written. public int WriteLut8(IccLut value) { foreach (float item in value.Values) @@ -24,10 +24,10 @@ internal sealed partial class IccDataWriter } /// - /// Writes an 16bit lookup table + /// Writes an 16bit lookup table. /// - /// The LUT to write - /// The number of bytes written + /// The LUT to write. + /// The number of bytes written. public int WriteLut16(IccLut value) { foreach (float item in value.Values) @@ -39,10 +39,10 @@ internal sealed partial class IccDataWriter } /// - /// Writes an color lookup table + /// Writes an color lookup table. /// - /// The CLUT to write - /// The number of bytes written + /// The CLUT to write. + /// The number of bytes written. public int WriteClut(IccClut value) { int count = this.WriteArray(value.GridPointCount); @@ -67,57 +67,48 @@ internal sealed partial class IccDataWriter } /// - /// Writes a 8bit color lookup table + /// Writes a 8bit color lookup table. /// - /// The CLUT to write - /// The number of bytes written + /// The CLUT to write. + /// The number of bytes written. public int WriteClut8(IccClut value) { int count = 0; - foreach (float[] inArray in value.Values) + foreach (float item in value.Values) { - foreach (float item in inArray) - { - count += this.WriteByte((byte)Numerics.Clamp((item * byte.MaxValue) + 0.5F, 0, byte.MaxValue)); - } + count += this.WriteByte((byte)Numerics.Clamp((item * byte.MaxValue) + 0.5F, 0, byte.MaxValue)); } return count; } /// - /// Writes a 16bit color lookup table + /// Writes a 16bit color lookup table. /// - /// The CLUT to write - /// The number of bytes written + /// The CLUT to write. + /// The number of bytes written. public int WriteClut16(IccClut value) { int count = 0; - foreach (float[] inArray in value.Values) + foreach (float item in value.Values) { - foreach (float item in inArray) - { - count += this.WriteUInt16((ushort)Numerics.Clamp((item * ushort.MaxValue) + 0.5F, 0, ushort.MaxValue)); - } + count += this.WriteUInt16((ushort)Numerics.Clamp((item * ushort.MaxValue) + 0.5F, 0, ushort.MaxValue)); } return count; } /// - /// Writes a 32bit float color lookup table + /// Writes a 32bit float color lookup table. /// - /// The CLUT to write - /// The number of bytes written + /// The CLUT to write. + /// The number of bytes written. public int WriteClutF32(IccClut value) { int count = 0; - foreach (float[] inArray in value.Values) + foreach (float item in value.Values) { - foreach (float item in inArray) - { - count += this.WriteSingle(item); - } + count += this.WriteSingle(item); } return count; diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Matrix.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Matrix.cs index 1e5f359e09..636cc90a57 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Matrix.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.Matrix.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. using System.Numerics; @@ -61,15 +61,21 @@ internal sealed partial class IccDataWriter public int WriteMatrix(in DenseMatrix value, bool isSingle) { int count = 0; - for (int y = 0; y < value.Rows; y++) + if (isSingle) { - for (int x = 0; x < value.Columns; x++) + for (int y = 0; y < value.Rows; y++) { - if (isSingle) + for (int x = 0; x < value.Columns; x++) { count += this.WriteSingle(value[x, y]); } - else + } + } + else + { + for (int y = 0; y < value.Rows; y++) + { + for (int x = 0; x < value.Columns; x++) { count += this.WriteFix16(value[x, y]); } @@ -88,15 +94,22 @@ internal sealed partial class IccDataWriter public int WriteMatrix(float[,] value, bool isSingle) { int count = 0; - for (int y = 0; y < value.GetLength(1); y++) + + if (isSingle) { - for (int x = 0; x < value.GetLength(0); x++) + for (int y = 0; y < value.GetLength(1); y++) { - if (isSingle) + for (int x = 0; x < value.GetLength(0); x++) { count += this.WriteSingle(value[x, y]); } - else + } + } + else + { + for (int y = 0; y < value.GetLength(1); y++) + { + for (int x = 0; x < value.GetLength(0); x++) { count += this.WriteFix16(value[x, y]); } diff --git a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs index 1f9c101fb5..6019a0bff7 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs @@ -231,7 +231,7 @@ internal sealed partial class IccDataWriter { int count = this.WriteByte((byte)value.InputChannelCount); count += this.WriteByte((byte)value.OutputChannelCount); - count += this.WriteByte((byte)value.ClutValues.Values[0].Length); + count += this.WriteByte((byte)value.ClutValues.OutputChannelCount); count += this.WriteEmpty(1); count += this.WriteMatrix(value.Matrix, false); diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccFormulaCurveType.cs b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccFormulaCurveType.cs index e0c6f4c962..27af2a91f7 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccFormulaCurveType.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/Enums/IccFormulaCurveType.cs @@ -14,7 +14,7 @@ internal enum IccFormulaCurveType : ushort Type1 = 0, /// - /// Type 1: Y = a * log10 (b * X^γ + c) + d + /// Type 2: Y = a * log10 (b * X^γ + c) + d /// Type2 = 1, diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Exceptions/InvalidIccProfileException.cs b/src/ImageSharp/Metadata/Profiles/ICC/Exceptions/InvalidIccProfileException.cs index c1cb3f10f0..c6b4b65773 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/Exceptions/InvalidIccProfileException.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/Exceptions/InvalidIccProfileException.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. namespace SixLabors.ImageSharp.Metadata.Profiles.Icc; diff --git a/src/ImageSharp/Metadata/Profiles/ICC/IccProfile.cs b/src/ImageSharp/Metadata/Profiles/ICC/IccProfile.cs index ac78318f2b..da015b2b07 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/IccProfile.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/IccProfile.cs @@ -190,7 +190,6 @@ public sealed class IccProfile : IDeepCloneable return; } - IccReader reader = new(); this.header = IccReader.ReadHeader(this.data); } @@ -207,7 +206,6 @@ public sealed class IccProfile : IDeepCloneable return; } - IccReader reader = new(); this.entries = IccReader.ReadTagData(this.data); } } diff --git a/src/ImageSharp/Metadata/Profiles/ICC/IccReader.cs b/src/ImageSharp/Metadata/Profiles/ICC/IccReader.cs index 45074c9a6e..074712d302 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/IccReader.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/IccReader.cs @@ -83,28 +83,19 @@ internal sealed class IccReader { IccTagTableEntry[] tagTable = ReadTagTable(reader); List entries = new(tagTable.Length); - Dictionary store = new(); foreach (IccTagTableEntry tag in tagTable) { IccTagDataEntry entry; - if (store.TryGetValue(tag.Offset, out IccTagDataEntry? value)) + + try { - entry = value; + entry = reader.ReadTagDataEntry(tag); } - else + catch { - try - { - entry = reader.ReadTagDataEntry(tag); - } - catch - { - // Ignore tags that could not be read - continue; - } - - store.Add(tag.Offset, entry); + // Ignore tags that could not be read + continue; } entry.TagSignature = tag.Signature; diff --git a/src/ImageSharp/Metadata/Profiles/ICC/IccTagDataEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/IccTagDataEntry.cs index 12228f3f58..f7a99645bb 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/IccTagDataEntry.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/IccTagDataEntry.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. namespace SixLabors.ImageSharp.Metadata.Profiles.Icc; @@ -41,9 +41,7 @@ public abstract class IccTagDataEntry : IEquatable /// public override bool Equals(object? obj) - { - return obj is IccTagDataEntry entry && this.Equals(entry); - } + => obj is IccTagDataEntry entry && this.Equals(entry); /// public virtual bool Equals(IccTagDataEntry? other) diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccClut.cs b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccClut.cs index 26a882810e..bbec7ce43e 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccClut.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccClut.cs @@ -1,20 +1,21 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. namespace SixLabors.ImageSharp.Metadata.Profiles.Icc; /// -/// Color Lookup Table +/// Color Lookup Table. /// internal sealed class IccClut : IEquatable { /// /// Initializes a new instance of the class. /// - /// The CLUT values - /// The gridpoint count - /// The data type of this CLUT - public IccClut(float[][] values, byte[] gridPointCount, IccClutDataType type) + /// The CLUT values. + /// The gridpoint count. + /// The data type of this CLUT. + /// The output channels count. + public IccClut(float[] values, byte[] gridPointCount, IccClutDataType type, int outputChannelCount) { Guard.NotNull(values, nameof(values)); Guard.NotNull(gridPointCount, nameof(gridPointCount)); @@ -22,91 +23,33 @@ internal sealed class IccClut : IEquatable this.Values = values; this.DataType = type; this.InputChannelCount = gridPointCount.Length; - this.OutputChannelCount = values[0].Length; + this.OutputChannelCount = outputChannelCount; this.GridPointCount = gridPointCount; this.CheckValues(); } /// - /// Initializes a new instance of the class. - /// - /// The CLUT values - /// The gridpoint count - public IccClut(ushort[][] values, byte[] gridPointCount) - { - Guard.NotNull(values, nameof(values)); - Guard.NotNull(gridPointCount, nameof(gridPointCount)); - - const float Max = ushort.MaxValue; - - this.Values = new float[values.Length][]; - for (int i = 0; i < values.Length; i++) - { - this.Values[i] = new float[values[i].Length]; - for (int j = 0; j < values[i].Length; j++) - { - this.Values[i][j] = values[i][j] / Max; - } - } - - this.DataType = IccClutDataType.UInt16; - this.InputChannelCount = gridPointCount.Length; - this.OutputChannelCount = values[0].Length; - this.GridPointCount = gridPointCount; - this.CheckValues(); - } - - /// - /// Initializes a new instance of the class. - /// - /// The CLUT values - /// The gridpoint count - public IccClut(byte[][] values, byte[] gridPointCount) - { - Guard.NotNull(values, nameof(values)); - Guard.NotNull(gridPointCount, nameof(gridPointCount)); - - const float Max = byte.MaxValue; - - this.Values = new float[values.Length][]; - for (int i = 0; i < values.Length; i++) - { - this.Values[i] = new float[values[i].Length]; - for (int j = 0; j < values[i].Length; j++) - { - this.Values[i][j] = values[i][j] / Max; - } - } - - this.DataType = IccClutDataType.UInt8; - this.InputChannelCount = gridPointCount.Length; - this.OutputChannelCount = values[0].Length; - this.GridPointCount = gridPointCount; - this.CheckValues(); - } - - /// - /// Gets the values that make up this table + /// Gets the values that make up this table. /// - public float[][] Values { get; } + public float[] Values { get; } /// - /// Gets the CLUT data type (important when writing a profile) + /// Gets the CLUT data type (important when writing a profile). /// public IccClutDataType DataType { get; } /// - /// Gets the number of input channels + /// Gets the number of input channels. /// public int InputChannelCount { get; } /// - /// Gets the number of output channels + /// Gets the number of output channels. /// public int OutputChannelCount { get; } /// - /// Gets the number of grid points per input channel + /// Gets the number of grid points per input channel. /// public byte[] GridPointCount { get; } @@ -134,15 +77,12 @@ internal sealed class IccClut : IEquatable public override bool Equals(object? obj) => obj is IccClut other && this.Equals(other); /// - public override int GetHashCode() - { - return HashCode.Combine( + public override int GetHashCode() => HashCode.Combine( this.Values, this.DataType, this.InputChannelCount, this.OutputChannelCount, this.GridPointCount); - } private bool EqualsValuesArray(IccClut other) { @@ -153,7 +93,7 @@ internal sealed class IccClut : IEquatable for (int i = 0; i < this.Values.Length; i++) { - if (!this.Values[i].AsSpan().SequenceEqual(other.Values[i])) + if (!this.Values.SequenceEqual(other.Values)) { return false; } @@ -167,17 +107,13 @@ internal sealed class IccClut : IEquatable Guard.MustBeBetweenOrEqualTo(this.InputChannelCount, 1, 15, nameof(this.InputChannelCount)); Guard.MustBeBetweenOrEqualTo(this.OutputChannelCount, 1, 15, nameof(this.OutputChannelCount)); - bool isLengthDifferent = this.Values.Any(t => t.Length != this.OutputChannelCount); - Guard.IsFalse(isLengthDifferent, nameof(this.Values), "The number of output values varies"); - int length = 0; for (int i = 0; i < this.InputChannelCount; i++) { length += (int)Math.Pow(this.GridPointCount[i], this.InputChannelCount); } - length /= this.InputChannelCount; - - Guard.IsTrue(this.Values.Length == length, nameof(this.Values), "Length of values array does not match the grid points"); + // TODO: Disabled this check, not sure if this check is correct. + // Guard.IsTrue(this.Values.Length == length, nameof(this.Values), "Length of values array does not match the grid points"); } } diff --git a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccTagTableEntry.cs b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccTagTableEntry.cs index e7d7461d5d..a71cbfaf5a 100644 --- a/src/ImageSharp/Metadata/Profiles/ICC/Various/IccTagTableEntry.cs +++ b/src/ImageSharp/Metadata/Profiles/ICC/Various/IccTagTableEntry.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. namespace SixLabors.ImageSharp.Metadata.Profiles.Icc; @@ -49,9 +49,7 @@ internal readonly struct IccTagTableEntry : IEquatable /// True if the parameter is equal to the parameter; otherwise, false. /// public static bool operator ==(IccTagTableEntry left, IccTagTableEntry right) - { - return left.Equals(right); - } + => left.Equals(right); /// /// Compares two objects for equality. @@ -62,9 +60,7 @@ internal readonly struct IccTagTableEntry : IEquatable /// True if the parameter is not equal to the parameter; otherwise, false. /// public static bool operator !=(IccTagTableEntry left, IccTagTableEntry right) - { - return !left.Equals(right); - } + => !left.Equals(right); /// public override bool Equals(object? obj) => obj is IccTagTableEntry other && this.Equals(other); diff --git a/src/ImageSharp/PixelFormats/IPixel.cs b/src/ImageSharp/PixelFormats/IPixel.cs index adf386614d..528b3e76d4 100644 --- a/src/ImageSharp/PixelFormats/IPixel.cs +++ b/src/ImageSharp/PixelFormats/IPixel.cs @@ -23,7 +23,8 @@ public interface IPixel : IPixel, IEquatable static abstract PixelOperations CreatePixelOperations(); /// - /// Initializes the pixel instance from a generic scaled . + /// Initializes the pixel instance from a generic a generic ("scaled") representation + /// with values scaled and clamped between 0 and 1 /// /// The vector to load the pixel from. /// The . diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs index 0aa7bad237..b03a54c585 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs @@ -61,7 +61,8 @@ public partial struct Rgb24 : IPixel /// The instance of to convert. /// An instance of . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static implicit operator Rgb24(Rgb color) => FromScaledVector4(new Vector4(color.ToVector3(), 1f)); + public static implicit operator Rgb24(Rgb color) + => FromScaledVector4(new Vector4(color.ToScaledVector3(), 1F)); /// /// Compares two objects for equality. diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs index 0491553430..507d6d70b6 100644 --- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs +++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs @@ -187,7 +187,7 @@ public partial struct Rgba32 : IPixel, IPackedVector /// The instance of to convert. /// An instance of . [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static implicit operator Rgba32(Rgb color) => FromScaledVector4(new Vector4(color.ToVector3(), 1F)); + public static implicit operator Rgba32(Rgb color) => FromScaledVector4(new Vector4(color.ToScaledVector3(), 1F)); /// /// Compares two objects for equality. diff --git a/src/ImageSharp/Processing/Processors/CloningImageProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/CloningImageProcessor{TPixel}.cs index abe32e3882..bc34f759a0 100644 --- a/src/ImageSharp/Processing/Processors/CloningImageProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/CloningImageProcessor{TPixel}.cs @@ -132,16 +132,14 @@ public abstract class CloningImageProcessor : ICloningImageProcessorThe source image. Cannot be null. /// The cloned/destination image. Cannot be null. protected virtual void AfterFrameApply(ImageFrame source, ImageFrame destination) - { - } + => destination.Metadata.AfterFrameApply(source, destination); /// /// This method is called after the process is applied to prepare the processor. /// /// The cloned/destination image. Cannot be null. protected virtual void AfterImageApply(Image destination) - { - } + => destination.Metadata.AfterImageApply(destination); /// /// Disposes the object and frees resources for the Garbage Collector. diff --git a/src/ImageSharp/Processing/Processors/Dithering/ErroDither.KnownTypes.cs b/src/ImageSharp/Processing/Processors/Dithering/ErrorDither.KnownTypes.cs similarity index 100% rename from src/ImageSharp/Processing/Processors/Dithering/ErroDither.KnownTypes.cs rename to src/ImageSharp/Processing/Processors/Dithering/ErrorDither.KnownTypes.cs diff --git a/src/ImageSharp/Processing/Processors/Dithering/IDither.cs b/src/ImageSharp/Processing/Processors/Dithering/IDither.cs index ac2921b98d..3217601270 100644 --- a/src/ImageSharp/Processing/Processors/Dithering/IDither.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/IDither.cs @@ -21,7 +21,7 @@ public interface IDither /// The source image. /// The destination quantized frame. /// The region of interest bounds. - void ApplyQuantizationDither( + public void ApplyQuantizationDither( ref TFrameQuantizer quantizer, ImageFrame source, IndexedImageFrame destination, @@ -38,7 +38,7 @@ public interface IDither /// The palette dithering processor. /// The source image. /// The region of interest bounds. - void ApplyPaletteDither( + public void ApplyPaletteDither( in TPaletteDitherImageProcessor processor, ImageFrame source, Rectangle bounds) diff --git a/src/ImageSharp/Processing/Processors/Dithering/IPaletteDitherImageProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Dithering/IPaletteDitherImageProcessor{TPixel}.cs index e406d82c69..347e2f0ef6 100644 --- a/src/ImageSharp/Processing/Processors/Dithering/IPaletteDitherImageProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/IPaletteDitherImageProcessor{TPixel}.cs @@ -15,22 +15,22 @@ public interface IPaletteDitherImageProcessor /// /// Gets the configuration instance to use when performing operations. /// - Configuration Configuration { get; } + public Configuration Configuration { get; } /// /// Gets the dithering palette. /// - ReadOnlyMemory Palette { get; } + public ReadOnlyMemory Palette { get; } /// /// Gets the dithering scale used to adjust the amount of dither. Range 0..1. /// - float DitherScale { get; } + public float DitherScale { get; } /// /// Returns the color from the dithering palette corresponding to the given color. /// /// The color to match. /// The match. - TPixel GetPaletteColor(TPixel color); + public TPixel GetPaletteColor(TPixel color); } diff --git a/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessor{TPixel}.cs index 7e672393c7..0d4680e21f 100644 --- a/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Dithering/PaletteDitherProcessor{TPixel}.cs @@ -80,7 +80,7 @@ internal sealed class PaletteDitherProcessor : ImageProcessor Justification = "https://github.com/dotnet/roslyn-analyzers/issues/6151")] internal readonly struct DitherProcessor : IPaletteDitherImageProcessor, IDisposable { - private readonly EuclideanPixelMap pixelMap; + private readonly PixelMap pixelMap; [MethodImpl(InliningOptions.ShortMethod)] public DitherProcessor( @@ -89,7 +89,7 @@ internal sealed class PaletteDitherProcessor : ImageProcessor float ditherScale) { this.Configuration = configuration; - this.pixelMap = new EuclideanPixelMap(configuration, palette); + this.pixelMap = PixelMapFactory.Create(configuration, palette, ColorMatchingMode.Coarse); this.Palette = palette; this.DitherScale = ditherScale; } diff --git a/src/ImageSharp/Processing/Processors/ImageProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/ImageProcessor{TPixel}.cs index 2fa79220e5..e1f7d1fffb 100644 --- a/src/ImageSharp/Processing/Processors/ImageProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/ImageProcessor{TPixel}.cs @@ -95,7 +95,7 @@ public abstract class ImageProcessor : IImageProcessor protected abstract void OnFrameApply(ImageFrame source); /// - /// This method is called after the process is applied to prepare the processor. + /// This method is called after the process is applied to each frame. /// /// The source image. Cannot be null. protected virtual void AfterFrameApply(ImageFrame source) @@ -103,11 +103,10 @@ public abstract class ImageProcessor : IImageProcessor } /// - /// This method is called after the process is applied to prepare the processor. + /// This method is called after the process is applied to the complete image. /// protected virtual void AfterImageApply() - { - } + => this.Source.Metadata.AfterImageApply(this.Source); /// /// Disposes the object and frees resources for the Garbage Collector. diff --git a/src/ImageSharp/Processing/Processors/Quantization/ColorMatchingMode.cs b/src/ImageSharp/Processing/Processors/Quantization/ColorMatchingMode.cs new file mode 100644 index 0000000000..26fd7d5d76 --- /dev/null +++ b/src/ImageSharp/Processing/Processors/Quantization/ColorMatchingMode.cs @@ -0,0 +1,28 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +namespace SixLabors.ImageSharp.Processing.Processors.Quantization; + +/// +/// Defines the precision level used when matching colors during quantization. +/// +public enum ColorMatchingMode +{ + /// + /// Uses a coarse caching strategy optimized for performance at the expense of exact matches. + /// This provides the fastest matching but may yield approximate results. + /// + Coarse, + + /// + /// Enables an exact color match cache for the first 512 unique colors encountered, + /// falling back to coarse matching thereafter. + /// + Hybrid, + + /// + /// Performs exact color matching without any caching optimizations. + /// This is the slowest but most accurate matching strategy. + /// + Exact +} diff --git a/src/ImageSharp/Processing/Processors/Quantization/EuclideanPixelMap{TPixel,TCache}.cs b/src/ImageSharp/Processing/Processors/Quantization/EuclideanPixelMap{TPixel,TCache}.cs new file mode 100644 index 0000000000..5b0c7252cb --- /dev/null +++ b/src/ImageSharp/Processing/Processors/Quantization/EuclideanPixelMap{TPixel,TCache}.cs @@ -0,0 +1,184 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Processing.Processors.Quantization; + +/// +/// Gets the closest color to the supplied color based upon the Euclidean distance. +/// +/// The pixel format. +/// The cache type. +/// +/// This class is not thread safe and should not be accessed in parallel. +/// Doing so will result in non-idempotent results. +/// +internal sealed class EuclideanPixelMap : PixelMap + where TPixel : unmanaged, IPixel + where TCache : struct, IColorIndexCache +{ + private Rgba32[] rgbaPalette; + + // Do not make readonly. It's a mutable struct. +#pragma warning disable IDE0044 // Add readonly modifier + private TCache cache; +#pragma warning restore IDE0044 // Add readonly modifier + + private readonly Configuration configuration; + + /// + /// Initializes a new instance of the class. + /// + /// Specifies the settings and resources for the pixel map's operations. + /// Defines the color palette used for pixel mapping. + public EuclideanPixelMap(Configuration configuration, ReadOnlyMemory palette) + { + this.configuration = configuration; + this.Palette = palette; + this.rgbaPalette = new Rgba32[palette.Length]; + this.cache = TCache.Create(configuration.MemoryAllocator); + PixelOperations.Instance.ToRgba32(configuration, this.Palette.Span, this.rgbaPalette); + } + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public override int GetClosestColor(TPixel color, out TPixel match) + { + ref TPixel paletteRef = ref MemoryMarshal.GetReference(this.Palette.Span); + Rgba32 rgba = color.ToRgba32(); + + if (this.cache.TryGetValue(rgba, out short index)) + { + match = Unsafe.Add(ref paletteRef, (ushort)index); + return index; + } + + return this.GetClosestColorSlow(rgba, ref paletteRef, out match); + } + + /// + public override void Clear(ReadOnlyMemory palette) + { + this.Palette = palette; + this.rgbaPalette = new Rgba32[palette.Length]; + PixelOperations.Instance.ToRgba32(this.configuration, this.Palette.Span, this.rgbaPalette); + this.cache.Clear(); + } + + [MethodImpl(InliningOptions.ColdPath)] + private int GetClosestColorSlow(Rgba32 rgba, ref TPixel paletteRef, out TPixel match) + { + // Loop through the palette and find the nearest match. + int index = 0; + float leastDistance = float.MaxValue; + for (int i = 0; i < this.rgbaPalette.Length; i++) + { + Rgba32 candidate = this.rgbaPalette[i]; + if (candidate.PackedValue == rgba.PackedValue) + { + index = i; + break; + } + + float distance = DistanceSquared(rgba, candidate); + if (distance == 0) + { + index = i; + break; + } + + if (distance < leastDistance) + { + index = i; + leastDistance = distance; + } + } + + // Now I have the index, pop it into the cache for next time + _ = this.cache.TryAdd(rgba, (short)index); + match = Unsafe.Add(ref paletteRef, (uint)index); + + return index; + } + + /// + /// Returns the Euclidean distance squared between two specified points. + /// + /// The first point. + /// The second point. + /// The distance squared. + [MethodImpl(InliningOptions.ShortMethod)] + private static float DistanceSquared(Rgba32 a, Rgba32 b) + { + float deltaR = a.R - b.R; + float deltaG = a.G - b.G; + float deltaB = a.B - b.B; + float deltaA = a.A - b.A; + return (deltaR * deltaR) + (deltaG * deltaG) + (deltaB * deltaB) + (deltaA * deltaA); + } + + /// + public override void Dispose() => this.cache.Dispose(); +} + +/// +/// Represents a map of colors to indices. +/// +/// The pixel format. +internal abstract class PixelMap : IDisposable + where TPixel : unmanaged, IPixel +{ + /// + /// Gets the color palette of this . + /// + public ReadOnlyMemory Palette { get; private protected set; } + + /// + /// Returns the closest color in the palette and the index of that pixel. + /// + /// The color to match. + /// The matched color. + /// + /// The index. + /// + public abstract int GetClosestColor(TPixel color, out TPixel match); + + /// + /// Clears the map, resetting it to use the given palette. + /// + /// The color palette to map from. + public abstract void Clear(ReadOnlyMemory palette); + + /// + public abstract void Dispose(); +} + +/// +/// A factory for creating instances. +/// +internal static class PixelMapFactory +{ + /// + /// Creates a new instance. + /// + /// The pixel format. + /// The configuration. + /// The color palette to map from. + /// The color matching mode. + /// + /// The . + /// + public static PixelMap Create( + Configuration configuration, + ReadOnlyMemory palette, + ColorMatchingMode colorMatchingMode) + where TPixel : unmanaged, IPixel => colorMatchingMode switch + { + ColorMatchingMode.Hybrid => new EuclideanPixelMap(configuration, palette), + ColorMatchingMode.Exact => new EuclideanPixelMap(configuration, palette), + _ => new EuclideanPixelMap(configuration, palette), + }; +} diff --git a/src/ImageSharp/Processing/Processors/Quantization/EuclideanPixelMap{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/EuclideanPixelMap{TPixel}.cs deleted file mode 100644 index 4fd37d479d..0000000000 --- a/src/ImageSharp/Processing/Processors/Quantization/EuclideanPixelMap{TPixel}.cs +++ /dev/null @@ -1,258 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Six Labors Split License. - -using System.Buffers; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using SixLabors.ImageSharp.Memory; -using SixLabors.ImageSharp.PixelFormats; - -namespace SixLabors.ImageSharp.Processing.Processors.Quantization; - -/// -/// Gets the closest color to the supplied color based upon the Euclidean distance. -/// -/// The pixel format. -/// -/// This class is not thread safe and should not be accessed in parallel. -/// Doing so will result in non-idempotent results. -/// -internal sealed class EuclideanPixelMap : IDisposable - where TPixel : unmanaged, IPixel -{ - private Rgba32[] rgbaPalette; - private int transparentIndex; - private readonly TPixel transparentMatch; - - /// - /// Do not make this readonly! Struct value would be always copied on non-readonly method calls. - /// - private ColorDistanceCache cache; - private readonly Configuration configuration; - - /// - /// Initializes a new instance of the class. - /// - /// The configuration. - /// The color palette to map from. - public EuclideanPixelMap(Configuration configuration, ReadOnlyMemory palette) - : this(configuration, palette, -1) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The configuration. - /// The color palette to map from. - /// An explicit index at which to match transparent pixels. - public EuclideanPixelMap(Configuration configuration, ReadOnlyMemory palette, int transparentIndex = -1) - { - this.configuration = configuration; - this.Palette = palette; - this.rgbaPalette = new Rgba32[palette.Length]; - this.cache = new ColorDistanceCache(configuration.MemoryAllocator); - PixelOperations.Instance.ToRgba32(configuration, this.Palette.Span, this.rgbaPalette); - - this.transparentIndex = transparentIndex; - this.transparentMatch = TPixel.FromRgba32(default); - } - - /// - /// Gets the color palette of this . - /// The palette memory is owned by the palette source that created it. - /// - public ReadOnlyMemory Palette { get; private set; } - - /// - /// Returns the closest color in the palette and the index of that pixel. - /// The palette contents must match the one used in the constructor. - /// - /// The color to match. - /// The matched color. - /// The index. - [MethodImpl(InliningOptions.ShortMethod)] - public int GetClosestColor(TPixel color, out TPixel match) - { - ref TPixel paletteRef = ref MemoryMarshal.GetReference(this.Palette.Span); - Rgba32 rgba = color.ToRgba32(); - - // Check if the color is in the lookup table - if (!this.cache.TryGetValue(rgba, out short index)) - { - return this.GetClosestColorSlow(rgba, ref paletteRef, out match); - } - - match = Unsafe.Add(ref paletteRef, (ushort)index); - return index; - } - - /// - /// Clears the map, resetting it to use the given palette. - /// - /// The color palette to map from. - public void Clear(ReadOnlyMemory palette) - { - this.Palette = palette; - this.rgbaPalette = new Rgba32[palette.Length]; - PixelOperations.Instance.ToRgba32(this.configuration, this.Palette.Span, this.rgbaPalette); - this.transparentIndex = -1; - this.cache.Clear(); - } - - /// - /// Allows setting the transparent index after construction. - /// - /// An explicit index at which to match transparent pixels. - public void SetTransparentIndex(int index) - { - if (index != this.transparentIndex) - { - this.cache.Clear(); - } - - this.transparentIndex = index; - } - - [MethodImpl(InliningOptions.ShortMethod)] - private int GetClosestColorSlow(Rgba32 rgba, ref TPixel paletteRef, out TPixel match) - { - // Loop through the palette and find the nearest match. - int index = 0; - - if (this.transparentIndex >= 0 && rgba == default) - { - // We have explicit instructions. No need to search. - index = this.transparentIndex; - this.cache.Add(rgba, (byte)index); - match = this.transparentMatch; - return index; - } - - float leastDistance = float.MaxValue; - for (int i = 0; i < this.rgbaPalette.Length; i++) - { - Rgba32 candidate = this.rgbaPalette[i]; - float distance = DistanceSquared(rgba, candidate); - - // If it's an exact match, exit the loop - if (distance == 0) - { - index = i; - break; - } - - if (distance < leastDistance) - { - // Less than... assign. - index = i; - leastDistance = distance; - } - } - - // Now I have the index, pop it into the cache for next time - this.cache.Add(rgba, (byte)index); - match = Unsafe.Add(ref paletteRef, (uint)index); - return index; - } - - /// - /// Returns the Euclidean distance squared between two specified points. - /// - /// The first point. - /// The second point. - /// The distance squared. - [MethodImpl(InliningOptions.ShortMethod)] - private static float DistanceSquared(Rgba32 a, Rgba32 b) - { - float deltaR = a.R - b.R; - float deltaG = a.G - b.G; - float deltaB = a.B - b.B; - float deltaA = a.A - b.A; - return (deltaR * deltaR) + (deltaG * deltaG) + (deltaB * deltaB) + (deltaA * deltaA); - } - - public void Dispose() => this.cache.Dispose(); - - /// - /// A cache for storing color distance matching results. - /// - /// - /// - /// The granularity of the cache has been determined based upon the current - /// suite of test images and provides the lowest possible memory usage while - /// providing enough match accuracy. - /// Entry count is currently limited to 2335905 entries (4MB). - /// - /// - private unsafe struct ColorDistanceCache : IDisposable - { - private const int IndexRBits = 5; - private const int IndexGBits = 5; - private const int IndexBBits = 5; - private const int IndexABits = 6; - private const int IndexRCount = (1 << IndexRBits) + 1; - private const int IndexGCount = (1 << IndexGBits) + 1; - private const int IndexBCount = (1 << IndexBBits) + 1; - private const int IndexACount = (1 << IndexABits) + 1; - private const int RShift = 8 - IndexRBits; - private const int GShift = 8 - IndexGBits; - private const int BShift = 8 - IndexBBits; - private const int AShift = 8 - IndexABits; - private const int Entries = IndexRCount * IndexGCount * IndexBCount * IndexACount; - private MemoryHandle tableHandle; - private readonly IMemoryOwner table; - private readonly short* tablePointer; - - public ColorDistanceCache(MemoryAllocator allocator) - { - this.table = allocator.Allocate(Entries); - this.table.GetSpan().Fill(-1); - this.tableHandle = this.table.Memory.Pin(); - this.tablePointer = (short*)this.tableHandle.Pointer; - } - - [MethodImpl(InliningOptions.ShortMethod)] - public readonly void Add(Rgba32 rgba, byte index) - { - int idx = GetPaletteIndex(rgba); - this.tablePointer[idx] = index; - } - - [MethodImpl(InliningOptions.ShortMethod)] - public readonly bool TryGetValue(Rgba32 rgba, out short match) - { - int idx = GetPaletteIndex(rgba); - match = this.tablePointer[idx]; - return match > -1; - } - - /// - /// Clears the cache resetting each entry to empty. - /// - [MethodImpl(InliningOptions.ShortMethod)] - public readonly void Clear() => this.table.GetSpan().Fill(-1); - - [MethodImpl(InliningOptions.ShortMethod)] - private static int GetPaletteIndex(Rgba32 rgba) - { - int rIndex = rgba.R >> RShift; - int gIndex = rgba.G >> GShift; - int bIndex = rgba.B >> BShift; - int aIndex = rgba.A >> AShift; - - return (aIndex * (IndexRCount * IndexGCount * IndexBCount)) + - (rIndex * (IndexGCount * IndexBCount)) + - (gIndex * IndexBCount) + bIndex; - } - - public void Dispose() - { - if (this.table != null) - { - this.tableHandle.Dispose(); - this.table.Dispose(); - } - } - } -} diff --git a/src/ImageSharp/Processing/Processors/Quantization/IColorIndexCache.cs b/src/ImageSharp/Processing/Processors/Quantization/IColorIndexCache.cs new file mode 100644 index 0000000000..32d95137bc --- /dev/null +++ b/src/ImageSharp/Processing/Processors/Quantization/IColorIndexCache.cs @@ -0,0 +1,569 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Buffers; +using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Processing.Processors.Quantization; + +/// +/// Represents a cache used for efficiently retrieving palette indices for colors. +/// +internal interface IColorIndexCache : IDisposable +{ + /// + /// Adds a color to the cache. + /// + /// The color to add. + /// The index of the color in the palette. + /// + /// if the color was added; otherwise, . + /// + public bool TryAdd(Rgba32 color, short value); + + /// + /// Gets the index of the color in the palette. + /// + /// The color to get the index for. + /// The index of the color in the palette. + /// + /// if the color is in the palette; otherwise, . + /// + public bool TryGetValue(Rgba32 color, out short value); + + /// + /// Clears the cache. + /// + public void Clear(); +} + +/// +/// Represents a cache used for efficiently retrieving palette indices for colors. +/// +/// The type of the cache. +internal interface IColorIndexCache : IColorIndexCache + where T : struct, IColorIndexCache +{ + /// + /// Creates a new instance of the cache. + /// + /// The memory allocator to use. + /// + /// The new instance of the cache. + /// + public static abstract T Create(MemoryAllocator allocator); +} + +/// +/// A hybrid color distance cache that combines a small, fixed-capacity exact-match dictionary +/// (ExactCache, ~4–5 KB for up to 512 entries) with a coarse lookup table (CoarseCache) for 5,5,5,6 precision. +/// +/// +/// ExactCache provides O(1) lookup for common cases using a simple 256-entry hash-based dictionary, while CoarseCache +/// quantizes RGB channels to 5 bits (yielding 32^3 buckets) and alpha to 6 bits, storing up to 4 alpha entries per bucket +/// (a design chosen based on probability theory to capture most real-world variations) for a total memory footprint of +/// roughly 576 KB. Lookups and insertions are performed in constant time, making the overall design both fast and memory-predictable. +/// +internal unsafe struct HybridCache : IColorIndexCache +{ + private CoarseCache coarseCache; + private AccurateCache accurateCache; + + public HybridCache(MemoryAllocator allocator) + { + this.accurateCache = AccurateCache.Create(allocator); + this.coarseCache = CoarseCache.Create(allocator); + } + + /// + public static HybridCache Create(MemoryAllocator allocator) => new(allocator); + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public bool TryAdd(Rgba32 color, short index) + { + if (this.accurateCache.TryAdd(color, index)) + { + return true; + } + + return this.coarseCache.TryAdd(color, index); + } + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public readonly bool TryGetValue(Rgba32 color, out short value) + { + if (this.accurateCache.TryGetValue(color, out value)) + { + return true; + } + + return this.coarseCache.TryGetValue(color, out value); + } + + /// + public readonly void Clear() + { + this.accurateCache.Clear(); + this.coarseCache.Clear(); + } + + /// + public void Dispose() + { + this.accurateCache.Dispose(); + this.coarseCache.Dispose(); + } +} + +/// +/// A coarse cache for color distance lookups that uses a fixed-size lookup table. +/// +/// +/// This cache uses a fixed lookup table with 2,097,152 bins, each storing a 2-byte value, +/// resulting in a memory usage of approximately 4 MB. Lookups and insertions are +/// performed in constant time (O(1)) via direct table indexing. This design is optimized for +/// speed while maintaining a predictable, fixed memory footprint. +/// +internal unsafe struct CoarseCache : IColorIndexCache +{ + private const int IndexRBits = 5; + private const int IndexGBits = 5; + private const int IndexBBits = 5; + private const int IndexABits = 6; + private const int IndexRCount = 1 << IndexRBits; // 32 bins for red + private const int IndexGCount = 1 << IndexGBits; // 32 bins for green + private const int IndexBCount = 1 << IndexBBits; // 32 bins for blue + private const int IndexACount = 1 << IndexABits; // 64 bins for alpha + private const int TotalBins = IndexRCount * IndexGCount * IndexBCount * IndexACount; // 2,097,152 bins + + private readonly IMemoryOwner binsOwner; + private readonly short* binsPointer; + private MemoryHandle binsHandle; + + private CoarseCache(MemoryAllocator allocator) + { + this.binsOwner = allocator.Allocate(TotalBins); + this.binsOwner.GetSpan().Fill(-1); + this.binsHandle = this.binsOwner.Memory.Pin(); + this.binsPointer = (short*)this.binsHandle.Pointer; + } + + /// + public static CoarseCache Create(MemoryAllocator allocator) => new(allocator); + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public readonly bool TryAdd(Rgba32 color, short value) + { + this.binsPointer[GetCoarseIndex(color)] = value; + return true; + } + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public readonly bool TryGetValue(Rgba32 color, out short value) + { + value = this.binsPointer[GetCoarseIndex(color)]; + return value > -1; // Coarse match found + } + + [MethodImpl(InliningOptions.ShortMethod)] + private static int GetCoarseIndex(Rgba32 color) + { + int rIndex = color.R >> (8 - IndexRBits); + int gIndex = color.G >> (8 - IndexGBits); + int bIndex = color.B >> (8 - IndexBBits); + int aIndex = color.A >> (8 - IndexABits); + + return (aIndex * IndexRCount * IndexGCount * IndexBCount) + + (rIndex * IndexGCount * IndexBCount) + + (gIndex * IndexBCount) + + bIndex; + } + + /// + public readonly void Clear() + => this.binsOwner.GetSpan().Fill(-1); + + /// + public void Dispose() + { + this.binsHandle.Dispose(); + this.binsOwner.Dispose(); + } +} + +/// +/// +/// CoarseCache is a fast, low-memory lookup structure for caching palette indices associated with RGBA values, +/// using a quantized representation of 5,5,5,6 (RGB: 5 bits each, Alpha: 6 bits). +/// +/// +/// The cache quantizes the RGB channels to 5 bits each, resulting in 32 levels per channel and a total of 32³ = 32,768 buckets. +/// Each bucket is represented by an , which holds a small, inline array of alpha entries. +/// Each alpha entry stores the alpha value quantized to 6 bits (0–63) along with a palette index (a 16-bit value). +/// +/// +/// Performance Characteristics: +/// - Lookup: O(1) for computing the bucket index from the RGB channels, plus a small constant time (up to 8 iterations) +/// to search through the alpha entries in the bucket. +/// - Insertion: O(1) for bucket index computation and a quick linear search over a very small (fixed) number of entries. +/// +/// +/// Memory Characteristics: +/// - The cache consists of 32,768 buckets. +/// - Each is implemented using an inline array with a capacity of 8 entries. +/// - Each bucket occupies approximately 1 byte (Count) + (8 entries × 3 bytes each) ≈ 25 bytes. +/// - Overall, the buckets occupy roughly 32,768 × 25 bytes = 819,200 bytes (≈ 800 KB). +/// +/// +/// This design provides nearly constant-time lookup and insertion with minimal memory usage, +/// making it ideal for applications such as color distance caching in images with a limited palette (up to 256 entries). +/// +/// +internal unsafe struct CoarseCacheLite : IColorIndexCache +{ + // Use 5 bits per channel for R, G, and B: 32 levels each. + // Total buckets = 32^3 = 32768. + private const int RgbBits = 5; + private const int RgbShift = 8 - RgbBits; // 3 + private const int BucketCount = 1 << (RgbBits * 3); // 32768 + private readonly IMemoryOwner bucketsOwner; + private readonly AlphaBucket* buckets; + private MemoryHandle bucketHandle; + + private CoarseCacheLite(MemoryAllocator allocator) + { + this.bucketsOwner = allocator.Allocate(BucketCount, AllocationOptions.Clean); + this.bucketHandle = this.bucketsOwner.Memory.Pin(); + this.buckets = (AlphaBucket*)this.bucketHandle.Pointer; + } + + /// + public static CoarseCacheLite Create(MemoryAllocator allocator) => new(allocator); + + /// + public readonly bool TryAdd(Rgba32 color, short paletteIndex) + { + int bucketIndex = GetBucketIndex(color.R, color.G, color.B); + byte quantAlpha = QuantizeAlpha(color.A); + this.buckets[bucketIndex].Add(quantAlpha, paletteIndex); + return true; + } + + /// + public readonly bool TryGetValue(Rgba32 color, out short paletteIndex) + { + int bucketIndex = GetBucketIndex(color.R, color.G, color.B); + byte quantAlpha = QuantizeAlpha(color.A); + return this.buckets[bucketIndex].TryGetValue(quantAlpha, out paletteIndex); + } + + /// + public readonly void Clear() + { + Span bucketsSpan = this.bucketsOwner.GetSpan(); + bucketsSpan.Clear(); + } + + /// + public void Dispose() + { + this.bucketHandle.Dispose(); + this.bucketsOwner.Dispose(); + } + + [MethodImpl(InliningOptions.ShortMethod)] + private static int GetBucketIndex(byte r, byte g, byte b) + { + int qr = r >> RgbShift; + int qg = g >> RgbShift; + int qb = b >> RgbShift; + + // Combine the quantized channels into a single index. + return (qr << (RgbBits << 1)) | (qg << RgbBits) | qb; + } + + [MethodImpl(InliningOptions.ShortMethod)] + private static byte QuantizeAlpha(byte a) + + // Quantize to 6 bits: shift right by (8 - 6) = 2 bits. + => (byte)(a >> 2); + + public struct AlphaEntry + { + // Store the alpha value quantized to 6 bits (0..63) + public byte QuantizedAlpha; + public short PaletteIndex; + } + + public struct AlphaBucket + { + // Fixed capacity for alpha entries in this bucket. + // We choose a capacity of 8 for several reasons: + // + // 1. The alpha channel is quantized to 6 bits, so there are 64 possible distinct values. + // In the worst-case, a given RGB bucket might encounter up to 64 different alpha values. + // + // 2. However, in practice (based on probability theory and typical image data), + // the number of unique alpha values that actually occur for a given quantized RGB + // bucket is usually very small. If you randomly sample 8 values out of 64, + // the probability that these 4 samples are all unique is high if the distribution + // of alpha values is skewed or if only a few alpha values are used. + // + // 3. Statistically, for many real-world images, most RGB buckets will have only a couple + // of unique alpha values. Allocating 8 slots per bucket provides a good trade-off: + // it captures the common-case scenario while keeping overall memory usage low. + // + // 4. Even if more than 8 unique alpha values occur in a bucket, + // our design overwrites the first entry. This behavior gives us some "wriggle room" + // while preserving the most frequently encountered or most recent values. + public const int Capacity = 8; + public byte Count; + private InlineArray8 entries; + + [MethodImpl(InliningOptions.ShortMethod)] + public bool TryGetValue(byte quantizedAlpha, out short paletteIndex) + { + for (int i = 0; i < this.Count; i++) + { + ref AlphaEntry entry = ref this.entries[i]; + if (entry.QuantizedAlpha == quantizedAlpha) + { + paletteIndex = entry.PaletteIndex; + return true; + } + } + + paletteIndex = -1; + return false; + } + + [MethodImpl(InliningOptions.ShortMethod)] + public void Add(byte quantizedAlpha, short paletteIndex) + { + // Check for an existing entry with the same quantized alpha. + for (int i = 0; i < this.Count; i++) + { + ref AlphaEntry entry = ref this.entries[i]; + if (entry.QuantizedAlpha == quantizedAlpha) + { + // Update palette index if found. + entry.PaletteIndex = paletteIndex; + return; + } + } + + // If there's room, add a new entry. + if (this.Count < Capacity) + { + ref AlphaEntry newEntry = ref this.entries[this.Count]; + newEntry.QuantizedAlpha = quantizedAlpha; + newEntry.PaletteIndex = paletteIndex; + this.Count++; + } + else + { + // Bucket is full. Overwrite the first entry to give us some wriggle room. + this.entries[0].QuantizedAlpha = quantizedAlpha; + this.entries[0].PaletteIndex = paletteIndex; + } + } + } +} + +/// +/// A fixed-capacity dictionary with exactly 512 entries mapping a key +/// to a value. +/// +/// +/// The dictionary is implemented using a fixed array of 512 buckets and an entries array +/// of the same size. The bucket for a key is computed as (key & 0x1FF), and collisions are +/// resolved through a linked chain stored in the field. +/// The overall memory usage is approximately 4–5 KB. Both lookup and insertion operations are, +/// on average, O(1) since the bucket is determined via a simple bitmask and collision chains are +/// typically very short; in the worst-case, the number of iterations is bounded by 256. +/// This guarantees highly efficient and predictable performance for small, fixed-size color palettes. +/// +internal unsafe struct AccurateCache : IColorIndexCache +{ + // Buckets array: each bucket holds the index (0-based) into the entries array + // of the first entry in the chain, or -1 if empty. + private readonly IMemoryOwner bucketsOwner; + private MemoryHandle bucketsHandle; + private short* buckets; + + // Entries array: stores up to 256 entries. + private readonly IMemoryOwner entriesOwner; + private MemoryHandle entriesHandle; + private Entry* entries; + + public const int Capacity = 512; + + private AccurateCache(MemoryAllocator allocator) + { + this.Count = 0; + + // Allocate exactly 512 indexes for buckets. + this.bucketsOwner = allocator.Allocate(Capacity, AllocationOptions.Clean); + Span bucketSpan = this.bucketsOwner.GetSpan(); + bucketSpan.Fill(-1); + this.bucketsHandle = this.bucketsOwner.Memory.Pin(); + this.buckets = (short*)this.bucketsHandle.Pointer; + + // Allocate exactly 512 entries. + this.entriesOwner = allocator.Allocate(Capacity, AllocationOptions.Clean); + this.entriesHandle = this.entriesOwner.Memory.Pin(); + this.entries = (Entry*)this.entriesHandle.Pointer; + } + + public int Count { get; private set; } + + /// + public static AccurateCache Create(MemoryAllocator allocator) => new(allocator); + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public bool TryAdd(Rgba32 color, short value) + { + if (this.Count == Capacity) + { + return false; // Dictionary is full. + } + + uint key = color.PackedValue; + + // The key is a 32-bit unsigned integer representing an RGBA color, where the bytes are laid out as R|G|B|A + // (with R in the most significant byte and A in the least significant). + // To compute the bucket index: + // 1. (key >> 16) extracts the top 16 bits, effectively giving us the R and G channels. + // 2. (key >> 8) shifts the key right by 8 bits, bringing R, G, and B into the lower 24 bits (dropping A). + // 3. XORing these two values with the original key mixes bits from all four channels (R, G, B, and A), + // which helps to counteract situations where one or more channels have a limited range. + // 4. Finally, we apply a bitmask of 0x1FF to keep only the lowest 9 bits, ensuring the result is between 0 and 511, + // which corresponds to our fixed bucket count of 512. + int bucket = (int)(((key >> 16) ^ (key >> 8) ^ key) & 0x1FF); + int i = this.buckets[bucket]; + + // Traverse the collision chain. + Entry* entries = this.entries; + while (i != -1) + { + Entry e = entries[i]; + if (e.Key == key) + { + // Key already exists; do not overwrite. + return false; + } + + i = e.Next; + } + + short index = (short)this.Count; + this.Count++; + + // Insert the new entry: + entries[index].Key = key; + entries[index].Value = value; + + // Link this new entry into the bucket chain. + entries[index].Next = this.buckets[bucket]; + this.buckets[bucket] = index; + return true; + } + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public bool TryGetValue(Rgba32 color, out short value) + { + uint key = color.PackedValue; + int bucket = (int)(((key >> 16) ^ (key >> 8) ^ key) & 0x1FF); + int i = this.buckets[bucket]; + + // If the bucket is empty, return immediately. + if (i == -1) + { + value = -1; + return false; + } + + // Traverse the chain. + Entry* entries = this.entries; + do + { + Entry e = entries[i]; + if (e.Key == key) + { + value = e.Value; + return true; + } + + i = e.Next; + } + while (i != -1); + + value = -1; + return false; + } + + /// + /// Clears the dictionary. + /// + public void Clear() + { + Span bucketSpan = this.bucketsOwner.GetSpan(); + bucketSpan.Fill(-1); + this.Count = 0; + } + + public void Dispose() + { + this.bucketsHandle.Dispose(); + this.bucketsOwner.Dispose(); + this.entriesHandle.Dispose(); + this.entriesOwner.Dispose(); + this.buckets = null; + this.entries = null; + } + + private struct Entry + { + public uint Key; // The key (packed RGBA) + public short Value; // The value; -1 means unused. + public short Next; // Index of the next entry in the chain, or -1 if none. + } +} + +/// +/// Represents a cache that does not store any values. +/// It allows adding colors, but always returns false when trying to retrieve them. +/// +internal readonly struct NullCache : IColorIndexCache +{ + /// + public static NullCache Create(MemoryAllocator allocator) => default; + + /// + public bool TryAdd(Rgba32 color, short value) => true; + + /// + public bool TryGetValue(Rgba32 color, out short value) + { + value = -1; + return false; + } + + /// + public void Clear() + { + } + + /// + public void Dispose() + { + } +} diff --git a/src/ImageSharp/Processing/Processors/Quantization/IQuantizer.cs b/src/ImageSharp/Processing/Processors/Quantization/IQuantizer.cs index 9d5b606040..02dce8ca48 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/IQuantizer.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/IQuantizer.cs @@ -13,7 +13,7 @@ public interface IQuantizer /// /// Gets the quantizer options defining quantization rules. /// - QuantizerOptions Options { get; } + public QuantizerOptions Options { get; } /// /// Creates the generic frame quantizer. @@ -21,7 +21,7 @@ public interface IQuantizer /// The to configure internal operations. /// The pixel format. /// The . - IQuantizer CreatePixelSpecificQuantizer(Configuration configuration) + public IQuantizer CreatePixelSpecificQuantizer(Configuration configuration) where TPixel : unmanaged, IPixel; /// @@ -31,6 +31,6 @@ public interface IQuantizer /// The to configure internal operations. /// The options to create the quantizer with. /// The . - IQuantizer CreatePixelSpecificQuantizer(Configuration configuration, QuantizerOptions options) + public IQuantizer CreatePixelSpecificQuantizer(Configuration configuration, QuantizerOptions options) where TPixel : unmanaged, IPixel; } diff --git a/src/ImageSharp/Processing/Processors/Quantization/IQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/IQuantizer{TPixel}.cs index 35bbb1289e..1e6420eaa9 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/IQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/IQuantizer{TPixel}.cs @@ -16,26 +16,26 @@ public interface IQuantizer : IDisposable /// /// Gets the configuration. /// - Configuration Configuration { get; } + public Configuration Configuration { get; } /// /// Gets the quantizer options defining quantization rules. /// - QuantizerOptions Options { get; } + public QuantizerOptions Options { get; } /// /// Gets the quantized color palette. /// /// - /// The palette has not been built via . + /// The palette has not been built via . /// - ReadOnlyMemory Palette { get; } + public ReadOnlyMemory Palette { get; } /// /// Adds colors to the quantized palette from the given pixel source. /// /// The of source pixels to register. - void AddPaletteColors(Buffer2DRegion pixelRegion); + public void AddPaletteColors(in Buffer2DRegion pixelRegion); /// /// Quantizes an image frame and return the resulting output pixels. @@ -46,10 +46,10 @@ public interface IQuantizer : IDisposable /// A representing a quantized version of the source frame pixels. /// /// - /// Only executes the second (quantization) step. The palette has to be built by calling . - /// To run both steps, use . + /// Only executes the second (quantization) step. The palette has to be built by calling . + /// To run both steps, use . /// - IndexedImageFrame QuantizeFrame(ImageFrame source, Rectangle bounds); + public IndexedImageFrame QuantizeFrame(ImageFrame source, Rectangle bounds); /// /// Returns the index and color from the quantized palette corresponding to the given color. @@ -57,7 +57,7 @@ public interface IQuantizer : IDisposable /// The color to match. /// The matched color. /// The index. - byte GetQuantizedColor(TPixel color, out TPixel match); + public byte GetQuantizedColor(TPixel color, out TPixel match); // TODO: Enable bulk operations. // void GetQuantizedColors(ReadOnlySpan colors, ReadOnlySpan palette, Span indices, Span matches); diff --git a/src/ImageSharp/Processing/Processors/Quantization/IQuantizingPixelRowDelegate{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/IQuantizingPixelRowDelegate{TPixel}.cs new file mode 100644 index 0000000000..3cf4c93d62 --- /dev/null +++ b/src/ImageSharp/Processing/Processors/Quantization/IQuantizingPixelRowDelegate{TPixel}.cs @@ -0,0 +1,21 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using SixLabors.ImageSharp.PixelFormats; + +namespace SixLabors.ImageSharp.Processing.Processors.Quantization; + +/// +/// Defines a delegate for processing a row of pixels in an image for quantization. +/// +/// Represents a pixel type that can be processed in a quantizing operation. +internal interface IQuantizingPixelRowDelegate + where TPixel : unmanaged, IPixel +{ + /// + /// Processes a row of pixels for quantization. + /// + /// The row of pixels to process. + /// The index of the row being processed. + public void Invoke(ReadOnlySpan row, int rowIndex); +} diff --git a/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs index 8b39b74579..07596b68a8 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs @@ -16,11 +16,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization; /// /// /// The pixel format. -[SuppressMessage( - "Design", - "CA1001:Types that own disposable fields should be disposable", - Justification = "https://github.com/dotnet/roslyn-analyzers/issues/6151")] +#pragma warning disable CA1001 // Types that own disposable fields should be disposable +// See https://github.com/dotnet/roslyn-analyzers/issues/6151 public struct OctreeQuantizer : IQuantizer +#pragma warning restore CA1001 // Types that own disposable fields should be disposable where TPixel : unmanaged, IPixel { private readonly int maxColors; @@ -28,14 +27,14 @@ public struct OctreeQuantizer : IQuantizer private readonly Octree octree; private readonly IMemoryOwner paletteOwner; private ReadOnlyMemory palette; - private EuclideanPixelMap? pixelMap; + private PixelMap? pixelMap; private readonly bool isDithering; private bool isDisposed; /// /// Initializes a new instance of the struct. /// - /// The configuration which allows altering default behaviour or extending the library. + /// The configuration which allows altering default behavior or extending the library. /// The quantizer options defining quantization rules. [MethodImpl(InliningOptions.ShortMethod)] public OctreeQuantizer(Configuration configuration, QuantizerOptions options) @@ -45,7 +44,7 @@ public struct OctreeQuantizer : IQuantizer this.maxColors = this.Options.MaxColors; this.bitDepth = Numerics.Clamp(ColorNumerics.GetBitsNeededForColorDepth(this.maxColors), 1, 8); - this.octree = new Octree(this.bitDepth); + this.octree = new Octree(configuration, this.bitDepth, this.maxColors, this.Options.TransparencyThreshold); this.paletteOwner = configuration.MemoryAllocator.Allocate(this.maxColors, AllocationOptions.Clean); this.pixelMap = default; this.palette = default; @@ -60,64 +59,41 @@ public struct OctreeQuantizer : IQuantizer public QuantizerOptions Options { get; } /// - public readonly ReadOnlyMemory Palette + public ReadOnlyMemory Palette { get { - QuantizerUtilities.CheckPaletteState(in this.palette); + if (this.palette.IsEmpty) + { + this.ResolvePalette(); + QuantizerUtilities.CheckPaletteState(in this.palette); + } + return this.palette; } } /// - public void AddPaletteColors(Buffer2DRegion pixelRegion) + public readonly void AddPaletteColors(in Buffer2DRegion pixelRegion) { - using (IMemoryOwner buffer = this.Configuration.MemoryAllocator.Allocate(pixelRegion.Width)) - { - Span bufferSpan = buffer.GetSpan(); - - // Loop through each row - for (int y = 0; y < pixelRegion.Height; y++) - { - Span row = pixelRegion.DangerousGetRowSpan(y); - PixelOperations.Instance.ToRgba32(this.Configuration, row, bufferSpan); - - for (int x = 0; x < bufferSpan.Length; x++) - { - Rgba32 rgba = bufferSpan[x]; - - // Add the color to the Octree - this.octree.AddColor(rgba); - } - } - } + PixelRowDelegate pixelRowDelegate = new(this.octree); + QuantizerUtilities.AddPaletteColors, TPixel, Rgba32, PixelRowDelegate>( + ref Unsafe.AsRef(in this), + in pixelRegion, + in pixelRowDelegate); + } - int paletteIndex = 0; + private void ResolvePalette() + { + short paletteIndex = 0; Span paletteSpan = this.paletteOwner.GetSpan(); - // On very rare occasions, (blur.png), the quantizer does not preserve a - // transparent entry when palletizing the captured colors. - // To workaround this we ensure the palette ends with the default color - // for higher bit depths. Lower bit depths will correctly reduce the palette. - // TODO: Investigate more evenly reduced palette reduction. - int max = this.maxColors; - if (this.bitDepth >= 4) - { - max--; - } - - this.octree.Palletize(paletteSpan, max, ref paletteIndex); + this.octree.Palettize(paletteSpan, ref paletteIndex); ReadOnlyMemory result = this.paletteOwner.Memory[..paletteSpan.Length]; - // When called multiple times by QuantizerUtilities.BuildPalette - // this prevents memory churn caused by reallocation. - if (this.pixelMap is null) - { - this.pixelMap = new EuclideanPixelMap(this.Configuration, result); - } - else + if (this.isDithering) { - this.pixelMap.Clear(result); + this.pixelMap = PixelMapFactory.Create(this.Configuration, result, this.Options.ColorMatchingMode); } this.palette = result; @@ -132,18 +108,19 @@ public struct OctreeQuantizer : IQuantizer [MethodImpl(InliningOptions.ShortMethod)] public readonly byte GetQuantizedColor(TPixel color, out TPixel match) { - // Octree only maps the RGB component of a color - // so cannot tell the difference between a fully transparent - // pixel and a black one. - if (this.isDithering || color.Equals(default)) + // Due to the addition of new colors by dithering that are not part of the original histogram, + // the octree nodes might not match the correct color. + // In this case, we must use the pixel map to get the closest color. + if (this.isDithering) { return (byte)this.pixelMap!.GetClosestColor(color, out match); } ref TPixel paletteRef = ref MemoryMarshal.GetReference(this.palette.Span); - byte index = (byte)this.octree.GetPaletteIndex(color); - match = Unsafe.Add(ref paletteRef, index); - return index; + + int index = this.octree.GetPaletteIndex(color); + match = Unsafe.Add(ref paletteRef, (nuint)index); + return (byte)index; } /// @@ -155,413 +132,529 @@ public struct OctreeQuantizer : IQuantizer this.paletteOwner.Dispose(); this.pixelMap?.Dispose(); this.pixelMap = null; + this.octree.Dispose(); } } + private readonly struct PixelRowDelegate : IQuantizingPixelRowDelegate + { + private readonly Octree octree; + + public PixelRowDelegate(Octree octree) => this.octree = octree; + + public void Invoke(ReadOnlySpan row, int rowIndex) => this.octree.AddColors(row); + } + /// - /// Class which does the actual quantization. + /// A hexadecatree-based color quantization structure used for fast color distance lookups and palette generation. + /// This tree maintains a fixed pool of nodes (capacity 4096) where each node can have up to 16 children, stores + /// color accumulation data, and supports dynamic node allocation and reduction. It offers near-constant-time insertions + /// and lookups while consuming roughly 240 KB for the node pool. /// - private sealed class Octree + internal sealed class Octree : IDisposable { - /// - /// The root of the Octree - /// - private readonly OctreeNode root; + // The memory allocator. + private readonly MemoryAllocator allocator; - /// - /// Maximum number of significant bits in the image - /// + // Pooled buffer for OctreeNodes. + private readonly IMemoryOwner nodesOwner; + + // Reducible nodes: one per level; we use an integer index; -1 means “no node.” + private readonly short[] reducibleNodes; + + // Maximum number of allowable colors. + private readonly int maxColors; + + // Maximum significant bits. private readonly int maxColorBits; - /// - /// Store the last node quantized - /// - private OctreeNode? previousNode; + // The threshold for transparent colors. + private readonly int transparencyThreshold255; - /// - /// Cache the previous color quantized - /// + // Instead of a reference to the root, we store the index of the root node. + // Index 0 is reserved for the root. + private readonly short rootIndex; + + // Running index for node allocation. Start at 1 so that index 0 is reserved for the root. + private short nextNode = 1; + + // Previously quantized node (index; -1 if none) and its color. + private int previousNode; private Rgba32 previousColor; + // Free list for reclaimed node indices. + private readonly Stack freeIndices = new(); + /// /// Initializes a new instance of the class. /// - /// - /// The maximum number of significant bits in the image - /// - public Octree(int maxColorBits) + /// The configuration which allows altering default behavior or extending the library. + /// The maximum number of significant bits in the image. + /// The maximum number of colors to allow in the palette. + /// The threshold for transparent colors. + public Octree( + Configuration configuration, + int maxColorBits, + int maxColors, + float transparencyThreshold) { this.maxColorBits = maxColorBits; + this.maxColors = maxColors; + this.transparencyThreshold255 = (int)(transparencyThreshold * 255F); this.Leaves = 0; - this.ReducibleNodes = new OctreeNode[9]; - this.root = new OctreeNode(0, this.maxColorBits, this); + this.previousNode = -1; this.previousColor = default; - this.previousNode = null; + + // Allocate a conservative buffer for nodes. + const int capacity = 4096; + this.allocator = configuration.MemoryAllocator; + this.nodesOwner = this.allocator.Allocate(capacity, AllocationOptions.Clean); + + // Create the reducible nodes array (one per level 0 .. maxColorBits-1). + this.reducibleNodes = new short[this.maxColorBits]; + this.reducibleNodes.AsSpan().Fill(-1); + + // Reserve index 0 for the root. + this.rootIndex = 0; + ref OctreeNode root = ref this.Nodes[this.rootIndex]; + root.Initialize(0, this.maxColorBits, this, this.rootIndex); } /// - /// Gets or sets the number of leaves in the tree + /// Gets or sets the number of leaves in the tree. /// - public int Leaves - { - [MethodImpl(InliningOptions.ShortMethod)] - get; + public int Leaves { get; set; } - [MethodImpl(InliningOptions.ShortMethod)] - set; - } + /// + /// Gets the full collection of nodes as a span. + /// + internal Span Nodes => this.nodesOwner.Memory.Span; /// - /// Gets the array of reducible nodes + /// Adds a span of colors to the octree. /// - private OctreeNode?[] ReducibleNodes + /// A span of color values to be added. + public void AddColors(ReadOnlySpan row) { - [MethodImpl(InliningOptions.ShortMethod)] - get; + for (int x = 0; x < row.Length; x++) + { + this.AddColor(row[x]); + } } /// - /// Add a given color value to the Octree + /// Add a color to the Octree. /// /// The color to add. - public void AddColor(Rgba32 color) + private void AddColor(Rgba32 color) { - // Check if this request is for the same color as the last + // Ensure that the tree is not already full. + if (this.nextNode >= this.Nodes.Length && this.freeIndices.Count == 0) + { + while (this.Leaves > this.maxColors) + { + this.Reduce(); + } + } + + // If the color is the same as the previous color, increment the node. + // Otherwise, add a new node. if (this.previousColor.Equals(color)) { - // If so, check if I have a previous node setup. - // This will only occur if the first color in the image - // happens to be black, with an alpha component of zero. - if (this.previousNode is null) + if (this.previousNode == -1) { this.previousColor = color; - this.root.AddColor(ref color, this.maxColorBits, 0, this); + OctreeNode.AddColor(this.rootIndex, color, this.maxColorBits, 0, this); } else { - // Just update the previous node - this.previousNode.Increment(ref color); + OctreeNode.Increment(this.previousNode, color, this); } } else { this.previousColor = color; - this.root.AddColor(ref color, this.maxColorBits, 0, this); + OctreeNode.AddColor(this.rootIndex, color, this.maxColorBits, 0, this); } } /// - /// Convert the nodes in the Octree to a palette with a maximum of colorCount colors + /// Construct the palette from the octree. /// - /// The palette to fill. - /// The maximum number of colors - /// The palette index, used to calculate the final size of the palette. - [MethodImpl(InliningOptions.ShortMethod)] - public void Palletize(Span palette, int colorCount, ref int paletteIndex) + /// The palette to construct. + /// The current palette index. + public void Palettize(Span palette, ref short paletteIndex) { - while (this.Leaves > colorCount) + while (this.Leaves > this.maxColors) { this.Reduce(); } - this.root.ConstructPalette(palette, ref paletteIndex); + this.Nodes[this.rootIndex].ConstructPalette(this, palette, ref paletteIndex); } /// - /// Get the palette index for the passed color + /// Get the palette index for the passed color. /// - /// The color to match. - /// - /// The index. - /// - [MethodImpl(InliningOptions.ShortMethod)] + /// The color to get the palette index for. + /// The . + [MethodImpl(MethodImplOptions.AggressiveInlining)] public int GetPaletteIndex(TPixel color) - { - Rgba32 rgba = color.ToRgba32(); - return this.root.GetPaletteIndex(ref rgba, 0); - } + => this.Nodes[this.rootIndex].GetPaletteIndex(color.ToRgba32(), 0, this); /// - /// Keep track of the previous node that was quantized + /// Track the previous node and color. /// - /// - /// The node last quantized - /// - [MethodImpl(InliningOptions.ShortMethod)] - public void TrackPrevious(OctreeNode node) => this.previousNode = node; + /// The node index. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void TrackPrevious(int nodeIndex) + => this.previousNode = nodeIndex; /// - /// Reduce the depth of the tree + /// Reduce the depth of the tree. /// private void Reduce() { // Find the deepest level containing at least one reducible node int index = this.maxColorBits - 1; - while ((index > 0) && (this.ReducibleNodes[index] is null)) + while ((index > 0) && (this.reducibleNodes[index] == -1)) { index--; } // Reduce the node most recently added to the list at level 'index' - OctreeNode node = this.ReducibleNodes[index]!; - this.ReducibleNodes[index] = node.NextReducible; + ref OctreeNode node = ref this.Nodes[this.reducibleNodes[index]]; + this.reducibleNodes[index] = node.NextReducibleIndex; // Decrement the leaf count after reducing the node - this.Leaves -= node.Reduce(); + node.Reduce(this); // And just in case I've reduced the last color to be added, and the next color to // be added is the same, invalidate the previousNode... - this.previousNode = null; + this.previousNode = -1; } - /// - /// Class which encapsulates each node in the tree - /// - public sealed class OctreeNode + // Allocate a new OctreeNode from the pooled buffer. + // First check the freeIndices stack. + internal short AllocateNode() { - /// - /// Pointers to any child nodes - /// - private readonly OctreeNode?[]? children; - - /// - /// Flag indicating that this is a leaf node - /// - private bool leaf; + if (this.freeIndices.Count > 0) + { + return this.freeIndices.Pop(); + } - /// - /// Number of pixels in this node - /// - private int pixelCount; + if (this.nextNode >= this.Nodes.Length) + { + return -1; + } - /// - /// Red component - /// - private int red; + short newIndex = this.nextNode; + this.nextNode++; + return newIndex; + } - /// - /// Green Component - /// - private int green; + /// + /// Free a node index, making it available for re-allocation. + /// + /// The index to free. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal void FreeNode(short index) + { + this.freeIndices.Push(index); + this.Leaves--; + } - /// - /// Blue component - /// - private int blue; + /// + public void Dispose() => this.nodesOwner.Dispose(); - /// - /// The index of this node in the palette - /// - private int paletteIndex; + [StructLayout(LayoutKind.Sequential)] + internal unsafe struct OctreeNode + { + public bool Leaf; + public int PixelCount; + public int Red; + public int Green; + public int Blue; + public int Alpha; + public short PaletteIndex; + public short NextReducibleIndex; + private InlineArray16 children; + + [UnscopedRef] + public Span Children => this.children; /// - /// Initializes a new instance of the class. + /// Initialize the . /// - /// The level in the tree = 0 - 7. + /// The level of the node. /// The number of significant color bits in the image. - /// The tree to which this node belongs. - public OctreeNode(int level, int colorBits, Octree octree) + /// The parent octree. + /// The index of the node. + public void Initialize(int level, int colorBits, Octree octree, short index) { - // Construct the new node - this.leaf = level == colorBits; - - this.red = this.green = this.blue = 0; - this.pixelCount = 0; - - // If a leaf, increment the leaf count - if (this.leaf) + // Construct the new node. + this.Leaf = level == colorBits; + this.Red = 0; + this.Green = 0; + this.Blue = 0; + this.Alpha = 0; + this.PixelCount = 0; + this.PaletteIndex = 0; + this.NextReducibleIndex = -1; + + // Always clear the Children array. + this.Children.Fill(-1); + + if (this.Leaf) { octree.Leaves++; - this.NextReducible = null; - this.children = null; } else { - // Otherwise add this to the reducible nodes - this.NextReducible = octree.ReducibleNodes[level]; - octree.ReducibleNodes[level] = this; - this.children = new OctreeNode[8]; + // Add this node to the reducible nodes list for its level. + this.NextReducibleIndex = octree.reducibleNodes[level]; + octree.reducibleNodes[level] = index; } } /// - /// Gets the next reducible node - /// - public OctreeNode? NextReducible - { - [MethodImpl(InliningOptions.ShortMethod)] - get; - } - - /// - /// Add a color into the tree + /// Add a color to the Octree. /// + /// The node index. /// The color to add. - /// The number of significant color bits. - /// The level in the tree. - /// The tree to which this node belongs. - public void AddColor(ref Rgba32 color, int colorBits, int level, Octree octree) + /// The number of significant color bits in the image. + /// The level of the node. + /// The parent octree. + public static void AddColor(int nodeIndex, Rgba32 color, int colorBits, int level, Octree octree) { - // Update the color information if this is a leaf - if (this.leaf) + ref OctreeNode node = ref octree.Nodes[nodeIndex]; + if (node.Leaf) { - this.Increment(ref color); - - // Setup the previous node - octree.TrackPrevious(this); + Increment(nodeIndex, color, octree); + octree.TrackPrevious(nodeIndex); } else { - // Go to the next level down in the tree - int index = GetColorIndex(ref color, level); + int index = GetColorIndex(color, level); + short childIndex; - OctreeNode? child = this.children![index]; - if (child is null) + Span children = node.Children; + childIndex = children[index]; + + if (childIndex == -1) { - // Create a new child node and store it in the array - child = new OctreeNode(level + 1, colorBits, octree); - this.children[index] = child; + childIndex = octree.AllocateNode(); + + if (childIndex == -1) + { + // No room in the tree, so increment the count and return. + Increment(nodeIndex, color, octree); + octree.TrackPrevious(nodeIndex); + return; + } + + ref OctreeNode child = ref octree.Nodes[childIndex]; + child.Initialize(level + 1, colorBits, octree, childIndex); + children[index] = childIndex; } - // Add the color to the child node - child.AddColor(ref color, colorBits, level + 1, octree); + AddColor(childIndex, color, colorBits, level + 1, octree); } } /// - /// Reduce this node by removing all of its children + /// Increment the color components of this node. + /// + /// The node index. + /// The color to increment by. + /// The parent octree. + public static void Increment(int nodeIndex, Rgba32 color, Octree octree) + { + ref OctreeNode node = ref octree.Nodes[nodeIndex]; + node.PixelCount++; + node.Red += color.R; + node.Green += color.G; + node.Blue += color.B; + node.Alpha += color.A; + } + + /// + /// Reduce this node by ensuring its children are all reduced (i.e. leaves) and then merging their data. /// - /// The number of leaves removed - public int Reduce() + /// The parent octree. + public void Reduce(Octree octree) { - this.red = this.green = this.blue = 0; - int childNodes = 0; + // If already a leaf, do nothing. + if (this.Leaf) + { + return; + } - // Loop through all children and add their information to this node - for (int index = 0; index < 8; index++) + // Now merge the (presumably reduced) children. + int pixelCount = 0; + int sumRed = 0, sumGreen = 0, sumBlue = 0, sumAlpha = 0; + Span children = this.Children; + for (int i = 0; i < children.Length; i++) { - OctreeNode? child = this.children![index]; - if (child != null) + short childIndex = children[i]; + if (childIndex != -1) { - this.red += child.red; - this.green += child.green; - this.blue += child.blue; - this.pixelCount += child.pixelCount; - ++childNodes; - this.children[index] = null; + ref OctreeNode child = ref octree.Nodes[childIndex]; + int pixels = child.PixelCount; + + sumRed += child.Red; + sumGreen += child.Green; + sumBlue += child.Blue; + sumAlpha += child.Alpha; + pixelCount += pixels; + + // Free the child immediately. + children[i] = -1; + octree.FreeNode(childIndex); } } - // Now change this to a leaf node - this.leaf = true; + if (pixelCount > 0) + { + this.Red = sumRed; + this.Green = sumGreen; + this.Blue = sumBlue; + this.Alpha = sumAlpha; + this.PixelCount = pixelCount; + } + else + { + this.Red = this.Green = this.Blue = this.Alpha = 0; + this.PixelCount = 0; + } - // Return the number of nodes to decrement the leaf count by - return childNodes - 1; + this.Leaf = true; + octree.Leaves++; } /// - /// Traverse the tree, building up the color palette + /// Traverse the tree to construct the palette. /// - /// The palette - /// The current palette index - [MethodImpl(InliningOptions.ColdPath)] - public void ConstructPalette(Span palette, ref int index) + /// The parent octree. + /// The palette to construct. + /// The current palette index. + public void ConstructPalette(Octree octree, Span palette, ref short paletteIndex) { - if (this.leaf) + if (this.Leaf) { - // Set the color of the palette entry - Vector3 vector = Vector3.Clamp( - new Vector3(this.red, this.green, this.blue) / this.pixelCount, - Vector3.Zero, - new Vector3(255)); + Vector4 sum = new(this.Red, this.Green, this.Blue, this.Alpha); + Vector4 offset = new(this.PixelCount >> 1); + Vector4 vector = Vector4.Clamp( + (sum + offset) / this.PixelCount, + Vector4.Zero, + new Vector4(255)); + + if (vector.W < octree.transparencyThreshold255) + { + vector = Vector4.Zero; + } - palette[index] = TPixel.FromRgba32(new Rgba32((byte)vector.X, (byte)vector.Y, (byte)vector.Z)); + palette[paletteIndex] = TPixel.FromRgba32(new Rgba32((byte)vector.X, (byte)vector.Y, (byte)vector.Z, (byte)vector.W)); - // Consume the next palette index - this.paletteIndex = index++; + this.PaletteIndex = paletteIndex++; } else { - // Loop through children looking for leaves - for (int i = 0; i < 8; i++) + Span children = this.Children; + for (int i = 0; i < children.Length; i++) { - this.children![i]?.ConstructPalette(palette, ref index); + int childIndex = children[i]; + if (childIndex != -1) + { + octree.Nodes[childIndex].ConstructPalette(octree, palette, ref paletteIndex); + } } } } /// - /// Return the palette index for the passed color + /// Get the palette index for the passed color. /// - /// The pixel data. - /// The level. - /// - /// The representing the index of the pixel in the palette. - /// - [MethodImpl(InliningOptions.ColdPath)] - public int GetPaletteIndex(ref Rgba32 pixel, int level) + /// The color to get the palette index for. + /// The level of the node. + /// The parent octree. + public int GetPaletteIndex(Rgba32 color, int level, Octree octree) { - if (this.leaf) + if (this.Leaf) { - return this.paletteIndex; + return this.PaletteIndex; } - int colorIndex = GetColorIndex(ref pixel, level); - OctreeNode? child = this.children![colorIndex]; - - int index = 0; - if (child != null) + int colorIndex = GetColorIndex(color, level); + Span children = this.Children; + int childIndex = children[colorIndex]; + if (childIndex != -1) { - index = child.GetPaletteIndex(ref pixel, level + 1); + return octree.Nodes[childIndex].GetPaletteIndex(color, level + 1, octree); } - else + + for (int i = 0; i < children.Length; i++) { - // Check other children. - for (int i = 0; i < this.children.Length; i++) + childIndex = children[i]; + if (childIndex != -1) { - child = this.children[i]; - if (child != null) + int childPaletteIndex = octree.Nodes[childIndex].GetPaletteIndex(color, level + 1, octree); + if (childPaletteIndex != -1) { - int childIndex = child.GetPaletteIndex(ref pixel, level + 1); - if (childIndex != 0) - { - return childIndex; - } + return childPaletteIndex; } } } - return index; + return -1; } /// /// Gets the color index at the given level. /// - /// The color. - /// The node level. - /// The index. - [MethodImpl(InliningOptions.ShortMethod)] - private static int GetColorIndex(ref Rgba32 color, int level) + /// The color to get the index for. + /// The level to get the index at. + public static int GetColorIndex(Rgba32 color, int level) { + // Determine how many bits to shift based on the current tree level. + // At level 0, shift = 7; as level increases, the shift decreases. int shift = 7 - level; byte mask = (byte)(1 << shift); - return ((color.R & mask) >> shift) - | (((color.G & mask) >> shift) << 1) - | (((color.B & mask) >> shift) << 2); - } + // Compute the luminance of the RGB components using the BT.709 standard. + // This gives a measure of brightness for the color. + int luminance = ColorNumerics.Get8BitBT709Luminance(color.R, color.G, color.B); - /// - /// Increment the color count and add to the color information - /// - /// The pixel to add. - [MethodImpl(InliningOptions.ShortMethod)] - public void Increment(ref Rgba32 color) - { - this.pixelCount++; - this.red += color.R; - this.green += color.G; - this.blue += color.B; + // Define thresholds for determining when to include the alpha bit in the index. + // The thresholds are scaled according to the current level. + // 128 is the midpoint of the 8-bit range (0–255), so shifting it right by 'level' + // produces a threshold that scales with the color cube subdivision. + int darkThreshold = 128 >> level; + + // The light threshold is set symmetrically: 255 minus the scaled midpoint. + int lightThreshold = 255 - (128 >> level); + + // If the pixel is fully opaque and its brightness falls between the dark and light thresholds, + // ignore the alpha channel to maximize RGB resolution. + // Otherwise (if the pixel is dark, light, or semi-transparent), include the alpha bit + // to preserve any gradient that may be present. + if (color.A == 255 && luminance > darkThreshold && luminance < lightThreshold) + { + // Extract one bit each from R, G, and B channels and combine them into a 3-bit index. + int rBits = ((color.R & mask) >> shift) << 2; + int gBits = ((color.G & mask) >> shift) << 1; + int bBits = (color.B & mask) >> shift; + return rBits | gBits | bBits; + } + else + { + // Extract one bit from each channel including alpha (alpha becomes the most significant bit). + int aBits = ((color.A & mask) >> shift) << 3; + int rBits = ((color.R & mask) >> shift) << 2; + int gBits = ((color.G & mask) >> shift) << 1; + int bBits = (color.B & mask) >> shift; + return aBits | rBits | gBits | bBits; + } } } } diff --git a/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer.cs b/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer.cs index 13a59a26de..a49691515a 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer.cs @@ -11,7 +11,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization; public class PaletteQuantizer : IQuantizer { private readonly ReadOnlyMemory colorPalette; - private readonly int transparentIndex; + private readonly int transparencyIndex; + private readonly Color transparentColor; /// /// Initializes a new instance of the class. @@ -25,27 +26,33 @@ public class PaletteQuantizer : IQuantizer /// /// Initializes a new instance of the class. /// - /// The color palette. + /// The color palette to use. /// The quantizer options defining quantization rules. public PaletteQuantizer(ReadOnlyMemory palette, QuantizerOptions options) - : this(palette, options, -1) + : this(palette, options, -1, default) { } /// /// Initializes a new instance of the class. /// - /// The color palette. + /// The color palette to use. /// The quantizer options defining quantization rules. - /// An explicit index at which to match transparent pixels. - internal PaletteQuantizer(ReadOnlyMemory palette, QuantizerOptions options, int transparentIndex) + /// The index of the color in the palette that should be considered as transparent. + /// The color that should be considered as transparent. + internal PaletteQuantizer( + ReadOnlyMemory palette, + QuantizerOptions options, + int transparencyIndex, + Color transparentColor) { Guard.MustBeGreaterThan(palette.Length, 0, nameof(palette)); Guard.NotNull(options, nameof(options)); this.colorPalette = palette; this.Options = options; - this.transparentIndex = transparentIndex; + this.transparencyIndex = transparencyIndex; + this.transparentColor = transparentColor; } /// @@ -66,6 +73,6 @@ public class PaletteQuantizer : IQuantizer // treat the buffer as FILO. TPixel[] palette = new TPixel[Math.Min(options.MaxColors, this.colorPalette.Length)]; Color.ToPixel(this.colorPalette.Span[..palette.Length], palette.AsSpan()); - return new PaletteQuantizer(configuration, options, palette, this.transparentIndex); + return new PaletteQuantizer(configuration, options, palette, this.transparencyIndex, this.transparentColor.ToPixel()); } } diff --git a/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs index 092975d28a..4fd044ab40 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/PaletteQuantizer{TPixel}.cs @@ -17,10 +17,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization; "Design", "CA1001:Types that own disposable fields should be disposable", Justification = "https://github.com/dotnet/roslyn-analyzers/issues/6151")] -internal readonly struct PaletteQuantizer : IQuantizer +internal struct PaletteQuantizer : IQuantizer where TPixel : unmanaged, IPixel { - private readonly EuclideanPixelMap pixelMap; + private readonly PixelMap pixelMap; + private int transparencyIndex; + private TPixel transparentColor; /// /// Initializes a new instance of the struct. @@ -28,20 +30,37 @@ internal readonly struct PaletteQuantizer : IQuantizer /// The configuration which allows altering default behavior or extending the library. /// The quantizer options defining quantization rules. /// The palette to use. - /// An explicit index at which to match transparent pixels. [MethodImpl(InliningOptions.ShortMethod)] + public PaletteQuantizer(Configuration configuration, QuantizerOptions options, ReadOnlyMemory palette) + : this(configuration, options, palette, -1, default) + { + Guard.NotNull(configuration, nameof(configuration)); + Guard.NotNull(options, nameof(options)); + } + + /// + /// Initializes a new instance of the struct. + /// + /// The configuration which allows altering default behavior or extending the library. + /// The quantizer options defining quantization rules. + /// The palette to use. + /// The index of the color in the palette that should be considered as transparent. + /// The color that should be considered as transparent. public PaletteQuantizer( Configuration configuration, QuantizerOptions options, ReadOnlyMemory palette, - int transparentIndex) + int transparencyIndex, + TPixel transparentColor) { Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(options, nameof(options)); this.Configuration = configuration; this.Options = options; - this.pixelMap = new EuclideanPixelMap(configuration, palette, transparentIndex); + this.pixelMap = PixelMapFactory.Create(this.Configuration, palette, options.ColorMatchingMode); + this.transparencyIndex = transparencyIndex; + this.transparentColor = transparentColor; } /// @@ -51,7 +70,13 @@ internal readonly struct PaletteQuantizer : IQuantizer public QuantizerOptions Options { get; } /// - public ReadOnlyMemory Palette => this.pixelMap.Palette; + public readonly ReadOnlyMemory Palette => this.pixelMap.Palette; + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public readonly void AddPaletteColors(in Buffer2DRegion pixelRegion) + { + } /// [MethodImpl(InliningOptions.ShortMethod)] @@ -60,21 +85,23 @@ internal readonly struct PaletteQuantizer : IQuantizer /// [MethodImpl(InliningOptions.ShortMethod)] - public void AddPaletteColors(Buffer2DRegion pixelRegion) + public readonly byte GetQuantizedColor(TPixel color, out TPixel match) { - } + if (this.transparencyIndex >= 0 && color.Equals(this.transparentColor)) + { + match = this.transparentColor; + return (byte)this.transparencyIndex; + } - /// - /// Allows setting the transparent index after construction. - /// - /// An explicit index at which to match transparent pixels. - public void SetTransparentIndex(int index) => this.pixelMap.SetTransparentIndex(index); + return (byte)this.pixelMap.GetClosestColor(color, out match); + } - /// - [MethodImpl(InliningOptions.ShortMethod)] - public readonly byte GetQuantizedColor(TPixel color, out TPixel match) - => (byte)this.pixelMap.GetClosestColor(color, out match); + public void SetTransparencyIndex(int transparencyIndex, TPixel transparentColor) + { + this.transparencyIndex = transparencyIndex; + this.transparentColor = transparentColor; + } /// - public void Dispose() => this.pixelMap.Dispose(); + public readonly void Dispose() => this.pixelMap.Dispose(); } diff --git a/src/ImageSharp/Processing/Processors/Quantization/QuantizerConstants.cs b/src/ImageSharp/Processing/Processors/Quantization/QuantizerConstants.cs index 2bf4c6d56d..3b515e372d 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/QuantizerConstants.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/QuantizerConstants.cs @@ -21,15 +21,30 @@ public static class QuantizerConstants public const int MaxColors = 256; /// - /// The minumim dithering scale used to adjust the amount of dither. + /// The minimum dithering scale used to adjust the amount of dither. /// public const float MinDitherScale = 0; /// - /// The max dithering scale used to adjust the amount of dither. + /// The maximum dithering scale used to adjust the amount of dither. /// public const float MaxDitherScale = 1F; + /// + /// The default threshold at which to consider a pixel transparent. + /// + public const float DefaultTransparencyThreshold = 64 / 255F; + + /// + /// The minimum threshold at which to consider a pixel transparent. + /// + public const float MinTransparencyThreshold = 0F; + + /// + /// The maximum threshold at which to consider a pixel transparent. + /// + public const float MaxTransparencyThreshold = 1F; + /// /// Gets the default dithering algorithm to use. /// diff --git a/src/ImageSharp/Processing/Processors/Quantization/QuantizerOptions.cs b/src/ImageSharp/Processing/Processors/Quantization/QuantizerOptions.cs index a6bb265a81..16dfd5b330 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/QuantizerOptions.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/QuantizerOptions.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Processing.Processors.Dithering; namespace SixLabors.ImageSharp.Processing.Processors.Quantization; @@ -8,10 +9,34 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization; /// /// Defines options for quantization. /// -public class QuantizerOptions +public class QuantizerOptions : IDeepCloneable { +#pragma warning disable IDE0032 // Use auto property private float ditherScale = QuantizerConstants.MaxDitherScale; private int maxColors = QuantizerConstants.MaxColors; + private float threshold = QuantizerConstants.DefaultTransparencyThreshold; +#pragma warning restore IDE0032 // Use auto property + + /// + /// Initializes a new instance of the class. + /// + public QuantizerOptions() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The options to clone. + private QuantizerOptions(QuantizerOptions options) + { + this.Dither = options.Dither; + this.DitherScale = options.DitherScale; + this.MaxColors = options.MaxColors; + this.TransparencyThreshold = options.TransparencyThreshold; + this.ColorMatchingMode = options.ColorMatchingMode; + this.TransparentColorMode = options.TransparentColorMode; + } /// /// Gets or sets the algorithm to apply to the output image. @@ -38,4 +63,30 @@ public class QuantizerOptions get => this.maxColors; set => this.maxColors = Numerics.Clamp(value, QuantizerConstants.MinColors, QuantizerConstants.MaxColors); } + + /// + /// Gets or sets the color matching mode used for matching pixel values to palette colors. + /// Defaults to . + /// + public ColorMatchingMode ColorMatchingMode { get; set; } = ColorMatchingMode.Coarse; + + /// + /// Gets or sets the threshold at which to consider a pixel transparent. Range 0..1. + /// Defaults to . + /// + public float TransparencyThreshold + { + get => this.threshold; + set => this.threshold = Numerics.Clamp(value, QuantizerConstants.MinTransparencyThreshold, QuantizerConstants.MaxTransparencyThreshold); + } + + /// + /// Gets or sets the transparent color mode used for handling transparent colors + /// when not using thresholding. + /// Defaults to . + /// + public TransparentColorMode TransparentColorMode { get; set; } = TransparentColorMode.Preserve; + + /// + public QuantizerOptions DeepClone() => new(this); } diff --git a/src/ImageSharp/Processing/Processors/Quantization/QuantizerUtilities.cs b/src/ImageSharp/Processing/Processors/Quantization/QuantizerUtilities.cs index 6d2200b8a7..e121aff90b 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/QuantizerUtilities.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/QuantizerUtilities.cs @@ -1,7 +1,11 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. +using System.Buffers; +using System.Numerics; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; @@ -14,6 +18,130 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization; /// public static class QuantizerUtilities { + /// + /// Performs a deep clone the instance and optionally mutates the clone. + /// + /// The instance to clone. + /// An optional delegate to mutate the cloned instance. + /// The cloned instance. + public static QuantizerOptions DeepClone(this QuantizerOptions options, Action? mutate) + { + QuantizerOptions clone = options.DeepClone(); + mutate?.Invoke(clone); + return clone; + } + + /// + /// Determines if transparent pixels can be replaced based on the specified color mode and pixel type. + /// + /// The type of the pixel. + /// The alpha threshold used to determine if a pixel is transparent. + /// Returns true if transparent pixels can be replaced; otherwise, false. + public static bool ShouldReplacePixelsByAlphaThreshold(float threshold) + where TPixel : unmanaged, IPixel + => threshold > 0 && TPixel.GetPixelTypeInfo().AlphaRepresentation == PixelAlphaRepresentation.Unassociated; + + /// + /// Replaces pixels in a span with fully transparent pixels based on an alpha threshold. + /// + /// A span of color vectors that will be checked for transparency and potentially modified. + /// The alpha threshold used to determine if a pixel is transparent. + public static void ReplacePixelsByAlphaThreshold(Span source, float threshold) + { + if (Vector512.IsHardwareAccelerated && source.Length >= 4) + { + Vector512 threshold512 = Vector512.Create(threshold); + Span> source512 = MemoryMarshal.Cast>(source); + for (int i = 0; i < source512.Length; i++) + { + ref Vector512 v = ref source512[i]; + + // Do `vector < threshold` + Vector512 mask = Vector512.LessThan(v, threshold512); + + // Replicate the result for W to all elements (is AllBitsSet if the W was less than threshold and Zero otherwise) + mask = Vector512.Shuffle(mask, Vector512.Create(3, 3, 3, 3, 7, 7, 7, 7, 11, 11, 11, 11, 15, 15, 15, 15)); + + // Use the mask to select the replacement vector + // (replacement & mask) | (v512 & ~mask) + v = Vector512.ConditionalSelect(mask, Vector512.Zero, v); + } + + int m = Numerics.Modulo4(source.Length); + if (m != 0) + { + for (int i = source.Length - m; i < source.Length; i++) + { + if (source[i].W < threshold) + { + source[i] = Vector4.Zero; + } + } + } + } + else if (Vector256.IsHardwareAccelerated && source.Length >= 2) + { + Vector256 threshold256 = Vector256.Create(threshold); + Span> source256 = MemoryMarshal.Cast>(source); + for (int i = 0; i < source256.Length; i++) + { + ref Vector256 v = ref source256[i]; + + // Do `vector < threshold` + Vector256 mask = Vector256.LessThan(v, threshold256); + + // Replicate the result for W to all elements (is AllBitsSet if the W was less than threshold and Zero otherwise) + mask = Vector256.Shuffle(mask, Vector256.Create(3, 3, 3, 3, 7, 7, 7, 7)); + + // Use the mask to select the replacement vector + // (replacement & mask) | (v256 & ~mask) + v = Vector256.ConditionalSelect(mask, Vector256.Zero, v); + } + + int m = Numerics.Modulo2(source.Length); + if (m != 0) + { + for (int i = source.Length - m; i < source.Length; i++) + { + if (source[i].W < threshold) + { + source[i] = Vector4.Zero; + } + } + } + } + else if (Vector128.IsHardwareAccelerated) + { + Vector128 threshold128 = Vector128.Create(threshold); + + for (int i = 0; i < source.Length; i++) + { + ref Vector4 v = ref source[i]; + Vector128 v128 = v.AsVector128(); + + // Do `vector < threshold` + Vector128 mask = Vector128.LessThan(v128, threshold128); + + // Replicate the result for W to all elements (is AllBitsSet if the W was less than threshold and Zero otherwise) + mask = Vector128.Shuffle(mask, Vector128.Create(3, 3, 3, 3)); + + // Use the mask to select the replacement vector + // (replacement & mask) | (v128 & ~mask) + v = Vector128.ConditionalSelect(mask, Vector128.Zero, v128).AsVector4(); + } + } + else + { + for (int i = 0; i < source.Length; i++) + { + if (source[i].W < threshold) + { + source[i] = Vector4.Zero; + } + } + } + } + /// /// Helper method for throwing an exception when a frame quantizer palette has /// been requested but not built yet. @@ -21,12 +149,13 @@ public static class QuantizerUtilities /// The pixel format. /// The frame quantizer palette. /// - /// The palette has not been built via + /// The palette has not been built via /// + [MethodImpl(InliningOptions.ColdPath)] public static void CheckPaletteState(in ReadOnlyMemory palette) where TPixel : unmanaged, IPixel { - if (palette.Equals(default)) + if (palette.IsEmpty) { throw new InvalidOperationException("Frame Quantizer palette has not been built."); } @@ -54,8 +183,7 @@ public static class QuantizerUtilities Rectangle interest = Rectangle.Intersect(source.Bounds, bounds); Buffer2DRegion region = source.PixelBuffer.GetRegion(interest); - // Collect the palette. Required before the second pass runs. - quantizer.AddPaletteColors(region); + quantizer.AddPaletteColors(in region); return quantizer.QuantizeFrame(source, bounds); } @@ -112,39 +240,10 @@ public static class QuantizerUtilities IPixelSamplingStrategy pixelSamplingStrategy, Image source) where TPixel : unmanaged, IPixel - => quantizer.BuildPalette(source.Configuration, TransparentColorMode.Preserve, pixelSamplingStrategy, source); - - /// - /// Adds colors to the quantized palette from the given pixel regions. - /// - /// The pixel format. - /// The pixel specific quantizer. - /// The configuration. - /// The transparent color mode. - /// The pixel sampling strategy. - /// The source image to sample from. - public static void BuildPalette( - this IQuantizer quantizer, - Configuration configuration, - TransparentColorMode mode, - IPixelSamplingStrategy pixelSamplingStrategy, - Image source) - where TPixel : unmanaged, IPixel { - if (EncodingUtilities.ShouldClearTransparentPixels(mode)) - { - foreach (Buffer2DRegion region in pixelSamplingStrategy.EnumeratePixelRegions(source)) - { - using Buffer2D clone = region.Buffer.CloneRegion(configuration, region.Rectangle); - quantizer.AddPaletteColors(clone.GetRegion()); - } - } - else + foreach (Buffer2DRegion region in pixelSamplingStrategy.EnumeratePixelRegions(source)) { - foreach (Buffer2DRegion region in pixelSamplingStrategy.EnumeratePixelRegions(source)) - { - quantizer.AddPaletteColors(region); - } + quantizer.AddPaletteColors(in region); } } @@ -160,43 +259,75 @@ public static class QuantizerUtilities IPixelSamplingStrategy pixelSamplingStrategy, ImageFrame source) where TPixel : unmanaged, IPixel - => quantizer.BuildPalette(source.Configuration, TransparentColorMode.Preserve, pixelSamplingStrategy, source); + { + foreach (Buffer2DRegion region in pixelSamplingStrategy.EnumeratePixelRegions(source)) + { + quantizer.AddPaletteColors(in region); + } + } - /// - /// Adds colors to the quantized palette from the given pixel regions. - /// - /// The pixel format. - /// The pixel specific quantizer. - /// The configuration. - /// The transparent color mode. - /// The pixel sampling strategy. - /// The source image frame to sample from. - public static void BuildPalette( - this IQuantizer quantizer, - Configuration configuration, - TransparentColorMode mode, - IPixelSamplingStrategy pixelSamplingStrategy, - ImageFrame source) + internal static void AddPaletteColors( + ref TFrameQuantizer quantizer, + in Buffer2DRegion source, + in TDelegate rowDelegate) + where TFrameQuantizer : struct, IQuantizer where TPixel : unmanaged, IPixel + where TPixel2 : unmanaged, IPixel + where TDelegate : struct, IQuantizingPixelRowDelegate { - if (EncodingUtilities.ShouldClearTransparentPixels(mode)) + Configuration configuration = quantizer.Configuration; + float threshold = quantizer.Options.TransparencyThreshold; + TransparentColorMode mode = quantizer.Options.TransparentColorMode; + + using IMemoryOwner delegateRowOwner = configuration.MemoryAllocator.Allocate(source.Width); + Span delegateRow = delegateRowOwner.Memory.Span; + + bool replaceByThreshold = ShouldReplacePixelsByAlphaThreshold(threshold); + bool replaceTransparent = EncodingUtilities.ShouldReplaceTransparentPixels(mode); + + if (replaceByThreshold || replaceTransparent) { - foreach (Buffer2DRegion region in pixelSamplingStrategy.EnumeratePixelRegions(source)) + using IMemoryOwner vectorRowOwner = configuration.MemoryAllocator.Allocate(source.Width); + Span vectorRow = vectorRowOwner.Memory.Span; + + if (replaceByThreshold) { - using Buffer2D clone = region.Buffer.CloneRegion(configuration, region.Rectangle); - quantizer.AddPaletteColors(clone.GetRegion()); + for (int y = 0; y < source.Height; y++) + { + Span sourceRow = source.DangerousGetRowSpan(y); + PixelOperations.Instance.ToVector4(configuration, sourceRow, vectorRow, PixelConversionModifiers.Scale); + + ReplacePixelsByAlphaThreshold(vectorRow, threshold); + + PixelOperations.Instance.FromVector4Destructive(configuration, vectorRow, delegateRow, PixelConversionModifiers.Scale); + rowDelegate.Invoke(delegateRow, y); + } + } + else + { + for (int y = 0; y < source.Height; y++) + { + Span sourceRow = source.DangerousGetRowSpan(y); + PixelOperations.Instance.ToVector4(configuration, sourceRow, vectorRow, PixelConversionModifiers.Scale); + + EncodingUtilities.ReplaceTransparentPixels(vectorRow); + + PixelOperations.Instance.FromVector4Destructive(configuration, vectorRow, delegateRow, PixelConversionModifiers.Scale); + rowDelegate.Invoke(delegateRow, y); + } } } else { - foreach (Buffer2DRegion region in pixelSamplingStrategy.EnumeratePixelRegions(source)) + for (int y = 0; y < source.Height; y++) { - quantizer.AddPaletteColors(region); + Span sourceRow = source.DangerousGetRowSpan(y); + PixelOperations.Instance.To(configuration, sourceRow, delegateRow); + rowDelegate.Invoke(delegateRow, y); } } } - [MethodImpl(InliningOptions.ShortMethod)] private static void SecondPass( ref TFrameQuantizer quantizer, ImageFrame source, @@ -205,28 +336,111 @@ public static class QuantizerUtilities where TFrameQuantizer : struct, IQuantizer where TPixel : unmanaged, IPixel { + float threshold = quantizer.Options.TransparencyThreshold; + bool replaceByThreshold = ShouldReplacePixelsByAlphaThreshold(threshold); + + TransparentColorMode mode = quantizer.Options.TransparentColorMode; + bool replaceTransparent = EncodingUtilities.ShouldReplaceTransparentPixels(mode); + IDither? dither = quantizer.Options.Dither; Buffer2D sourceBuffer = source.PixelBuffer; + Buffer2DRegion region = sourceBuffer.GetRegion(bounds); + + Configuration configuration = quantizer.Configuration; + using IMemoryOwner vectorOwner = configuration.MemoryAllocator.Allocate(region.Width); + Span vectorRow = vectorOwner.Memory.Span; if (dither is null) { - int offsetY = bounds.Top; - int offsetX = bounds.Left; + using IMemoryOwner quantizingRowOwner = configuration.MemoryAllocator.Allocate(region.Width); + Span quantizingRow = quantizingRowOwner.Memory.Span; + + // This is NOT a clone so we DO NOT write back to the source. + if (replaceByThreshold || replaceTransparent) + { + if (replaceByThreshold) + { + for (int y = 0; y < region.Height; y++) + { + Span sourceRow = region.DangerousGetRowSpan(y); + PixelOperations.Instance.ToVector4(configuration, sourceRow, vectorRow, PixelConversionModifiers.Scale); + + ReplacePixelsByAlphaThreshold(vectorRow, threshold); + + PixelOperations.Instance.FromVector4Destructive(configuration, vectorRow, quantizingRow, PixelConversionModifiers.Scale); + + Span destinationRow = destination.GetWritablePixelRowSpanUnsafe(y); + for (int x = 0; x < destinationRow.Length; x++) + { + destinationRow[x] = quantizer.GetQuantizedColor(quantizingRow[x], out TPixel _); + } + } + } + else + { + for (int y = 0; y < region.Height; y++) + { + Span sourceRow = region.DangerousGetRowSpan(y); + PixelOperations.Instance.ToVector4(configuration, sourceRow, vectorRow, PixelConversionModifiers.Scale); + + EncodingUtilities.ReplaceTransparentPixels(vectorRow); + + PixelOperations.Instance.FromVector4Destructive(configuration, vectorRow, quantizingRow, PixelConversionModifiers.Scale); + + Span destinationRow = destination.GetWritablePixelRowSpanUnsafe(y); + for (int x = 0; x < destinationRow.Length; x++) + { + destinationRow[x] = quantizer.GetQuantizedColor(quantizingRow[x], out TPixel _); + } + } + } - for (int y = 0; y < destination.Height; y++) + return; + } + + for (int y = 0; y < region.Height; y++) { - ReadOnlySpan sourceRow = sourceBuffer.DangerousGetRowSpan(y + offsetY); + ReadOnlySpan sourceRow = region.DangerousGetRowSpan(y); Span destinationRow = destination.GetWritablePixelRowSpanUnsafe(y); for (int x = 0; x < destinationRow.Length; x++) { - destinationRow[x] = Unsafe.AsRef(in quantizer).GetQuantizedColor(sourceRow[x + offsetX], out TPixel _); + destinationRow[x] = quantizer.GetQuantizedColor(sourceRow[x], out TPixel _); } } return; } + // This is a clone so we write back to the source. + if (replaceByThreshold || replaceTransparent) + { + if (replaceByThreshold) + { + for (int y = 0; y < region.Height; y++) + { + Span sourceRow = region.DangerousGetRowSpan(y); + PixelOperations.Instance.ToVector4(configuration, sourceRow, vectorRow, PixelConversionModifiers.Scale); + + ReplacePixelsByAlphaThreshold(vectorRow, threshold); + + PixelOperations.Instance.FromVector4Destructive(configuration, vectorRow, sourceRow, PixelConversionModifiers.Scale); + } + } + else + { + for (int y = 0; y < region.Height; y++) + { + Span sourceRow = region.DangerousGetRowSpan(y); + PixelOperations.Instance.ToVector4(configuration, sourceRow, vectorRow, PixelConversionModifiers.Scale); + + EncodingUtilities.ReplaceTransparentPixels(vectorRow); + + PixelOperations.Instance.FromVector4Destructive(configuration, vectorRow, sourceRow, PixelConversionModifiers.Scale); + } + } + } + dither.ApplyQuantizationDither(ref quantizer, source, destination, bounds); } } diff --git a/src/ImageSharp/Processing/Processors/Quantization/WebSafePaletteQuantizer.cs b/src/ImageSharp/Processing/Processors/Quantization/WebSafePaletteQuantizer.cs index 604cae6681..fa1763367c 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/WebSafePaletteQuantizer.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/WebSafePaletteQuantizer.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization; /// /// A palette quantizer consisting of web safe colors as defined in the CSS Color Module Level 4. /// -public class WebSafePaletteQuantizer : PaletteQuantizer +public sealed class WebSafePaletteQuantizer : PaletteQuantizer { /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp/Processing/Processors/Quantization/WernerPaletteQuantizer.cs b/src/ImageSharp/Processing/Processors/Quantization/WernerPaletteQuantizer.cs index 023ee7f2e0..cd7b80e81d 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/WernerPaletteQuantizer.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/WernerPaletteQuantizer.cs @@ -7,7 +7,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Quantization; /// A palette quantizer consisting 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 /// -public class WernerPaletteQuantizer : PaletteQuantizer +public sealed class WernerPaletteQuantizer : PaletteQuantizer { /// /// Initializes a new instance of the class. diff --git a/src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs index ba2ab825ad..03d6ac0da6 100644 --- a/src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Quantization/WuQuantizer{TPixel}.cs @@ -43,30 +43,10 @@ internal struct WuQuantizer : IQuantizer // The following two variables determine the amount of bits to preserve when calculating the histogram. // Reducing the value of these numbers the granularity of the color maps produced, making it much faster // and using much less memory but potentially less accurate. Current results are very good though! - - /// - /// The index bits. 6 in original code. - /// private const int IndexBits = 5; - - /// - /// The index alpha bits. 3 in original code. - /// private const int IndexAlphaBits = 5; - - /// - /// The index count. - /// private const int IndexCount = (1 << IndexBits) + 1; - - /// - /// The index alpha count. - /// private const int IndexAlphaCount = (1 << IndexAlphaBits) + 1; - - /// - /// The table length. Now 1185921. originally 2471625. - /// private const int TableLength = IndexCount * IndexCount * IndexCount * IndexAlphaCount; private readonly IMemoryOwner momentsOwner; @@ -75,14 +55,14 @@ internal struct WuQuantizer : IQuantizer private ReadOnlyMemory palette; private int maxColors; private readonly Box[] colorCube; - private EuclideanPixelMap? pixelMap; + private PixelMap? pixelMap; private readonly bool isDithering; private bool isDisposed; /// /// Initializes a new instance of the struct. /// - /// The configuration which allows altering default behaviour or extending the library. + /// The configuration which allows altering default behavior or extending the library. /// The quantizer options defining quantization rules. [MethodImpl(InliningOptions.ShortMethod)] public WuQuantizer(Configuration configuration, QuantizerOptions options) @@ -101,7 +81,7 @@ internal struct WuQuantizer : IQuantizer this.isDisposed = false; this.pixelMap = default; this.palette = default; - this.isDithering = this.isDithering = this.Options.Dither is not null; + this.isDithering = this.Options.Dither is not null; } /// @@ -111,57 +91,71 @@ internal struct WuQuantizer : IQuantizer public QuantizerOptions Options { get; } /// - public readonly ReadOnlyMemory Palette + public ReadOnlyMemory Palette { get { - QuantizerUtilities.CheckPaletteState(in this.palette); + if (this.palette.IsEmpty) + { + this.ResolvePalette(); + QuantizerUtilities.CheckPaletteState(in this.palette); + } + return this.palette; } } /// - public void AddPaletteColors(Buffer2DRegion pixelRegion) + public readonly void AddPaletteColors(in Buffer2DRegion pixelRegion) + { + PixelRowDelegate pixelRowDelegate = new(ref Unsafe.AsRef(in this)); + QuantizerUtilities.AddPaletteColors, TPixel, Rgba32, PixelRowDelegate>( + ref Unsafe.AsRef(in this), + in pixelRegion, + in pixelRowDelegate); + } + + /// + /// Once all histogram data has been accumulated, this method computes the moments, + /// splits the color cube, and resolves the final palette from the accumulated histogram. + /// + private void ResolvePalette() { - // TODO: Something is destroying the existing palette when adding new colors. - // When the QuantizingImageEncoder.PixelSamplingStrategy is DefaultPixelSamplingStrategy - // this leads to performance issues + the palette is not preserved. - // https://github.com/SixLabors/ImageSharp/issues/2498 - this.Build3DHistogram(pixelRegion); + // Calculate the cumulative moments from the accumulated histogram. this.Get3DMoments(this.memoryAllocator); + + // Partition the histogram into color cubes. this.BuildCube(); - // Slice again since maxColors has been updated since the buffer was created. + // Compute the palette colors from the resolved cubes. Span paletteSpan = this.paletteOwner.GetSpan()[..this.maxColors]; ReadOnlySpan momentsSpan = this.momentsOwner.GetSpan(); + + float transparencyThreshold = this.Options.TransparencyThreshold; for (int k = 0; k < paletteSpan.Length; k++) { this.Mark(ref this.colorCube[k], (byte)k); - Moment moment = Volume(ref this.colorCube[k], momentsSpan); - if (moment.Weight > 0) { - paletteSpan[k] = TPixel.FromScaledVector4(moment.Normalize()); + Vector4 normalized = moment.Normalize(); + if (normalized.W < transparencyThreshold) + { + normalized = Vector4.Zero; + } + + paletteSpan[k] = TPixel.FromScaledVector4(normalized); } } - ReadOnlyMemory result = this.paletteOwner.Memory[..paletteSpan.Length]; - if (this.isDithering) + // Update the palette to the new computed colors. + this.palette = this.paletteOwner.Memory[..paletteSpan.Length]; + + // Create the pixel map if dithering is enabled. + if (this.isDithering && this.pixelMap is null) { - // When called multiple times by QuantizerUtilities.BuildPalette - // this prevents memory churn caused by reallocation. - if (this.pixelMap is null) - { - this.pixelMap = new EuclideanPixelMap(this.Configuration, result); - } - else - { - this.pixelMap.Clear(result); - } + this.pixelMap = PixelMapFactory.Create(this.Configuration, this.palette, this.Options.ColorMatchingMode); } - - this.palette = result; } /// @@ -172,6 +166,9 @@ internal struct WuQuantizer : IQuantizer /// public readonly byte GetQuantizedColor(TPixel color, out TPixel match) { + // Due to the addition of new colors by dithering that are not part of the original histogram, + // the color cube might not match the correct color. + // In this case, we must use the pixel map to get the closest color. if (this.isDithering) { return (byte)this.pixelMap!.GetClosestColor(color, out match); @@ -188,7 +185,7 @@ internal struct WuQuantizer : IQuantizer ReadOnlySpan tagSpan = this.tagsOwner.GetSpan(); byte index = tagSpan[GetPaletteIndex(r + 1, g + 1, b + 1, a + 1)]; ref TPixel paletteRef = ref MemoryMarshal.GetReference(this.palette.Span); - match = Unsafe.Add(ref paletteRef, index); + match = Unsafe.Add(ref paletteRef, (nuint)index); return index; } @@ -359,31 +356,19 @@ internal struct WuQuantizer : IQuantizer /// /// Builds a 3-D color histogram of counts, r/g/b, c^2. /// - /// The source pixel data. - private readonly void Build3DHistogram(Buffer2DRegion source) + /// The source pixel data. + private readonly void Build3DHistogram(ReadOnlySpan pixels) { - Span momentSpan = this.momentsOwner.GetSpan(); - - // Build up the 3-D color histogram - using IMemoryOwner buffer = this.memoryAllocator.Allocate(source.Width); - Span bufferSpan = buffer.GetSpan(); - - for (int y = 0; y < source.Height; y++) + Span moments = this.momentsOwner.GetSpan(); + for (int x = 0; x < pixels.Length; x++) { - Span row = source.DangerousGetRowSpan(y); - PixelOperations.Instance.ToRgba32(this.Configuration, row, bufferSpan); - - for (int x = 0; x < bufferSpan.Length; x++) - { - Rgba32 rgba = bufferSpan[x]; - - int r = (rgba.R >> (8 - IndexBits)) + 1; - int g = (rgba.G >> (8 - IndexBits)) + 1; - int b = (rgba.B >> (8 - IndexBits)) + 1; - int a = (rgba.A >> (8 - IndexAlphaBits)) + 1; + Rgba32 rgba = pixels[x]; + int r = (rgba.R >> (8 - IndexBits)) + 1; + int g = (rgba.G >> (8 - IndexBits)) + 1; + int b = (rgba.B >> (8 - IndexBits)) + 1; + int a = (rgba.A >> (8 - IndexAlphaBits)) + 1; - momentSpan[GetPaletteIndex(r, g, b, a)] += rgba; - } + moments[GetPaletteIndex(r, g, b, a)] += rgba; } } @@ -895,4 +880,13 @@ internal struct WuQuantizer : IQuantizer return hash.ToHashCode(); } } + + private readonly struct PixelRowDelegate : IQuantizingPixelRowDelegate + { + private readonly WuQuantizer quantizer; + + public PixelRowDelegate(ref WuQuantizer quantizer) => this.quantizer = quantizer; + + public void Invoke(ReadOnlySpan row, int rowIndex) => this.quantizer.Build3DHistogram(row); + } } diff --git a/src/ImageSharp/Processing/Processors/Transforms/TransformProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/TransformProcessor{TPixel}.cs index bdfac00366..a8455a06ea 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/TransformProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/TransformProcessor{TPixel}.cs @@ -3,6 +3,7 @@ using SixLabors.ImageSharp.PixelFormats; +// TODO: DO we need this class? namespace SixLabors.ImageSharp.Processing.Processors.Transforms; /// @@ -22,18 +23,4 @@ internal abstract class TransformProcessor : CloningImageProcessor - protected override void AfterFrameApply(ImageFrame source, ImageFrame destination) - { - base.AfterFrameApply(source, destination); - destination.Metadata.AfterFrameApply(source, destination); - } - - /// - protected override void AfterImageApply(Image destination) - { - base.AfterImageApply(destination); - destination.Metadata.AfterImageApply(destination); - } } diff --git a/tests/ImageSharp.Benchmarks/Codecs/Gif/DecodeEncodeGif.cs b/tests/ImageSharp.Benchmarks/Codecs/Gif/DecodeEncodeGif.cs new file mode 100644 index 0000000000..3238e8dac2 --- /dev/null +++ b/tests/ImageSharp.Benchmarks/Codecs/Gif/DecodeEncodeGif.cs @@ -0,0 +1,59 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Drawing.Imaging; +using BenchmarkDotNet.Attributes; +using SixLabors.ImageSharp.Formats.Gif; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Quantization; +using SixLabors.ImageSharp.Tests; +using SDImage = System.Drawing.Image; + +namespace SixLabors.ImageSharp.Benchmarks.Codecs; + +public abstract class DecodeEncodeGif +{ + private MemoryStream outputStream; + + protected abstract GifEncoder Encoder { get; } + + [Params(TestImages.Gif.Leo, TestImages.Gif.Cheers)] + public string TestImage { get; set; } + + private string TestImageFullPath => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImage); + + [GlobalSetup] + public void Setup() => this.outputStream = new MemoryStream(); + + [GlobalCleanup] + public void Cleanup() => this.outputStream.Close(); + + [Benchmark(Baseline = true)] + public void SystemDrawing() + { + this.outputStream.Position = 0; + using SDImage image = SDImage.FromFile(this.TestImageFullPath); + image.Save(this.outputStream, ImageFormat.Gif); + } + + [Benchmark] + public void ImageSharp() + { + this.outputStream.Position = 0; + using Image image = Image.Load(this.TestImageFullPath); + image.SaveAsGif(this.outputStream, this.Encoder); + } +} + +public class DecodeEncodeGif_DefaultEncoder : DecodeEncodeGif +{ + protected override GifEncoder Encoder => new(); +} + +public class DecodeEncodeGif_CoarsePaletteEncoder : DecodeEncodeGif +{ + protected override GifEncoder Encoder => new() + { + Quantizer = new WebSafePaletteQuantizer(new QuantizerOptions { Dither = KnownDitherings.Bayer4x4, ColorMatchingMode = ColorMatchingMode.Coarse }) + }; +} diff --git a/tests/ImageSharp.Benchmarks/Codecs/Gif/EncodeGif.cs b/tests/ImageSharp.Benchmarks/Codecs/Gif/EncodeGif.cs index beedbbe07c..b8f8f78517 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Gif/EncodeGif.cs +++ b/tests/ImageSharp.Benchmarks/Codecs/Gif/EncodeGif.cs @@ -3,6 +3,7 @@ using System.Drawing.Imaging; using BenchmarkDotNet.Attributes; +using ImageMagick; using SixLabors.ImageSharp.Formats.Gif; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; @@ -12,21 +13,17 @@ using SDImage = System.Drawing.Image; namespace SixLabors.ImageSharp.Benchmarks.Codecs; -[Config(typeof(Config.Short))] -public class EncodeGif +public abstract class EncodeGif { // System.Drawing needs this. private FileStream bmpStream; private SDImage bmpDrawing; private Image bmpCore; + private MagickImageCollection magickImage; - // Try to get as close to System.Drawing's output as possible - private readonly GifEncoder encoder = new() - { - Quantizer = new WebSafePaletteQuantizer(new QuantizerOptions { Dither = KnownDitherings.Bayer4x4 }) - }; + protected abstract GifEncoder Encoder { get; } - [Params(TestImages.Bmp.Car, TestImages.Png.Rgb48Bpp)] + [Params(TestImages.Gif.Leo, TestImages.Gif.Cheers)] public string TestImage { get; set; } [GlobalSetup] @@ -34,10 +31,14 @@ public class EncodeGif { if (this.bmpStream == null) { - this.bmpStream = File.OpenRead(Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImage)); + string filePath = Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImage); + this.bmpStream = File.OpenRead(filePath); this.bmpCore = Image.Load(this.bmpStream); this.bmpStream.Position = 0; this.bmpDrawing = SDImage.FromStream(this.bmpStream); + + this.bmpStream.Position = 0; + this.magickImage = new MagickImageCollection(this.bmpStream); } } @@ -48,6 +49,7 @@ public class EncodeGif this.bmpStream = null; this.bmpCore.Dispose(); this.bmpDrawing.Dispose(); + this.magickImage.Dispose(); } [Benchmark(Baseline = true, Description = "System.Drawing Gif")] @@ -61,6 +63,26 @@ public class EncodeGif public void GifImageSharp() { using MemoryStream memoryStream = new(); - this.bmpCore.SaveAsGif(memoryStream, this.encoder); + this.bmpCore.SaveAsGif(memoryStream, this.Encoder); } + + [Benchmark(Description = "Magick.NET Gif")] + public void GifMagickNet() + { + using MemoryStream ms = new(); + this.magickImage.Write(ms, MagickFormat.Gif); + } +} + +public class EncodeGif_DefaultEncoder : EncodeGif +{ + protected override GifEncoder Encoder => new(); +} + +public class EncodeGif_CoarsePaletteEncoder : EncodeGif +{ + protected override GifEncoder Encoder => new() + { + Quantizer = new WebSafePaletteQuantizer(new QuantizerOptions { Dither = KnownDitherings.Bayer4x4, ColorMatchingMode = ColorMatchingMode.Coarse }) + }; } diff --git a/tests/ImageSharp.Benchmarks/Color/RgbWorkingSpaceAdapt.cs b/tests/ImageSharp.Benchmarks/Color/RgbWorkingSpaceAdapt.cs index 6cd8df3fc7..b847e3ac54 100644 --- a/tests/ImageSharp.Benchmarks/Color/RgbWorkingSpaceAdapt.cs +++ b/tests/ImageSharp.Benchmarks/Color/RgbWorkingSpaceAdapt.cs @@ -13,7 +13,7 @@ public class RgbWorkingSpaceAdapt private static readonly RGBColor RGBColor = new(0.206162, 0.260277, 0.746717); - private static readonly ColorProfileConverter ColorProfileConverter = new(new ColorConversionOptions { RgbWorkingSpace = KnownRgbWorkingSpaces.WideGamutRgb, TargetRgbWorkingSpace = KnownRgbWorkingSpaces.SRgb }); + private static readonly ColorProfileConverter ColorProfileConverter = new(new ColorConversionOptions { SourceRgbWorkingSpace = KnownRgbWorkingSpaces.WideGamutRgb, TargetRgbWorkingSpace = KnownRgbWorkingSpaces.SRgb }); private static readonly IColorConverter ColourfulConverter = new ConverterBuilder().FromRGB(RGBWorkingSpaces.WideGamutRGB).ToRGB(RGBWorkingSpaces.sRGB).Build(); diff --git a/tests/ImageSharp.Tests/ColorProfiles/ApproximateColorProfileComparer.cs b/tests/ImageSharp.Tests/ColorProfiles/ApproximateColorProfileComparer.cs index 56d495a87a..f4078887c7 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/ApproximateColorProfileComparer.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/ApproximateColorProfileComparer.cs @@ -22,7 +22,9 @@ internal readonly struct ApproximateColorProfileComparer : IEqualityComparer, IEqualityComparer, IEqualityComparer, - IEqualityComparer + IEqualityComparer, + IEqualityComparer, + IEqualityComparer { private readonly float epsilon; @@ -58,6 +60,10 @@ internal readonly struct ApproximateColorProfileComparer : public bool Equals(HunterLab x, HunterLab y) => this.Equals(x.L, y.L) && this.Equals(x.A, y.A) && this.Equals(x.B, y.B); + public bool Equals(Y x, Y y) => this.Equals(x.L, y.L); + + public bool Equals(YccK x, YccK y) => this.Equals(x.Y, y.Y) && this.Equals(x.Cb, y.Cb) && this.Equals(x.Cr, y.Cr) && this.Equals(x.K, y.K); + public int GetHashCode([DisallowNull] CieLab obj) => obj.GetHashCode(); public int GetHashCode([DisallowNull] CieXyz obj) => obj.GetHashCode(); @@ -84,6 +90,10 @@ internal readonly struct ApproximateColorProfileComparer : public int GetHashCode([DisallowNull] HunterLab obj) => obj.GetHashCode(); + public int GetHashCode([DisallowNull] Y obj) => obj.GetHashCode(); + + public int GetHashCode([DisallowNull] YccK obj) => obj.GetHashCode(); + private bool Equals(float x, float y) { float d = x - y; diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieLabAndCieLchConversionTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CieLabAndCieLchConversionTests.cs index 9a894c7760..d6e3738952 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieLabAndCieLchConversionTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieLabAndCieLchConversionTests.cs @@ -12,6 +12,7 @@ namespace SixLabors.ImageSharp.Tests.ColorProfiles; /// Test data generated using: /// /// +[Trait("Color", "Conversion")] public class CieLabAndCieLchConversionTests { private static readonly ApproximateColorProfileComparer Comparer = new(.0001f); @@ -30,7 +31,7 @@ public class CieLabAndCieLchConversionTests // Arrange CieLch input = new(l, c, h); CieLab expected = new(l2, a, b); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D50, TargetWhitePoint = KnownIlluminants.D50 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D50, TargetWhitePoint = KnownIlluminants.D50 }; ColorProfileConverter converter = new(options); Span inputSpan = new CieLch[5]; @@ -65,7 +66,7 @@ public class CieLabAndCieLchConversionTests // Arrange CieLab input = new(l, a, b); CieLch expected = new(l2, c, h); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D50, TargetWhitePoint = KnownIlluminants.D50 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D50, TargetWhitePoint = KnownIlluminants.D50 }; ColorProfileConverter converter = new(options); Span inputSpan = new CieLab[5]; diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieLabAndCieLchuvConversionTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CieLabAndCieLchuvConversionTests.cs index 4b1b5e1a56..73fa7128fa 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieLabAndCieLchuvConversionTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieLabAndCieLchuvConversionTests.cs @@ -24,7 +24,7 @@ public class CieLabAndCieLchuvConversionTests // Arrange CieLchuv input = new(l, c, h); CieLab expected = new(l2, a, b); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D50 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D50 }; ColorProfileConverter converter = new(options); Span inputSpan = new CieLchuv[5]; @@ -53,7 +53,7 @@ public class CieLabAndCieLchuvConversionTests // Arrange CieLab input = new(l, a, b); CieLchuv expected = new(l2, c, h); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D50, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D50, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); Span inputSpan = new CieLab[5]; diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieLabAndCieLuvConversionTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CieLabAndCieLuvConversionTests.cs index 44756c779a..0846bdda3f 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieLabAndCieLuvConversionTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieLabAndCieLuvConversionTests.cs @@ -24,7 +24,7 @@ public class CieLabAndCieLuvConversionTests // Arrange CieLuv input = new(l, u, v); CieLab expected = new(l2, a, b); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D50 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D50 }; ColorProfileConverter converter = new(options); Span inputSpan = new CieLuv[5]; @@ -53,7 +53,7 @@ public class CieLabAndCieLuvConversionTests // Arrange CieLab input = new(l, a, b); CieLuv expected = new(l2, u, v); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D50, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D50, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); Span inputSpan = new CieLab[5]; diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieLabAndYCbCrConversionTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CieLabAndYCbCrConversionTests.cs index 9a29b15398..15677c46f0 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieLabAndYCbCrConversionTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieLabAndYCbCrConversionTests.cs @@ -13,8 +13,9 @@ public class CieLabAndYCbCrConversionTests private static readonly ApproximateColorProfileComparer Comparer = new(.0002F); [Theory] - [InlineData(0, 128, 128, 0, 0, 0)] - [InlineData(87.4179, 133.9763, 247.5308, 55.06287, 82.54838, 23.1697)] + [InlineData(1, .5F, .5F, 100, 0, 0)] + [InlineData(0, .5F, .5F, 0, 0, 0)] + [InlineData(.5F, .5F, .5F, 53.38897F, 0, 0)] public void Convert_YCbCr_to_CieLab(float y, float cb, float cr, float l, float a, float b) { // Arrange @@ -41,8 +42,9 @@ public class CieLabAndYCbCrConversionTests } [Theory] - [InlineData(0, 0, 0, 0, 128, 128)] - [InlineData(55.06287, 82.54838, 23.1697, 87.41701, 133.97232, 247.5314)] + [InlineData(100, 0, 0, 1, .5F, .5F)] + [InlineData(0, 0, 0, 0, .5F, .5F)] + [InlineData(53.38897F, 0, 0, .5F, .5F, .5F)] public void Convert_CieLab_to_YCbCr(float l, float a, float b, float y, float cb, float cr) { // Arrange diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieLabTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CieLabTests.cs index 3c015259b1..69fabc7508 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieLabTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieLabTests.cs @@ -9,6 +9,7 @@ namespace SixLabors.ImageSharp.Tests.ColorProfiles; /// /// Tests the struct. /// +[Trait("Color", "Conversion")] public class CieLabTests { [Fact] diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieLchAndCieLuvConversionTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CieLchAndCieLuvConversionTests.cs index 598d4af335..12313281fa 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieLchAndCieLuvConversionTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieLchAndCieLuvConversionTests.cs @@ -20,7 +20,7 @@ public class CieLchAndCieLuvConversionTests // Arrange CieLch input = new(l, c, h); CieLuv expected = new(l2, u, v); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D50, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D50, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); Span inputSpan = new CieLch[5]; @@ -48,7 +48,7 @@ public class CieLchAndCieLuvConversionTests // Arrange CieLuv input = new(l2, u, v); CieLch expected = new(l, c, h); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D50 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D50 }; ColorProfileConverter converter = new(options); Span inputSpan = new CieLuv[5]; diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieLchuvAndCieLchConversionTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CieLchuvAndCieLchConversionTests.cs index a3e0b45e0d..857bdb3da1 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieLchuvAndCieLchConversionTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieLchuvAndCieLchConversionTests.cs @@ -20,7 +20,7 @@ public class CieLchuvAndCieLchConversionTests // Arrange CieLch input = new(l2, c2, h2); CieLchuv expected = new(l, c, h); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D50, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D50, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); Span inputSpan = new CieLch[5]; @@ -48,7 +48,7 @@ public class CieLchuvAndCieLchConversionTests // Arrange CieLchuv input = new(l, c, h); CieLch expected = new(l2, c2, h2); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D50 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D50 }; ColorProfileConverter converter = new(options); Span inputSpan = new CieLchuv[5]; diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieLchuvAndCieLuvConversionTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CieLchuvAndCieLuvConversionTests.cs index 465237490d..424cb8cc77 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieLchuvAndCieLuvConversionTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieLchuvAndCieLuvConversionTests.cs @@ -12,6 +12,7 @@ namespace SixLabors.ImageSharp.Tests.ColorProfiles; /// Test data generated using: /// /// +[Trait("Color", "Conversion")] public class CieLchuvAndCieLuvConversionTests { private static readonly ApproximateColorProfileComparer Comparer = new(.0001F); @@ -30,7 +31,7 @@ public class CieLchuvAndCieLuvConversionTests // Arrange CieLchuv input = new(l, c, h); CieLuv expected = new(l2, u, v); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); Span inputSpan = new CieLchuv[5]; @@ -66,7 +67,7 @@ public class CieLchuvAndCieLuvConversionTests // Arrange CieLuv input = new(l, u, v); CieLchuv expected = new(l2, c, h); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); Span inputSpan = new CieLuv[5]; diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieLchuvAndCmykConversionTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CieLchuvAndCmykConversionTests.cs index 60ac3da16e..3c8a93ee12 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieLchuvAndCmykConversionTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieLchuvAndCmykConversionTests.cs @@ -20,7 +20,7 @@ public class CieLchuvAndCmykConversionTests // Arrange Cmyk input = new(c2, m, y, k); CieLchuv expected = new(l, c, h); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); Span inputSpan = new Cmyk[5]; @@ -49,7 +49,7 @@ public class CieLchuvAndCmykConversionTests // Arrange CieLchuv input = new(l, c, h); Cmyk expected = new(c2, m, y, k); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); Span inputSpan = new CieLchuv[5]; diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieLchuvTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CieLchuvTests.cs index 0b737cdfca..3fe550a5ba 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieLchuvTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieLchuvTests.cs @@ -9,6 +9,7 @@ namespace SixLabors.ImageSharp.Tests.ColorProfiles; /// /// Tests the struct. /// +[Trait("Color", "Conversion")] public class CieLchuvTests { [Fact] diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndCieXyyConversionTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndCieXyyConversionTests.cs index e73edcda7c..08e73a1a71 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndCieXyyConversionTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndCieXyyConversionTests.cs @@ -20,7 +20,7 @@ public class CieLuvAndCieXyyConversionTests // Arrange CieLuv input = new(l, u, v); CieXyy expected = new(x, y, yl); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); Span inputSpan = new CieLuv[5]; @@ -49,7 +49,7 @@ public class CieLuvAndCieXyyConversionTests // Arrange CieXyy input = new(x, y, yl); CieLuv expected = new(l, u, v); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); Span inputSpan = new CieXyy[5]; diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndHslConversionTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndHslConversionTests.cs index b178b22b20..bfcd236c75 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndHslConversionTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndHslConversionTests.cs @@ -20,7 +20,7 @@ public class CieLuvAndHslConversionTests // Arrange CieLuv input = new(l, u, v); Hsl expected = new(h, s, l2); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); Span inputSpan = new CieLuv[5]; @@ -49,7 +49,7 @@ public class CieLuvAndHslConversionTests // Arrange Hsl input = new(h, s, l2); CieLuv expected = new(l, u, v); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); Span inputSpan = new Hsl[5]; diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndHsvConversionTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndHsvConversionTests.cs index 2866093377..8a25f95b7b 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndHsvConversionTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndHsvConversionTests.cs @@ -20,7 +20,7 @@ public class CieLuvAndHsvConversionTests // Arrange CieLuv input = new(l, u, v); Hsv expected = new(h, s, v2); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); Span inputSpan = new CieLuv[5]; @@ -49,7 +49,7 @@ public class CieLuvAndHsvConversionTests // Arrange Hsv input = new(h, s, v2); CieLuv expected = new(l, u, v); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); Span inputSpan = new Hsv[5]; diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndHunterLabConversionTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndHunterLabConversionTests.cs index 73b605fb62..1c667f6794 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndHunterLabConversionTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndHunterLabConversionTests.cs @@ -20,7 +20,7 @@ public class CieLuvAndHunterLabConversionTests // Arrange CieLuv input = new(l, u, v); HunterLab expected = new(l2, a, b); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D50 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D50 }; ColorProfileConverter converter = new(options); Span inputSpan = new CieLuv[5]; @@ -49,7 +49,7 @@ public class CieLuvAndHunterLabConversionTests // Arrange HunterLab input = new(l2, a, b); CieLuv expected = new(l, u, v); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D50, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D50, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); Span inputSpan = new HunterLab[5]; diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndLmsConversionTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndLmsConversionTests.cs index 812ca44ddc..812b2b61e5 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndLmsConversionTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndLmsConversionTests.cs @@ -20,7 +20,7 @@ public class CieLuvAndLmsConversionTests // Arrange CieLuv input = new(l, u, v); Lms expected = new(l2, m, s); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); Span inputSpan = new CieLuv[5]; @@ -49,7 +49,7 @@ public class CieLuvAndLmsConversionTests // Arrange Lms input = new(l2, m, s); CieLuv expected = new(l, u, v); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); Span inputSpan = new Lms[5]; diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndRgbConversionTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndRgbConversionTests.cs index f1da6e33fd..1af802326e 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndRgbConversionTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndRgbConversionTests.cs @@ -20,7 +20,7 @@ public class CieLuvAndRgbConversionTests // Arrange CieLuv input = new(l, u, v); Rgb expected = new(r, g, b); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); Span inputSpan = new CieLuv[5]; @@ -49,7 +49,7 @@ public class CieLuvAndRgbConversionTests // Arrange Rgb input = new(r, g, b); CieLuv expected = new(l, u, v); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); Span inputSpan = new Rgb[5]; diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndYCbCrConversionTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndYCbCrConversionTests.cs index fa7e2ece3f..62b276a1f1 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndYCbCrConversionTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieLuvAndYCbCrConversionTests.cs @@ -13,14 +13,15 @@ public class CieLuvAndYCbCrConversionTests private static readonly ApproximateColorProfileComparer Comparer = new(.0002F); [Theory] - [InlineData(0, 0, 0, 0, 128, 128)] - [InlineData(36.0555, 93.6901, 10.01514, 71.8283, 119.3174, 193.9839)] + [InlineData(100, 0, 0, 1, .5F, .5F)] + [InlineData(0, 0, 0, 0, .5F, .5F)] + [InlineData(53.38897F, 0, 0, .5F, .5F, .5F)] public void Convert_CieLuv_to_YCbCr(float l, float u, float v, float y, float cb, float cr) { // Arrange CieLuv input = new(l, u, v); YCbCr expected = new(y, cb, cr); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); Span inputSpan = new CieLuv[5]; @@ -42,14 +43,15 @@ public class CieLuvAndYCbCrConversionTests } [Theory] - [InlineData(0, 128, 128, 0, 0, 0)] - [InlineData(71.8283, 119.3174, 193.9839, 36.00565, 93.44593, 10.2234)] + [InlineData(1, .5F, .5F, 100, 0, 0)] + [InlineData(0, .5F, .5F, 0, 0, 0)] + [InlineData(.5F, .5F, .5F, 53.38897F, 0, 0)] public void Convert_YCbCr_to_CieLuv(float y, float cb, float cr, float l, float u, float v) { // Arrange YCbCr input = new(y, cb, cr); CieLuv expected = new(l, u, v); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); Span inputSpan = new YCbCr[5]; diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieLuvTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CieLuvTests.cs index db903a0bf5..173491081d 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieLuvTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieLuvTests.cs @@ -9,6 +9,7 @@ namespace SixLabors.ImageSharp.Tests.ColorProfiles; /// /// Tests the struct. /// +[Trait("Color", "Conversion")] public class CieLuvTests { [Fact] diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieXyChromaticityCoordinatesTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CieXyChromaticityCoordinatesTests.cs index a85a08a21e..8bc71f1e18 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieXyChromaticityCoordinatesTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieXyChromaticityCoordinatesTests.cs @@ -8,6 +8,7 @@ namespace SixLabors.ImageSharp.Tests.ColorProfiles; /// /// Tests the struct. /// +[Trait("Color", "Conversion")] public class CieXyChromaticityCoordinatesTests { [Fact] diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieXyyAndYCbCrConversionTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CieXyyAndYCbCrConversionTests.cs index 1fe3596036..f9d571e036 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieXyyAndYCbCrConversionTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieXyyAndYCbCrConversionTests.cs @@ -13,8 +13,9 @@ public class CieXyyAndYCbCrConversionTests private static readonly ApproximateColorProfileComparer Comparer = new(.0002f); [Theory] - [InlineData(0, 0, 0, 0, 128, 128)] - [InlineData(0.360555, 0.936901, 0.1001514, 64.0204849, 91.87107, 82.33627)] + [InlineData(.34566915F, .358496159F, .99999994F, 1, .5F, .5F)] + [InlineData(0, 0, 0, 0, .5F, .5F)] + [InlineData(.34566915F, .358496159F, .214041144F, .5F, .5F, .5F)] public void Convert_CieXyy_to_YCbCr(float x, float y, float yl, float y2, float cb, float cr) { // Arrange @@ -41,8 +42,9 @@ public class CieXyyAndYCbCrConversionTests } [Theory] - [InlineData(0, 128, 128, 0, 0, 0)] - [InlineData(64.0204849, 91.87107, 82.33627, 0.32114, 0.59787, 0.10976)] + [InlineData(1, .5F, .5F, .34566915F, .358496159F, .99999994F)] + [InlineData(0, .5F, .5F, 0, 0, 0)] + [InlineData(.5F, .5F, .5F, .34566915F, .358496159F, .214041144F)] public void Convert_YCbCr_to_CieXyy(float y2, float cb, float cr, float x, float y, float yl) { // Arrange diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieXyyTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CieXyyTests.cs index 245512f8a8..80904c5df1 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieXyyTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieXyyTests.cs @@ -9,6 +9,7 @@ namespace SixLabors.ImageSharp.Tests.ColorProfiles; /// /// Tests the struct. /// +[Trait("Color", "Conversion")] public class CieXyyTests { [Fact] diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieXyzAndCieLabConversionTest.cs b/tests/ImageSharp.Tests/ColorProfiles/CieXyzAndCieLabConversionTest.cs index cb4d028895..76fceec413 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieXyzAndCieLabConversionTest.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieXyzAndCieLabConversionTest.cs @@ -12,6 +12,7 @@ namespace SixLabors.ImageSharp.Tests.ColorProfiles; /// Test data generated using: /// /// +[Trait("Color", "Conversion")] public class CieXyzAndCieLabConversionTest { private static readonly ApproximateColorProfileComparer Comparer = new(.0001f); @@ -29,7 +30,7 @@ public class CieXyzAndCieLabConversionTest { // Arrange CieLab input = new(l, a, b); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); CieXyz expected = new(x, y, z); @@ -62,7 +63,7 @@ public class CieXyzAndCieLabConversionTest { // Arrange CieXyz input = new(x, y, z); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); CieLab expected = new(l, a, b); diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieXyzAndCieLuvConversionTest.cs b/tests/ImageSharp.Tests/ColorProfiles/CieXyzAndCieLuvConversionTest.cs index 944b990054..b269818ae8 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieXyzAndCieLuvConversionTest.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieXyzAndCieLuvConversionTest.cs @@ -29,7 +29,7 @@ public class CieXyzAndCieLuvConversionTest CieXyz input = new(x, y, z); CieLuv expected = new(l, u, v); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); Span inputSpan = new CieXyz[5]; @@ -64,7 +64,7 @@ public class CieXyzAndCieLuvConversionTest CieLuv input = new(l, u, v); CieXyz expected = new(x, y, z); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D65 }; ColorProfileConverter converter = new(options); Span inputSpan = new CieLuv[5]; diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieXyzAndCieXyyConversionTest.cs b/tests/ImageSharp.Tests/ColorProfiles/CieXyzAndCieXyyConversionTest.cs index 7b1d0ac781..48bb6c1e16 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieXyzAndCieXyyConversionTest.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieXyzAndCieXyyConversionTest.cs @@ -12,6 +12,7 @@ namespace SixLabors.ImageSharp.Tests.ColorProfiles; /// Test data generated using: /// /// +[Trait("Color", "Conversion")] public class CieXyzAndCieXyyConversionTest { private static readonly ApproximateColorProfileComparer Comparer = new(.0001F); diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieXyzAndLmsConversionTest.cs b/tests/ImageSharp.Tests/ColorProfiles/CieXyzAndLmsConversionTest.cs index 185fcd256c..c7898904da 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieXyzAndLmsConversionTest.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieXyzAndLmsConversionTest.cs @@ -11,6 +11,7 @@ namespace SixLabors.ImageSharp.Tests.ColorProfiles; /// /// Test data generated using original colorful library. /// +[Trait("Color", "Conversion")] public class CieXyzAndLmsConversionTest { private static readonly ApproximateColorProfileComparer Comparer = new(.0001f); diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieXyzAndYCbCrConversionTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CieXyzAndYCbCrConversionTests.cs index 475673da84..90175a0585 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieXyzAndYCbCrConversionTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieXyzAndYCbCrConversionTests.cs @@ -13,8 +13,8 @@ public class CieXyzAndYCbCrConversionTests private static readonly ApproximateColorProfileComparer Comparer = new(.0002f); [Theory] - [InlineData(0, 0, 0, 0, 128, 128)] - [InlineData(0.360555, 0.936901, 0.1001514, 149.685, 43.52769, 21.23457)] + [InlineData(0, 0, 0, 0, .5F, .5F)] + [InlineData(.206382737F, .214041144F, .176628917F, .5F, .5F, .5F)] public void Convert_CieXyz_to_YCbCr(float x, float y, float z, float y2, float cb, float cr) { // Arrange @@ -41,8 +41,8 @@ public class CieXyzAndYCbCrConversionTests } [Theory] - [InlineData(0, 128, 128, 0, 0, 0)] - [InlineData(149.685, 43.52769, 21.23457, 0.38506496, 0.716878653, 0.0971045)] + [InlineData(0, .5F, .5F, 0, 0, 0)] + [InlineData(.5F, .5F, .5F, .206382737F, .214041144F, .176628917F)] public void Convert_YCbCr_to_CieXyz(float y2, float cb, float cr, float x, float y, float z) { // Arrange diff --git a/tests/ImageSharp.Tests/ColorProfiles/CieXyzTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CieXyzTests.cs index 88138304a8..683b3b6611 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CieXyzTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CieXyzTests.cs @@ -9,6 +9,7 @@ namespace SixLabors.ImageSharp.Tests.ColorProfiles; /// /// Tests the struct. /// +[Trait("Color", "Conversion")] public class CieXyzTests { [Fact] diff --git a/tests/ImageSharp.Tests/ColorProfiles/CmykAndYCbCrConversionTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CmykAndYCbCrConversionTests.cs index 64b47e2b97..3a5fe7c15c 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CmykAndYCbCrConversionTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CmykAndYCbCrConversionTests.cs @@ -13,8 +13,9 @@ public class CmykAndYCbCrConversionTests private static readonly ApproximateColorProfileComparer Comparer = new(.0002F); [Theory] - [InlineData(0, 0, 0, 0, 255, 128, 128)] - [InlineData(0.360555, 0.1036901, 0.818514, 0.274615, 136.5134, 69.90555, 114.9948)] + [InlineData(0, 0, 0, 1, 0, .5F, .5F)] + [InlineData(0, 0, 0, 0, 1, .5F, .5F)] + [InlineData(0, .8570679F, .49999997F, 0, .439901F, .5339159F, .899500132F)] public void Convert_Cmyk_To_YCbCr(float c, float m, float y, float k, float y2, float cb, float cr) { // Arrange @@ -41,8 +42,9 @@ public class CmykAndYCbCrConversionTests } [Theory] - [InlineData(255, 128, 128, 0, 0, 0, 5.960464E-08)] - [InlineData(136.5134, 69.90555, 114.9948, 0.2891567, 0, 0.7951807, 0.3490196)] + [InlineData(0, .5F, .5F, 0, 0, 0, 1)] + [InlineData(1, .5F, .5F, 0, 0, 0, 0)] + [InlineData(.5F, .5F, 1F, 0, .8570679F, .49999997F, 0)] public void Convert_YCbCr_To_Cmyk(float y2, float cb, float cr, float c, float m, float y, float k) { // Arrange diff --git a/tests/ImageSharp.Tests/ColorProfiles/CmykTests.cs b/tests/ImageSharp.Tests/ColorProfiles/CmykTests.cs index e2044a75d0..22b7a7f70c 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/CmykTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/CmykTests.cs @@ -9,6 +9,7 @@ namespace SixLabors.ImageSharp.Tests.ColorProfiles; /// /// Tests the struct. /// +[Trait("Color", "Conversion")] public class CmykTests { [Fact] diff --git a/tests/ImageSharp.Tests/ColorProfiles/ColorProfileConverterChomaticAdaptationTests.cs b/tests/ImageSharp.Tests/ColorProfiles/ColorProfileConverterChomaticAdaptationTests.cs index a90e5b9e86..525220d8e0 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/ColorProfileConverterChomaticAdaptationTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/ColorProfileConverterChomaticAdaptationTests.cs @@ -26,7 +26,7 @@ public class ColorProfileConverterChomaticAdaptationTests Rgb expected = new(r2, g2, b2); ColorConversionOptions options = new() { - RgbWorkingSpace = KnownRgbWorkingSpaces.WideGamutRgb, + SourceRgbWorkingSpace = KnownRgbWorkingSpaces.WideGamutRgb, TargetRgbWorkingSpace = KnownRgbWorkingSpaces.SRgb }; ColorProfileConverter converter = new(options); @@ -49,7 +49,7 @@ public class ColorProfileConverterChomaticAdaptationTests Rgb expected = new(r2, g2, b2); ColorConversionOptions options = new() { - RgbWorkingSpace = KnownRgbWorkingSpaces.SRgb, + SourceRgbWorkingSpace = KnownRgbWorkingSpaces.SRgb, TargetRgbWorkingSpace = KnownRgbWorkingSpaces.WideGamutRgb }; ColorProfileConverter converter = new(options); @@ -71,7 +71,7 @@ public class ColorProfileConverterChomaticAdaptationTests CieLab expected = new(l2, a2, b2); ColorConversionOptions options = new() { - WhitePoint = KnownIlluminants.D65, + SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D50 }; ColorProfileConverter converter = new(options); @@ -93,7 +93,7 @@ public class ColorProfileConverterChomaticAdaptationTests CieXyz expected = new(x2, y2, z2); ColorConversionOptions options = new() { - WhitePoint = KnownIlluminants.D65, + SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D50, AdaptationMatrix = KnownChromaticAdaptationMatrices.Bradford }; @@ -117,7 +117,7 @@ public class ColorProfileConverterChomaticAdaptationTests CieXyz expected = new(x2, y2, z2); ColorConversionOptions options = new() { - WhitePoint = KnownIlluminants.D65, + SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D50, AdaptationMatrix = KnownChromaticAdaptationMatrices.XyzScaling }; @@ -141,7 +141,7 @@ public class ColorProfileConverterChomaticAdaptationTests HunterLab expected = new(l2, a2, b2); ColorConversionOptions options = new() { - WhitePoint = KnownIlluminants.D65, + SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D50, }; @@ -164,7 +164,7 @@ public class ColorProfileConverterChomaticAdaptationTests CieLchuv expected = new(l2, c2, h2); ColorConversionOptions options = new() { - WhitePoint = KnownIlluminants.D65, + SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D50, AdaptationMatrix = KnownChromaticAdaptationMatrices.XyzScaling }; @@ -187,7 +187,7 @@ public class ColorProfileConverterChomaticAdaptationTests CieLch expected = new(l2, c2, h2); ColorConversionOptions options = new() { - WhitePoint = KnownIlluminants.D65, + SourceWhitePoint = KnownIlluminants.D65, TargetWhitePoint = KnownIlluminants.D50, AdaptationMatrix = KnownChromaticAdaptationMatrices.XyzScaling }; diff --git a/tests/ImageSharp.Tests/ColorProfiles/HslTests.cs b/tests/ImageSharp.Tests/ColorProfiles/HslTests.cs index d18e65117e..6697cbfde2 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/HslTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/HslTests.cs @@ -9,6 +9,7 @@ namespace SixLabors.ImageSharp.Tests.ColorProfiles; /// /// Tests the struct. /// +[Trait("Color", "Conversion")] public class HslTests { [Fact] diff --git a/tests/ImageSharp.Tests/ColorProfiles/HsvTests.cs b/tests/ImageSharp.Tests/ColorProfiles/HsvTests.cs index 46f58b18e2..dd71fcd3ff 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/HsvTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/HsvTests.cs @@ -9,6 +9,7 @@ namespace SixLabors.ImageSharp.Tests.ColorProfiles; /// /// Tests the struct. /// +[Trait("Color", "Conversion")] public class HsvTests { [Fact] diff --git a/tests/ImageSharp.Tests/ColorProfiles/HunterLabTests.cs b/tests/ImageSharp.Tests/ColorProfiles/HunterLabTests.cs index 5fbdd0788f..af06b3c91f 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/HunterLabTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/HunterLabTests.cs @@ -9,6 +9,7 @@ namespace SixLabors.ImageSharp.Tests.ColorProfiles; /// /// Tests the struct. /// +[Trait("Color", "Conversion")] public class HunterLabTests { [Fact] diff --git a/tests/ImageSharp.Tests/ColorProfiles/Icc/Calculators/ClutCalculatorTests.cs b/tests/ImageSharp.Tests/ColorProfiles/Icc/Calculators/ClutCalculatorTests.cs new file mode 100644 index 0000000000..249e7f4ed1 --- /dev/null +++ b/tests/ImageSharp.Tests/ColorProfiles/Icc/Calculators/ClutCalculatorTests.cs @@ -0,0 +1,27 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Numerics; +using SixLabors.ImageSharp.ColorProfiles.Icc.Calculators; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc.Conversion; + +namespace SixLabors.ImageSharp.Tests.ColorProfiles.Icc.Calculators; + +/// +/// Tests ICC +/// +[Trait("Color", "Conversion")] +public class ClutCalculatorTests +{ + [Theory] + [MemberData(nameof(IccConversionDataClut.ClutConversionTestData), MemberType = typeof(IccConversionDataClut))] + internal void ClutCalculator_WithClut_ReturnsResult(IccClut lut, Vector4 input, Vector4 expected) + { + ClutCalculator calculator = new(lut); + + Vector4 result = calculator.Calculate(input); + + VectorAssert.Equal(expected, result, 4); + } +} diff --git a/tests/ImageSharp.Tests/ColorProfiles/Icc/Calculators/CurveCalculatorTests.cs b/tests/ImageSharp.Tests/ColorProfiles/Icc/Calculators/CurveCalculatorTests.cs new file mode 100644 index 0000000000..8f48277d6c --- /dev/null +++ b/tests/ImageSharp.Tests/ColorProfiles/Icc/Calculators/CurveCalculatorTests.cs @@ -0,0 +1,26 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using SixLabors.ImageSharp.ColorProfiles.Conversion.Icc; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc.Conversion; + +namespace SixLabors.ImageSharp.Tests.ColorProfiles.Icc.Calculators; + +/// +/// Tests ICC +/// +[Trait("Color", "Conversion")] +public class CurveCalculatorTests +{ + [Theory] + [MemberData(nameof(IccConversionDataTrc.CurveConversionTestData), MemberType = typeof(IccConversionDataTrc))] + internal void CurveCalculator_WithCurveEntry_ReturnsResult(IccCurveTagDataEntry curve, bool inverted, float input, float expected) + { + CurveCalculator calculator = new(curve, inverted); + + float result = calculator.Calculate(input); + + Assert.Equal(expected, result, 4f); + } +} diff --git a/tests/ImageSharp.Tests/ColorProfiles/Icc/Calculators/LutABCalculatorTests.cs b/tests/ImageSharp.Tests/ColorProfiles/Icc/Calculators/LutABCalculatorTests.cs new file mode 100644 index 0000000000..de2b4f5fae --- /dev/null +++ b/tests/ImageSharp.Tests/ColorProfiles/Icc/Calculators/LutABCalculatorTests.cs @@ -0,0 +1,38 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Numerics; +using SixLabors.ImageSharp.ColorProfiles.Conversion.Icc; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc.Conversion; + +namespace SixLabors.ImageSharp.Tests.ColorProfiles.Icc.Calculators; + +/// +/// Tests ICC +/// +[Trait("Color", "Conversion")] +public class LutABCalculatorTests +{ + [Theory] + [MemberData(nameof(IccConversionDataLutAB.LutAToBConversionTestData), MemberType = typeof(IccConversionDataLutAB))] + internal void LutABCalculator_WithLutAToB_ReturnsResult(IccLutAToBTagDataEntry lut, Vector4 input, Vector4 expected) + { + LutABCalculator calculator = new(lut); + + Vector4 result = calculator.Calculate(input); + + VectorAssert.Equal(expected, result, 4); + } + + [Theory] + [MemberData(nameof(IccConversionDataLutAB.LutBToAConversionTestData), MemberType = typeof(IccConversionDataLutAB))] + internal void LutABCalculator_WithLutBToA_ReturnsResult(IccLutBToATagDataEntry lut, Vector4 input, Vector4 expected) + { + LutABCalculator calculator = new(lut); + + Vector4 result = calculator.Calculate(input); + + VectorAssert.Equal(expected, result, 4); + } +} diff --git a/tests/ImageSharp.Tests/ColorProfiles/Icc/Calculators/LutCalculatorTests.cs b/tests/ImageSharp.Tests/ColorProfiles/Icc/Calculators/LutCalculatorTests.cs new file mode 100644 index 0000000000..6cc77247a9 --- /dev/null +++ b/tests/ImageSharp.Tests/ColorProfiles/Icc/Calculators/LutCalculatorTests.cs @@ -0,0 +1,25 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using SixLabors.ImageSharp.ColorProfiles.Icc.Calculators; +using SixLabors.ImageSharp.Tests.TestDataIcc.Conversion; + +namespace SixLabors.ImageSharp.Tests.ColorProfiles.Icc.Calculators; + +/// +/// Tests ICC +/// +[Trait("Color", "Conversion")] +public class LutCalculatorTests +{ + [Theory] + [MemberData(nameof(IccConversionDataLut.LutConversionTestData), MemberType = typeof(IccConversionDataLut))] + internal void LutCalculator_WithLut_ReturnsResult(float[] lut, bool inverted, float input, float expected) + { + LutCalculator calculator = new(lut, inverted); + + float result = calculator.Calculate(input); + + Assert.Equal(expected, result, 4f); + } +} diff --git a/tests/ImageSharp.Tests/ColorProfiles/Icc/Calculators/LutEntryCalculatorTests.cs b/tests/ImageSharp.Tests/ColorProfiles/Icc/Calculators/LutEntryCalculatorTests.cs new file mode 100644 index 0000000000..14f1386eb8 --- /dev/null +++ b/tests/ImageSharp.Tests/ColorProfiles/Icc/Calculators/LutEntryCalculatorTests.cs @@ -0,0 +1,38 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Numerics; +using SixLabors.ImageSharp.ColorProfiles.Icc.Calculators; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc.Conversion; + +namespace SixLabors.ImageSharp.Tests.ColorProfiles.Icc.Calculators; + +/// +/// Tests ICC +/// +[Trait("Color", "Conversion")] +public class LutEntryCalculatorTests +{ + [Theory] + [MemberData(nameof(IccConversionDataLutEntry.Lut8ConversionTestData), MemberType = typeof(IccConversionDataLutEntry))] + internal void LutEntryCalculator_WithLut8_ReturnsResult(IccLut8TagDataEntry lut, Vector4 input, Vector4 expected) + { + LutEntryCalculator calculator = new(lut); + + Vector4 result = calculator.Calculate(input); + + VectorAssert.Equal(expected, result, 4); + } + + [Theory] + [MemberData(nameof(IccConversionDataLutEntry.Lut16ConversionTestData), MemberType = typeof(IccConversionDataLutEntry))] + internal void LutEntryCalculator_WithLut16_ReturnsResult(IccLut16TagDataEntry lut, Vector4 input, Vector4 expected) + { + LutEntryCalculator calculator = new(lut); + + Vector4 result = calculator.Calculate(input); + + VectorAssert.Equal(expected, result, 4); + } +} diff --git a/tests/ImageSharp.Tests/ColorProfiles/Icc/Calculators/MatrixCalculatorTests.cs b/tests/ImageSharp.Tests/ColorProfiles/Icc/Calculators/MatrixCalculatorTests.cs new file mode 100644 index 0000000000..f56bf5873e --- /dev/null +++ b/tests/ImageSharp.Tests/ColorProfiles/Icc/Calculators/MatrixCalculatorTests.cs @@ -0,0 +1,26 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Numerics; +using SixLabors.ImageSharp.ColorProfiles.Icc.Calculators; +using SixLabors.ImageSharp.Tests.TestDataIcc.Conversion; + +namespace SixLabors.ImageSharp.Tests.ColorProfiles.Icc.Calculators; + +/// +/// Tests ICC +/// +[Trait("Color", "Conversion")] +public class MatrixCalculatorTests +{ + [Theory] + [MemberData(nameof(IccConversionDataMatrix.MatrixConversionTestData), MemberType = typeof(IccConversionDataMatrix))] + internal void MatrixCalculator_WithMatrix_ReturnsResult(Matrix4x4 matrix2D, Vector3 matrix1D, Vector4 input, Vector4 expected) + { + MatrixCalculator calculator = new(matrix2D, matrix1D); + + Vector4 result = calculator.Calculate(input); + + VectorAssert.Equal(expected, result, 4); + } +} diff --git a/tests/ImageSharp.Tests/ColorProfiles/Icc/Calculators/ParametricCurveCalculatorTests.cs b/tests/ImageSharp.Tests/ColorProfiles/Icc/Calculators/ParametricCurveCalculatorTests.cs new file mode 100644 index 0000000000..aac3f42c9b --- /dev/null +++ b/tests/ImageSharp.Tests/ColorProfiles/Icc/Calculators/ParametricCurveCalculatorTests.cs @@ -0,0 +1,26 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using SixLabors.ImageSharp.ColorProfiles.Icc.Calculators; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc.Conversion; + +namespace SixLabors.ImageSharp.Tests.ColorProfiles.Icc.Calculators; + +/// +/// Tests ICC +/// +[Trait("Color", "Conversion")] +public class ParametricCurveCalculatorTests +{ + [Theory] + [MemberData(nameof(IccConversionDataTrc.ParametricCurveConversionTestData), MemberType = typeof(IccConversionDataTrc))] + internal void ParametricCurveCalculator_WithCurveEntry_ReturnsResult(IccParametricCurveTagDataEntry curve, bool inverted, float input, float expected) + { + ParametricCurveCalculator calculator = new(curve, inverted); + + float result = calculator.Calculate(input); + + Assert.Equal(expected, result, 4f); + } +} diff --git a/tests/ImageSharp.Tests/ColorProfiles/Icc/Calculators/TrcCalculatorTests.cs b/tests/ImageSharp.Tests/ColorProfiles/Icc/Calculators/TrcCalculatorTests.cs new file mode 100644 index 0000000000..65f02c3fb7 --- /dev/null +++ b/tests/ImageSharp.Tests/ColorProfiles/Icc/Calculators/TrcCalculatorTests.cs @@ -0,0 +1,27 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Numerics; +using SixLabors.ImageSharp.ColorProfiles.Icc.Calculators; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc.Conversion; + +namespace SixLabors.ImageSharp.Tests.ColorProfiles.Icc.Calculators; + +/// +/// Tests ICC +/// +[Trait("Color", "Conversion")] +public class TrcCalculatorTests +{ + [Theory] + [MemberData(nameof(IccConversionDataTrc.TrcArrayConversionTestData), MemberType = typeof(IccConversionDataTrc))] + internal void TrcCalculator_WithCurvesArray_ReturnsResult(IccTagDataEntry[] entries, bool inverted, Vector4 input, Vector4 expected) + { + TrcCalculator calculator = new(entries, inverted); + + Vector4 result = calculator.Calculate(input); + + VectorAssert.Equal(expected, result, 4); + } +} diff --git a/tests/ImageSharp.Tests/ColorProfiles/Icc/ColorProfileConverterTests.Icc.cs b/tests/ImageSharp.Tests/ColorProfiles/Icc/ColorProfileConverterTests.Icc.cs new file mode 100644 index 0000000000..7e01a629bc --- /dev/null +++ b/tests/ImageSharp.Tests/ColorProfiles/Icc/ColorProfileConverterTests.Icc.cs @@ -0,0 +1,262 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Numerics; +using SixLabors.ImageSharp.ColorProfiles; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using Wacton.Unicolour; +using Wacton.Unicolour.Icc; +using Xunit.Abstractions; +using Rgb = SixLabors.ImageSharp.ColorProfiles.Rgb; + +namespace SixLabors.ImageSharp.Tests.ColorProfiles.Icc; + +public class ColorProfileConverterTests(ITestOutputHelper testOutputHelper) +{ + // for 3-channel spaces, 4th item is ignored + private static readonly List Inputs = + [ + [0, 0, 0, 0], + [1, 0, 0, 0], + [0, 1, 0, 0], + [0, 0, 1, 0], + [0, 0, 0, 1], + [1, 1, 1, 1], + [0.5f, 0.5f, 0.5f, 0.5f], + [0.199678659f, 0.67982769f, 0.805381715f, 0.982666492f], // requires clipping before source is PCS adjusted for Fogra39 -> sRGBv2 + [0.776568174f, 0.961630166f, 0.31032759f, 0.895294666f], // requires clipping after target is PCS adjusted for Fogra39 -> sRGBv2 + [GetNormalizedRandomValue(), GetNormalizedRandomValue(), GetNormalizedRandomValue(), GetNormalizedRandomValue()] + ]; + + [Theory] + [InlineData(TestIccProfiles.Fogra39, TestIccProfiles.Fogra39)] // CMYK -> LAB -> CMYK (commonly used v2 profiles) + [InlineData(TestIccProfiles.Fogra39, TestIccProfiles.Swop2006)] // CMYK -> LAB -> CMYK (commonly used v2 profiles) + [InlineData(TestIccProfiles.Swop2006, TestIccProfiles.Fogra39)] // CMYK -> LAB -> CMYK (commonly used v2 profiles) + [InlineData(TestIccProfiles.Swop2006, TestIccProfiles.Swop2006)] // CMYK -> LAB -> CMYK (commonly used v2 profiles) + [InlineData(TestIccProfiles.Fogra39, TestIccProfiles.JapanColor2003)] // CMYK -> LAB -> CMYK (different bit depth v2 LUTs, 8-bit vs 16-bit) + [InlineData(TestIccProfiles.JapanColor2011, TestIccProfiles.Fogra39)] // CMYK -> LAB -> CMYK (different LUT versions, v2 vs v4) + [InlineData(TestIccProfiles.Fogra39, TestIccProfiles.Cgats21)] // CMYK -> LAB -> RGB (different LUT versions, v2 vs v4) + [InlineData(TestIccProfiles.Fogra39, TestIccProfiles.StandardRgbV4)] // RGB -> LAB -> CMYK (different LUT versions, v4 vs v2) + [InlineData(TestIccProfiles.StandardRgbV4, TestIccProfiles.Fogra39)] // RGB -> LAB -> XYZ -> RGB (different LUT elements, B-Matrix-M-CLUT-A vs B-Matrix-M) + [InlineData(TestIccProfiles.StandardRgbV4, TestIccProfiles.RommRgb)] // RGB -> XYZ -> LAB -> RGB (different LUT elements, B-Matrix-M vs B-Matrix-M-CLUT-A) + [InlineData(TestIccProfiles.RommRgb, TestIccProfiles.StandardRgbV4)] // CMYK -> LAB -> CMYK (different bit depth v2 LUTs, 16-bit vs 8-bit) + [InlineData(TestIccProfiles.Fogra39, TestIccProfiles.StandardRgbV2, 0.0005)] // CMYK -> LAB -> XYZ -> RGB (different LUT tags, A2B vs TRC) --- tolerance slightly higher due to difference in inverse curve implementation + [InlineData(TestIccProfiles.StandardRgbV2, TestIccProfiles.Fogra39)] // RGB -> XYZ -> LAB -> CMYK (different LUT tags, TRC vs A2B) + public void CanConvertIccProfiles(string sourceProfile, string targetProfile, double tolerance = 0.00005) + { + List actual = Inputs.ConvertAll(input => GetActualTargetValues(input, sourceProfile, targetProfile)); + AssertConversion(sourceProfile, targetProfile, actual, tolerance, testOutputHelper); + } + + [Theory] + [InlineData(TestIccProfiles.Fogra39, TestIccProfiles.Fogra39)] // CMYK -> LAB -> CMYK (commonly used v2 profiles) + [InlineData(TestIccProfiles.Fogra39, TestIccProfiles.Swop2006)] // CMYK -> LAB -> CMYK (commonly used v2 profiles) + [InlineData(TestIccProfiles.Swop2006, TestIccProfiles.Fogra39)] // CMYK -> LAB -> CMYK (commonly used v2 profiles) + [InlineData(TestIccProfiles.Swop2006, TestIccProfiles.Swop2006)] // CMYK -> LAB -> CMYK (commonly used v2 profiles) + [InlineData(TestIccProfiles.Fogra39, TestIccProfiles.JapanColor2003)] // CMYK -> LAB -> CMYK (different bit depth v2 LUTs, 8-bit vs 16-bit) + [InlineData(TestIccProfiles.JapanColor2011, TestIccProfiles.Fogra39)] // CMYK -> LAB -> CMYK (different LUT versions, v2 vs v4) + [InlineData(TestIccProfiles.Fogra39, TestIccProfiles.Cgats21)] // CMYK -> LAB -> RGB (different LUT versions, v2 vs v4) + [InlineData(TestIccProfiles.Fogra39, TestIccProfiles.StandardRgbV4)] // RGB -> LAB -> CMYK (different LUT versions, v4 vs v2) + [InlineData(TestIccProfiles.StandardRgbV4, TestIccProfiles.Fogra39)] // RGB -> LAB -> XYZ -> RGB (different LUT elements, B-Matrix-M-CLUT-A vs B-Matrix-M) + [InlineData(TestIccProfiles.StandardRgbV4, TestIccProfiles.RommRgb)] // RGB -> XYZ -> LAB -> RGB (different LUT elements, B-Matrix-M vs B-Matrix-M-CLUT-A) + [InlineData(TestIccProfiles.RommRgb, TestIccProfiles.StandardRgbV4)] // CMYK -> LAB -> CMYK (different bit depth v2 LUTs, 16-bit vs 8-bit) + [InlineData(TestIccProfiles.Fogra39, TestIccProfiles.StandardRgbV2, 0.0005)] // CMYK -> LAB -> XYZ -> RGB (different LUT tags, A2B vs TRC) --- tolerance slightly higher due to difference in inverse curve implementation + [InlineData(TestIccProfiles.StandardRgbV2, TestIccProfiles.Fogra39)] // RGB -> XYZ -> LAB -> CMYK (different LUT tags, TRC vs A2B) + public void CanBulkConvertIccProfiles(string sourceProfile, string targetProfile, double tolerance = 0.00005) + { + List actual = GetBulkActualTargetValues(Inputs, sourceProfile, targetProfile); + AssertConversion(sourceProfile, targetProfile, actual, tolerance, testOutputHelper); + } + + private static void AssertConversion(string sourceProfile, string targetProfile, List actual, double tolerance, ITestOutputHelper testOutputHelper) + { + List expected = Inputs.ConvertAll(input => GetExpectedTargetValues(sourceProfile, targetProfile, input, testOutputHelper)); + Assert.Equal(expected.Count, actual.Count); + + for (int i = 0; i < expected.Count; i++) + { + Log(testOutputHelper, Inputs[i], expected[i], actual[i]); + for (int j = 0; j < expected[i].Length; j++) + { + Assert.Equal(expected[i][j], actual[i][j], tolerance); + } + } + } + + private static double[] GetExpectedTargetValues(string sourceProfile, string targetProfile, float[] input, ITestOutputHelper testOutputHelper) + { + Wacton.Unicolour.Configuration sourceConfig = TestIccProfiles.GetUnicolourConfiguration(sourceProfile); + Wacton.Unicolour.Configuration targetConfig = TestIccProfiles.GetUnicolourConfiguration(targetProfile); + + if (sourceConfig.Icc.Error != null || targetConfig.Icc.Error != null) + { + Assert.Fail("Unicolour does not support the ICC profile - test values will need to be calculated manually"); + } + + /* This is a hack to trick Unicolour to work in the same way as ImageSharp. + * ImageSharp bypasses PCS adjustment for v2 perceptual intent if source and target both need it + * as they both share the same understanding of what the PCS is (see ColorProfileConverterExtensionsIcc.GetTargetPcsWithPerceptualAdjustment) + * Unicolour does not support a direct profile-to-profile conversion so will always perform PCS adjustment for v2 perceptual intent. + * However, PCS adjustment clips negative XYZ values, causing those particular values in Unicolour and ImageSharp to diverge. + * It's unclear to me if there's a fundamental correct answer here. + * + * There are two obvious ways to keep Unicolour and ImageSharp values aligned: + * 1. Make ImageSharp always perform PCS adjustment, clipping negative XYZ values during the process - but creates a lot more calculations + * 2. Make Unicolour stop performing PCS adjustment, allowing negative XYZ values during conversion + * + * Option 2 is implemented by modifying the profiles so they claim to be v4 profiles + * since v4 perceptual profiles do not apply PCS adjustment. + */ + bool isSourcePerceptualV2 = sourceConfig.Icc.Intent == Intent.Perceptual && sourceConfig.Icc.Profile!.Header.ProfileVersion.Major == 2; + bool isTargetPerceptualV2 = targetConfig.Icc.Intent == Intent.Perceptual && targetConfig.Icc.Profile!.Header.ProfileVersion.Major == 2; + if (isSourcePerceptualV2 && isTargetPerceptualV2) + { + sourceConfig = GetUnicolourConfigAsV4Header(sourceConfig); + targetConfig = GetUnicolourConfigAsV4Header(targetConfig); + } + + Channels channels = new([.. input.Select(value => (double)value)]); + Unicolour source = new(sourceConfig, channels); + Unicolour target = source.ConvertToConfiguration(targetConfig); + if (target.Icc.Error != null) + { + testOutputHelper.WriteLine($"Error during Unicolour ICC conversion of supported profile: {target.Icc.Error}"); + } + + return target.Icc.Values; + } + + private static Wacton.Unicolour.Configuration GetUnicolourConfigAsV4Header(Wacton.Unicolour.Configuration config) + { + string profilePath = config.Icc.Profile!.FileInfo.FullName; + string modifiedFilename = $"{Path.GetFileNameWithoutExtension(profilePath)}_modified.icc"; + string modifiedProfile = Path.Combine(Path.GetDirectoryName(profilePath)!, modifiedFilename); + + Wacton.Unicolour.Configuration modifiedConfig; + if (!TestIccProfiles.HasUnicolourConfiguration(modifiedProfile)) + { + byte[] bytes = File.ReadAllBytes(profilePath); + bytes[8] = 4; // byte 8 of profile is major version + File.WriteAllBytes(modifiedProfile, bytes); + modifiedConfig = TestIccProfiles.GetUnicolourConfiguration(modifiedProfile); + File.Delete(modifiedProfile); + } + else + { + modifiedConfig = TestIccProfiles.GetUnicolourConfiguration(modifiedProfile); + } + + return modifiedConfig; + } + + private static Vector4 GetActualTargetValues(float[] input, string sourceProfile, string targetProfile) + { + ColorProfileConverter converter = new(new ColorConversionOptions + { + SourceIccProfile = TestIccProfiles.GetProfile(sourceProfile), + TargetIccProfile = TestIccProfiles.GetProfile(targetProfile) + }); + + IccColorSpaceType sourceDataSpace = converter.Options.SourceIccProfile!.Header.DataColorSpace; + IccColorSpaceType targetDataSpace = converter.Options.TargetIccProfile!.Header.DataColorSpace; + return sourceDataSpace switch + { + IccColorSpaceType.Cmyk when targetDataSpace == IccColorSpaceType.Cmyk + => converter.Convert(new Cmyk(new Vector4(input))).ToScaledVector4(), + IccColorSpaceType.Cmyk when targetDataSpace == IccColorSpaceType.Rgb + => converter.Convert(new Cmyk(new Vector4(input))).ToScaledVector4(), + IccColorSpaceType.Rgb when targetDataSpace == IccColorSpaceType.Cmyk + => converter.Convert(new Rgb(new Vector3(input))).ToScaledVector4(), + IccColorSpaceType.Rgb when targetDataSpace == IccColorSpaceType.Rgb + => converter.Convert(new Rgb(new Vector3(input))).ToScaledVector4(), + _ => throw new NotSupportedException($"Unsupported ICC profile data color space conversion: {sourceDataSpace} -> {targetDataSpace}") + }; + } + + private static List GetBulkActualTargetValues(List inputs, string sourceProfile, string targetProfile) + { + ColorProfileConverter converter = new(new ColorConversionOptions + { + SourceIccProfile = TestIccProfiles.GetProfile(sourceProfile), + TargetIccProfile = TestIccProfiles.GetProfile(targetProfile) + }); + + IccColorSpaceType sourceDataSpace = converter.Options.SourceIccProfile!.Header.DataColorSpace; + IccColorSpaceType targetDataSpace = converter.Options.TargetIccProfile!.Header.DataColorSpace; + + switch (sourceDataSpace) + { + case IccColorSpaceType.Cmyk: + { + Span inputSpan = inputs.Select(x => new Cmyk(new Vector4(x))).ToArray(); + + switch (targetDataSpace) + { + case IccColorSpaceType.Cmyk: + { + Span outputSpan = stackalloc Cmyk[inputs.Count]; + converter.Convert(inputSpan, outputSpan); + return [.. outputSpan.ToArray().Select(x => x.ToScaledVector4())]; + } + + case IccColorSpaceType.Rgb: + { + Span outputSpan = stackalloc Rgb[inputs.Count]; + converter.Convert(inputSpan, outputSpan); + return [.. outputSpan.ToArray().Select(x => x.ToScaledVector4())]; + } + + default: + throw new NotSupportedException($"Unsupported ICC profile data color space conversion: {sourceDataSpace} -> {targetDataSpace}"); + } + } + + case IccColorSpaceType.Rgb: + { + Span inputSpan = inputs.Select(x => new Rgb(new Vector3(x))).ToArray(); + + switch (targetDataSpace) + { + case IccColorSpaceType.Cmyk: + { + Span outputSpan = stackalloc Cmyk[inputs.Count]; + converter.Convert(inputSpan, outputSpan); + return [.. outputSpan.ToArray().Select(x => x.ToScaledVector4())]; + } + + case IccColorSpaceType.Rgb: + { + Span outputSpan = stackalloc Rgb[inputs.Count]; + converter.Convert(inputSpan, outputSpan); + return [.. outputSpan.ToArray().Select(x => x.ToScaledVector4())]; + } + + default: + throw new NotSupportedException($"Unsupported ICC profile data color space conversion: {sourceDataSpace} -> {targetDataSpace}"); + } + } + + default: + throw new NotSupportedException($"Unsupported ICC profile data color space conversion: {sourceDataSpace} -> {targetDataSpace}"); + } + } + + private static float GetNormalizedRandomValue() + { + // Generate a random value between 0 (inclusive) and 1 (exclusive). + double value = Random.Shared.NextDouble(); + + // If the random value is exactly 0, return 0F to ensure inclusivity at the lower bound. + // For non-zero values, add a small increment (0.0000001F) to ensure the range + // is inclusive at the upper bound while retaining precision. + // Clamp the result between 0 and 1 to ensure it does not exceed the bounds. + return value == 0 ? 0F : Math.Clamp((float)value + 0.0000001F, 0, 1); + } + + private static void Log(ITestOutputHelper testOutputHelper, float[] input, double[] expected, Vector4 actual) + { + string inputText = string.Join(", ", input); + string expectedText = string.Join(", ", expected.Select(x => $"{x:f8}")); + testOutputHelper.WriteLine($"Input {inputText} · Expected output {expectedText} · Actual output {actual}"); + } +} diff --git a/tests/ImageSharp.Tests/ColorProfiles/Icc/TestIccProfiles.cs b/tests/ImageSharp.Tests/ColorProfiles/Icc/TestIccProfiles.cs new file mode 100644 index 0000000000..3fc36a91b0 --- /dev/null +++ b/tests/ImageSharp.Tests/ColorProfiles/Icc/TestIccProfiles.cs @@ -0,0 +1,67 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Collections.Concurrent; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using Wacton.Unicolour.Icc; + +namespace SixLabors.ImageSharp.Tests.ColorProfiles.Icc; + +internal static class TestIccProfiles +{ + private static readonly ConcurrentDictionary ProfileCache = new(); + private static readonly ConcurrentDictionary UnicolourConfigurationCache = new(); + + /// + /// v2 CMYK -> LAB, output, lut16 + /// + public const string Fogra39 = "Coated_Fogra39L_VIGC_300.icc"; + /// + /// v2 CMYK -> LAB, output, lut16 + /// + public const string Swop2006 = "SWOP2006_Coated5v2.icc"; + + /// + /// v2 CMYK -> LAB, output, lut8 (A2B tags) + /// + public const string JapanColor2011 = "JapanColor2011Coated.icc"; + + /// + /// v2 CMYK -> LAB, output, lut8 (B2A tags) + /// + public const string JapanColor2003 = "JapanColor2003WebCoated.icc"; + + /// + /// v4 CMYK -> LAB, output, lutAToB: B-CLUT-A + /// + public const string Cgats21 = "CGATS21_CRPC7.icc"; + + /// + /// v4 RGB -> XYZ, colorspace, lutAToB: B-Matrix-M [only intent 0] + /// + public const string RommRgb = "ISO22028-2_ROMM-RGB.icc"; + + /// + /// v4 RGB -> LAB, colorspace, lutAToB: B-Matrix-M-CLUT-A [only intent 0 & 1] + /// + public const string StandardRgbV4 = "sRGB_v4_ICC_preference.icc"; + + /// + /// v2 RGB -> XYZ, display, TRCs + /// + public const string StandardRgbV2 = "sRGB2014.icc"; + + public static IccProfile GetProfile(string file) + => ProfileCache.GetOrAdd(file, f => new IccProfile(File.ReadAllBytes(GetFullPath(f)))); + + public static Wacton.Unicolour.Configuration GetUnicolourConfiguration(string file) + => UnicolourConfigurationCache.GetOrAdd( + file, + f => new Wacton.Unicolour.Configuration(iccConfig: new(GetFullPath(f), Intent.Unspecified, f))); + + public static bool HasUnicolourConfiguration(string file) + => UnicolourConfigurationCache.ContainsKey(file); + + private static string GetFullPath(string file) + => Path.GetFullPath(Path.Combine(".", "TestDataIcc", "Profiles", file)); +} diff --git a/tests/ImageSharp.Tests/ColorProfiles/LmsTests.cs b/tests/ImageSharp.Tests/ColorProfiles/LmsTests.cs index 138fd544da..395b547fdb 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/LmsTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/LmsTests.cs @@ -9,6 +9,7 @@ namespace SixLabors.ImageSharp.Tests.ColorProfiles; /// /// Tests the struct. /// +[Trait("Color", "Conversion")] public class LmsTests { [Fact] diff --git a/tests/ImageSharp.Tests/ColorProfiles/RbgAndYConversionTests.cs b/tests/ImageSharp.Tests/ColorProfiles/RbgAndYConversionTests.cs new file mode 100644 index 0000000000..1cd6f6cf41 --- /dev/null +++ b/tests/ImageSharp.Tests/ColorProfiles/RbgAndYConversionTests.cs @@ -0,0 +1,84 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using SixLabors.ImageSharp.ColorProfiles; + +namespace SixLabors.ImageSharp.Tests.ColorProfiles; + +/// +/// Tests - conversions. +/// +/// +/// Test data generated mathematically +/// +public class RbgAndYConversionTests +{ + private static readonly ApproximateColorProfileComparer Comparer = new(.001F); + + [Theory] + [InlineData(0F, 0F, 0F, 0F)] + [InlineData(0.5F, 0.5F, 0.5F, 0.5F)] + [InlineData(1F, 1F, 1F, 1F)] + public void Convert_Rgb_To_Y_BT601(float r, float g, float b, float y) + { + ColorConversionOptions options = new() + { + YCbCrMatrix = KnownYCbCrMatrices.BT601 + }; + + Convert_Rgb_To_Y_Core(r, g, b, y, options); + } + + [Theory] + [InlineData(0F, 0F, 0F, 0F)] + [InlineData(0.5F, 0.5F, 0.5F, 0.5F)] + [InlineData(1F, 1F, 1F, 1F)] + public void Convert_Rgb_To_Y_BT709(float r, float g, float b, float y) + { + ColorConversionOptions options = new() + { + YCbCrMatrix = KnownYCbCrMatrices.BT709 + }; + + Convert_Rgb_To_Y_Core(r, g, b, y, options); + } + + [Theory] + [InlineData(0F, 0F, 0F, 0F)] + [InlineData(0.5F, 0.5F, 0.5F, 0.49999997F)] + [InlineData(1F, 1F, 1F, 0.99999994F)] + public void Convert_Rgb_To_Y_BT2020(float r, float g, float b, float y) + { + ColorConversionOptions options = new() + { + YCbCrMatrix = KnownYCbCrMatrices.BT2020 + }; + + Convert_Rgb_To_Y_Core(r, g, b, y, options); + } + + private static void Convert_Rgb_To_Y_Core(float r, float g, float b, float y, ColorConversionOptions options) + { + // Arrange + Rgb input = new(r, g, b); + Y expected = new(y); + ColorProfileConverter converter = new(options); + + Span inputSpan = new Rgb[5]; + inputSpan.Fill(input); + + Span actualSpan = new Y[5]; + + // Act + Y actual = converter.Convert(input); + converter.Convert(inputSpan, actualSpan); + + // Assert + Assert.Equal(expected, actual, Comparer); + + for (int i = 0; i < actualSpan.Length; i++) + { + Assert.Equal(expected, actualSpan[i], Comparer); + } + } +} diff --git a/tests/ImageSharp.Tests/ColorProfiles/RgbAndCieXyzConversionTest.cs b/tests/ImageSharp.Tests/ColorProfiles/RgbAndCieXyzConversionTest.cs index c10aa2c3c5..7b48089c7c 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/RgbAndCieXyzConversionTest.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/RgbAndCieXyzConversionTest.cs @@ -27,7 +27,7 @@ public class RgbAndCieXyzConversionTest { // Arrange CieXyz input = new(x, y, z); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D50, TargetRgbWorkingSpace = KnownRgbWorkingSpaces.SRgb }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D50, TargetRgbWorkingSpace = KnownRgbWorkingSpaces.SRgb }; ColorProfileConverter converter = new(options); Rgb expected = new(r, g, b); @@ -60,7 +60,7 @@ public class RgbAndCieXyzConversionTest { // Arrange CieXyz input = new(x, y, z); - ColorConversionOptions options = new() { WhitePoint = KnownIlluminants.D65, TargetRgbWorkingSpace = KnownRgbWorkingSpaces.SRgb }; + ColorConversionOptions options = new() { SourceWhitePoint = KnownIlluminants.D65, TargetRgbWorkingSpace = KnownRgbWorkingSpaces.SRgb }; ColorProfileConverter converter = new(options); Rgb expected = new(r, g, b); @@ -93,7 +93,7 @@ public class RgbAndCieXyzConversionTest { // Arrange Rgb input = new(r, g, b); - ColorConversionOptions options = new() { TargetWhitePoint = KnownIlluminants.D50, RgbWorkingSpace = KnownRgbWorkingSpaces.SRgb }; + ColorConversionOptions options = new() { TargetWhitePoint = KnownIlluminants.D50, SourceRgbWorkingSpace = KnownRgbWorkingSpaces.SRgb }; ColorProfileConverter converter = new(options); CieXyz expected = new(x, y, z); @@ -126,7 +126,7 @@ public class RgbAndCieXyzConversionTest { // Arrange Rgb input = new(r, g, b); - ColorConversionOptions options = new() { TargetWhitePoint = KnownIlluminants.D65, RgbWorkingSpace = KnownRgbWorkingSpaces.SRgb }; + ColorConversionOptions options = new() { TargetWhitePoint = KnownIlluminants.D65, SourceRgbWorkingSpace = KnownRgbWorkingSpaces.SRgb }; ColorProfileConverter converter = new(options); CieXyz expected = new(x, y, z); diff --git a/tests/ImageSharp.Tests/ColorProfiles/RgbAndCmykConversionTest.cs b/tests/ImageSharp.Tests/ColorProfiles/RgbAndCmykConversionTest.cs index 4f4ecb70be..bd35fb7751 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/RgbAndCmykConversionTest.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/RgbAndCmykConversionTest.cs @@ -13,6 +13,7 @@ namespace SixLabors.ImageSharp.Tests.ColorProfiles; /// /// /// +[Trait("Color", "Conversion")] public class RgbAndCmykConversionTest { private static readonly ApproximateColorProfileComparer Comparer = new(.0001F); diff --git a/tests/ImageSharp.Tests/ColorProfiles/RgbAndHslConversionTest.cs b/tests/ImageSharp.Tests/ColorProfiles/RgbAndHslConversionTest.cs index 0dc95628b9..e5874c3d13 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/RgbAndHslConversionTest.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/RgbAndHslConversionTest.cs @@ -13,6 +13,7 @@ namespace SixLabors.ImageSharp.Tests.ColorProfiles; /// /// /// +[Trait("Color", "Conversion")] public class RgbAndHslConversionTest { private static readonly ApproximateColorProfileComparer Comparer = new(.0001f); diff --git a/tests/ImageSharp.Tests/ColorProfiles/RgbAndHsvConversionTest.cs b/tests/ImageSharp.Tests/ColorProfiles/RgbAndHsvConversionTest.cs index b89b576b6c..4a685abe5f 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/RgbAndHsvConversionTest.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/RgbAndHsvConversionTest.cs @@ -12,6 +12,7 @@ namespace SixLabors.ImageSharp.Tests.ColorProfiles; /// Test data generated using: /// /// +[Trait("Color", "Conversion")] public class RgbAndHsvConversionTest { private static readonly ApproximateColorProfileComparer Comparer = new(.0001f); diff --git a/tests/ImageSharp.Tests/ColorProfiles/RgbAndYCbCrConversionTest.cs b/tests/ImageSharp.Tests/ColorProfiles/RgbAndYCbCrConversionTest.cs index 91f7fc08ee..ede8226e40 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/RgbAndYCbCrConversionTest.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/RgbAndYCbCrConversionTest.cs @@ -16,9 +16,9 @@ public class RgbAndYCbCrConversionTest private static readonly ApproximateColorProfileComparer Comparer = new(.001F); [Theory] - [InlineData(255, 128, 128, 1, 1, 1)] - [InlineData(0, 128, 128, 0, 0, 0)] - [InlineData(128, 128, 128, 0.502, 0.502, 0.502)] + [InlineData(1, .5F, .5F, 1, 1, 1)] + [InlineData(0, .5F, .5F, 0, 0, 0)] + [InlineData(.5F, .5F, .5F, .5F, .5F, .5F)] public void Convert_YCbCr_To_Rgb(float y, float cb, float cr, float r, float g, float b) { // Arrange @@ -45,10 +45,9 @@ public class RgbAndYCbCrConversionTest } [Theory] - [InlineData(0, 0, 0, 0, 128, 128)] - [InlineData(1, 1, 1, 255, 128, 128)] - [InlineData(0.5, 0.5, 0.5, 127.5, 128, 128)] - [InlineData(1, 0, 0, 76.245, 84.972, 255)] + [InlineData(1, 1, 1, 1, .5F, .5F)] + [InlineData(0, 0, 0, 0, .5F, .5F)] + [InlineData(.5F, .5F, .5F, .5F, .5F, .5F)] public void Convert_Rgb_To_YCbCr(float r, float g, float b, float y, float cb, float cr) { // Arrange diff --git a/tests/ImageSharp.Tests/ColorProfiles/RgbAndYccKConversionTests.cs b/tests/ImageSharp.Tests/ColorProfiles/RgbAndYccKConversionTests.cs new file mode 100644 index 0000000000..78f424cc28 --- /dev/null +++ b/tests/ImageSharp.Tests/ColorProfiles/RgbAndYccKConversionTests.cs @@ -0,0 +1,80 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using SixLabors.ImageSharp.ColorProfiles; + +namespace SixLabors.ImageSharp.Tests.ColorProfiles; + +/// +/// Tests - conversions. +/// +/// +/// Test data generated mathematically +/// +public class RgbAndYccKConversionTests +{ + private static readonly ApproximateColorProfileComparer Comparer = new(.001F); + + [Theory] + [InlineData(1, .5F, .5F, 0, 1, 1, 1)] + [InlineData(0, .5F, .5F, 1, 0, 0, 0)] + [InlineData(.5F, .5F, .5F, 0, .5F, .5F, .5F)] + public void Convert_YccK_To_Rgb(float y, float cb, float cr, float k, float r, float g, float b) + { + // Arrange + YccK input = new(y, cb, cr, k); + Rgb expected = new(r, g, b); + ColorProfileConverter converter = new(); + + Span inputSpan = new YccK[5]; + inputSpan.Fill(input); + + Span actualSpan = new Rgb[5]; + + // Act + Rgb actual = converter.Convert(input); + converter.Convert(inputSpan, actualSpan); + + // Assert + Assert.Equal(expected, actual, Comparer); + + for (int i = 0; i < actualSpan.Length; i++) + { + Assert.Equal(expected, actualSpan[i], Comparer); + } + } + + [Theory] + [InlineData(1, 1, 1, 1, .5F, .5F, 0)] + [InlineData(0, 0, 0, 0, .5F, .5F, 1)] + [InlineData(.5F, .5F, .5F, 1, .5F, .5F, .5F)] + public void Convert_Rgb_To_YccK(float r, float g, float b, float y, float cb, float cr, float k) + { + // Multiple YccK representations can decode to the same RGB value. + // For example, (Y=1.0, Cb=0.5, Cr=0.5, K=0.5) and (Y=0.5, Cb=0.5, Cr=0.5, K=0.0) both yield RGB (0.5, 0.5, 0.5). + // This is expected because YccK is not a unique encoding — K modulates RGB after YCbCr decoding. + // Round-tripping RGB -> YccK -> RGB is stable, but YccK -> RGB -> YccK is not injective. + + // Arrange + Rgb input = new(r, g, b); + YccK expected = new(y, cb, cr, k); + ColorProfileConverter converter = new(); + + Span inputSpan = new Rgb[5]; + inputSpan.Fill(input); + + Span actualSpan = new YccK[5]; + + // Act + YccK actual = converter.Convert(input); + converter.Convert(inputSpan, actualSpan); + + // Assert + Assert.Equal(expected, actual, Comparer); + + for (int i = 0; i < actualSpan.Length; i++) + { + Assert.Equal(expected, actualSpan[i], Comparer); + } + } +} diff --git a/tests/ImageSharp.Tests/ColorProfiles/RgbTests.cs b/tests/ImageSharp.Tests/ColorProfiles/RgbTests.cs index 7e4d4ee0e7..707b3e2a7d 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/RgbTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/RgbTests.cs @@ -10,6 +10,7 @@ namespace SixLabors.ImageSharp.Tests.ColorProfiles; /// /// Tests the struct. /// +[Trait("Color", "Conversion")] public class RgbTests { [Fact] diff --git a/tests/ImageSharp.Tests/ColorProfiles/StringRepresentationTests.cs b/tests/ImageSharp.Tests/ColorProfiles/StringRepresentationTests.cs index 770c987dba..f61124d8f5 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/StringRepresentationTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/StringRepresentationTests.cs @@ -6,11 +6,13 @@ using SixLabors.ImageSharp.ColorProfiles; namespace SixLabors.ImageSharp.Tests.ColorProfiles; +[Trait("Color", "Conversion")] public class StringRepresentationTests { private static readonly Vector3 One = new(1); private static readonly Vector3 Zero = new(0); private static readonly Vector3 Random = new(42.4F, 94.5F, 83.4F); + private static readonly Vector4 Random4 = new(42.4F, 94.5F, 83.4F, 1); public static readonly TheoryData TestData = new() { @@ -51,7 +53,10 @@ public class StringRepresentationTests { Rgb.Clamp(new Rgb(Random)), "Rgb(1, 1, 1)" }, { new Hsl(Random), "Hsl(42.4, 1, 1)" }, // clamping to 1 is expected { new Hsv(Random), "Hsv(42.4, 1, 1)" }, // clamping to 1 is expected - { new YCbCr(Random), "YCbCr(42.4, 94.5, 83.4)" }, + { new Y(Random.X), "Y(1)" }, + { new YCbCr(Random), "YCbCr(1, 1, 1)" }, + { new YccK(Random4), "YccK(1, 1, 1, 1)" }, + { new Cmyk(Random4), "Cmyk(1, 1, 1, 1)" }, }; [Theory] diff --git a/tests/ImageSharp.Tests/ColorProfiles/VonKriesChromaticAdaptationTests.cs b/tests/ImageSharp.Tests/ColorProfiles/VonKriesChromaticAdaptationTests.cs index 7f5687dee2..1622af1bfb 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/VonKriesChromaticAdaptationTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/VonKriesChromaticAdaptationTests.cs @@ -20,7 +20,7 @@ public class VonKriesChromaticAdaptationTests { ColorConversionOptions options = new() { - WhitePoint = from, + SourceWhitePoint = from, TargetWhitePoint = to }; diff --git a/tests/ImageSharp.Tests/ColorProfiles/YCbCrTests.cs b/tests/ImageSharp.Tests/ColorProfiles/YCbCrTests.cs index f8404ad948..64558a3f8a 100644 --- a/tests/ImageSharp.Tests/ColorProfiles/YCbCrTests.cs +++ b/tests/ImageSharp.Tests/ColorProfiles/YCbCrTests.cs @@ -9,14 +9,15 @@ namespace SixLabors.ImageSharp.Tests.ColorProfiles; /// /// Tests the struct. /// +[Trait("Color", "Conversion")] public class YCbCrTests { [Fact] public void YCbCrConstructorAssignsFields() { - const float y = 75F; - const float cb = 64F; - const float cr = 87F; + const float y = .75F; + const float cb = .64F; + const float cr = .87F; YCbCr yCbCr = new(y, cb, cr); Assert.Equal(y, yCbCr.Y); diff --git a/tests/ImageSharp.Tests/ColorProfiles/YTests.cs b/tests/ImageSharp.Tests/ColorProfiles/YTests.cs new file mode 100644 index 0000000000..7e5e48b69e --- /dev/null +++ b/tests/ImageSharp.Tests/ColorProfiles/YTests.cs @@ -0,0 +1,38 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using SixLabors.ImageSharp.ColorProfiles; + +namespace SixLabors.ImageSharp.Tests.ColorProfiles; + +/// +/// Tests the struct. +/// +[Trait("Color", "Conversion")] +public class YTests +{ + [Fact] + public void YConstructorAssignsFields() + { + const float y = .75F; + Y yValue = new(y); + + Assert.Equal(y, yValue.L); + } + + [Fact] + public void YEquality() + { + Y x = default; + Y y = new(1F); + Assert.True(default == default(Y)); + Assert.False(default != default(Y)); + Assert.Equal(default, default(Y)); + Assert.Equal(new Y(1), new Y(1)); + + Assert.Equal(new Y(.5F), new Y(.5F)); + Assert.False(x.Equals(y)); + Assert.False(x.Equals((object)y)); + Assert.False(x.GetHashCode().Equals(y.GetHashCode())); + } +} diff --git a/tests/ImageSharp.Tests/ColorProfiles/YccKTests.cs b/tests/ImageSharp.Tests/ColorProfiles/YccKTests.cs new file mode 100644 index 0000000000..bfe0bdb175 --- /dev/null +++ b/tests/ImageSharp.Tests/ColorProfiles/YccKTests.cs @@ -0,0 +1,44 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using SixLabors.ImageSharp.ColorProfiles; + +namespace SixLabors.ImageSharp.Tests.ColorProfiles; + +/// +/// Tests the struct. +/// +[Trait("Color", "Conversion")] +public class YccKTests +{ + [Fact] + public void YccKConstructorAssignsFields() + { + const float y = .75F; + const float cb = .5F; + const float cr = .25F; + const float k = .125F; + + YccK ycckValue = new(y, cb, cr, k); + Assert.Equal(y, ycckValue.Y); + Assert.Equal(cb, ycckValue.Cb); + Assert.Equal(cr, ycckValue.Cr); + Assert.Equal(k, ycckValue.K); + } + + [Fact] + public void YccKEquality() + { + YccK x = default; + YccK y = new(1F, 1F, 1F, 1F); + Assert.True(default == default(YccK)); + Assert.False(default != default(YccK)); + Assert.Equal(default, default(YccK)); + Assert.Equal(new YccK(1, 1, 1, 1), new YccK(1, 1, 1, 1)); + Assert.Equal(new YccK(.5F, .5F, .5F, .5F), new YccK(.5F, .5F, .5F, .5F)); + + Assert.False(x.Equals(y)); + Assert.False(x.Equals((object)y)); + Assert.False(x.GetHashCode().Equals(y.GetHashCode())); + } +} diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs index bc6eeedcbe..6593b8df70 100644 --- a/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs @@ -34,6 +34,41 @@ public class GifDecoderTests image.CompareToReferenceOutputMultiFrame(provider, ImageComparer.Exact); } + [Theory] + [WithFile(TestImages.Gif.AnimatedLoop, PixelTypes.Rgba32)] + [WithFile(TestImages.Gif.AnimatedLoopInterlaced, PixelTypes.Rgba32)] + public void Decode_Animated(TestImageProvider provider) + where TPixel : unmanaged, IPixel + { + using Image image = provider.GetImage(); + image.DebugSaveMultiFrame(provider); + image.CompareToReferenceOutputMultiFrame(provider, ImageComparer.Exact); + } + + [Theory] + [WithFile(TestImages.Gif.AnimatedTransparentNoRestore, PixelTypes.Rgba32)] + [WithFile(TestImages.Gif.AnimatedTransparentRestorePrevious, PixelTypes.Rgba32)] + [WithFile(TestImages.Gif.AnimatedTransparentLoop, PixelTypes.Rgba32)] + [WithFile(TestImages.Gif.AnimatedTransparentFirstFrameRestorePrev, PixelTypes.Rgba32)] + public void Decode_Animated_WithTransparency(TestImageProvider provider) + where TPixel : unmanaged, IPixel + { + using Image image = provider.GetImage(); + image.DebugSaveMultiFrame(provider); + image.CompareToReferenceOutputMultiFrame(provider, ImageComparer.Exact); + } + + [Theory] + [WithFile(TestImages.Gif.StaticNontransparent, PixelTypes.Rgba32)] + [WithFile(TestImages.Gif.StaticTransparent, PixelTypes.Rgba32)] + public void Decode_Static_No_Animation(TestImageProvider provider) + where TPixel : unmanaged, IPixel + { + using Image image = provider.GetImage(); + image.DebugSave(provider); + image.CompareFirstFrameToReferenceOutput(ImageComparer.Exact, provider); + } + [Theory] [WithFile(TestImages.Gif.Issues.Issue2450_A, PixelTypes.Rgba32)] [WithFile(TestImages.Gif.Issues.Issue2450_B, PixelTypes.Rgba32)] diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs index f12f66186e..44ed5e38dd 100644 --- a/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs @@ -56,7 +56,7 @@ public class GifEncoderTests { // Use the palette quantizer without dithering to ensure results // are consistent - Quantizer = new WebSafePaletteQuantizer(new QuantizerOptions { Dither = null }) + Quantizer = new WebSafePaletteQuantizer(new QuantizerOptions { Dither = null, TransparencyThreshold = 0 }) }; // Always save as we need to compare the encoded output. @@ -419,4 +419,21 @@ public class GifEncoderTests } }); } + + [Theory] + [WithFile(TestImages.Gif.Issues.Issue2866, PixelTypes.Rgba32)] + public void GifEncoder_CanDecode_AndEncode_Issue2866(TestImageProvider provider) + where TPixel : unmanaged, IPixel + { + using Image image = provider.GetImage(); + + // Save the image for visual inspection. + provider.Utility.SaveTestOutputFile(image, "gif", new GifEncoder(), "animated"); + + // Now compare the debug output with the reference output. + // We do this because the gif encoding is lossy and encoding will lead to differences in the 10s of percent. + // From the unencoded image, we can see that the image is visually the same. + static bool Predicate(int i, int _) => i % 8 == 0; // Image has many frames, only compare a selection of them. + image.CompareDebugOutputToReferenceOutputMultiFrame(provider, ImageComparer.Exact, extension: "gif", predicate: Predicate); + } } diff --git a/tests/ImageSharp.Tests/Formats/Icon/Cur/CurEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Icon/Cur/CurEncoderTests.cs index bf94e1d489..69c6317a75 100644 --- a/tests/ImageSharp.Tests/Formats/Icon/Cur/CurEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Icon/Cur/CurEncoderTests.cs @@ -4,6 +4,7 @@ using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Cur; using SixLabors.ImageSharp.Formats.Ico; +using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using static SixLabors.ImageSharp.Tests.TestImages.Cur; @@ -49,8 +50,8 @@ public class CurEncoderTests using Image encoded = Image.Load(memStream); encoded.DebugSaveMultiFrame(provider); - // Despite preservation of the palette. The process can still be lossy - encoded.CompareToOriginalMultiFrame(provider, ImageComparer.TolerantPercentage(.23f), IcoDecoder.Instance); + // Color palettes are not preserved when transcoding. + encoded.CompareToOriginalMultiFrame(provider, ImageComparer.TolerantPercentage(.05F), IcoDecoder.Instance); for (int i = 0; i < image.Frames.Count; i++) { diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs index 25e605cef2..1dba8ee1c9 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs @@ -1,8 +1,6 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -using System.Runtime.Intrinsics.Arm; -using System.Runtime.Intrinsics.X86; using SixLabors.ImageSharp.ColorProfiles; using SixLabors.ImageSharp.Formats.Jpeg.Components; using SixLabors.ImageSharp.Memory; @@ -15,7 +13,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg; [Trait("Format", "Jpg")] public class JpegColorConverterTests { - private const float MaxColorChannelValue = 255f; + private const float MaxColorChannelValue = 255F; private const float Precision = 0.1F / 255; @@ -754,7 +752,7 @@ public class JpegColorConverterTests ValidateGrayScale(original, result, i); break; case JpegColorSpace.Ycck: - ValidateCyyK(original, result, i); + ValidateYccK(original, result, i); break; case JpegColorSpace.Cmyk: ValidateCmyk(original, result, i); @@ -774,17 +772,25 @@ public class JpegColorConverterTests private static void ValidateYCbCr(in JpegColorConverterBase.ComponentValues values, in JpegColorConverterBase.ComponentValues result, int i) { float y = values.Component0[i]; - float cb = values.Component1[i]; - float cr = values.Component2[i]; - Rgb expected = ColorSpaceConverter.Convert(new YCbCr(y, cb, cr)); + float cb = values.Component1[i] - 128; + float cr = values.Component2[i] - 128; + float r = (float)Math.Round(y + (1.402F * cr), MidpointRounding.AwayFromZero); + float g = (float)Math.Round(y - (0.344136F * cb) - (0.714136F * cr), MidpointRounding.AwayFromZero); + float b = (float)Math.Round(y + (1.772F * cb), MidpointRounding.AwayFromZero); + + r /= MaxColorChannelValue; + g /= MaxColorChannelValue; + b /= MaxColorChannelValue; + + Rgb expected = Rgb.Clamp(new(r, g, b)); Rgb actual = Rgb.Clamp(new(result.Component0[i], result.Component1[i], result.Component2[i])); bool equal = ColorSpaceComparer.Equals(expected, actual); Assert.True(equal, $"Colors {expected} and {actual} are not equal at index {i}"); } - private static void ValidateCyyK(in JpegColorConverterBase.ComponentValues values, in JpegColorConverterBase.ComponentValues result, int i) + private static void ValidateYccK(in JpegColorConverterBase.ComponentValues values, in JpegColorConverterBase.ComponentValues result, int i) { float y = values.Component0[i]; float cb = values.Component1[i] - 128F; @@ -792,9 +798,7 @@ public class JpegColorConverterTests float k = values.Component3[i] / 255F; float r = (255F - (float)Math.Round(y + (1.402F * cr), MidpointRounding.AwayFromZero)) * k; - float g = (255F - (float)Math.Round( - y - (0.344136F * cb) - (0.714136F * cr), - MidpointRounding.AwayFromZero)) * k; + float g = (255F - (float)Math.Round(y - (0.344136F * cb) - (0.714136F * cr), MidpointRounding.AwayFromZero)) * k; float b = (255F - (float)Math.Round(y + (1.772F * cb), MidpointRounding.AwayFromZero)) * k; r /= MaxColorChannelValue; diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.Metadata.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.Metadata.cs index 039215bbc5..99322687cc 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.Metadata.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.Metadata.cs @@ -7,6 +7,7 @@ using SixLabors.ImageSharp.Metadata.Profiles.Exif; using SixLabors.ImageSharp.Metadata.Profiles.Icc; using SixLabors.ImageSharp.Metadata.Profiles.Iptc; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestDataIcc; namespace SixLabors.ImageSharp.Tests.Formats.Jpg; @@ -77,7 +78,7 @@ public partial class JpegEncoderTests { // arrange using Image input = new(1, 1); - input.Metadata.IccProfile = new IccProfile(IccTestDataProfiles.Profile_Random_Array); + input.Metadata.IccProfile = new IccProfile(IccTestDataProfiles.ProfileRandomArray); // act using MemoryStream memStream = new(); diff --git a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs index b4995d77b6..b0d0563ccb 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs @@ -407,6 +407,7 @@ public partial class PngEncoderTests [WithFile(TestImages.Png.APng, PixelTypes.Rgba32)] [WithFile(TestImages.Png.DefaultNotAnimated, PixelTypes.Rgba32)] [WithFile(TestImages.Png.FrameOffset, PixelTypes.Rgba32)] + [WithFile(TestImages.Png.Issue2882, PixelTypes.Rgba32)] public void Encode_APng(TestImageProvider provider) where TPixel : unmanaged, IPixel { @@ -419,8 +420,8 @@ public partial class PngEncoderTests using Image output = Image.Load(memStream); - // some loss from original, due to compositing - ImageComparer.TolerantPercentage(0.01f).VerifySimilarity(output, image); + // Some loss from original, due to palette matching accuracy. + ImageComparer.TolerantPercentage(0.172F).VerifySimilarity(output, image); Assert.Equal(image.Frames.Count, output.Frames.Count); @@ -443,6 +444,7 @@ public partial class PngEncoderTests [Theory] [WithFile(TestImages.Gif.Leo, PixelTypes.Rgba32)] + [WithFile(TestImages.Gif.Issues.Issue2866, PixelTypes.Rgba32)] public void Encode_AnimatedFormatTransform_FromGif(TestImageProvider provider) where TPixel : unmanaged, IPixel { @@ -453,26 +455,30 @@ public partial class PngEncoderTests using Image image = provider.GetImage(GifDecoder.Instance); + // Save the image for visual inspection. + provider.Utility.SaveTestOutputFile(image, "png", PngEncoder, "animated"); + + // Now compare the debug output with the reference output. + // We do this because the transcoding encoding is lossy and encoding will lead to differences. + // From the unencoded image, we can see that the image is visually the same. + static bool Predicate(int i, int _) => i % 8 == 0; // Image has many frames, only compare a selection of them. + image.CompareDebugOutputToReferenceOutputMultiFrame(provider, ImageComparer.Exact, extension: "png", encoder: PngEncoder, predicate: Predicate); + + // Now save the image and load it again to compare the metadata. using MemoryStream memStream = new(); image.Save(memStream, PngEncoder); memStream.Position = 0; - using Image output = Image.Load(memStream); - - // TODO: Find a better way to compare. - // The image has been visually checked but the quantization pattern used in the png encoder - // means we cannot use an exact comparison nor replicate using the quantizing processor. - ImageComparer.TolerantPercentage(0.613f).VerifySimilarity(output, image); - + using Image encoded = Image.Load(memStream); GifMetadata gif = image.Metadata.GetGifMetadata(); - PngMetadata png = output.Metadata.GetPngMetadata(); + PngMetadata png = encoded.Metadata.GetPngMetadata(); Assert.Equal(gif.RepeatCount, png.RepeatCount); for (int i = 0; i < image.Frames.Count; i++) { GifFrameMetadata gifF = image.Frames[i].Metadata.GetGifMetadata(); - PngFrameMetadata pngF = output.Frames[i].Metadata.GetPngMetadata(); + PngFrameMetadata pngF = encoded.Frames[i].Metadata.GetPngMetadata(); Assert.Equal(gifF.FrameDelay, (int)(pngF.FrameDelay.ToDouble() * 100)); @@ -641,7 +647,7 @@ public partial class PngEncoderTests encoded.CompareToReferenceOutput(ImageComparer.Exact, provider); } - // https://github.com/SixLabors/ImageSharp/issues/2469 + // https://github.com/SixLabors/ImageSharp/issues/2668 [Theory] [WithFile(TestImages.Png.Issue2668, PixelTypes.Rgba32)] public void Issue2668_Quantized_Encode_Alpha(TestImageProvider provider) @@ -657,6 +663,39 @@ public partial class PngEncoderTests encoded.CompareToReferenceOutput(ImageComparer.Exact, provider); } + [Fact] + public void Issue_2862() + { + // Create a grayscale palette (or any other palette with colors that are very close to each other): + Rgba32[] palette = [.. Enumerable.Range(0, 256).Select(i => new Rgba32((byte)i, (byte)i, (byte)i))]; + + using Image image = new(254, 4); + for (int y = 0; y < image.Height; y++) + { + for (int x = 0; x < image.Width; x++) + { + image[x, y] = palette[x]; + } + } + + PaletteQuantizer quantizer = new( + palette.Select(Color.FromPixel).ToArray(), + new QuantizerOptions() { ColorMatchingMode = ColorMatchingMode.Hybrid }); + + using MemoryStream ms = new(); + image.Save(ms, new PngEncoder + { + ColorType = PngColorType.Palette, + BitDepth = PngBitDepth.Bit8, + Quantizer = quantizer + }); + + ms.Position = 0; + + using Image encoded = Image.Load(ms); + ImageComparer.Exact.VerifySimilarity(image, encoded); + } + private static void TestPngEncoderCore( TestImageProvider provider, PngColorType pngColorType, diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebpCommonUtilsTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebpCommonUtilsTests.cs index 80302db393..1491cd13cf 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/WebpCommonUtilsTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/WebpCommonUtilsTests.cs @@ -106,7 +106,7 @@ public class WebpCommonUtilsTests 174, 183, 189, 255, 148, 158, 158, 255, }; - Span row = MemoryMarshal.Cast((Span)rowBytes); + ReadOnlySpan row = MemoryMarshal.Cast(rowBytes); bool noneOpaque; for (int length = 8; length < row.Length; length += 8) @@ -188,7 +188,7 @@ public class WebpCommonUtilsTests 174, 183, 189, 255, 148, 158, 158, 255, }; - Span row = MemoryMarshal.Cast((Span)rowBytes); + ReadOnlySpan row = MemoryMarshal.Cast(rowBytes); bool noneOpaque; for (int length = 8; length < row.Length; length += 8) diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs index 657ab25546..adabb727d8 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs @@ -450,6 +450,22 @@ public class WebpDecoderTests image.CompareToOriginal(provider, ReferenceDecoder); } + // https://github.com/SixLabors/ImageSharp/issues/2866 + [Theory] + [WithFile(Lossy.Issue2866, PixelTypes.Rgba32)] + public void WebpDecoder_CanDecode_Issue2866(TestImageProvider provider) + where TPixel : unmanaged, IPixel + { + // Web + using Image image = provider.GetImage( + WebpDecoder.Instance, + new WebpDecoderOptions() { BackgroundColorHandling = BackgroundColorHandling.Ignore }); + + // We can't use the reference decoder here. + // It creates frames of different size without blending the frames. + image.DebugSave(provider, extension: "webp", encoder: new WebpEncoder()); + } + [Theory] [WithFile(Lossless.LossLessCorruptImage3, PixelTypes.Rgba32)] public void WebpDecoder_ThrowImageFormatException_OnInvalidImages(TestImageProvider provider) diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs index f82fa65df8..af6f7eea17 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs @@ -8,6 +8,8 @@ using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.Formats.Webp; using SixLabors.ImageSharp.Metadata; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Processors.Quantization; using SixLabors.ImageSharp.Tests.TestUtilities; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs; @@ -110,6 +112,63 @@ public class WebpEncoderTests } } + [Theory] + // [WithFile(AlphaBlend, PixelTypes.Rgba32)] + // [WithFile(AlphaBlend2, PixelTypes.Rgba32)] + [WithFile(AlphaBlend3, PixelTypes.Rgba32)] + // [WithFile(AlphaBlend4, PixelTypes.Rgba32)] + public void Encode_AlphaBlended(TestImageProvider provider) + where TPixel : unmanaged, IPixel + { + using Image image = provider.GetImage(); + WebpEncoder encoder = new() + { + FileFormat = WebpFileFormatType.Lossless + }; + + QuantizerOptions options = new() + { + TransparencyThreshold = 128 / 255F + }; + + // First save as gif to gif using different quantizers with default options. + // Alpha thresholding is 64/255F. + GifEncoder gifEncoder = new() + { + Quantizer = new OctreeQuantizer(options) + }; + provider.Utility.SaveTestOutputFile(image, "gif", gifEncoder, "octree"); + + gifEncoder = new GifEncoder() + { + Quantizer = new WuQuantizer(options) + }; + provider.Utility.SaveTestOutputFile(image, "gif", gifEncoder, "wu"); + + // Now clone and quantize the image using the same quantizers without alpha thresholding and save as webp. + options = new() + { + TransparencyThreshold = 0 + }; + + using Image cloned1 = image.Clone(); + cloned1.Mutate(c => c.Quantize(new OctreeQuantizer(options))); + provider.Utility.SaveTestOutputFile(cloned1, "webp", encoder, "octree"); + + using Image cloned2 = image.Clone(); + cloned2.Mutate(c => c.Quantize(new WuQuantizer(options))); + provider.Utility.SaveTestOutputFile(cloned2, "webp", encoder, "wu"); + + // Now blend the images with a blue background and save as webp. + using Image background1 = new(image.Width, image.Height, Color.White.ToPixel()); + background1.Mutate(c => c.DrawImage(cloned1, 1)); + provider.Utility.SaveTestOutputFile(background1, "webp", encoder, "octree-blended"); + + using Image background2 = new(image.Width, image.Height, Color.White.ToPixel()); + background2.Mutate(c => c.DrawImage(cloned2, 1)); + provider.Utility.SaveTestOutputFile(background2, "webp", encoder, "wu-blended"); + } + [Theory] [WithFile(TestImages.Png.APng, PixelTypes.Rgba32)] public void Encode_AnimatedFormatTransform_FromPng(TestImageProvider provider) diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj index 9af4f41a81..ce391fad2c 100644 --- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj +++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj @@ -32,6 +32,9 @@ True PixelOperationsTests.Specialized.Generated.tt + + PreserveNewest + @@ -47,6 +50,7 @@ + diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderCurvesTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderCurvesTests.cs index 73ae46c2c9..86c6a5e9f2 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderCurvesTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderCurvesTests.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc; namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.ICC.DataReader; diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderLutTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderLutTests.cs index 63585a3bd4..a686d44872 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderLutTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderLutTests.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc; namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.ICC.DataReader; diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderMatrixTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderMatrixTests.cs index b81395bb2e..5ef102cd93 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderMatrixTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderMatrixTests.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc; namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.ICC.DataReader; @@ -9,7 +10,7 @@ namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.ICC.DataReader; public class IccDataReaderMatrixTests { [Theory] - [MemberData(nameof(IccTestDataMatrix.Matrix2D_FloatArrayTestData), MemberType = typeof(IccTestDataMatrix))] + [MemberData(nameof(IccTestDataMatrix.Matrix2DFloatArrayTestData), MemberType = typeof(IccTestDataMatrix))] public void ReadMatrix2D(byte[] data, int xCount, int yCount, bool isSingle, float[,] expected) { IccDataReader reader = CreateReader(data); @@ -20,7 +21,7 @@ public class IccDataReaderMatrixTests } [Theory] - [MemberData(nameof(IccTestDataMatrix.Matrix1D_ArrayTestData), MemberType = typeof(IccTestDataMatrix))] + [MemberData(nameof(IccTestDataMatrix.Matrix1DArrayTestData), MemberType = typeof(IccTestDataMatrix))] public void ReadMatrix1D(byte[] data, int yCount, bool isSingle, float[] expected) { IccDataReader reader = CreateReader(data); @@ -30,8 +31,5 @@ public class IccDataReaderMatrixTests Assert.Equal(expected, output); } - private static IccDataReader CreateReader(byte[] data) - { - return new IccDataReader(data); - } + private static IccDataReader CreateReader(byte[] data) => new(data); } diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderMultiProcessElementTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderMultiProcessElementTests.cs index 9023b1b723..930665a07c 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderMultiProcessElementTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderMultiProcessElementTests.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc; namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.ICC.DataReader; diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderNonPrimitivesTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderNonPrimitivesTests.cs index 91294a3dab..ee0464bb23 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderNonPrimitivesTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderNonPrimitivesTests.cs @@ -3,6 +3,7 @@ using System.Numerics; using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc; namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.ICC.DataReader; diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderPrimitivesTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderPrimitivesTests.cs index b6135cd197..9c5be4c675 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderPrimitivesTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderPrimitivesTests.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc; namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.ICC.DataReader; diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderTagDataEntryTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderTagDataEntryTests.cs index d41707b7ce..e0cfa65431 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderTagDataEntryTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderTagDataEntryTests.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc; namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.ICC.DataReader; @@ -166,7 +167,7 @@ public class IccDataReaderTagDataEntryTests [Theory] [MemberData( - nameof(IccTestDataTagDataEntry.MultiLocalizedUnicodeTagDataEntryTestData_Read), + nameof(IccTestDataTagDataEntry.MultiLocalizedUnicodeTagDataEntryTestDataRead), MemberType = typeof(IccTestDataTagDataEntry))] internal void ReadMultiLocalizedUnicodeTagDataEntry(byte[] data, IccMultiLocalizedUnicodeTagDataEntry expected) { diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderTests.cs index f2150cc03a..6f2e868c56 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataReader/IccDataReaderTests.cs @@ -9,8 +9,5 @@ namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.ICC.DataReader; public class IccDataReaderTests { [Fact] - public void ConstructorThrowsNullException() - { - Assert.Throws(() => new IccDataReader(null)); - } + public void ConstructorThrowsNullException() => Assert.Throws(() => new IccDataReader(null)); } diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterCurvesTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterCurvesTests.cs index 1a23c8d002..f6ac8517d8 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterCurvesTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterCurvesTests.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc; namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.ICC.DataWriter; @@ -80,8 +81,5 @@ public class IccDataWriterCurvesTests Assert.Equal(expected, output); } - private static IccDataWriter CreateWriter() - { - return new IccDataWriter(); - } + private static IccDataWriter CreateWriter() => new IccDataWriter(); } diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterLutTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterLutTests.cs index 4a3dc48bcb..8f696e99df 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterLutTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterLutTests.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc; namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.ICC.DataWriter; @@ -80,8 +81,5 @@ public class IccDataWriterLutTests Assert.Equal(expected, output); } - private static IccDataWriter CreateWriter() - { - return new IccDataWriter(); - } + private static IccDataWriter CreateWriter() => new IccDataWriter(); } diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterLutTests1.cs b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterLutTests1.cs index 1973d94b89..9317b45034 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterLutTests1.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterLutTests1.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc; namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.ICC.DataWriter; @@ -80,8 +81,5 @@ public class IccDataWriterLutTests1 Assert.Equal(expected, output); } - private static IccDataWriter CreateWriter() - { - return new IccDataWriter(); - } + private static IccDataWriter CreateWriter() => new(); } diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterLutTests2.cs b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterLutTests2.cs index 4ffc9e0c36..147a332c39 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterLutTests2.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterLutTests2.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc; namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.ICC.DataWriter; @@ -80,8 +81,5 @@ public class IccDataWriterLutTests2 Assert.Equal(expected, output); } - private static IccDataWriter CreateWriter() - { - return new IccDataWriter(); - } + private static IccDataWriter CreateWriter() => new(); } diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterMatrixTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterMatrixTests.cs index 7d046aa49b..c72d4386ad 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterMatrixTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterMatrixTests.cs @@ -3,6 +3,7 @@ using System.Numerics; using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc; namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.ICC.DataWriter; @@ -10,7 +11,7 @@ namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.ICC.DataWriter; public class IccDataWriterMatrixTests { [Theory] - [MemberData(nameof(IccTestDataMatrix.Matrix2D_FloatArrayTestData), MemberType = typeof(IccTestDataMatrix))] + [MemberData(nameof(IccTestDataMatrix.Matrix2DFloatArrayTestData), MemberType = typeof(IccTestDataMatrix))] public void WriteMatrix2D_Array(byte[] expected, int xCount, int yCount, bool isSingle, float[,] data) { using IccDataWriter writer = CreateWriter(); @@ -22,7 +23,7 @@ public class IccDataWriterMatrixTests } [Theory] - [MemberData(nameof(IccTestDataMatrix.Matrix2D_Matrix4x4TestData), MemberType = typeof(IccTestDataMatrix))] + [MemberData(nameof(IccTestDataMatrix.Matrix2DMatrix4X4TestData), MemberType = typeof(IccTestDataMatrix))] public void WriteMatrix2D_Matrix4x4(byte[] expected, int xCount, int yCount, bool isSingle, Matrix4x4 data) { using IccDataWriter writer = CreateWriter(); @@ -34,7 +35,7 @@ public class IccDataWriterMatrixTests } [Theory] - [MemberData(nameof(IccTestDataMatrix.Matrix2D_DenseMatrixTestData), MemberType = typeof(IccTestDataMatrix))] + [MemberData(nameof(IccTestDataMatrix.Matrix2DDenseMatrixTestData), MemberType = typeof(IccTestDataMatrix))] internal void WriteMatrix2D_DenseMatrix(byte[] expected, int xCount, int yCount, bool isSingle, in DenseMatrix data) { using IccDataWriter writer = CreateWriter(); @@ -46,7 +47,7 @@ public class IccDataWriterMatrixTests } [Theory] - [MemberData(nameof(IccTestDataMatrix.Matrix1D_ArrayTestData), MemberType = typeof(IccTestDataMatrix))] + [MemberData(nameof(IccTestDataMatrix.Matrix1DArrayTestData), MemberType = typeof(IccTestDataMatrix))] public void WriteMatrix1D_Array(byte[] expected, int yCount, bool isSingle, float[] data) { using IccDataWriter writer = CreateWriter(); @@ -58,7 +59,7 @@ public class IccDataWriterMatrixTests } [Theory] - [MemberData(nameof(IccTestDataMatrix.Matrix1D_Vector3TestData), MemberType = typeof(IccTestDataMatrix))] + [MemberData(nameof(IccTestDataMatrix.Matrix1DVector3TestData), MemberType = typeof(IccTestDataMatrix))] public void WriteMatrix1D_Vector3(byte[] expected, int yCount, bool isSingle, Vector3 data) { using IccDataWriter writer = CreateWriter(); @@ -69,8 +70,5 @@ public class IccDataWriterMatrixTests Assert.Equal(expected, output); } - private static IccDataWriter CreateWriter() - { - return new IccDataWriter(); - } + private static IccDataWriter CreateWriter() => new(); } diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterMultiProcessElementTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterMultiProcessElementTests.cs index ba2add5eb9..b7259d536a 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterMultiProcessElementTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterMultiProcessElementTests.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc; namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.ICC.DataWriter; @@ -56,8 +57,5 @@ public class IccDataWriterMultiProcessElementTests Assert.Equal(expected, output); } - private static IccDataWriter CreateWriter() - { - return new IccDataWriter(); - } + private static IccDataWriter CreateWriter() => new(); } diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterNonPrimitivesTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterNonPrimitivesTests.cs index b17ed44419..b1b30d49fa 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterNonPrimitivesTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterNonPrimitivesTests.cs @@ -3,6 +3,7 @@ using System.Numerics; using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc; namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.ICC.DataWriter; @@ -117,8 +118,5 @@ public class IccDataWriterNonPrimitivesTests Assert.Equal(expected, output); } - private static IccDataWriter CreateWriter() - { - return new IccDataWriter(); - } + private static IccDataWriter CreateWriter() => new(); } diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterPrimitivesTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterPrimitivesTests.cs index fbe8fe1ced..c8f46d3aa4 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterPrimitivesTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterPrimitivesTests.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc; namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.ICC.DataWriter; @@ -112,8 +113,5 @@ public class IccDataWriterPrimitivesTests Assert.Equal(expected, output); } - private static IccDataWriter CreateWriter() - { - return new IccDataWriter(); - } + private static IccDataWriter CreateWriter() => new(); } diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterTagDataEntryTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterTagDataEntryTests.cs index 7eda24c8cf..791bcee5e6 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterTagDataEntryTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterTagDataEntryTests.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc; namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.ICC.DataWriter; @@ -153,7 +154,7 @@ public class IccDataWriterTagDataEntryTests } [Theory] - [MemberData(nameof(IccTestDataTagDataEntry.MultiLocalizedUnicodeTagDataEntryTestData_Write), MemberType = typeof(IccTestDataTagDataEntry))] + [MemberData(nameof(IccTestDataTagDataEntry.MultiLocalizedUnicodeTagDataEntryTestDataWrite), MemberType = typeof(IccTestDataTagDataEntry))] internal void WriteMultiLocalizedUnicodeTagDataEntry(byte[] expected, IccMultiLocalizedUnicodeTagDataEntry data) { using IccDataWriter writer = CreateWriter(); @@ -404,8 +405,5 @@ public class IccDataWriterTagDataEntryTests Assert.Equal(expected, output); } - private static IccDataWriter CreateWriter() - { - return new IccDataWriter(); - } + private static IccDataWriter CreateWriter() => new(); } diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterTests.cs index 205941fcec..606a69d390 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/DataWriter/IccDataWriterTests.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc; namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.ICC.DataWriter; @@ -105,8 +106,5 @@ public class IccDataWriterTests Assert.Equal(expected, output); } - private static IccDataWriter CreateWriter() - { - return new IccDataWriter(); - } + private static IccDataWriter CreateWriter() => new(); } diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/IccProfileTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/IccProfileTests.cs index fbbea97fb3..9c4abfe3e6 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/IccProfileTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/IccProfileTests.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc; namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.Icc; @@ -20,7 +21,7 @@ public class IccProfileTests [Fact] public void CalculateHash_WithByteArray_DoesNotModifyData() { - byte[] data = IccTestDataProfiles.Profile_Random_Array; + byte[] data = IccTestDataProfiles.ProfileRandomArray; var copy = new byte[data.Length]; Buffer.BlockCopy(data, 0, copy, 0, data.Length); diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/IccReaderTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/IccReaderTests.cs index 9b2ca2a275..2a80ae9e9c 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/IccReaderTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/IccReaderTests.cs @@ -2,24 +2,45 @@ // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestDataIcc; namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.Icc; [Trait("Profile", "Icc")] public class IccReaderTests { + [Theory] + [WithFile(TestImages.Jpeg.ICC.AdobeRgb, PixelTypes.Rgb24, 10, IccColorSpaceType.Rgb, IccColorSpaceType.CieXyz, 560)] + [WithFile(TestImages.Jpeg.ICC.AppleRGB, PixelTypes.Rgb24, 10, IccColorSpaceType.Rgb, IccColorSpaceType.CieXyz, 552)] + [WithFile(TestImages.Jpeg.ICC.ColorMatch, PixelTypes.Rgb24, 10, IccColorSpaceType.Rgb, IccColorSpaceType.CieXyz, 560)] + [WithFile(TestImages.Jpeg.ICC.WideRGB, PixelTypes.Rgb24, 10, IccColorSpaceType.Rgb, IccColorSpaceType.CieXyz, 560)] + [WithFile(TestImages.Jpeg.ICC.SRgb, PixelTypes.Rgb24, 17, IccColorSpaceType.Rgb, IccColorSpaceType.CieXyz, 3144)] + [WithFile(TestImages.Jpeg.ICC.ProPhoto, PixelTypes.Rgb24, 12, IccColorSpaceType.Rgb, IccColorSpaceType.CieXyz, 940)] + [WithFile(TestImages.Jpeg.ICC.CMYK, PixelTypes.Rgb24, 10, IccColorSpaceType.Cmyk, IccColorSpaceType.CieLab, 557168)] + public void ReadProfile_Works(TestImageProvider provider, int expectedEntries, IccColorSpaceType expectedDataColorSpace, IccColorSpaceType expectedConnectionSpace, uint expectedDataSize) + where TPixel : unmanaged, IPixel + { + using Image image = provider.GetImage(); + IccProfile profile = image.Metadata.IccProfile; + + Assert.NotNull(profile); + Assert.Equal(expectedEntries, profile.Entries.Length); + Assert.Equal(expectedDataColorSpace, profile.Header.DataColorSpace); + Assert.Equal(expectedConnectionSpace, profile.Header.ProfileConnectionSpace); + Assert.Equal(expectedDataSize, profile.Header.Size); + } + [Fact] public void ReadProfile_NoEntries() { - IccReader reader = this.CreateReader(); - - IccProfile output = IccReader.Read(IccTestDataProfiles.Header_Random_Array); + IccProfile output = IccReader.Read(IccTestDataProfiles.HeaderRandomArray); Assert.Equal(0, output.Entries.Length); Assert.NotNull(output.Header); IccProfileHeader header = output.Header; - IccProfileHeader expected = IccTestDataProfiles.Header_Random_Read; + IccProfileHeader expected = IccTestDataProfiles.HeaderRandomRead; Assert.Equal(header.Class, expected.Class); Assert.Equal(header.CmmType, expected.CmmType); Assert.Equal(header.CreationDate, expected.CreationDate); @@ -38,20 +59,4 @@ public class IccReaderTests Assert.Equal(header.Size, expected.Size); Assert.Equal(header.Version, expected.Version); } - - [Fact] - public void ReadProfile_DuplicateEntry() - { - IccReader reader = this.CreateReader(); - - IccProfile output = IccReader.Read(IccTestDataProfiles.Profile_Random_Array); - - Assert.Equal(2, output.Entries.Length); - Assert.True(ReferenceEquals(output.Entries[0], output.Entries[1])); - } - - private IccReader CreateReader() - { - return new IccReader(); - } } diff --git a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/IccWriterTests.cs b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/IccWriterTests.cs index 89b63b7dcc..24671aa3c5 100644 --- a/tests/ImageSharp.Tests/Metadata/Profiles/ICC/IccWriterTests.cs +++ b/tests/ImageSharp.Tests/Metadata/Profiles/ICC/IccWriterTests.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. using SixLabors.ImageSharp.Metadata.Profiles.Icc; +using SixLabors.ImageSharp.Tests.TestDataIcc; namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.Icc; @@ -11,29 +12,20 @@ public class IccWriterTests [Fact] public void WriteProfile_NoEntries() { - IccWriter writer = this.CreateWriter(); - var profile = new IccProfile { - Header = IccTestDataProfiles.Header_Random_Write + Header = IccTestDataProfiles.HeaderRandomWrite }; byte[] output = IccWriter.Write(profile); - Assert.Equal(IccTestDataProfiles.Header_Random_Array, output); + Assert.Equal(IccTestDataProfiles.HeaderRandomArray, output); } [Fact] public void WriteProfile_DuplicateEntry() { - IccWriter writer = this.CreateWriter(); - - byte[] output = IccWriter.Write(IccTestDataProfiles.Profile_Random_Val); + byte[] output = IccWriter.Write(IccTestDataProfiles.ProfileRandomVal); - Assert.Equal(IccTestDataProfiles.Profile_Random_Array, output); - } - - private IccWriter CreateWriter() - { - return new IccWriter(); + Assert.Equal(IccTestDataProfiles.ProfileRandomArray, output); } } diff --git a/tests/ImageSharp.Tests/Quantization/WuQuantizerTests.cs b/tests/ImageSharp.Tests/Quantization/WuQuantizerTests.cs index 74f2fc3b42..28a7c49e51 100644 --- a/tests/ImageSharp.Tests/Quantization/WuQuantizerTests.cs +++ b/tests/ImageSharp.Tests/Quantization/WuQuantizerTests.cs @@ -79,7 +79,7 @@ public class WuQuantizerTests } Configuration config = Configuration.Default; - WuQuantizer quantizer = new(new QuantizerOptions { Dither = null }); + WuQuantizer quantizer = new(new QuantizerOptions { Dither = null, TransparencyThreshold = 0 }); ImageFrame frame = image.Frames.RootFrame; @@ -152,7 +152,7 @@ public class WuQuantizerTests } Configuration config = Configuration.Default; - WuQuantizer quantizer = new(new QuantizerOptions { Dither = null }); + WuQuantizer quantizer = new(new QuantizerOptions { Dither = null, TransparencyThreshold = 0 }); ImageFrame frame = image.Frames.RootFrame; using (IQuantizer frameQuantizer = quantizer.CreatePixelSpecificQuantizer(config)) diff --git a/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataClut.cs b/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataClut.cs new file mode 100644 index 0000000000..397986a189 --- /dev/null +++ b/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataClut.cs @@ -0,0 +1,162 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Numerics; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; + +namespace SixLabors.ImageSharp.Tests.TestDataIcc.Conversion; + +public class IccConversionDataClut +{ + internal static IccClut Clut3x2 = new( + [ + 0.1f, 0.1f, + 0.2f, 0.2f, + 0.3f, 0.3f, + + 0.11f, 0.11f, + 0.21f, 0.21f, + 0.31f, 0.31f, + + 0.12f, 0.12f, + 0.22f, 0.22f, + 0.32f, 0.32f, + + 0.13f, 0.13f, + 0.23f, 0.23f, + 0.33f, 0.33f, + + 0.14f, 0.14f, + 0.24f, 0.24f, + 0.34f, 0.34f, + + 0.15f, 0.15f, + 0.25f, 0.25f, + 0.35f, 0.35f, + + 0.16f, 0.16f, + 0.26f, 0.26f, + 0.36f, 0.36f, + + 0.17f, 0.17f, + 0.27f, 0.27f, + 0.37f, 0.37f, + + 0.18f, 0.18f, + 0.28f, 0.28f, + 0.38f, 0.38f, + ], + [3, 3, 3], + IccClutDataType.Float, + outputChannelCount: 2); + + internal static IccClut Clut3x1 = new( + [ + 0.10f, + 0.20f, + 0.30f, + + 0.11f, + 0.21f, + 0.31f, + + 0.12f, + 0.22f, + 0.32f, + + 0.13f, + 0.23f, + 0.33f, + + 0.14f, + 0.24f, + 0.34f, + + 0.15f, + 0.25f, + 0.35f, + + 0.16f, + 0.26f, + 0.36f, + + 0.17f, + 0.27f, + 0.37f, + + 0.18f, + 0.28f, + 0.38f, + ], + [3, 3, 3], + IccClutDataType.Float, + outputChannelCount: 1); + + internal static IccClut Clut2x2 = new( + [ + 0.1f, 0.9f, + 0.2f, 0.8f, + 0.3f, 0.7f, + + 0.4f, 0.6f, + 0.5f, 0.5f, + 0.6f, 0.4f, + + 0.7f, 0.3f, + 0.8f, 0.2f, + 0.9f, 0.1f, + ], + [3, 3], + IccClutDataType.Float, + outputChannelCount: 2); + + internal static IccClut Clut2x1 = new( + [ + 0.1f, + 0.2f, + 0.3f, + + 0.4f, + 0.5f, + 0.6f, + + 0.7f, + 0.8f, + 0.9f, + ], + [3, 3], + IccClutDataType.Float, + outputChannelCount: 1); + + internal static IccClut Clut1x2 = new( + [ + 0f, 0.5f, + 0.25f, 0.75f, + 0.5f, 1f, + ], + [3], + IccClutDataType.Float, + outputChannelCount: 2); + + internal static IccClut Clut1x1 = new( + [ + 0f, + 0.5f, + 1f, + ], + [3], + IccClutDataType.Float, + outputChannelCount: 1); + + public static object[][] ClutConversionTestData = + [ + [Clut3x2, new Vector4(0.75f, 0.75f, 0.75f, 0), new Vector4(0.31f, 0.31f, 0, 0)], + [Clut3x1, new Vector4(0.2f, 0.6f, 0.8f, 0), new Vector4(0.284f, 0, 0, 0)], + [Clut3x1, new Vector4(0.75f, 0.75f, 0.75f, 0), new Vector4(0.31f, 0, 0, 0)], + [Clut2x2, new Vector4(0.2f, 0.6f, 0, 0), new Vector4(0.34f, 0.66f, 0, 0)], + [Clut2x2, new Vector4(0.25f, 0.75f, 0, 0), new Vector4(0.4f, 0.6f, 0, 0)], + [Clut2x1, new Vector4(0.25f, 0.75f, 0, 0), new Vector4(0.4f, 0, 0, 0)], + [Clut1x2, new Vector4(0.25f, 0, 0, 0), new Vector4(0.125f, 0.625f, 0, 0)], + [Clut1x1, new Vector4(0.25f, 0, 0, 0), new Vector4(0.25f, 0, 0, 0)], + ]; +} diff --git a/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataLut.cs b/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataLut.cs new file mode 100644 index 0000000000..e910038efb --- /dev/null +++ b/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataLut.cs @@ -0,0 +1,30 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +namespace SixLabors.ImageSharp.Tests.TestDataIcc.Conversion; + +public class IccConversionDataLut +{ + private static readonly float[] LutEven = { 0, 0.5f, 1 }; + + private static readonly float[] LutUneven = { 0, 0.7f, 1 }; + + public static object[][] LutConversionTestData = + { + new object[] { LutEven, false, 0.5f, 0.5f }, + new object[] { LutEven, false, 0.25f, 0.25f }, + new object[] { LutEven, false, 0.75f, 0.75f }, + + new object[] { LutEven, true, 0.5f, 0.5f }, + new object[] { LutEven, true, 0.25f, 0.25f }, + new object[] { LutEven, true, 0.75f, 0.75f }, + + new object[] { LutUneven, false, 0.1, 0.14 }, + new object[] { LutUneven, false, 0.5, 0.7 }, + new object[] { LutUneven, false, 0.75, 0.85 }, + + new object[] { LutUneven, true, 0.14, 0.1 }, + new object[] { LutUneven, true, 0.7, 0.5 }, + new object[] { LutUneven, true, 0.85, 0.75 }, + }; +} diff --git a/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataLutAB.cs b/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataLutAB.cs new file mode 100644 index 0000000000..02fc23735b --- /dev/null +++ b/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataLutAB.cs @@ -0,0 +1,50 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Numerics; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; + +namespace SixLabors.ImageSharp.Tests.TestDataIcc.Conversion; + +public class IccConversionDataLutAB +{ + private static readonly IccLutAToBTagDataEntry LutAtoBSingleCurve = new( + new IccTagDataEntry[] + { + IccConversionDataTrc.IdentityCurve, + IccConversionDataTrc.IdentityCurve, + IccConversionDataTrc.IdentityCurve + }, + null, + null, + null, + null, + null); + + // also need: + // # CurveM + matrix + // # CurveA + CLUT + CurveB + // # CurveA + CLUT + CurveM + Matrix + CurveB + private static readonly IccLutBToATagDataEntry LutBtoASingleCurve = new( + new IccTagDataEntry[] + { + IccConversionDataTrc.IdentityCurve, + IccConversionDataTrc.IdentityCurve, + IccConversionDataTrc.IdentityCurve + }, + null, + null, + null, + null, + null); + + public static object[][] LutAToBConversionTestData = + { + new object[] { LutAtoBSingleCurve, new Vector4(0.2f, 0.3f, 0.4f, 0), new Vector4(0.2f, 0.3f, 0.4f, 0) }, + }; + + public static object[][] LutBToAConversionTestData = + { + new object[] { LutBtoASingleCurve, new Vector4(0.2f, 0.3f, 0.4f, 0), new Vector4(0.2f, 0.3f, 0.4f, 0) }, + }; +} diff --git a/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataLutEntry.cs b/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataLutEntry.cs new file mode 100644 index 0000000000..40f54ea74c --- /dev/null +++ b/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataLutEntry.cs @@ -0,0 +1,71 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Numerics; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; + +namespace SixLabors.ImageSharp.Tests.TestDataIcc.Conversion; + +public class IccConversionDataLutEntry +{ + private static readonly IccLut Lut256 = CreateLut(256); + private static readonly IccLut Lut32 = CreateLut(32); + private static readonly IccLut LutIdentity = CreateIdentityLut(0, 1); + + // test cases were originally calculated unaware that + // IccConversionDataMatrix.Matrix3x3Random is actually the row-major transposed matrix + // of the typical column-major matrix + public static float[,] TestMatrix = + { + { 0.1f, 0.4f, 0.7f }, + { 0.2f, 0.5f, 0.8f }, + { 0.3f, 0.6f, 0.9f } + }; + + private static readonly IccLut8TagDataEntry Lut8 = new( + [Lut256, Lut256], + IccConversionDataClut.Clut2x1, + [Lut256]); + + private static readonly IccLut16TagDataEntry Lut16 = new( + [Lut32, Lut32], + IccConversionDataClut.Clut2x1, + [LutIdentity]); + + private static readonly IccLut8TagDataEntry Lut8Matrix = new( + TestMatrix, + [Lut256, Lut256, Lut256], + IccConversionDataClut.Clut3x1, + [Lut256]); + + private static readonly IccLut16TagDataEntry Lut16Matrix = new( + TestMatrix, + [Lut32, Lut32, Lut32], + IccConversionDataClut.Clut3x1, + [LutIdentity]); + + private static IccLut CreateLut(int length) + { + float[] values = new float[length]; + for (int i = 0; i < values.Length; i++) + { + values[i] = 0.1f + (i / (float)length); + } + + return new IccLut(values); + } + + private static IccLut CreateIdentityLut(float min, float max) => new([min, max]); + + public static object[][] Lut8ConversionTestData = + [ + [Lut8, new Vector4(0.2f, 0.3f, 0, 0), new Vector4(0.4578933760499877f, 0, 0, 0)], + [Lut8Matrix, new Vector4(0.21f, 0.31f, 0.41f, 0), new Vector4(0.40099657491875312f, 0, 0, 0)] + ]; + + public static object[][] Lut16ConversionTestData = + [ + [Lut16, new Vector4(0.2f, 0.3f, 0, 0), new Vector4(0.3543750030529918f, 0, 0, 0)], + [Lut16Matrix, new Vector4(0.21f, 0.31f, 0.41f, 0), new Vector4(0.29739562389689594f, 0, 0, 0)] + ]; +} diff --git a/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataMatrix.cs b/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataMatrix.cs new file mode 100644 index 0000000000..f91c32df8a --- /dev/null +++ b/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataMatrix.cs @@ -0,0 +1,53 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Numerics; + +namespace SixLabors.ImageSharp.Tests.TestDataIcc.Conversion; + +public class IccConversionDataMatrix +{ + private static readonly Vector3 Vector3Zero = new(0.0f, 0.0f, 0.0f); + + public static float[,] Matrix3x3Random = + { + { 0.1f, 0.2f, 0.3f }, + { 0.4f, 0.5f, 0.6f }, + { 0.7f, 0.8f, 0.9f } + }; + + public static float[,] Matrix3x3Identity = + { + { 1, 0, 0 }, + { 0, 1, 0 }, + { 0, 0, 1 } + }; + + public static object[][] MatrixConversionTestData = + { + new object[] { CreateMatrix(Matrix3x3Identity), Vector3Zero, new Vector4(0.5f, 0.5f, 0.5f, 0), new Vector4(0.5f, 0.5f, 0.5f, 0) }, + new object[] { CreateMatrix(Matrix3x3Identity), new Vector3(0.2f, 0.2f, 0.2f), new Vector4(0.5f, 0.5f, 0.5f, 0), new Vector4(0.7f, 0.7f, 0.7f, 0) }, + new object[] { CreateMatrix(Matrix3x3Random), Vector3Zero, new Vector4(0.5f, 0.5f, 0.5f, 0), new Vector4(0.6f, 0.75f, 0.9f, 0) }, + new object[] { CreateMatrix(Matrix3x3Random), new Vector3(0.1f, 0.2f, 0.3f), new Vector4(0.5f, 0.5f, 0.5f, 0), new Vector4(0.7f, 0.95f, 1.2f, 0) }, + new object[] { CreateMatrix(Matrix3x3Random), Vector3Zero, new Vector4(0.2f, 0.4f, 0.7f, 0), new Vector4(0.67f, 0.8f, 0.93f, 0) }, + new object[] { CreateMatrix(Matrix3x3Random), new Vector3(0.1f, 0.2f, 0.3f), new Vector4(0.2f, 0.4f, 0.7f, 0), new Vector4(0.77f, 1, 1.23f, 0) }, + }; + + private static Matrix4x4 CreateMatrix(float[,] matrix) => new( + matrix[0, 0], + matrix[0, 1], + matrix[0, 2], + 0, + matrix[1, 0], + matrix[1, 1], + matrix[1, 2], + 0, + matrix[2, 0], + matrix[2, 1], + matrix[2, 2], + 0, + 0, + 0, + 0, + 1); +} diff --git a/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataMultiProcessElement.cs b/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataMultiProcessElement.cs new file mode 100644 index 0000000000..e4adba078d --- /dev/null +++ b/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataMultiProcessElement.cs @@ -0,0 +1,80 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using SixLabors.ImageSharp.Metadata.Profiles.Icc; + +namespace SixLabors.ImageSharp.Tests.TestDataIcc.Conversion; + +public class IccConversionDataMultiProcessElement +{ + private static readonly IccMatrixProcessElement Matrix = new( + new float[,] + { + { 2, 4, 6 }, + { 3, 5, 7 }, + }, + new float[] { 3, 4, 5 }); + + private static readonly IccClut Clut = new( + new[] + { + 0.2f, 0.3f, + 0.4f, 0.2f, + + 0.21f, 0.31f, + 0.41f, 0.51f, + + 0.22f, 0.32f, + 0.42f, 0.52f, + + 0.23f, 0.33f, + 0.43f, 0.53f, + }, + new byte[] { 2, 2, 2 }, + IccClutDataType.Float, + outputChannelCount: 2); + + private static readonly IccFormulaCurveElement FormulaCurveElement1 = new(IccFormulaCurveType.Type1, 2.2f, 0.7f, 0.2f, 0.3f, 0, 0); + private static readonly IccFormulaCurveElement FormulaCurveElement2 = new(IccFormulaCurveType.Type2, 2.2f, 0.9f, 0.9f, 0.02f, 0.1f, 0); + private static readonly IccFormulaCurveElement FormulaCurveElement3 = new(IccFormulaCurveType.Type3, 0, 0.9f, 0.9f, 1.02f, 0.1f, 0.02f); + + private static readonly IccCurveSetProcessElement CurveSet1DFormula1 = Create1DSingleCurveSet(FormulaCurveElement1); + private static readonly IccCurveSetProcessElement CurveSet1DFormula2 = Create1DSingleCurveSet(FormulaCurveElement2); + private static readonly IccCurveSetProcessElement CurveSet1DFormula3 = Create1DSingleCurveSet(FormulaCurveElement3); + + private static readonly IccCurveSetProcessElement CurveSet1DFormula1And2 = Create1DMultiCurveSet(new[] { 0.5f }, FormulaCurveElement1, FormulaCurveElement2); + + private static readonly IccClutProcessElement ClutElement = new(Clut); + + private static IccCurveSetProcessElement Create1DSingleCurveSet(IccCurveSegment segment) + { + var curve = new IccOneDimensionalCurve(new float[0], new[] { segment }); + return new IccCurveSetProcessElement(new[] { curve }); + } + + private static IccCurveSetProcessElement Create1DMultiCurveSet(float[] breakPoints, params IccCurveSegment[] segments) + { + var curve = new IccOneDimensionalCurve(breakPoints, segments); + return new IccCurveSetProcessElement(new[] { curve }); + } + + public static object[][] MpeCurveConversionTestData = + { + new object[] { CurveSet1DFormula1, new[] { 0.51f }, new[] { 0.575982451f } }, + new object[] { CurveSet1DFormula2, new[] { 0.52f }, new[] { -0.4684991f } }, + new object[] { CurveSet1DFormula3, new[] { 0.53f }, new[] { 0.86126f } }, + + new object[] { CurveSet1DFormula1And2, new[] { 0.31f }, new[] { 0.445982f } }, + new object[] { CurveSet1DFormula1And2, new[] { 0.61f }, new[] { -0.341274023f } }, + }; + + public static object[][] MpeMatrixConversionTestData = + { + new object[] { Matrix, new float[] { 2, 4 }, new float[] { 19, 32, 45 } } + }; + + public static object[][] MpeClutConversionTestData = + { + new object[] { ClutElement, new[] { 0.5f, 0.5f, 0.5f }, new[] { 0.5f, 0.5f } } + }; +} diff --git a/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataTrc.cs b/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataTrc.cs new file mode 100644 index 0000000000..6cd99367a9 --- /dev/null +++ b/tests/ImageSharp.Tests/TestDataIcc/Conversion/IccConversionDataTrc.cs @@ -0,0 +1,76 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Numerics; +using SixLabors.ImageSharp.Metadata.Profiles.Icc; + +namespace SixLabors.ImageSharp.Tests.TestDataIcc.Conversion; + +public static class IccConversionDataTrc +{ + internal static IccCurveTagDataEntry IdentityCurve = new(); + internal static IccCurveTagDataEntry Gamma2Curve = new(2); + internal static IccCurveTagDataEntry LutCurve = new(new float[] { 0, 0.7f, 1 }); + + internal static IccParametricCurveTagDataEntry ParamCurve1 = new(new IccParametricCurve(2.2f)); + internal static IccParametricCurveTagDataEntry ParamCurve2 = new(new IccParametricCurve(2.2f, 1.5f, -0.5f)); + internal static IccParametricCurveTagDataEntry ParamCurve3 = new(new IccParametricCurve(2.2f, 1.5f, -0.5f, 0.3f)); + internal static IccParametricCurveTagDataEntry ParamCurve4 = new(new IccParametricCurve(2.4f, 1 / 1.055f, 0.055f / 1.055f, 1 / 12.92f, 0.04045f)); + internal static IccParametricCurveTagDataEntry ParamCurve5 = new(new IccParametricCurve(2.2f, 0.7f, 0.2f, 0.3f, 0.1f, 0.5f, 0.2f)); + + public static object[][] TrcArrayConversionTestData { get; } = + { + new object[] + { + new IccTagDataEntry[] { IdentityCurve, Gamma2Curve, ParamCurve1 }, + false, + new Vector4(2, 2, 0.5f, 0), + new Vector4(2, 4, 0.217637628f, 0), + }, + new object[] + { + new IccTagDataEntry[] { IdentityCurve, Gamma2Curve, ParamCurve1 }, + true, + new Vector4(1, 4, 0.217637628f, 0), + new Vector4(1, 2, 0.5f, 0), + }, + }; + + public static object[][] CurveConversionTestData { get; } = + { + new object[] { IdentityCurve, false, 2, 2 }, + new object[] { Gamma2Curve, false, 2, 4 }, + new object[] { LutCurve, false, 0.1, 0.14 }, + new object[] { LutCurve, false, 0.5, 0.7 }, + new object[] { LutCurve, false, 0.75, 0.85 }, + + new object[] { IdentityCurve, true, 2, 2 }, + new object[] { Gamma2Curve, true, 4, 2 }, + new object[] { LutCurve, true, 0.14, 0.1 }, + new object[] { LutCurve, true, 0.7, 0.5 }, + new object[] { LutCurve, true, 0.85, 0.75 }, + }; + + public static object[][] ParametricCurveConversionTestData { get; } = + { + new object[] { ParamCurve1, false, 0.5f, 0.217637628f }, + new object[] { ParamCurve2, false, 0.6f, 0.133208528f }, + new object[] { ParamCurve2, false, 0.21f, 0 }, + new object[] { ParamCurve3, false, 0.61f, 0.444446117f }, + new object[] { ParamCurve3, false, 0.22f, 0.3f }, + new object[] { ParamCurve4, false, 0.3f, 0.0732389539f }, + new object[] { ParamCurve4, false, 0.03f, 0.00232198136f }, + new object[] { ParamCurve5, false, 0.2f, 0.593165159f }, + new object[] { ParamCurve5, false, 0.05f, 0.215f }, + + new object[] { ParamCurve1, true, 0.217637628f, 0.5f }, + new object[] { ParamCurve2, true, 0.133208528f, 0.6f }, + new object[] { ParamCurve2, true, 0, 1 / 3f }, + new object[] { ParamCurve3, true, 0.444446117f, 0.61f }, + new object[] { ParamCurve3, true, 0.3f, 1 / 3f }, + new object[] { ParamCurve4, true, 0.0732389539f, 0.3f }, + new object[] { ParamCurve4, true, 0.00232198136f, 0.03f }, + new object[] { ParamCurve5, true, 0.593165159f, 0.2f }, + new object[] { ParamCurve5, true, 0.215f, 0.05f }, + }; +} diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataArray.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataArray.cs index 8288a294dd..cedd20f2d7 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataArray.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataArray.cs @@ -1,7 +1,7 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -namespace SixLabors.ImageSharp.Tests; +namespace SixLabors.ImageSharp.Tests.TestDataIcc; internal static class IccTestDataArray { @@ -12,98 +12,98 @@ internal static class IccTestDataArray new object[] { UInt8, UInt8 } }; - public static readonly ushort[] UInt16_Val = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + public static readonly ushort[] UInt16Val = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - public static readonly byte[] UInt16_Arr = ArrayHelper.Concat( - IccTestDataPrimitives.UInt16_0, - IccTestDataPrimitives.UInt16_1, - IccTestDataPrimitives.UInt16_2, - IccTestDataPrimitives.UInt16_3, - IccTestDataPrimitives.UInt16_4, - IccTestDataPrimitives.UInt16_5, - IccTestDataPrimitives.UInt16_6, - IccTestDataPrimitives.UInt16_7, - IccTestDataPrimitives.UInt16_8, - IccTestDataPrimitives.UInt16_9); + public static readonly byte[] UInt16Arr = ArrayHelper.Concat( + IccTestDataPrimitives.UInt160, + IccTestDataPrimitives.UInt161, + IccTestDataPrimitives.UInt162, + IccTestDataPrimitives.UInt163, + IccTestDataPrimitives.UInt164, + IccTestDataPrimitives.UInt165, + IccTestDataPrimitives.UInt166, + IccTestDataPrimitives.UInt167, + IccTestDataPrimitives.UInt168, + IccTestDataPrimitives.UInt169); public static readonly object[][] UInt16TestData = { - new object[] { UInt16_Arr, UInt16_Val } + new object[] { UInt16Arr, UInt16Val } }; - public static readonly short[] Int16_Val = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + public static readonly short[] Int16Val = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - public static readonly byte[] Int16_Arr = ArrayHelper.Concat( - IccTestDataPrimitives.Int16_0, - IccTestDataPrimitives.Int16_1, - IccTestDataPrimitives.Int16_2, - IccTestDataPrimitives.Int16_3, - IccTestDataPrimitives.Int16_4, - IccTestDataPrimitives.Int16_5, - IccTestDataPrimitives.Int16_6, - IccTestDataPrimitives.Int16_7, - IccTestDataPrimitives.Int16_8, - IccTestDataPrimitives.Int16_9); + public static readonly byte[] Int16Arr = ArrayHelper.Concat( + IccTestDataPrimitives.Int160, + IccTestDataPrimitives.Int161, + IccTestDataPrimitives.Int162, + IccTestDataPrimitives.Int163, + IccTestDataPrimitives.Int164, + IccTestDataPrimitives.Int165, + IccTestDataPrimitives.Int166, + IccTestDataPrimitives.Int167, + IccTestDataPrimitives.Int168, + IccTestDataPrimitives.Int169); public static readonly object[][] Int16TestData = { - new object[] { Int16_Arr, Int16_Val } + new object[] { Int16Arr, Int16Val } }; - public static readonly uint[] UInt32_Val = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + public static readonly uint[] UInt32Val = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - public static readonly byte[] UInt32_Arr = ArrayHelper.Concat( - IccTestDataPrimitives.UInt32_0, - IccTestDataPrimitives.UInt32_1, - IccTestDataPrimitives.UInt32_2, - IccTestDataPrimitives.UInt32_3, - IccTestDataPrimitives.UInt32_4, - IccTestDataPrimitives.UInt32_5, - IccTestDataPrimitives.UInt32_6, - IccTestDataPrimitives.UInt32_7, - IccTestDataPrimitives.UInt32_8, - IccTestDataPrimitives.UInt32_9); + public static readonly byte[] UInt32Arr = ArrayHelper.Concat( + IccTestDataPrimitives.UInt320, + IccTestDataPrimitives.UInt321, + IccTestDataPrimitives.UInt322, + IccTestDataPrimitives.UInt323, + IccTestDataPrimitives.UInt324, + IccTestDataPrimitives.UInt325, + IccTestDataPrimitives.UInt326, + IccTestDataPrimitives.UInt327, + IccTestDataPrimitives.UInt328, + IccTestDataPrimitives.UInt329); public static readonly object[][] UInt32TestData = { - new object[] { UInt32_Arr, UInt32_Val } + new object[] { UInt32Arr, UInt32Val } }; - public static readonly int[] Int32_Val = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + public static readonly int[] Int32Val = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - public static readonly byte[] Int32_Arr = ArrayHelper.Concat( - IccTestDataPrimitives.Int32_0, - IccTestDataPrimitives.Int32_1, - IccTestDataPrimitives.Int32_2, - IccTestDataPrimitives.Int32_3, - IccTestDataPrimitives.Int32_4, - IccTestDataPrimitives.Int32_5, - IccTestDataPrimitives.Int32_6, - IccTestDataPrimitives.Int32_7, - IccTestDataPrimitives.Int32_8, - IccTestDataPrimitives.Int32_9); + public static readonly byte[] Int32Arr = ArrayHelper.Concat( + IccTestDataPrimitives.Int320, + IccTestDataPrimitives.Int321, + IccTestDataPrimitives.Int322, + IccTestDataPrimitives.Int323, + IccTestDataPrimitives.Int324, + IccTestDataPrimitives.Int325, + IccTestDataPrimitives.Int326, + IccTestDataPrimitives.Int327, + IccTestDataPrimitives.Int328, + IccTestDataPrimitives.Int329); public static readonly object[][] Int32TestData = { - new object[] { Int32_Arr, Int32_Val } + new object[] { Int32Arr, Int32Val } }; - public static readonly ulong[] UInt64_Val = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + public static readonly ulong[] UInt64Val = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - public static readonly byte[] UInt64_Arr = ArrayHelper.Concat( - IccTestDataPrimitives.UInt64_0, - IccTestDataPrimitives.UInt64_1, - IccTestDataPrimitives.UInt64_2, - IccTestDataPrimitives.UInt64_3, - IccTestDataPrimitives.UInt64_4, - IccTestDataPrimitives.UInt64_5, - IccTestDataPrimitives.UInt64_6, - IccTestDataPrimitives.UInt64_7, - IccTestDataPrimitives.UInt64_8, - IccTestDataPrimitives.UInt64_9); + public static readonly byte[] UInt64Arr = ArrayHelper.Concat( + IccTestDataPrimitives.UInt640, + IccTestDataPrimitives.UInt641, + IccTestDataPrimitives.UInt642, + IccTestDataPrimitives.UInt643, + IccTestDataPrimitives.UInt644, + IccTestDataPrimitives.UInt645, + IccTestDataPrimitives.UInt646, + IccTestDataPrimitives.UInt647, + IccTestDataPrimitives.UInt648, + IccTestDataPrimitives.UInt649); public static readonly object[][] UInt64TestData = { - new object[] { UInt64_Arr, UInt64_Val } + new object[] { UInt64Arr, UInt64Val } }; } diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataCurves.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataCurves.cs index f76d2ba036..6f8244f1c7 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataCurves.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataCurves.cs @@ -3,309 +3,309 @@ using SixLabors.ImageSharp.Metadata.Profiles.Icc; -namespace SixLabors.ImageSharp.Tests; +namespace SixLabors.ImageSharp.Tests.TestDataIcc; internal static class IccTestDataCurves { /// /// Channels: 3 /// - public static readonly IccResponseCurve Response_ValGrad = new IccResponseCurve( + public static readonly IccResponseCurve ResponseValGrad = new( IccCurveMeasurementEncodings.StatusA, new[] { - IccTestDataNonPrimitives.XyzNumber_ValVar1, - IccTestDataNonPrimitives.XyzNumber_ValVar2, - IccTestDataNonPrimitives.XyzNumber_ValVar3 + IccTestDataNonPrimitives.XyzNumberValVar1, + IccTestDataNonPrimitives.XyzNumberValVar2, + IccTestDataNonPrimitives.XyzNumberValVar3 }, - new IccResponseNumber[][] + new[] { - new IccResponseNumber[] { IccTestDataNonPrimitives.ResponseNumber_Val1, IccTestDataNonPrimitives.ResponseNumber_Val2 }, - new IccResponseNumber[] { IccTestDataNonPrimitives.ResponseNumber_Val3, IccTestDataNonPrimitives.ResponseNumber_Val4 }, - new IccResponseNumber[] { IccTestDataNonPrimitives.ResponseNumber_Val5, IccTestDataNonPrimitives.ResponseNumber_Val6 }, + new[] { IccTestDataNonPrimitives.ResponseNumberVal1, IccTestDataNonPrimitives.ResponseNumberVal2 }, + new[] { IccTestDataNonPrimitives.ResponseNumberVal3, IccTestDataNonPrimitives.ResponseNumberVal4 }, + new[] { IccTestDataNonPrimitives.ResponseNumberVal5, IccTestDataNonPrimitives.ResponseNumberVal6 }, }); /// /// Channels: 3 /// - public static readonly byte[] Response_Grad = ArrayHelper.Concat( + public static readonly byte[] ResponseGrad = ArrayHelper.Concat( new byte[] { 0x53, 0x74, 0x61, 0x41 }, - IccTestDataPrimitives.UInt32_2, - IccTestDataPrimitives.UInt32_2, - IccTestDataPrimitives.UInt32_2, - IccTestDataNonPrimitives.XyzNumber_Var1, - IccTestDataNonPrimitives.XyzNumber_Var2, - IccTestDataNonPrimitives.XyzNumber_Var3, - IccTestDataNonPrimitives.ResponseNumber_1, - IccTestDataNonPrimitives.ResponseNumber_2, - IccTestDataNonPrimitives.ResponseNumber_3, - IccTestDataNonPrimitives.ResponseNumber_4, - IccTestDataNonPrimitives.ResponseNumber_5, - IccTestDataNonPrimitives.ResponseNumber_6); + IccTestDataPrimitives.UInt322, + IccTestDataPrimitives.UInt322, + IccTestDataPrimitives.UInt322, + IccTestDataNonPrimitives.XyzNumberVar1, + IccTestDataNonPrimitives.XyzNumberVar2, + IccTestDataNonPrimitives.XyzNumberVar3, + IccTestDataNonPrimitives.ResponseNumber1, + IccTestDataNonPrimitives.ResponseNumber2, + IccTestDataNonPrimitives.ResponseNumber3, + IccTestDataNonPrimitives.ResponseNumber4, + IccTestDataNonPrimitives.ResponseNumber5, + IccTestDataNonPrimitives.ResponseNumber6); public static readonly object[][] ResponseCurveTestData = { - new object[] { Response_Grad, Response_ValGrad, 3 }, + new object[] { ResponseGrad, ResponseValGrad, 3 }, }; - public static readonly IccParametricCurve Parametric_ValVar1 = new IccParametricCurve(1); - public static readonly IccParametricCurve Parametric_ValVar2 = new IccParametricCurve(1, 2, 3); - public static readonly IccParametricCurve Parametric_ValVar3 = new IccParametricCurve(1, 2, 3, 4); - public static readonly IccParametricCurve Parametric_ValVar4 = new IccParametricCurve(1, 2, 3, 4, 5); - public static readonly IccParametricCurve Parametric_ValVar5 = new IccParametricCurve(1, 2, 3, 4, 5, 6, 7); + public static readonly IccParametricCurve ParametricValVar1 = new(1); + public static readonly IccParametricCurve ParametricValVar2 = new(1, 2, 3); + public static readonly IccParametricCurve ParametricValVar3 = new(1, 2, 3, 4); + public static readonly IccParametricCurve ParametricValVar4 = new(1, 2, 3, 4, 5); + public static readonly IccParametricCurve ParametricValVar5 = new(1, 2, 3, 4, 5, 6, 7); - public static readonly byte[] Parametric_Var1 = ArrayHelper.Concat( + public static readonly byte[] ParametricVar1 = ArrayHelper.Concat( new byte[] { 0x00, 0x00, 0x00, 0x00, }, - IccTestDataPrimitives.Fix16_1); + IccTestDataPrimitives.Fix161); - public static readonly byte[] Parametric_Var2 = ArrayHelper.Concat( + public static readonly byte[] ParametricVar2 = ArrayHelper.Concat( new byte[] { 0x00, 0x01, 0x00, 0x00, }, - IccTestDataPrimitives.Fix16_1, - IccTestDataPrimitives.Fix16_2, - IccTestDataPrimitives.Fix16_3); + IccTestDataPrimitives.Fix161, + IccTestDataPrimitives.Fix162, + IccTestDataPrimitives.Fix163); - public static readonly byte[] Parametric_Var3 = ArrayHelper.Concat( + public static readonly byte[] ParametricVar3 = ArrayHelper.Concat( new byte[] { 0x00, 0x02, 0x00, 0x00, }, - IccTestDataPrimitives.Fix16_1, - IccTestDataPrimitives.Fix16_2, - IccTestDataPrimitives.Fix16_3, - IccTestDataPrimitives.Fix16_4); + IccTestDataPrimitives.Fix161, + IccTestDataPrimitives.Fix162, + IccTestDataPrimitives.Fix163, + IccTestDataPrimitives.Fix164); - public static readonly byte[] Parametric_Var4 = ArrayHelper.Concat( + public static readonly byte[] ParametricVar4 = ArrayHelper.Concat( new byte[] { 0x00, 0x03, 0x00, 0x00, }, - IccTestDataPrimitives.Fix16_1, - IccTestDataPrimitives.Fix16_2, - IccTestDataPrimitives.Fix16_3, - IccTestDataPrimitives.Fix16_4, - IccTestDataPrimitives.Fix16_5); + IccTestDataPrimitives.Fix161, + IccTestDataPrimitives.Fix162, + IccTestDataPrimitives.Fix163, + IccTestDataPrimitives.Fix164, + IccTestDataPrimitives.Fix165); - public static readonly byte[] Parametric_Var5 = ArrayHelper.Concat( + public static readonly byte[] ParametricVar5 = ArrayHelper.Concat( new byte[] { 0x00, 0x04, 0x00, 0x00, }, - IccTestDataPrimitives.Fix16_1, - IccTestDataPrimitives.Fix16_2, - IccTestDataPrimitives.Fix16_3, - IccTestDataPrimitives.Fix16_4, - IccTestDataPrimitives.Fix16_5, - IccTestDataPrimitives.Fix16_6, - IccTestDataPrimitives.Fix16_7); + IccTestDataPrimitives.Fix161, + IccTestDataPrimitives.Fix162, + IccTestDataPrimitives.Fix163, + IccTestDataPrimitives.Fix164, + IccTestDataPrimitives.Fix165, + IccTestDataPrimitives.Fix166, + IccTestDataPrimitives.Fix167); public static readonly object[][] ParametricCurveTestData = { - new object[] { Parametric_Var1, Parametric_ValVar1 }, - new object[] { Parametric_Var2, Parametric_ValVar2 }, - new object[] { Parametric_Var3, Parametric_ValVar3 }, - new object[] { Parametric_Var4, Parametric_ValVar4 }, - new object[] { Parametric_Var5, Parametric_ValVar5 }, + new object[] { ParametricVar1, ParametricValVar1 }, + new object[] { ParametricVar2, ParametricValVar2 }, + new object[] { ParametricVar3, ParametricValVar3 }, + new object[] { ParametricVar4, ParametricValVar4 }, + new object[] { ParametricVar5, ParametricValVar5 }, }; // Formula Segment - public static readonly IccFormulaCurveElement Formula_ValVar1 = new IccFormulaCurveElement(IccFormulaCurveType.Type1, 1, 2, 3, 4, 0, 0); - public static readonly IccFormulaCurveElement Formula_ValVar2 = new IccFormulaCurveElement(IccFormulaCurveType.Type2, 1, 2, 3, 4, 5, 0); - public static readonly IccFormulaCurveElement Formula_ValVar3 = new IccFormulaCurveElement(IccFormulaCurveType.Type3, 0, 2, 3, 4, 5, 6); + public static readonly IccFormulaCurveElement FormulaValVar1 = new(IccFormulaCurveType.Type1, 1, 2, 3, 4, 0, 0); + public static readonly IccFormulaCurveElement FormulaValVar2 = new(IccFormulaCurveType.Type2, 1, 2, 3, 4, 5, 0); + public static readonly IccFormulaCurveElement FormulaValVar3 = new(IccFormulaCurveType.Type3, 0, 2, 3, 4, 5, 6); - public static readonly byte[] Formula_Var1 = ArrayHelper.Concat( + public static readonly byte[] FormulaVar1 = ArrayHelper.Concat( new byte[] { 0x00, 0x00, 0x00, 0x00, }, - IccTestDataPrimitives.Single_1, - IccTestDataPrimitives.Single_2, - IccTestDataPrimitives.Single_3, - IccTestDataPrimitives.Single_4); + IccTestDataPrimitives.Single1, + IccTestDataPrimitives.Single2, + IccTestDataPrimitives.Single3, + IccTestDataPrimitives.Single4); - public static readonly byte[] Formula_Var2 = ArrayHelper.Concat( + public static readonly byte[] FormulaVar2 = ArrayHelper.Concat( new byte[] { 0x00, 0x01, 0x00, 0x00, }, - IccTestDataPrimitives.Single_1, - IccTestDataPrimitives.Single_2, - IccTestDataPrimitives.Single_3, - IccTestDataPrimitives.Single_4, - IccTestDataPrimitives.Single_5); + IccTestDataPrimitives.Single1, + IccTestDataPrimitives.Single2, + IccTestDataPrimitives.Single3, + IccTestDataPrimitives.Single4, + IccTestDataPrimitives.Single5); - public static readonly byte[] Formula_Var3 = ArrayHelper.Concat( + public static readonly byte[] FormulaVar3 = ArrayHelper.Concat( new byte[] { 0x00, 0x02, 0x00, 0x00, }, - IccTestDataPrimitives.Single_2, - IccTestDataPrimitives.Single_3, - IccTestDataPrimitives.Single_4, - IccTestDataPrimitives.Single_5, - IccTestDataPrimitives.Single_6); + IccTestDataPrimitives.Single2, + IccTestDataPrimitives.Single3, + IccTestDataPrimitives.Single4, + IccTestDataPrimitives.Single5, + IccTestDataPrimitives.Single6); public static readonly object[][] FormulaCurveSegmentTestData = { - new object[] { Formula_Var1, Formula_ValVar1 }, - new object[] { Formula_Var2, Formula_ValVar2 }, - new object[] { Formula_Var3, Formula_ValVar3 }, + new object[] { FormulaVar1, FormulaValVar1 }, + new object[] { FormulaVar2, FormulaValVar2 }, + new object[] { FormulaVar3, FormulaValVar3 }, }; // Sampled Segment - public static readonly IccSampledCurveElement Sampled_ValGrad1 = new IccSampledCurveElement(new float[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }); - public static readonly IccSampledCurveElement Sampled_ValGrad2 = new IccSampledCurveElement(new float[] { 9, 8, 7, 6, 5, 4, 3, 2, 1 }); - - public static readonly byte[] Sampled_Grad1 = ArrayHelper.Concat( - IccTestDataPrimitives.UInt32_9, - IccTestDataPrimitives.Single_1, - IccTestDataPrimitives.Single_2, - IccTestDataPrimitives.Single_3, - IccTestDataPrimitives.Single_4, - IccTestDataPrimitives.Single_5, - IccTestDataPrimitives.Single_6, - IccTestDataPrimitives.Single_7, - IccTestDataPrimitives.Single_8, - IccTestDataPrimitives.Single_9); - - public static readonly byte[] Sampled_Grad2 = ArrayHelper.Concat( - IccTestDataPrimitives.UInt32_9, - IccTestDataPrimitives.Single_9, - IccTestDataPrimitives.Single_8, - IccTestDataPrimitives.Single_7, - IccTestDataPrimitives.Single_6, - IccTestDataPrimitives.Single_5, - IccTestDataPrimitives.Single_4, - IccTestDataPrimitives.Single_3, - IccTestDataPrimitives.Single_2, - IccTestDataPrimitives.Single_1); + public static readonly IccSampledCurveElement SampledValGrad1 = new(new float[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }); + public static readonly IccSampledCurveElement SampledValGrad2 = new(new float[] { 9, 8, 7, 6, 5, 4, 3, 2, 1 }); + + public static readonly byte[] SampledGrad1 = ArrayHelper.Concat( + IccTestDataPrimitives.UInt329, + IccTestDataPrimitives.Single1, + IccTestDataPrimitives.Single2, + IccTestDataPrimitives.Single3, + IccTestDataPrimitives.Single4, + IccTestDataPrimitives.Single5, + IccTestDataPrimitives.Single6, + IccTestDataPrimitives.Single7, + IccTestDataPrimitives.Single8, + IccTestDataPrimitives.Single9); + + public static readonly byte[] SampledGrad2 = ArrayHelper.Concat( + IccTestDataPrimitives.UInt329, + IccTestDataPrimitives.Single9, + IccTestDataPrimitives.Single8, + IccTestDataPrimitives.Single7, + IccTestDataPrimitives.Single6, + IccTestDataPrimitives.Single5, + IccTestDataPrimitives.Single4, + IccTestDataPrimitives.Single3, + IccTestDataPrimitives.Single2, + IccTestDataPrimitives.Single1); public static readonly object[][] SampledCurveSegmentTestData = { - new object[] { Sampled_Grad1, Sampled_ValGrad1 }, - new object[] { Sampled_Grad2, Sampled_ValGrad2 }, + new object[] { SampledGrad1, SampledValGrad1 }, + new object[] { SampledGrad2, SampledValGrad2 }, }; - public static readonly IccCurveSegment Segment_ValFormula1 = Formula_ValVar1; - public static readonly IccCurveSegment Segment_ValFormula2 = Formula_ValVar2; - public static readonly IccCurveSegment Segment_ValFormula3 = Formula_ValVar3; - public static readonly IccCurveSegment Segment_ValSampled1 = Sampled_ValGrad1; - public static readonly IccCurveSegment Segment_ValSampled2 = Sampled_ValGrad2; + public static readonly IccCurveSegment SegmentValFormula1 = FormulaValVar1; + public static readonly IccCurveSegment SegmentValFormula2 = FormulaValVar2; + public static readonly IccCurveSegment SegmentValFormula3 = FormulaValVar3; + public static readonly IccCurveSegment SegmentValSampled1 = SampledValGrad1; + public static readonly IccCurveSegment SegmentValSampled2 = SampledValGrad2; - public static readonly byte[] Segment_Formula1 = ArrayHelper.Concat( + public static readonly byte[] SegmentFormula1 = ArrayHelper.Concat( new byte[] { 0x70, 0x61, 0x72, 0x66, 0x00, 0x00, 0x00, 0x00, }, - Formula_Var1); + FormulaVar1); - public static readonly byte[] Segment_Formula2 = ArrayHelper.Concat( + public static readonly byte[] SegmentFormula2 = ArrayHelper.Concat( new byte[] { 0x70, 0x61, 0x72, 0x66, 0x00, 0x00, 0x00, 0x00, }, - Formula_Var2); + FormulaVar2); - public static readonly byte[] Segment_Formula3 = ArrayHelper.Concat( + public static readonly byte[] SegmentFormula3 = ArrayHelper.Concat( new byte[] { 0x70, 0x61, 0x72, 0x66, 0x00, 0x00, 0x00, 0x00, }, - Formula_Var3); + FormulaVar3); - public static readonly byte[] Segment_Sampled1 = ArrayHelper.Concat( + public static readonly byte[] SegmentSampled1 = ArrayHelper.Concat( new byte[] { 0x73, 0x61, 0x6D, 0x66, 0x00, 0x00, 0x00, 0x00, }, - Sampled_Grad1); + SampledGrad1); - public static readonly byte[] Segment_Sampled2 = ArrayHelper.Concat( + public static readonly byte[] SegmentSampled2 = ArrayHelper.Concat( new byte[] { 0x73, 0x61, 0x6D, 0x66, 0x00, 0x00, 0x00, 0x00, }, - Sampled_Grad2); + SampledGrad2); public static readonly object[][] CurveSegmentTestData = { - new object[] { Segment_Formula1, Segment_ValFormula1 }, - new object[] { Segment_Formula2, Segment_ValFormula2 }, - new object[] { Segment_Formula3, Segment_ValFormula3 }, - new object[] { Segment_Sampled1, Segment_ValSampled1 }, - new object[] { Segment_Sampled2, Segment_ValSampled2 }, + new object[] { SegmentFormula1, SegmentValFormula1 }, + new object[] { SegmentFormula2, SegmentValFormula2 }, + new object[] { SegmentFormula3, SegmentValFormula3 }, + new object[] { SegmentSampled1, SegmentValSampled1 }, + new object[] { SegmentSampled2, SegmentValSampled2 }, }; - public static readonly IccOneDimensionalCurve OneDimensional_ValFormula1 = new IccOneDimensionalCurve( + public static readonly IccOneDimensionalCurve OneDimensionalValFormula1 = new( new float[] { 0, 1 }, - new IccCurveSegment[] { Segment_ValFormula1, Segment_ValFormula2, Segment_ValFormula3 }); + new[] { SegmentValFormula1, SegmentValFormula2, SegmentValFormula3 }); - public static readonly IccOneDimensionalCurve OneDimensional_ValFormula2 = new IccOneDimensionalCurve( + public static readonly IccOneDimensionalCurve OneDimensionalValFormula2 = new( new float[] { 0, 1 }, - new IccCurveSegment[] { Segment_ValFormula3, Segment_ValFormula2, Segment_ValFormula1 }); + new[] { SegmentValFormula3, SegmentValFormula2, SegmentValFormula1 }); - public static readonly IccOneDimensionalCurve OneDimensional_ValSampled = new IccOneDimensionalCurve( + public static readonly IccOneDimensionalCurve OneDimensionalValSampled = new( new float[] { 0, 1 }, - new IccCurveSegment[] { Segment_ValSampled1, Segment_ValSampled2, Segment_ValSampled1 }); + new[] { SegmentValSampled1, SegmentValSampled2, SegmentValSampled1 }); - public static readonly byte[] OneDimensional_Formula1 = ArrayHelper.Concat( + public static readonly byte[] OneDimensionalFormula1 = ArrayHelper.Concat( new byte[] { 0x00, 0x03, 0x00, 0x00, }, - IccTestDataPrimitives.Single_0, - IccTestDataPrimitives.Single_1, - Segment_Formula1, - Segment_Formula2, - Segment_Formula3); + IccTestDataPrimitives.Single0, + IccTestDataPrimitives.Single1, + SegmentFormula1, + SegmentFormula2, + SegmentFormula3); - public static readonly byte[] OneDimensional_Formula2 = ArrayHelper.Concat( + public static readonly byte[] OneDimensionalFormula2 = ArrayHelper.Concat( new byte[] { 0x00, 0x03, 0x00, 0x00, }, - IccTestDataPrimitives.Single_0, - IccTestDataPrimitives.Single_1, - Segment_Formula3, - Segment_Formula2, - Segment_Formula1); + IccTestDataPrimitives.Single0, + IccTestDataPrimitives.Single1, + SegmentFormula3, + SegmentFormula2, + SegmentFormula1); - public static readonly byte[] OneDimensional_Sampled = ArrayHelper.Concat( + public static readonly byte[] OneDimensionalSampled = ArrayHelper.Concat( new byte[] { 0x00, 0x03, 0x00, 0x00, }, - IccTestDataPrimitives.Single_0, - IccTestDataPrimitives.Single_1, - Segment_Sampled1, - Segment_Sampled2, - Segment_Sampled1); + IccTestDataPrimitives.Single0, + IccTestDataPrimitives.Single1, + SegmentSampled1, + SegmentSampled2, + SegmentSampled1); public static readonly object[][] OneDimensionalCurveTestData = { - new object[] { OneDimensional_Formula1, OneDimensional_ValFormula1 }, - new object[] { OneDimensional_Formula2, OneDimensional_ValFormula2 }, - new object[] { OneDimensional_Sampled, OneDimensional_ValSampled }, + new object[] { OneDimensionalFormula1, OneDimensionalValFormula1 }, + new object[] { OneDimensionalFormula2, OneDimensionalValFormula2 }, + new object[] { OneDimensionalSampled, OneDimensionalValSampled }, }; } diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataLut.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataLut.cs index 7a778f269b..2bd47e4497 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataLut.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataLut.cs @@ -3,14 +3,14 @@ using SixLabors.ImageSharp.Metadata.Profiles.Icc; -namespace SixLabors.ImageSharp.Tests; +namespace SixLabors.ImageSharp.Tests.TestDataIcc; internal static class IccTestDataLut { - public static readonly IccLut LUT8_ValGrad = CreateLUT8Val(); - public static readonly byte[] LUT8_Grad = CreateLUT8(); + public static readonly IccLut Lut8ValGrad = CreateLut8Val(); + public static readonly byte[] Lut8Grad = CreateLut8(); - private static IccLut CreateLUT8Val() + private static IccLut CreateLut8Val() { float[] result = new float[256]; for (int i = 0; i < 256; i++) @@ -21,7 +21,7 @@ internal static class IccTestDataLut return new IccLut(result); } - private static byte[] CreateLUT8() + private static byte[] CreateLut8() { byte[] result = new byte[256]; for (int i = 0; i < 256; i++) @@ -34,10 +34,10 @@ internal static class IccTestDataLut public static readonly object[][] Lut8TestData = { - new object[] { LUT8_Grad, LUT8_ValGrad }, + new object[] { Lut8Grad, Lut8ValGrad }, }; - public static readonly IccLut LUT16_ValGrad = new IccLut(new float[] + public static readonly IccLut Lut16ValGrad = new(new[] { 1f / ushort.MaxValue, 2f / ushort.MaxValue, @@ -52,48 +52,49 @@ internal static class IccTestDataLut 1f }); - public static readonly byte[] LUT16_Grad = ArrayHelper.Concat( - IccTestDataPrimitives.UInt16_1, - IccTestDataPrimitives.UInt16_2, - IccTestDataPrimitives.UInt16_3, - IccTestDataPrimitives.UInt16_4, - IccTestDataPrimitives.UInt16_5, - IccTestDataPrimitives.UInt16_6, - IccTestDataPrimitives.UInt16_7, - IccTestDataPrimitives.UInt16_8, - IccTestDataPrimitives.UInt16_9, - IccTestDataPrimitives.UInt16_32768, - IccTestDataPrimitives.UInt16_Max); + public static readonly byte[] Lut16Grad = ArrayHelper.Concat( + IccTestDataPrimitives.UInt161, + IccTestDataPrimitives.UInt162, + IccTestDataPrimitives.UInt163, + IccTestDataPrimitives.UInt164, + IccTestDataPrimitives.UInt165, + IccTestDataPrimitives.UInt166, + IccTestDataPrimitives.UInt167, + IccTestDataPrimitives.UInt168, + IccTestDataPrimitives.UInt169, + IccTestDataPrimitives.UInt1632768, + IccTestDataPrimitives.UInt16Max); public static readonly object[][] Lut16TestData = { - new object[] { LUT16_Grad, LUT16_ValGrad, 11 }, + new object[] { Lut16Grad, Lut16ValGrad, 11 }, }; - public static readonly IccClut CLUT8_ValGrad = new IccClut( - new float[][] + public static readonly IccClut Clut8ValGrad = new( + new[] { - new float[] { 1f / byte.MaxValue, 2f / byte.MaxValue, 3f / byte.MaxValue }, - new float[] { 4f / byte.MaxValue, 5f / byte.MaxValue, 6f / byte.MaxValue }, - new float[] { 7f / byte.MaxValue, 8f / byte.MaxValue, 9f / byte.MaxValue }, + 1f / byte.MaxValue, 2f / byte.MaxValue, 3f / byte.MaxValue, + 4f / byte.MaxValue, 5f / byte.MaxValue, 6f / byte.MaxValue, + 7f / byte.MaxValue, 8f / byte.MaxValue, 9f / byte.MaxValue, - new float[] { 10f / byte.MaxValue, 11f / byte.MaxValue, 12f / byte.MaxValue }, - new float[] { 13f / byte.MaxValue, 14f / byte.MaxValue, 15f / byte.MaxValue }, - new float[] { 16f / byte.MaxValue, 17f / byte.MaxValue, 18f / byte.MaxValue }, + 10f / byte.MaxValue, 11f / byte.MaxValue, 12f / byte.MaxValue, + 13f / byte.MaxValue, 14f / byte.MaxValue, 15f / byte.MaxValue, + 16f / byte.MaxValue, 17f / byte.MaxValue, 18f / byte.MaxValue, - new float[] { 19f / byte.MaxValue, 20f / byte.MaxValue, 21f / byte.MaxValue }, - new float[] { 22f / byte.MaxValue, 23f / byte.MaxValue, 24f / byte.MaxValue }, - new float[] { 25f / byte.MaxValue, 26f / byte.MaxValue, 27f / byte.MaxValue }, + 19f / byte.MaxValue, 20f / byte.MaxValue, 21f / byte.MaxValue, + 22f / byte.MaxValue, 23f / byte.MaxValue, 24f / byte.MaxValue, + 25f / byte.MaxValue, 26f / byte.MaxValue, 27f / byte.MaxValue, }, new byte[] { 3, 3 }, - IccClutDataType.UInt8); + IccClutDataType.UInt8, + outputChannelCount: 3); /// /// Input Channel Count: 2 /// Output Channel Count: 3 /// Grid-point Count: { 3, 3 } /// - public static readonly byte[] CLUT8_Grad = + public static readonly byte[] Clut8Grad = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, @@ -110,33 +111,34 @@ internal static class IccTestDataLut public static readonly object[][] Clut8TestData = { - new object[] { CLUT8_Grad, CLUT8_ValGrad, 2, 3, new byte[] { 3, 3 } }, + new object[] { Clut8Grad, Clut8ValGrad, 2, 3, new byte[] { 3, 3 } }, }; - public static readonly IccClut CLUT16_ValGrad = new IccClut( - new float[][] + public static readonly IccClut Clut16ValGrad = new( + new[] { - new float[] { 1f / ushort.MaxValue, 2f / ushort.MaxValue, 3f / ushort.MaxValue }, - new float[] { 4f / ushort.MaxValue, 5f / ushort.MaxValue, 6f / ushort.MaxValue }, - new float[] { 7f / ushort.MaxValue, 8f / ushort.MaxValue, 9f / ushort.MaxValue }, + 1f / ushort.MaxValue, 2f / ushort.MaxValue, 3f / ushort.MaxValue, + 4f / ushort.MaxValue, 5f / ushort.MaxValue, 6f / ushort.MaxValue, + 7f / ushort.MaxValue, 8f / ushort.MaxValue, 9f / ushort.MaxValue, - new float[] { 10f / ushort.MaxValue, 11f / ushort.MaxValue, 12f / ushort.MaxValue }, - new float[] { 13f / ushort.MaxValue, 14f / ushort.MaxValue, 15f / ushort.MaxValue }, - new float[] { 16f / ushort.MaxValue, 17f / ushort.MaxValue, 18f / ushort.MaxValue }, + 10f / ushort.MaxValue, 11f / ushort.MaxValue, 12f / ushort.MaxValue, + 13f / ushort.MaxValue, 14f / ushort.MaxValue, 15f / ushort.MaxValue, + 16f / ushort.MaxValue, 17f / ushort.MaxValue, 18f / ushort.MaxValue, - new float[] { 19f / ushort.MaxValue, 20f / ushort.MaxValue, 21f / ushort.MaxValue }, - new float[] { 22f / ushort.MaxValue, 23f / ushort.MaxValue, 24f / ushort.MaxValue }, - new float[] { 25f / ushort.MaxValue, 26f / ushort.MaxValue, 27f / ushort.MaxValue }, + 19f / ushort.MaxValue, 20f / ushort.MaxValue, 21f / ushort.MaxValue, + 22f / ushort.MaxValue, 23f / ushort.MaxValue, 24f / ushort.MaxValue, + 25f / ushort.MaxValue, 26f / ushort.MaxValue, 27f / ushort.MaxValue, }, new byte[] { 3, 3 }, - IccClutDataType.UInt16); + IccClutDataType.UInt16, + outputChannelCount: 3); /// /// Input Channel Count: 2 /// Output Channel Count: 3 /// Grid-point Count: { 3, 3 } /// - public static readonly byte[] CLUT16_Grad = + public static readonly byte[] Clut16Grad = { 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, @@ -153,88 +155,89 @@ internal static class IccTestDataLut public static readonly object[][] Clut16TestData = { - new object[] { CLUT16_Grad, CLUT16_ValGrad, 2, 3, new byte[] { 3, 3 } }, + new object[] { Clut16Grad, Clut16ValGrad, 2, 3, new byte[] { 3, 3 } }, }; - public static readonly IccClut CLUTf32_ValGrad = new IccClut( - new float[][] + public static readonly IccClut CluTf32ValGrad = new( + new[] { - new float[] { 1f, 2f, 3f }, - new float[] { 4f, 5f, 6f }, - new float[] { 7f, 8f, 9f }, + 1f, 2f, 3f, + 4f, 5f, 6f, + 7f, 8f, 9f, - new float[] { 1f, 2f, 3f }, - new float[] { 4f, 5f, 6f }, - new float[] { 7f, 8f, 9f }, + 1f, 2f, 3f, + 4f, 5f, 6f, + 7f, 8f, 9f, - new float[] { 1f, 2f, 3f }, - new float[] { 4f, 5f, 6f }, - new float[] { 7f, 8f, 9f }, + 1f, 2f, 3f, + 4f, 5f, 6f, + 7f, 8f, 9f, }, new byte[] { 3, 3 }, - IccClutDataType.Float); + IccClutDataType.Float, + outputChannelCount: 3); /// /// Input Channel Count: 2 /// Output Channel Count: 3 /// Grid-point Count: { 3, 3 } /// - public static readonly byte[] CLUTf32_Grad = ArrayHelper.Concat( - IccTestDataPrimitives.Single_1, - IccTestDataPrimitives.Single_2, - IccTestDataPrimitives.Single_3, - IccTestDataPrimitives.Single_4, - IccTestDataPrimitives.Single_5, - IccTestDataPrimitives.Single_6, - IccTestDataPrimitives.Single_7, - IccTestDataPrimitives.Single_8, - IccTestDataPrimitives.Single_9, - IccTestDataPrimitives.Single_1, - IccTestDataPrimitives.Single_2, - IccTestDataPrimitives.Single_3, - IccTestDataPrimitives.Single_4, - IccTestDataPrimitives.Single_5, - IccTestDataPrimitives.Single_6, - IccTestDataPrimitives.Single_7, - IccTestDataPrimitives.Single_8, - IccTestDataPrimitives.Single_9, - IccTestDataPrimitives.Single_1, - IccTestDataPrimitives.Single_2, - IccTestDataPrimitives.Single_3, - IccTestDataPrimitives.Single_4, - IccTestDataPrimitives.Single_5, - IccTestDataPrimitives.Single_6, - IccTestDataPrimitives.Single_7, - IccTestDataPrimitives.Single_8, - IccTestDataPrimitives.Single_9); + public static readonly byte[] CluTf32Grad = ArrayHelper.Concat( + IccTestDataPrimitives.Single1, + IccTestDataPrimitives.Single2, + IccTestDataPrimitives.Single3, + IccTestDataPrimitives.Single4, + IccTestDataPrimitives.Single5, + IccTestDataPrimitives.Single6, + IccTestDataPrimitives.Single7, + IccTestDataPrimitives.Single8, + IccTestDataPrimitives.Single9, + IccTestDataPrimitives.Single1, + IccTestDataPrimitives.Single2, + IccTestDataPrimitives.Single3, + IccTestDataPrimitives.Single4, + IccTestDataPrimitives.Single5, + IccTestDataPrimitives.Single6, + IccTestDataPrimitives.Single7, + IccTestDataPrimitives.Single8, + IccTestDataPrimitives.Single9, + IccTestDataPrimitives.Single1, + IccTestDataPrimitives.Single2, + IccTestDataPrimitives.Single3, + IccTestDataPrimitives.Single4, + IccTestDataPrimitives.Single5, + IccTestDataPrimitives.Single6, + IccTestDataPrimitives.Single7, + IccTestDataPrimitives.Single8, + IccTestDataPrimitives.Single9); public static readonly object[][] ClutF32TestData = { - new object[] { CLUTf32_Grad, CLUTf32_ValGrad, 2, 3, new byte[] { 3, 3 } }, + new object[] { CluTf32Grad, CluTf32ValGrad, 2, 3, new byte[] { 3, 3 } }, }; - public static readonly IccClut CLUT_Val8 = CLUT8_ValGrad; - public static readonly IccClut CLUT_Val16 = CLUT16_ValGrad; - public static readonly IccClut CLUT_Valf32 = CLUTf32_ValGrad; + public static readonly IccClut ClutVal8 = Clut8ValGrad; + public static readonly IccClut ClutVal16 = Clut16ValGrad; + public static readonly IccClut ClutValf32 = CluTf32ValGrad; - public static readonly byte[] CLUT_8 = ArrayHelper.Concat( + public static readonly byte[] Clut8 = ArrayHelper.Concat( new byte[16] { 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, new byte[4] { 0x01, 0x00, 0x00, 0x00 }, - CLUT8_Grad); + Clut8Grad); - public static readonly byte[] CLUT_16 = ArrayHelper.Concat( + public static readonly byte[] Clut16 = ArrayHelper.Concat( new byte[16] { 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, new byte[4] { 0x02, 0x00, 0x00, 0x00 }, - CLUT16_Grad); + Clut16Grad); - public static readonly byte[] CLUT_f32 = ArrayHelper.Concat( + public static readonly byte[] ClutF32 = ArrayHelper.Concat( new byte[16] { 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - CLUTf32_Grad); + CluTf32Grad); public static readonly object[][] ClutTestData = { - new object[] { CLUT_8, CLUT_Val8, 2, 3, false }, - new object[] { CLUT_16, CLUT_Val16, 2, 3, false }, - new object[] { CLUT_f32, CLUT_Valf32, 2, 3, true }, + new object[] { Clut8, ClutVal8, 2, 3, false }, + new object[] { Clut16, ClutVal16, 2, 3, false }, + new object[] { ClutF32, ClutValf32, 2, 3, true }, }; } diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMatrix.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMatrix.cs index 94df8d69a6..1a72d39b19 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMatrix.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMatrix.cs @@ -3,16 +3,14 @@ using System.Numerics; -namespace SixLabors.ImageSharp.Tests; - -using SixLabors.ImageSharp; +namespace SixLabors.ImageSharp.Tests.TestDataIcc; internal static class IccTestDataMatrix { /// /// 3x3 Matrix /// - public static readonly float[,] Single_2DArray_ValGrad = + public static readonly float[,] Single2DArrayValGrad = { { 1, 2, 3 }, { 4, 5, 6 }, @@ -22,7 +20,7 @@ internal static class IccTestDataMatrix /// /// 3x3 Matrix /// - public static readonly float[,] Single_2DArray_ValIdentity = + public static readonly float[,] Single2DArrayValIdentity = { { 1, 0, 0 }, { 0, 1, 0 }, @@ -32,121 +30,121 @@ internal static class IccTestDataMatrix /// /// 3x3 Matrix /// - public static readonly Matrix4x4 Single_Matrix4x4_ValGrad = new Matrix4x4(1, 2, 3, 0, 4, 5, 6, 0, 7, 8, 9, 0, 0, 0, 0, 1); + public static readonly Matrix4x4 SingleMatrix4X4ValGrad = new(1, 2, 3, 0, 4, 5, 6, 0, 7, 8, 9, 0, 0, 0, 0, 1); /// /// 3x3 Matrix /// - public static readonly Matrix4x4 Single_Matrix4x4_ValIdentity = Matrix4x4.Identity; + public static readonly Matrix4x4 SingleMatrix4X4ValIdentity = Matrix4x4.Identity; /// /// 3x3 Matrix /// - public static readonly DenseMatrix Single_DenseMatrix_ValGrad = new DenseMatrix(Single_2DArray_ValGrad); + public static readonly DenseMatrix SingleDenseMatrixValGrad = new(Single2DArrayValGrad); /// /// 3x3 Matrix /// - public static readonly DenseMatrix Single_DenseMatrix_ValIdentity = new DenseMatrix(Single_2DArray_ValIdentity); + public static readonly DenseMatrix SingleDenseMatrixValIdentity = new(Single2DArrayValIdentity); /// /// 3x3 Matrix /// - public static readonly byte[] Fix16_2D_Grad = ArrayHelper.Concat( - IccTestDataPrimitives.Fix16_1, - IccTestDataPrimitives.Fix16_4, - IccTestDataPrimitives.Fix16_7, - IccTestDataPrimitives.Fix16_2, - IccTestDataPrimitives.Fix16_5, - IccTestDataPrimitives.Fix16_8, - IccTestDataPrimitives.Fix16_3, - IccTestDataPrimitives.Fix16_6, - IccTestDataPrimitives.Fix16_9); + public static readonly byte[] Fix162DGrad = ArrayHelper.Concat( + IccTestDataPrimitives.Fix161, + IccTestDataPrimitives.Fix164, + IccTestDataPrimitives.Fix167, + IccTestDataPrimitives.Fix162, + IccTestDataPrimitives.Fix165, + IccTestDataPrimitives.Fix168, + IccTestDataPrimitives.Fix163, + IccTestDataPrimitives.Fix166, + IccTestDataPrimitives.Fix169); /// /// 3x3 Matrix /// - public static readonly byte[] Fix16_2D_Identity = ArrayHelper.Concat( - IccTestDataPrimitives.Fix16_1, - IccTestDataPrimitives.Fix16_0, - IccTestDataPrimitives.Fix16_0, - IccTestDataPrimitives.Fix16_0, - IccTestDataPrimitives.Fix16_1, - IccTestDataPrimitives.Fix16_0, - IccTestDataPrimitives.Fix16_0, - IccTestDataPrimitives.Fix16_0, - IccTestDataPrimitives.Fix16_1); + public static readonly byte[] Fix162DIdentity = ArrayHelper.Concat( + IccTestDataPrimitives.Fix161, + IccTestDataPrimitives.Fix160, + IccTestDataPrimitives.Fix160, + IccTestDataPrimitives.Fix160, + IccTestDataPrimitives.Fix161, + IccTestDataPrimitives.Fix160, + IccTestDataPrimitives.Fix160, + IccTestDataPrimitives.Fix160, + IccTestDataPrimitives.Fix161); /// /// 3x3 Matrix /// - public static readonly byte[] Single_2D_Grad = ArrayHelper.Concat( - IccTestDataPrimitives.Single_1, - IccTestDataPrimitives.Single_4, - IccTestDataPrimitives.Single_7, - IccTestDataPrimitives.Single_2, - IccTestDataPrimitives.Single_5, - IccTestDataPrimitives.Single_8, - IccTestDataPrimitives.Single_3, - IccTestDataPrimitives.Single_6, - IccTestDataPrimitives.Single_9); - - public static readonly object[][] Matrix2D_FloatArrayTestData = + public static readonly byte[] Single2DGrad = ArrayHelper.Concat( + IccTestDataPrimitives.Single1, + IccTestDataPrimitives.Single4, + IccTestDataPrimitives.Single7, + IccTestDataPrimitives.Single2, + IccTestDataPrimitives.Single5, + IccTestDataPrimitives.Single8, + IccTestDataPrimitives.Single3, + IccTestDataPrimitives.Single6, + IccTestDataPrimitives.Single9); + + public static readonly object[][] Matrix2DFloatArrayTestData = { - new object[] { Fix16_2D_Grad, 3, 3, false, Single_2DArray_ValGrad }, - new object[] { Fix16_2D_Identity, 3, 3, false, Single_2DArray_ValIdentity }, - new object[] { Single_2D_Grad, 3, 3, true, Single_2DArray_ValGrad }, + new object[] { Fix162DGrad, 3, 3, false, Single2DArrayValGrad }, + new object[] { Fix162DIdentity, 3, 3, false, Single2DArrayValIdentity }, + new object[] { Single2DGrad, 3, 3, true, Single2DArrayValGrad }, }; - public static readonly object[][] Matrix2D_DenseMatrixTestData = + public static readonly object[][] Matrix2DDenseMatrixTestData = { - new object[] { Fix16_2D_Grad, 3, 3, false, Single_DenseMatrix_ValGrad }, - new object[] { Fix16_2D_Identity, 3, 3, false, Single_DenseMatrix_ValIdentity }, - new object[] { Single_2D_Grad, 3, 3, true, Single_DenseMatrix_ValGrad }, + new object[] { Fix162DGrad, 3, 3, false, SingleDenseMatrixValGrad }, + new object[] { Fix162DIdentity, 3, 3, false, SingleDenseMatrixValIdentity }, + new object[] { Single2DGrad, 3, 3, true, SingleDenseMatrixValGrad }, }; - public static readonly object[][] Matrix2D_Matrix4x4TestData = + public static readonly object[][] Matrix2DMatrix4X4TestData = { - new object[] { Fix16_2D_Grad, 3, 3, false, Single_Matrix4x4_ValGrad }, - new object[] { Fix16_2D_Identity, 3, 3, false, Single_Matrix4x4_ValIdentity }, - new object[] { Single_2D_Grad, 3, 3, true, Single_Matrix4x4_ValGrad }, + new object[] { Fix162DGrad, 3, 3, false, SingleMatrix4X4ValGrad }, + new object[] { Fix162DIdentity, 3, 3, false, SingleMatrix4X4ValIdentity }, + new object[] { Single2DGrad, 3, 3, true, SingleMatrix4X4ValGrad }, }; /// /// 3x1 Matrix /// - public static readonly float[] Single_1DArray_ValGrad = { 1, 4, 7 }; + public static readonly float[] Single1DArrayValGrad = { 1, 4, 7 }; /// /// 3x1 Matrix /// - public static readonly Vector3 Single_Vector3_ValGrad = new Vector3(1, 4, 7); + public static readonly Vector3 SingleVector3ValGrad = new(1, 4, 7); /// /// 3x1 Matrix /// - public static readonly byte[] Fix16_1D_Grad = ArrayHelper.Concat( - IccTestDataPrimitives.Fix16_1, - IccTestDataPrimitives.Fix16_4, - IccTestDataPrimitives.Fix16_7); + public static readonly byte[] Fix161DGrad = ArrayHelper.Concat( + IccTestDataPrimitives.Fix161, + IccTestDataPrimitives.Fix164, + IccTestDataPrimitives.Fix167); /// /// 3x1 Matrix /// - public static readonly byte[] Single_1D_Grad = ArrayHelper.Concat( - IccTestDataPrimitives.Single_1, - IccTestDataPrimitives.Single_4, - IccTestDataPrimitives.Single_7); + public static readonly byte[] Single1DGrad = ArrayHelper.Concat( + IccTestDataPrimitives.Single1, + IccTestDataPrimitives.Single4, + IccTestDataPrimitives.Single7); - public static readonly object[][] Matrix1D_ArrayTestData = + public static readonly object[][] Matrix1DArrayTestData = { - new object[] { Fix16_1D_Grad, 3, false, Single_1DArray_ValGrad }, - new object[] { Single_1D_Grad, 3, true, Single_1DArray_ValGrad }, + new object[] { Fix161DGrad, 3, false, Single1DArrayValGrad }, + new object[] { Single1DGrad, 3, true, Single1DArrayValGrad }, }; - public static readonly object[][] Matrix1D_Vector3TestData = + public static readonly object[][] Matrix1DVector3TestData = { - new object[] { Fix16_1D_Grad, 3, false, Single_Vector3_ValGrad }, - new object[] { Single_1D_Grad, 3, true, Single_Vector3_ValGrad }, + new object[] { Fix161DGrad, 3, false, SingleVector3ValGrad }, + new object[] { Single1DGrad, 3, true, SingleVector3ValGrad }, }; } diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMultiProcessElements.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMultiProcessElements.cs index 2c5c432710..2e3679e3af 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMultiProcessElements.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataMultiProcessElements.cs @@ -3,7 +3,7 @@ using SixLabors.ImageSharp.Metadata.Profiles.Icc; -namespace SixLabors.ImageSharp.Tests; +namespace SixLabors.ImageSharp.Tests.TestDataIcc; internal static class IccTestDataMultiProcessElements { @@ -11,99 +11,99 @@ internal static class IccTestDataMultiProcessElements /// Input Channel Count: 3 /// Output Channel Count: 3 /// - public static readonly IccCurveSetProcessElement CurvePE_ValGrad = new IccCurveSetProcessElement(new IccOneDimensionalCurve[] + public static readonly IccCurveSetProcessElement CurvePeValGrad = new(new[] { - IccTestDataCurves.OneDimensional_ValFormula1, - IccTestDataCurves.OneDimensional_ValFormula2, - IccTestDataCurves.OneDimensional_ValFormula1 + IccTestDataCurves.OneDimensionalValFormula1, + IccTestDataCurves.OneDimensionalValFormula2, + IccTestDataCurves.OneDimensionalValFormula1 }); /// /// Input Channel Count: 3 /// Output Channel Count: 3 /// - public static readonly byte[] CurvePE_Grad = ArrayHelper.Concat( - IccTestDataCurves.OneDimensional_Formula1, - IccTestDataCurves.OneDimensional_Formula2, - IccTestDataCurves.OneDimensional_Formula1); + public static readonly byte[] CurvePeGrad = ArrayHelper.Concat( + IccTestDataCurves.OneDimensionalFormula1, + IccTestDataCurves.OneDimensionalFormula2, + IccTestDataCurves.OneDimensionalFormula1); public static readonly object[][] CurveSetTestData = { - new object[] { CurvePE_Grad, CurvePE_ValGrad, 3, 3 }, + new object[] { CurvePeGrad, CurvePeValGrad, 3, 3 }, }; /// /// Input Channel Count: 3 /// Output Channel Count: 3 /// - public static readonly IccMatrixProcessElement MatrixPE_ValGrad = new IccMatrixProcessElement( - IccTestDataMatrix.Single_2DArray_ValGrad, - IccTestDataMatrix.Single_1DArray_ValGrad); + public static readonly IccMatrixProcessElement MatrixPeValGrad = new( + IccTestDataMatrix.Single2DArrayValGrad, + IccTestDataMatrix.Single1DArrayValGrad); /// /// Input Channel Count: 3 /// Output Channel Count: 3 /// - public static readonly byte[] MatrixPE_Grad = ArrayHelper.Concat( - IccTestDataMatrix.Single_2D_Grad, - IccTestDataMatrix.Single_1D_Grad); + public static readonly byte[] MatrixPeGrad = ArrayHelper.Concat( + IccTestDataMatrix.Single2DGrad, + IccTestDataMatrix.Single1DGrad); public static readonly object[][] MatrixTestData = { - new object[] { MatrixPE_Grad, MatrixPE_ValGrad, 3, 3 }, + new object[] { MatrixPeGrad, MatrixPeValGrad, 3, 3 }, }; /// /// Input Channel Count: 2 /// Output Channel Count: 3 /// - public static readonly IccClutProcessElement CLUTPE_ValGrad = new IccClutProcessElement(IccTestDataLut.CLUT_Valf32); + public static readonly IccClutProcessElement ClutpeValGrad = new(IccTestDataLut.ClutValf32); /// /// Input Channel Count: 2 /// Output Channel Count: 3 /// - public static readonly byte[] CLUTPE_Grad = IccTestDataLut.CLUT_f32; + public static readonly byte[] ClutpeGrad = IccTestDataLut.ClutF32; public static readonly object[][] ClutTestData = { - new object[] { CLUTPE_Grad, CLUTPE_ValGrad, 2, 3 }, + new object[] { ClutpeGrad, ClutpeValGrad, 2, 3 }, }; - public static readonly IccMultiProcessElement MPE_ValMatrix = MatrixPE_ValGrad; - public static readonly IccMultiProcessElement MPE_ValCLUT = CLUTPE_ValGrad; - public static readonly IccMultiProcessElement MPE_ValCurve = CurvePE_ValGrad; - public static readonly IccMultiProcessElement MPE_ValbACS = new IccBAcsProcessElement(3, 3); - public static readonly IccMultiProcessElement MPE_ValeACS = new IccEAcsProcessElement(3, 3); + public static readonly IccMultiProcessElement MpeValMatrix = MatrixPeValGrad; + public static readonly IccMultiProcessElement MpeValClut = ClutpeValGrad; + public static readonly IccMultiProcessElement MpeValCurve = CurvePeValGrad; + public static readonly IccMultiProcessElement MpeValbAcs = new IccBAcsProcessElement(3, 3); + public static readonly IccMultiProcessElement MpeValeAcs = new IccEAcsProcessElement(3, 3); - public static readonly byte[] MPE_Matrix = ArrayHelper.Concat( + public static readonly byte[] MpeMatrix = ArrayHelper.Concat( new byte[] { 0x6D, 0x61, 0x74, 0x66, 0x00, 0x03, 0x00, 0x03, }, - MatrixPE_Grad); + MatrixPeGrad); - public static readonly byte[] MPE_CLUT = ArrayHelper.Concat( + public static readonly byte[] MpeClut = ArrayHelper.Concat( new byte[] { 0x63, 0x6C, 0x75, 0x74, 0x00, 0x02, 0x00, 0x03, }, - CLUTPE_Grad); + ClutpeGrad); - public static readonly byte[] MPE_Curve = ArrayHelper.Concat( + public static readonly byte[] MpeCurve = ArrayHelper.Concat( new byte[] { 0x6D, 0x66, 0x6C, 0x74, 0x00, 0x03, 0x00, 0x03, }, - CurvePE_Grad); + CurvePeGrad); - public static readonly byte[] MPE_bACS = + public static readonly byte[] MpeBAcs = { 0x62, 0x41, 0x43, 0x53, 0x00, 0x03, @@ -111,7 +111,7 @@ internal static class IccTestDataMultiProcessElements 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; - public static readonly byte[] MPE_eACS = + public static readonly byte[] MpeEAcs = { 0x65, 0x41, 0x43, 0x53, 0x00, 0x03, @@ -121,10 +121,10 @@ internal static class IccTestDataMultiProcessElements public static readonly object[][] MultiProcessElementTestData = { - new object[] { MPE_Matrix, MPE_ValMatrix }, - new object[] { MPE_CLUT, MPE_ValCLUT }, - new object[] { MPE_Curve, MPE_ValCurve }, - new object[] { MPE_bACS, MPE_ValbACS }, - new object[] { MPE_eACS, MPE_ValeACS }, + new object[] { MpeMatrix, MpeValMatrix }, + new object[] { MpeClut, MpeValClut }, + new object[] { MpeCurve, MpeValCurve }, + new object[] { MpeBAcs, MpeValbAcs }, + new object[] { MpeEAcs, MpeValeAcs }, }; } diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataNonPrimitives.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataNonPrimitives.cs index c476f2e6c7..0674274246 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataNonPrimitives.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataNonPrimitives.cs @@ -5,15 +5,15 @@ using System.Globalization; using System.Numerics; using SixLabors.ImageSharp.Metadata.Profiles.Icc; -namespace SixLabors.ImageSharp.Tests; +namespace SixLabors.ImageSharp.Tests.TestDataIcc; internal static class IccTestDataNonPrimitives { - public static readonly DateTime DateTime_ValMin = new DateTime(1, 1, 1, 0, 0, 0, DateTimeKind.Utc); - public static readonly DateTime DateTime_ValMax = new DateTime(9999, 12, 31, 23, 59, 59, DateTimeKind.Utc); - public static readonly DateTime DateTime_ValRand1 = new DateTime(1990, 11, 26, 3, 19, 47, DateTimeKind.Utc); + public static readonly DateTime DateTimeValMin = new(1, 1, 1, 0, 0, 0, DateTimeKind.Utc); + public static readonly DateTime DateTimeValMax = new(9999, 12, 31, 23, 59, 59, DateTimeKind.Utc); + public static readonly DateTime DateTimeValRand1 = new(1990, 11, 26, 3, 19, 47, DateTimeKind.Utc); - public static readonly byte[] DateTime_Min = + public static readonly byte[] DateTimeMin = { 0x00, 0x01, // Year 1 0x00, 0x01, // Month 1 @@ -23,7 +23,7 @@ internal static class IccTestDataNonPrimitives 0x00, 0x00, // Second 0 }; - public static readonly byte[] DateTime_Max = + public static readonly byte[] DateTimeMax = { 0x27, 0x0F, // Year 9999 0x00, 0x0C, // Month 12 @@ -33,7 +33,7 @@ internal static class IccTestDataNonPrimitives 0x00, 0x3B, // Second 59 }; - public static readonly byte[] DateTime_Invalid = + public static readonly byte[] DateTimeInvalid = { 0xFF, 0xFF, // Year 65535 0x00, 0x0E, // Month 14 @@ -43,7 +43,7 @@ internal static class IccTestDataNonPrimitives 0x00, 0x3D, // Second 61 }; - public static readonly byte[] DateTime_Rand1 = + public static readonly byte[] DateTimeRand1 = { 0x07, 0xC6, // Year 1990 0x00, 0x0B, // Month 11 @@ -55,135 +55,135 @@ internal static class IccTestDataNonPrimitives public static readonly object[][] DateTimeTestData = { - new object[] { DateTime_Min, DateTime_ValMin }, - new object[] { DateTime_Max, DateTime_ValMax }, - new object[] { DateTime_Rand1, DateTime_ValRand1 }, + new object[] { DateTimeMin, DateTimeValMin }, + new object[] { DateTimeMax, DateTimeValMax }, + new object[] { DateTimeRand1, DateTimeValRand1 }, }; - public static readonly IccVersion VersionNumber_ValMin = new IccVersion(0, 0, 0); - public static readonly IccVersion VersionNumber_Val211 = new IccVersion(2, 1, 1); - public static readonly IccVersion VersionNumber_Val430 = new IccVersion(4, 3, 0); - public static readonly IccVersion VersionNumber_ValMax = new IccVersion(255, 15, 15); + public static readonly IccVersion VersionNumberValMin = new(0, 0, 0); + public static readonly IccVersion VersionNumberVal211 = new(2, 1, 1); + public static readonly IccVersion VersionNumberVal430 = new(4, 3, 0); + public static readonly IccVersion VersionNumberValMax = new(255, 15, 15); - public static readonly byte[] VersionNumber_Min = { 0x00, 0x00, 0x00, 0x00 }; - public static readonly byte[] VersionNumber_211 = { 0x02, 0x11, 0x00, 0x00 }; - public static readonly byte[] VersionNumber_430 = { 0x04, 0x30, 0x00, 0x00 }; - public static readonly byte[] VersionNumber_Max = { 0xFF, 0xFF, 0x00, 0x00 }; + public static readonly byte[] VersionNumberMin = { 0x00, 0x00, 0x00, 0x00 }; + public static readonly byte[] VersionNumber211 = { 0x02, 0x11, 0x00, 0x00 }; + public static readonly byte[] VersionNumber430 = { 0x04, 0x30, 0x00, 0x00 }; + public static readonly byte[] VersionNumberMax = { 0xFF, 0xFF, 0x00, 0x00 }; public static readonly object[][] VersionNumberTestData = { - new object[] { VersionNumber_Min, VersionNumber_ValMin }, - new object[] { VersionNumber_211, VersionNumber_Val211 }, - new object[] { VersionNumber_430, VersionNumber_Val430 }, - new object[] { VersionNumber_Max, VersionNumber_ValMax }, + new object[] { VersionNumberMin, VersionNumberValMin }, + new object[] { VersionNumber211, VersionNumberVal211 }, + new object[] { VersionNumber430, VersionNumberVal430 }, + new object[] { VersionNumberMax, VersionNumberValMax }, }; - public static readonly Vector3 XyzNumber_ValMin = new Vector3(IccTestDataPrimitives.Fix16_ValMin, IccTestDataPrimitives.Fix16_ValMin, IccTestDataPrimitives.Fix16_ValMin); - public static readonly Vector3 XyzNumber_Val0 = new Vector3(0, 0, 0); - public static readonly Vector3 XyzNumber_Val1 = new Vector3(1, 1, 1); - public static readonly Vector3 XyzNumber_ValVar1 = new Vector3(1, 2, 3); - public static readonly Vector3 XyzNumber_ValVar2 = new Vector3(4, 5, 6); - public static readonly Vector3 XyzNumber_ValVar3 = new Vector3(7, 8, 9); - public static readonly Vector3 XyzNumber_ValMax = new Vector3(IccTestDataPrimitives.Fix16_ValMax, IccTestDataPrimitives.Fix16_ValMax, IccTestDataPrimitives.Fix16_ValMax); - - public static readonly byte[] XyzNumber_Min = ArrayHelper.Concat(IccTestDataPrimitives.Fix16_Min, IccTestDataPrimitives.Fix16_Min, IccTestDataPrimitives.Fix16_Min); - public static readonly byte[] XyzNumber_0 = ArrayHelper.Concat(IccTestDataPrimitives.Fix16_0, IccTestDataPrimitives.Fix16_0, IccTestDataPrimitives.Fix16_0); - public static readonly byte[] XyzNumber_1 = ArrayHelper.Concat(IccTestDataPrimitives.Fix16_1, IccTestDataPrimitives.Fix16_1, IccTestDataPrimitives.Fix16_1); - public static readonly byte[] XyzNumber_Var1 = ArrayHelper.Concat(IccTestDataPrimitives.Fix16_1, IccTestDataPrimitives.Fix16_2, IccTestDataPrimitives.Fix16_3); - public static readonly byte[] XyzNumber_Var2 = ArrayHelper.Concat(IccTestDataPrimitives.Fix16_4, IccTestDataPrimitives.Fix16_5, IccTestDataPrimitives.Fix16_6); - public static readonly byte[] XyzNumber_Var3 = ArrayHelper.Concat(IccTestDataPrimitives.Fix16_7, IccTestDataPrimitives.Fix16_8, IccTestDataPrimitives.Fix16_9); - public static readonly byte[] XyzNumber_Max = ArrayHelper.Concat(IccTestDataPrimitives.Fix16_Max, IccTestDataPrimitives.Fix16_Max, IccTestDataPrimitives.Fix16_Max); + public static readonly Vector3 XyzNumberValMin = new(IccTestDataPrimitives.Fix16ValMin, IccTestDataPrimitives.Fix16ValMin, IccTestDataPrimitives.Fix16ValMin); + public static readonly Vector3 XyzNumberVal0 = new(0, 0, 0); + public static readonly Vector3 XyzNumberVal1 = new(1, 1, 1); + public static readonly Vector3 XyzNumberValVar1 = new(1, 2, 3); + public static readonly Vector3 XyzNumberValVar2 = new(4, 5, 6); + public static readonly Vector3 XyzNumberValVar3 = new(7, 8, 9); + public static readonly Vector3 XyzNumberValMax = new(IccTestDataPrimitives.Fix16ValMax, IccTestDataPrimitives.Fix16ValMax, IccTestDataPrimitives.Fix16ValMax); + + public static readonly byte[] XyzNumberMin = ArrayHelper.Concat(IccTestDataPrimitives.Fix16Min, IccTestDataPrimitives.Fix16Min, IccTestDataPrimitives.Fix16Min); + public static readonly byte[] XyzNumber0 = ArrayHelper.Concat(IccTestDataPrimitives.Fix160, IccTestDataPrimitives.Fix160, IccTestDataPrimitives.Fix160); + public static readonly byte[] XyzNumber1 = ArrayHelper.Concat(IccTestDataPrimitives.Fix161, IccTestDataPrimitives.Fix161, IccTestDataPrimitives.Fix161); + public static readonly byte[] XyzNumberVar1 = ArrayHelper.Concat(IccTestDataPrimitives.Fix161, IccTestDataPrimitives.Fix162, IccTestDataPrimitives.Fix163); + public static readonly byte[] XyzNumberVar2 = ArrayHelper.Concat(IccTestDataPrimitives.Fix164, IccTestDataPrimitives.Fix165, IccTestDataPrimitives.Fix166); + public static readonly byte[] XyzNumberVar3 = ArrayHelper.Concat(IccTestDataPrimitives.Fix167, IccTestDataPrimitives.Fix168, IccTestDataPrimitives.Fix169); + public static readonly byte[] XyzNumberMax = ArrayHelper.Concat(IccTestDataPrimitives.Fix16Max, IccTestDataPrimitives.Fix16Max, IccTestDataPrimitives.Fix16Max); public static readonly object[][] XyzNumberTestData = { - new object[] { XyzNumber_Min, XyzNumber_ValMin }, - new object[] { XyzNumber_0, XyzNumber_Val0 }, - new object[] { XyzNumber_Var1, XyzNumber_ValVar1 }, - new object[] { XyzNumber_Max, XyzNumber_ValMax }, + new object[] { XyzNumberMin, XyzNumberValMin }, + new object[] { XyzNumber0, XyzNumberVal0 }, + new object[] { XyzNumberVar1, XyzNumberValVar1 }, + new object[] { XyzNumberMax, XyzNumberValMax }, }; - public static readonly IccProfileId ProfileId_ValMin = new IccProfileId(0, 0, 0, 0); - public static readonly IccProfileId ProfileId_ValRand = new IccProfileId(IccTestDataPrimitives.UInt32_ValRand1, IccTestDataPrimitives.UInt32_ValRand2, IccTestDataPrimitives.UInt32_ValRand3, IccTestDataPrimitives.UInt32_ValRand4); - public static readonly IccProfileId ProfileId_ValMax = new IccProfileId(uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue); + public static readonly IccProfileId ProfileIdValMin = new(0, 0, 0, 0); + public static readonly IccProfileId ProfileIdValRand = new(IccTestDataPrimitives.UInt32ValRand1, IccTestDataPrimitives.UInt32ValRand2, IccTestDataPrimitives.UInt32ValRand3, IccTestDataPrimitives.UInt32ValRand4); + public static readonly IccProfileId ProfileIdValMax = new(uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue); - public static readonly byte[] ProfileId_Min = ArrayHelper.Concat(IccTestDataPrimitives.UInt32_0, IccTestDataPrimitives.UInt32_0, IccTestDataPrimitives.UInt32_0, IccTestDataPrimitives.UInt32_0); - public static readonly byte[] ProfileId_Rand = ArrayHelper.Concat(IccTestDataPrimitives.UInt32_Rand1, IccTestDataPrimitives.UInt32_Rand2, IccTestDataPrimitives.UInt32_Rand3, IccTestDataPrimitives.UInt32_Rand4); - public static readonly byte[] ProfileId_Max = ArrayHelper.Concat(IccTestDataPrimitives.UInt32_Max, IccTestDataPrimitives.UInt32_Max, IccTestDataPrimitives.UInt32_Max, IccTestDataPrimitives.UInt32_Max); + public static readonly byte[] ProfileIdMin = ArrayHelper.Concat(IccTestDataPrimitives.UInt320, IccTestDataPrimitives.UInt320, IccTestDataPrimitives.UInt320, IccTestDataPrimitives.UInt320); + public static readonly byte[] ProfileIdRand = ArrayHelper.Concat(IccTestDataPrimitives.UInt32Rand1, IccTestDataPrimitives.UInt32Rand2, IccTestDataPrimitives.UInt32Rand3, IccTestDataPrimitives.UInt32Rand4); + public static readonly byte[] ProfileIdMax = ArrayHelper.Concat(IccTestDataPrimitives.UInt32Max, IccTestDataPrimitives.UInt32Max, IccTestDataPrimitives.UInt32Max, IccTestDataPrimitives.UInt32Max); public static readonly object[][] ProfileIdTestData = { - new object[] { ProfileId_Min, ProfileId_ValMin }, - new object[] { ProfileId_Rand, ProfileId_ValRand }, - new object[] { ProfileId_Max, ProfileId_ValMax }, + new object[] { ProfileIdMin, ProfileIdValMin }, + new object[] { ProfileIdRand, ProfileIdValRand }, + new object[] { ProfileIdMax, ProfileIdValMax }, }; - public static readonly IccPositionNumber PositionNumber_ValMin = new IccPositionNumber(0, 0); - public static readonly IccPositionNumber PositionNumber_ValRand = new IccPositionNumber(IccTestDataPrimitives.UInt32_ValRand1, IccTestDataPrimitives.UInt32_ValRand2); - public static readonly IccPositionNumber PositionNumber_ValMax = new IccPositionNumber(uint.MaxValue, uint.MaxValue); + public static readonly IccPositionNumber PositionNumberValMin = new(0, 0); + public static readonly IccPositionNumber PositionNumberValRand = new(IccTestDataPrimitives.UInt32ValRand1, IccTestDataPrimitives.UInt32ValRand2); + public static readonly IccPositionNumber PositionNumberValMax = new(uint.MaxValue, uint.MaxValue); - public static readonly byte[] PositionNumber_Min = ArrayHelper.Concat(IccTestDataPrimitives.UInt32_0, IccTestDataPrimitives.UInt32_0); - public static readonly byte[] PositionNumber_Rand = ArrayHelper.Concat(IccTestDataPrimitives.UInt32_Rand1, IccTestDataPrimitives.UInt32_Rand2); - public static readonly byte[] PositionNumber_Max = ArrayHelper.Concat(IccTestDataPrimitives.UInt32_Max, IccTestDataPrimitives.UInt32_Max); + public static readonly byte[] PositionNumberMin = ArrayHelper.Concat(IccTestDataPrimitives.UInt320, IccTestDataPrimitives.UInt320); + public static readonly byte[] PositionNumberRand = ArrayHelper.Concat(IccTestDataPrimitives.UInt32Rand1, IccTestDataPrimitives.UInt32Rand2); + public static readonly byte[] PositionNumberMax = ArrayHelper.Concat(IccTestDataPrimitives.UInt32Max, IccTestDataPrimitives.UInt32Max); public static readonly object[][] PositionNumberTestData = { - new object[] { PositionNumber_Min, PositionNumber_ValMin }, - new object[] { PositionNumber_Rand, PositionNumber_ValRand }, - new object[] { PositionNumber_Max, PositionNumber_ValMax }, + new object[] { PositionNumberMin, PositionNumberValMin }, + new object[] { PositionNumberRand, PositionNumberValRand }, + new object[] { PositionNumberMax, PositionNumberValMax }, }; - public static readonly IccResponseNumber ResponseNumber_ValMin = new IccResponseNumber(0, IccTestDataPrimitives.Fix16_ValMin); - public static readonly IccResponseNumber ResponseNumber_Val1 = new IccResponseNumber(1, 1); - public static readonly IccResponseNumber ResponseNumber_Val2 = new IccResponseNumber(2, 2); - public static readonly IccResponseNumber ResponseNumber_Val3 = new IccResponseNumber(3, 3); - public static readonly IccResponseNumber ResponseNumber_Val4 = new IccResponseNumber(4, 4); - public static readonly IccResponseNumber ResponseNumber_Val5 = new IccResponseNumber(5, 5); - public static readonly IccResponseNumber ResponseNumber_Val6 = new IccResponseNumber(6, 6); - public static readonly IccResponseNumber ResponseNumber_Val7 = new IccResponseNumber(7, 7); - public static readonly IccResponseNumber ResponseNumber_Val8 = new IccResponseNumber(8, 8); - public static readonly IccResponseNumber ResponseNumber_Val9 = new IccResponseNumber(9, 9); - public static readonly IccResponseNumber ResponseNumber_ValMax = new IccResponseNumber(ushort.MaxValue, IccTestDataPrimitives.Fix16_ValMax); - - public static readonly byte[] ResponseNumber_Min = ArrayHelper.Concat(IccTestDataPrimitives.UInt16_0, IccTestDataPrimitives.Fix16_Min); - public static readonly byte[] ResponseNumber_1 = ArrayHelper.Concat(IccTestDataPrimitives.UInt16_1, IccTestDataPrimitives.Fix16_1); - public static readonly byte[] ResponseNumber_2 = ArrayHelper.Concat(IccTestDataPrimitives.UInt16_2, IccTestDataPrimitives.Fix16_2); - public static readonly byte[] ResponseNumber_3 = ArrayHelper.Concat(IccTestDataPrimitives.UInt16_3, IccTestDataPrimitives.Fix16_3); - public static readonly byte[] ResponseNumber_4 = ArrayHelper.Concat(IccTestDataPrimitives.UInt16_4, IccTestDataPrimitives.Fix16_4); - public static readonly byte[] ResponseNumber_5 = ArrayHelper.Concat(IccTestDataPrimitives.UInt16_5, IccTestDataPrimitives.Fix16_5); - public static readonly byte[] ResponseNumber_6 = ArrayHelper.Concat(IccTestDataPrimitives.UInt16_6, IccTestDataPrimitives.Fix16_6); - public static readonly byte[] ResponseNumber_7 = ArrayHelper.Concat(IccTestDataPrimitives.UInt16_7, IccTestDataPrimitives.Fix16_7); - public static readonly byte[] ResponseNumber_8 = ArrayHelper.Concat(IccTestDataPrimitives.UInt16_8, IccTestDataPrimitives.Fix16_8); - public static readonly byte[] ResponseNumber_9 = ArrayHelper.Concat(IccTestDataPrimitives.UInt16_9, IccTestDataPrimitives.Fix16_9); - public static readonly byte[] ResponseNumber_Max = ArrayHelper.Concat(IccTestDataPrimitives.UInt16_Max, IccTestDataPrimitives.Fix16_Max); + public static readonly IccResponseNumber ResponseNumberValMin = new(0, IccTestDataPrimitives.Fix16ValMin); + public static readonly IccResponseNumber ResponseNumberVal1 = new(1, 1); + public static readonly IccResponseNumber ResponseNumberVal2 = new(2, 2); + public static readonly IccResponseNumber ResponseNumberVal3 = new(3, 3); + public static readonly IccResponseNumber ResponseNumberVal4 = new(4, 4); + public static readonly IccResponseNumber ResponseNumberVal5 = new(5, 5); + public static readonly IccResponseNumber ResponseNumberVal6 = new(6, 6); + public static readonly IccResponseNumber ResponseNumberVal7 = new(7, 7); + public static readonly IccResponseNumber ResponseNumberVal8 = new(8, 8); + public static readonly IccResponseNumber ResponseNumberVal9 = new(9, 9); + public static readonly IccResponseNumber ResponseNumberValMax = new(ushort.MaxValue, IccTestDataPrimitives.Fix16ValMax); + + public static readonly byte[] ResponseNumberMin = ArrayHelper.Concat(IccTestDataPrimitives.UInt160, IccTestDataPrimitives.Fix16Min); + public static readonly byte[] ResponseNumber1 = ArrayHelper.Concat(IccTestDataPrimitives.UInt161, IccTestDataPrimitives.Fix161); + public static readonly byte[] ResponseNumber2 = ArrayHelper.Concat(IccTestDataPrimitives.UInt162, IccTestDataPrimitives.Fix162); + public static readonly byte[] ResponseNumber3 = ArrayHelper.Concat(IccTestDataPrimitives.UInt163, IccTestDataPrimitives.Fix163); + public static readonly byte[] ResponseNumber4 = ArrayHelper.Concat(IccTestDataPrimitives.UInt164, IccTestDataPrimitives.Fix164); + public static readonly byte[] ResponseNumber5 = ArrayHelper.Concat(IccTestDataPrimitives.UInt165, IccTestDataPrimitives.Fix165); + public static readonly byte[] ResponseNumber6 = ArrayHelper.Concat(IccTestDataPrimitives.UInt166, IccTestDataPrimitives.Fix166); + public static readonly byte[] ResponseNumber7 = ArrayHelper.Concat(IccTestDataPrimitives.UInt167, IccTestDataPrimitives.Fix167); + public static readonly byte[] ResponseNumber8 = ArrayHelper.Concat(IccTestDataPrimitives.UInt168, IccTestDataPrimitives.Fix168); + public static readonly byte[] ResponseNumber9 = ArrayHelper.Concat(IccTestDataPrimitives.UInt169, IccTestDataPrimitives.Fix169); + public static readonly byte[] ResponseNumberMax = ArrayHelper.Concat(IccTestDataPrimitives.UInt16Max, IccTestDataPrimitives.Fix16Max); public static readonly object[][] ResponseNumberTestData = { - new object[] { ResponseNumber_Min, ResponseNumber_ValMin }, - new object[] { ResponseNumber_1, ResponseNumber_Val1 }, - new object[] { ResponseNumber_4, ResponseNumber_Val4 }, - new object[] { ResponseNumber_Max, ResponseNumber_ValMax }, + new object[] { ResponseNumberMin, ResponseNumberValMin }, + new object[] { ResponseNumber1, ResponseNumberVal1 }, + new object[] { ResponseNumber4, ResponseNumberVal4 }, + new object[] { ResponseNumberMax, ResponseNumberValMax }, }; - public static readonly IccNamedColor NamedColor_ValMin = new IccNamedColor( + public static readonly IccNamedColor NamedColorValMin = new( ArrayHelper.Fill('A', 31), new ushort[] { 0, 0, 0 }, new ushort[] { 0, 0, 0 }); - public static readonly IccNamedColor NamedColor_ValRand = new IccNamedColor( + public static readonly IccNamedColor NamedColorValRand = new( ArrayHelper.Fill('5', 31), new ushort[] { 10794, 10794, 10794 }, new ushort[] { 17219, 17219, 17219, 17219, 17219 }); - public static readonly IccNamedColor NamedColor_ValMax = new IccNamedColor( + public static readonly IccNamedColor NamedColorValMax = new( ArrayHelper.Fill('4', 31), - new ushort[] { ushort.MaxValue, ushort.MaxValue, ushort.MaxValue }, - new ushort[] { ushort.MaxValue, ushort.MaxValue, ushort.MaxValue, ushort.MaxValue }); + new[] { ushort.MaxValue, ushort.MaxValue, ushort.MaxValue }, + new[] { ushort.MaxValue, ushort.MaxValue, ushort.MaxValue, ushort.MaxValue }); - public static readonly byte[] NamedColor_Min = CreateNamedColor(3, 0x41, 0x00, 0x00); - public static readonly byte[] NamedColor_Rand = CreateNamedColor(5, 0x35, 42, 67); - public static readonly byte[] NamedColor_Max = CreateNamedColor(4, 0x34, 0xFF, 0xFF); + public static readonly byte[] NamedColorMin = CreateNamedColor(3, 0x41, 0x00, 0x00); + public static readonly byte[] NamedColorRand = CreateNamedColor(5, 0x35, 42, 67); + public static readonly byte[] NamedColorMax = CreateNamedColor(4, 0x34, 0xFF, 0xFF); - private static byte[] CreateNamedColor(int devCoordCount, byte name, byte pCS, byte device) + private static byte[] CreateNamedColor(int devCoordCount, byte name, byte pCs, byte device) { byte[] data = new byte[32 + 6 + (devCoordCount * 2)]; for (int i = 0; i < data.Length; i++) @@ -198,7 +198,7 @@ internal static class IccTestDataNonPrimitives } else if (i < 32 + 6) { - data[i] = pCS; // PCS Coordinates + data[i] = pCs; // PCS Coordinates } else { @@ -211,145 +211,144 @@ internal static class IccTestDataNonPrimitives public static readonly object[][] NamedColorTestData = { - new object[] { NamedColor_Min, NamedColor_ValMin, 3u }, - new object[] { NamedColor_Rand, NamedColor_ValRand, 5u }, - new object[] { NamedColor_Max, NamedColor_ValMax, 4u }, + new object[] { NamedColorMin, NamedColorValMin, 3u }, + new object[] { NamedColorRand, NamedColorValRand, 5u }, + new object[] { NamedColorMax, NamedColorValMax, 4u }, }; - private static readonly CultureInfo CultureEnUs = new CultureInfo("en-US"); - private static readonly CultureInfo CultureDeAT = new CultureInfo("de-AT"); + private static readonly CultureInfo CultureEnUs = new("en-US"); + private static readonly CultureInfo CultureDeAt = new("de-AT"); - private static readonly IccLocalizedString LocalizedString_Rand1 = new IccLocalizedString(CultureEnUs, IccTestDataPrimitives.Unicode_ValRand2); - private static readonly IccLocalizedString LocalizedString_Rand2 = new IccLocalizedString(CultureDeAT, IccTestDataPrimitives.Unicode_ValRand3); + private static readonly IccLocalizedString LocalizedStringRand1 = new(CultureEnUs, IccTestDataPrimitives.UnicodeValRand2); + private static readonly IccLocalizedString LocalizedStringRand2 = new(CultureDeAt, IccTestDataPrimitives.UnicodeValRand3); - private static readonly IccLocalizedString[] LocalizedString_RandArr1 = new IccLocalizedString[] - { - LocalizedString_Rand1, - LocalizedString_Rand2, + private static readonly IccLocalizedString[] LocalizedStringRandArr1 = { + LocalizedStringRand1, + LocalizedStringRand2, }; - private static readonly IccMultiLocalizedUnicodeTagDataEntry MultiLocalizedUnicode_Val = new IccMultiLocalizedUnicodeTagDataEntry(LocalizedString_RandArr1); - private static readonly byte[] MultiLocalizedUnicode_Arr = ArrayHelper.Concat( - IccTestDataPrimitives.UInt32_2, + private static readonly IccMultiLocalizedUnicodeTagDataEntry MultiLocalizedUnicodeVal = new(LocalizedStringRandArr1); + private static readonly byte[] MultiLocalizedUnicodeArr = ArrayHelper.Concat( + IccTestDataPrimitives.UInt322, new byte[] { 0x00, 0x00, 0x00, 0x0C }, // 12 - new byte[] { (byte)'e', (byte)'n', (byte)'U', (byte)'S' }, + new[] { (byte)'e', (byte)'n', (byte)'U', (byte)'S' }, new byte[] { 0x00, 0x00, 0x00, 0x0C }, // 12 new byte[] { 0x00, 0x00, 0x00, 0x28 }, // 40 - new byte[] { (byte)'d', (byte)'e', (byte)'A', (byte)'T' }, + new[] { (byte)'d', (byte)'e', (byte)'A', (byte)'T' }, new byte[] { 0x00, 0x00, 0x00, 0x0E }, // 14 new byte[] { 0x00, 0x00, 0x00, 0x34 }, // 52 - IccTestDataPrimitives.Unicode_Rand2, - IccTestDataPrimitives.Unicode_Rand3); + IccTestDataPrimitives.UnicodeRand2, + IccTestDataPrimitives.UnicodeRand3); - public static readonly IccTextDescriptionTagDataEntry TextDescription_Val1 = new IccTextDescriptionTagDataEntry( - IccTestDataPrimitives.Ascii_ValRand, - IccTestDataPrimitives.Unicode_ValRand1, + public static readonly IccTextDescriptionTagDataEntry TextDescriptionVal1 = new( + IccTestDataPrimitives.AsciiValRand, + IccTestDataPrimitives.UnicodeValRand1, ArrayHelper.Fill('A', 66), 1701729619, 2); - public static readonly byte[] TextDescription_Arr1 = ArrayHelper.Concat( + public static readonly byte[] TextDescriptionArr1 = ArrayHelper.Concat( new byte[] { 0x00, 0x00, 0x00, 0x0B }, // 11 - IccTestDataPrimitives.Ascii_Rand, + IccTestDataPrimitives.AsciiRand, new byte[] { 0x00 }, // Null terminator - new byte[] { (byte)'e', (byte)'n', (byte)'U', (byte)'S' }, + new[] { (byte)'e', (byte)'n', (byte)'U', (byte)'S' }, new byte[] { 0x00, 0x00, 0x00, 0x07 }, // 7 - IccTestDataPrimitives.Unicode_Rand2, + IccTestDataPrimitives.UnicodeRand2, new byte[] { 0x00, 0x00 }, // Null terminator new byte[] { 0x00, 0x02, 0x43 }, // 2, 67 ArrayHelper.Fill((byte)0x41, 66), new byte[] { 0x00 }); // Null terminator - public static readonly IccProfileDescription ProfileDescription_ValRand1 = new IccProfileDescription( + public static readonly IccProfileDescription ProfileDescriptionValRand1 = new( 1, 2, IccDeviceAttribute.ChromaBlackWhite | IccDeviceAttribute.ReflectivityMatte, IccProfileTag.ProfileDescription, - MultiLocalizedUnicode_Val.Texts, - MultiLocalizedUnicode_Val.Texts); + MultiLocalizedUnicodeVal.Texts, + MultiLocalizedUnicodeVal.Texts); - public static readonly IccProfileDescription ProfileDescription_ValRand2 = new IccProfileDescription( + public static readonly IccProfileDescription ProfileDescriptionValRand2 = new( 1, 2, IccDeviceAttribute.ChromaBlackWhite | IccDeviceAttribute.ReflectivityMatte, IccProfileTag.ProfileDescription, - new IccLocalizedString[] { LocalizedString_Rand1 }, - new IccLocalizedString[] { LocalizedString_Rand1 }); + new[] { LocalizedStringRand1 }, + new[] { LocalizedStringRand1 }); - public static readonly byte[] ProfileDescription_Rand1 = ArrayHelper.Concat( - IccTestDataPrimitives.UInt32_1, - IccTestDataPrimitives.UInt32_2, + public static readonly byte[] ProfileDescriptionRand1 = ArrayHelper.Concat( + IccTestDataPrimitives.UInt321, + IccTestDataPrimitives.UInt322, new byte[] { 0, 0, 0, 0, 0, 0, 0, 10 }, new byte[] { 0x64, 0x65, 0x73, 0x63 }, new byte[] { 0x6D, 0x6C, 0x75, 0x63 }, new byte[] { 0x00, 0x00, 0x00, 0x00 }, - MultiLocalizedUnicode_Arr, + MultiLocalizedUnicodeArr, new byte[] { 0x6D, 0x6C, 0x75, 0x63 }, new byte[] { 0x00, 0x00, 0x00, 0x00 }, - MultiLocalizedUnicode_Arr); + MultiLocalizedUnicodeArr); - public static readonly byte[] ProfileDescription_Rand2 = ArrayHelper.Concat( - IccTestDataPrimitives.UInt32_1, - IccTestDataPrimitives.UInt32_2, + public static readonly byte[] ProfileDescriptionRand2 = ArrayHelper.Concat( + IccTestDataPrimitives.UInt321, + IccTestDataPrimitives.UInt322, new byte[] { 0, 0, 0, 0, 0, 0, 0, 10 }, new byte[] { 0x64, 0x65, 0x73, 0x63 }, new byte[] { 0x64, 0x65, 0x73, 0x63 }, new byte[] { 0x00, 0x00, 0x00, 0x00 }, - TextDescription_Arr1, + TextDescriptionArr1, new byte[] { 0x64, 0x65, 0x73, 0x63 }, new byte[] { 0x00, 0x00, 0x00, 0x00 }, - TextDescription_Arr1); + TextDescriptionArr1); public static readonly object[][] ProfileDescriptionReadTestData = { - new object[] { ProfileDescription_Rand1, ProfileDescription_ValRand1 }, - new object[] { ProfileDescription_Rand2, ProfileDescription_ValRand2 }, + new object[] { ProfileDescriptionRand1, ProfileDescriptionValRand1 }, + new object[] { ProfileDescriptionRand2, ProfileDescriptionValRand2 }, }; public static readonly object[][] ProfileDescriptionWriteTestData = { - new object[] { ProfileDescription_Rand1, ProfileDescription_ValRand1 }, + new object[] { ProfileDescriptionRand1, ProfileDescriptionValRand1 }, }; - public static readonly IccColorantTableEntry ColorantTableEntry_ValRand1 = new IccColorantTableEntry(ArrayHelper.Fill('A', 31), 1, 2, 3); - public static readonly IccColorantTableEntry ColorantTableEntry_ValRand2 = new IccColorantTableEntry(ArrayHelper.Fill('4', 31), 4, 5, 6); + public static readonly IccColorantTableEntry ColorantTableEntryValRand1 = new(ArrayHelper.Fill('A', 31), 1, 2, 3); + public static readonly IccColorantTableEntry ColorantTableEntryValRand2 = new(ArrayHelper.Fill('4', 31), 4, 5, 6); - public static readonly byte[] ColorantTableEntry_Rand1 = ArrayHelper.Concat( + public static readonly byte[] ColorantTableEntryRand1 = ArrayHelper.Concat( ArrayHelper.Fill((byte)0x41, 31), new byte[1], // null terminator - IccTestDataPrimitives.UInt16_1, - IccTestDataPrimitives.UInt16_2, - IccTestDataPrimitives.UInt16_3); + IccTestDataPrimitives.UInt161, + IccTestDataPrimitives.UInt162, + IccTestDataPrimitives.UInt163); - public static readonly byte[] ColorantTableEntry_Rand2 = ArrayHelper.Concat( + public static readonly byte[] ColorantTableEntryRand2 = ArrayHelper.Concat( ArrayHelper.Fill((byte)0x34, 31), new byte[1], // null terminator - IccTestDataPrimitives.UInt16_4, - IccTestDataPrimitives.UInt16_5, - IccTestDataPrimitives.UInt16_6); + IccTestDataPrimitives.UInt164, + IccTestDataPrimitives.UInt165, + IccTestDataPrimitives.UInt166); public static readonly object[][] ColorantTableEntryTestData = { - new object[] { ColorantTableEntry_Rand1, ColorantTableEntry_ValRand1 }, - new object[] { ColorantTableEntry_Rand2, ColorantTableEntry_ValRand2 }, + new object[] { ColorantTableEntryRand1, ColorantTableEntryValRand1 }, + new object[] { ColorantTableEntryRand2, ColorantTableEntryValRand2 }, }; - public static readonly IccScreeningChannel ScreeningChannel_ValRand1 = new IccScreeningChannel(4, 6, IccScreeningSpotType.Cross); - public static readonly IccScreeningChannel ScreeningChannel_ValRand2 = new IccScreeningChannel(8, 5, IccScreeningSpotType.Diamond); + public static readonly IccScreeningChannel ScreeningChannelValRand1 = new(4, 6, IccScreeningSpotType.Cross); + public static readonly IccScreeningChannel ScreeningChannelValRand2 = new(8, 5, IccScreeningSpotType.Diamond); - public static readonly byte[] ScreeningChannel_Rand1 = ArrayHelper.Concat( - IccTestDataPrimitives.Fix16_4, - IccTestDataPrimitives.Fix16_6, - IccTestDataPrimitives.Int32_7); + public static readonly byte[] ScreeningChannelRand1 = ArrayHelper.Concat( + IccTestDataPrimitives.Fix164, + IccTestDataPrimitives.Fix166, + IccTestDataPrimitives.Int327); - public static readonly byte[] ScreeningChannel_Rand2 = ArrayHelper.Concat( - IccTestDataPrimitives.Fix16_8, - IccTestDataPrimitives.Fix16_5, - IccTestDataPrimitives.Int32_3); + public static readonly byte[] ScreeningChannelRand2 = ArrayHelper.Concat( + IccTestDataPrimitives.Fix168, + IccTestDataPrimitives.Fix165, + IccTestDataPrimitives.Int323); public static readonly object[][] ScreeningChannelTestData = { - new object[] { ScreeningChannel_Rand1, ScreeningChannel_ValRand1 }, - new object[] { ScreeningChannel_Rand2, ScreeningChannel_ValRand2 }, + new object[] { ScreeningChannelRand1, ScreeningChannelValRand1 }, + new object[] { ScreeningChannelRand2, ScreeningChannelValRand2 }, }; } diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataPrimitives.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataPrimitives.cs index f8e8717273..81cfea46fd 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataPrimitives.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataPrimitives.cs @@ -1,242 +1,242 @@ // Copyright (c) Six Labors. // Licensed under the Six Labors Split License. -namespace SixLabors.ImageSharp.Tests; +namespace SixLabors.ImageSharp.Tests.TestDataIcc; internal static class IccTestDataPrimitives { - public static readonly byte[] UInt16_0 = { 0x00, 0x00 }; - public static readonly byte[] UInt16_1 = { 0x00, 0x01 }; - public static readonly byte[] UInt16_2 = { 0x00, 0x02 }; - public static readonly byte[] UInt16_3 = { 0x00, 0x03 }; - public static readonly byte[] UInt16_4 = { 0x00, 0x04 }; - public static readonly byte[] UInt16_5 = { 0x00, 0x05 }; - public static readonly byte[] UInt16_6 = { 0x00, 0x06 }; - public static readonly byte[] UInt16_7 = { 0x00, 0x07 }; - public static readonly byte[] UInt16_8 = { 0x00, 0x08 }; - public static readonly byte[] UInt16_9 = { 0x00, 0x09 }; - public static readonly byte[] UInt16_32768 = { 0x80, 0x00 }; - public static readonly byte[] UInt16_Max = { 0xFF, 0xFF }; - - public static readonly byte[] Int16_Min = { 0x80, 0x00 }; - public static readonly byte[] Int16_0 = { 0x00, 0x00 }; - public static readonly byte[] Int16_1 = { 0x00, 0x01 }; - public static readonly byte[] Int16_2 = { 0x00, 0x02 }; - public static readonly byte[] Int16_3 = { 0x00, 0x03 }; - public static readonly byte[] Int16_4 = { 0x00, 0x04 }; - public static readonly byte[] Int16_5 = { 0x00, 0x05 }; - public static readonly byte[] Int16_6 = { 0x00, 0x06 }; - public static readonly byte[] Int16_7 = { 0x00, 0x07 }; - public static readonly byte[] Int16_8 = { 0x00, 0x08 }; - public static readonly byte[] Int16_9 = { 0x00, 0x09 }; - public static readonly byte[] Int16_Max = { 0x7F, 0xFF }; - - public static readonly byte[] UInt32_0 = { 0x00, 0x00, 0x00, 0x00 }; - public static readonly byte[] UInt32_1 = { 0x00, 0x00, 0x00, 0x01 }; - public static readonly byte[] UInt32_2 = { 0x00, 0x00, 0x00, 0x02 }; - public static readonly byte[] UInt32_3 = { 0x00, 0x00, 0x00, 0x03 }; - public static readonly byte[] UInt32_4 = { 0x00, 0x00, 0x00, 0x04 }; - public static readonly byte[] UInt32_5 = { 0x00, 0x00, 0x00, 0x05 }; - public static readonly byte[] UInt32_6 = { 0x00, 0x00, 0x00, 0x06 }; - public static readonly byte[] UInt32_7 = { 0x00, 0x00, 0x00, 0x07 }; - public static readonly byte[] UInt32_8 = { 0x00, 0x00, 0x00, 0x08 }; - public static readonly byte[] UInt32_9 = { 0x00, 0x00, 0x00, 0x09 }; - public static readonly byte[] UInt32_Max = { 0xFF, 0xFF, 0xFF, 0xFF }; - - public static readonly uint UInt32_ValRand1 = 1749014123; - public static readonly uint UInt32_ValRand2 = 3870560989; - public static readonly uint UInt32_ValRand3 = 1050090334; - public static readonly uint UInt32_ValRand4 = 3550252874; - - public static readonly byte[] UInt32_Rand1 = { 0x68, 0x3F, 0xD6, 0x6B }; - public static readonly byte[] UInt32_Rand2 = { 0xE6, 0xB4, 0x12, 0xDD }; - public static readonly byte[] UInt32_Rand3 = { 0x3E, 0x97, 0x1B, 0x5E }; - public static readonly byte[] UInt32_Rand4 = { 0xD3, 0x9C, 0x8F, 0x4A }; - - public static readonly byte[] Int32_Min = { 0x80, 0x00, 0x00, 0x00 }; - public static readonly byte[] Int32_0 = { 0x00, 0x00, 0x00, 0x00 }; - public static readonly byte[] Int32_1 = { 0x00, 0x00, 0x00, 0x01 }; - public static readonly byte[] Int32_2 = { 0x00, 0x00, 0x00, 0x02 }; - public static readonly byte[] Int32_3 = { 0x00, 0x00, 0x00, 0x03 }; - public static readonly byte[] Int32_4 = { 0x00, 0x00, 0x00, 0x04 }; - public static readonly byte[] Int32_5 = { 0x00, 0x00, 0x00, 0x05 }; - public static readonly byte[] Int32_6 = { 0x00, 0x00, 0x00, 0x06 }; - public static readonly byte[] Int32_7 = { 0x00, 0x00, 0x00, 0x07 }; - public static readonly byte[] Int32_8 = { 0x00, 0x00, 0x00, 0x08 }; - public static readonly byte[] Int32_9 = { 0x00, 0x00, 0x00, 0x09 }; - public static readonly byte[] Int32_Max = { 0x7F, 0xFF, 0xFF, 0xFF }; - - public static readonly byte[] UInt64_0 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - public static readonly byte[] UInt64_1 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; - public static readonly byte[] UInt64_2 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }; - public static readonly byte[] UInt64_3 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03 }; - public static readonly byte[] UInt64_4 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04 }; - public static readonly byte[] UInt64_5 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05 }; - public static readonly byte[] UInt64_6 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06 }; - public static readonly byte[] UInt64_7 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07 }; - public static readonly byte[] UInt64_8 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08 }; - public static readonly byte[] UInt64_9 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09 }; - public static readonly byte[] UInt64_Max = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; - - public static readonly byte[] Int64_Min = { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - public static readonly byte[] Int64_0 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - public static readonly byte[] Int64_1 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; - public static readonly byte[] Int64_2 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }; - public static readonly byte[] Int64_3 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03 }; - public static readonly byte[] Int64_4 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04 }; - public static readonly byte[] Int64_5 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05 }; - public static readonly byte[] Int64_6 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06 }; - public static readonly byte[] Int64_7 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07 }; - public static readonly byte[] Int64_8 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08 }; - public static readonly byte[] Int64_9 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09 }; - public static readonly byte[] Int64_Max = { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; - - public static readonly byte[] Single_Min = { 0xFF, 0x7F, 0xFF, 0xFF }; - public static readonly byte[] Single_0 = { 0x00, 0x00, 0x00, 0x00 }; - public static readonly byte[] Single_1 = { 0x3F, 0x80, 0x00, 0x00 }; - public static readonly byte[] Single_2 = { 0x40, 0x00, 0x00, 0x00 }; - public static readonly byte[] Single_3 = { 0x40, 0x40, 0x00, 0x00 }; - public static readonly byte[] Single_4 = { 0x40, 0x80, 0x00, 0x00 }; - public static readonly byte[] Single_5 = { 0x40, 0xA0, 0x00, 0x00 }; - public static readonly byte[] Single_6 = { 0x40, 0xC0, 0x00, 0x00 }; - public static readonly byte[] Single_7 = { 0x40, 0xE0, 0x00, 0x00 }; - public static readonly byte[] Single_8 = { 0x41, 0x00, 0x00, 0x00 }; - public static readonly byte[] Single_9 = { 0x41, 0x10, 0x00, 0x00 }; - public static readonly byte[] Single_Max = { 0x7F, 0x7F, 0xFF, 0xFF }; - - public static readonly byte[] Double_Min = { 0xFF, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; - public static readonly byte[] Double_0 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - public static readonly byte[] Double_1 = { 0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - public static readonly byte[] Double_Max = { 0x7F, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; - - public const float Fix16_ValMin = short.MinValue; - public const float Fix16_ValMax = short.MaxValue + (65535f / 65536f); - - public static readonly byte[] Fix16_Min = { 0x80, 0x00, 0x00, 0x00 }; - public static readonly byte[] Fix16_0 = { 0x00, 0x00, 0x00, 0x00 }; - public static readonly byte[] Fix16_1 = { 0x00, 0x01, 0x00, 0x00 }; - public static readonly byte[] Fix16_2 = { 0x00, 0x02, 0x00, 0x00 }; - public static readonly byte[] Fix16_3 = { 0x00, 0x03, 0x00, 0x00 }; - public static readonly byte[] Fix16_4 = { 0x00, 0x04, 0x00, 0x00 }; - public static readonly byte[] Fix16_5 = { 0x00, 0x05, 0x00, 0x00 }; - public static readonly byte[] Fix16_6 = { 0x00, 0x06, 0x00, 0x00 }; - public static readonly byte[] Fix16_7 = { 0x00, 0x07, 0x00, 0x00 }; - public static readonly byte[] Fix16_8 = { 0x00, 0x08, 0x00, 0x00 }; - public static readonly byte[] Fix16_9 = { 0x00, 0x09, 0x00, 0x00 }; - public static readonly byte[] Fix16_Max = { 0x7F, 0xFF, 0xFF, 0xFF }; + public static readonly byte[] UInt160 = { 0x00, 0x00 }; + public static readonly byte[] UInt161 = { 0x00, 0x01 }; + public static readonly byte[] UInt162 = { 0x00, 0x02 }; + public static readonly byte[] UInt163 = { 0x00, 0x03 }; + public static readonly byte[] UInt164 = { 0x00, 0x04 }; + public static readonly byte[] UInt165 = { 0x00, 0x05 }; + public static readonly byte[] UInt166 = { 0x00, 0x06 }; + public static readonly byte[] UInt167 = { 0x00, 0x07 }; + public static readonly byte[] UInt168 = { 0x00, 0x08 }; + public static readonly byte[] UInt169 = { 0x00, 0x09 }; + public static readonly byte[] UInt1632768 = { 0x80, 0x00 }; + public static readonly byte[] UInt16Max = { 0xFF, 0xFF }; + + public static readonly byte[] Int16Min = { 0x80, 0x00 }; + public static readonly byte[] Int160 = { 0x00, 0x00 }; + public static readonly byte[] Int161 = { 0x00, 0x01 }; + public static readonly byte[] Int162 = { 0x00, 0x02 }; + public static readonly byte[] Int163 = { 0x00, 0x03 }; + public static readonly byte[] Int164 = { 0x00, 0x04 }; + public static readonly byte[] Int165 = { 0x00, 0x05 }; + public static readonly byte[] Int166 = { 0x00, 0x06 }; + public static readonly byte[] Int167 = { 0x00, 0x07 }; + public static readonly byte[] Int168 = { 0x00, 0x08 }; + public static readonly byte[] Int169 = { 0x00, 0x09 }; + public static readonly byte[] Int16Max = { 0x7F, 0xFF }; + + public static readonly byte[] UInt320 = { 0x00, 0x00, 0x00, 0x00 }; + public static readonly byte[] UInt321 = { 0x00, 0x00, 0x00, 0x01 }; + public static readonly byte[] UInt322 = { 0x00, 0x00, 0x00, 0x02 }; + public static readonly byte[] UInt323 = { 0x00, 0x00, 0x00, 0x03 }; + public static readonly byte[] UInt324 = { 0x00, 0x00, 0x00, 0x04 }; + public static readonly byte[] UInt325 = { 0x00, 0x00, 0x00, 0x05 }; + public static readonly byte[] UInt326 = { 0x00, 0x00, 0x00, 0x06 }; + public static readonly byte[] UInt327 = { 0x00, 0x00, 0x00, 0x07 }; + public static readonly byte[] UInt328 = { 0x00, 0x00, 0x00, 0x08 }; + public static readonly byte[] UInt329 = { 0x00, 0x00, 0x00, 0x09 }; + public static readonly byte[] UInt32Max = { 0xFF, 0xFF, 0xFF, 0xFF }; + + public static readonly uint UInt32ValRand1 = 1749014123; + public static readonly uint UInt32ValRand2 = 3870560989; + public static readonly uint UInt32ValRand3 = 1050090334; + public static readonly uint UInt32ValRand4 = 3550252874; + + public static readonly byte[] UInt32Rand1 = { 0x68, 0x3F, 0xD6, 0x6B }; + public static readonly byte[] UInt32Rand2 = { 0xE6, 0xB4, 0x12, 0xDD }; + public static readonly byte[] UInt32Rand3 = { 0x3E, 0x97, 0x1B, 0x5E }; + public static readonly byte[] UInt32Rand4 = { 0xD3, 0x9C, 0x8F, 0x4A }; + + public static readonly byte[] Int32Min = { 0x80, 0x00, 0x00, 0x00 }; + public static readonly byte[] Int320 = { 0x00, 0x00, 0x00, 0x00 }; + public static readonly byte[] Int321 = { 0x00, 0x00, 0x00, 0x01 }; + public static readonly byte[] Int322 = { 0x00, 0x00, 0x00, 0x02 }; + public static readonly byte[] Int323 = { 0x00, 0x00, 0x00, 0x03 }; + public static readonly byte[] Int324 = { 0x00, 0x00, 0x00, 0x04 }; + public static readonly byte[] Int325 = { 0x00, 0x00, 0x00, 0x05 }; + public static readonly byte[] Int326 = { 0x00, 0x00, 0x00, 0x06 }; + public static readonly byte[] Int327 = { 0x00, 0x00, 0x00, 0x07 }; + public static readonly byte[] Int328 = { 0x00, 0x00, 0x00, 0x08 }; + public static readonly byte[] Int329 = { 0x00, 0x00, 0x00, 0x09 }; + public static readonly byte[] Int32Max = { 0x7F, 0xFF, 0xFF, 0xFF }; + + public static readonly byte[] UInt640 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + public static readonly byte[] UInt641 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; + public static readonly byte[] UInt642 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }; + public static readonly byte[] UInt643 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03 }; + public static readonly byte[] UInt644 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04 }; + public static readonly byte[] UInt645 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05 }; + public static readonly byte[] UInt646 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06 }; + public static readonly byte[] UInt647 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07 }; + public static readonly byte[] UInt648 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08 }; + public static readonly byte[] UInt649 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09 }; + public static readonly byte[] UInt64Max = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; + + public static readonly byte[] Int64Min = { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + public static readonly byte[] Int640 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + public static readonly byte[] Int641 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; + public static readonly byte[] Int642 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }; + public static readonly byte[] Int643 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03 }; + public static readonly byte[] Int644 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04 }; + public static readonly byte[] Int645 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05 }; + public static readonly byte[] Int646 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06 }; + public static readonly byte[] Int647 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07 }; + public static readonly byte[] Int648 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08 }; + public static readonly byte[] Int649 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09 }; + public static readonly byte[] Int64Max = { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; + + public static readonly byte[] SingleMin = { 0xFF, 0x7F, 0xFF, 0xFF }; + public static readonly byte[] Single0 = { 0x00, 0x00, 0x00, 0x00 }; + public static readonly byte[] Single1 = { 0x3F, 0x80, 0x00, 0x00 }; + public static readonly byte[] Single2 = { 0x40, 0x00, 0x00, 0x00 }; + public static readonly byte[] Single3 = { 0x40, 0x40, 0x00, 0x00 }; + public static readonly byte[] Single4 = { 0x40, 0x80, 0x00, 0x00 }; + public static readonly byte[] Single5 = { 0x40, 0xA0, 0x00, 0x00 }; + public static readonly byte[] Single6 = { 0x40, 0xC0, 0x00, 0x00 }; + public static readonly byte[] Single7 = { 0x40, 0xE0, 0x00, 0x00 }; + public static readonly byte[] Single8 = { 0x41, 0x00, 0x00, 0x00 }; + public static readonly byte[] Single9 = { 0x41, 0x10, 0x00, 0x00 }; + public static readonly byte[] SingleMax = { 0x7F, 0x7F, 0xFF, 0xFF }; + + public static readonly byte[] DoubleMin = { 0xFF, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; + public static readonly byte[] Double0 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + public static readonly byte[] Double1 = { 0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + public static readonly byte[] DoubleMax = { 0x7F, 0xEF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; + + public const float Fix16ValMin = short.MinValue; + public const float Fix16ValMax = short.MaxValue + (65535f / 65536f); + + public static readonly byte[] Fix16Min = { 0x80, 0x00, 0x00, 0x00 }; + public static readonly byte[] Fix160 = { 0x00, 0x00, 0x00, 0x00 }; + public static readonly byte[] Fix161 = { 0x00, 0x01, 0x00, 0x00 }; + public static readonly byte[] Fix162 = { 0x00, 0x02, 0x00, 0x00 }; + public static readonly byte[] Fix163 = { 0x00, 0x03, 0x00, 0x00 }; + public static readonly byte[] Fix164 = { 0x00, 0x04, 0x00, 0x00 }; + public static readonly byte[] Fix165 = { 0x00, 0x05, 0x00, 0x00 }; + public static readonly byte[] Fix166 = { 0x00, 0x06, 0x00, 0x00 }; + public static readonly byte[] Fix167 = { 0x00, 0x07, 0x00, 0x00 }; + public static readonly byte[] Fix168 = { 0x00, 0x08, 0x00, 0x00 }; + public static readonly byte[] Fix169 = { 0x00, 0x09, 0x00, 0x00 }; + public static readonly byte[] Fix16Max = { 0x7F, 0xFF, 0xFF, 0xFF }; public static readonly object[][] Fix16TestData = { - new object[] { Fix16_Min, Fix16_ValMin }, - new object[] { Fix16_0, 0 }, - new object[] { Fix16_4, 4 }, - new object[] { Fix16_Max, Fix16_ValMax }, + new object[] { Fix16Min, Fix16ValMin }, + new object[] { Fix160, 0 }, + new object[] { Fix164, 4 }, + new object[] { Fix16Max, Fix16ValMax }, }; - public const float UFix16_ValMin = 0; - public const float UFix16_ValMax = ushort.MaxValue + (65535f / 65536f); - - public static readonly byte[] UFix16_0 = { 0x00, 0x00, 0x00, 0x00 }; - public static readonly byte[] UFix16_1 = { 0x00, 0x01, 0x00, 0x00 }; - public static readonly byte[] UFix16_2 = { 0x00, 0x02, 0x00, 0x00 }; - public static readonly byte[] UFix16_3 = { 0x00, 0x03, 0x00, 0x00 }; - public static readonly byte[] UFix16_4 = { 0x00, 0x04, 0x00, 0x00 }; - public static readonly byte[] UFix16_5 = { 0x00, 0x05, 0x00, 0x00 }; - public static readonly byte[] UFix16_6 = { 0x00, 0x06, 0x00, 0x00 }; - public static readonly byte[] UFix16_7 = { 0x00, 0x07, 0x00, 0x00 }; - public static readonly byte[] UFix16_8 = { 0x00, 0x08, 0x00, 0x00 }; - public static readonly byte[] UFix16_9 = { 0x00, 0x09, 0x00, 0x00 }; - public static readonly byte[] UFix16_Max = { 0xFF, 0xFF, 0xFF, 0xFF }; + public const float UFix16ValMin = 0; + public const float UFix16ValMax = ushort.MaxValue + (65535f / 65536f); + + public static readonly byte[] UFix160 = { 0x00, 0x00, 0x00, 0x00 }; + public static readonly byte[] UFix161 = { 0x00, 0x01, 0x00, 0x00 }; + public static readonly byte[] UFix162 = { 0x00, 0x02, 0x00, 0x00 }; + public static readonly byte[] UFix163 = { 0x00, 0x03, 0x00, 0x00 }; + public static readonly byte[] UFix164 = { 0x00, 0x04, 0x00, 0x00 }; + public static readonly byte[] UFix165 = { 0x00, 0x05, 0x00, 0x00 }; + public static readonly byte[] UFix166 = { 0x00, 0x06, 0x00, 0x00 }; + public static readonly byte[] UFix167 = { 0x00, 0x07, 0x00, 0x00 }; + public static readonly byte[] UFix168 = { 0x00, 0x08, 0x00, 0x00 }; + public static readonly byte[] UFix169 = { 0x00, 0x09, 0x00, 0x00 }; + public static readonly byte[] UFix16Max = { 0xFF, 0xFF, 0xFF, 0xFF }; public static readonly object[][] UFix16TestData = { - new object[] { UFix16_0, 0 }, - new object[] { UFix16_4, 4 }, - new object[] { UFix16_Max, UFix16_ValMax }, + new object[] { UFix160, 0 }, + new object[] { UFix164, 4 }, + new object[] { UFix16Max, UFix16ValMax }, }; - public const float U1Fix15_ValMin = 0; - public const float U1Fix15_ValMax = 1f + (32767f / 32768f); + public const float U1Fix15ValMin = 0; + public const float U1Fix15ValMax = 1f + (32767f / 32768f); - public static readonly byte[] U1Fix15_0 = { 0x00, 0x00 }; - public static readonly byte[] U1Fix15_1 = { 0x80, 0x00 }; - public static readonly byte[] U1Fix15_Max = { 0xFF, 0xFF }; + public static readonly byte[] U1Fix150 = { 0x00, 0x00 }; + public static readonly byte[] U1Fix151 = { 0x80, 0x00 }; + public static readonly byte[] U1Fix15Max = { 0xFF, 0xFF }; public static readonly object[][] U1Fix15TestData = { - new object[] { U1Fix15_0, 0 }, - new object[] { U1Fix15_1, 1 }, - new object[] { U1Fix15_Max, U1Fix15_ValMax }, + new object[] { U1Fix150, 0 }, + new object[] { U1Fix151, 1 }, + new object[] { U1Fix15Max, U1Fix15ValMax }, }; - public const float UFix8_ValMin = 0; - public const float UFix8_ValMax = byte.MaxValue + (255f / 256f); - - public static readonly byte[] UFix8_0 = { 0x00, 0x00 }; - public static readonly byte[] UFix8_1 = { 0x01, 0x00 }; - public static readonly byte[] UFix8_2 = { 0x02, 0x00 }; - public static readonly byte[] UFix8_3 = { 0x03, 0x00 }; - public static readonly byte[] UFix8_4 = { 0x04, 0x00 }; - public static readonly byte[] UFix8_5 = { 0x05, 0x00 }; - public static readonly byte[] UFix8_6 = { 0x06, 0x00 }; - public static readonly byte[] UFix8_7 = { 0x07, 0x00 }; - public static readonly byte[] UFix8_8 = { 0x08, 0x00 }; - public static readonly byte[] UFix8_9 = { 0x09, 0x00 }; - public static readonly byte[] UFix8_Max = { 0xFF, 0xFF }; + public const float UFix8ValMin = 0; + public const float UFix8ValMax = byte.MaxValue + (255f / 256f); + + public static readonly byte[] UFix80 = { 0x00, 0x00 }; + public static readonly byte[] UFix81 = { 0x01, 0x00 }; + public static readonly byte[] UFix82 = { 0x02, 0x00 }; + public static readonly byte[] UFix83 = { 0x03, 0x00 }; + public static readonly byte[] UFix84 = { 0x04, 0x00 }; + public static readonly byte[] UFix85 = { 0x05, 0x00 }; + public static readonly byte[] UFix86 = { 0x06, 0x00 }; + public static readonly byte[] UFix87 = { 0x07, 0x00 }; + public static readonly byte[] UFix88 = { 0x08, 0x00 }; + public static readonly byte[] UFix89 = { 0x09, 0x00 }; + public static readonly byte[] UFix8Max = { 0xFF, 0xFF }; public static readonly object[][] UFix8TestData = { - new object[] { UFix8_0, 0 }, - new object[] { UFix8_4, 4 }, - new object[] { UFix8_Max, UFix8_ValMax }, + new object[] { UFix80, 0 }, + new object[] { UFix84, 4 }, + new object[] { UFix8Max, UFix8ValMax }, }; - public const string Ascii_ValRand = "aBcdEf1234"; - public const string Ascii_ValRand1 = "Ecf3a"; - public const string Ascii_ValRand2 = "2Bd4c"; - public const string Ascii_ValRand3 = "cad14"; - public const string Ascii_ValRand4 = "fd4E1"; - public const string Ascii_ValRandLength4 = "aBcd"; - public const string Ascii_ValNullRand = "aBcd\0Ef\0123"; - - public static readonly byte[] Ascii_Rand = { 97, 66, 99, 100, 69, 102, 49, 50, 51, 52 }; - public static readonly byte[] Ascii_Rand1 = { 69, 99, 102, 51, 97 }; - public static readonly byte[] Ascii_Rand2 = { 50, 66, 100, 52, 99 }; - public static readonly byte[] Ascii_Rand3 = { 99, 97, 100, 49, 52 }; - public static readonly byte[] Ascii_Rand4 = { 102, 100, 52, 69, 49 }; - public static readonly byte[] Ascii_RandLength4 = { 97, 66, 99, 100 }; - public static readonly byte[] Ascii_PaddedRand = { 97, 66, 99, 100, 69, 102, 49, 50, 51, 52, 0, 0, 0, 0 }; - public static readonly byte[] Ascii_NullRand = { 97, 66, 99, 100, 0, 69, 102, 0, 49, 50, 51 }; - - public const int Ascii_Rand_Length = 10; - public const int Ascii_PaddedRand_Length = 14; - public const int Ascii_NullRand_Length = 11; - public const int Ascii_NullRand_LengthNoNull = 4; + public const string AsciiValRand = "aBcdEf1234"; + public const string AsciiValRand1 = "Ecf3a"; + public const string AsciiValRand2 = "2Bd4c"; + public const string AsciiValRand3 = "cad14"; + public const string AsciiValRand4 = "fd4E1"; + public const string AsciiValRandLength4 = "aBcd"; + public const string AsciiValNullRand = "aBcd\0Ef\0123"; + + public static readonly byte[] AsciiRand = { 97, 66, 99, 100, 69, 102, 49, 50, 51, 52 }; + public static readonly byte[] AsciiRand1 = { 69, 99, 102, 51, 97 }; + public static readonly byte[] AsciiRand2 = { 50, 66, 100, 52, 99 }; + public static readonly byte[] AsciiRand3 = { 99, 97, 100, 49, 52 }; + public static readonly byte[] AsciiRand4 = { 102, 100, 52, 69, 49 }; + public static readonly byte[] AsciiRandLength4 = { 97, 66, 99, 100 }; + public static readonly byte[] AsciiPaddedRand = { 97, 66, 99, 100, 69, 102, 49, 50, 51, 52, 0, 0, 0, 0 }; + public static readonly byte[] AsciiNullRand = { 97, 66, 99, 100, 0, 69, 102, 0, 49, 50, 51 }; + + public const int AsciiRandLength = 10; + public const int AsciiPaddedRandLength = 14; + public const int AsciiNullRandLength = 11; + public const int AsciiNullRandLengthNoNull = 4; public static readonly object[][] AsciiTestData = { - new object[] { Ascii_Rand, Ascii_Rand_Length, Ascii_ValRand }, - new object[] { Ascii_Rand, 4, Ascii_ValRandLength4 }, - new object[] { Ascii_NullRand, Ascii_NullRand_LengthNoNull, Ascii_ValRandLength4 }, + new object[] { AsciiRand, AsciiRandLength, AsciiValRand }, + new object[] { AsciiRand, 4, AsciiValRandLength4 }, + new object[] { AsciiNullRand, AsciiNullRandLengthNoNull, AsciiValRandLength4 }, }; public static readonly object[][] AsciiWriteTestData = { - new object[] { Ascii_Rand, Ascii_ValRand }, - new object[] { Ascii_NullRand, Ascii_ValNullRand }, + new object[] { AsciiRand, AsciiValRand }, + new object[] { AsciiNullRand, AsciiValNullRand }, }; public static readonly object[][] AsciiPaddingTestData = { - new object[] { Ascii_PaddedRand, Ascii_PaddedRand_Length, Ascii_ValRand, true }, - new object[] { Ascii_RandLength4, 4, Ascii_ValRand, false }, + new object[] { AsciiPaddedRand, AsciiPaddedRandLength, AsciiValRand, true }, + new object[] { AsciiRandLength4, 4, AsciiValRand, false }, }; - public const string Unicode_ValRand1 = ".6Abäñ$€β𐐷𤭢"; - public const string Unicode_ValRand2 = ".6Abäñ"; - public const string Unicode_ValRand3 = "$€β𐐷𤭢"; + public const string UnicodeValRand1 = ".6Abäñ$€β𐐷𤭢"; + public const string UnicodeValRand2 = ".6Abäñ"; + public const string UnicodeValRand3 = "$€β𐐷𤭢"; - public static readonly byte[] Unicode_Rand1 = + public static readonly byte[] UnicodeRand1 = { 0x00, 0x2e, // . 0x00, 0x36, // 6 @@ -251,7 +251,7 @@ internal static class IccTestDataPrimitives 0xD8, 0x52, 0xDF, 0x62, // 𤭢 }; - public static readonly byte[] Unicode_Rand2 = + public static readonly byte[] UnicodeRand2 = { 0x00, 0x2e, // . 0x00, 0x36, // 6 @@ -261,7 +261,7 @@ internal static class IccTestDataPrimitives 0x00, 0xf1, // ñ }; - public static readonly byte[] Unicode_Rand3 = + public static readonly byte[] UnicodeRand3 = { 0x00, 0x24, // $ 0x20, 0xAC, // € diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataProfiles.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataProfiles.cs index 8fd6f7e4ae..7441bede83 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataProfiles.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataProfiles.cs @@ -4,59 +4,54 @@ using System.Numerics; using SixLabors.ImageSharp.Metadata.Profiles.Icc; -namespace SixLabors.ImageSharp.Tests; +namespace SixLabors.ImageSharp.Tests.TestDataIcc; internal static class IccTestDataProfiles { - public static readonly IccProfileId Header_Random_Id_Value = new IccProfileId(0x84A8D460, 0xC716B6F3, 0x9B0E4C3D, 0xAB95F838); - public static readonly IccProfileId Profile_Random_Id_Value = new IccProfileId(0x917D6DE6, 0x84C958D1, 0x3BB0F5BB, 0xADD1134F); + public static readonly IccProfileId HeaderRandomIdValue = new(0x84A8D460, 0xC716B6F3, 0x9B0E4C3D, 0xAB95F838); + public static readonly IccProfileId ProfileRandomIdValue = new(0x917D6DE6, 0x84C958D1, 0x3BB0F5BB, 0xADD1134F); - public static readonly byte[] Header_Random_Id_Array = + public static readonly byte[] HeaderRandomIdArray = { 0x84, 0xA8, 0xD4, 0x60, 0xC7, 0x16, 0xB6, 0xF3, 0x9B, 0x0E, 0x4C, 0x3D, 0xAB, 0x95, 0xF8, 0x38, }; - public static readonly byte[] Profile_Random_Id_Array = + public static readonly byte[] ProfileRandomIdArray = { 0x91, 0x7D, 0x6D, 0xE6, 0x84, 0xC9, 0x58, 0xD1, 0x3B, 0xB0, 0xF5, 0xBB, 0xAD, 0xD1, 0x13, 0x4F, }; - public static readonly IccProfileHeader Header_Random_Write = CreateHeaderRandomValue( + public static readonly IccProfileHeader HeaderRandomWrite = CreateHeaderRandomValue( 562, // should be overwritten new IccProfileId(1, 2, 3, 4), // should be overwritten "ijkl"); // should be overwritten to "acsp" - public static readonly IccProfileHeader Header_Random_Read = CreateHeaderRandomValue(132, Header_Random_Id_Value, "acsp"); + public static readonly IccProfileHeader HeaderRandomRead = CreateHeaderRandomValue(132, HeaderRandomIdValue, "acsp"); - public static readonly byte[] Header_Random_Array = CreateHeaderRandomArray(132, 0, Header_Random_Id_Array); + public static readonly byte[] HeaderRandomArray = CreateHeaderRandomArray(132, 0, HeaderRandomIdArray); - public static IccProfileHeader CreateHeaderRandomValue(uint size, IccProfileId id, string fileSignature) + public static IccProfileHeader CreateHeaderRandomValue(uint size, IccProfileId id, string fileSignature) => new() { - return new IccProfileHeader - { - Class = IccProfileClass.DisplayDevice, - CmmType = "abcd", - CreationDate = new DateTime(1990, 11, 26, 7, 21, 42), - CreatorSignature = "dcba", - DataColorSpace = IccColorSpaceType.Rgb, - DeviceAttributes = IccDeviceAttribute.ChromaBlackWhite | IccDeviceAttribute.OpacityTransparent, - DeviceManufacturer = 123456789u, - DeviceModel = 987654321u, - FileSignature = "acsp", - Flags = IccProfileFlag.Embedded | IccProfileFlag.Independent, - Id = id, - PcsIlluminant = new Vector3(4, 5, 6), - PrimaryPlatformSignature = IccPrimaryPlatformType.MicrosoftCorporation, - ProfileConnectionSpace = IccColorSpaceType.CieXyz, - RenderingIntent = IccRenderingIntent.AbsoluteColorimetric, - Size = size, - Version = new IccVersion(4, 3, 0), - }; - } - - public static byte[] CreateHeaderRandomArray(uint size, uint nrOfEntries, byte[] profileId) - { - return ArrayHelper.Concat( + Class = IccProfileClass.DisplayDevice, + CmmType = "abcd", + CreationDate = new DateTime(1990, 11, 26, 7, 21, 42), + CreatorSignature = "dcba", + DataColorSpace = IccColorSpaceType.Rgb, + DeviceAttributes = IccDeviceAttribute.ChromaBlackWhite | IccDeviceAttribute.OpacityTransparent, + DeviceManufacturer = 123456789u, + DeviceModel = 987654321u, + FileSignature = "acsp", + Flags = IccProfileFlag.Embedded | IccProfileFlag.Independent, + Id = id, + PcsIlluminant = new Vector3(4, 5, 6), + PrimaryPlatformSignature = IccPrimaryPlatformType.MicrosoftCorporation, + ProfileConnectionSpace = IccColorSpaceType.CieXyz, + RenderingIntent = IccRenderingIntent.AbsoluteColorimetric, + Size = size, + Version = new IccVersion(4, 3, 0), + }; + + public static byte[] CreateHeaderRandomArray(uint size, uint nrOfEntries, byte[] profileId) => ArrayHelper.Concat( new byte[] { (byte)(size >> 24), (byte)(size >> 16), (byte)(size >> 8), (byte)size, // Size @@ -91,10 +86,9 @@ internal static class IccTestDataProfiles (byte)(nrOfEntries >> 8), (byte)nrOfEntries }); - } - public static readonly byte[] Profile_Random_Array = ArrayHelper.Concat( - CreateHeaderRandomArray(168, 2, Profile_Random_Id_Array), + public static readonly byte[] ProfileRandomArray = ArrayHelper.Concat( + CreateHeaderRandomArray(168, 2, ProfileRandomIdArray), new byte[] { 0x00, 0x00, 0x00, 0x00, // tag signature (Unknown) @@ -104,17 +98,17 @@ internal static class IccTestDataProfiles 0x00, 0x00, 0x00, 0x9C, // tag offset (156) 0x00, 0x00, 0x00, 0x0C, // tag size (12) }, - IccTestDataTagDataEntry.TagDataEntryHeader_UnknownArr, - IccTestDataTagDataEntry.Unknown_Arr); + IccTestDataTagDataEntry.TagDataEntryHeaderUnknownArr, + IccTestDataTagDataEntry.UnknownArr); - public static readonly IccProfile Profile_Random_Val = new IccProfile( + public static readonly IccProfile ProfileRandomVal = new( CreateHeaderRandomValue( 168, - Profile_Random_Id_Value, + ProfileRandomIdValue, "acsp"), - new IccTagDataEntry[] { IccTestDataTagDataEntry.Unknown_Val, IccTestDataTagDataEntry.Unknown_Val }); + new IccTagDataEntry[] { IccTestDataTagDataEntry.UnknownVal, IccTestDataTagDataEntry.UnknownVal }); - public static readonly byte[] Header_CorruptDataColorSpace_Array = + public static readonly byte[] HeaderCorruptDataColorSpaceArray = { 0x00, 0x00, 0x00, 0x80, // Size 0x61, 0x62, 0x63, 0x64, // CmmType @@ -143,7 +137,7 @@ internal static class IccTestDataProfiles 0x00, 0x00, 0x00, 0x00, }; - public static readonly byte[] Header_CorruptProfileConnectionSpace_Array = + public static readonly byte[] HeaderCorruptProfileConnectionSpaceArray = { 0x00, 0x00, 0x00, 0x80, // Size 0x62, 0x63, 0x64, 0x65, // CmmType @@ -172,7 +166,7 @@ internal static class IccTestDataProfiles 0x00, 0x00, 0x00, 0x00, }; - public static readonly byte[] Header_CorruptRenderingIntent_Array = + public static readonly byte[] HeaderCorruptRenderingIntentArray = { 0x00, 0x00, 0x00, 0x80, // Size 0x63, 0x64, 0x65, 0x66, // CmmType @@ -201,29 +195,29 @@ internal static class IccTestDataProfiles 0x00, 0x00, 0x00, 0x00, }; - public static readonly byte[] Header_DataTooSmall_Array = new byte[127]; + public static readonly byte[] HeaderDataTooSmallArray = new byte[127]; - public static readonly byte[] Header_InvalidSizeSmall_Array = CreateHeaderRandomArray(127, 0, Header_Random_Id_Array); + public static readonly byte[] HeaderInvalidSizeSmallArray = CreateHeaderRandomArray(127, 0, HeaderRandomIdArray); - public static readonly byte[] Header_InvalidSizeBig_Array = CreateHeaderRandomArray(50_000_000, 0, Header_Random_Id_Array); + public static readonly byte[] HeaderInvalidSizeBigArray = CreateHeaderRandomArray(50_000_000, 0, HeaderRandomIdArray); - public static readonly byte[] Header_SizeBiggerThanData_Array = CreateHeaderRandomArray(160, 0, Header_Random_Id_Array); + public static readonly byte[] HeaderSizeBiggerThanDataArray = CreateHeaderRandomArray(160, 0, HeaderRandomIdArray); public static readonly object[][] ProfileIdTestData = { - new object[] { Header_Random_Array, Header_Random_Id_Value }, - new object[] { Profile_Random_Array, Profile_Random_Id_Value }, + new object[] { HeaderRandomArray, HeaderRandomIdValue }, + new object[] { ProfileRandomArray, ProfileRandomIdValue }, }; public static readonly object[][] ProfileValidityTestData = { - new object[] { Header_CorruptDataColorSpace_Array, false }, - new object[] { Header_CorruptProfileConnectionSpace_Array, false }, - new object[] { Header_CorruptRenderingIntent_Array, false }, - new object[] { Header_DataTooSmall_Array, false }, - new object[] { Header_InvalidSizeSmall_Array, false }, - new object[] { Header_InvalidSizeBig_Array, false }, - new object[] { Header_SizeBiggerThanData_Array, false }, - new object[] { Header_Random_Array, true }, + new object[] { HeaderCorruptDataColorSpaceArray, false }, + new object[] { HeaderCorruptProfileConnectionSpaceArray, false }, + new object[] { HeaderCorruptRenderingIntentArray, false }, + new object[] { HeaderDataTooSmallArray, false }, + new object[] { HeaderInvalidSizeSmallArray, false }, + new object[] { HeaderInvalidSizeBigArray, false }, + new object[] { HeaderSizeBiggerThanDataArray, false }, + new object[] { HeaderRandomArray, true }, }; } diff --git a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataTagDataEntry.cs b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataTagDataEntry.cs index 69d375cedf..a83dc3575d 100644 --- a/tests/ImageSharp.Tests/TestDataIcc/IccTestDataTagDataEntry.cs +++ b/tests/ImageSharp.Tests/TestDataIcc/IccTestDataTagDataEntry.cs @@ -2,29 +2,28 @@ // Licensed under the Six Labors Split License. using System.Globalization; -using System.Numerics; using SixLabors.ImageSharp.Metadata.Profiles.Icc; -namespace SixLabors.ImageSharp.Tests; +namespace SixLabors.ImageSharp.Tests.TestDataIcc; internal static class IccTestDataTagDataEntry { - public static readonly IccTypeSignature TagDataEntryHeader_UnknownVal = IccTypeSignature.Unknown; - public static readonly byte[] TagDataEntryHeader_UnknownArr = + public static readonly IccTypeSignature TagDataEntryHeaderUnknownVal = IccTypeSignature.Unknown; + public static readonly byte[] TagDataEntryHeaderUnknownArr = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; - public static readonly IccTypeSignature TagDataEntryHeader_MultiLocalizedUnicodeVal = IccTypeSignature.MultiLocalizedUnicode; - public static readonly byte[] TagDataEntryHeader_MultiLocalizedUnicodeArr = + public static readonly IccTypeSignature TagDataEntryHeaderMultiLocalizedUnicodeVal = IccTypeSignature.MultiLocalizedUnicode; + public static readonly byte[] TagDataEntryHeaderMultiLocalizedUnicodeArr = { 0x6D, 0x6C, 0x75, 0x63, 0x00, 0x00, 0x00, 0x00, }; - public static readonly IccTypeSignature TagDataEntryHeader_CurveVal = IccTypeSignature.Curve; - public static readonly byte[] TagDataEntryHeader_CurveArr = + public static readonly IccTypeSignature TagDataEntryHeaderCurveVal = IccTypeSignature.Curve; + public static readonly byte[] TagDataEntryHeaderCurveArr = { 0x63, 0x75, 0x72, 0x76, 0x00, 0x00, 0x00, 0x00, @@ -32,24 +31,24 @@ internal static class IccTestDataTagDataEntry public static readonly object[][] TagDataEntryHeaderTestData = { - new object[] { TagDataEntryHeader_UnknownArr, TagDataEntryHeader_UnknownVal }, - new object[] { TagDataEntryHeader_MultiLocalizedUnicodeArr, TagDataEntryHeader_MultiLocalizedUnicodeVal }, - new object[] { TagDataEntryHeader_CurveArr, TagDataEntryHeader_CurveVal }, + new object[] { TagDataEntryHeaderUnknownArr, TagDataEntryHeaderUnknownVal }, + new object[] { TagDataEntryHeaderMultiLocalizedUnicodeArr, TagDataEntryHeaderMultiLocalizedUnicodeVal }, + new object[] { TagDataEntryHeaderCurveArr, TagDataEntryHeaderCurveVal }, }; - public static readonly IccUnknownTagDataEntry Unknown_Val = new(new byte[] { 0x00, 0x01, 0x02, 0x03 }); + public static readonly IccUnknownTagDataEntry UnknownVal = new(new byte[] { 0x00, 0x01, 0x02, 0x03 }); - public static readonly byte[] Unknown_Arr = { 0x00, 0x01, 0x02, 0x03 }; + public static readonly byte[] UnknownArr = { 0x00, 0x01, 0x02, 0x03 }; public static readonly object[][] UnknownTagDataEntryTestData = { - new object[] { Unknown_Arr, Unknown_Val, 12u }, + new object[] { UnknownArr, UnknownVal, 12u }, }; - public static readonly IccChromaticityTagDataEntry Chromaticity_Val1 = new(IccColorantEncoding.ItuRBt709_2); - public static readonly byte[] Chromaticity_Arr1 = ArrayHelper.Concat( - IccTestDataPrimitives.UInt16_3, - IccTestDataPrimitives.UInt16_1, + public static readonly IccChromaticityTagDataEntry ChromaticityVal1 = new(IccColorantEncoding.ItuRBt709_2); + public static readonly byte[] ChromaticityArr1 = ArrayHelper.Concat( + IccTestDataPrimitives.UInt163, + IccTestDataPrimitives.UInt161, new byte[] { 0x00, 0x00, 0xA3, 0xD7 }, // 0.640 new byte[] { 0x00, 0x00, 0x54, 0x7B }, // 0.330 new byte[] { 0x00, 0x00, 0x4C, 0xCD }, // 0.300 @@ -57,103 +56,99 @@ internal static class IccTestDataTagDataEntry new byte[] { 0x00, 0x00, 0x26, 0x66 }, // 0.150 new byte[] { 0x00, 0x00, 0x0F, 0x5C }); // 0.060 - public static readonly IccChromaticityTagDataEntry Chromaticity_Val2 = new( - new double[][] + public static readonly IccChromaticityTagDataEntry ChromaticityVal2 = new( + new[] { new double[] { 1, 2 }, new double[] { 3, 4 }, }); - public static readonly byte[] Chromaticity_Arr2 = ArrayHelper.Concat( - IccTestDataPrimitives.UInt16_2, - IccTestDataPrimitives.UInt16_0, - IccTestDataPrimitives.UFix16_1, - IccTestDataPrimitives.UFix16_2, - IccTestDataPrimitives.UFix16_3, - IccTestDataPrimitives.UFix16_4); + public static readonly byte[] ChromaticityArr2 = ArrayHelper.Concat( + IccTestDataPrimitives.UInt162, + IccTestDataPrimitives.UInt160, + IccTestDataPrimitives.UFix161, + IccTestDataPrimitives.UFix162, + IccTestDataPrimitives.UFix163, + IccTestDataPrimitives.UFix164); /// /// : channel count must be 3 for any enum other than /// - public static readonly byte[] Chromaticity_ArrInvalid1 = ArrayHelper.Concat( - IccTestDataPrimitives.UInt16_5, - IccTestDataPrimitives.UInt16_1); + public static readonly byte[] ChromaticityArrInvalid1 = ArrayHelper.Concat( + IccTestDataPrimitives.UInt165, + IccTestDataPrimitives.UInt161); /// /// : invalid enum value /// - public static readonly byte[] Chromaticity_ArrInvalid2 = ArrayHelper.Concat( - IccTestDataPrimitives.UInt16_3, - IccTestDataPrimitives.UInt16_9); + public static readonly byte[] ChromaticityArrInvalid2 = ArrayHelper.Concat( + IccTestDataPrimitives.UInt163, + IccTestDataPrimitives.UInt169); public static readonly object[][] ChromaticityTagDataEntryTestData = { - new object[] { Chromaticity_Arr1, Chromaticity_Val1 }, - new object[] { Chromaticity_Arr2, Chromaticity_Val2 }, + new object[] { ChromaticityArr1, ChromaticityVal1 }, + new object[] { ChromaticityArr2, ChromaticityVal2 }, }; - public static readonly IccColorantOrderTagDataEntry ColorantOrder_Val = new(new byte[] { 0x00, 0x01, 0x02 }); - public static readonly byte[] ColorantOrder_Arr = ArrayHelper.Concat(IccTestDataPrimitives.UInt32_3, new byte[] { 0x00, 0x01, 0x02 }); + public static readonly IccColorantOrderTagDataEntry ColorantOrderVal = new(new byte[] { 0x00, 0x01, 0x02 }); + public static readonly byte[] ColorantOrderArr = ArrayHelper.Concat(IccTestDataPrimitives.UInt323, new byte[] { 0x00, 0x01, 0x02 }); public static readonly object[][] ColorantOrderTagDataEntryTestData = { - new object[] { ColorantOrder_Arr, ColorantOrder_Val }, + new object[] { ColorantOrderArr, ColorantOrderVal }, }; - public static readonly IccColorantTableTagDataEntry ColorantTable_Val = new( - new IccColorantTableEntry[] + public static readonly IccColorantTableTagDataEntry ColorantTableVal = new( + new[] { - IccTestDataNonPrimitives.ColorantTableEntry_ValRand1, - IccTestDataNonPrimitives.ColorantTableEntry_ValRand2 + IccTestDataNonPrimitives.ColorantTableEntryValRand1, + IccTestDataNonPrimitives.ColorantTableEntryValRand2 }); - public static readonly byte[] ColorantTable_Arr = ArrayHelper.Concat( - IccTestDataPrimitives.UInt32_2, - IccTestDataNonPrimitives.ColorantTableEntry_Rand1, - IccTestDataNonPrimitives.ColorantTableEntry_Rand2); + public static readonly byte[] ColorantTableArr = ArrayHelper.Concat( + IccTestDataPrimitives.UInt322, + IccTestDataNonPrimitives.ColorantTableEntryRand1, + IccTestDataNonPrimitives.ColorantTableEntryRand2); public static readonly object[][] ColorantTableTagDataEntryTestData = { - new object[] { ColorantTable_Arr, ColorantTable_Val }, + new object[] { ColorantTableArr, ColorantTableVal }, }; - public static readonly IccCurveTagDataEntry Curve_Val_0 = new(); - public static readonly byte[] Curve_Arr_0 = IccTestDataPrimitives.UInt32_0; + public static readonly IccCurveTagDataEntry CurveVal0 = new(); + public static readonly byte[] CurveArr0 = IccTestDataPrimitives.UInt320; - public static readonly IccCurveTagDataEntry Curve_Val_1 = new(1f); - public static readonly byte[] Curve_Arr_1 = ArrayHelper.Concat( - IccTestDataPrimitives.UInt32_1, - IccTestDataPrimitives.UFix8_1); + public static readonly IccCurveTagDataEntry CurveVal1 = new(1f); + public static readonly byte[] CurveArr1 = ArrayHelper.Concat( + IccTestDataPrimitives.UInt321, + IccTestDataPrimitives.UFix81); - public static readonly IccCurveTagDataEntry Curve_Val_2 = new(new float[] { 1 / 65535f, 2 / 65535f, 3 / 65535f }); - public static readonly byte[] Curve_Arr_2 = ArrayHelper.Concat( - IccTestDataPrimitives.UInt32_3, - IccTestDataPrimitives.UInt16_1, - IccTestDataPrimitives.UInt16_2, - IccTestDataPrimitives.UInt16_3); + public static readonly IccCurveTagDataEntry CurveVal2 = new(new float[] { 1 / 65535f, 2 / 65535f, 3 / 65535f }); + public static readonly byte[] CurveArr2 = ArrayHelper.Concat( + IccTestDataPrimitives.UInt323, + IccTestDataPrimitives.UInt161, + IccTestDataPrimitives.UInt162, + IccTestDataPrimitives.UInt163); public static readonly object[][] CurveTagDataEntryTestData = { - new object[] { Curve_Arr_0, Curve_Val_0 }, - new object[] { Curve_Arr_1, Curve_Val_1 }, - new object[] { Curve_Arr_2, Curve_Val_2 }, + new object[] { CurveArr0, CurveVal0 }, + new object[] { CurveArr1, CurveVal1 }, + new object[] { CurveArr2, CurveVal2 }, }; - public static readonly IccDataTagDataEntry Data_ValNoASCII = new( - new byte[] { 0x01, 0x02, 0x03, 0x04 }, - false); + public static readonly IccDataTagDataEntry DataValNoAscii = new(new byte[] { 0x01, 0x02, 0x03, 0x04 }, false); - public static readonly byte[] Data_ArrNoASCII = + public static readonly byte[] DataArrNoAscii = { 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04 }; - public static readonly IccDataTagDataEntry Data_ValASCII = new( - new byte[] { (byte)'A', (byte)'S', (byte)'C', (byte)'I', (byte)'I' }, - true); + public static readonly IccDataTagDataEntry DataValAscii = new(new[] { (byte)'A', (byte)'S', (byte)'C', (byte)'I', (byte)'I' }, true); - public static readonly byte[] Data_ArrASCII = + public static readonly byte[] DataArrAscii = { 0x00, 0x00, 0x00, 0x01, (byte)'A', (byte)'S', (byte)'C', (byte)'I', (byte)'I' @@ -161,86 +156,77 @@ internal static class IccTestDataTagDataEntry public static readonly object[][] DataTagDataEntryTestData = { - new object[] { Data_ArrNoASCII, Data_ValNoASCII, 16u }, - new object[] { Data_ArrASCII, Data_ValASCII, 17u }, + new object[] { DataArrNoAscii, DataValNoAscii, 16u }, + new object[] { DataArrAscii, DataValAscii, 17u }, }; - public static readonly IccDateTimeTagDataEntry DateTime_Val = new(IccTestDataNonPrimitives.DateTime_ValRand1); - public static readonly byte[] DateTime_Arr = IccTestDataNonPrimitives.DateTime_Rand1; + public static readonly IccDateTimeTagDataEntry DateTimeVal = new(IccTestDataNonPrimitives.DateTimeValRand1); + public static readonly byte[] DateTimeArr = IccTestDataNonPrimitives.DateTimeRand1; public static readonly object[][] DateTimeTagDataEntryTestData = { - new object[] { DateTime_Arr, DateTime_Val }, + new object[] { DateTimeArr, DateTimeVal }, }; - public static readonly IccLut16TagDataEntry Lut16_Val = new( - new IccLut[] { IccTestDataLut.LUT16_ValGrad, IccTestDataLut.LUT16_ValGrad }, - IccTestDataLut.CLUT16_ValGrad, - new IccLut[] { IccTestDataLut.LUT16_ValGrad, IccTestDataLut.LUT16_ValGrad, IccTestDataLut.LUT16_ValGrad }); + public static readonly IccLut16TagDataEntry Lut16Val = new( + new[] { IccTestDataLut.Lut16ValGrad, IccTestDataLut.Lut16ValGrad }, + IccTestDataLut.Clut16ValGrad, + new[] { IccTestDataLut.Lut16ValGrad, IccTestDataLut.Lut16ValGrad, IccTestDataLut.Lut16ValGrad }); - public static readonly byte[] Lut16_Arr = ArrayHelper.Concat( + public static readonly byte[] Lut16Arr = ArrayHelper.Concat( new byte[] { 0x02, 0x03, 0x03, 0x00 }, - IccTestDataMatrix.Fix16_2D_Identity, - new byte[] { 0x00, (byte)IccTestDataLut.LUT16_ValGrad.Values.Length, 0x00, (byte)IccTestDataLut.LUT16_ValGrad.Values.Length }, - IccTestDataLut.LUT16_Grad, - IccTestDataLut.LUT16_Grad, - IccTestDataLut.CLUT16_Grad, - IccTestDataLut.LUT16_Grad, - IccTestDataLut.LUT16_Grad, - IccTestDataLut.LUT16_Grad); + IccTestDataMatrix.Fix162DIdentity, + new byte[] { 0x00, (byte)IccTestDataLut.Lut16ValGrad.Values.Length, 0x00, (byte)IccTestDataLut.Lut16ValGrad.Values.Length }, + IccTestDataLut.Lut16Grad, + IccTestDataLut.Lut16Grad, + IccTestDataLut.Clut16Grad, + IccTestDataLut.Lut16Grad, + IccTestDataLut.Lut16Grad, + IccTestDataLut.Lut16Grad); public static readonly object[][] Lut16TagDataEntryTestData = { - new object[] { Lut16_Arr, Lut16_Val }, + new object[] { Lut16Arr, Lut16Val }, }; - public static readonly IccLut8TagDataEntry Lut8_Val = new( - new IccLut[] { IccTestDataLut.LUT8_ValGrad, IccTestDataLut.LUT8_ValGrad }, - IccTestDataLut.CLUT8_ValGrad, - new IccLut[] { IccTestDataLut.LUT8_ValGrad, IccTestDataLut.LUT8_ValGrad, IccTestDataLut.LUT8_ValGrad }); + public static readonly IccLut8TagDataEntry Lut8Val = new( + new IccLut[] { IccTestDataLut.Lut8ValGrad, IccTestDataLut.Lut8ValGrad }, + IccTestDataLut.Clut8ValGrad, + new IccLut[] { IccTestDataLut.Lut8ValGrad, IccTestDataLut.Lut8ValGrad, IccTestDataLut.Lut8ValGrad }); - public static readonly byte[] Lut8_Arr = ArrayHelper.Concat( + public static readonly byte[] Lut8Arr = ArrayHelper.Concat( new byte[] { 0x02, 0x03, 0x03, 0x00 }, - IccTestDataMatrix.Fix16_2D_Identity, - IccTestDataLut.LUT8_Grad, - IccTestDataLut.LUT8_Grad, - IccTestDataLut.CLUT8_Grad, - IccTestDataLut.LUT8_Grad, - IccTestDataLut.LUT8_Grad, - IccTestDataLut.LUT8_Grad); + IccTestDataMatrix.Fix162DIdentity, + IccTestDataLut.Lut8Grad, + IccTestDataLut.Lut8Grad, + IccTestDataLut.Clut8Grad, + IccTestDataLut.Lut8Grad, + IccTestDataLut.Lut8Grad, + IccTestDataLut.Lut8Grad); - public static readonly object[][] Lut8TagDataEntryTestData = - { - new object[] { Lut8_Arr, Lut8_Val }, - }; + public static readonly object[][] Lut8TagDataEntryTestData = { new object[] { Lut8Arr, Lut8Val }, }; - private static readonly byte[] CurveFull_0 = ArrayHelper.Concat( - TagDataEntryHeader_CurveArr, - Curve_Arr_0); + private static readonly byte[] CurveFull0 = ArrayHelper.Concat(TagDataEntryHeaderCurveArr, CurveArr0); - private static readonly byte[] CurveFull_1 = ArrayHelper.Concat( - TagDataEntryHeader_CurveArr, - Curve_Arr_1); + private static readonly byte[] CurveFull1 = ArrayHelper.Concat(TagDataEntryHeaderCurveArr, CurveArr1); - private static readonly byte[] CurveFull_2 = ArrayHelper.Concat( - TagDataEntryHeader_CurveArr, - Curve_Arr_2); + private static readonly byte[] CurveFull2 = ArrayHelper.Concat(TagDataEntryHeaderCurveArr, CurveArr2); - public static readonly IccLutAToBTagDataEntry LutAToB_Val + public static readonly IccLutAToBTagDataEntry LutAToBVal = new( - new IccCurveTagDataEntry[] + new[] { - Curve_Val_0, - Curve_Val_1, - Curve_Val_2, + CurveVal0, + CurveVal1, + CurveVal2, }, - IccTestDataMatrix.Single_2DArray_ValGrad, - IccTestDataMatrix.Single_1DArray_ValGrad, - new IccCurveTagDataEntry[] { Curve_Val_1, Curve_Val_2, Curve_Val_0 }, - IccTestDataLut.CLUT_Val16, - new IccCurveTagDataEntry[] { Curve_Val_2, Curve_Val_1 }); + IccTestDataMatrix.Single2DArrayValGrad, + IccTestDataMatrix.Single1DArrayValGrad, + new[] { CurveVal1, CurveVal2, CurveVal0 }, + IccTestDataLut.ClutVal16, + new[] { CurveVal2, CurveVal1 }); - public static readonly byte[] LutAToB_Arr = ArrayHelper.Concat( + public static readonly byte[] LutAToBArr = ArrayHelper.Concat( new byte[] { 0x02, 0x03, 0x00, 0x00 }, new byte[] { 0x00, 0x00, 0x00, 0x20 }, // b: 32 new byte[] { 0x00, 0x00, 0x00, 0x50 }, // matrix: 80 @@ -249,51 +235,48 @@ internal static class IccTestDataTagDataEntry new byte[] { 0x00, 0x00, 0x00, 0xFC }, // a: 252 // B - CurveFull_0, // 12 bytes - CurveFull_1, // 14 bytes + CurveFull0, // 12 bytes + CurveFull1, // 14 bytes new byte[] { 0x00, 0x00 }, // Padding - CurveFull_2, // 18 bytes + CurveFull2, // 18 bytes new byte[] { 0x00, 0x00 }, // Padding // Matrix - IccTestDataMatrix.Fix16_2D_Grad, // 36 bytes - IccTestDataMatrix.Fix16_1D_Grad, // 12 bytes + IccTestDataMatrix.Fix162DGrad, // 36 bytes + IccTestDataMatrix.Fix161DGrad, // 12 bytes // M - CurveFull_1, // 14 bytes + CurveFull1, // 14 bytes new byte[] { 0x00, 0x00 }, // Padding - CurveFull_2, // 18 bytes + CurveFull2, // 18 bytes new byte[] { 0x00, 0x00 }, // Padding - CurveFull_0, // 12 bytes + CurveFull0, // 12 bytes // CLUT - IccTestDataLut.CLUT_16, // 74 bytes + IccTestDataLut.Clut16, // 74 bytes new byte[] { 0x00, 0x00 }, // Padding // A - CurveFull_2, // 18 bytes + CurveFull2, // 18 bytes new byte[] { 0x00, 0x00 }, // Padding - CurveFull_1, // 14 bytes + CurveFull1, // 14 bytes new byte[] { 0x00, 0x00 }); // Padding - public static readonly object[][] LutAToBTagDataEntryTestData = - { - new object[] { LutAToB_Arr, LutAToB_Val }, - }; + public static readonly object[][] LutAToBTagDataEntryTestData = { new object[] { LutAToBArr, LutAToBVal }, }; - public static readonly IccLutBToATagDataEntry LutBToA_Val = new( + public static readonly IccLutBToATagDataEntry LutBToAVal = new( new[] { - Curve_Val_0, - Curve_Val_1, + CurveVal0, + CurveVal1, }, null, null, null, - IccTestDataLut.CLUT_Val16, - new[] { Curve_Val_2, Curve_Val_1, Curve_Val_0 }); + IccTestDataLut.ClutVal16, + new[] { CurveVal2, CurveVal1, CurveVal0 }); - public static readonly byte[] LutBToA_Arr = ArrayHelper.Concat( + public static readonly byte[] LutBToAArr = ArrayHelper.Concat( new byte[] { 0x02, 0x03, 0x00, 0x00 }, new byte[] { 0x00, 0x00, 0x00, 0x20 }, // b: 32 new byte[] { 0x00, 0x00, 0x00, 0x00 }, // matrix: 0 @@ -302,52 +285,52 @@ internal static class IccTestDataTagDataEntry new byte[] { 0x00, 0x00, 0x00, 0x88 }, // a: 136 // B - CurveFull_0, // 12 bytes - CurveFull_1, // 14 bytes + CurveFull0, // 12 bytes + CurveFull1, // 14 bytes new byte[] { 0x00, 0x00 }, // Padding // CLUT - IccTestDataLut.CLUT_16, // 74 bytes + IccTestDataLut.Clut16, // 74 bytes new byte[] { 0x00, 0x00 }, // Padding // A - CurveFull_2, // 18 bytes + CurveFull2, // 18 bytes new byte[] { 0x00, 0x00 }, // Padding - CurveFull_1, // 14 bytes + CurveFull1, // 14 bytes new byte[] { 0x00, 0x00 }, // Padding - CurveFull_0); // 12 bytes + CurveFull0); // 12 bytes public static readonly object[][] LutBToATagDataEntryTestData = { - new object[] { LutBToA_Arr, LutBToA_Val }, + new object[] { LutBToAArr, LutBToAVal }, }; - public static readonly IccMeasurementTagDataEntry Measurement_Val = new( + public static readonly IccMeasurementTagDataEntry MeasurementVal = new( IccStandardObserver.Cie1931Observer, - IccTestDataNonPrimitives.XyzNumber_ValVar1, + IccTestDataNonPrimitives.XyzNumberValVar1, IccMeasurementGeometry.Degree0ToDOrDTo0, 1f, IccStandardIlluminant.D50); - public static readonly byte[] Measurement_Arr = ArrayHelper.Concat( - IccTestDataPrimitives.UInt32_1, - IccTestDataNonPrimitives.XyzNumber_Var1, - IccTestDataPrimitives.UInt32_2, - IccTestDataPrimitives.UFix16_1, - IccTestDataPrimitives.UInt32_1); + public static readonly byte[] MeasurementArr = ArrayHelper.Concat( + IccTestDataPrimitives.UInt321, + IccTestDataNonPrimitives.XyzNumberVar1, + IccTestDataPrimitives.UInt322, + IccTestDataPrimitives.UFix161, + IccTestDataPrimitives.UInt321); public static readonly object[][] MeasurementTagDataEntryTestData = { - new object[] { Measurement_Arr, Measurement_Val }, + new object[] { MeasurementArr, MeasurementVal }, }; - private static readonly IccLocalizedString LocalizedString_Rand_enUS = CreateLocalizedString("en", "US", IccTestDataPrimitives.Unicode_ValRand2); - private static readonly IccLocalizedString LocalizedString_Rand_deDE = CreateLocalizedString("de", "DE", IccTestDataPrimitives.Unicode_ValRand3); - private static readonly IccLocalizedString LocalizedString_Rand2_deDE = CreateLocalizedString("de", "DE", IccTestDataPrimitives.Unicode_ValRand2); - private static readonly IccLocalizedString LocalizedString_Rand2_esXL = CreateLocalizedString("es", "XL", IccTestDataPrimitives.Unicode_ValRand2); - private static readonly IccLocalizedString LocalizedString_Rand2_xyXL = CreateLocalizedString("xy", "XL", IccTestDataPrimitives.Unicode_ValRand2); - private static readonly IccLocalizedString LocalizedString_Rand_en = CreateLocalizedString("en", null, IccTestDataPrimitives.Unicode_ValRand2); - private static readonly IccLocalizedString LocalizedString_Rand_Invariant = new(CultureInfo.InvariantCulture, IccTestDataPrimitives.Unicode_ValRand3); + private static readonly IccLocalizedString LocalizedStringRandEnUs = CreateLocalizedString("en", "US", IccTestDataPrimitives.UnicodeValRand2); + private static readonly IccLocalizedString LocalizedStringRandDeDe = CreateLocalizedString("de", "DE", IccTestDataPrimitives.UnicodeValRand3); + private static readonly IccLocalizedString LocalizedStringRand2DeDe = CreateLocalizedString("de", "DE", IccTestDataPrimitives.UnicodeValRand2); + private static readonly IccLocalizedString LocalizedStringRand2EsXl = CreateLocalizedString("es", "XL", IccTestDataPrimitives.UnicodeValRand2); + private static readonly IccLocalizedString LocalizedStringRand2XyXl = CreateLocalizedString("xy", "XL", IccTestDataPrimitives.UnicodeValRand2); + private static readonly IccLocalizedString LocalizedStringRandEn = CreateLocalizedString("en", null, IccTestDataPrimitives.UnicodeValRand2); + private static readonly IccLocalizedString LocalizedStringRandInvariant = new(CultureInfo.InvariantCulture, IccTestDataPrimitives.UnicodeValRand3); private static IccLocalizedString CreateLocalizedString(string language, string country, string text) { @@ -378,29 +361,29 @@ internal static class IccTestDataTagDataEntry return new IccLocalizedString(culture, text); } - private static readonly IccLocalizedString[] LocalizedString_RandArr_enUS_deDE = new IccLocalizedString[] + private static readonly IccLocalizedString[] LocalizedStringRandArrEnUsDeDe = new[] { - LocalizedString_Rand_enUS, - LocalizedString_Rand_deDE, + LocalizedStringRandEnUs, + LocalizedStringRandDeDe, }; - private static readonly IccLocalizedString[] LocalizedString_RandArr_en_Invariant = new IccLocalizedString[] + private static readonly IccLocalizedString[] LocalizedStringRandArrEnInvariant = new[] { - LocalizedString_Rand_en, - LocalizedString_Rand_Invariant, + LocalizedStringRandEn, + LocalizedStringRandInvariant, }; - private static readonly IccLocalizedString[] LocalizedString_SameArr_enUS_deDE_esXL_xyXL = new IccLocalizedString[] + private static readonly IccLocalizedString[] LocalizedStringSameArrEnUsDeDeEsXlXyXl = new[] { - LocalizedString_Rand_enUS, - LocalizedString_Rand2_deDE, - LocalizedString_Rand2_esXL, - LocalizedString_Rand2_xyXL, + LocalizedStringRandEnUs, + LocalizedStringRand2DeDe, + LocalizedStringRand2EsXl, + LocalizedStringRand2XyXl, }; - public static readonly IccMultiLocalizedUnicodeTagDataEntry MultiLocalizedUnicode_Val = new(LocalizedString_RandArr_enUS_deDE); - public static readonly byte[] MultiLocalizedUnicode_Arr = ArrayHelper.Concat( - IccTestDataPrimitives.UInt32_2, + public static readonly IccMultiLocalizedUnicodeTagDataEntry MultiLocalizedUnicodeVal = new(LocalizedStringRandArrEnUsDeDe); + public static readonly byte[] MultiLocalizedUnicodeArr = ArrayHelper.Concat( + IccTestDataPrimitives.UInt322, new byte[] { 0x00, 0x00, 0x00, 0x0C }, // 12 new byte[] { (byte)'e', (byte)'n', (byte)'U', (byte)'S' }, new byte[] { 0x00, 0x00, 0x00, 0x0C }, // 12 @@ -408,12 +391,12 @@ internal static class IccTestDataTagDataEntry new byte[] { (byte)'d', (byte)'e', (byte)'D', (byte)'E' }, new byte[] { 0x00, 0x00, 0x00, 0x0E }, // 14 new byte[] { 0x00, 0x00, 0x00, 0x34 }, // 52 - IccTestDataPrimitives.Unicode_Rand2, - IccTestDataPrimitives.Unicode_Rand3); + IccTestDataPrimitives.UnicodeRand2, + IccTestDataPrimitives.UnicodeRand3); - public static readonly IccMultiLocalizedUnicodeTagDataEntry MultiLocalizedUnicode_Val2 = new(LocalizedString_RandArr_en_Invariant); - public static readonly byte[] MultiLocalizedUnicode_Arr2_Read = ArrayHelper.Concat( - IccTestDataPrimitives.UInt32_2, + public static readonly IccMultiLocalizedUnicodeTagDataEntry MultiLocalizedUnicodeVal2 = new(LocalizedStringRandArrEnInvariant); + public static readonly byte[] MultiLocalizedUnicodeArr2Read = ArrayHelper.Concat( + IccTestDataPrimitives.UInt322, new byte[] { 0x00, 0x00, 0x00, 0x0C }, // 12 new byte[] { (byte)'e', (byte)'n', 0x00, 0x00 }, new byte[] { 0x00, 0x00, 0x00, 0x0C }, // 12 @@ -421,11 +404,11 @@ internal static class IccTestDataTagDataEntry new byte[] { 0x00, 0x00, 0x00, 0x00 }, new byte[] { 0x00, 0x00, 0x00, 0x0E }, // 14 new byte[] { 0x00, 0x00, 0x00, 0x34 }, // 52 - IccTestDataPrimitives.Unicode_Rand2, - IccTestDataPrimitives.Unicode_Rand3); + IccTestDataPrimitives.UnicodeRand2, + IccTestDataPrimitives.UnicodeRand3); - public static readonly byte[] MultiLocalizedUnicode_Arr2_Write = ArrayHelper.Concat( - IccTestDataPrimitives.UInt32_2, + public static readonly byte[] MultiLocalizedUnicodeArr2Write = ArrayHelper.Concat( + IccTestDataPrimitives.UInt322, new byte[] { 0x00, 0x00, 0x00, 0x0C }, // 12 new byte[] { (byte)'e', (byte)'n', 0x00, 0x00 }, new byte[] { 0x00, 0x00, 0x00, 0x0C }, // 12 @@ -433,12 +416,12 @@ internal static class IccTestDataTagDataEntry new byte[] { (byte)'x', (byte)'x', 0x00, 0x00 }, new byte[] { 0x00, 0x00, 0x00, 0x0E }, // 14 new byte[] { 0x00, 0x00, 0x00, 0x34 }, // 52 - IccTestDataPrimitives.Unicode_Rand2, - IccTestDataPrimitives.Unicode_Rand3); + IccTestDataPrimitives.UnicodeRand2, + IccTestDataPrimitives.UnicodeRand3); - public static readonly IccMultiLocalizedUnicodeTagDataEntry MultiLocalizedUnicode_Val3 = new(LocalizedString_SameArr_enUS_deDE_esXL_xyXL); - public static readonly byte[] MultiLocalizedUnicode_Arr3 = ArrayHelper.Concat( - IccTestDataPrimitives.UInt32_4, + public static readonly IccMultiLocalizedUnicodeTagDataEntry MultiLocalizedUnicodeVal3 = new(LocalizedStringSameArrEnUsDeDeEsXlXyXl); + public static readonly byte[] MultiLocalizedUnicodeArr3 = ArrayHelper.Concat( + IccTestDataPrimitives.UInt324, new byte[] { 0x00, 0x00, 0x00, 0x0C }, // 12 new byte[] { (byte)'e', (byte)'n', (byte)'U', (byte)'S' }, new byte[] { 0x00, 0x00, 0x00, 0x0C }, // 12 @@ -452,374 +435,374 @@ internal static class IccTestDataTagDataEntry new byte[] { (byte)'x', (byte)'y', (byte)'X', (byte)'L' }, new byte[] { 0x00, 0x00, 0x00, 0x0C }, // 12 new byte[] { 0x00, 0x00, 0x00, 0x40 }, // 64 - IccTestDataPrimitives.Unicode_Rand2); + IccTestDataPrimitives.UnicodeRand2); - public static readonly object[][] MultiLocalizedUnicodeTagDataEntryTestData_Read = + public static readonly object[][] MultiLocalizedUnicodeTagDataEntryTestDataRead = { - new object[] { MultiLocalizedUnicode_Arr, MultiLocalizedUnicode_Val }, - new object[] { MultiLocalizedUnicode_Arr2_Read, MultiLocalizedUnicode_Val2 }, - new object[] { MultiLocalizedUnicode_Arr3, MultiLocalizedUnicode_Val3 }, + new object[] { MultiLocalizedUnicodeArr, MultiLocalizedUnicodeVal }, + new object[] { MultiLocalizedUnicodeArr2Read, MultiLocalizedUnicodeVal2 }, + new object[] { MultiLocalizedUnicodeArr3, MultiLocalizedUnicodeVal3 }, }; - public static readonly object[][] MultiLocalizedUnicodeTagDataEntryTestData_Write = + public static readonly object[][] MultiLocalizedUnicodeTagDataEntryTestDataWrite = { - new object[] { MultiLocalizedUnicode_Arr, MultiLocalizedUnicode_Val }, - new object[] { MultiLocalizedUnicode_Arr2_Write, MultiLocalizedUnicode_Val2 }, - new object[] { MultiLocalizedUnicode_Arr3, MultiLocalizedUnicode_Val3 }, + new object[] { MultiLocalizedUnicodeArr, MultiLocalizedUnicodeVal }, + new object[] { MultiLocalizedUnicodeArr2Write, MultiLocalizedUnicodeVal2 }, + new object[] { MultiLocalizedUnicodeArr3, MultiLocalizedUnicodeVal3 }, }; - public static readonly IccMultiProcessElementsTagDataEntry MultiProcessElements_Val = new( + public static readonly IccMultiProcessElementsTagDataEntry MultiProcessElementsVal = new( new IccMultiProcessElement[] { - IccTestDataMultiProcessElements.MPE_ValCLUT, - IccTestDataMultiProcessElements.MPE_ValCLUT, + IccTestDataMultiProcessElements.MpeValClut, + IccTestDataMultiProcessElements.MpeValClut, }); - public static readonly byte[] MultiProcessElements_Arr = ArrayHelper.Concat( - IccTestDataPrimitives.UInt16_2, - IccTestDataPrimitives.UInt16_3, - IccTestDataPrimitives.UInt32_2, + public static readonly byte[] MultiProcessElementsArr = ArrayHelper.Concat( + IccTestDataPrimitives.UInt162, + IccTestDataPrimitives.UInt163, + IccTestDataPrimitives.UInt322, new byte[] { 0x00, 0x00, 0x00, 0x20 }, // 32 new byte[] { 0x00, 0x00, 0x00, 0x84 }, // 132 new byte[] { 0x00, 0x00, 0x00, 0xA4 }, // 164 new byte[] { 0x00, 0x00, 0x00, 0x84 }, // 132 - IccTestDataMultiProcessElements.MPE_CLUT, - IccTestDataMultiProcessElements.MPE_CLUT); + IccTestDataMultiProcessElements.MpeClut, + IccTestDataMultiProcessElements.MpeClut); public static readonly object[][] MultiProcessElementsTagDataEntryTestData = { - new object[] { MultiProcessElements_Arr, MultiProcessElements_Val }, + new object[] { MultiProcessElementsArr, MultiProcessElementsVal }, }; - public static readonly IccNamedColor2TagDataEntry NamedColor2_Val = new( + public static readonly IccNamedColor2TagDataEntry NamedColor2Val = new( 16909060, ArrayHelper.Fill('A', 31), ArrayHelper.Fill('4', 31), - new IccNamedColor[] { IccTestDataNonPrimitives.NamedColor_ValMin, IccTestDataNonPrimitives.NamedColor_ValMin }); + new IccNamedColor[] { IccTestDataNonPrimitives.NamedColorValMin, IccTestDataNonPrimitives.NamedColorValMin }); - public static readonly byte[] NamedColor2_Arr = ArrayHelper.Concat( + public static readonly byte[] NamedColor2Arr = ArrayHelper.Concat( new byte[] { 0x01, 0x02, 0x03, 0x04 }, - IccTestDataPrimitives.UInt32_2, - IccTestDataPrimitives.UInt32_3, + IccTestDataPrimitives.UInt322, + IccTestDataPrimitives.UInt323, ArrayHelper.Fill((byte)0x41, 31), new byte[] { 0x00 }, ArrayHelper.Fill((byte)0x34, 31), new byte[] { 0x00 }, - IccTestDataNonPrimitives.NamedColor_Min, - IccTestDataNonPrimitives.NamedColor_Min); + IccTestDataNonPrimitives.NamedColorMin, + IccTestDataNonPrimitives.NamedColorMin); public static readonly object[][] NamedColor2TagDataEntryTestData = { - new object[] { NamedColor2_Arr, NamedColor2_Val }, + new object[] { NamedColor2Arr, NamedColor2Val }, }; - public static readonly IccParametricCurveTagDataEntry ParametricCurve_Val = new(IccTestDataCurves.Parametric_ValVar1); - public static readonly byte[] ParametricCurve_Arr = IccTestDataCurves.Parametric_Var1; + public static readonly IccParametricCurveTagDataEntry ParametricCurveVal = new(IccTestDataCurves.ParametricValVar1); + public static readonly byte[] ParametricCurveArr = IccTestDataCurves.ParametricVar1; public static readonly object[][] ParametricCurveTagDataEntryTestData = { - new object[] { ParametricCurve_Arr, ParametricCurve_Val }, + new object[] { ParametricCurveArr, ParametricCurveVal }, }; - public static readonly IccProfileSequenceDescTagDataEntry ProfileSequenceDesc_Val = new( + public static readonly IccProfileSequenceDescTagDataEntry ProfileSequenceDescVal = new( new IccProfileDescription[] { - IccTestDataNonPrimitives.ProfileDescription_ValRand1, - IccTestDataNonPrimitives.ProfileDescription_ValRand1 + IccTestDataNonPrimitives.ProfileDescriptionValRand1, + IccTestDataNonPrimitives.ProfileDescriptionValRand1 }); - public static readonly byte[] ProfileSequenceDesc_Arr = ArrayHelper.Concat( - IccTestDataPrimitives.UInt32_2, - IccTestDataNonPrimitives.ProfileDescription_Rand1, - IccTestDataNonPrimitives.ProfileDescription_Rand1); + public static readonly byte[] ProfileSequenceDescArr = ArrayHelper.Concat( + IccTestDataPrimitives.UInt322, + IccTestDataNonPrimitives.ProfileDescriptionRand1, + IccTestDataNonPrimitives.ProfileDescriptionRand1); public static readonly object[][] ProfileSequenceDescTagDataEntryTestData = { - new object[] { ProfileSequenceDesc_Arr, ProfileSequenceDesc_Val }, + new object[] { ProfileSequenceDescArr, ProfileSequenceDescVal }, }; public static readonly IccProfileSequenceIdentifierTagDataEntry ProfileSequenceIdentifier_Val = new( - new IccProfileSequenceIdentifier[] + new[] { - new IccProfileSequenceIdentifier(IccTestDataNonPrimitives.ProfileId_ValRand, LocalizedString_RandArr_enUS_deDE), - new IccProfileSequenceIdentifier(IccTestDataNonPrimitives.ProfileId_ValRand, LocalizedString_RandArr_enUS_deDE), + new IccProfileSequenceIdentifier(IccTestDataNonPrimitives.ProfileIdValRand, LocalizedStringRandArrEnUsDeDe), + new IccProfileSequenceIdentifier(IccTestDataNonPrimitives.ProfileIdValRand, LocalizedStringRandArrEnUsDeDe), }); - public static readonly byte[] ProfileSequenceIdentifier_Arr = ArrayHelper.Concat( - IccTestDataPrimitives.UInt32_2, + public static readonly byte[] ProfileSequenceIdentifierArr = ArrayHelper.Concat( + IccTestDataPrimitives.UInt322, new byte[] { 0x00, 0x00, 0x00, 0x1C }, // 28 new byte[] { 0x00, 0x00, 0x00, 0x54 }, // 84 new byte[] { 0x00, 0x00, 0x00, 0x70 }, // 112 new byte[] { 0x00, 0x00, 0x00, 0x54 }, // 84 - IccTestDataNonPrimitives.ProfileId_Rand, // 16 bytes - TagDataEntryHeader_MultiLocalizedUnicodeArr, // 8 bytes - MultiLocalizedUnicode_Arr, // 58 bytes + IccTestDataNonPrimitives.ProfileIdRand, // 16 bytes + TagDataEntryHeaderMultiLocalizedUnicodeArr, // 8 bytes + MultiLocalizedUnicodeArr, // 58 bytes new byte[] { 0x00, 0x00 }, // 2 bytes (padding) - IccTestDataNonPrimitives.ProfileId_Rand, - TagDataEntryHeader_MultiLocalizedUnicodeArr, - MultiLocalizedUnicode_Arr, + IccTestDataNonPrimitives.ProfileIdRand, + TagDataEntryHeaderMultiLocalizedUnicodeArr, + MultiLocalizedUnicodeArr, new byte[] { 0x00, 0x00 }); public static readonly object[][] ProfileSequenceIdentifierTagDataEntryTestData = { - new object[] { ProfileSequenceIdentifier_Arr, ProfileSequenceIdentifier_Val }, + new object[] { ProfileSequenceIdentifierArr, ProfileSequenceIdentifier_Val }, }; - public static readonly IccResponseCurveSet16TagDataEntry ResponseCurveSet16_Val = new( - new IccResponseCurve[] + public static readonly IccResponseCurveSet16TagDataEntry ResponseCurveSet16Val = new( + new[] { - IccTestDataCurves.Response_ValGrad, - IccTestDataCurves.Response_ValGrad, + IccTestDataCurves.ResponseValGrad, + IccTestDataCurves.ResponseValGrad, }); - public static readonly byte[] ResponseCurveSet16_Arr = ArrayHelper.Concat( - IccTestDataPrimitives.UInt16_3, - IccTestDataPrimitives.UInt16_2, + public static readonly byte[] ResponseCurveSet16Arr = ArrayHelper.Concat( + IccTestDataPrimitives.UInt163, + IccTestDataPrimitives.UInt162, new byte[] { 0x00, 0x00, 0x00, 0x14 }, // 20 new byte[] { 0x00, 0x00, 0x00, 0x6C }, // 108 - IccTestDataCurves.Response_Grad, // 88 bytes - IccTestDataCurves.Response_Grad); // 88 bytes + IccTestDataCurves.ResponseGrad, // 88 bytes + IccTestDataCurves.ResponseGrad); // 88 bytes public static readonly object[][] ResponseCurveSet16TagDataEntryTestData = { - new object[] { ResponseCurveSet16_Arr, ResponseCurveSet16_Val }, + new object[] { ResponseCurveSet16Arr, ResponseCurveSet16Val }, }; - public static readonly IccFix16ArrayTagDataEntry Fix16Array_Val = new(new float[] { 1 / 256f, 2 / 256f, 3 / 256f }); - public static readonly byte[] Fix16Array_Arr = ArrayHelper.Concat( - IccTestDataPrimitives.Fix16_1, - IccTestDataPrimitives.Fix16_2, - IccTestDataPrimitives.Fix16_3); + public static readonly IccFix16ArrayTagDataEntry Fix16ArrayVal = new(new[] { 1 / 256f, 2 / 256f, 3 / 256f }); + public static readonly byte[] Fix16ArrayArr = ArrayHelper.Concat( + IccTestDataPrimitives.Fix161, + IccTestDataPrimitives.Fix162, + IccTestDataPrimitives.Fix163); public static readonly object[][] Fix16ArrayTagDataEntryTestData = { - new object[] { Fix16Array_Arr, Fix16Array_Val, 20u }, + new object[] { Fix16ArrayArr, Fix16ArrayVal, 20u }, }; - public static readonly IccSignatureTagDataEntry Signature_Val = new("ABCD"); - public static readonly byte[] Signature_Arr = { 0x41, 0x42, 0x43, 0x44, }; + public static readonly IccSignatureTagDataEntry SignatureVal = new("ABCD"); + public static readonly byte[] SignatureArr = { 0x41, 0x42, 0x43, 0x44, }; public static readonly object[][] SignatureTagDataEntryTestData = { - new object[] { Signature_Arr, Signature_Val }, + new object[] { SignatureArr, SignatureVal }, }; - public static readonly IccTextTagDataEntry Text_Val = new("ABCD"); - public static readonly byte[] Text_Arr = { 0x41, 0x42, 0x43, 0x44 }; + public static readonly IccTextTagDataEntry TextVal = new("ABCD"); + public static readonly byte[] TextArr = { 0x41, 0x42, 0x43, 0x44 }; public static readonly object[][] TextTagDataEntryTestData = { - new object[] { Text_Arr, Text_Val, 12u }, + new object[] { TextArr, TextVal, 12u }, }; - public static readonly IccUFix16ArrayTagDataEntry UFix16Array_Val = new(new float[] { 1, 2, 3 }); - public static readonly byte[] UFix16Array_Arr = ArrayHelper.Concat( - IccTestDataPrimitives.UFix16_1, - IccTestDataPrimitives.UFix16_2, - IccTestDataPrimitives.UFix16_3); + public static readonly IccUFix16ArrayTagDataEntry UFix16ArrayVal = new(new float[] { 1, 2, 3 }); + public static readonly byte[] UFix16ArrayArr = ArrayHelper.Concat( + IccTestDataPrimitives.UFix161, + IccTestDataPrimitives.UFix162, + IccTestDataPrimitives.UFix163); public static readonly object[][] UFix16ArrayTagDataEntryTestData = { - new object[] { UFix16Array_Arr, UFix16Array_Val, 20u }, + new object[] { UFix16ArrayArr, UFix16ArrayVal, 20u }, }; - public static readonly IccUInt16ArrayTagDataEntry UInt16Array_Val = new(new ushort[] { 1, 2, 3 }); - public static readonly byte[] UInt16Array_Arr = ArrayHelper.Concat( - IccTestDataPrimitives.UInt16_1, - IccTestDataPrimitives.UInt16_2, - IccTestDataPrimitives.UInt16_3); + public static readonly IccUInt16ArrayTagDataEntry UInt16ArrayVal = new(new ushort[] { 1, 2, 3 }); + public static readonly byte[] UInt16ArrayArr = ArrayHelper.Concat( + IccTestDataPrimitives.UInt161, + IccTestDataPrimitives.UInt162, + IccTestDataPrimitives.UInt163); public static readonly object[][] UInt16ArrayTagDataEntryTestData = { - new object[] { UInt16Array_Arr, UInt16Array_Val, 14u }, + new object[] { UInt16ArrayArr, UInt16ArrayVal, 14u }, }; - public static readonly IccUInt32ArrayTagDataEntry UInt32Array_Val = new(new uint[] { 1, 2, 3 }); - public static readonly byte[] UInt32Array_Arr = ArrayHelper.Concat( - IccTestDataPrimitives.UInt32_1, - IccTestDataPrimitives.UInt32_2, - IccTestDataPrimitives.UInt32_3); + public static readonly IccUInt32ArrayTagDataEntry UInt32ArrayVal = new(new uint[] { 1, 2, 3 }); + public static readonly byte[] UInt32ArrayArr = ArrayHelper.Concat( + IccTestDataPrimitives.UInt321, + IccTestDataPrimitives.UInt322, + IccTestDataPrimitives.UInt323); public static readonly object[][] UInt32ArrayTagDataEntryTestData = { - new object[] { UInt32Array_Arr, UInt32Array_Val, 20u }, + new object[] { UInt32ArrayArr, UInt32ArrayVal, 20u }, }; - public static readonly IccUInt64ArrayTagDataEntry UInt64Array_Val = new(new ulong[] { 1, 2, 3 }); - public static readonly byte[] UInt64Array_Arr = ArrayHelper.Concat( - IccTestDataPrimitives.UInt64_1, - IccTestDataPrimitives.UInt64_2, - IccTestDataPrimitives.UInt64_3); + public static readonly IccUInt64ArrayTagDataEntry UInt64ArrayVal = new(new ulong[] { 1, 2, 3 }); + public static readonly byte[] UInt64ArrayArr = ArrayHelper.Concat( + IccTestDataPrimitives.UInt641, + IccTestDataPrimitives.UInt642, + IccTestDataPrimitives.UInt643); public static readonly object[][] UInt64ArrayTagDataEntryTestData = { - new object[] { UInt64Array_Arr, UInt64Array_Val, 32u }, + new object[] { UInt64ArrayArr, UInt64ArrayVal, 32u }, }; - public static readonly IccUInt8ArrayTagDataEntry UInt8Array_Val = new(new byte[] { 1, 2, 3 }); - public static readonly byte[] UInt8Array_Arr = { 1, 2, 3 }; + public static readonly IccUInt8ArrayTagDataEntry UInt8ArrayVal = new(new byte[] { 1, 2, 3 }); + public static readonly byte[] UInt8ArrayArr = { 1, 2, 3 }; public static readonly object[][] UInt8ArrayTagDataEntryTestData = { - new object[] { UInt8Array_Arr, UInt8Array_Val, 11u }, + new object[] { UInt8ArrayArr, UInt8ArrayVal, 11u }, }; - public static readonly IccViewingConditionsTagDataEntry ViewingConditions_Val = new( - IccTestDataNonPrimitives.XyzNumber_ValVar1, - IccTestDataNonPrimitives.XyzNumber_ValVar2, + public static readonly IccViewingConditionsTagDataEntry ViewingConditionsVal = new( + IccTestDataNonPrimitives.XyzNumberValVar1, + IccTestDataNonPrimitives.XyzNumberValVar2, IccStandardIlluminant.D50); - public static readonly byte[] ViewingConditions_Arr = ArrayHelper.Concat( - IccTestDataNonPrimitives.XyzNumber_Var1, - IccTestDataNonPrimitives.XyzNumber_Var2, - IccTestDataPrimitives.UInt32_1); + public static readonly byte[] ViewingConditionsArr = ArrayHelper.Concat( + IccTestDataNonPrimitives.XyzNumberVar1, + IccTestDataNonPrimitives.XyzNumberVar2, + IccTestDataPrimitives.UInt321); public static readonly object[][] ViewingConditionsTagDataEntryTestData = { - new object[] { ViewingConditions_Arr, ViewingConditions_Val }, + new object[] { ViewingConditionsArr, ViewingConditionsVal }, }; - public static readonly IccXyzTagDataEntry XYZ_Val = new(new Vector3[] + public static readonly IccXyzTagDataEntry XyzVal = new(new[] { - IccTestDataNonPrimitives.XyzNumber_ValVar1, - IccTestDataNonPrimitives.XyzNumber_ValVar2, - IccTestDataNonPrimitives.XyzNumber_ValVar3, + IccTestDataNonPrimitives.XyzNumberValVar1, + IccTestDataNonPrimitives.XyzNumberValVar2, + IccTestDataNonPrimitives.XyzNumberValVar3, }); - public static readonly byte[] XYZ_Arr = ArrayHelper.Concat( - IccTestDataNonPrimitives.XyzNumber_Var1, - IccTestDataNonPrimitives.XyzNumber_Var2, - IccTestDataNonPrimitives.XyzNumber_Var3); + public static readonly byte[] XyzArr = ArrayHelper.Concat( + IccTestDataNonPrimitives.XyzNumberVar1, + IccTestDataNonPrimitives.XyzNumberVar2, + IccTestDataNonPrimitives.XyzNumberVar3); public static readonly object[][] XYZTagDataEntryTestData = { - new object[] { XYZ_Arr, XYZ_Val, 44u }, + new object[] { XyzArr, XyzVal, 44u }, }; - public static readonly IccTextDescriptionTagDataEntry TextDescription_Val1 = new( - IccTestDataPrimitives.Ascii_ValRand, - IccTestDataPrimitives.Unicode_ValRand1, + public static readonly IccTextDescriptionTagDataEntry TextDescriptionVal1 = new( + IccTestDataPrimitives.AsciiValRand, + IccTestDataPrimitives.UnicodeValRand1, ArrayHelper.Fill('A', 66), 1701729619, 2); - public static readonly byte[] TextDescription_Arr1 = ArrayHelper.Concat( + public static readonly byte[] TextDescriptionArr1 = ArrayHelper.Concat( new byte[] { 0x00, 0x00, 0x00, 0x0B }, // 11 - IccTestDataPrimitives.Ascii_Rand, + IccTestDataPrimitives.AsciiRand, new byte[] { 0x00 }, // Null terminator new byte[] { 0x65, 0x6E, 0x55, 0x53 }, // enUS new byte[] { 0x00, 0x00, 0x00, 0x0E }, // 14 - IccTestDataPrimitives.Unicode_Rand1, + IccTestDataPrimitives.UnicodeRand1, new byte[] { 0x00, 0x00 }, // Null terminator new byte[] { 0x00, 0x02, 0x43 }, // 2, 67 ArrayHelper.Fill((byte)0x41, 66), new byte[] { 0x00 }); // Null terminator - public static readonly IccTextDescriptionTagDataEntry TextDescription_Val2 = new(IccTestDataPrimitives.Ascii_ValRand, null, null, 0, 0); - public static readonly byte[] TextDescription_Arr2 = ArrayHelper.Concat( + public static readonly IccTextDescriptionTagDataEntry TextDescriptionVal2 = new(IccTestDataPrimitives.AsciiValRand, null, null, 0, 0); + public static readonly byte[] TextDescriptionArr2 = ArrayHelper.Concat( new byte[] { 0x00, 0x00, 0x00, 0x0B }, // 11 - IccTestDataPrimitives.Ascii_Rand, + IccTestDataPrimitives.AsciiRand, new byte[] { 0x00 }, // Null terminator - IccTestDataPrimitives.UInt32_0, - IccTestDataPrimitives.UInt32_0, + IccTestDataPrimitives.UInt320, + IccTestDataPrimitives.UInt320, new byte[] { 0x00, 0x00, 0x00 }, // 0, 0 ArrayHelper.Fill((byte)0x00, 67)); public static readonly object[][] TextDescriptionTagDataEntryTestData = { - new object[] { TextDescription_Arr1, TextDescription_Val1 }, - new object[] { TextDescription_Arr2, TextDescription_Val2 }, + new object[] { TextDescriptionArr1, TextDescriptionVal1 }, + new object[] { TextDescriptionArr2, TextDescriptionVal2 }, }; - public static readonly IccCrdInfoTagDataEntry CrdInfo_Val = new( - IccTestDataPrimitives.Ascii_ValRand4, - IccTestDataPrimitives.Ascii_ValRand1, - IccTestDataPrimitives.Ascii_ValRand2, - IccTestDataPrimitives.Ascii_ValRand3, - IccTestDataPrimitives.Ascii_ValRand4); + public static readonly IccCrdInfoTagDataEntry CrdInfoVal = new( + IccTestDataPrimitives.AsciiValRand4, + IccTestDataPrimitives.AsciiValRand1, + IccTestDataPrimitives.AsciiValRand2, + IccTestDataPrimitives.AsciiValRand3, + IccTestDataPrimitives.AsciiValRand4); - public static readonly byte[] CrdInfo_Arr = ArrayHelper.Concat( - IccTestDataPrimitives.UInt32_6, - IccTestDataPrimitives.Ascii_Rand4, + public static readonly byte[] CrdInfoArr = ArrayHelper.Concat( + IccTestDataPrimitives.UInt326, + IccTestDataPrimitives.AsciiRand4, new byte[] { 0 }, - IccTestDataPrimitives.UInt32_6, - IccTestDataPrimitives.Ascii_Rand1, + IccTestDataPrimitives.UInt326, + IccTestDataPrimitives.AsciiRand1, new byte[] { 0 }, - IccTestDataPrimitives.UInt32_6, - IccTestDataPrimitives.Ascii_Rand2, + IccTestDataPrimitives.UInt326, + IccTestDataPrimitives.AsciiRand2, new byte[] { 0 }, - IccTestDataPrimitives.UInt32_6, - IccTestDataPrimitives.Ascii_Rand3, + IccTestDataPrimitives.UInt326, + IccTestDataPrimitives.AsciiRand3, new byte[] { 0 }, - IccTestDataPrimitives.UInt32_6, - IccTestDataPrimitives.Ascii_Rand4, + IccTestDataPrimitives.UInt326, + IccTestDataPrimitives.AsciiRand4, new byte[] { 0 }); public static readonly object[][] CrdInfoTagDataEntryTestData = { - new object[] { CrdInfo_Arr, CrdInfo_Val }, + new object[] { CrdInfoArr, CrdInfoVal }, }; - public static readonly IccScreeningTagDataEntry Screening_Val = new( + public static readonly IccScreeningTagDataEntry ScreeningVal = new( IccScreeningFlag.DefaultScreens | IccScreeningFlag.UnitLinesPerCm, - new IccScreeningChannel[] { IccTestDataNonPrimitives.ScreeningChannel_ValRand1, IccTestDataNonPrimitives.ScreeningChannel_ValRand2 }); + new IccScreeningChannel[] { IccTestDataNonPrimitives.ScreeningChannelValRand1, IccTestDataNonPrimitives.ScreeningChannelValRand2 }); - public static readonly byte[] Screening_Arr = ArrayHelper.Concat( - IccTestDataPrimitives.Int32_1, - IccTestDataPrimitives.UInt32_2, - IccTestDataNonPrimitives.ScreeningChannel_Rand1, - IccTestDataNonPrimitives.ScreeningChannel_Rand2); + public static readonly byte[] ScreeningArr = ArrayHelper.Concat( + IccTestDataPrimitives.Int321, + IccTestDataPrimitives.UInt322, + IccTestDataNonPrimitives.ScreeningChannelRand1, + IccTestDataNonPrimitives.ScreeningChannelRand2); public static readonly object[][] ScreeningTagDataEntryTestData = { - new object[] { Screening_Arr, Screening_Val }, + new object[] { ScreeningArr, ScreeningVal }, }; - public static readonly IccUcrBgTagDataEntry UcrBg_Val = new( + public static readonly IccUcrBgTagDataEntry UcrBgVal = new( new ushort[] { 3, 4, 6 }, new ushort[] { 9, 7, 2, 5 }, - IccTestDataPrimitives.Ascii_ValRand); - - public static readonly byte[] UcrBg_Arr = ArrayHelper.Concat( - IccTestDataPrimitives.UInt32_3, - IccTestDataPrimitives.UInt16_3, - IccTestDataPrimitives.UInt16_4, - IccTestDataPrimitives.UInt16_6, - IccTestDataPrimitives.UInt32_4, - IccTestDataPrimitives.UInt16_9, - IccTestDataPrimitives.UInt16_7, - IccTestDataPrimitives.UInt16_2, - IccTestDataPrimitives.UInt16_5, - IccTestDataPrimitives.Ascii_Rand, + IccTestDataPrimitives.AsciiValRand); + + public static readonly byte[] UcrBgArr = ArrayHelper.Concat( + IccTestDataPrimitives.UInt323, + IccTestDataPrimitives.UInt163, + IccTestDataPrimitives.UInt164, + IccTestDataPrimitives.UInt166, + IccTestDataPrimitives.UInt324, + IccTestDataPrimitives.UInt169, + IccTestDataPrimitives.UInt167, + IccTestDataPrimitives.UInt162, + IccTestDataPrimitives.UInt165, + IccTestDataPrimitives.AsciiRand, new byte[] { 0 }); public static readonly object[][] UcrBgTagDataEntryTestData = { - new object[] { UcrBg_Arr, UcrBg_Val, 41 }, + new object[] { UcrBgArr, UcrBgVal, 41 }, }; - public static readonly IccTagDataEntry TagDataEntry_CurveVal = Curve_Val_2; - public static readonly byte[] TagDataEntry_CurveArr = ArrayHelper.Concat( - TagDataEntryHeader_CurveArr, - Curve_Arr_2, + public static readonly IccTagDataEntry TagDataEntryCurveVal = CurveVal2; + public static readonly byte[] TagDataEntryCurveArr = ArrayHelper.Concat( + TagDataEntryHeaderCurveArr, + CurveArr2, new byte[] { 0x00, 0x00 }); // padding - public static readonly IccTagDataEntry TagDataEntry_MultiLocalizedUnicodeVal = MultiLocalizedUnicode_Val; - public static readonly byte[] TagDataEntry_MultiLocalizedUnicodeArr = ArrayHelper.Concat( - TagDataEntryHeader_MultiLocalizedUnicodeArr, - MultiLocalizedUnicode_Arr, + public static readonly IccTagDataEntry TagDataEntryMultiLocalizedUnicodeVal = MultiLocalizedUnicodeVal; + public static readonly byte[] TagDataEntryMultiLocalizedUnicodeArr = ArrayHelper.Concat( + TagDataEntryHeaderMultiLocalizedUnicodeArr, + MultiLocalizedUnicodeArr, new byte[] { 0x00, 0x00 }); // padding - public static readonly IccTagTableEntry TagDataEntry_MultiLocalizedUnicodeTable = new( + public static readonly IccTagTableEntry TagDataEntryMultiLocalizedUnicodeTable = new( IccProfileTag.Unknown, 0, - (uint)TagDataEntry_MultiLocalizedUnicodeArr.Length - 2); + (uint)TagDataEntryMultiLocalizedUnicodeArr.Length - 2); - public static readonly IccTagTableEntry TagDataEntry_CurveTable = new(IccProfileTag.Unknown, 0, (uint)TagDataEntry_CurveArr.Length - 2); + public static readonly IccTagTableEntry TagDataEntryCurveTable = new(IccProfileTag.Unknown, 0, (uint)TagDataEntryCurveArr.Length - 2); public static readonly object[][] TagDataEntryTestData = { - new object[] { TagDataEntry_CurveArr, TagDataEntry_CurveVal }, - new object[] { TagDataEntry_MultiLocalizedUnicodeArr, TagDataEntry_MultiLocalizedUnicodeVal }, + new object[] { TagDataEntryCurveArr, TagDataEntryCurveVal }, + new object[] { TagDataEntryMultiLocalizedUnicodeArr, TagDataEntryMultiLocalizedUnicodeVal }, }; } diff --git a/tests/ImageSharp.Tests/TestDataIcc/Profiles/CGATS21_CRPC7.icc b/tests/ImageSharp.Tests/TestDataIcc/Profiles/CGATS21_CRPC7.icc new file mode 100644 index 0000000000..c4b7084721 --- /dev/null +++ b/tests/ImageSharp.Tests/TestDataIcc/Profiles/CGATS21_CRPC7.icc @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2b186e6dadc38883138ccd30203b2870fb71db6451d3a5d24f9590cfabd26689 +size 3462496 diff --git a/tests/ImageSharp.Tests/TestDataIcc/Profiles/Coated_Fogra39L_VIGC_300.icc b/tests/ImageSharp.Tests/TestDataIcc/Profiles/Coated_Fogra39L_VIGC_300.icc new file mode 100644 index 0000000000..a21b7f657d --- /dev/null +++ b/tests/ImageSharp.Tests/TestDataIcc/Profiles/Coated_Fogra39L_VIGC_300.icc @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6df43849a84d2632e7900a125f657bd09364ed56775bc4740c1e39a5492d47e3 +size 8652444 diff --git a/tests/ImageSharp.Tests/TestDataIcc/Profiles/ISO22028-2_ROMM-RGB.icc b/tests/ImageSharp.Tests/TestDataIcc/Profiles/ISO22028-2_ROMM-RGB.icc new file mode 100644 index 0000000000..b06abf217a --- /dev/null +++ b/tests/ImageSharp.Tests/TestDataIcc/Profiles/ISO22028-2_ROMM-RGB.icc @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:96b2f2987f83e2a545e607799fbfdff43ef8158fb9b215b187c574db8f145aaf +size 864 diff --git a/tests/ImageSharp.Tests/TestDataIcc/Profiles/JapanColor2003WebCoated.icc b/tests/ImageSharp.Tests/TestDataIcc/Profiles/JapanColor2003WebCoated.icc new file mode 100644 index 0000000000..028a3cde63 --- /dev/null +++ b/tests/ImageSharp.Tests/TestDataIcc/Profiles/JapanColor2003WebCoated.icc @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:662a345063b2853a66ed12dc54215e513e8485cbf4cb7f673971c834979eb25f +size 654432 diff --git a/tests/ImageSharp.Tests/TestDataIcc/Profiles/JapanColor2011Coated.icc b/tests/ImageSharp.Tests/TestDataIcc/Profiles/JapanColor2011Coated.icc new file mode 100644 index 0000000000..ee8dde35aa --- /dev/null +++ b/tests/ImageSharp.Tests/TestDataIcc/Profiles/JapanColor2011Coated.icc @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:73202ea802e57a63a0be05ed993fde8e4d51cc436120e6c47815ce785ff42916 +size 1979304 diff --git a/tests/ImageSharp.Tests/TestDataIcc/Profiles/SWOP2006_Coated5v2.icc b/tests/ImageSharp.Tests/TestDataIcc/Profiles/SWOP2006_Coated5v2.icc new file mode 100644 index 0000000000..e24f272f35 --- /dev/null +++ b/tests/ImageSharp.Tests/TestDataIcc/Profiles/SWOP2006_Coated5v2.icc @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0ac00fe6f03901bfd06ef70e72ec2c55fa3c043c6c34c0b6d70f06cc7a40a822 +size 2747952 diff --git a/tests/ImageSharp.Tests/TestDataIcc/Profiles/sRGB2014.icc b/tests/ImageSharp.Tests/TestDataIcc/Profiles/sRGB2014.icc new file mode 100644 index 0000000000..46916dd8ce --- /dev/null +++ b/tests/ImageSharp.Tests/TestDataIcc/Profiles/sRGB2014.icc @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:384b832de3412066743b52a75ee906b6fb9fb8d9e09e936fc2c43223815c6e0a +size 3024 diff --git a/tests/ImageSharp.Tests/TestDataIcc/Profiles/sRGB_v4_ICC_preference.icc b/tests/ImageSharp.Tests/TestDataIcc/Profiles/sRGB_v4_ICC_preference.icc new file mode 100644 index 0000000000..8ddb31b2b8 --- /dev/null +++ b/tests/ImageSharp.Tests/TestDataIcc/Profiles/sRGB_v4_ICC_preference.icc @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:83174717332326ddc198d9df188a4daec27b8979ba152cebbfc470c793d0bb11 +size 60960 diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 53f512df8b..373b38eee4 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -76,6 +76,7 @@ public static class TestImages public const string FrameOffset = "Png/animated/frame-offset.png"; public const string DefaultNotAnimated = "Png/animated/default-not-animated.png"; public const string Issue2666 = "Png/issues/Issue_2666.png"; + public const string Issue2882 = "Png/issues/Issue_2882.png"; // Filtered test images from http://www.schaik.com/pngsuite/pngsuite_fil_png.html public const string Filter0 = "Png/filter0.png"; @@ -202,6 +203,17 @@ public static class TestImages public static class Jpeg { + public static class ICC + { + public const string SRgb = "Jpg/icc-profiles/Momiji-sRGB-yes.jpg"; + public const string AdobeRgb = "Jpg/icc-profiles/Momiji-AdobeRGB-yes.jpg"; + public const string ColorMatch = "Jpg/icc-profiles/Momiji-ColorMatch-yes.jpg"; + public const string ProPhoto = "Jpg/icc-profiles/Momiji-ProPhoto-yes.jpg"; + public const string WideRGB = "Jpg/icc-profiles/Momiji-WideRGB-yes.jpg"; + public const string AppleRGB = "Jpg/icc-profiles/Momiji-AppleRGB-yes.jpg"; + public const string CMYK = "Jpg/icc-profiles/issue-129.jpg"; + } + public static class Progressive { public const string Fb = "Jpg/progressive/fb.jpg"; @@ -509,6 +521,31 @@ public static class TestImages public const string Bit18RGBCube = "Gif/18-bit_RGB_Cube.gif"; public const string Global256NoTrans = "Gif/global-256-no-trans.gif"; + // Test images from: https://github.com/peterdn/gif-test-suite.git + // Animated gif with 4 frames, looping forever, no transparency. + public const string AnimatedLoop = "Gif/animated_loop.gif"; + + // Animated gif with 4 frames, interlaced, looping forever, no transparency. + public const string AnimatedLoopInterlaced = "Gif/animated_loop_interlaced.gif"; + + // Transparent gif with 4 frames, loops forever. + public const string AnimatedTransparentLoop = "Gif/animated_transparent_loop.gif"; + + // Transparent gif with 4 frames, loops forever, first frame restore previous. + public const string AnimatedTransparentFirstFrameRestorePrev = "Gif/animated_transparent_firstframerestoreprev_loop.gif"; + + // Transparent gif with 4 transparent frames, loops forever, no dispose + public const string AnimatedTransparentNoRestore = "Gif/animated_transparent_frame_norestore_loop.gif"; + + // Transparent gif with 4 transparent frames, loops forever, restore previous. + public const string AnimatedTransparentRestorePrevious = "Gif/animated_transparent_frame_restoreprev_loop.gif"; + + // Static gif with no animation, no transparency. + public const string StaticNontransparent = "Gif/static_nontransparent.gif"; + + // Static transparent gif with no animation. + public const string StaticTransparent = "Gif/static_transparent.gif"; + // Test images from https://github.com/robert-ancell/pygif/tree/master/test-suite public const string ZeroSize = "Gif/image-zero-size.gif"; public const string ZeroHeight = "Gif/image-zero-height.gif"; @@ -537,6 +574,7 @@ public static class TestImages public const string Issue2450_B = "Gif/issues/issue_2450_2.gif"; public const string Issue2198 = "Gif/issues/issue_2198.gif"; public const string Issue2758 = "Gif/issues/issue_2758.gif"; + public const string Issue2866 = "Gif/issues/issue_2866.gif"; public const string Issue2859_A = "Gif/issues/issue_2859_A.gif"; public const string Issue2859_B = "Gif/issues/issue_2859_B.gif"; } @@ -831,7 +869,13 @@ public static class TestImages public const string Issue2670 = "Webp/issues/Issue2670.webp"; public const string Issue2763 = "Webp/issues/Issue2763.png"; public const string Issue2801 = "Webp/issues/Issue2801.webp"; + public const string Issue2866 = "Webp/issues/Issue2866.webp"; } + + public const string AlphaBlend = "Webp/alpha-blend.webp"; + public const string AlphaBlend2 = "Webp/alpha-blend-2.webp"; + public const string AlphaBlend3 = "Webp/alpha-blend-3.webp"; + public const string AlphaBlend4 = "Webp/alpha-blend-4.webp"; } public static class Tiff diff --git a/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs b/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs index 78e5c90204..73777ef60a 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs @@ -50,8 +50,8 @@ public class ImagingTestCaseUtility } string fn = appendSourceFileOrDescription - ? Path.GetFileNameWithoutExtension(this.SourceFileOrDescription) - : string.Empty; + ? Path.GetFileNameWithoutExtension(this.SourceFileOrDescription) + : string.Empty; if (string.IsNullOrWhiteSpace(extension)) { @@ -63,7 +63,7 @@ public class ImagingTestCaseUtility extension = ".bmp"; } - extension = extension.ToLower(CultureInfo.InvariantCulture); + extension = extension.ToLowerInvariant(); if (extension[0] != '.') { diff --git a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/MagickReferenceDecoder.cs b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/MagickReferenceDecoder.cs index 57813f66ac..bdc78f3f54 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/MagickReferenceDecoder.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/MagickReferenceDecoder.cs @@ -64,20 +64,27 @@ public class MagickReferenceDecoder : ImageDecoder settings.SetDefines(pngReadDefines); using MagickImageCollection magickImageCollection = new(stream, settings); + int imageWidth = magickImageCollection.Max(x => x.Width); + int imageHeight = magickImageCollection.Max(x => x.Height); + List> framesList = []; foreach (IMagickImage magicFrame in magickImageCollection) { - ImageFrame frame = new(configuration, (int)magicFrame.Width, (int)magicFrame.Height); + ImageFrame frame = new(configuration, imageWidth, imageHeight); framesList.Add(frame); - MemoryGroup framePixels = frame.PixelBuffer.FastMemoryGroup; + Buffer2DRegion buffer = frame.PixelBuffer.GetRegion( + imageWidth - magicFrame.Width, + imageHeight - magicFrame.Height, + magicFrame.Width, + magicFrame.Height); using IUnsafePixelCollection pixels = magicFrame.GetPixelsUnsafe(); if (magicFrame.Depth is 12 or 10 or 8 or 6 or 5 or 4 or 3 or 2 or 1) { byte[] data = pixels.ToByteArray(PixelMapping.RGBA); - FromRgba32Bytes(configuration, data, framePixels); + FromRgba32Bytes(configuration, data, buffer); } else if (magicFrame.Depth is 14 or 16 or 32) { @@ -88,7 +95,7 @@ public class MagickReferenceDecoder : ImageDecoder ushort[] data = pixels.ToShortArray(PixelMapping.RGBA); Span bytes = MemoryMarshal.Cast(data.AsSpan()); - FromRgba64Bytes(configuration, bytes, framePixels); + FromRgba64Bytes(configuration, bytes, buffer); } else { @@ -111,33 +118,40 @@ public class MagickReferenceDecoder : ImageDecoder PixelType = metadata.GetDecodedPixelTypeInfo() }; } - - private static void FromRgba32Bytes(Configuration configuration, Span rgbaBytes, IMemoryGroup destinationGroup) + private static void FromRgba32Bytes( + Configuration configuration, + Span rgbaBytes, + Buffer2DRegion destinationGroup) where TPixel : unmanaged, ImageSharp.PixelFormats.IPixel { Span sourcePixels = MemoryMarshal.Cast(rgbaBytes); - foreach (Memory m in destinationGroup) + for (int y = 0; y < destinationGroup.Height; y++) { - Span destBuffer = m.Span; + Span destBuffer = destinationGroup.DangerousGetRowSpan(y); PixelOperations.Instance.FromRgba32( configuration, sourcePixels[..destBuffer.Length], destBuffer); + sourcePixels = sourcePixels[destBuffer.Length..]; } } - private static void FromRgba64Bytes(Configuration configuration, Span rgbaBytes, IMemoryGroup destinationGroup) + private static void FromRgba64Bytes( + Configuration configuration, + Span rgbaBytes, + Buffer2DRegion destinationGroup) where TPixel : unmanaged, ImageSharp.PixelFormats.IPixel { - foreach (Memory m in destinationGroup) + for (int y = 0; y < destinationGroup.Height; y++) { - Span destBuffer = m.Span; + Span destBuffer = destinationGroup.DangerousGetRowSpan(y); PixelOperations.Instance.FromRgba64Bytes( configuration, rgbaBytes, destBuffer, destBuffer.Length); + rgbaBytes = rgbaBytes[(destBuffer.Length * 8)..]; } } diff --git a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs index 05abedbd8e..263df8f3a6 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs @@ -107,6 +107,7 @@ public static class TestImageExtensions ITestImageProvider provider, object testOutputDetails = null, string extension = "png", + IImageEncoder encoder = null, bool appendPixelTypeToFileName = true, Func predicate = null) where TPixel : unmanaged, IPixel @@ -119,6 +120,7 @@ public static class TestImageExtensions provider.Utility.SaveTestOutputFileMultiFrame( image, extension, + encoder: encoder, testOutputDetails: testOutputDetails, appendPixelTypeToFileName: appendPixelTypeToFileName, predicate: predicate); @@ -277,6 +279,47 @@ public static class TestImageExtensions return image; } + public static Image CompareDebugOutputToReferenceOutputMultiFrame( + this Image image, + ITestImageProvider provider, + ImageComparer comparer, + object testOutputDetails = null, + string extension = "png", + IImageEncoder encoder = null, + bool appendPixelTypeToFileName = true, + Func predicate = null) + where TPixel : unmanaged, IPixel + { + image.DebugSaveMultiFrame( + provider, + testOutputDetails, + extension, + encoder, + appendPixelTypeToFileName, + predicate: predicate); + + using (Image debugImage = GetDebugOutputImageMultiFrame( + provider, + image.Frames.Count, + testOutputDetails, + extension, + appendPixelTypeToFileName, + predicate: predicate)) + + using (Image referenceImage = GetReferenceOutputImageMultiFrame( + provider, + image.Frames.Count, + testOutputDetails, + extension, + appendPixelTypeToFileName, + predicate: predicate)) + { + comparer.VerifySimilarity(referenceImage, debugImage); + } + + return image; + } + public static Image CompareToReferenceOutputMultiFrame( this Image image, ITestImageProvider provider, @@ -375,6 +418,54 @@ public static class TestImageExtensions return result; } + public static Image GetDebugOutputImageMultiFrame( + this ITestImageProvider provider, + int frameCount, + object testOutputDetails = null, + string extension = "png", + bool appendPixelTypeToFileName = true, + Func predicate = null) + where TPixel : unmanaged, IPixel + { + (int Index, string FileName)[] frameFiles = [.. provider.Utility.GetTestOutputFileNamesMultiFrame( + frameCount, + extension, + testOutputDetails, + appendPixelTypeToFileName, + predicate: predicate)]; + + List> temporaryFrameImages = []; + + IImageDecoder decoder = TestEnvironment.GetReferenceDecoder(frameFiles[0].FileName); + + for (int i = 0; i < frameFiles.Length; i++) + { + string path = frameFiles[i].FileName; + if (!File.Exists(path)) + { + throw new FileNotFoundException("Reference output file missing: " + path); + } + + using FileStream stream = File.OpenRead(path); + Image tempImage = decoder.Decode(DecoderOptions.Default, stream); + temporaryFrameImages.Add(tempImage); + } + + Image firstTemp = temporaryFrameImages[0]; + + Image result = new(firstTemp.Width, firstTemp.Height); + + foreach (Image fi in temporaryFrameImages) + { + result.Frames.AddFrame(fi.Frames.RootFrame); + fi.Dispose(); + } + + // Remove the initial empty frame: + result.Frames.RemoveFrame(0); + return result; + } + public static IEnumerable GetReferenceOutputSimilarityReports( this Image image, ITestImageProvider provider, diff --git a/tests/Images/External/ReferenceOutput/BmpEncoderTests/Encode_8BitColor_WithOctreeQuantizer_rgb32.bmp b/tests/Images/External/ReferenceOutput/BmpEncoderTests/Encode_8BitColor_WithOctreeQuantizer_rgb32.bmp index 2b8e05b070..f4ae3b9b68 100644 --- a/tests/Images/External/ReferenceOutput/BmpEncoderTests/Encode_8BitColor_WithOctreeQuantizer_rgb32.bmp +++ b/tests/Images/External/ReferenceOutput/BmpEncoderTests/Encode_8BitColor_WithOctreeQuantizer_rgb32.bmp @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:11375b15df083d98335f4a4baf0717e7fdd6b21ab2132a6815cadc787ac17e7d +oid sha256:a98b1ec707af066f77fad7d1a64b858d460986beb6d27682717dd5e221310fd4 size 9270 diff --git a/tests/Images/External/ReferenceOutput/DitherTests/ApplyDitherFilterInBox_Rgba32_CalliphoraPartial - Copy.png b/tests/Images/External/ReferenceOutput/DitherTests/ApplyDitherFilterInBox_Rgba32_CalliphoraPartial - Copy.png new file mode 100644 index 0000000000..43e414da6d --- /dev/null +++ b/tests/Images/External/ReferenceOutput/DitherTests/ApplyDitherFilterInBox_Rgba32_CalliphoraPartial - Copy.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a899a84c6af24bfad89f9fde75957c7a979d65bcf096ab667cb976efd71cb560 +size 271171 diff --git a/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_Atkinson.png b/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_Atkinson.png index cc2327b23f..70acb3f32e 100644 --- a/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_Atkinson.png +++ b/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_Atkinson.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7e22401dddf6552cd91517c1cdd142d3b9a66a7ad5c80d2e52ae07a7f583708e -size 57657 +oid sha256:e44c49a8f2ab1280c38e6ba71da29a93803b2aa4cf117e1e919909521b0373e6 +size 57636 diff --git a/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_Burks.png b/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_Burks.png index e3ae6508e1..af35177491 100644 --- a/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_Burks.png +++ b/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_Burks.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:819a0ce38e27e2adfa454d8c5ad5b24e818bf8954c9f2406f608dcecf506c2c4 -size 59838 +oid sha256:359a44bb957481c85d5acd65559b43ffc0acf806d4f4e57d6a791ca65b28295b +size 59839 diff --git a/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_FloydSteinberg.png b/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_FloydSteinberg.png index 2b897a5d6d..a14c2cb1f6 100644 --- a/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_FloydSteinberg.png +++ b/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_FloydSteinberg.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:007ac609ec61b39c7bdd04bc87a698f5cdc76eadd834c1457f41eb9c135c3f7b +oid sha256:7fb3743098a8147fd24294d933d93a61ec0155d754f52544650f6589719905be size 60688 diff --git a/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_JarvisJudiceNinke.png b/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_JarvisJudiceNinke.png index 10ba90ae86..683f59ea1e 100644 --- a/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_JarvisJudiceNinke.png +++ b/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_JarvisJudiceNinke.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:46892c07e9a93f1df71f0e38b331a437fb9b7c52d8f40cf62780cb6bd35d3b13 -size 58963 +oid sha256:41fa7d92a10db450f3b3729ab9e36074224baaefeda21cffd0466e37a111e138 +size 59113 diff --git a/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_Sierra2.png b/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_Sierra2.png index 9608289e84..813289a26d 100644 --- a/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_Sierra2.png +++ b/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_Sierra2.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1b83345ca3de8d1fc0fbb5d8e68329b94ad79fc29b9f10a1392a97ffe9a0733e -size 58985 +oid sha256:bebf3b3762b339874891e3d434511e5f2557be90d66d6d7fe827b50334ede6c2 +size 58976 diff --git a/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_Sierra3.png b/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_Sierra3.png index 79d2c5eb14..d4da100376 100644 --- a/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_Sierra3.png +++ b/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_Sierra3.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c775a5b19ba09e1b335389e0dc12cb0c3feaff6072e904da750a676fcd6b07dc -size 59202 +oid sha256:fd4358826739db2c22064e8aa90597f8b6403b9d7e2866ec280e743c51d2f41f +size 59203 diff --git a/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_Stucki.png b/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_Stucki.png index edec46a92a..fa8eea57a9 100644 --- a/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_Stucki.png +++ b/tests/Images/External/ReferenceOutput/DitherTests/DiffusionFilter_WorksWithAllErrorDiffusers_CalliphoraPartial_Stucki.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8cc216ed952216d203836dc559234216614f1ed059651677cc0ea714010bd932 -size 58855 +oid sha256:174ee39c08eb9a174b48b19dc618d043bf6b71eee68ab7127407eb713e164e61 +size 58934 diff --git a/tests/Images/External/ReferenceOutput/DitherTests/DitherFilter_ShouldNotDependOnSinglePixelType_Bgra32_filter0.png b/tests/Images/External/ReferenceOutput/DitherTests/DitherFilter_ShouldNotDependOnSinglePixelType_Bgra32_filter0.png index e2e4147f68..2c67b3bf23 100644 --- a/tests/Images/External/ReferenceOutput/DitherTests/DitherFilter_ShouldNotDependOnSinglePixelType_Bgra32_filter0.png +++ b/tests/Images/External/ReferenceOutput/DitherTests/DitherFilter_ShouldNotDependOnSinglePixelType_Bgra32_filter0.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a3253003b088c9975725cf321c2fc827547a5feb199f2d1aa515c69bde59deb7 -size 871 +oid sha256:1110b46ec3296a1631420e0bb915f6fdc3d1cead4b0fc5a63a7a280fbf841ea2 +size 870 diff --git a/tests/Images/External/ReferenceOutput/DitherTests/DitherFilter_ShouldNotDependOnSinglePixelType_Rgb24_filter0.png b/tests/Images/External/ReferenceOutput/DitherTests/DitherFilter_ShouldNotDependOnSinglePixelType_Rgb24_filter0.png index aa0e9a4824..1305c5ede9 100644 --- a/tests/Images/External/ReferenceOutput/DitherTests/DitherFilter_ShouldNotDependOnSinglePixelType_Rgb24_filter0.png +++ b/tests/Images/External/ReferenceOutput/DitherTests/DitherFilter_ShouldNotDependOnSinglePixelType_Rgb24_filter0.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bb3e3b9b3001e76505fb0e2db7ad200cad2a016c06f1993c60c3cab42c134863 -size 867 +oid sha256:e51abcab66201997deda99637de604330ef977fd2d1dbebaa0416c621d03b8f9 +size 869 diff --git a/tests/Images/External/ReferenceOutput/DitherTests/DitherFilter_ShouldNotDependOnSinglePixelType_Rgba32_filter0.png b/tests/Images/External/ReferenceOutput/DitherTests/DitherFilter_ShouldNotDependOnSinglePixelType_Rgba32_filter0.png index e2e4147f68..2c67b3bf23 100644 --- a/tests/Images/External/ReferenceOutput/DitherTests/DitherFilter_ShouldNotDependOnSinglePixelType_Rgba32_filter0.png +++ b/tests/Images/External/ReferenceOutput/DitherTests/DitherFilter_ShouldNotDependOnSinglePixelType_Rgba32_filter0.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a3253003b088c9975725cf321c2fc827547a5feb199f2d1aa515c69bde59deb7 -size 871 +oid sha256:1110b46ec3296a1631420e0bb915f6fdc3d1cead4b0fc5a63a7a280fbf841ea2 +size 870 diff --git a/tests/Images/External/ReferenceOutput/DitherTests/DitherFilter_ShouldNotDependOnSinglePixelType_RgbaVector_filter0.png b/tests/Images/External/ReferenceOutput/DitherTests/DitherFilter_ShouldNotDependOnSinglePixelType_RgbaVector_filter0.png index e2e4147f68..2c67b3bf23 100644 --- a/tests/Images/External/ReferenceOutput/DitherTests/DitherFilter_ShouldNotDependOnSinglePixelType_RgbaVector_filter0.png +++ b/tests/Images/External/ReferenceOutput/DitherTests/DitherFilter_ShouldNotDependOnSinglePixelType_RgbaVector_filter0.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a3253003b088c9975725cf321c2fc827547a5feb199f2d1aa515c69bde59deb7 -size 871 +oid sha256:1110b46ec3296a1631420e0bb915f6fdc3d1cead4b0fc5a63a7a280fbf841ea2 +size 870 diff --git a/tests/Images/External/ReferenceOutput/DitherTests/DitherFilter_WorksWithAllDitherers_CalliphoraPartial_Bayer16x16.png b/tests/Images/External/ReferenceOutput/DitherTests/DitherFilter_WorksWithAllDitherers_CalliphoraPartial_Bayer16x16.png index 4175cf40b7..da1f62b728 100644 --- a/tests/Images/External/ReferenceOutput/DitherTests/DitherFilter_WorksWithAllDitherers_CalliphoraPartial_Bayer16x16.png +++ b/tests/Images/External/ReferenceOutput/DitherTests/DitherFilter_WorksWithAllDitherers_CalliphoraPartial_Bayer16x16.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9316cbbcb137ae6ff31646f6a5ba1d0aec100db4512509f7684187e74d16a111 -size 51074 +oid sha256:eb86f2037a0aff48a84c0161f22eb2e2495daadbfa9c33185ddfd7b8429a4ea9 +size 51266 diff --git a/tests/Images/External/ReferenceOutput/DitherTests/DitherFilter_WorksWithAllDitherers_CalliphoraPartial_Bayer8x8.png b/tests/Images/External/ReferenceOutput/DitherTests/DitherFilter_WorksWithAllDitherers_CalliphoraPartial_Bayer8x8.png index ac56fa9236..03848e81ce 100644 --- a/tests/Images/External/ReferenceOutput/DitherTests/DitherFilter_WorksWithAllDitherers_CalliphoraPartial_Bayer8x8.png +++ b/tests/Images/External/ReferenceOutput/DitherTests/DitherFilter_WorksWithAllDitherers_CalliphoraPartial_Bayer8x8.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6d2289ed4fa0c679f0f120d260fec8ab40b1599043cc0a1fbebc6b67e238ff87 -size 51428 +oid sha256:ef033a419e2e1b06b57a66175bad9068f71ae4c862a66c5734f65cdaae8a27f0 +size 51461 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_Rgba32_animated_loop.gif/00.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_Rgba32_animated_loop.gif/00.png new file mode 100644 index 0000000000..65b2c6ff72 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_Rgba32_animated_loop.gif/00.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0b980fb1927a70f88bd26b039c54e4ea20a6a1ad68aacd6f1a68a46eb1997a29 +size 1180 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_Rgba32_animated_loop.gif/01.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_Rgba32_animated_loop.gif/01.png new file mode 100644 index 0000000000..8c9e125ade --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_Rgba32_animated_loop.gif/01.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4006374b88ff4c4ed665333608a19e693fc083ae72beb71850d0e39ad45c9943 +size 1144 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_Rgba32_animated_loop.gif/02.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_Rgba32_animated_loop.gif/02.png new file mode 100644 index 0000000000..a2fc2ab3bc --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_Rgba32_animated_loop.gif/02.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1f5054e1e464c9e9fc999eec00b9949a6dc256ee062e9910b5718b6d4658661a +size 1303 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_Rgba32_animated_loop.gif/03.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_Rgba32_animated_loop.gif/03.png new file mode 100644 index 0000000000..9d5b54c718 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_Rgba32_animated_loop.gif/03.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:49e8bcbcc5dc63fbd555f90a52b4e111cfc058f3adba2ca9c52dec966dbbae8f +size 1371 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_Rgba32_animated_loop_interlaced.gif/00.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_Rgba32_animated_loop_interlaced.gif/00.png new file mode 100644 index 0000000000..65b2c6ff72 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_Rgba32_animated_loop_interlaced.gif/00.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0b980fb1927a70f88bd26b039c54e4ea20a6a1ad68aacd6f1a68a46eb1997a29 +size 1180 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_Rgba32_animated_loop_interlaced.gif/01.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_Rgba32_animated_loop_interlaced.gif/01.png new file mode 100644 index 0000000000..8c9e125ade --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_Rgba32_animated_loop_interlaced.gif/01.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4006374b88ff4c4ed665333608a19e693fc083ae72beb71850d0e39ad45c9943 +size 1144 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_Rgba32_animated_loop_interlaced.gif/02.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_Rgba32_animated_loop_interlaced.gif/02.png new file mode 100644 index 0000000000..a2fc2ab3bc --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_Rgba32_animated_loop_interlaced.gif/02.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1f5054e1e464c9e9fc999eec00b9949a6dc256ee062e9910b5718b6d4658661a +size 1303 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_Rgba32_animated_loop_interlaced.gif/03.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_Rgba32_animated_loop_interlaced.gif/03.png new file mode 100644 index 0000000000..9d5b54c718 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_Rgba32_animated_loop_interlaced.gif/03.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:49e8bcbcc5dc63fbd555f90a52b4e111cfc058f3adba2ca9c52dec966dbbae8f +size 1371 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_firstframerestoreprev_loop.gif/00.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_firstframerestoreprev_loop.gif/00.png new file mode 100644 index 0000000000..193cde24d9 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_firstframerestoreprev_loop.gif/00.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:18b60d2066cb53d41988da37b8c521ddcb5355b995320a8413b95522a0492140 +size 687 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_firstframerestoreprev_loop.gif/01.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_firstframerestoreprev_loop.gif/01.png new file mode 100644 index 0000000000..4d2d255108 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_firstframerestoreprev_loop.gif/01.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:30ff7708250c5f02dc02d74238d398b319d8fc6c071178f32f82a17e3b637afd +size 542 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_firstframerestoreprev_loop.gif/02.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_firstframerestoreprev_loop.gif/02.png new file mode 100644 index 0000000000..0654e49d45 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_firstframerestoreprev_loop.gif/02.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d21f4576486692122b6ee719d75883849f65ddb07f632ea1c62b42651c289688 +size 591 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_firstframerestoreprev_loop.gif/03.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_firstframerestoreprev_loop.gif/03.png new file mode 100644 index 0000000000..0c1090f662 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_firstframerestoreprev_loop.gif/03.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:88db68f2d59301b8ff9326143455a03c94cb616220f6e8e3832f13effe0c09bc +size 545 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_frame_norestore_loop.gif/00.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_frame_norestore_loop.gif/00.png new file mode 100644 index 0000000000..193cde24d9 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_frame_norestore_loop.gif/00.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:18b60d2066cb53d41988da37b8c521ddcb5355b995320a8413b95522a0492140 +size 687 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_frame_norestore_loop.gif/01.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_frame_norestore_loop.gif/01.png new file mode 100644 index 0000000000..f289fdca31 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_frame_norestore_loop.gif/01.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:034b0b6b94c13fbef8c44d650daa07362f113aae6600d63230a3f96e29b16dec +size 790 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_frame_norestore_loop.gif/02.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_frame_norestore_loop.gif/02.png new file mode 100644 index 0000000000..07537b9df0 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_frame_norestore_loop.gif/02.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f4b3684db6e3df52a9eb520d562b51b54632e897e9e39bff5ce904ae00799f2f +size 924 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_frame_norestore_loop.gif/03.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_frame_norestore_loop.gif/03.png new file mode 100644 index 0000000000..e376be6890 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_frame_norestore_loop.gif/03.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6e33c564f55b653a693105612949401002014821abaecaf654c96d0f2b5d59b4 +size 962 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_frame_restoreprev_loop.gif/00.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_frame_restoreprev_loop.gif/00.png new file mode 100644 index 0000000000..193cde24d9 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_frame_restoreprev_loop.gif/00.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:18b60d2066cb53d41988da37b8c521ddcb5355b995320a8413b95522a0492140 +size 687 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_frame_restoreprev_loop.gif/01.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_frame_restoreprev_loop.gif/01.png new file mode 100644 index 0000000000..f289fdca31 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_frame_restoreprev_loop.gif/01.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:034b0b6b94c13fbef8c44d650daa07362f113aae6600d63230a3f96e29b16dec +size 790 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_frame_restoreprev_loop.gif/02.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_frame_restoreprev_loop.gif/02.png new file mode 100644 index 0000000000..27f29acbb0 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_frame_restoreprev_loop.gif/02.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a4f4eb12da36cd43c620aa5ad1c793bb6eb8431c61d2cc1b77c1118f35a741cc +size 876 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_frame_restoreprev_loop.gif/03.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_frame_restoreprev_loop.gif/03.png new file mode 100644 index 0000000000..684c2fa389 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_frame_restoreprev_loop.gif/03.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:15bf02e06c6819d74a0a79cbfc5c86913c248a8812ff0ec613c0e747a000241b +size 789 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_loop.gif/00.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_loop.gif/00.png new file mode 100644 index 0000000000..193cde24d9 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_loop.gif/00.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:18b60d2066cb53d41988da37b8c521ddcb5355b995320a8413b95522a0492140 +size 687 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_loop.gif/01.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_loop.gif/01.png new file mode 100644 index 0000000000..7818cf380f --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_loop.gif/01.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:01f389a2e93023f3132927a9565c04c8c1f827e36111ebe682177adecc3a27ee +size 774 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_loop.gif/02.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_loop.gif/02.png new file mode 100644 index 0000000000..18bc408639 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_loop.gif/02.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:00ef57db2fef89112ac7d1808afb6803612c6a20fc589166be6d6b7007c46400 +size 946 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_loop.gif/03.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_loop.gif/03.png new file mode 100644 index 0000000000..bd2ea67aed --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Animated_WithTransparency_Rgba32_animated_transparent_loop.gif/03.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:deafa4d4f8fd84489c061ca1042c2ad9e655fff3b6419248cfb35fa4ea40d9e6 +size 1000 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Static_No_Animation_Rgba32_static_nontransparent.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Static_No_Animation_Rgba32_static_nontransparent.png new file mode 100644 index 0000000000..65b2c6ff72 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Static_No_Animation_Rgba32_static_nontransparent.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0b980fb1927a70f88bd26b039c54e4ea20a6a1ad68aacd6f1a68a46eb1997a29 +size 1180 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Static_No_Animation_Rgba32_static_transparent.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Static_No_Animation_Rgba32_static_transparent.png new file mode 100644 index 0000000000..193cde24d9 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Decode_Static_No_Animation_Rgba32_static_transparent.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:18b60d2066cb53d41988da37b8c521ddcb5355b995320a8413b95522a0492140 +size 687 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Issue1962_Rgba32_issue1962_tiniest_gif_1st.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Issue1962_Rgba32_issue1962_tiniest_gif_1st.png index 24f5e9c0cd..a52b27708a 100644 --- a/tests/Images/External/ReferenceOutput/GifDecoderTests/Issue1962_Rgba32_issue1962_tiniest_gif_1st.png +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Issue1962_Rgba32_issue1962_tiniest_gif_1st.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4f8c6d416f09671777934e57bc67fb52ccc97145dc6f1869e628d9ffd7d8f6e7 -size 119 +oid sha256:9ab8374e77865606a2426e3d22628f717914472431de1d9d8ee9690d319850a0 +size 118 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/Issue2012BadMinCode_Rgba32_issue2012_drona1.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/Issue2012BadMinCode_Rgba32_issue2012_drona1.png index b07e806620..5d443b52aa 100644 --- a/tests/Images/External/ReferenceOutput/GifDecoderTests/Issue2012BadMinCode_Rgba32_issue2012_drona1.png +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/Issue2012BadMinCode_Rgba32_issue2012_drona1.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:588d055a93c7b4fdb62e8b77f3ae08753a9e8990151cb0523f5e761996189b70 -size 142244 +oid sha256:a0e1677baade797de1eaec390f2e475865d24de8bd344edddbb3fce200d6bcb0 +size 135418 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/00.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/00.png index 923fbc1225..52f14e0f72 100644 --- a/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/00.png +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/00.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:800d1ec2d7c7c99d449db1f49ef202cf18214016eae65ebc4216d6f4b1f4d328 -size 537 +oid sha256:473c5629d7a9f8b3d6c809e8ede40f8fd38e90beddf71851b352c726fc0570d6 +size 534 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/01.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/01.png index 6c2134d8b8..b47f34ba04 100644 --- a/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/01.png +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/01.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:94dcd97831b16165f3331e429d72d7ef546e04038cab754c7918f9cf535ff30a -size 542 +oid sha256:4b9b9f856c0347b460f824d6b027b343c65c67a29360793181c9a29a76f9002b +size 538 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/02.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/02.png index 6f50397ea4..64869ca3c6 100644 --- a/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/02.png +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/02.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ec1a589a8fae1b17a82b70a9583ea2ee012a476b1fa8fdba27fee2b7ce0403b2 -size 540 +oid sha256:74b8015c60d215808b1d663ae4af956d1454414206ba21326ad35b8952b0cab6 +size 534 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/03.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/03.png index 82061ba0aa..ab52225f8b 100644 --- a/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/03.png +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/03.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0c8751f4fafd5c56066dbb8d64a3890fc420a3bd66881a55e309ba274b6d14e4 -size 542 +oid sha256:8dacb6a468d3cdc94613d56264ddf34d3649846edf33619fc13b9522fcf982d6 +size 539 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/04.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/04.png index 8902eb824a..78988aa60a 100644 --- a/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/04.png +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/04.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b78516c9874cb15de4c4b98ed307e8105d962fc6bfa7aa3490b2c7e13b455a2d -size 544 +oid sha256:8af74db6e01928ad54444fa122e4b87929741052c85abe9c0ffc998adffcbdfc +size 542 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/05.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/05.png index 82061ba0aa..ab52225f8b 100644 --- a/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/05.png +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/05.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0c8751f4fafd5c56066dbb8d64a3890fc420a3bd66881a55e309ba274b6d14e4 -size 542 +oid sha256:8dacb6a468d3cdc94613d56264ddf34d3649846edf33619fc13b9522fcf982d6 +size 539 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/06.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/06.png index 6f50397ea4..64869ca3c6 100644 --- a/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/06.png +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/06.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ec1a589a8fae1b17a82b70a9583ea2ee012a476b1fa8fdba27fee2b7ce0403b2 -size 540 +oid sha256:74b8015c60d215808b1d663ae4af956d1454414206ba21326ad35b8952b0cab6 +size 534 diff --git a/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/07.png b/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/07.png index efba40c99d..97610dbc00 100644 --- a/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/07.png +++ b/tests/Images/External/ReferenceOutput/GifDecoderTests/IssueTooLargeLzwBits_Rgba32_issue_2743.gif/07.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5016a323018f09e292165ad5392d82dcbad5e79c2b6b93aff3322dffff80b309 -size 126 +oid sha256:c816ca1e58d14361b84ba47454e4cbf4d3e4d29dfb7827756eb52ef2604f297c +size 161 diff --git a/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/00.gif b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/00.gif new file mode 100644 index 0000000000..b219975ade --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/00.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cb4bbef09dc6618380e34c5dcf8612fa5a51ba81a09edc5500be9191f0554d9c +size 49665 diff --git a/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/08.gif b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/08.gif new file mode 100644 index 0000000000..2d50761636 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/08.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:81a0d629326bb39cfced1a261542e5f94b423527f95bc45422670091b91583b4 +size 50730 diff --git a/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/104.gif b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/104.gif new file mode 100644 index 0000000000..b1b7781a21 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/104.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e64d9f2f7a8346f62c9b41a14b3e6b71f76a48e07fa42ac9e0d4a5b146a8a9da +size 58856 diff --git a/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/112.gif b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/112.gif new file mode 100644 index 0000000000..f058764b4f --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/112.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b01517c53b19f6b151a76cc75142ba3a8a45da8c6e94416447703cbd54ce1a8a +size 48282 diff --git a/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/16.gif b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/16.gif new file mode 100644 index 0000000000..b9f1e2d099 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/16.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1db212159613778c962883de9067852da3bea5f3483dd9f967c0aabbcdc1b2f6 +size 64655 diff --git a/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/24.gif b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/24.gif new file mode 100644 index 0000000000..c7a1368ce1 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/24.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9d09ddfff1f26ed7842df5bf4b8938373700658322c85b154a878dd5e3a90dc1 +size 64432 diff --git a/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/32.gif b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/32.gif new file mode 100644 index 0000000000..ffd61e5123 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/32.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:18ca31ff631ecc33fe33a893e94e23af8b086a78c3684461e449c02800fffb2b +size 66510 diff --git a/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/40.gif b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/40.gif new file mode 100644 index 0000000000..eb93ea4d4a --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/40.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:823358342cbc25a9f7ae34abc2669096acd7c0e0c93a8a0b371e548822ed0897 +size 66912 diff --git a/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/48.gif b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/48.gif new file mode 100644 index 0000000000..99f0e64dc6 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/48.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:90558311a7b7127d9f970a17ae0630d81507be246f511f1cc3b10c6ee953a25c +size 61986 diff --git a/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/56.gif b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/56.gif new file mode 100644 index 0000000000..8e6410f9bf --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/56.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9514b736d946d4e93ba3f59b586d2c29e0c031155f7824756ecf468ef87ea8e6 +size 61367 diff --git a/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/64.gif b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/64.gif new file mode 100644 index 0000000000..2257625c41 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/64.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0334c551b9efcaa9f5c16c4599884b4aabe5129e3f023222be3214cf8623242e +size 60825 diff --git a/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/72.gif b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/72.gif new file mode 100644 index 0000000000..efc9569f4d --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/72.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:32a9fecdad6508c1c6beae839717d1854cca1f7b247bff36a00a93cc953f608c +size 57370 diff --git a/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/80.gif b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/80.gif new file mode 100644 index 0000000000..9f7ae53fb0 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/80.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5d50d4ccba947ef95b9e8a2c4acd08f57c414f4e38a0d03d65b5fee093e4481a +size 67784 diff --git a/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/88.gif b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/88.gif new file mode 100644 index 0000000000..22dc30784c --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/88.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:840780f2916cb9d010a95802d9c123c3051bcee5dde7b173a50854e3b5f3636a +size 72552 diff --git a/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/96.gif b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/96.gif new file mode 100644 index 0000000000..53e1a35cbf --- /dev/null +++ b/tests/Images/External/ReferenceOutput/GifEncoderTests/GifEncoder_CanDecode_AndEncode_Issue2866_Rgba32_issue_2866.gif/96.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:41db6ded3de84d43dec1175c1481f75a045c5ad126369e4e82ae29ec4bad0bc4 +size 76868 diff --git a/tests/Images/External/ReferenceOutput/IccProfileConverterTests/CanConvertToSRGB_Momiji-AdobeRGB-yes.png b/tests/Images/External/ReferenceOutput/IccProfileConverterTests/CanConvertToSRGB_Momiji-AdobeRGB-yes.png new file mode 100644 index 0000000000..46d728c8d6 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/IccProfileConverterTests/CanConvertToSRGB_Momiji-AdobeRGB-yes.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:650256637c7039c59e135bbdabd31bee1ad99c9d9ff014562300945d41b6ac3a +size 459515 diff --git a/tests/Images/External/ReferenceOutput/IccProfileConverterTests/CanConvertToSRGB_Momiji-AppleRGB-yes.png b/tests/Images/External/ReferenceOutput/IccProfileConverterTests/CanConvertToSRGB_Momiji-AppleRGB-yes.png new file mode 100644 index 0000000000..3c856c2c32 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/IccProfileConverterTests/CanConvertToSRGB_Momiji-AppleRGB-yes.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4e2d477de13a3767a364260b7b54b1f2a46c833e8df7aa1fded7990a3ac60563 +size 483943 diff --git a/tests/Images/External/ReferenceOutput/IccProfileConverterTests/CanConvertToSRGB_Momiji-ColorMatch-yes.png b/tests/Images/External/ReferenceOutput/IccProfileConverterTests/CanConvertToSRGB_Momiji-ColorMatch-yes.png new file mode 100644 index 0000000000..408f52e11e --- /dev/null +++ b/tests/Images/External/ReferenceOutput/IccProfileConverterTests/CanConvertToSRGB_Momiji-ColorMatch-yes.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7ee8f5c7f658b11a380e6da2130dc8563da3255f3ff5d9fd9cc98ec87bb1852b +size 465348 diff --git a/tests/Images/External/ReferenceOutput/IccProfileConverterTests/CanConvertToSRGB_Momiji-ProPhoto-yes.png b/tests/Images/External/ReferenceOutput/IccProfileConverterTests/CanConvertToSRGB_Momiji-ProPhoto-yes.png new file mode 100644 index 0000000000..714340ad6f --- /dev/null +++ b/tests/Images/External/ReferenceOutput/IccProfileConverterTests/CanConvertToSRGB_Momiji-ProPhoto-yes.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c702f52b08ac5be9eb65fd1f4e841fc46c897db45c709974954265b93d46b854 +size 478310 diff --git a/tests/Images/External/ReferenceOutput/IccProfileConverterTests/CanConvertToSRGB_Momiji-WideRGB-yes.png b/tests/Images/External/ReferenceOutput/IccProfileConverterTests/CanConvertToSRGB_Momiji-WideRGB-yes.png new file mode 100644 index 0000000000..c678bf52b3 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/IccProfileConverterTests/CanConvertToSRGB_Momiji-WideRGB-yes.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f06f61eca4187823cfb76255caaa9f9f9d43e9ea56da3cd0fac830f6198d9d8a +size 469400 diff --git a/tests/Images/External/ReferenceOutput/IccProfileConverterTests/CanConvertToSRGB_Momiji-sRGB-yes.png b/tests/Images/External/ReferenceOutput/IccProfileConverterTests/CanConvertToSRGB_Momiji-sRGB-yes.png new file mode 100644 index 0000000000..786937c2bb --- /dev/null +++ b/tests/Images/External/ReferenceOutput/IccProfileConverterTests/CanConvertToSRGB_Momiji-sRGB-yes.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dc3657d9aa0e36beee1d24144ace5bdd1198c0249ac661f302ae38b7d478d374 +size 436479 diff --git a/tests/Images/External/ReferenceOutput/IccProfileConverterTests/CanConvertToSRGB_issue-129.png b/tests/Images/External/ReferenceOutput/IccProfileConverterTests/CanConvertToSRGB_issue-129.png new file mode 100644 index 0000000000..52dd0e0f3a --- /dev/null +++ b/tests/Images/External/ReferenceOutput/IccProfileConverterTests/CanConvertToSRGB_issue-129.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d423959ad2f5c9a3fc8df0ca1ff9b3d6d6751bb552cee65dbda29623581cb816 +size 2043144 diff --git a/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/00.png b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/00.png new file mode 100644 index 0000000000..17c8e35c6f --- /dev/null +++ b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/00.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4aa1dea5da7a94fddd2259cd86e7171a57cb5cd2198decedd86149778b9aa20a +size 64030 diff --git a/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/08.png b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/08.png new file mode 100644 index 0000000000..f2ec385a88 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/08.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:16d4159e492162372a16b08fb3a4fdf36908ce759c6a0ad72a0da4bbeb477b72 +size 68619 diff --git a/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/104.png b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/104.png new file mode 100644 index 0000000000..dc57ed717f --- /dev/null +++ b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/104.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1095bc829b8fab3c5fda66b90cdd751b81439ad80e9fc7d564a5212c75155b2c +size 76100 diff --git a/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/112.png b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/112.png new file mode 100644 index 0000000000..0158b28407 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/112.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0212cd29319c0d90c18a5f90716156a888c9925e4a36a6d9bbbe8d67a706db8f +size 66282 diff --git a/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/16.png b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/16.png new file mode 100644 index 0000000000..52867f468e --- /dev/null +++ b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/16.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:620ea89afc2e41b6199c47b2e4777f5ef9afe139e22bfabca9ec094b0adcbdc2 +size 73862 diff --git a/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/24.png b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/24.png new file mode 100644 index 0000000000..26ae147489 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/24.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d39997f18af5b97ed32ea30c15da879f70906b4f5cf12439ea6ff2d229e40199 +size 75734 diff --git a/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/32.png b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/32.png new file mode 100644 index 0000000000..6cd5074ecf --- /dev/null +++ b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/32.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4b459edf763ffff8a8a016c1b7d9e13b7e99f6752e4452b52539d2eb0f7f31be +size 79505 diff --git a/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/40.png b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/40.png new file mode 100644 index 0000000000..8b9ea7c239 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/40.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f1957c82709b22abbaa354ecd679159eeddf135aabb301c266518c23ff4918f9 +size 77588 diff --git a/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/48.png b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/48.png new file mode 100644 index 0000000000..4430290427 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/48.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ae33b303bd1feae301cf645ee6596c499ad4eaa9164c52a37fca760169f9f363 +size 80317 diff --git a/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/56.png b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/56.png new file mode 100644 index 0000000000..8feae54c6a --- /dev/null +++ b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/56.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d86360bd43de392a9cf4b671a4cf3cd7ba9f61952a6d0400a5baab7dbb5eeb6d +size 78578 diff --git a/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/64.png b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/64.png new file mode 100644 index 0000000000..284ad99233 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/64.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:60e1694b121d0d3fa17d62f4477de349376aa6c2a98b83f9a4525da9ea471662 +size 75204 diff --git a/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/72.png b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/72.png new file mode 100644 index 0000000000..d09b77afca --- /dev/null +++ b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/72.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9348ef330a239bea501f41a3256107fc10a6bb323642118b1fcbe5227b742c88 +size 79048 diff --git a/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/80.png b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/80.png new file mode 100644 index 0000000000..d31fd5a808 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/80.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:452dd2339b6ad3e35528601c289d88eafcc7e9a6e717f25da2bbf4267b85be97 +size 81553 diff --git a/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/88.png b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/88.png new file mode 100644 index 0000000000..669dfb8600 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/88.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b67e3b57b62f9e1c924de6fbd2699f93a6594812ad8c4cafd6160323547b1a88 +size 86402 diff --git a/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/96.png b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/96.png new file mode 100644 index 0000000000..f9a5aee191 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_issue_2866.gif/96.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:887e94402f93a491820d3d25d641c5901cf796c1275a2feb9e1c072a6a63ce28 +size 87335 diff --git a/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_leo.gif/00.png b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_leo.gif/00.png new file mode 100644 index 0000000000..961e205f9f --- /dev/null +++ b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_leo.gif/00.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a6baac5db47ef2ee3ba72c7e8d5e04fc888c5e1460d4d7e348f63b597e1b5ff7 +size 23660 diff --git a/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_leo.gif/08.png b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_leo.gif/08.png new file mode 100644 index 0000000000..82cb6168e8 --- /dev/null +++ b/tests/Images/External/ReferenceOutput/PngEncoderTests/Encode_AnimatedFormatTransform_FromGif_Rgba32_leo.gif/08.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7fad45a0682a70a1fb84eec76d4a80ee054e85df59e6729508f3698d39999e31 +size 29509 diff --git a/tests/Images/External/ReferenceOutput/PngEncoderTests/Issue2668_Quantized_Encode_Alpha_Rgba32_Issue_2668.png b/tests/Images/External/ReferenceOutput/PngEncoderTests/Issue2668_Quantized_Encode_Alpha_Rgba32_Issue_2668.png index 7af5391f70..b292138707 100644 --- a/tests/Images/External/ReferenceOutput/PngEncoderTests/Issue2668_Quantized_Encode_Alpha_Rgba32_Issue_2668.png +++ b/tests/Images/External/ReferenceOutput/PngEncoderTests/Issue2668_Quantized_Encode_Alpha_Rgba32_Issue_2668.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f934af128b85b9e8f557d71ac8b1f1473a0922d0754fc0c4ece0d0e3d8d94c39 -size 7702 +oid sha256:df34f8f3640b145add4f24f8003c288fe7991373b079a87b4be90842e18c82ae +size 8236 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationInBox_Bike_OctreeQuantizer_ErrorDither.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationInBox_Bike_OctreeQuantizer_ErrorDither.png index 4948c7adee..327366f5b6 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationInBox_Bike_OctreeQuantizer_ErrorDither.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationInBox_Bike_OctreeQuantizer_ErrorDither.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a51d04953c1c82d99884af62912d2271108c6bc62f18d4b32d0b5290c01fa7f7 -size 247462 +oid sha256:0086044f12a7c58e49733f203af29a8aff2826ea654730274720eada15669254 +size 249163 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationInBox_Bike_OctreeQuantizer_NoDither.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationInBox_Bike_OctreeQuantizer_NoDither.png index d993923d48..3e0be536e3 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationInBox_Bike_OctreeQuantizer_NoDither.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationInBox_Bike_OctreeQuantizer_NoDither.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9f165908729d723818b6c5843bd75298d987448e2cd4278dfe3f388a62025add -size 238396 +oid sha256:85ee8479984aa52f837badbc49085c5448597fbfd987438fe25b58bad475e85f +size 239498 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationInBox_Bike_OctreeQuantizer_OrderedDither.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationInBox_Bike_OctreeQuantizer_OrderedDither.png index 223d3bc012..816fdf704b 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationInBox_Bike_OctreeQuantizer_OrderedDither.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationInBox_Bike_OctreeQuantizer_OrderedDither.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:34eaa0696da00838e591b2c48e7797641521f7f3feb01abbd774591c4dd6f200 -size 265546 +oid sha256:4ee35a7c21e90a2de1bf953e1c0be96d4f63492d0c8b2809fe9f39a9d0e64191 +size 266755 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationInBox_CalliphoraPartial_OctreeQuantizer_ErrorDither.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationInBox_CalliphoraPartial_OctreeQuantizer_ErrorDither.png index ebb9ff6b00..f29db004f5 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationInBox_CalliphoraPartial_OctreeQuantizer_ErrorDither.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationInBox_CalliphoraPartial_OctreeQuantizer_ErrorDither.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f414473561bfa792c2e6342ff5e5dddffbdec5286932781b11a093803593b52a -size 313787 +oid sha256:ce381c2d261b9b1ca61d8f6e2ff07b992283c327dc6b7cf53c7e5c9317abb7d3 +size 316443 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationInBox_CalliphoraPartial_OctreeQuantizer_NoDither.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationInBox_CalliphoraPartial_OctreeQuantizer_NoDither.png index 7e3080562c..284c3a2702 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationInBox_CalliphoraPartial_OctreeQuantizer_NoDither.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationInBox_CalliphoraPartial_OctreeQuantizer_NoDither.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0203ecb9e4665e7c3992b7da4777c6d35b539790506fc9ca2acbcbc2bdb5db18 -size 303979 +oid sha256:2bfc23a95df8a88ac6e2777d67f381e800d23647c162a9a97131a101bbb97143 +size 306703 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationInBox_CalliphoraPartial_OctreeQuantizer_OrderedDither.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationInBox_CalliphoraPartial_OctreeQuantizer_OrderedDither.png index 5626fa1b83..5911faa723 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationInBox_CalliphoraPartial_OctreeQuantizer_OrderedDither.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationInBox_CalliphoraPartial_OctreeQuantizer_OrderedDither.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:62cdce27fc46a38a16995df8ed1501f65091d69315288479b1d613b1d87c8239 -size 321123 +oid sha256:9d3f58a108d933ec9ac0a5271af5b65d0a8ab9d521d54e48312b280cc42d71ac +size 322049 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_ErrorDither_0.25.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_ErrorDither_0.25.png index 82b965123d..a2fb2a6760 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_ErrorDither_0.25.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_ErrorDither_0.25.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4bed69d43856ebd4b1af4055f8d3aacabd50c361a4e1e1f9cad080d799d6b744 -size 13853 +oid sha256:18a47a6fa0f7949daef6969a847d8bc04deeb16bb482211ec3a958bc63f23f89 +size 13158 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_ErrorDither_0.5.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_ErrorDither_0.5.png index 571b0db4b9..8d99eb49b2 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_ErrorDither_0.5.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_ErrorDither_0.5.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4c8c8393708002f06f9d8ed1ff8979db820035585c08b66ae463d94724fa64d3 -size 14330 +oid sha256:abfdd1e40c2c1d7fde419bda1da6e534ed989598e790b8ae4de35152a83f77a0 +size 13686 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_ErrorDither_0.75.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_ErrorDither_0.75.png index a1b3da6816..bf93c39ff8 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_ErrorDither_0.75.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_ErrorDither_0.75.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fda13875f4c762a95001426487cc04c9add39821eb793168fdbe5cc18e705643 -size 14566 +oid sha256:60c28eb1dc3c0416b20cec230917c0e4a70dd2929467bbab796ecbb04fe5a178 +size 13886 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_ErrorDither_0.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_ErrorDither_0.png index 82b965123d..a2fb2a6760 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_ErrorDither_0.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_ErrorDither_0.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4bed69d43856ebd4b1af4055f8d3aacabd50c361a4e1e1f9cad080d799d6b744 -size 13853 +oid sha256:18a47a6fa0f7949daef6969a847d8bc04deeb16bb482211ec3a958bc63f23f89 +size 13158 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_ErrorDither_1.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_ErrorDither_1.png index e0fc792026..457298b544 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_ErrorDither_1.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_ErrorDither_1.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cb826afb127fe4175e6e47253b8a8313b9d10aee193c316731f34e5d327a2591 -size 14580 +oid sha256:a523f097bf3b155f3823c5e400190b5d5e0d4470db7136576472c3257db76600 +size 13909 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_OrderedDither_0.25.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_OrderedDither_0.25.png index 491847e491..5431ffdefd 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_OrderedDither_0.25.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_OrderedDither_0.25.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:37018ecc499651833208d846a0f446db94cc11eae002ab6e7ce45b3e7c09e86c -size 17734 +oid sha256:dd8b648b89f9420a0004a5f95dd54dc3769d1f78816b6708c5c6e1c14e8533a1 +size 17802 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_OrderedDither_0.5.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_OrderedDither_0.5.png index 013bb4a3b7..02ade5b868 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_OrderedDither_0.5.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_OrderedDither_0.5.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c2f9ed902882f58704b22460bc64a7b27bc6f47fc2c822ee09f52345cc0d6ebf -size 19255 +oid sha256:7e559263bd8c293797d59166e723fdaf8b1b6ff9ae20fabac0efc86d8306123e +size 19266 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_OrderedDither_0.75.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_OrderedDither_0.75.png index 31fd7a5445..cfbb9c2d5c 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_OrderedDither_0.75.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_OrderedDither_0.75.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:aad3f26f2939f3679afa2b6165db29885fff40bbb1d171d5ffecc7861b5fac31 -size 19654 +oid sha256:5ae4ba533dd19271937d7e02e8ed3d243f164820b7d3bb20a4390e2deaa1d0d6 +size 19639 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_OrderedDither_0.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_OrderedDither_0.png index 82b965123d..a2fb2a6760 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_OrderedDither_0.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_OrderedDither_0.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4bed69d43856ebd4b1af4055f8d3aacabd50c361a4e1e1f9cad080d799d6b744 -size 13853 +oid sha256:18a47a6fa0f7949daef6969a847d8bc04deeb16bb482211ec3a958bc63f23f89 +size 13158 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_OrderedDither_1.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_OrderedDither_1.png index e2a05b9bd5..ce546cbfe1 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_OrderedDither_1.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_OctreeQuantizer_OrderedDither_1.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6d21029fa22dbe72cdc60b90c758cb9becd9fce03a33580d9466c1aedd323c1c -size 20000 +oid sha256:ac17dd1abc6405cb84e9d8a6404da2c2bdb220b3390d09613d3644baad6e8e99 +size 20128 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_ErrorDither_0.25.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_ErrorDither_0.25.png index dba9232097..eaf7e8241d 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_ErrorDither_0.25.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_ErrorDither_0.25.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:faa91657288e6a6797d8459d41d5fecca3c0a2e8e63317ebaf47df28688d13d7 -size 13853 +oid sha256:4baf0e7bc4ae8b8a911d87f3a7af2bf3ef0235f77f3f509251f2d2f26cfb639d +size 13158 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_ErrorDither_0.5.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_ErrorDither_0.5.png index ea062d5be6..02879b7a38 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_ErrorDither_0.5.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_ErrorDither_0.5.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:79e48506430f3a9b25f484ef191fd820819c438392a4e588c2ecafb6db9a2210 -size 13775 +oid sha256:c4ac8b88b317281738d833fc71f52348d9f4f45ea5a1303dd91fdb8b42be4267 +size 13186 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_ErrorDither_0.75.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_ErrorDither_0.75.png index ae90ea9b5f..ba05094800 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_ErrorDither_0.75.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_ErrorDither_0.75.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f56c884a0e4666cd662d36ec3a0d4e751c899c0122595378154507fffc69fda4 -size 14010 +oid sha256:1305d54f2139d4577490317051d6ce94a7fc8dd45b902d87a30fb04098dd4594 +size 13407 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_ErrorDither_0.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_ErrorDither_0.png index dba9232097..eaf7e8241d 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_ErrorDither_0.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_ErrorDither_0.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:faa91657288e6a6797d8459d41d5fecca3c0a2e8e63317ebaf47df28688d13d7 -size 13853 +oid sha256:4baf0e7bc4ae8b8a911d87f3a7af2bf3ef0235f77f3f509251f2d2f26cfb639d +size 13158 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_ErrorDither_1.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_ErrorDither_1.png index 1e1795063b..b16a5a5c7b 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_ErrorDither_1.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_ErrorDither_1.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4095927693b3cd49df58c0c1d7c5430255350c9ae595408a52ad83b1a65614ac -size 14269 +oid sha256:a3fc3a7ace123c330ea06072eb36dd5d65ed9154d4d0f55a828fc542c8a422c1 +size 13472 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_OrderedDither_0.25.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_OrderedDither_0.25.png index 29a3ed7ffd..6adac16cf5 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_OrderedDither_0.25.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_OrderedDither_0.25.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d062d4b79ee01942776ae13467e9bcbb529a7eeb5ad7c28ff3d0ccd3d88dcde6 -size 15962 +oid sha256:35757f2e0831cae2fbd3cc11ffaaae855e853ebaa9a1a5564b6568a5e1c442e9 +size 16031 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_OrderedDither_0.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_OrderedDither_0.png index dba9232097..eaf7e8241d 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_OrderedDither_0.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantizationWithDitheringScale_david_WuQuantizer_OrderedDither_0.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:faa91657288e6a6797d8459d41d5fecca3c0a2e8e63317ebaf47df28688d13d7 -size 13853 +oid sha256:4baf0e7bc4ae8b8a911d87f3a7af2bf3ef0235f77f3f509251f2d2f26cfb639d +size 13158 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_Bike_OctreeQuantizer_ErrorDither.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_Bike_OctreeQuantizer_ErrorDither.png index 09c471914a..e9782bc076 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_Bike_OctreeQuantizer_ErrorDither.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_Bike_OctreeQuantizer_ErrorDither.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a40b319d264f046159722cb57599eda51de9ba3795272b3785901cdc51053fab -size 83010 +oid sha256:b380eda5646fe97ee217ef711103001e54ee023fb8d95f7f3bbad19d886130da +size 83702 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_Bike_OctreeQuantizer_NoDither.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_Bike_OctreeQuantizer_NoDither.png index 3bd7cbabbb..5e1556dc45 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_Bike_OctreeQuantizer_NoDither.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_Bike_OctreeQuantizer_NoDither.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3bc93509a983e20986614f4937f66d5d979bbb433a30a7736150934cf14b452a -size 55213 +oid sha256:af9e6c3b9e9e90186fb66be188bad9f3f0738d558aab915b3c8dd78652010674 +size 55419 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_Bike_OctreeQuantizer_OrderedDither.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_Bike_OctreeQuantizer_OrderedDither.png index 34490e602d..601abdeb4c 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_Bike_OctreeQuantizer_OrderedDither.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_Bike_OctreeQuantizer_OrderedDither.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b92f3320120d53444cefc79b4684933cfe2b933dc79c2414496785743b5c8f18 -size 80808 +oid sha256:aba024f962e5dc96e118b68c19903045f43a327c6cf45643da195382ef79a778 +size 84368 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_Bike_WuQuantizer_ErrorDither.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_Bike_WuQuantizer_ErrorDither.png index 747ca70c1d..37e5035d86 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_Bike_WuQuantizer_ErrorDither.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_Bike_WuQuantizer_ErrorDither.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d58c425ce5b1ca56450095a66dea24b379935b0087aec7b4102f15a99f95a017 -size 101999 +oid sha256:3802cfe67638a24869d6cc9ace1d94460b4c0c26f2c91b12b95fa8f979de64bb +size 101579 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_Bike_WuQuantizer_NoDither.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_Bike_WuQuantizer_NoDither.png index de464b94cc..e72ea4b246 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_Bike_WuQuantizer_NoDither.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_Bike_WuQuantizer_NoDither.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:93a4822e39babba059a88536a965e4f3207e4402d2b92d7d18485fec5e9e69da -size 84378 +oid sha256:bf2021eba9edbb2295924f8394472ac0bb237f0c462c39aa32a2074ef15f9acc +size 81771 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_Bike_WuQuantizer_OrderedDither.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_Bike_WuQuantizer_OrderedDither.png index ce54548279..0997945e52 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_Bike_WuQuantizer_OrderedDither.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_Bike_WuQuantizer_OrderedDither.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:35969c8dc96de4dacc3048ae760a0681278a2011993a0edbceaacc93d6fc3a67 -size 102713 +oid sha256:2d11b18946d373b995ecbb449c8c4cfcc7078aad1c8705997bcbf83131acde03 +size 102439 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_OctreeQuantizer_ErrorDither.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_OctreeQuantizer_ErrorDither.png index 5efcaedc94..314a056060 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_OctreeQuantizer_ErrorDither.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_OctreeQuantizer_ErrorDither.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:40d012f4ecb4e36c94d086f8ec7bc199fbfd9fb30a9427a07b35df1b1e430a71 -size 95601 +oid sha256:2236e81d33fcfb50afb9d5fd1a38c5ddf5d33fbb52de1c3204a4a9892fd334ce +size 99084 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_OctreeQuantizer_NoDither.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_OctreeQuantizer_NoDither.png index 916dc37566..5293046724 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_OctreeQuantizer_NoDither.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_OctreeQuantizer_NoDither.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fa64863f73dfd1c5daef645c54e9275136f66513a87750bee0ec8e13ac357da5 -size 79649 +oid sha256:c4b59097d1507236af2556ae5f2638360b223b7752cd4c8f760bc14673d811d0 +size 81709 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_OctreeQuantizer_OrderedDither.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_OctreeQuantizer_OrderedDither.png index f039dd222e..d253a321d5 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_OctreeQuantizer_OrderedDither.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_OctreeQuantizer_OrderedDither.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8f5138589c606de20ba193d4279f049ee1ecb3f1801b949d3436995bbf242cbe -size 92683 +oid sha256:3fa41128fd3f7a6b4b74b758186494ce7ed780561b9825277fae0c345116b1d7 +size 95067 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WebSafePaletteQuantizer_ErrorDither.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WebSafePaletteQuantizer_ErrorDither.png index 2b897a5d6d..a14c2cb1f6 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WebSafePaletteQuantizer_ErrorDither.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WebSafePaletteQuantizer_ErrorDither.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:007ac609ec61b39c7bdd04bc87a698f5cdc76eadd834c1457f41eb9c135c3f7b +oid sha256:7fb3743098a8147fd24294d933d93a61ec0155d754f52544650f6589719905be size 60688 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WebSafePaletteQuantizer_OrderedDither.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WebSafePaletteQuantizer_OrderedDither.png index ac56fa9236..03848e81ce 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WebSafePaletteQuantizer_OrderedDither.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WebSafePaletteQuantizer_OrderedDither.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6d2289ed4fa0c679f0f120d260fec8ab40b1599043cc0a1fbebc6b67e238ff87 -size 51428 +oid sha256:ef033a419e2e1b06b57a66175bad9068f71ae4c862a66c5734f65cdaae8a27f0 +size 51461 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WernerPaletteQuantizer_ErrorDither.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WernerPaletteQuantizer_ErrorDither.png index 8b79a19e05..0d548ca79d 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WernerPaletteQuantizer_ErrorDither.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WernerPaletteQuantizer_ErrorDither.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ef2b6073b75a2de97a78d47d3b3e40c264687c5756f153d3d85bc5b2714cf85a -size 68226 +oid sha256:e2f4f4e2237925403fd0228344f9fce9be96c0f26e3465775763aca775779763 +size 68222 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WernerPaletteQuantizer_OrderedDither.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WernerPaletteQuantizer_OrderedDither.png index 88cf83a306..b51076bd17 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WernerPaletteQuantizer_OrderedDither.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WernerPaletteQuantizer_OrderedDither.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:513844ed95c2b50e792d3346398256846b8b280dbadf7ef3f4e11d58c1e679c0 -size 69529 +oid sha256:7a8d9c0d81525d9f37d2f36946939040aea30edfc2b7ec0bf329fb49f6c7d73f +size 69896 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WuQuantizer_ErrorDither.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WuQuantizer_ErrorDither.png index a3eefcba20..7204abff47 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WuQuantizer_ErrorDither.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WuQuantizer_ErrorDither.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:32b269d62d4eebe555d5d9f12b9958b41206848504bb985dcd1ff9c81a5003c6 -size 117073 +oid sha256:4474b94e2d563938e10ec0526e7d94ba06b440db51b910604e752f7f9e814d66 +size 110757 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WuQuantizer_NoDither.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WuQuantizer_NoDither.png index 3b0c46ac38..691623fc88 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WuQuantizer_NoDither.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WuQuantizer_NoDither.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:12f58b00a16913cd85ffa18fcea580a59550dcc201295b060d55a870230f37f7 -size 113995 +oid sha256:58a61c1d9a1d05acd484948c3e5c0496dbc74c0060f5de71741de39eae04ffa8 +size 103875 diff --git a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WuQuantizer_OrderedDither.png b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WuQuantizer_OrderedDither.png index 328f863307..e80e6c6e81 100644 --- a/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WuQuantizer_OrderedDither.png +++ b/tests/Images/External/ReferenceOutput/QuantizerTests/ApplyQuantization_CalliphoraPartial_WuQuantizer_OrderedDither.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:867d7b727de278cbc01b7d2b8e968f1fc0d0a81a3e4af636ce4a6598a8709be6 -size 114630 +oid sha256:b6649918c0394ead13c016a57b6a08561290651bccac88f7f15ba0e29dc5faa4 +size 110422 diff --git a/tests/Images/Input/Gif/animated_loop.gif b/tests/Images/Input/Gif/animated_loop.gif new file mode 100644 index 0000000000..5fad702a10 --- /dev/null +++ b/tests/Images/Input/Gif/animated_loop.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a8750149c953e9e910472684158c07a2cb551c1f7e95744ab48db1a67f63f342 +size 873 diff --git a/tests/Images/Input/Gif/animated_loop_interlaced.gif b/tests/Images/Input/Gif/animated_loop_interlaced.gif new file mode 100644 index 0000000000..9577a84658 --- /dev/null +++ b/tests/Images/Input/Gif/animated_loop_interlaced.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c2bc2f895f03092b1c26381a32b5dd5838aacd3331e07f7e4dae55d5cbb4e149 +size 878 diff --git a/tests/Images/Input/Gif/animated_transparent_firstframerestoreprev_loop.gif b/tests/Images/Input/Gif/animated_transparent_firstframerestoreprev_loop.gif new file mode 100644 index 0000000000..5012324caf --- /dev/null +++ b/tests/Images/Input/Gif/animated_transparent_firstframerestoreprev_loop.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6b0cf18d386dc979fcf853d6a9adac673a2709a8751d31a94930199dededa25f +size 536 diff --git a/tests/Images/Input/Gif/animated_transparent_frame_norestore_loop.gif b/tests/Images/Input/Gif/animated_transparent_frame_norestore_loop.gif new file mode 100644 index 0000000000..712f334aba --- /dev/null +++ b/tests/Images/Input/Gif/animated_transparent_frame_norestore_loop.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ad7359801fa6ed89fb041de1e88faea856b1028d9f477fdc4eda774df6e5f1ce +size 685 diff --git a/tests/Images/Input/Gif/animated_transparent_frame_restorebackground_loop.gif b/tests/Images/Input/Gif/animated_transparent_frame_restorebackground_loop.gif new file mode 100644 index 0000000000..b6f675dcaf --- /dev/null +++ b/tests/Images/Input/Gif/animated_transparent_frame_restorebackground_loop.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:12254f22eeee9eac6babbfbfb34b6ae9302342454fd6677e8c7c9937656cc127 +size 685 diff --git a/tests/Images/Input/Gif/animated_transparent_frame_restoreprev_loop.gif b/tests/Images/Input/Gif/animated_transparent_frame_restoreprev_loop.gif new file mode 100644 index 0000000000..be7fdf85d8 --- /dev/null +++ b/tests/Images/Input/Gif/animated_transparent_frame_restoreprev_loop.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0cdfba6efea653bb94ede6edd0577ba6af1f7c130307b94903dd94f0f8bbc4f9 +size 685 diff --git a/tests/Images/Input/Gif/animated_transparent_loop.gif b/tests/Images/Input/Gif/animated_transparent_loop.gif new file mode 100644 index 0000000000..cb001ece8f --- /dev/null +++ b/tests/Images/Input/Gif/animated_transparent_loop.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3297987894ba27c2acc6a5c447c3d3a52cc169447b451409535decccc1743e55 +size 536 diff --git a/tests/Images/Input/Gif/animated_transparent_restoreprev_loop.gif b/tests/Images/Input/Gif/animated_transparent_restoreprev_loop.gif new file mode 100644 index 0000000000..f51d02433e --- /dev/null +++ b/tests/Images/Input/Gif/animated_transparent_restoreprev_loop.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9418561ef2f2307456bb068ecc1a9d5aa02da5e314e7aadd722985e27503926b +size 536 diff --git a/tests/Images/Input/Gif/issues/issue_2866.gif b/tests/Images/Input/Gif/issues/issue_2866.gif new file mode 100644 index 0000000000..0ead86bf89 --- /dev/null +++ b/tests/Images/Input/Gif/issues/issue_2866.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0b2a9e3728c41e1b45d6f865e4692eadbed28dcaec65806e6bda22a9a16f930f +size 7526725 diff --git a/tests/Images/Input/Gif/static_nontransparent.gif b/tests/Images/Input/Gif/static_nontransparent.gif new file mode 100644 index 0000000000..17ab1e2ec7 --- /dev/null +++ b/tests/Images/Input/Gif/static_nontransparent.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d0a5e1b2f0c5c1763eb950a1d92c5317f048875e04e88dca7f1a966552c2774c +size 678 diff --git a/tests/Images/Input/Gif/static_transparent.gif b/tests/Images/Input/Gif/static_transparent.gif new file mode 100644 index 0000000000..89039a732a --- /dev/null +++ b/tests/Images/Input/Gif/static_transparent.gif @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f73f56bbe2206bd1cd8a4625b6a4d61506214b37b61ff3e8194e2030b28abca5 +size 341 diff --git a/tests/Images/Input/Jpg/icc-profiles/Momiji-AdobeRGB-yes.jpg b/tests/Images/Input/Jpg/icc-profiles/Momiji-AdobeRGB-yes.jpg new file mode 100644 index 0000000000..077ee22beb --- /dev/null +++ b/tests/Images/Input/Jpg/icc-profiles/Momiji-AdobeRGB-yes.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cb8bdcc137efa3e28db69e48612230b3a9fec17267de9ce29757d9bacc181d28 +size 42001 diff --git a/tests/Images/Input/Jpg/icc-profiles/Momiji-AppleRGB-yes.jpg b/tests/Images/Input/Jpg/icc-profiles/Momiji-AppleRGB-yes.jpg new file mode 100644 index 0000000000..188faa2bdd --- /dev/null +++ b/tests/Images/Input/Jpg/icc-profiles/Momiji-AppleRGB-yes.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7129f5485e997b75cff143021522cc8ab94e2c3c1912689bc765ce2b3b937441 +size 72150 diff --git a/tests/Images/Input/Jpg/icc-profiles/Momiji-ColorMatch-yes.jpg b/tests/Images/Input/Jpg/icc-profiles/Momiji-ColorMatch-yes.jpg new file mode 100644 index 0000000000..befc3d1170 --- /dev/null +++ b/tests/Images/Input/Jpg/icc-profiles/Momiji-ColorMatch-yes.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fe7fa60a53893836200c62f34492c7a0c931692dd073dffa4afc49fe3826e433 +size 44446 diff --git a/tests/Images/Input/Jpg/icc-profiles/Momiji-ProPhoto-yes.jpg b/tests/Images/Input/Jpg/icc-profiles/Momiji-ProPhoto-yes.jpg new file mode 100644 index 0000000000..645ad2869a --- /dev/null +++ b/tests/Images/Input/Jpg/icc-profiles/Momiji-ProPhoto-yes.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bb686b44e3253143a32db890823f63c79026c9ac9badc4ad9de21f6cb2fa2f2a +size 40703 diff --git a/tests/Images/Input/Jpg/icc-profiles/Momiji-WideRGB-yes.jpg b/tests/Images/Input/Jpg/icc-profiles/Momiji-WideRGB-yes.jpg new file mode 100644 index 0000000000..57727aaa29 --- /dev/null +++ b/tests/Images/Input/Jpg/icc-profiles/Momiji-WideRGB-yes.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:928b854a9629d1532d37095c4744da6bc2fc986f878a76aea373f69490f4b586 +size 40505 diff --git a/tests/Images/Input/Jpg/icc-profiles/Momiji-sRGB-yes.jpg b/tests/Images/Input/Jpg/icc-profiles/Momiji-sRGB-yes.jpg new file mode 100644 index 0000000000..4b7b612be0 --- /dev/null +++ b/tests/Images/Input/Jpg/icc-profiles/Momiji-sRGB-yes.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:faf67048c2b7bd3fb5fa9b69bd53943d63a216ef371c5dc9d062ac443c9d2d34 +size 47434 diff --git a/tests/Images/Input/Jpg/icc-profiles/issue-129.jpg b/tests/Images/Input/Jpg/icc-profiles/issue-129.jpg new file mode 100644 index 0000000000..98949f43f1 --- /dev/null +++ b/tests/Images/Input/Jpg/icc-profiles/issue-129.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e1728dd548d862ef3f960c82528716e0ad1b8eb0119a5eed4dfde51026d7bb74 +size 2903429 diff --git a/tests/Images/Input/Png/issues/Issue_2882.png b/tests/Images/Input/Png/issues/Issue_2882.png new file mode 100644 index 0000000000..2d7a51dacb --- /dev/null +++ b/tests/Images/Input/Png/issues/Issue_2882.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cebc98e62bcfe31df73ae7b6980382f4b56bdf7e7e6e9037946f5a84cb51c7d2 +size 1117 diff --git a/tests/Images/Input/Png/issues/issue_2469-i.png b/tests/Images/Input/Png/issues/issue_2469-i.png new file mode 100644 index 0000000000..bd651a3f2d --- /dev/null +++ b/tests/Images/Input/Png/issues/issue_2469-i.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d4e0da0601ca5f479684359633c4dbd82881a35631d63477c01e8fd180e31482 +size 2521324 diff --git a/tests/Images/Input/Webp/alpha-blend-2.webp b/tests/Images/Input/Webp/alpha-blend-2.webp new file mode 100644 index 0000000000..3ca4c77cff --- /dev/null +++ b/tests/Images/Input/Webp/alpha-blend-2.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b07a49ab8b3af82fa123faf897ec537cd26d57175b1d6301b617372c06432899 +size 1580484 diff --git a/tests/Images/Input/Webp/alpha-blend-3.webp b/tests/Images/Input/Webp/alpha-blend-3.webp new file mode 100644 index 0000000000..1922f561d5 --- /dev/null +++ b/tests/Images/Input/Webp/alpha-blend-3.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b7244a2cfb42285a196fc7846c49da65fac47e5b85f735bc07b131707c8a2d46 +size 948 diff --git a/tests/Images/Input/Webp/alpha-blend-4.webp b/tests/Images/Input/Webp/alpha-blend-4.webp new file mode 100644 index 0000000000..6f4db231f6 --- /dev/null +++ b/tests/Images/Input/Webp/alpha-blend-4.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8c8b98f188d006715bd5bc60593ff2a379078f28a7fc14a51d28ae1cfb279aac +size 2185502 diff --git a/tests/Images/Input/Webp/alpha-blend.webp b/tests/Images/Input/Webp/alpha-blend.webp new file mode 100644 index 0000000000..110d2a594c --- /dev/null +++ b/tests/Images/Input/Webp/alpha-blend.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5dc2762d1c1030fb951e1af57eaa7e66035a7b5e63bd9dc9f9bd50f0ff5c4c3a +size 1297692 diff --git a/tests/Images/Input/Webp/issues/Issue2866.webp b/tests/Images/Input/Webp/issues/Issue2866.webp new file mode 100644 index 0000000000..845569624d --- /dev/null +++ b/tests/Images/Input/Webp/issues/Issue2866.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:15e8a52a6d528fe071e73b037543b682bf62da7bab6d98ab690f25dd97f7298e +size 248688