Decompiled source of SixLabors ImageSharp v2.1.13
SixLabors.ImageSharp.dll
Decompiled 9 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Buffers; using System.Buffers.Binary; using System.Buffers.Text; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.IO.Compression; using System.Linq; using System.Numerics; using System.Reflection; using System.Resources; using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Cryptography; using System.Security.Permissions; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Xml.Linq; using Microsoft.CodeAnalysis; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.ColorSpaces; using SixLabors.ImageSharp.ColorSpaces.Companding; using SixLabors.ImageSharp.ColorSpaces.Conversion; using SixLabors.ImageSharp.Common.Helpers; using SixLabors.ImageSharp.Compression.Zlib; using SixLabors.ImageSharp.Diagnostics; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Bmp; using SixLabors.ImageSharp.Formats.Gif; using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Formats.Jpeg.Components; using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters; using SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder; using SixLabors.ImageSharp.Formats.Pbm; using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.Formats.Png.Chunks; using SixLabors.ImageSharp.Formats.Png.Filters; using SixLabors.ImageSharp.Formats.Tga; using SixLabors.ImageSharp.Formats.Tiff; using SixLabors.ImageSharp.Formats.Tiff.Compression; using SixLabors.ImageSharp.Formats.Tiff.Compression.Compressors; using SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors; using SixLabors.ImageSharp.Formats.Tiff.Constants; using SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation; using SixLabors.ImageSharp.Formats.Tiff.Utils; using SixLabors.ImageSharp.Formats.Tiff.Writers; using SixLabors.ImageSharp.Formats.Webp; using SixLabors.ImageSharp.Formats.Webp.BitReader; using SixLabors.ImageSharp.Formats.Webp.BitWriter; using SixLabors.ImageSharp.Formats.Webp.Lossless; using SixLabors.ImageSharp.Formats.Webp.Lossy; using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory.Internals; using SixLabors.ImageSharp.Metadata; using SixLabors.ImageSharp.Metadata.Profiles.Exif; using SixLabors.ImageSharp.Metadata.Profiles.Icc; using SixLabors.ImageSharp.Metadata.Profiles.Iptc; using SixLabors.ImageSharp.Metadata.Profiles.Xmp; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats.PixelBlenders; using SixLabors.ImageSharp.PixelFormats.Utils; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors; using SixLabors.ImageSharp.Processing.Processors.Binarization; using SixLabors.ImageSharp.Processing.Processors.Convolution; using SixLabors.ImageSharp.Processing.Processors.Convolution.Parameters; using SixLabors.ImageSharp.Processing.Processors.Dithering; using SixLabors.ImageSharp.Processing.Processors.Drawing; using SixLabors.ImageSharp.Processing.Processors.Effects; using SixLabors.ImageSharp.Processing.Processors.Filters; using SixLabors.ImageSharp.Processing.Processors.Normalization; using SixLabors.ImageSharp.Processing.Processors.Overlays; using SixLabors.ImageSharp.Processing.Processors.Quantization; using SixLabors.ImageSharp.Processing.Processors.Transforms; using SixLabors.ImageSharp.Tuples; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] [assembly: InternalsVisibleTo("ImageSharp.Benchmarks, PublicKey=00240000048000009400000006020000002400005253413100040000010001000147e6fe6766715eec6cfed61f1e7dcdbf69748a3e355c67e9d8dfd953acab1d5e012ba34b23308166fdc61ee1d0390d5f36d814a6091dd4b5ed9eda5a26afced924c683b4bfb4b3d64b0586a57eff9f02b1f84e3cb0ddd518bd1697f2c84dcbb97eb8bb5c7801be12112ed0ec86db934b0e9a5171e6bb1384b6d2f7d54dfa97")] [assembly: InternalsVisibleTo("ImageSharp.Tests.ProfilingSandbox, PublicKey=00240000048000009400000006020000002400005253413100040000010001000147e6fe6766715eec6cfed61f1e7dcdbf69748a3e355c67e9d8dfd953acab1d5e012ba34b23308166fdc61ee1d0390d5f36d814a6091dd4b5ed9eda5a26afced924c683b4bfb4b3d64b0586a57eff9f02b1f84e3cb0ddd518bd1697f2c84dcbb97eb8bb5c7801be12112ed0ec86db934b0e9a5171e6bb1384b6d2f7d54dfa97")] [assembly: InternalsVisibleTo("SixLabors.ImageSharp.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001000147e6fe6766715eec6cfed61f1e7dcdbf69748a3e355c67e9d8dfd953acab1d5e012ba34b23308166fdc61ee1d0390d5f36d814a6091dd4b5ed9eda5a26afced924c683b4bfb4b3d64b0586a57eff9f02b1f84e3cb0ddd518bd1697f2c84dcbb97eb8bb5c7801be12112ed0ec86db934b0e9a5171e6bb1384b6d2f7d54dfa97")] [assembly: InternalsVisibleTo("SixLabors.ImageSharp.Drawing.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001000147e6fe6766715eec6cfed61f1e7dcdbf69748a3e355c67e9d8dfd953acab1d5e012ba34b23308166fdc61ee1d0390d5f36d814a6091dd4b5ed9eda5a26afced924c683b4bfb4b3d64b0586a57eff9f02b1f84e3cb0ddd518bd1697f2c84dcbb97eb8bb5c7801be12112ed0ec86db934b0e9a5171e6bb1384b6d2f7d54dfa97")] [assembly: AssemblyCompany("Six Labors")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Copyright © Six Labors")] [assembly: AssemblyDescription("A new, fully featured, fully managed, cross-platform, 2D graphics API for .NET")] [assembly: AssemblyFileVersion("2.1.13.0")] [assembly: AssemblyInformationalVersion("2.1.13+2c3967b22543545c902fb1fecf57d44025bda84d")] [assembly: AssemblyProduct("SixLabors.ImageSharp")] [assembly: AssemblyTitle("SixLabors.ImageSharp")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/SixLabors/ImageSharp")] [assembly: NeutralResourcesLanguage("en")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("2.0.0.0")] [assembly: TypeForwardedTo(typeof(ExcludeFromCodeCoverageAttribute))] [assembly: TypeForwardedTo(typeof(HashCode))] [assembly: TypeForwardedTo(typeof(MathF))] [module: UnverifiableCode] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] internal sealed class IsUnmanagedAttribute : Attribute { } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NativeIntegerAttribute : Attribute { public readonly bool[] TransformFlags; public NativeIntegerAttribute() { TransformFlags = new bool[1] { true }; } public NativeIntegerAttribute(bool[] P_0) { TransformFlags = P_0; } } } namespace SixLabors { [DebuggerStepThrough] internal static class DebugGuard { [Conditional("DEBUG")] public static void IsTrue(bool target, string message) { if (!target) { throw new InvalidOperationException(message); } } [Conditional("DEBUG")] public static void NotDisposed(bool isDisposed, string objectName) { if (isDisposed) { throw new ObjectDisposedException(objectName); } } [Conditional("DEBUG")] public static void MustBeSameSized<T>(ReadOnlySpan<T> target, ReadOnlySpan<T> other, string parameterName) where T : struct { if (target.Length != other.Length) { throw new ArgumentException("Span-s must be the same size!", parameterName); } } [Conditional("DEBUG")] public static void MustBeSizedAtLeast<T>(ReadOnlySpan<T> target, ReadOnlySpan<T> minSpan, string parameterName) where T : struct { if (target.Length < minSpan.Length) { throw new ArgumentException($"Span-s must be at least of length {minSpan.Length}!", parameterName); } } [Conditional("DEBUG")] public static void NotNull<TValue>(TValue value, string parameterName) where TValue : class { if (value == null) { ThrowArgumentNullException(parameterName); } } [Conditional("DEBUG")] public static void NotNullOrWhiteSpace(string value, string parameterName) { if (value == null) { ThrowArgumentNullException(parameterName); } if (string.IsNullOrWhiteSpace(value)) { ThrowArgumentException("Must not be empty or whitespace.", parameterName); } } [Conditional("DEBUG")] public static void MustBeLessThan<TValue>(TValue value, TValue max, string parameterName) where TValue : IComparable<TValue> { if (value.CompareTo(max) >= 0) { ThrowArgumentOutOfRangeException(parameterName, $"Value {value} must be less than {max}."); } } [Conditional("DEBUG")] public static void MustBeLessThanOrEqualTo<TValue>(TValue value, TValue max, string parameterName) where TValue : IComparable<TValue> { if (value.CompareTo(max) > 0) { ThrowArgumentOutOfRangeException(parameterName, $"Value {value} must be less than or equal to {max}."); } } [Conditional("DEBUG")] public static void MustBeGreaterThan<TValue>(TValue value, TValue min, string parameterName) where TValue : IComparable<TValue> { if (value.CompareTo(min) <= 0) { ThrowArgumentOutOfRangeException(parameterName, $"Value {value} must be greater than {min}."); } } [Conditional("DEBUG")] public static void MustBeGreaterThanOrEqualTo<TValue>(TValue value, TValue min, string parameterName) where TValue : IComparable<TValue> { if (value.CompareTo(min) < 0) { ThrowArgumentOutOfRangeException(parameterName, $"Value {value} must be greater than or equal to {min}."); } } [Conditional("DEBUG")] public static void MustBeBetweenOrEqualTo<TValue>(TValue value, TValue min, TValue max, string parameterName) where TValue : IComparable<TValue> { if (value.CompareTo(min) < 0 || value.CompareTo(max) > 0) { ThrowArgumentOutOfRangeException(parameterName, $"Value {value} must be greater than or equal to {min} and less than or equal to {max}."); } } [Conditional("DEBUG")] public static void IsTrue(bool target, string parameterName, string message) { if (!target) { ThrowArgumentException(message, parameterName); } } [Conditional("DEBUG")] public static void IsFalse(bool target, string parameterName, string message) { if (target) { ThrowArgumentException(message, parameterName); } } [Conditional("DEBUG")] public static void MustBeSizedAtLeast<T>(ReadOnlySpan<T> source, int minLength, string parameterName) { if (source.Length < minLength) { ThrowArgumentException($"Span-s must be at least of length {minLength}!", parameterName); } } [Conditional("DEBUG")] public static void MustBeSizedAtLeast<T>(Span<T> source, int minLength, string parameterName) { if (source.Length < minLength) { ThrowArgumentException($"The size must be at least {minLength}.", parameterName); } } [Conditional("DEBUG")] public static void DestinationShouldNotBeTooShort<TSource, TDest>(ReadOnlySpan<TSource> source, Span<TDest> destination, string destinationParamName) { if (destination.Length < source.Length) { ThrowArgumentException("Destination span is too short!", destinationParamName); } } [Conditional("DEBUG")] public static void DestinationShouldNotBeTooShort<TSource, TDest>(Span<TSource> source, Span<TDest> destination, string destinationParamName) { if (destination.Length < source.Length) { ThrowArgumentException("Destination span is too short!", destinationParamName); } } [MethodImpl(MethodImplOptions.NoInlining)] private static void ThrowArgumentException(string message, string parameterName) { throw new ArgumentException(message, parameterName); } [MethodImpl(MethodImplOptions.NoInlining)] private static void ThrowArgumentOutOfRangeException(string parameterName, string message) { throw new ArgumentOutOfRangeException(parameterName, message); } [MethodImpl(MethodImplOptions.NoInlining)] private static void ThrowArgumentNullException(string parameterName) { throw new ArgumentNullException(parameterName); } } [DebuggerStepThrough] internal static class Guard { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeValueType<TValue>(TValue value, string parameterName) { if (!value.GetType().IsValueType) { ThrowHelper.ThrowArgumentException("Type must be a struct.", parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void NotNull<TValue>(TValue value, string parameterName) where TValue : class { if (value == null) { ThrowHelper.ThrowArgumentNullExceptionForNotNull(parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void NotNullOrWhiteSpace(string value, string parameterName) { if (string.IsNullOrWhiteSpace(value)) { ThrowHelper.ThrowArgumentExceptionForNotNullOrWhitespace(value, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan<TValue>(TValue value, TValue max, string parameterName) where TValue : IComparable<TValue> { if (value.CompareTo(max) >= 0) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo<TValue>(TValue value, TValue max, string parameterName) where TValue : IComparable<TValue> { if (value.CompareTo(max) > 0) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan<TValue>(TValue value, TValue min, string parameterName) where TValue : IComparable<TValue> { if (value.CompareTo(min) <= 0) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo<TValue>(TValue value, TValue min, string parameterName) where TValue : IComparable<TValue> { if (value.CompareTo(min) < 0) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo<TValue>(TValue value, TValue min, TValue max, string parameterName) where TValue : IComparable<TValue> { if (value.CompareTo(min) < 0 || value.CompareTo(max) > 0) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void IsTrue(bool target, string parameterName, string message) { if (!target) { ThrowHelper.ThrowArgumentException(message, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void IsFalse(bool target, string parameterName, string message) { if (target) { ThrowHelper.ThrowArgumentException(message, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeSizedAtLeast<T>(ReadOnlySpan<T> source, int minLength, string parameterName) { if (source.Length < minLength) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeSizedAtLeast(minLength, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeSizedAtLeast<T>(Span<T> source, int minLength, string parameterName) { if (source.Length < minLength) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeSizedAtLeast(minLength, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void DestinationShouldNotBeTooShort<TSource, TDest>(ReadOnlySpan<TSource> source, Span<TDest> destination, string destinationParamName) { if (destination.Length < source.Length) { ThrowHelper.ThrowArgumentException("Destination span is too short!", destinationParamName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void DestinationShouldNotBeTooShort<TSource, TDest>(Span<TSource> source, Span<TDest> destination, string destinationParamName) { if (destination.Length < source.Length) { ThrowHelper.ThrowArgumentException("Destination span is too short!", destinationParamName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan(byte value, byte max, string parameterName) { if (value >= max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo(byte value, byte max, string parameterName) { if (value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan(byte value, byte min, string parameterName) { if (value <= min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo(byte value, byte min, string parameterName) { if (value < min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo(byte value, byte min, byte max, string parameterName) { if (value < min || value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan(sbyte value, sbyte max, string parameterName) { if (value >= max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo(sbyte value, sbyte max, string parameterName) { if (value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan(sbyte value, sbyte min, string parameterName) { if (value <= min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo(sbyte value, sbyte min, string parameterName) { if (value < min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo(sbyte value, sbyte min, sbyte max, string parameterName) { if (value < min || value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan(short value, short max, string parameterName) { if (value >= max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo(short value, short max, string parameterName) { if (value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan(short value, short min, string parameterName) { if (value <= min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo(short value, short min, string parameterName) { if (value < min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo(short value, short min, short max, string parameterName) { if (value < min || value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan(ushort value, ushort max, string parameterName) { if (value >= max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo(ushort value, ushort max, string parameterName) { if (value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan(ushort value, ushort min, string parameterName) { if (value <= min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo(ushort value, ushort min, string parameterName) { if (value < min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo(ushort value, ushort min, ushort max, string parameterName) { if (value < min || value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan(char value, char max, string parameterName) { if (value >= max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo(char value, char max, string parameterName) { if (value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan(char value, char min, string parameterName) { if (value <= min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo(char value, char min, string parameterName) { if (value < min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo(char value, char min, char max, string parameterName) { if (value < min || value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan(int value, int max, string parameterName) { if (value >= max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo(int value, int max, string parameterName) { if (value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan(int value, int min, string parameterName) { if (value <= min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo(int value, int min, string parameterName) { if (value < min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo(int value, int min, int max, string parameterName) { if (value < min || value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan(uint value, uint max, string parameterName) { if (value >= max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo(uint value, uint max, string parameterName) { if (value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan(uint value, uint min, string parameterName) { if (value <= min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo(uint value, uint min, string parameterName) { if (value < min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo(uint value, uint min, uint max, string parameterName) { if (value < min || value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan(float value, float max, string parameterName) { if (!(value < max)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo(float value, float max, string parameterName) { if (!(value <= max)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan(float value, float min, string parameterName) { if (!(value > min)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo(float value, float min, string parameterName) { if (!(value >= min)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo(float value, float min, float max, string parameterName) { if (!(value >= min) || !(value <= max)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan(long value, long max, string parameterName) { if (value >= max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo(long value, long max, string parameterName) { if (value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan(long value, long min, string parameterName) { if (value <= min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo(long value, long min, string parameterName) { if (value < min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo(long value, long min, long max, string parameterName) { if (value < min || value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan(ulong value, ulong max, string parameterName) { if (value >= max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo(ulong value, ulong max, string parameterName) { if (value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan(ulong value, ulong min, string parameterName) { if (value <= min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo(ulong value, ulong min, string parameterName) { if (value < min) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo(ulong value, ulong min, ulong max, string parameterName) { if (value < min || value > max) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan(double value, double max, string parameterName) { if (!(value < max)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo(double value, double max, string parameterName) { if (!(value <= max)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan(double value, double min, string parameterName) { if (!(value > min)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo(double value, double min, string parameterName) { if (!(value >= min)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo(double value, double min, double max, string parameterName) { if (!(value >= min) || !(value <= max)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThan(decimal value, decimal max, string parameterName) { if (!(value < max)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThan(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeLessThanOrEqualTo(decimal value, decimal max, string parameterName) { if (!(value <= max)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo(value, max, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThan(decimal value, decimal min, string parameterName) { if (!(value > min)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeGreaterThanOrEqualTo(decimal value, decimal min, string parameterName) { if (!(value >= min)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo(value, min, parameterName); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void MustBeBetweenOrEqualTo(decimal value, decimal min, decimal max, string parameterName) { if (!(value >= min) || !(value <= max)) { ThrowHelper.ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo(value, min, max, parameterName); } } } internal static class ThrowHelper { [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentNullExceptionForNotNull(string name) { ThrowArgumentNullException(name, "Parameter \"" + name + "\" must be not null."); } [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentExceptionForNotNullOrWhitespace(string value, string name) { if (value == null) { ThrowArgumentNullException(name, "Parameter \"" + name + "\" must be not null."); } else { ThrowArgumentException(name, "Parameter \"" + name + "\" must not be empty or whitespace."); } } [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentOutOfRangeExceptionForMustBeLessThan<T>(T value, T max, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter \"{name}\" ({typeof(T)}) must be less than {max}, was {value}"); } [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentOutOfRangeExceptionForMustBeLessThanOrEqualTo<T>(T value, T maximum, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter \"{name}\" ({typeof(T)}) must be less than or equal to {maximum}, was {value}"); } [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentOutOfRangeExceptionForMustBeGreaterThan<T>(T value, T minimum, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter \"{name}\" ({typeof(T)}) must be greater than {minimum}, was {value}"); } [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentOutOfRangeExceptionForMustBeGreaterThanOrEqualTo<T>(T value, T minimum, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter \"{name}\" ({typeof(T)}) must be greater than or equal to {minimum}, was {value}"); } [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentOutOfRangeExceptionForMustBeBetweenOrEqualTo<T>(T value, T minimum, T maximum, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter \"{name}\" ({typeof(T)}) must be between or equal to {minimum} and {maximum}, was {value}"); } [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentOutOfRangeExceptionForMustBeSizedAtLeast(int minLength, string parameterName) { ThrowArgumentException($"Spans must be at least of length {minLength}!", parameterName); } [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentException(string message, string name) { throw new ArgumentException(message, name); } [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentNullException(string name, string message) { throw new ArgumentNullException(name, message); } [MethodImpl(MethodImplOptions.NoInlining)] public static void ThrowArgumentOutOfRangeException(string name, string message) { throw new ArgumentOutOfRangeException(name, message); } } } namespace SixLabors.ImageSharp { public readonly struct Color : IEquatable<Color> { private readonly Rgba64 data; private readonly IPixel boxedHighPrecisionPixel; private static readonly Lazy<Dictionary<string, Color>> NamedColorsLookupLazy = new Lazy<Dictionary<string, Color>>(CreateNamedColorsLookup, isThreadSafe: true); public static readonly Color AliceBlue = FromRgba(240, 248, byte.MaxValue, byte.MaxValue); public static readonly Color AntiqueWhite = FromRgba(250, 235, 215, byte.MaxValue); public static readonly Color Aqua = FromRgba(0, byte.MaxValue, byte.MaxValue, byte.MaxValue); public static readonly Color Aquamarine = FromRgba(127, byte.MaxValue, 212, byte.MaxValue); public static readonly Color Azure = FromRgba(240, byte.MaxValue, byte.MaxValue, byte.MaxValue); public static readonly Color Beige = FromRgba(245, 245, 220, byte.MaxValue); public static readonly Color Bisque = FromRgba(byte.MaxValue, 228, 196, byte.MaxValue); public static readonly Color Black = FromRgba(0, 0, 0, byte.MaxValue); public static readonly Color BlanchedAlmond = FromRgba(byte.MaxValue, 235, 205, byte.MaxValue); public static readonly Color Blue = FromRgba(0, 0, byte.MaxValue, byte.MaxValue); public static readonly Color BlueViolet = FromRgba(138, 43, 226, byte.MaxValue); public static readonly Color Brown = FromRgba(165, 42, 42, byte.MaxValue); public static readonly Color BurlyWood = FromRgba(222, 184, 135, byte.MaxValue); public static readonly Color CadetBlue = FromRgba(95, 158, 160, byte.MaxValue); public static readonly Color Chartreuse = FromRgba(127, byte.MaxValue, 0, byte.MaxValue); public static readonly Color Chocolate = FromRgba(210, 105, 30, byte.MaxValue); public static readonly Color Coral = FromRgba(byte.MaxValue, 127, 80, byte.MaxValue); public static readonly Color CornflowerBlue = FromRgba(100, 149, 237, byte.MaxValue); public static readonly Color Cornsilk = FromRgba(byte.MaxValue, 248, 220, byte.MaxValue); public static readonly Color Crimson = FromRgba(220, 20, 60, byte.MaxValue); public static readonly Color Cyan = Aqua; public static readonly Color DarkBlue = FromRgba(0, 0, 139, byte.MaxValue); public static readonly Color DarkCyan = FromRgba(0, 139, 139, byte.MaxValue); public static readonly Color DarkGoldenrod = FromRgba(184, 134, 11, byte.MaxValue); public static readonly Color DarkGray = FromRgba(169, 169, 169, byte.MaxValue); public static readonly Color DarkGreen = FromRgba(0, 100, 0, byte.MaxValue); public static readonly Color DarkGrey = DarkGray; public static readonly Color DarkKhaki = FromRgba(189, 183, 107, byte.MaxValue); public static readonly Color DarkMagenta = FromRgba(139, 0, 139, byte.MaxValue); public static readonly Color DarkOliveGreen = FromRgba(85, 107, 47, byte.MaxValue); public static readonly Color DarkOrange = FromRgba(byte.MaxValue, 140, 0, byte.MaxValue); public static readonly Color DarkOrchid = FromRgba(153, 50, 204, byte.MaxValue); public static readonly Color DarkRed = FromRgba(139, 0, 0, byte.MaxValue); public static readonly Color DarkSalmon = FromRgba(233, 150, 122, byte.MaxValue); public static readonly Color DarkSeaGreen = FromRgba(143, 188, 143, byte.MaxValue); public static readonly Color DarkSlateBlue = FromRgba(72, 61, 139, byte.MaxValue); public static readonly Color DarkSlateGray = FromRgba(47, 79, 79, byte.MaxValue); public static readonly Color DarkSlateGrey = DarkSlateGray; public static readonly Color DarkTurquoise = FromRgba(0, 206, 209, byte.MaxValue); public static readonly Color DarkViolet = FromRgba(148, 0, 211, byte.MaxValue); public static readonly Color DeepPink = FromRgba(byte.MaxValue, 20, 147, byte.MaxValue); public static readonly Color DeepSkyBlue = FromRgba(0, 191, byte.MaxValue, byte.MaxValue); public static readonly Color DimGray = FromRgba(105, 105, 105, byte.MaxValue); public static readonly Color DimGrey = DimGray; public static readonly Color DodgerBlue = FromRgba(30, 144, byte.MaxValue, byte.MaxValue); public static readonly Color Firebrick = FromRgba(178, 34, 34, byte.MaxValue); public static readonly Color FloralWhite = FromRgba(byte.MaxValue, 250, 240, byte.MaxValue); public static readonly Color ForestGreen = FromRgba(34, 139, 34, byte.MaxValue); public static readonly Color Fuchsia = FromRgba(byte.MaxValue, 0, byte.MaxValue, byte.MaxValue); public static readonly Color Gainsboro = FromRgba(220, 220, 220, byte.MaxValue); public static readonly Color GhostWhite = FromRgba(248, 248, byte.MaxValue, byte.MaxValue); public static readonly Color Gold = FromRgba(byte.MaxValue, 215, 0, byte.MaxValue); public static readonly Color Goldenrod = FromRgba(218, 165, 32, byte.MaxValue); public static readonly Color Gray = FromRgba(128, 128, 128, byte.MaxValue); public static readonly Color Green = FromRgba(0, 128, 0, byte.MaxValue); public static readonly Color GreenYellow = FromRgba(173, byte.MaxValue, 47, byte.MaxValue); public static readonly Color Grey = Gray; public static readonly Color Honeydew = FromRgba(240, byte.MaxValue, 240, byte.MaxValue); public static readonly Color HotPink = FromRgba(byte.MaxValue, 105, 180, byte.MaxValue); public static readonly Color IndianRed = FromRgba(205, 92, 92, byte.MaxValue); public static readonly Color Indigo = FromRgba(75, 0, 130, byte.MaxValue); public static readonly Color Ivory = FromRgba(byte.MaxValue, byte.MaxValue, 240, byte.MaxValue); public static readonly Color Khaki = FromRgba(240, 230, 140, byte.MaxValue); public static readonly Color Lavender = FromRgba(230, 230, 250, byte.MaxValue); public static readonly Color LavenderBlush = FromRgba(byte.MaxValue, 240, 245, byte.MaxValue); public static readonly Color LawnGreen = FromRgba(124, 252, 0, byte.MaxValue); public static readonly Color LemonChiffon = FromRgba(byte.MaxValue, 250, 205, byte.MaxValue); public static readonly Color LightBlue = FromRgba(173, 216, 230, byte.MaxValue); public static readonly Color LightCoral = FromRgba(240, 128, 128, byte.MaxValue); public static readonly Color LightCyan = FromRgba(224, byte.MaxValue, byte.MaxValue, byte.MaxValue); public static readonly Color LightGoldenrodYellow = FromRgba(250, 250, 210, byte.MaxValue); public static readonly Color LightGray = FromRgba(211, 211, 211, byte.MaxValue); public static readonly Color LightGreen = FromRgba(144, 238, 144, byte.MaxValue); public static readonly Color LightGrey = LightGray; public static readonly Color LightPink = FromRgba(byte.MaxValue, 182, 193, byte.MaxValue); public static readonly Color LightSalmon = FromRgba(byte.MaxValue, 160, 122, byte.MaxValue); public static readonly Color LightSeaGreen = FromRgba(32, 178, 170, byte.MaxValue); public static readonly Color LightSkyBlue = FromRgba(135, 206, 250, byte.MaxValue); public static readonly Color LightSlateGray = FromRgba(119, 136, 153, byte.MaxValue); public static readonly Color LightSlateGrey = LightSlateGray; public static readonly Color LightSteelBlue = FromRgba(176, 196, 222, byte.MaxValue); public static readonly Color LightYellow = FromRgba(byte.MaxValue, byte.MaxValue, 224, byte.MaxValue); public static readonly Color Lime = FromRgba(0, byte.MaxValue, 0, byte.MaxValue); public static readonly Color LimeGreen = FromRgba(50, 205, 50, byte.MaxValue); public static readonly Color Linen = FromRgba(250, 240, 230, byte.MaxValue); public static readonly Color Magenta = Fuchsia; public static readonly Color Maroon = FromRgba(128, 0, 0, byte.MaxValue); public static readonly Color MediumAquamarine = FromRgba(102, 205, 170, byte.MaxValue); public static readonly Color MediumBlue = FromRgba(0, 0, 205, byte.MaxValue); public static readonly Color MediumOrchid = FromRgba(186, 85, 211, byte.MaxValue); public static readonly Color MediumPurple = FromRgba(147, 112, 219, byte.MaxValue); public static readonly Color MediumSeaGreen = FromRgba(60, 179, 113, byte.MaxValue); public static readonly Color MediumSlateBlue = FromRgba(123, 104, 238, byte.MaxValue); public static readonly Color MediumSpringGreen = FromRgba(0, 250, 154, byte.MaxValue); public static readonly Color MediumTurquoise = FromRgba(72, 209, 204, byte.MaxValue); public static readonly Color MediumVioletRed = FromRgba(199, 21, 133, byte.MaxValue); public static readonly Color MidnightBlue = FromRgba(25, 25, 112, byte.MaxValue); public static readonly Color MintCream = FromRgba(245, byte.MaxValue, 250, byte.MaxValue); public static readonly Color MistyRose = FromRgba(byte.MaxValue, 228, 225, byte.MaxValue); public static readonly Color Moccasin = FromRgba(byte.MaxValue, 228, 181, byte.MaxValue); public static readonly Color NavajoWhite = FromRgba(byte.MaxValue, 222, 173, byte.MaxValue); public static readonly Color Navy = FromRgba(0, 0, 128, byte.MaxValue); public static readonly Color OldLace = FromRgba(253, 245, 230, byte.MaxValue); public static readonly Color Olive = FromRgba(128, 128, 0, byte.MaxValue); public static readonly Color OliveDrab = FromRgba(107, 142, 35, byte.MaxValue); public static readonly Color Orange = FromRgba(byte.MaxValue, 165, 0, byte.MaxValue); public static readonly Color OrangeRed = FromRgba(byte.MaxValue, 69, 0, byte.MaxValue); public static readonly Color Orchid = FromRgba(218, 112, 214, byte.MaxValue); public static readonly Color PaleGoldenrod = FromRgba(238, 232, 170, byte.MaxValue); public static readonly Color PaleGreen = FromRgba(152, 251, 152, byte.MaxValue); public static readonly Color PaleTurquoise = FromRgba(175, 238, 238, byte.MaxValue); public static readonly Color PaleVioletRed = FromRgba(219, 112, 147, byte.MaxValue); public static readonly Color PapayaWhip = FromRgba(byte.MaxValue, 239, 213, byte.MaxValue); public static readonly Color PeachPuff = FromRgba(byte.MaxValue, 218, 185, byte.MaxValue); public static readonly Color Peru = FromRgba(205, 133, 63, byte.MaxValue); public static readonly Color Pink = FromRgba(byte.MaxValue, 192, 203, byte.MaxValue); public static readonly Color Plum = FromRgba(221, 160, 221, byte.MaxValue); public static readonly Color PowderBlue = FromRgba(176, 224, 230, byte.MaxValue); public static readonly Color Purple = FromRgba(128, 0, 128, byte.MaxValue); public static readonly Color RebeccaPurple = FromRgba(102, 51, 153, byte.MaxValue); public static readonly Color Red = FromRgba(byte.MaxValue, 0, 0, byte.MaxValue); public static readonly Color RosyBrown = FromRgba(188, 143, 143, byte.MaxValue); public static readonly Color RoyalBlue = FromRgba(65, 105, 225, byte.MaxValue); public static readonly Color SaddleBrown = FromRgba(139, 69, 19, byte.MaxValue); public static readonly Color Salmon = FromRgba(250, 128, 114, byte.MaxValue); public static readonly Color SandyBrown = FromRgba(244, 164, 96, byte.MaxValue); public static readonly Color SeaGreen = FromRgba(46, 139, 87, byte.MaxValue); public static readonly Color SeaShell = FromRgba(byte.MaxValue, 245, 238, byte.MaxValue); public static readonly Color Sienna = FromRgba(160, 82, 45, byte.MaxValue); public static readonly Color Silver = FromRgba(192, 192, 192, byte.MaxValue); public static readonly Color SkyBlue = FromRgba(135, 206, 235, byte.MaxValue); public static readonly Color SlateBlue = FromRgba(106, 90, 205, byte.MaxValue); public static readonly Color SlateGray = FromRgba(112, 128, 144, byte.MaxValue); public static readonly Color SlateGrey = SlateGray; public static readonly Color Snow = FromRgba(byte.MaxValue, 250, 250, byte.MaxValue); public static readonly Color SpringGreen = FromRgba(0, byte.MaxValue, 127, byte.MaxValue); public static readonly Color SteelBlue = FromRgba(70, 130, 180, byte.MaxValue); public static readonly Color Tan = FromRgba(210, 180, 140, byte.MaxValue); public static readonly Color Teal = FromRgba(0, 128, 128, byte.MaxValue); public static readonly Color Thistle = FromRgba(216, 191, 216, byte.MaxValue); public static readonly Color Tomato = FromRgba(byte.MaxValue, 99, 71, byte.MaxValue); public static readonly Color Transparent = FromRgba(0, 0, 0, 0); public static readonly Color Turquoise = FromRgba(64, 224, 208, byte.MaxValue); public static readonly Color Violet = FromRgba(238, 130, 238, byte.MaxValue); public static readonly Color Wheat = FromRgba(245, 222, 179, byte.MaxValue); public static readonly Color White = FromRgba(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue); public static readonly Color WhiteSmoke = FromRgba(245, 245, 245, byte.MaxValue); public static readonly Color Yellow = FromRgba(byte.MaxValue, byte.MaxValue, 0, byte.MaxValue); public static readonly Color YellowGreen = FromRgba(154, 205, 50, byte.MaxValue); private static readonly Lazy<Color[]> WebSafePaletteLazy = new Lazy<Color[]>(CreateWebSafePalette, isThreadSafe: true); private static readonly Lazy<Color[]> WernerPaletteLazy = new Lazy<Color[]>(CreateWernerPalette, isThreadSafe: true); public static ReadOnlyMemory<Color> WebSafePalette => WebSafePaletteLazy.Value; public static ReadOnlyMemory<Color> WernerPalette => WernerPaletteLazy.Value; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(Rgba64 pixel) { data = pixel; boxedHighPrecisionPixel = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(Rgb48 pixel) { data = new Rgba64(pixel.R, pixel.G, pixel.B, ushort.MaxValue); boxedHighPrecisionPixel = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(La32 pixel) { data = new Rgba64(pixel.L, pixel.L, pixel.L, pixel.A); boxedHighPrecisionPixel = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(L16 pixel) { data = new Rgba64(pixel.PackedValue, pixel.PackedValue, pixel.PackedValue, ushort.MaxValue); boxedHighPrecisionPixel = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(Rgba32 pixel) { data = new Rgba64(pixel); boxedHighPrecisionPixel = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(Argb32 pixel) { data = new Rgba64(pixel); boxedHighPrecisionPixel = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(Bgra32 pixel) { data = new Rgba64(pixel); boxedHighPrecisionPixel = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(Abgr32 pixel) { data = new Rgba64(pixel); boxedHighPrecisionPixel = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(Rgb24 pixel) { data = new Rgba64(pixel); boxedHighPrecisionPixel = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(Bgr24 pixel) { data = new Rgba64(pixel); boxedHighPrecisionPixel = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color(Vector4 vector) { vector = Numerics.Clamp(vector, Vector4.Zero, Vector4.One); boxedHighPrecisionPixel = new RgbaVector(vector.X, vector.Y, vector.Z, vector.W); data = default(Rgba64); } public static explicit operator Vector4(Color color) { return color.ToVector4(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static explicit operator Color(Vector4 source) { return new Color(source); } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Rgba32 ToRgba32() { if (boxedHighPrecisionPixel == null) { return data.ToRgba32(); } Rgba32 dest = default(Rgba32); boxedHighPrecisionPixel.ToRgba32(ref dest); return dest; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Bgra32 ToBgra32() { if (boxedHighPrecisionPixel == null) { return data.ToBgra32(); } Bgra32 result = default(Bgra32); result.FromScaledVector4(boxedHighPrecisionPixel.ToScaledVector4()); return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Argb32 ToArgb32() { if (boxedHighPrecisionPixel == null) { return data.ToArgb32(); } Argb32 result = default(Argb32); result.FromScaledVector4(boxedHighPrecisionPixel.ToScaledVector4()); return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Abgr32 ToAbgr32() { if (boxedHighPrecisionPixel == null) { return data.ToAbgr32(); } Abgr32 result = default(Abgr32); result.FromScaledVector4(boxedHighPrecisionPixel.ToScaledVector4()); return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Rgb24 ToRgb24() { if (boxedHighPrecisionPixel == null) { return data.ToRgb24(); } Rgb24 result = default(Rgb24); result.FromScaledVector4(boxedHighPrecisionPixel.ToScaledVector4()); return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Bgr24 ToBgr24() { if (boxedHighPrecisionPixel == null) { return data.ToBgr24(); } Bgr24 result = default(Bgr24); result.FromScaledVector4(boxedHighPrecisionPixel.ToScaledVector4()); return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Vector4 ToVector4() { if (boxedHighPrecisionPixel == null) { return data.ToScaledVector4(); } return boxedHighPrecisionPixel.ToScaledVector4(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private Color(byte r, byte g, byte b, byte a) { data = new Rgba64(ColorNumerics.UpscaleFrom8BitTo16Bit(r), ColorNumerics.UpscaleFrom8BitTo16Bit(g), ColorNumerics.UpscaleFrom8BitTo16Bit(b), ColorNumerics.UpscaleFrom8BitTo16Bit(a)); boxedHighPrecisionPixel = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private Color(byte r, byte g, byte b) { data = new Rgba64(ColorNumerics.UpscaleFrom8BitTo16Bit(r), ColorNumerics.UpscaleFrom8BitTo16Bit(g), ColorNumerics.UpscaleFrom8BitTo16Bit(b), ushort.MaxValue); boxedHighPrecisionPixel = null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private Color(IPixel pixel) { boxedHighPrecisionPixel = pixel; data = default(Rgba64); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Color left, Color right) { return left.Equals(right); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Color left, Color right) { return !left.Equals(right); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Color FromRgba(byte r, byte g, byte b, byte a) { return new Color(r, g, b, a); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Color FromRgb(byte r, byte g, byte b) { return new Color(r, g, b); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Color FromPixel<TPixel>(TPixel pixel) where TPixel : unmanaged, IPixel<TPixel> { if (typeof(TPixel) == typeof(Rgba64)) { return new Color((Rgba64)(object)pixel); } if (typeof(TPixel) == typeof(Rgb48)) { return new Color((Rgb48)(object)pixel); } if (typeof(TPixel) == typeof(La32)) { return new Color((La32)(object)pixel); } if (typeof(TPixel) == typeof(L16)) { return new Color((L16)(object)pixel); } if (Unsafe.SizeOf<TPixel>() <= Unsafe.SizeOf<Rgba32>()) { Rgba32 dest = default(Rgba32); pixel.ToRgba32(ref dest); return new Color(dest); } return new Color(pixel); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Color ParseHex(string hex) { return new Color(Rgba32.ParseHex(hex)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseHex(string hex, out Color result) { result = default(Color); if (Rgba32.TryParseHex(hex, out var result2)) { result = new Color(result2); return true; } return false; } public static Color Parse(string input) { Guard.NotNull(input, "input"); if (!TryParse(input, out var result)) { throw new ArgumentException("Input string is not in the correct format.", "input"); } return result; } public static bool TryParse(string input, out Color result) { result = default(Color); if (string.IsNullOrWhiteSpace(input)) { return false; } if (NamedColorsLookupLazy.Value.TryGetValue(input, out result)) { return true; } return TryParseHex(input, out result); } public Color WithAlpha(float alpha) { Vector4 vector = (Vector4)this; vector.W = alpha; return new Color(vector); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public string ToHex() { return data.ToRgba32().ToHex(); } public override string ToString() { return ToHex(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public TPixel ToPixel<TPixel>() where TPixel : unmanaged, IPixel<TPixel> { IPixel pixel = boxedHighPrecisionPixel; if (pixel is TPixel) { return (TPixel)pixel; } TPixel result; if (boxedHighPrecisionPixel == null) { result = default(TPixel); result.FromRgba64(data); return result; } result = default(TPixel); result.FromScaledVector4(boxedHighPrecisionPixel.ToScaledVector4()); return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void ToPixel<TPixel>(Configuration configuration, ReadOnlySpan<Color> source, Span<TPixel> destination) where TPixel : unmanaged, IPixel<TPixel> { Guard.DestinationShouldNotBeTooShort(source, destination, "destination"); for (int i = 0; i < source.Length; i++) { destination[i] = source[i].ToPixel<TPixel>(); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Color other) { if (boxedHighPrecisionPixel == null && other.boxedHighPrecisionPixel == null) { return data.PackedValue == other.data.PackedValue; } return boxedHighPrecisionPixel?.Equals(other.boxedHighPrecisionPixel) ?? false; } public override bool Equals(object obj) { if (obj is Color other) { return Equals(other); } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { if (boxedHighPrecisionPixel == null) { return data.PackedValue.GetHashCode(); } return boxedHighPrecisionPixel.GetHashCode(); } private static Dictionary<string, Color> CreateNamedColorsLookup() { return new Dictionary<string, Color>(StringComparer.OrdinalIgnoreCase) { { "AliceBlue", AliceBlue }, { "AntiqueWhite", AntiqueWhite }, { "Aqua", Aqua }, { "Aquamarine", Aquamarine }, { "Azure", Azure }, { "Beige", Beige }, { "Bisque", Bisque }, { "Black", Black }, { "BlanchedAlmond", BlanchedAlmond }, { "Blue", Blue }, { "BlueViolet", BlueViolet }, { "Brown", Brown }, { "BurlyWood", BurlyWood }, { "CadetBlue", CadetBlue }, { "Chartreuse", Chartreuse }, { "Chocolate", Chocolate }, { "Coral", Coral }, { "CornflowerBlue", CornflowerBlue }, { "Cornsilk", Cornsilk }, { "Crimson", Crimson }, { "Cyan", Cyan }, { "DarkBlue", DarkBlue }, { "DarkCyan", DarkCyan }, { "DarkGoldenrod", DarkGoldenrod }, { "DarkGray", DarkGray }, { "DarkGreen", DarkGreen }, { "DarkGrey", DarkGrey }, { "DarkKhaki", DarkKhaki }, { "DarkMagenta", DarkMagenta }, { "DarkOliveGreen", DarkOliveGreen }, { "DarkOrange", DarkOrange }, { "DarkOrchid", DarkOrchid }, { "DarkRed", DarkRed }, { "DarkSalmon", DarkSalmon }, { "DarkSeaGreen", DarkSeaGreen }, { "DarkSlateBlue", DarkSlateBlue }, { "DarkSlateGray", DarkSlateGray }, { "DarkSlateGrey", DarkSlateGrey }, { "DarkTurquoise", DarkTurquoise }, { "DarkViolet", DarkViolet }, { "DeepPink", DeepPink }, { "DeepSkyBlue", DeepSkyBlue }, { "DimGray", DimGray }, { "DimGrey", DimGrey }, { "DodgerBlue", DodgerBlue }, { "Firebrick", Firebrick }, { "FloralWhite", FloralWhite }, { "ForestGreen", ForestGreen }, { "Fuchsia", Fuchsia }, { "Gainsboro", Gainsboro }, { "GhostWhite", GhostWhite }, { "Gold", Gold }, { "Goldenrod", Goldenrod }, { "Gray", Gray }, { "Green", Green }, { "GreenYellow", GreenYellow }, { "Grey", Grey }, { "Honeydew", Honeydew }, { "HotPink", HotPink }, { "IndianRed", IndianRed }, { "Indigo", Indigo }, { "Ivory", Ivory }, { "Khaki", Khaki }, { "Lavender", Lavender }, { "LavenderBlush", LavenderBlush }, { "LawnGreen", LawnGreen }, { "LemonChiffon", LemonChiffon }, { "LightBlue", LightBlue }, { "LightCoral", LightCoral }, { "LightCyan", LightCyan }, { "LightGoldenrodYellow", LightGoldenrodYellow }, { "LightGray", LightGray }, { "LightGreen", LightGreen }, { "LightGrey", LightGrey }, { "LightPink", LightPink }, { "LightSalmon", LightSalmon }, { "LightSeaGreen", LightSeaGreen }, { "LightSkyBlue", LightSkyBlue }, { "LightSlateGray", LightSlateGray }, { "LightSlateGrey", LightSlateGrey }, { "LightSteelBlue", LightSteelBlue }, { "LightYellow", LightYellow }, { "Lime", Lime }, { "LimeGreen", LimeGreen }, { "Linen", Linen }, { "Magenta", Magenta }, { "Maroon", Maroon }, { "MediumAquamarine", MediumAquamarine }, { "MediumBlue", MediumBlue }, { "MediumOrchid", MediumOrchid }, { "MediumPurple", MediumPurple }, { "MediumSeaGreen", MediumSeaGreen }, { "MediumSlateBlue", MediumSlateBlue }, { "MediumSpringGreen", MediumSpringGreen }, { "MediumTurquoise", MediumTurquoise }, { "MediumVioletRed", MediumVioletRed }, { "MidnightBlue", MidnightBlue }, { "MintCream", MintCream }, { "MistyRose", MistyRose }, { "Moccasin", Moccasin }, { "NavajoWhite", NavajoWhite }, { "Navy", Navy }, { "OldLace", OldLace }, { "Olive", Olive }, { "OliveDrab", OliveDrab }, { "Orange", Orange }, { "OrangeRed", OrangeRed }, { "Orchid", Orchid }, { "PaleGoldenrod", PaleGoldenrod }, { "PaleGreen", PaleGreen }, { "PaleTurquoise", PaleTurquoise }, { "PaleVioletRed", PaleVioletRed }, { "PapayaWhip", PapayaWhip }, { "PeachPuff", PeachPuff }, { "Peru", Peru }, { "Pink", Pink }, { "Plum", Plum }, { "PowderBlue", PowderBlue }, { "Purple", Purple }, { "RebeccaPurple", RebeccaPurple }, { "Red", Red }, { "RosyBrown", RosyBrown }, { "RoyalBlue", RoyalBlue }, { "SaddleBrown", SaddleBrown }, { "Salmon", Salmon }, { "SandyBrown", SandyBrown }, { "SeaGreen", SeaGreen }, { "SeaShell", SeaShell }, { "Sienna", Sienna }, { "Silver", Silver }, { "SkyBlue", SkyBlue }, { "SlateBlue", SlateBlue }, { "SlateGray", SlateGray }, { "SlateGrey", SlateGrey }, { "Snow", Snow }, { "SpringGreen", SpringGreen }, { "SteelBlue", SteelBlue }, { "Tan", Tan }, { "Teal", Teal }, { "Thistle", Thistle }, { "Tomato", Tomato }, { "Transparent", Transparent }, { "Turquoise", Turquoise }, { "Violet", Violet }, { "Wheat", Wheat }, { "White", White }, { "WhiteSmoke", WhiteSmoke }, { "Yellow", Yellow }, { "YellowGreen", YellowGreen } }; } private static Color[] CreateWebSafePalette() { return new Color[142] { AliceBlue, AntiqueWhite, Aqua, Aquamarine, Azure, Beige, Bisque, Black, BlanchedAlmond, Blue, BlueViolet, Brown, BurlyWood, CadetBlue, Chartreuse, Chocolate, Coral, CornflowerBlue, Cornsilk, Crimson, Cyan, DarkBlue, DarkCyan, DarkGoldenrod, DarkGray, DarkGreen, DarkKhaki, DarkMagenta, DarkOliveGreen, DarkOrange, DarkOrchid, DarkRed, DarkSalmon, DarkSeaGreen, DarkSlateBlue, DarkSlateGray, DarkTurquoise, DarkViolet, DeepPink, DeepSkyBlue, DimGray, DodgerBlue, Firebrick, FloralWhite, ForestGreen, Fuchsia, Gainsboro, GhostWhite, Gold, Goldenrod, Gray, Green, GreenYellow, Honeydew, HotPink, IndianRed, Indigo, Ivory, Khaki, Lavender, LavenderBlush, LawnGreen, LemonChiffon, LightBlue, LightCoral, LightCyan, LightGoldenrodYellow, LightGray, LightGreen, LightPink, LightSalmon, LightSeaGreen, LightSkyBlue, LightSlateGray, LightSteelBlue, LightYellow, Lime, LimeGreen, Linen, Magenta, Maroon, MediumAquamarine, MediumBlue, MediumOrchid, MediumPurple, MediumSeaGreen, MediumSlateBlue, MediumSpringGreen, MediumTurquoise, MediumVioletRed, MidnightBlue, MintCream, MistyRose, Moccasin, NavajoWhite, Navy, OldLace, Olive, OliveDrab, Orange, OrangeRed, Orchid, PaleGoldenrod, PaleGreen, PaleTurquoise, PaleVioletRed, PapayaWhip, PeachPuff, Peru, Pink, Plum, PowderBlue, Purple, RebeccaPurple, Red, RosyBrown, RoyalBlue, SaddleBrown, Salmon, SandyBrown, SeaGreen, SeaShell, Sienna, Silver, SkyBlue, SlateBlue, SlateGray, Snow, SpringGreen, SteelBlue, Tan, Teal, Thistle, Tomato, Transparent, Turquoise, Violet, Wheat, White, WhiteSmoke, Yellow, YellowGreen }; } private static Color[] CreateWernerPalette() { return new Color[110] { ParseHex("#f1e9cd"), ParseHex("#f2e7cf"), ParseHex("#ece6d0"), ParseHex("#f2eacc"), ParseHex("#f3e9ca"), ParseHex("#f2ebcd"), ParseHex("#e6e1c9"), ParseHex("#e2ddc6"), ParseHex("#cbc8b7"), ParseHex("#bfbbb0"), ParseHex("#bebeb3"), ParseHex("#b7b5ac"), ParseHex("#bab191"), ParseHex("#9c9d9a"), ParseHex("#8a8d84"), ParseHex("#5b5c61"), ParseHex("#555152"), ParseHex("#413f44"), ParseHex("#454445"), ParseHex("#423937"), ParseHex("#433635"), ParseHex("#252024"), ParseHex("#241f20"), ParseHex("#281f3f"), ParseHex("#1c1949"), ParseHex("#4f638d"), ParseHex("#383867"), ParseHex("#5c6b8f"), ParseHex("#657abb"), ParseHex("#6f88af"), ParseHex("#7994b5"), ParseHex("#6fb5a8"), ParseHex("#719ba2"), ParseHex("#8aa1a6"), ParseHex("#d0d5d3"), ParseHex("#8590ae"), ParseHex("#3a2f52"), ParseHex("#39334a"), ParseHex("#6c6d94"), ParseHex("#584c77"), ParseHex("#533552"), ParseHex("#463759"), ParseHex("#bfbac0"), ParseHex("#77747f"), ParseHex("#4a475c"), ParseHex("#b8bfaf"), ParseHex("#b2b599"), ParseHex("#979c84"), ParseHex("#5d6161"), ParseHex("#61ac86"), ParseHex("#a4b6a7"), ParseHex("#adba98"), ParseHex("#93b778"), ParseHex("#7d8c55"), ParseHex("#33431e"), ParseHex("#7c8635"), ParseHex("#8e9849"), ParseHex("#c2c190"), ParseHex("#67765b"), ParseHex("#ab924b"), ParseHex("#c8c76f"), ParseHex("#ccc050"), ParseHex("#ebdd99"), ParseHex("#ab9649"), ParseHex("#dbc364"), ParseHex("#e6d058"), ParseHex("#ead665"), ParseHex("#d09b2c"), ParseHex("#a36629"), ParseHex("#a77d35"), ParseHex("#f0d696"), ParseHex("#d7c485"), ParseHex("#f1d28c"), ParseHex("#efcc83"), ParseHex("#f3daa7"), ParseHex("#dfa837"), ParseHex("#ebbc71"), ParseHex("#d17c3f"), ParseHex("#92462f"), ParseHex("#be7249"), ParseHex("#bb603c"), ParseHex("#c76b4a"), ParseHex("#a75536"), ParseHex("#b63e36"), ParseHex("#b5493a"), ParseHex("#cd6d57"), ParseHex("#711518"), ParseHex("#e9c49d"), ParseHex("#eedac3"), ParseHex("#eecfbf"), ParseHex("#ce536b"), ParseHex("#b74a70"), ParseHex("#b7757c"), ParseHex("#612741"), ParseHex("#7a4848"), ParseHex("#3f3033"), ParseHex("#8d746f"), ParseHex("#4d3635"), ParseHex("#6e3b31"), ParseHex("#864735"), ParseHex("#553d3a"), ParseHex("#613936"), ParseHex("#7a4b3a"), ParseHex("#946943"), ParseHex("#c39e6d"), ParseHex("#513e32"), ParseHex("#8b7859"), ParseHex("#9b856b"), ParseHex("#766051"), ParseHex("#453b32") }; } } public enum ByteOrder { BigEndian, LittleEndian } internal static class Constants { public static readonly float Epsilon = 0.001f; public static readonly float EpsilonSquared = Epsilon * Epsilon; } public class ImageFormatException : Exception { internal ImageFormatException(string errorMessage) : base(errorMessage) { } internal ImageFormatException(string errorMessage, Exception innerException) : base(errorMessage, innerException) { } } public sealed class ImageProcessingException : Exception { public ImageProcessingException() { } public ImageProcessingException(string errorMessage) : base(errorMessage) { } public ImageProcessingException(string errorMessage, Exception innerException) : base(errorMessage, innerException) { } } public sealed class InvalidImageContentException : ImageFormatException { public InvalidImageContentException(string errorMessage) : base(errorMessage) { } public InvalidImageContentException(string errorMessage, Exception innerException) : base(errorMessage, innerException) { } internal InvalidImageContentException(Size size, InvalidMemoryOperationException memoryException) : this($"Cannot decode image. Failed to allocate buffers for possibly degenerate dimensions: {size.Width}x{size.Height}.", memoryException) { } } public sealed class UnknownImageFormatException : ImageFormatException { public UnknownImageFormatException(string errorMessage) : base(errorMessage) { } } internal static class ConfigurationExtensions { public static ParallelOptions GetParallelOptions(this Configuration configuration) { return new ParallelOptions { MaxDegreeOfParallelism = configuration.MaxDegreeOfParallelism }; } } internal static class EnumerableExtensions { public static IEnumerable<int> SteppedRange(int fromInclusive, Func<int, bool> toDelegate, int step) { return RangeIterator(fromInclusive, toDelegate, step); } private static IEnumerable<int> RangeIterator(int fromInclusive, Func<int, bool> toDelegate, int step) { for (int i = fromInclusive; toDelegate(i); i += step) { yield return i; } } } internal static class StreamExtensions { public static void Write(this Stream stream, Span<byte> buffer, int offset, int count) { stream.Write(buffer.Slice(offset, count)); } public static int Read(this Stream stream, Span<byte> buffer, int offset, int count) { return stream.Read(buffer.Slice(offset, count)); } public static void Skip(this Stream stream, int count) { if (count < 1) { return; } if (stream.CanSeek) { stream.Seek(count, SeekOrigin.Current); return; } byte[] array = ArrayPool<byte>.Shared.Rent(count); try { while (count > 0) { int num = stream.Read(array, 0, count); if (num == 0) { break; } count -= num; } } finally { ArrayPool<byte>.Shared.Return(array); } } } internal static class ColorNumerics { private static readonly Vector4 Bt709 = new Vector4(0.2126f, 0.7152f, 0.0722f, 0f); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int GetBT709Luminance(ref Vector4 vector, int luminanceLevels) { return (int)MathF.Round(Vector4.Dot(vector, Bt709) * (float)(luminanceLevels - 1)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte Get8BitBT709Luminance(byte r, byte g, byte b) { return (byte)((float)(int)r * 0.2126f + (float)(int)g * 0.7152f + (float)(int)b * 0.0722f + 0.5f); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ushort Get16BitBT709Luminance(ushort r, ushort g, ushort b) { return (ushort)((float)(int)r * 0.2126f + (float)(int)g * 0.7152f + (float)(int)b * 0.0722f + 0.5f); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ushort Get16BitBT709Luminance(float r, float g, float b) { return (ushort)(r * 0.2126f + g * 0.7152f + b * 0.0722f + 0.5f); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte DownScaleFrom16BitTo8Bit(ushort component) { return (byte)(component * 255 + 32895 >> 16); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ushort UpscaleFrom8BitTo16Bit(byte component) { return (ushort)(component * 257); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int GetBitsNeededForColorDepth(int colors) { return Math.Max(1, (int)Math.Ceiling(Math.Log(colors, 2.0))); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int GetColorCountForBitDepth(int bitDepth) { return 1 << bitDepth; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Transform(ref Vector4 vector, ref ColorMatrix matrix) { float x = vector.X; float y = vector.Y; float z = vector.Z; float w = vector.W; vector.X = x * matrix.M11 + y * matrix.M21 + z * matrix.M31 + w * matrix.M41 + matrix.M51; vector.Y = x * matrix.M12 + y * matrix.M22 + z * matrix.M32 + w * matrix.M42 + matrix.M52; vector.Z = x * matrix.M13 + y * matrix.M23 + z * matrix.M33 + w * matrix.M43 + matrix.M53; vector.W = x * matrix.M14 + y * matrix.M24 + z * matrix.M34 + w * matrix.M44 + matrix.M54; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Transform(Span<Vector4> vectors, ref ColorMatrix matrix) { ref Vector4 reference = ref MemoryMarshal.GetReference(vectors); for (int i = 0; i < vectors.Length; i++) { Transform(ref Unsafe.Add(ref reference, i), ref matrix); } } } internal static class EnumUtils { public static TEnum Parse<TEnum>(int value, TEnum defaultValue) where TEnum : Enum { foreach (TEnum value2 in Enum.GetValues(typeof(TEnum))) { TEnum source = value2; if (value == Unsafe.As<TEnum, int>(ref source)) { return value2; } } return defaultValue; } public static bool HasFlag<TEnum>(TEnum value, TEnum flag) where TEnum : Enum { uint num = Unsafe.As<TEnum, uint>(ref flag); return (Unsafe.As<TEnum, uint>(ref value) & num) == num; } } internal static class InliningOptions { public const MethodImplOptions AlwaysInline = MethodImplOptions.AggressiveInlining; public const MethodImplOptions HotPath = MethodImplOptions.AggressiveInlining; public const MethodImplOptions ShortMethod = MethodImplOptions.AggressiveInlining; public const MethodImplOptions ColdPath = MethodImplOptions.NoInlining; } internal static class Numerics { private static ReadOnlySpan<byte> Log2DeBruijn => new byte[32] { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int GreatestCommonDivisor(int a, int b) { while (b != 0) { int num = b; b = a % b; a = num; } return a; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int LeastCommonMultiple(int a, int b) { return a / GreatestCommonDivisor(a, b) * b; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Modulo2(int x) { return x & 1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Modulo4(int x) { return x & 3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Modulo8(int x) { return x & 7; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int ModuloP2(int x, int m) { return x & (m - 1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Abs(int x) { int num = x >> 31; return (x ^ num) - num; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Pow2(float x) { return x * x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Pow3(float x) { return x * x * x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Gaussian(float x, float sigma) { float num = MathF.Sqrt(MathF.PI * 2f) * sigma; float num2 = (0f - x) * x; float num3 = 2f * Pow2(sigma); float num4 = 1f / num; float num5 = MathF.Exp(num2 / num3); return num4 * num5; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float SinC(float f) { if (MathF.Abs(f) > Constants.Epsilon) { f *= MathF.PI; float num = MathF.Sin(f) / f; if (!(MathF.Abs(num) < Constants.Epsilon)) { return num; } return 0f; } return 1f; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte Clamp(byte value, byte min, byte max) { if (value > max) { return max; } if (value < min) { return min; } return value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint Clamp(uint value, uint min, uint max) { if (value > max) { return max; } if (value < min) { return min; } return value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Clamp(int value, int min, int max) { if (value > max) { return max; } if (value < min) { return min; } return value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Clamp(float value, float min, float max) { if (value > max) { return max; } if (value < min) { return min; } return value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Clamp(double value, double min, double max) { if (value > max) { return max; } if (value < min) { return min; } return value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Vector4 Clamp(Vector4 value, Vector4 min, Vector4 max) { return Vector4.Min(Vector4.Max(value, min), max); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Clamp(Span<byte> span, byte min, byte max) { Span<byte> span2 = span.Slice(ClampReduce(span, min, max)); if (span2.Length > 0) { ref byte reference = ref MemoryMarshal.GetReference(span2); ref byte right = ref Unsafe.Add(ref reference, span2.Length); while (Unsafe.IsAddressLessThan(in reference, in right)) { reference = Clamp(reference, min, max); reference = ref Unsafe.Add(ref reference, 1); } } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Clamp(Span<uint> span, uint min, uint max) { Span<uint> span2 = span.Slice(ClampReduce(span, min, max)); if (span2.Length > 0) { ref uint reference = ref MemoryMarshal.GetReference(span2); ref uint right = ref Unsafe.Add(ref reference, span2.Length); while (Unsafe.IsAddressLessThan(in reference, in right)) { reference = Clamp(reference, min, max); reference = ref Unsafe.Add(ref reference, 1); } } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Clamp(Span<int> span, int min, int max) { Span<int> span2 = span.Slice(ClampReduce(span, min, max)); if (span2.Length > 0) { ref int reference = ref MemoryMarshal.GetReference(span2); ref int right = ref Unsafe.Add(ref reference, span2.Length); while (Unsafe.IsAddressLessThan(in reference, in right)) { reference = Clamp(reference, min, max); reference = ref Unsafe.Add(ref reference, 1); } } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Clamp(Span<float> span, float min, float max) { Span<float> span2 = span.Slice(ClampReduce(span, min, max)); if (span2.Length > 0) { ref float reference = ref MemoryMarshal.GetReference(span2); ref float right = ref Unsafe.Add(ref reference, span2.Length); while (Unsafe.IsAddressLessThan(in reference, in right)) { reference = Clamp(reference, min, max); reference = ref Unsafe.Add(ref reference, 1); } } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Clamp(Span<double> span, double min, double max) { Span<double> span2 = span.Slice(ClampReduce(span, min, max)); if (span2.Length > 0) { ref double reference = ref MemoryMarshal.GetReference(span2); ref double right = ref Unsafe.Add(ref reference, span2.Length); while (Unsafe.IsAddressLessThan(in reference, in right)) { reference = Clamp(reference, min, max); reference = ref Unsafe.Add(ref reference, 1); } } } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static int ClampReduce<T>(Span<T> span, T min, T max) where T : unmanaged { if (Vector.IsHardwareAccelerated && span.Length >= Vector<T>.Count) { int num = ModuloP2(span.Length, Vector<T>.Count); int num2 = span.Length - num; if (num2 > 0) { ClampImpl(span.Slice(0, num2), min, max); } return num2; } return 0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void ClampImpl<T>(Span<T> span, T min, T max) where T : unmanaged { MemoryMarshal.GetReference(span); Vector<T> left = new Vector<T>(min); Vector<T> right = new Vector<T>(max); int num = span.Length / Vector<T>.Count; int num2 = Modulo4(num); int elementOffset = num - num2; ref Vector<T> reference = ref Unsafe.As<T, Vector<T>>(ref MemoryMarshal.GetReference(span)); ref Vector<T> reference2 = ref Unsafe.Add(ref reference, 1); ref Vector<T> reference3 = ref Unsafe.Add(ref reference, 2); ref Vector<T> reference4 = ref Unsafe.Add(ref reference, 3); ref Vector<T> reference5 = ref Unsafe.Add(ref reference, elementOffset); while (Unsafe.IsAddressLessThan(in reference, in reference5)) { reference = Vector.Min(Vector.Max(left, reference), right); reference2 = Vector.Min(Vector.Max(left, reference2), right); reference3 = Vector.Min(Vector.Max(left, reference3), right); reference4 = Vector.Min(Vector.Max(left, reference4), right); reference = ref Unsafe.Add(ref reference, 4); reference2 = ref Unsafe.Add(ref reference2, 4); reference3 = ref Unsafe.Add(ref reference3, 4); reference4 = ref Unsafe.Add(ref reference4, 4); } if (num2 > 0) { reference = ref reference5; reference5 = ref Unsafe.Add(ref reference5, num2); while (Unsafe.IsAddressLessThan(in reference, in reference5)) { reference = Vector.Min(Vector.Max(left, reference), right); reference = ref Unsafe.Add(ref reference, 1); } } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Premultiply(ref Vector4 source) { float w = source.W; source *= w; source.W = w; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void UnPremultiply(ref Vector4 source) { float w = source.W; source /= w; source.W = w; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Premultiply(Span<Vector4> vectors) { ref Vector4 reference = ref MemoryMarshal.GetReference(vectors); ref Vector4 right = ref Unsafe.Add(ref reference, vectors.Length); while (Unsafe.IsAddressLessThan(in reference, in right)) { Premultiply(ref reference); reference = ref Unsafe.Add(ref reference, 1); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void UnPremultiply(Span<Vector4> vectors) { ref Vector4 reference = ref MemoryMarshal.GetReference(vectors); ref Vector4 right = ref Unsafe.Add(ref reference, vectors.Length); while (Unsafe.IsAddressLessThan(in reference, in right)) { UnPremultiply(ref reference); reference = ref Unsafe.Add(ref reference, 1); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void CubePowOnXYZ(Span<Vector4> vectors) { ref Vector4 reference = ref MemoryMarshal.GetReference(vectors); ref Vector4 right = ref Unsafe.Add(ref reference, vectors.Length); while (Unsafe.IsAddressLessThan(in reference, in right)) { Vector4 vector = reference; float w = vector.W; vector = vector * vector * vector; vector.W = w; reference = vector; reference = ref Unsafe.Add(ref reference, 1); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe static void CubeRootOnXYZ(Span<Vector4> vectors) { ref Vector4 reference = ref MemoryMarshal.GetReference(vectors); ref Vector4 right = ref Unsafe.Add(ref reference, vectors.Length); Vector4 vector2 = default(Vector4); while (Unsafe.IsAddressLessThan(in reference, in right)) { Vector4 vector = reference; double num = vector.X; double num2 = vector.Y; double num3 = vector.Z; float w = vector.W; ulong num4 = *(ulong*)(&num); ulong num5 = *(ulong*)(&num2); ulong num6 = *(ulong*)(&num3); num4 = 3071325735593686528L + num4 / 3; num5 = 3071325735593686528L + num5 / 3; num6 = 3071325735593686528L + num6 / 3; vector2.X = (float)(*(double*)(&num4)); vector2.Y = (float)(*(double*)(&num5)); vector2.Z = (float)(*(double*)(&num6)); vector2.W = 0f; vector2 = 2f / 3f * vector2 + 1f / 3f * (vector / (vector2 * vector2)); vector2 = 2f / 3f * vector2 + 1f / 3f * (vector / (vector2 * vector2)); vector2.W = w; reference = vector2; reference = ref Unsafe.Add(ref reference, 1); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Lerp(float value1, float value2, float amount) { return (value2 - value1) * amount + value1; } public static int Log2(uint value) { return Log2SoftwareFallback(value); } private static int Log2SoftwareFallback(uint value) { value |= value >> 1; value |= value >> 2; value |= value >> 4; value |= value >> 8; value |= value >> 16; return Unsafe.AddByteOffset(ref MemoryMarshal.GetReference(Log2DeBruijn), (IntPtr)(int)(value * 130329821 >> 27)); } public static uint DivideCeil(uint value, uint divisor) { return (value + divisor - 1) / divisor; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint RotateLeft(uint value, int offset) { return RotateLeftSoftwareFallback(value, offset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint RotateLeftSoftwareFallback(uint value, int offset) { return (value << offset) | (value >> 32 - offset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint RotateRight(uint value, int offset) { return RotateRightSoftwareFallback(value, offset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint RotateRightSoftwareFallback(uint value, int offset) { return (value >> offset) | (value << 32 - offset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOutOfRange(int value, int min, int max) { return (uint)(value - min) > (uint)(max - min); } } internal static class RuntimeEnvironment { private static readonly Lazy<bool> IsNetCoreLazy = new Lazy<bool>(() => FrameworkDescription.StartsWith(".NET Core", StringComparison.OrdinalIgnoreCase)); public static bool IsNetCore => IsNetCoreLazy.Value; public static string FrameworkDescription => RuntimeInformation.FrameworkDescription; public static bool IsOSPlatform(OSPlatform osPlatform) { return RuntimeInformation.IsOSPlatform(osPlatform); } } internal interface IComponentShuffle { byte Control { get; } void RunFallbackShuffle(ReadOnlySpan<byte> source, Span<byte> dest); } internal interface IShuffle4 : IComponentShuffle { } internal readonly struct DefaultShuffle4 : IShuffle4, IComponentShuffle { private readonly byte p3; private readonly byte p2; private readonly byte p1; private readonly byte p0; public byte Control { get; } public DefaultShuffle4(byte p3, byte p2, byte p1, byte p0) { this.p3 = p3; this.p2 = p2; this.p1 = p1; this.p0 = p0; Control = SimdUtils.Shuffle.MmShuffle(p3, p2, p1, p0); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RunFallbackShuffle(ReadOnlySpan<byte> source, Span<byte> dest) { ref byte reference = ref MemoryMarshal.GetReference(source); ref byte reference2 = ref MemoryMarshal.GetReference(dest); int num = p3; int num2 = p2; int num3 = p1; int num4 = p0; for (int i = 0; i < source.Length; i += 4) { Unsafe.Add(ref reference2, i) = Unsafe.Add(ref reference, num4 + i); Unsafe.Add(ref reference2, i + 1) = Unsafe.Add(ref reference, num3 + i); Unsafe.Add(ref reference2, i + 2) = Unsafe.Add(ref reference, num2 + i); Unsafe.Add(ref reference2, i + 3) = Unsafe.Add(ref reference, num + i); } } } [StructLayout(LayoutKind.Sequential, Size = 1)] internal readonly struct WXYZShuffle4 : IShuffle4, IComponentShuffle { public byte Control { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return SimdUtils.Shuffle.MmShuffle(2, 1, 0, 3); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RunFallbackShuffle(ReadOnlySpan<byte> source, Span<byte> dest) { ref uint source2 = ref Unsafe.As<byte, uint>(ref MemoryMarshal.GetReference(source)); ref uint source3 = ref Unsafe.As<byte, uint>(ref MemoryMarshal.GetReference(dest)); int num = source.Length / 4; for (int i = 0; i < num; i++) { uint num2 = Unsafe.Add(ref source2, i); Unsafe.Add(ref source3, i) = (num2 << 8) | (num2 >> 24); } } } [StructLayout(LayoutKind.Sequential, Size = 1)] internal readonly struct WZYXShuffle4 : IShuffle4, IComponentShuffle { public byte Control { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return SimdUtils.Shuffle.MmShuffle(0, 1, 2, 3); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RunFallbackShuffle(ReadOnlySpan<byte> source, Span<byte> dest) { ref uint source2 = ref Unsafe.As<byte, uint>(ref MemoryMarshal.GetReference(source)); ref uint source3 = ref Unsafe.As<byte, uint>(ref MemoryMarshal.GetReference(dest)); int num = source.Length / 4; for (int i = 0; i < num; i++) { uint value = Unsafe.Add(ref source2, i); Unsafe.Add(ref source3, i) = BinaryPrimitives.ReverseEndianness(value); } } } [StructLayout(LayoutKind.Sequential, Size = 1)] internal readonly struct YZWXShuffle4 : IShuffle4, IComponentShuffle { public byte Control { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return SimdUtils.Shuffle.MmShuffle(0, 3, 2, 1); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RunFallbackShuffle(ReadOnlySpan<byte> source, Span<byte> dest) { ref uint source2 = ref Unsafe.As<byte, uint>(ref MemoryMarshal.GetReference(source)); ref uint source3 = ref Unsafe.As<byte, uint>(ref MemoryMarshal.GetReference(dest)); int num = source.Length / 4; for (int i = 0; i < num; i++) { uint value = Unsafe.Add(ref source2, i); Unsafe.Add(ref source3, i) = Numerics.RotateRight(value, 8); } } } [StructLayout(LayoutKind.Sequential, Size = 1)] internal readonly struct ZYXWShuffle4 : IShuffle4, IComponentShuffle { public byte Control { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return SimdUtils.Shuffle.MmShuffle(3, 0, 1, 2); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RunFallbackShuffle(ReadOnlySpan<byte> source, Span<byte> dest) { ref uint source2 = ref Unsafe.As<byte, uint>(ref MemoryMarshal.GetReference(source)); ref uint source3 = ref Unsafe.As<byte, uint>(ref MemoryMarshal.GetReference(dest)); int num = source.Length / 4; for (int i = 0; i < num; i++) { uint num2 = Unsafe.Add(ref source2, i); uint num3 = num2 & 0xFF00FF00u; uint num4 = Numerics.RotateLeft(num2 & 0xFF00FF, 16); Unsafe.Add(ref source3, i) = num3 + num4; } } } [StructLayout(LayoutKind.Sequential, Size = 1)] internal readonly struct XWZYShuffle4 : IShuffle4, IComponentShuffle { public byte Control { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return SimdUtils.Shuffle.MmShuffle(1, 2, 3, 0); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RunFallbackShuffle(ReadOnlySpan<byte> source, Span<byte> dest) { ref uint source2 = ref Unsafe.As<byte, uint>(ref MemoryMarshal.GetReference(source)); ref uint source3 = ref Unsafe.As<byte, uint>(ref MemoryMarshal.GetReference(dest)); int num = source.Length / 4; for (int i = 0; i < num; i++) { uint num2 = Unsafe.Add(ref source2, i); uint num3 = num2 & 0xFF00FF; uint num4 = Numerics.RotateLeft(num2 & 0xFF00FF00u, 16); Unsafe.Add(ref source3, i) = num3 + num4; } } } internal interface IPad3Shuffle4 : IComponentShuffle { } internal readonly struct DefaultPad3Shuffle4 : IPad3Shuffle4, IComponentShuffle { private readonly byte p3; private readonly byte p2; private readonly byte p1; private readonly byte p0; public byte Control { get; } public DefaultPad3Shuffle4(byte p3, byte p2, byte p1, byte p0) { this.p3 = p3; this.p2 = p2; this.p1 = p1; this.p0 = p0; Control = SimdUtils.Shuffle.MmShuffle(p3, p2, p1, p0); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RunFallbackShuffle(ReadOnlySpan<byte> source, Span<byte> dest) { ref byte reference = ref MemoryMarshal.GetReference(source); ref byte reference2 = ref MemoryMarshal.GetReference(dest); int elementOffset = p3; int elementOffset2 = p2; int elementOffset3 = p1; int elementOffset4 = p0; ref byte reference3 = ref MemoryMarshal.GetReference(stackalloc byte[4]); ref uint reference4 = ref Unsafe.As<byte, uint>(ref reference3); int num = 0; int num2 = 0; while (num < source.Length) { reference4 = Unsafe.As<byte, uint>(ref Unsafe.Add(ref reference, num)) | 0xFF000000u; Unsafe.Add(ref reference2, num2) = Unsafe.Add(ref reference3, elementOffset4); Unsafe.Add(ref reference2, num2 + 1) = Unsafe.Add(ref reference3, elementOffset3); Unsafe.Add(ref reference2, num2 + 2) = Unsafe.Add(ref reference3, elementOffset2); Unsafe.Add(ref reference2, num2 + 3) = Unsafe.Add(ref reference3, elementOffset); num += 3; num2 += 4; } } } [StructLayout(LayoutKind.Sequential, Size = 1)] internal readonly struct XYZWPad3Shuffle4 : IPad3Shuffle4, IComponentShuffle { public byte Control { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return SimdUtils.Shuffle.MmShuffle(3, 2, 1, 0); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RunFallbackShuffle(ReadOnlySpan<byte> source, Span<byte> dest) { ref byte reference = ref MemoryMarshal.GetReference(source); ref byte source2 = ref MemoryMarshal.GetReference(dest); ref byte reference2 = ref Unsafe.Add(ref reference, source.Length); ref byte right = ref Unsafe.Subtract(ref reference2, 4); while (Unsafe.IsAddressLessThan(in reference, in right)) { Unsafe.As<byte, uint>(ref source2) = Unsafe.As<byte, uint>(ref reference) | 0xFF000000u; reference = ref Unsafe.Add(ref reference, 3); source2 = ref Unsafe.Add(ref source2, 4); } while (Unsafe.IsAddressLessThan(in reference, in reference2)) { Unsafe.Add(ref source2, 0) = Unsafe.Add(ref reference, 0); Unsafe.Add(ref source2, 1) = Unsafe.Add(ref reference, 1); Unsafe.Add(ref source2, 2) = Unsafe.Add(ref reference, 2); Unsafe.Add(ref source2, 3) = byte.MaxValue; reference = ref Unsafe.Add(ref reference, 3); source2 = ref Unsafe.Add(ref source2, 4); } } } internal interface IShuffle3 : IComponentShuffle { } internal readonly struct DefaultShuffle3 : IShuffle3, IComponentShuffle { private readonly byte p2; private readonly byte p1; private readonly byte p0; public byte Control { get; } public DefaultShuffle3(byte p2, byte p1, byte p0) { this.p2 = p2; this.p1 = p1; this.p0 = p0; Control = SimdUtils.Shuffle.MmShuffle(3, p2, p1, p0); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RunFallbackShuffle(ReadOnlySpan<byte> source, Span<byte> dest) { ref byte reference = ref MemoryMarshal.GetReference(source); ref byte reference2 = ref MemoryMarshal.GetReference(dest); int num = p2; int num2 = p1; int num3 = p0; for (int i = 0; i < source.Length; i += 3) { Unsafe.Add(ref reference2, i) = Unsafe.Add(ref reference, num3 + i); Unsafe.Add(ref reference2, i + 1) = Unsafe.Add(ref reference, num2 + i); Unsafe.Add(ref reference2, i + 2) = Unsafe.Add(ref reference, num + i); } } } internal interface IShuffle4Slice3 : IComponentShuffle { } internal readonly struct DefaultShuffle4Slice3 : IShuffle4Slice3, IComponentShuffle { private readonly byte p2; private readonly byte p1; private readonly byte p0; public byte Control { get; } public DefaultShuffle4Slice3(byte p3, byte p2, byte p1, byte p0) { this.p2 = p2; this.p1 = p1; this.p0 = p0; Control = SimdUtils.Shuffle.MmShuffle(p3, p2, p1, p0); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RunFallbackShuffle(ReadOnlySpan<byte> source, Span<byte> dest) { ref byte reference = ref MemoryMarshal.GetReference(source); ref byte reference2 = ref MemoryMarshal.GetReference(dest); int num = p2; int num2 = p1; int num3 = p0; int num4 = 0; int num5 = 0; while (num4 < dest.Length) { Unsafe.Add(ref reference2, num4) = Unsafe.Add(ref reference, num3 + num5); Unsafe.Add(ref reference2, num4 + 1) = Unsafe.Add(ref reference, num2 + num5); Unsafe.Add(ref reference2, num4 + 2) = Unsafe.Add(ref reference, num + num5); num4 += 3; num5 += 4; } } } [StructLayout(LayoutKind.Sequential, Size = 1)] internal readonly struct XYZWShuffle4Slice3 : IShuffle4Slice3, IComponentShuffle { public byte Control { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return SimdUtils.Shuffle.MmShuffle(3, 2, 1, 0); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RunFallbackShuffle(ReadOnlySpan<byte> source, Span<byte> dest) { ref uint reference = ref Unsafe.As<byte, uint>(ref MemoryMarshal.GetReference(source)); ref Byte3 source2 = ref Unsafe.As<byte, Byte3>(ref MemoryMarshal.GetReference(dest)); int num = source.Length / 4; int num2 = Numerics.Modulo4(num); int elementOffset = num - num2; ref uint right = ref Unsafe.Add(ref reference, elementOffset); ref uint right2 = ref Unsafe.Add(ref reference, num); while (Unsafe.IsAddressLessThan(in reference, in right)) { Unsafe.Add(ref source2, 0) = Unsafe.As<uint, Byte3>(ref Unsafe.Add(ref reference, 0)); Unsafe.Add(ref source2, 1) = Unsafe.As<uint, Byte3>(ref Unsafe.Add(ref reference, 1)); Unsafe.Add(ref source2, 2) = Unsafe.As<uint, Byte3>(ref Unsafe.Add(ref reference, 2)); Unsafe.Add(ref source2, 3) = Unsafe.As<uint, Byte3>(ref Unsafe.Add(ref reference, 3)); reference = ref Unsafe.Add(ref reference, 4); source2 = ref Unsafe.Add(ref source2, 4); } while (Unsafe.IsAddressLessThan(in reference, in right2)) { Unsafe.Add(ref source2, 0) = Unsafe.As<uint, Byte3>(ref Unsafe.Add(ref reference, 0)); reference = ref Unsafe.Add(ref reference, 1); source2 = ref Unsafe.Add(ref source2, 1); } } } [StructLayout(LayoutKind.Explicit, Size = 3)] internal readonly struct Byte3 { } internal static class SimdUtils { public static class BasicIntrinsics256 { public static bool IsAvailable { get; } = HasVector8; [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static void ByteToNormalizedFloatReduce(ref ReadOnlySpan<byte> source, ref Span<float> dest) { if (IsAvailable) { int num = Numerics.Modulo8(source.Length); int num2 = source.Length - num; if (num2 > 0) { ByteToNormalizedFloat(source.Slice(0, num2), dest.Slice(0, num2)); source = s